From: asl Date: Tue, 13 Sep 2016 09:09:30 +0000 (+0300) Subject: debug of DTM presentation X-Git-Tag: v1.6~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c4738cc6d2fb23c60a1922847991007b3ac4e6d7;p=modules%2Fhydro.git debug of DTM presentation --- diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index 9e4da231..4db3a948 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -520,7 +520,7 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate size_t q = p>0 ? 2*mid[0].size() : 1; AltitudePoints points; points.reserve( p*q ); - for( size_t i=0; idumpView(); + QImage anActualImage; + if( theImage ) + anActualImage = *theImage; + else + anActualImage = viewWindow()->dumpView(); + + if( theCase ) + myKey = theCase; QString anExpectedRefFilePath = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO"; anExpectedRefFilePath += "/" + myKey + ".png"; diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 9030f33b..7173bb2f 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -24,6 +24,7 @@ class OCCViewer_ViewWindow; class TopoDS_Shape; class QString; class QColor; +class QImage; class Handle_AIS_InteractiveContext; class Handle_AIS_InteractiveObject; class Handle_Aspect_ColorScale; @@ -41,7 +42,7 @@ public: int theMode, int theSelectionMode, bool isFitAll, const char* theKey ); static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor ); static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey ); - static bool AssertImages( QString& theMessage ); + static bool AssertImages( QString& theMessage, const QImage* = 0, const char* theCase = 0 ); static QColor GetColor(int i); static Handle_Aspect_ColorScale colorScale(); @@ -72,6 +73,17 @@ private: } \ } \ +#define CPPUNIT_ASSERT_IMAGES2( theImage, theCase ) \ + { \ + QString aMessage; \ + if( !TestViewer::AssertImages( aMessage, theImage, theCase ) ) \ + { \ + TestViewer::showColorScale( false ); \ + std::string aMessageStl = aMessage.toStdString(); \ + CPPUNIT_FAIL( aMessageStl.c_str() ); \ + } \ + } \ + #define CPPUNIT_ASSERT_SCRIPTS_EQUAL( theBaseName, \ isExpectedUtf8, \ isActualUtf8, \ diff --git a/src/HYDRO_tests/reference_data/DTM_1.png b/src/HYDRO_tests/reference_data/DTM_1.png new file mode 100644 index 00000000..e84a2fca Binary files /dev/null and b/src/HYDRO_tests/reference_data/DTM_1.png differ diff --git a/src/HYDRO_tests/test_HYDROData_DTM.cxx b/src/HYDRO_tests/test_HYDROData_DTM.cxx index 96e779c7..97d122ab 100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@ -30,12 +30,119 @@ #include #include #include -#include +#include +#include +#include +#include +#include const double EPS = 1E-3; NCollection_Sequence points; +class DTM_item : public QGraphicsItem +{ +public: + DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d ) + { + Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() ); + Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints(); + myBB = QRectF(); + double xmin, xmax, ymin, ymax; + myD = d; + + int n = pp->VertexNumber(); + + for( int i=1; i<=n; i++ ) + { + gp_Pnt pnt = pp->Vertice( i ); + Quantity_Color col = pp->VertexColor( i ); + + int r = col.Red()*255; + int g = col.Green()*255; + int b = col.Blue()*255; + int val = ( r << 16 ) + ( g << 8 ) + b; + double x = pnt.X(); + double y = -pnt.Y(); + QPointF aPnt( x, y ); + myPoints[val].append( aPnt ); + if( i==1 ) + { + xmin = x; + xmax = x; + ymin = y; + ymax = y; + } + else + { + if( x>xmax ) + xmax = x; + if( xymax ) + ymax = y; + if( y >::const_iterator it = myPoints.begin(), last = myPoints.end(); + for( ; it!=last; it++ ) + { + int r = ( it.key() >> 16 ) % 256; + int g = ( it.key() >> 8 ) % 256; + int b = ( it.key() >> 0 ) % 256; + QColor aColor( r, g, b ); + QBrush aBrush( aColor ); + foreach( QPointF pnt, it.value() ) + { + QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD ); + p->fillRect( r, aBrush ); + } + } + } + +private: + QRectF myBB; + double myD; + QMap > myPoints; +}; + +QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight ) +{ + QGraphicsScene aScene; + QGraphicsView aView; + DTM_item anItem( theDTM, theD ); + + aView.setScene( &aScene ); + aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + aScene.addItem( &anItem ); + + aView.resize( theWidth, theHeight ); + QRectF bb = anItem.boundingRect(); + aView.fitInView( bb, Qt::KeepAspectRatio ); + QApplication::processEvents(); + + QPixmap aPixmap = QPixmap::grabWidget( &aView ); + return aPixmap.toImage(); +} + + void test_HYDROData_DTM::setUp() { points.Clear(); @@ -99,6 +206,14 @@ void test_HYDROData_DTM::test_hydraulic_axis() CPPUNIT_ASSERT_DOUBLES_EQUAL( 43.499, distances[1], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS ); + gp_Pnt2d p; + gp_Vec2d q; + HA->D1( 0, p, q ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.Y(), EPS ); + aDoc->Close(); } @@ -409,13 +524,13 @@ void test_HYDROData_DTM::test_presentation() aProfile1->SetParametricPoints( points ); aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); - aProfile1->SetLeftPoint( gp_XY( 20, 0 ) ); - aProfile1->SetRightPoint( gp_XY( 10, 10 ) ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 0 ) ); aProfile2->SetParametricPoints( points ); aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); - aProfile2->SetLeftPoint( gp_XY( 100, 0 ) ); - aProfile2->SetRightPoint( gp_XY( 110, 0 ) ); + aProfile2->SetLeftPoint( gp_XY( 110, 10 ) ); + aProfile2->SetRightPoint( gp_XY( 100, 0 ) ); HYDROData_SequenceOfObjects seq; seq.Append( aProfile1 ); @@ -427,7 +542,7 @@ void test_HYDROData_DTM::test_presentation() CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS ); DTM->Update(); - CPPUNIT_ASSERT_EQUAL( 10404, (int)DTM->GetAltitudePoints().size() ); + CPPUNIT_ASSERT_EQUAL( 10200, (int)DTM->GetAltitudePoints().size() ); Handle_AIS_InteractiveContext aContext = TestViewer::context(); HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); @@ -440,8 +555,8 @@ void test_HYDROData_DTM::test_presentation() aCS->SetNumberOfIntervals( 10 ); aBathPrs->UpdateWithColorScale( aCS ); - TestViewer::show( aBathPrs->getAISObject(), AIS_PointCloud::DM_Points, 0, true, "DTM_1" ); - CPPUNIT_ASSERT_IMAGES + QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 ); + CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" ); delete aBathPrs; aDoc->Close();