28 #include "WVertexFactory.h"
49 for (
size_t index = 0; index <
m_vertProp.size(); index++ )
64 if ( finalSize >= size )
69 for (
size_t vertID = size; vertID < finalSize * 3 / 2; vertID++ )
79 this->
m_vertProp[vertexID]->attachTriangle( triangleID );
95 int sizeN =
m_vertProp[vert1]->getTriangleCount();
96 for (
int neighbour = 0; vert1 != vert2 && neighbour < sizeN; neighbour++ )
98 size_t newTriID =
m_vertProp[vert1]->getAttachedTriangles() [neighbour];
100 if( newTriID != excludedTriangleID && this->
m_vertProp[vert2]->containsTriangle( newTriID )
103 int size = tris.size();
104 tris.reserve( size + 1 );
105 tris.resize( size + 1 );
106 tris[size] = newTriID;
117 if ( vert1 != id0 && vert2 != id0 )
120 if ( vert1 != id1 && vert2 != id1 )
127 if( vertID1 == vertID2 )
130 if( vertID1 > vertID2 )
132 size_t tmp = vertID1;
136 return this->
m_vertProp[vertID1]->newVertexExists( vertID2 );
144 return id0 != id1 && id0 != id2 && id1 != id2;
148 if ( vertex1 == vertex2 )
151 if ( vertex1 > vertex2 )
153 size_t tmp = vertex1;
157 this->
m_vertProp[vertex1]->attachNewVertex( vertex2 );
166 if ( vertex1 == vertex2 )
172 if ( vertex1 > vertex2 )
174 size_t tmp = vertex1;
178 return m_vertProp[vertex1]->getNewVertexProperty( vertex2 );
181 std::shared_ptr< WProgress > progress )
183 for (
size_t vert = fromVertex; vert <= toVertex; vert++ )
185 vector<size_t> attachedTriangles = this->
m_vertProp[vert]->getAttachedTriangles();
186 size_t totalTriangleCount = 0;
187 for (
size_t triangle = 0; triangle < attachedTriangles.size(); triangle++ )
189 totalTriangleCount++;
191 progress->increment( 1 );
192 size_t startTriID = 0;
193 while ( startTriID < attachedTriangles.size() && !
isValidTriangle(attachedTriangles[startTriID] ) )
196 if ( startTriID < attachedTriangles.size() )
198 size_t firstTri = attachedTriangles[startTriID],
200 vertBound = ( vertID0 != vert ? vertID0 : this->
m_triangleMesh->getTriVertId1( firstTri ) ),
201 firstVert = vertBound;
203 bool moreThanTwo = tris.size() > 2;
204 size_t firstDirection = tris[0];
205 size_t ranTriangles = 0;
210 property->addStencilNeighbourIDToBack( vertBound );
213 }
while( vertBound != firstVert && tris.size() == 1 );
215 if ( vertBound != firstVert && tris.size() < 2 )
217 property->addStencilNeighbourIDToBack( vertBound );
218 vertBound = firstVert;
220 while ( tris.size() == 1 )
224 property->insertStencilNeighbourIDToFront( vertBound );
229 if ( tris.size() > 1)
231 if ( vertBound == firstVert && !moreThanTwo && ranTriangles == totalTriangleCount )
238 this->
m_vertProp[vert]->setBoundClass( ( moreThanTwo || ranTriangles != totalTriangleCount ) ? 2 :1 );
239 if( !moreThanTwo && ranTriangles>totalTriangleCount )
247 float deltaX2 = pow( point2.x() - point1.x(), 2.0f );
248 float deltaY2 = pow( point2.y() - point1.y(), 2.0f );
249 float deltaZ2 = pow( point2.z() - point1.z(), 2.0f );
250 return pow( deltaX2 + deltaY2 + deltaZ2, 0.5f );
254 float baseX = base.x(), baseY = base.y(), baseZ = base.z();
255 float sumX = summand.x(), sumY = summand.y(), sumZ = summand.z();
256 float coordX = baseX + sumX * factor;
257 float coordY = baseY + sumY * factor;
258 float coordZ = baseZ + sumZ * factor;
259 return osg::Vec3( coordX, coordY, coordZ );
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.
void setValid(bool isValid)
Sets the new vertex property whether it's valid for butterfly subdivision or not.
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.