OpenWalnut  1.5.0dev
WVertexFactory.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2013 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WVERTEXFACTORY_H_
26 #define WVERTEXFACTORY_H_
27 
28 #include <memory>
29 #include <vector>
30 
31 #include "WNewVertex.h"
32 #include "WVertexProperty.h"
33 #include "core/graphicsEngine/WTriangleMesh.h"
34 #include "core/kernel/WModule.h"
35 #include "osg/Vec3"
36 
37 
38 namespace butterfly
39 {
40  /**
41  * Class that manages all vertex properties. It depicts the outer object that manages the entire set of the
42  * triangle mesh that is not possible to analyze using a triangle mesh only.
43  */
45  {
46  public:
47  /**
48  * Creates a vertex factory object and assigns the triangle mesh that should be analyzed in future.#
49  * \param triangleMesh Associated triangle mesh that should be analyzed.
50  */
51  explicit WVertexFactory( std::shared_ptr< WTriangleMesh > triangleMesh );
52  /**
53  * Creates a vertex factory object.
54  */
56  /**
57  * Destroys the vertex factory object.
58  */
59  virtual ~WVertexFactory();
60 
61  /**
62  * Sets the WTriangleMesh. It's necessary for the correct triangle mesh examination.
63  * \author schwarzkopf
64  * \param triangleMesh Triangle mesh to be registered.
65  */
66  void setTriangleMesh( std::shared_ptr< WTriangleMesh > triangleMesh );
67 
68  /**
69  * Resizes the Vertex property list to the wished size.
70  * \author schwarzkopf
71  * \param count Required list size.
72  */
73  void resize( size_t count );
74 
75  /**
76  * Registers triangle to all its vertex IDs.
77  * \author schwarzkopf
78  * \param vertexID The triangle will be registered in the vertex of this ID.
79  * \param triangleID Triangle ID to be registered.
80  */
81  void registerTriangle( size_t vertexID, size_t triangleID );
82 
83  /**
84  * Returns all Triangle IDs but the excluded attached to two particular vertices.
85  * \author schwarzkopf
86  * \param excludedTriangleID Triangle ID that should not be added to the returned list.
87  * \param vertex1 First vertex the triangle should lie on.
88  * \param vertex2 Second vertex the triangle should lie on.
89  * \return All triangle IDs which lie on the two vertices but the triangleID.
90  */
91  vector<size_t> getAttachedTriangleIDs( size_t excludedTriangleID, size_t vertex1, size_t vertex2 );
92 
93  /**
94  * Returns the third vertex ID of a triangle.
95  * \author schwarzkopf
96  * \param triangleID Triangle ID to examine.
97  * \param vertex1 First vertexID to exclude.
98  * \param vertex2 Second vertex ID to exclude.
99  * \return Not excluded vertex ID.
100  */
101  size_t get3rdVertexID( size_t triangleID, size_t vertex1, size_t vertex2 );
102 
103  /**
104  * Returns the Property List's vertex count
105  * \return Vertex property count of the list.
106  */
107  size_t getVertexCount();
108 
109  /**
110  * Returns whether properties of the subdividable new vertex between two vertices
111  * alreadey exists.
112  * \author schwarzkopf
113  * \param fromID First connected vertex to the subdividable line.
114  * \param toID Second connected vertex to the subdividable line.
115  * \return Properties of a subdividable new vertex have been registered or not.
116  */
117  bool newVertexExists( size_t fromID, size_t toID );
118 
119  /**
120  * Examine triangle by its ID for validity. Currently it basically checks whether all
121  * vertex Ds are used once.
122  * \param triangleID ID of a triangle to examine.
123  * \return Triangle is valid or not.
124  */
125  bool isValidTriangle( size_t triangleID );
126 
127  /**
128  * Registering a subdividable new vertex of an ID between two vertices. Invalid
129  * subdividable new vertices are also registered. But there are market to be invalid
130  * afterwards.
131  * \author schwarzkopf
132  * \param fromID The first neighbor vertex ID where the new vertex lies between.
133  * \param toID The second neighbor vertex ID where the new vertex lies between.
134  */
135  void attachNewVertex( size_t fromID, size_t toID );
136 
137  /**
138  * Get properties of a vertex
139  * \author schwarzkopf
140  * \param vertexID Vertex ID to get properties from.
141  * \return Properties' data set pointer.
142  */
143  WVertexProperty* getProperty( size_t vertexID );
144 
145  /**
146  * Get properties of a new vertex which subdivides a line between two vertices.
147  * \author schwarzkopf
148  * \param fromID The first neighbor vertex ID where the new vertex lies between.
149  * \param toID The second neighbor vertex ID where the new vertex lies between.
150  * \return Pointer to the properties of the new vertex.
151  */
152  WNewVertex* getNewVertexProperty( size_t fromID, size_t toID );
153 
154  /**
155  * Examines Butterfly stencils of all vertices and applies settings data to the vertex.
156  * properties. Due to this basically all neighbor vertices are sorted and stored
157  * into the butterfly stencil neighbor vertex ID array. The sort order is circular
158  * by each vertex. The neighbor vertex count is stored as valence.
159  *
160  * The first two parameters are to select the vertices to calculated. It's useful
161  * for multithreading.
162  * \author schwarzkopf
163  * \param fromVertex First data set holding vertex property.
164  * \param toVertex Last data set holding vertex property.
165  * \param progress Progress which is actualized during the calculation.
166  */
167  void examineStencilRange( size_t fromVertex, size_t toVertex,
168  std::shared_ptr< WProgress > progress );
169 
170  /**
171  * Calculate distance between two vertices.
172  * \author schwarzkopf
173  * \param point1 Vertex 1.
174  * \param point2 Vertex 2.
175  * \return Distance between two vertices
176  */
177  static float getDistance( osg::Vec3 point1, osg::Vec3 point2 );
178 
179  /**
180  * Adding a sum multiplied by a factor to the base number
181  * \author schwarzkopf
182  * \param base The base number to add the summand
183  * \param sum Summand that is added to the base number
184  * \param factor Number that multiplies the summand
185  * \return Base number + summand * factor
186  */
187  static osg::Vec3 add( osg::Vec3 base, osg::Vec3 sum, float factor );
188 
189 
190  private:
191  /**
192  * Vertex properties data. The valid size is not the actual vector size but vertexCount.
193  * It's been taken in order not to resize the whole array after each adding what would
194  * be a big performance drawback.
195  */
196  std::vector<WVertexProperty*> m_vertProp;
197 
198  /**
199  * Assigned Triangle mesh. It's necessary for the proper examination.
200  */
201  std::shared_ptr< WTriangleMesh > m_triangleMesh;
202 
203  /**
204  * Vertex count of the property list.
205  */
207 
208  /**
209  * Triangle count.
210  */
211  size_t m_triangleCount; //TODO(schwarzkopf): Consider removing this variable or describe it thoroughly.
212  };
213 } /* namespace butterfly */
214 #endif // WVERTEXFACTORY_H
Object that contains all necessary properties of a vertex necessary for a sufficient analysis.
Depicts a point that is subdivided on a line between two vertices.
Definition: WNewVertex.h:40
Class that manages all vertex properties.
size_t m_triangleCount
Triangle count.
WVertexProperty * getProperty(size_t vertexID)
Get properties of a vertex.
std::vector< WVertexProperty * > m_vertProp
Vertex properties data.
std::shared_ptr< WTriangleMesh > m_triangleMesh
Assigned Triangle mesh.
bool isValidTriangle(size_t triangleID)
Examine triangle by its ID for validity.
WNewVertex * getNewVertexProperty(size_t fromID, size_t toID)
Get properties of a new vertex which subdivides a line between two vertices.
size_t getVertexCount()
Returns the Property List's vertex count.
size_t get3rdVertexID(size_t triangleID, size_t vertex1, size_t vertex2)
Returns the third vertex ID of a triangle.
void setTriangleMesh(std::shared_ptr< WTriangleMesh > triangleMesh)
Sets the WTriangleMesh.
void examineStencilRange(size_t fromVertex, size_t toVertex, std::shared_ptr< WProgress > progress)
Examines Butterfly stencils of all vertices and applies settings data to the vertex.
static osg::Vec3 add(osg::Vec3 base, osg::Vec3 sum, float factor)
Adding a sum multiplied by a factor to the base number.
void attachNewVertex(size_t fromID, size_t toID)
Registering a subdividable new vertex of an ID between two vertices.
void registerTriangle(size_t vertexID, size_t triangleID)
Registers triangle to all its vertex IDs.
static float getDistance(osg::Vec3 point1, osg::Vec3 point2)
Calculate distance between two vertices.
vector< size_t > getAttachedTriangleIDs(size_t excludedTriangleID, size_t vertex1, size_t vertex2)
Returns all Triangle IDs but the excluded attached to two particular vertices.
size_t m_vertexCount
Vertex count of the property list.
void resize(size_t count)
Resizes the Vertex property list to the wished size.
virtual ~WVertexFactory()
Destroys the vertex factory object.
bool newVertexExists(size_t fromID, size_t toID)
Returns whether properties of the subdividable new vertex between two vertices alreadey exists.
WVertexFactory()
Creates a vertex factory object.