#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepOffsetAPI_NormalProjection.hxx>
+#include <BRepAdaptor_Curve.hxx>
#ifndef LIGHT_MODE
#include <GEOMBase.h>
#include <Geom_BSplineCurve.hxx>
#include <GCPnts_AbscissaPoint.hxx>
+#include <GCPnts_QuasiUniformDeflection.hxx>
#include <ImageComposer_MetaTypes.h>
#include <TColStd_ListIteratorOfListOfReal.hxx>
#include <TColStd_Array1OfReal.hxx>
+#include <TColgp_Array1OfPnt.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_BooleanList.hxx>
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
HYDROData_PolylineXY::HYDROData_PolylineXY()
-: HYDROData_IPolyline()
+: HYDROData_IPolyline(),
+ myIsInCustomFlag( false )
{
}
NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
NCollection_Sequence<bool>& theSectClosures,
NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
- const bool theIsCanBeClosed )
+ bool IsCanBeClosed,
+ bool IsInterpolationAllowed,
+ double theDeflection )
{
Standard_Real aFirst = 0.0, aLast = 0.0;
Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
HYDROData_PolylineXY::PointsList aPointsList;
- if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
+ if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
{
Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
aPointsList.Append( aSectLastPoint );
}
- else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
+ else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
{
aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
- Handle(Geom_BSplineCurve) aGeomSpline =
- Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
+ BRepAdaptor_Curve anAdaptorCurve( theEdge );
+ GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
- int aNbKnots = aGeomSpline->NbKnots();
+ int aNbPoints = aDiscrete.NbPoints();
- TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
- aGeomSpline->Knots( aSplineKnots );
+ // Decrease the number of imported poles because of last one
+ // pole is the closing point which are the start point
+ if ( anIsEdgeClosed ) aNbPoints--;
- // Decrease the number of imported knots because of last one
- // knot is the closing point which are the start point
- if ( anIsEdgeClosed ) aNbKnots--;
-
- for ( int i = 1; i <= aNbKnots; ++i )
+ for ( int i = 1; i <= aNbPoints; ++i )
{
- const Standard_Real& aKnot = aSplineKnots.Value( i );
-
- gp_Pnt aPoint;
- aGeomSpline->D0( aKnot, aPoint );
+ const gp_Pnt& aPoint = aDiscrete.Value( i );
HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
aPointsList.Append( aSectPoint );
return true;
}
-bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
+bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
+ bool IsInterpolationAllowed,
+ double theDeviation )
{
if ( theShape.IsNull() )
return false;
if ( theShape.ShapeType() == TopAbs_EDGE )
{
TopoDS_Edge anEdge = TopoDS::Edge( theShape );
- anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
+ anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
+ aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
}
else if ( theShape.ShapeType() == TopAbs_WIRE )
{
for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
{
TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
- anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
+ anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes,
+ aSectClosures, aSectPoints, false, IsInterpolationAllowed, theDeviation );
}
}
theSectTypes.Clear();
theSectClosures.Clear();
+ if( IsCustom() )
+ {
+ const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
+ }
+
Handle(TDataStd_ExtStringList) aNamesList;
Handle(TDataStd_IntegerList) aTypesList;
Handle(TDataStd_BooleanList) aClosuresList;
if( IsCustom() )
{
- //TODO: make interpolation to fill the list
+ const_cast<HYDROData_PolylineXY*>( this )->Interpolate();
}
Handle(TDataStd_RealList) aListX, aListY;
bool HYDROData_PolylineXY::IsCustom() const
{
+ if( myIsInCustomFlag )
+ return false;
+
bool isNull = GetShape().IsNull();
int aNbPoints = 0;
- //TODO: to check if there is no points
- //for( int i=0, n=NbSections(); i<n; i++ )
- // aNbPoints += NbPoints( i );
+ HYDROData_PolylineXY* aThat = const_cast<HYDROData_PolylineXY*>( this );
+ aThat->myIsInCustomFlag = true;
+ for( int i=0, n=NbSections(); i<n; i++ )
+ aNbPoints += NbPoints( i );
+ aThat->myIsInCustomFlag = false;
return !isNull && aNbPoints == 0;
}
+
+void HYDROData_PolylineXY::Interpolate()
+{
+ ImportShape( GetShape(), true );
+}
/**
* Returns the 3D presentation of all points.
*/
- HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape );
+ HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape,
+ bool IsInterpolationAllowed = false,
+ double theDeviation = 1E-3 );
/**
* Returns flag indicating that polyline can be edited or not.
*/
HYDRODATA_EXPORT virtual void setEditable( const bool theIsEditable );
+ HYDRODATA_EXPORT void Interpolate();
+
protected:
friend class HYDROData_Profile;
* Destructs properties of the object and object itself, removes it from the document.
*/
HYDRODATA_EXPORT ~HYDROData_PolylineXY();
+
+private:
+ bool myIsInCustomFlag;
};
#endif
return theStream;
}
+std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY )
+{
+ theStream << "(" << theXY.X() << "; " << theXY.Y() << ")";
+ return theStream;
+}
+
+bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 )
+{
+ const double EPS = 1E-3;
+ return
+ fabs( thePoint1.X() - thePoint2.X() ) < EPS &&
+ fabs( thePoint1.Y() - thePoint2.Y() ) < EPS;
+
+}
HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText );
HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape );
HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace );
+HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 );
+HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY );
#endif
#include <TopoDS_Face.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <GeomAPI_Interpolate.hxx>
+#include <gp_Circ.hxx>
TopoDS_Edge Edge( const QList<double>& theXYList, bool isClosed )
{
{
return BRepBuilderAPI_MakeFace( Wire( theXYList, true ), Standard_True ).Face();
}
+
+TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius )
+{
+ gp_Circ aCircle( gp_Ax2( theCenter, gp_Dir( 0, 0, 1 ) ), theRadius );
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCircle ).Edge();
+ return BRepBuilderAPI_MakeWire( anEdge ).Wire();
+}
class TopoDS_Edge;
class TopoDS_Wire;
class TopoDS_Face;
+class gp_Pnt;
TopoDS_Edge Edge( const QList<double>& theXYList, bool isClosed = false );
TopoDS_Wire Wire( const QList<double>& theXYList, bool isClosed = false );
+TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius );
TopoDS_Face Face( const QList<double>& theXYList );
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
+#include <gp_XY.hxx>
void test_HYDROData_PolylineXY::testPolyline()
{
anIt2.Next();
CPPUNIT_ASSERT_EQUAL( false, anIt2.More() );
anIt2.Next();
+
+ aDoc->Close();
+}
+
+void test_HYDROData_PolylineXY::test_custom_polylines()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+ Handle(HYDROData_PolylineXY) aPolyline1 =
+ Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+ Handle(HYDROData_PolylineXY) aPolyline2 =
+ Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+ Handle(HYDROData_PolylineXY) aPolyline3 =
+ Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+
+ aPolyline1->SetName( "test1" );
+ aPolyline2->SetName( "test2" );
+ aPolyline3->SetName( "test3" );
+
+ CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() );
+ aPolyline1->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false );
+ aPolyline1->Update();
+ CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() );
+ aPolyline1->AddPoint( 0, gp_XY( 0, 0 ) );
+ aPolyline1->Update();
+ CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() );
+
+ CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() );
+ aPolyline2->SetShape( Wire( QList<double>() << 0 << 0 << 1 << 1 << 2 << 0 ) );
+ CPPUNIT_ASSERT_EQUAL( true, aPolyline2->IsCustom() );
+ HYDROData_PolylineXY::PointsList aPointsList = aPolyline2->GetPoints( 0 );
+
+ CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() );
+ CPPUNIT_ASSERT_EQUAL( 33, aPointsList.Size() );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 0, 0 ), aPointsList.Value( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 0.5625, 0.808594 ), aPointsList.Value( 10 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 1.1875, 0.964844 ), aPointsList.Value( 20 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 2, 0 ), aPointsList.Value( 33 ) );
+
+
+ CPPUNIT_ASSERT_EQUAL( false, aPolyline3->IsCustom() );
+ aPolyline3->SetShape( WireCirc( gp_Pnt(), 1.0 ) );
+ CPPUNIT_ASSERT_EQUAL( true, aPolyline3->IsCustom() );
+ aPointsList = aPolyline3->GetPoints( 0 );
+
+ CPPUNIT_ASSERT_EQUAL( HYDROData_PolylineXY::SECTION_SPLINE, aPolyline3->GetSectionType( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( true, aPolyline3->IsClosedSection( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 71, aPointsList.Size() );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 1, 0 ), aPointsList.Value( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 0.699242, 0.714885 ), aPointsList.Value( 10 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( -0.110394, 0.993888 ), aPointsList.Value( 20 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( -0.839072, 0.54402 ), aPointsList.Value( 30 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( -0.952415, -0.304806 ), aPointsList.Value( 40 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( -0.367302, -0.930102 ), aPointsList.Value( 50 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 0.487173, -0.873306 ), aPointsList.Value( 60 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XY( 0.996087, -0.0883801 ), aPointsList.Value( 71 ) );
+
+ aDoc->Close();
}
CPPUNIT_TEST( test_presentation );
CPPUNIT_TEST( test_extraction_immersible_zone );
CPPUNIT_TEST( test_extraction_channel_refs_611 );
+ CPPUNIT_TEST( test_custom_polylines );
CPPUNIT_TEST_SUITE_END();
private:
void test_extraction_immersible_zone();
void test_extraction_channel_refs_611();
void test_presentation();
+ void test_custom_polylines();
};
CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_PolylineXY);