Salome HOME
implementation of algorithms for DTM
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_DTM.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
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>
25 #include <gp_XY.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
28
29 const double EPS = 1E-3;
30
31 void test_HYDROData_DTM::test_creation()
32 {
33   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
34
35   Handle(HYDROData_DTM) DTM = 
36     Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
37
38   CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
39    
40   aDoc->Close();
41 }
42
43 void test_HYDROData_DTM::test_profile_conversion_to_2d()
44 {
45   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
46
47   Handle(HYDROData_Profile) aProfile1 = 
48     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
49
50   Handle(HYDROData_Profile) aProfile2 = 
51     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
52
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 ) );
58
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 ) );
63
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 ) );
68
69   double aUMin1 = std::numeric_limits<double>::max(),
70          aUMax1 = -aUMin1,
71          aUMin2 = aUMin1,
72          aUMax2 = aUMax1;
73   std::vector<Handle_Geom2d_Curve> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1 );
74   std::vector<Handle_Geom2d_Curve> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2 );
75
76   gp_Pnt2d aFirst, aLast;
77   CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
78   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
79   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.839, aUMax1, EPS );
80   curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
81   curves1[0]->D0( curves1[0]->LastParameter(), aLast );
82   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
83   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aFirst.Y(), EPS );
84   CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(),  EPS );
85   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.0,   aLast.Y(),  EPS );
86   curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
87   curves1[1]->D0( curves1[1]->LastParameter(), aLast );
88   CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
89   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.0,   aFirst.Y(), EPS );
90   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aLast.X(),  EPS );
91   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aLast.Y(),  EPS );
92   curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
93   curves1[2]->D0( curves1[2]->LastParameter(), aLast );
94   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aFirst.X(), EPS );
95   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aFirst.Y(), EPS );
96   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.839, aLast.X(),  EPS );
97   CPPUNIT_ASSERT_DOUBLES_EQUAL(  4.0,   aLast.Y(),  EPS );
98
99   CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
100   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
101   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.839, aUMax2, EPS );
102   Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
103   CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
104   const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
105   CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
106   CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
107   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
108   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   poles.Value( 1 ).Y(), EPS );
109   CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
110   CPPUNIT_ASSERT_DOUBLES_EQUAL(  3.667, poles.Value( 2 ).Y(), EPS );
111   CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
112   CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.120, poles.Value( 3 ).Y(), EPS );
113   CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
114   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.574, poles.Value( 4 ).Y(), EPS );
115
116   aDoc->Close();
117 }