+HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints( double theEqDistance ) const
+{
+ Polyline3DPoints aPoints;
+
+ Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
+ TopoDS_Wire aWire = TopoDS::Wire( GetShape3D() );
+ if ( aPolylineXY.IsNull() || aWire.IsNull() ) {
+ return aPoints;
+ }
+
+ // Explode polyline on edges
+ TopTools_SequenceOfShape anEdges;
+ HYDROData_ShapesTool::ExploreShapeToShapes( aWire, TopAbs_EDGE, anEdges );
+
+ // Get points
+ if ( !anEdges.IsEmpty() ) {
+ HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+
+ if ( aSectionType == HYDROData_IPolyline::SECTION_POLYLINE ) {
+ // Get points from wire
+ /* Seems that intermediate vertices are duplicated
+ TopExp_Explorer anExp( aWire, TopAbs_VERTEX );
+ for ( ; anExp.More(); anExp.Next() ) {
+ TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
+ if ( !aVertex.IsNull() ) {
+ gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
+ aPoints.Append( aPnt.XYZ() );
+ }
+ }
+ */
+ TopExp_Explorer anExp( aWire, TopAbs_EDGE );
+ bool isFirst = true;
+ for ( ; anExp.More(); anExp.Next() ) {
+ TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() );
+ if ( !anEdge.IsNull() ) {
+ TopoDS_Vertex aV1, aV2;
+ TopExp::Vertices( anEdge, aV1, aV2 );
+ if ( isFirst ) {
+ gp_Pnt aPnt1 = BRep_Tool::Pnt( aV1 );
+ aPoints.Append( aPnt1.XYZ() );
+ }
+
+ gp_Pnt aPnt2 = BRep_Tool::Pnt( aV2 );
+ aPoints.Append( aPnt2.XYZ() );
+
+ isFirst = false;
+ }
+ }
+ } else {
+ // Get points from spline curve
+ Standard_Real aStart, anEnd;
+ TopoDS_Edge anEdge = TopoDS::Edge( anEdges.First() );
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
+
+ if( theEqDistance > 0 )
+ {
+ GeomAdaptor_Curve anAdaptorCurve( aCurve );
+ double aLength = GCPnts_AbscissaPoint::Length( anAdaptorCurve );
+ int aNbPoints = ceil( aLength / theEqDistance );
+ GCPnts_QuasiUniformAbscissa aDist( anAdaptorCurve, aNbPoints );
+ if( aDist.IsDone() )
+ {
+ aNbPoints = aDist.NbPoints();
+ for( int i=1; i<=aNbPoints; i++ )
+ {
+ double p = aDist.Parameter( i );
+ gp_Pnt aPnt;
+ aCurve->D0( p, aPnt );
+ aPoints.Append( aPnt.XYZ() );
+ }
+ return aPoints;
+ }
+ }
+
+ Handle(Geom_BSplineCurve) aGeomSpline = Handle(Geom_BSplineCurve)::DownCast( aCurve );
+
+ if ( !aGeomSpline.IsNull() ) {
+ int aNbKnots = aGeomSpline->NbKnots();
+
+ TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
+ aGeomSpline->Knots( aSplineKnots );
+
+ for ( int i = 1; i <= aNbKnots; ++i ) {
+ const Standard_Real& aKnot = aSplineKnots.Value( i );
+ gp_Pnt aPnt;
+ aGeomSpline->D0( aKnot, aPnt );
+ aPoints.Append( aPnt.XYZ() );
+ }
+ }
+ }
+ }
+
+ return aPoints;
+}