bool isInsideClosedContour( const SbVec3f& pt, const SoMFVec3f& point ) { bool oddNodes = false; int numPoints = point.getNum(); if( numPoints ) { // Shift the vertices so that 'pt' is the origin SoMFVec3f tmpPoint; tmpPoint.setValues( 0, numPoints, point.getValues(0) ); SbVec3f* ptr = tmpPoint.startEditing(); for( int k = 0; k < numPoints; ++ k ) { ptr[k] -= pt; if( isZero( ptr[k][0] ) && isZero( ptr[k][1] ) ) return true; } for( int i = 0, j = numPoints - 1; i < numPoints; j = i ++ ) { if( ptr[i][1] < 0 && ptr[j][1] >= 0 || ptr[j][1] < 0 && ptr[i][1] >= 0 ) { if( ptr[i][0] < ptr[i][1] / (ptr[j][1] - ptr[i][1]) * (ptr[j][0] - ptr[i][0]) ) oddNodes = !oddNodes; } } tmpPoint.finishEditing(); } return oddNodes; }
void SoXipOverlayExtractContour::appendContour( SoXipManipulableShape* shape, SoMFVec3f& accumulatePoint, SoMFInt32& accumulateCoordIndex ) { if( !shape->isClosed() ) { SoDebugError::post( __FILE__, "Contour extraction does not operate on shapes with opened contours" ); return ; } int oldNumPoints = accumulatePoint.getNum(); int oldNumIndices = accumulateCoordIndex.getNum(); SoMFVec3f linePoints; SoMFInt32 lineIndices; SbBool closed; shape->extractGeometries( linePoints, lineIndices, closed ); accumulatePoint.setValues( oldNumPoints, linePoints.getNum(), linePoints.getValues(0) ); accumulateCoordIndex.setValues( oldNumIndices, lineIndices.getNum(), lineIndices.getValues(0) ); int* indPtr = accumulateCoordIndex.startEditing() + oldNumIndices; for( int i = 0; i < lineIndices.getNum(); ++ i, ++ indPtr ) { if( *indPtr != -1 ) *indPtr += oldNumPoints; } accumulateCoordIndex.finishEditing(); }
void removeClosePoints( const SoMFVec3f& point, SoMFVec3f& cleanPoints, float minDist ) { cleanPoints.setNum( point.getNum() ); cleanPoints.setValues( 0, point.getNum(), point.getValues(0) ); int numPoints = cleanPoints.getNum(); if( cleanPoints.getNum() >= 2 ) { for( int ni = numPoints - 1, i = 0; i < numPoints; ) { if( (cleanPoints[ni] - cleanPoints[i]).length() <= minDist ) { cleanPoints.deleteValues( i, 1 ); -- numPoints; } else // move forward { ni = i ++; } } } }