-void Brush::buildBRep()
-{
- bool degenerate = buildWindings();
-
- std::size_t faces_size = 0;
- std::size_t faceVerticesCount = 0;
- for(Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i)
- {
- if((*i)->contributes())
- {
- ++faces_size;
- }
- faceVerticesCount += (*i)->getWinding().numpoints;
- }
-
- if(degenerate || faces_size < 4 || faceVerticesCount != (faceVerticesCount>>1)<<1) // sum of vertices for each face of a valid polyhedron is always even
- {
- m_uniqueVertexPoints.resize(0);
-
- vertex_clear();
- edge_clear();
-
- m_edge_indices.resize(0);
- m_edge_faces.resize(0);
-
- m_faceCentroidPoints.resize(0);
- m_uniqueEdgePoints.resize(0);
- m_uniqueVertexPoints.resize(0);
-
- for(Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i)
- {
- (*i)->getWinding().resize(0);
- }
- }
- else
- {
- {
- typedef std::vector<FaceVertexId> FaceVertices;
- FaceVertices faceVertices;
- faceVertices.reserve(faceVerticesCount);
-
- {
- for(std::size_t i = 0; i != m_faces.size(); ++i)
- {
- for(std::size_t j = 0; j < m_faces[i]->getWinding().numpoints; ++j)
- {
- faceVertices.push_back(FaceVertexId(i, j));
- }
- }
- }
-
- IndexBuffer uniqueEdgeIndices;
- typedef VertexBuffer<ProximalVertex> UniqueEdges;
- UniqueEdges uniqueEdges;
-
- uniqueEdgeIndices.reserve(faceVertices.size());
- uniqueEdges.reserve(faceVertices.size());
-
- {
- ProximalVertexArray edgePairs;
- edgePairs.resize(faceVertices.size());
-
- {
- for(std::size_t i=0; i<faceVertices.size(); ++i)
- {
- edgePairs[i].m_next = edgePairs.data() + absoluteIndex(next_edge(m_faces, faceVertices[i]));
- }
- }
-
- {
- UniqueVertexBuffer<ProximalVertex> inserter(uniqueEdges);
- for(ProximalVertexArray::iterator i = edgePairs.begin(); i != edgePairs.end(); ++i)
- {
- uniqueEdgeIndices.insert(inserter.insert(ProximalVertex(&(*i))));
- }
- }
-
- {
- edge_clear();
- m_select_edges.reserve(uniqueEdges.size());
- for(UniqueEdges::iterator i = uniqueEdges.begin(); i != uniqueEdges.end(); ++i)
- {
- edge_push_back(faceVertices[ProximalVertexArray_index(edgePairs, *i)]);
- }
- }
-
- {
- m_edge_faces.resize(uniqueEdges.size());
- for(std::size_t i=0; i<uniqueEdges.size(); ++i)
- {
- FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index(edgePairs, uniqueEdges[i])];
- m_edge_faces[i] = EdgeFaces(faceVertex.getFace(), m_faces[faceVertex.getFace()]->getWinding()[faceVertex.getVertex()].adjacent);
- }
- }
-
- {
- m_uniqueEdgePoints.resize(uniqueEdges.size());
- for(std::size_t i=0; i<uniqueEdges.size(); ++i)
- {
- FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index(edgePairs, uniqueEdges[i])];
-
- const Winding& w = m_faces[faceVertex.getFace()]->getWinding();
- Vector3 edge = vector3_mid(w[faceVertex.getVertex()].vertex, w[Winding_next(w, faceVertex.getVertex())].vertex);
- m_uniqueEdgePoints[i] = pointvertex_for_windingpoint(edge, colour_vertex);
- }
- }
-
- }
-
-
- IndexBuffer uniqueVertexIndices;
- typedef VertexBuffer<ProximalVertex> UniqueVertices;
- UniqueVertices uniqueVertices;
-
- uniqueVertexIndices.reserve(faceVertices.size());
- uniqueVertices.reserve(faceVertices.size());
-
- {
- ProximalVertexArray vertexRings;
- vertexRings.resize(faceVertices.size());
-
- {
- for(std::size_t i=0; i<faceVertices.size(); ++i)
- {
- vertexRings[i].m_next = vertexRings.data() + absoluteIndex(next_vertex(m_faces, faceVertices[i]));
- }
- }
-
- {
- UniqueVertexBuffer<ProximalVertex> inserter(uniqueVertices);
- for(ProximalVertexArray::iterator i = vertexRings.begin(); i != vertexRings.end(); ++i)
- {
- uniqueVertexIndices.insert(inserter.insert(ProximalVertex(&(*i))));
- }
- }
-
- {
- vertex_clear();
- m_select_vertices.reserve(uniqueVertices.size());
- for(UniqueVertices::iterator i = uniqueVertices.begin(); i != uniqueVertices.end(); ++i)
- {
- vertex_push_back(faceVertices[ProximalVertexArray_index(vertexRings, (*i))]);
- }
- }
-
- {
- m_uniqueVertexPoints.resize(uniqueVertices.size());
- for(std::size_t i=0; i<uniqueVertices.size(); ++i)
- {
- FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index(vertexRings, uniqueVertices[i])];
-
- const Winding& winding = m_faces[faceVertex.getFace()]->getWinding();
- m_uniqueVertexPoints[i] = pointvertex_for_windingpoint(winding[faceVertex.getVertex()].vertex, colour_vertex);
- }
- }
- }
-
- if((uniqueVertices.size() + faces_size) - uniqueEdges.size() != 2)
- {
- globalErrorStream() << "Final B-Rep: inconsistent vertex count\n";
- }
+void Brush::buildBRep(){
+ bool degenerate = buildWindings();
+
+ std::size_t faces_size = 0;
+ std::size_t faceVerticesCount = 0;
+ for ( Faces::const_iterator i = m_faces.begin(); i != m_faces.end(); ++i )
+ {
+ if ( ( *i )->contributes() ) {
+ ++faces_size;
+ }
+ faceVerticesCount += ( *i )->getWinding().numpoints;
+ }
+
+ if ( degenerate || faces_size < 4 || faceVerticesCount != ( faceVerticesCount >> 1 ) << 1 ) { // sum of vertices for each face of a valid polyhedron is always even
+ m_uniqueVertexPoints.resize( 0 );
+
+ vertex_clear();
+ edge_clear();
+
+ m_edge_indices.resize( 0 );
+ m_edge_faces.resize( 0 );
+
+ m_faceCentroidPoints.resize( 0 );
+ m_uniqueEdgePoints.resize( 0 );
+ m_uniqueVertexPoints.resize( 0 );
+
+ for ( Faces::iterator i = m_faces.begin(); i != m_faces.end(); ++i )
+ {
+ ( *i )->getWinding().resize( 0 );
+ }
+ }
+ else
+ {
+ {
+ typedef std::vector<FaceVertexId> FaceVertices;
+ FaceVertices faceVertices;
+ faceVertices.reserve( faceVerticesCount );
+
+ {
+ for ( std::size_t i = 0; i != m_faces.size(); ++i )
+ {
+ for ( std::size_t j = 0; j < m_faces[i]->getWinding().numpoints; ++j )
+ {
+ faceVertices.push_back( FaceVertexId( i, j ) );
+ }
+ }
+ }
+
+ IndexBuffer uniqueEdgeIndices;
+ typedef VertexBuffer<ProximalVertex> UniqueEdges;
+ UniqueEdges uniqueEdges;
+
+ uniqueEdgeIndices.reserve( faceVertices.size() );
+ uniqueEdges.reserve( faceVertices.size() );
+
+ {
+ ProximalVertexArray edgePairs;
+ edgePairs.resize( faceVertices.size() );
+
+ {
+ for ( std::size_t i = 0; i < faceVertices.size(); ++i )
+ {
+ edgePairs[i].m_next = edgePairs.data() + absoluteIndex( next_edge( m_faces, faceVertices[i] ) );
+ }
+ }
+
+ {
+ UniqueVertexBuffer<ProximalVertex> inserter( uniqueEdges );
+ for ( ProximalVertexArray::iterator i = edgePairs.begin(); i != edgePairs.end(); ++i )
+ {
+ uniqueEdgeIndices.insert( inserter.insert( ProximalVertex( &( *i ) ) ) );
+ }
+ }
+
+ {
+ edge_clear();
+ m_select_edges.reserve( uniqueEdges.size() );
+ for ( UniqueEdges::iterator i = uniqueEdges.begin(); i != uniqueEdges.end(); ++i )
+ {
+ edge_push_back( faceVertices[ProximalVertexArray_index( edgePairs, *i )] );
+ }
+ }
+
+ {
+ m_edge_faces.resize( uniqueEdges.size() );
+ for ( std::size_t i = 0; i < uniqueEdges.size(); ++i )
+ {
+ FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index( edgePairs, uniqueEdges[i] )];
+ m_edge_faces[i] = EdgeFaces( faceVertex.getFace(), m_faces[faceVertex.getFace()]->getWinding()[faceVertex.getVertex()].adjacent );
+ }
+ }
+
+ {
+ m_uniqueEdgePoints.resize( uniqueEdges.size() );
+ for ( std::size_t i = 0; i < uniqueEdges.size(); ++i )
+ {
+ FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index( edgePairs, uniqueEdges[i] )];
+
+ const Winding& w = m_faces[faceVertex.getFace()]->getWinding();
+ Vector3 edge = vector3_mid( w[faceVertex.getVertex()].vertex, w[Winding_next( w, faceVertex.getVertex() )].vertex );
+ m_uniqueEdgePoints[i] = pointvertex_for_windingpoint( edge, colour_vertex );
+ }
+ }
+
+ }
+
+
+ IndexBuffer uniqueVertexIndices;
+ typedef VertexBuffer<ProximalVertex> UniqueVertices;
+ UniqueVertices uniqueVertices;
+
+ uniqueVertexIndices.reserve( faceVertices.size() );
+ uniqueVertices.reserve( faceVertices.size() );
+
+ {
+ ProximalVertexArray vertexRings;
+ vertexRings.resize( faceVertices.size() );
+
+ {
+ for ( std::size_t i = 0; i < faceVertices.size(); ++i )
+ {
+ vertexRings[i].m_next = vertexRings.data() + absoluteIndex( next_vertex( m_faces, faceVertices[i] ) );
+ }
+ }
+
+ {
+ UniqueVertexBuffer<ProximalVertex> inserter( uniqueVertices );
+ for ( ProximalVertexArray::iterator i = vertexRings.begin(); i != vertexRings.end(); ++i )
+ {
+ uniqueVertexIndices.insert( inserter.insert( ProximalVertex( &( *i ) ) ) );
+ }
+ }
+
+ {
+ vertex_clear();
+ m_select_vertices.reserve( uniqueVertices.size() );
+ for ( UniqueVertices::iterator i = uniqueVertices.begin(); i != uniqueVertices.end(); ++i )
+ {
+ vertex_push_back( faceVertices[ProximalVertexArray_index( vertexRings, ( *i ) )] );
+ }
+ }
+
+ {
+ m_uniqueVertexPoints.resize( uniqueVertices.size() );
+ for ( std::size_t i = 0; i < uniqueVertices.size(); ++i )
+ {
+ FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index( vertexRings, uniqueVertices[i] )];
+
+ const Winding& winding = m_faces[faceVertex.getFace()]->getWinding();
+ m_uniqueVertexPoints[i] = pointvertex_for_windingpoint( winding[faceVertex.getVertex()].vertex, colour_vertex );
+ }
+ }
+ }
+
+ if ( ( uniqueVertices.size() + faces_size ) - uniqueEdges.size() != 2 ) {
+ globalErrorStream() << "Final B-Rep: inconsistent vertex count\n";
+ }