185 int BSPTreePoly::Vertex::nextID = 1;
186 int BSPTreePoly::Edge::nextID = 1;
187 int BSPTreePoly::Face::nextID = 1;
192 BSPTreePoly::Vertex::nextID = 1;
193 BSPTreePoly::Edge::nextID = 1;
194 BSPTreePoly::Face::nextID = 1;
220 if( nextPtr ==
this )
222 assert( prevPtr ==
this );
223 assert( vtxPtr->usePtr ==
this );
227 else if( vtxPtr->usePtr ==
this )
228 vtxPtr->usePtr = nextPtr;
230 nextPtr->prevPtr = prevPtr;
231 prevPtr->nextPtr = nextPtr;
232 nextPtr = prevPtr = 0;
239 if( nextPtr == prevPtr )
241 assert( nextPtr ==
this );
248 nextPtr->prevPtr = prevPtr;
249 prevPtr->nextPtr = nextPtr;
250 if( vtxPtr->usePtr ==
this ) vtxPtr->
usePtr = nextPtr;
258 prevPtr = vtxPtr->usePtr;
260 vtxPtr->usePtr->
nextPtr =
this;
268 assert( !
face->usePtr );
289 assert( start() == prev->
end() );
303 assert( end() == next->
start() );
314 if( facePtr->usePtr ==
this ) facePtr->usePtr = ( nextPtr == this ) ? 0 : nextPtr;
316 if( edgePtr->forwardPtr ==
this ) edgePtr->forwardPtr = 0;
317 if( edgePtr->reversePtr ==
this ) edgePtr->reversePtr = 0;
319 if( !edgePtr->forwardPtr && !edgePtr->reversePtr )
delete edgePtr;
321 nextPtr->prevPtr = prevPtr;
322 prevPtr->nextPtr = nextPtr;
323 nextPtr = prevPtr = 0;
328 if( edgePtr->forwardPtr ==
this )
330 else if( edgePtr->reversePtr ==
this )
338 if( edgePtr->forwardPtr ==
this )
339 return edgePtr->start();
340 else if( edgePtr->reversePtr ==
this )
341 return edgePtr->end();
348 if( edgePtr->forwardPtr ==
this )
349 return edgePtr->end();
350 else if( edgePtr->reversePtr ==
this )
351 return edgePtr->start();
366 if( forwardPtr && forwardPtr->facePtr ==
face )
368 else if( reversePtr && reversePtr->facePtr ==
face )
377 while( nextEdgeUsePtr )
379 delete nextEdgeUsePtr;
380 if( usePtr && usePtr != nextEdgeUsePtr )
381 nextEdgeUsePtr = usePtr;
403 for(
int i = 0; i < 8; ++i )
408 int start_id = Edge::nextID;
410 for(
int i = 0; i < 4; ++i )
412 int j = ( i + 1 ) % 4;
413 edges[i] =
new Edge( vertices[i], vertices[j] );
414 edges[i + 4] =
new Edge( vertices[i], vertices[i + 4] );
415 edges[i + 8] =
new Edge( vertices[i + 4], vertices[j + 4] );
418 for(
int i = 0; i < 12; ++i )
419 edges[i]->
id = start_id++;
422 static const int face_conn[6][4] = { { 0, 5, -8, -4 }, { 1, 6, -9, -5 }, { 2, 7, -10, -6 },
423 { 3, 4, -11, -7 }, { -3, -2, -1, -12 }, { 8, 9, 10, 11 } };
424 for(
int i = 0; i < 6; ++i )
428 for(
int j = 0; j < 4; ++j )
430 int e = face_conn[i][j];
434 assert( !edges[e]->reversePtr );
448 assert( !edges[e]->forwardPtr );
470 face_list.push_back(
face );
476 if( !
face || !
face->usePtr )
return;
481 vertices.push_back( *coedge->
end() );
483 }
while( coedge !=
face->usePtr );
489 const CartVect* base = usePtr->start();
490 CartVect d1 = ( *usePtr->end() - *base );
493 CartVect d2 = ( *coedge->end() - *base );
497 return ( 1.0 / 6.0 ) * (
sum % *base );
504 result += ptr->signed_volume();
515 edge->edgePtr->start()->markVal = value;
516 edge->edgePtr->end()->markVal = value;
576 if(
face->usePtr == ptr )
face->usePtr = keep_start;
585 edge->forwardPtr->prevPtr = keep_start;
587 edge->forwardPtr->nextPtr = keep_end;
590 edge->reversePtr->facePtr = new_face;
591 edge->reversePtr->nextPtr = start;
593 edge->reversePtr->prevPtr = end;
604 const double epsilon =
EPSILON * ( plane_normal % plane_normal );
608 const int UNKNOWN = 0;
628 double d = plane_normal % *start + plane_coeff;
629 if( d * d <= epsilon )
642 double d = plane_normal % *end + plane_coeff;
643 if( d * d <= epsilon )
658 double t = -( plane_normal % *start + plane_coeff ) / ( dir % plane_normal );
669 if( !num_above )
return false;
676 EdgeUse *split_start = 0, *split_end = 0, *other_split = 0;
679 if(
edge->end()->markVal == ON &&
edge->start()->markVal != ON )
682 split_start =
edge->nextPtr;
683 else if( !split_end )
694 if( split_end && !other_split )
696 assert( split_start );
708 bool some_above =
false;
711 if(
edge->start()->markVal == ABOVE )
717 }
while(
edge &&
edge != ( *lptr )->usePtr );
727 lptr = &( ( *lptr )->nextPtr );
746 }
while( co_edge && co_edge !=
face->usePtr );
748 if( !edge_ptr )
return false;
752 Vertex *next_vtx, *start_vtx;
756 next_vtx = edge_ptr->
start();
757 start_vtx = edge_ptr->
end();
763 next_vtx = edge_ptr->
end();
764 start_vtx = edge_ptr->
start();
769 while( next_vtx != start_vtx )
774 while( use != this_use )
779 assert( edge_ptr->
start() == next_vtx );
780 next_vtx = edge_ptr->
end();
789 assert( edge_ptr->
end() == next_vtx );
790 next_vtx = edge_ptr->
start();
798 assert( use != this_use );
807 std::set< Face* > list_faces;
812 if( ++i > 10000 )
return false;
813 if( !list_faces.insert( ptr ).second )
return false;
816 std::set< Vertex* > vertices;
823 if( ++i > 10000 )
return false;
828 if( !
edge->startPtr || !
edge->endPtr )
return false;
830 vertices.insert(
edge->start() );
831 vertices.insert(
edge->end() );
834 if(
edge->forwardPtr == coedge )
835 other =
edge->reversePtr;
836 else if(
edge->reversePtr != coedge )
839 other =
edge->forwardPtr;
840 if( !other )
return false;
841 if( list_faces.find( other->
facePtr ) == list_faces.end() )
return false;
844 if( next->
prevPtr != coedge )
return false;
845 if( coedge->
end() != next->
start() )
return false;
848 }
while( coedge !=
face->usePtr );
851 for( std::set< Vertex* >::iterator j = vertices.begin(); j != vertices.end(); ++j )
859 if( ++i > 10000 )
return false;
861 if( use->
vtxPtr != vtx )
return false;
864 if( !
edge )
return false;
865 if(
edge->startPtr != use &&
edge->endPtr != use )
return false;
868 if( next->
prevPtr != use )
return false;
871 }
while( use != vtx->
usePtr );
888 pt1 =
face->usePtr->start();
889 pt2 =
face->usePtr->end();
890 pt3 =
face->usePtr->nextPtr->end();
895 CartVect norm = ( *pt3 - *pt2 ) * ( *pt1 - *pt2 );
896 double coeff = -( norm % *pt2 );
897 if( ( norm % point + coeff ) >
EPSILON )