1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_HYDROData_DTM.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_DTM.h>
22 #include <HYDROData_Profile.h>
23 #include <Geom2d_Curve.hxx>
24 #include <Geom2d_BSplineCurve.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
29 const double EPS = 1E-3;
31 void test_HYDROData_DTM::test_creation()
33 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
35 Handle(HYDROData_DTM) DTM =
36 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
38 CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
43 void test_HYDROData_DTM::test_profile_conversion_to_2d()
45 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
47 Handle(HYDROData_Profile) aProfile1 =
48 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
50 Handle(HYDROData_Profile) aProfile2 =
51 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
53 NCollection_Sequence<HYDROData_IPolyline::Point> points;
54 points.Append( gp_XY( 0.0, 5.0 ) );
55 points.Append( gp_XY( 1.0, 1.0 ) );
56 points.Append( gp_XY( 1.5, 0.0 ) );
57 points.Append( gp_XY( 4.0, 4.0 ) );
59 aProfile1->SetParametricPoints( points );
60 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
61 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
62 aProfile1->SetRightPoint( gp_XY( 20, 20 ) );
64 aProfile2->SetParametricPoints( points );
65 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
66 aProfile2->SetLeftPoint( gp_XY( 10, 10 ) );
67 aProfile2->SetRightPoint( gp_XY( 20, 20 ) );
69 std::vector<Handle_Geom2d_Curve> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1 );
70 std::vector<Handle_Geom2d_Curve> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2 );
72 gp_Pnt2d aFirst, aLast;
73 CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
74 curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
75 curves1[0]->D0( curves1[0]->LastParameter(), aLast );
76 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
77 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS );
78 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS );
79 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS );
80 curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
81 curves1[1]->D0( curves1[1]->LastParameter(), aLast );
82 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
83 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS );
84 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS );
85 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS );
86 curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
87 curves1[2]->D0( curves1[2]->LastParameter(), aLast );
88 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS );
89 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS );
90 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS );
91 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS );
93 CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
94 Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
95 CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
96 const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
97 CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
98 CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
99 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
100 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS );
101 CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
102 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS );
103 CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
104 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS );
105 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
106 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS );