From: asl Date: Tue, 20 Oct 2015 09:25:18 +0000 (+0300) Subject: refs #662: the tests for land cover presentations X-Git-Tag: v1.5~78^2~1^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c97445698e2e2de4b03e82e844f2490b8ecbe211;p=modules%2Fhydro.git refs #662: the tests for land cover presentations --- diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index a71d556c..7a005c24 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -20,22 +20,17 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include -IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject ) -IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject ) +IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) +IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap ) - : AIS_InteractiveObject() + : AIS_ColoredShape( theMap->GetShape() ) { SetLandCoverMap( theMap ); } @@ -52,6 +47,22 @@ Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap ) { myLCMap = theMap; + UpdateColors(); +} + +void HYDROGUI_LandCoverMapPrs::UpdateColors() +{ + Set( myLCMap->GetShape() ); + SetMaterial( Graphic3d_NOM_PLASTIC ); + HYDROData_LandCoverMap::Iterator anIt( myLCMap ); + for( ; anIt.More(); anIt.Next() ) + { + TopoDS_Face aFace = anIt.Face(); + QString aStricklerType = anIt.StricklerType(); + Quantity_Color aColor = GetColor( aStricklerType ); + SetCustomColor( aFace, aColor ); + SetCustomWidth( aFace, 1.0 ); + } } Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const @@ -62,6 +73,16 @@ Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale ) { myColorScale = theColorScale; + double aMin = 0, aMax = 0; + if( myTable.IsNull() ) + { + //TODO: go through all Strickler tables in the document to get the global range + } + else + myTable->GetCoefficientRange( aMin, aMax ); + + myColorScale->SetRange( aMin, aMax ); + UpdateColors(); } Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const @@ -100,7 +121,7 @@ Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerTy Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); if( aTable->HasType( theStricklerType ) ) { - QColor aColor = myTable->GetColor( theStricklerType ); + QColor aColor = aTable->GetColor( theStricklerType ); return HYDROData_Tool::toOccColor( aColor ); } } @@ -108,98 +129,29 @@ Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerTy return Quantity_Color(); } -void DrawTriangulation( const Handle(Prs3d_Presentation)& thePresentation, - const Handle(Poly_Triangulation)& theTriangulation, - const Quantity_Color& theColor ) -{ - const TColgp_Array1OfPnt& aNodesArray = theTriangulation->Nodes(); - int aNbNodes = aNodesArray.Length(); - - const Poly_Array1OfTriangle& aTrianglesArray = theTriangulation->Triangles(); - int aNbTriangles = aTrianglesArray.Length(); - - Handle( Graphic3d_ArrayOfTriangles ) anArray = new Graphic3d_ArrayOfTriangles - ( aNbNodes, aNbTriangles * 3, Standard_True, Standard_True, Standard_False ); - - Prs3d_Root::NewGroup( thePresentation ); - Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( thePresentation ); - Handle( Graphic3d_AspectFillArea3d ) anAspect = new Graphic3d_AspectFillArea3d(); - Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC ); - aMaterialAspect.SetColor( theColor ); - anAspect->SetFrontMaterial( aMaterialAspect ); - anAspect->SetBackMaterial( aMaterialAspect ); - - Standard_Integer i; - - for( i = aNodesArray.Lower(); i <= aNodesArray.Upper(); i++ ) - { - anArray->AddVertex( aNodesArray( i ), theColor ); - anArray->SetVertexNormal( i, 0, 0, 1 ); - } - - Standard_Integer anIndexTriangle[3] = { 0, 0, 0 }; - for( i = aTrianglesArray.Lower(); i<= aTrianglesArray.Upper(); i++ ) - { - aTrianglesArray( i ).Get( anIndexTriangle[0], anIndexTriangle[1], anIndexTriangle[2] ); - anArray->AddEdge( anIndexTriangle[0] ); - anArray->AddEdge( anIndexTriangle[1] ); - anArray->AddEdge( anIndexTriangle[2] ); - } - aGroup->AddPrimitiveArray( anArray ); - //aGroup->SetGroupPrimitivesAspect( anAspect ); -} - void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode ) { - if( myLCMap.IsNull() ) - return; - thePresentation->Clear(); - const double aLinearDeflection = 1E-2; - BRepMesh_IncrementalMesh aMesh( myLCMap->GetShape(), aLinearDeflection ); - aMesh.Perform(); - bool isOK = aMesh.IsDone(); + + Quantity_Color anEdgeColor = Quantity_NOC_WHITE; + + myDrawer->UIsoAspect()->SetNumber( 0 ); + myDrawer->VIsoAspect()->SetNumber( 0 ); + myDrawer->LineAspect()->SetColor( anEdgeColor ); + myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor ); + myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor ); switch( theMode ) { + case AIS_WireFrame: case AIS_Shaded: - { - HYDROData_LandCoverMap::Iterator anIt( myLCMap ); - for( ; anIt.More(); anIt.Next() ) - { - TopoDS_Face aFace = anIt.Face(); - QString aStricklerType = anIt.StricklerType(); - Quantity_Color aColor = GetColor( aStricklerType ); - - TopLoc_Location aLocation; - Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation( aFace, aLocation ); - DrawTriangulation( thePresentation, aTriangulation, aColor ); - } - } - break; - default: + AIS_ColoredShape::Compute( thePresentationManager, thePresentation, theMode ); break; } -} - -void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, - const Standard_Integer theMode ) -{ - if( myLCMap.IsNull() ) - return; - if( theMode==0 ) - { - /*theSelection->Clear(); - Bnd_Box B = BoundingBox(); - Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this ); - Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B ); - theSelection->Add( aSensitiveBox );*/ - } - else - { - //TODO - } + if( theMode==AIS_Shaded ) + StdPrs_WFDeflectionShape::Add( thePresentation, Shape(), myDrawer ); } + diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h index 7a930bc0..0e9888a1 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h @@ -21,12 +21,12 @@ #include #include -#include +#include #include -DEFINE_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject ) +DEFINE_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) -class HYDROGUI_LandCoverMapPrs : public AIS_InteractiveObject +class HYDROGUI_LandCoverMapPrs : public AIS_ColoredShape { public: DEFINE_STANDARD_RTTI( HYDROGUI_LandCoverMapPrs ); @@ -47,11 +47,11 @@ public: const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode ); - virtual void ComputeSelection( const Handle(SelectMgr_Selection)& theSelection, - const Standard_Integer theMode ); - Quantity_Color GetColor( const QString& theStricklerType ) const; +protected: + void UpdateColors(); + private: Handle(HYDROData_LandCoverMap) myLCMap; Handle(Aspect_ColorScale) myColorScale; diff --git a/src/HYDRO_tests/Basics_OCCTVersion.hxx b/src/HYDRO_tests/Basics_OCCTVersion.hxx new file mode 100644 index 00000000..2f9b4942 --- /dev/null +++ b/src/HYDRO_tests/Basics_OCCTVersion.hxx @@ -0,0 +1,51 @@ +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : Basics_OCCTVersion.hxx +// Author : Julia DOROVSKIKH, Open CASCADE S.A.S (julia.dorovskikh@opencascade.com) + +#ifndef BASICS_OCCTVERSION_HXX +#define BASICS_OCCTVERSION_HXX + +#include + +// +// NOTE: Since version 6.7.0 OCC_VERSION_DEVELOPMENT macro in the Standard_Version.hxx +// points to the development status of the OCCT version: for example "dev", "alpha", +// "beta", "rc1", etc. +// OCC_VERSION_MAJOR, OCC_VERSION_MINOR and OCC_VERSION_MAINTENANCE macros +// specify actual (final) version number; for development version it is a future +// target version number (i.e. version number is incremented immediately after +// releasing of the stable version). +// + +#ifdef OCC_VERSION_SERVICEPACK +# define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8 | OCC_VERSION_SERVICEPACK) +#else +# ifdef OCC_VERSION_DEVELOPMENT +# define OCC_VERSION_LARGE ((OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8)-1) +# else +# define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8) +# endif +#endif + +#endif // BASICS_OCCTVERSION_HXX diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 45e7f12b..a12b8191 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -61,7 +61,7 @@ IF( ${WIN32} ) ELSE() link_directories( $ENV{CAS_ROOT_DIR}/lib ) ENDIF() -SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO TKV3d TKService ) +SET( CAS_LIBRARIES TKernel TKLCAF TKCAF TKCDF TKMath TKG2d TKG3d TKBRep TKGeomBase TKTopAlgo TKGeomAlgo TKBool TKShHealing TKXSBase TKOffset TKHLR TKBO TKV3d TKService TKMesh ) link_directories( $ENV{QT4_ROOT_DIR}/lib ) IF( ${WIN32} ) diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 02516f51..6cf7242f 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef WIN32 #pragma warning ( disable: 4251 ) #endif @@ -16,6 +17,7 @@ #endif #include #include +#include #include #include @@ -76,11 +78,13 @@ QColor randomColor() } void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject, - int theMode, int theSelectionMode, bool isFitAll ) + int theMode, int theSelectionMode, bool isFitAll, const char* theKey ) { context()->EraseAll( Standard_False ); context()->Display( theObject, theMode, theSelectionMode ); + myKey = theKey; + if( isFitAll ) { viewWindow()->onTopView(); @@ -177,3 +181,36 @@ bool TestViewer::AssertImages( QString& theMessage ) return false; } + +Handle_Aspect_ColorScale TestViewer::showColorScale() +{ + Handle(V3d_View) aView = myViewWindow->getViewPort()->getView(); + if( aView.IsNull() ) + return Handle(Aspect_ColorScale)(); + + Handle(Aspect_ColorScale) aColorScale = aView->ColorScale(); + if( aColorScale.IsNull() ) + return aColorScale; + + Standard_Real anXPos = 0.05; //TODO + Standard_Real anYPos = 0.1; //TODO + Standard_Real aWidth = 0.2; //TODO + Standard_Real aHeight = 0.5; //TODO + Standard_Integer aTextHeight = 14; //TODO + Standard_Integer aNbIntervals = 30; //TODO + + aColorScale->SetXPosition( anXPos ); + aColorScale->SetYPosition( anYPos ); + aColorScale->SetWidth( aWidth ); + aColorScale->SetHeight( aHeight ); + aColorScale->SetTextHeight( aTextHeight ); + aColorScale->SetNumberOfIntervals( aNbIntervals ); + + aColorScale->SetTitle( "test" ); + aColorScale->SetRange( 0, 1 ); + + if( !aView->ColorScaleIsDisplayed() ) + aView->ColorScaleDisplay(); + + return aColorScale; +} diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index a27a8c7d..73e50b59 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -8,6 +8,7 @@ class TopoDS_Shape; class QString; class QColor; class Handle_AIS_InteractiveObject; +class Handle_Aspect_ColorScale; class TestViewer { @@ -17,11 +18,13 @@ public: static OCCViewer_ViewWindow* viewWindow(); static void show( const Handle_AIS_InteractiveObject& theObject, - int theMode, int theSelelctionMode, bool isFitAll ); + int theMode, int theSelelctionMode, 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 Handle_Aspect_ColorScale showColorScale(); + private: static OCCViewer_ViewManager* myViewManager; static OCCViewer_ViewWindow* myViewWindow; diff --git a/src/HYDRO_tests/reference_data/LandCoverMap_PrsByCoeff.png b/src/HYDRO_tests/reference_data/LandCoverMap_PrsByCoeff.png new file mode 100644 index 00000000..e49f0768 Binary files /dev/null and b/src/HYDRO_tests/reference_data/LandCoverMap_PrsByCoeff.png differ diff --git a/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png b/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png new file mode 100644 index 00000000..18d7f51a Binary files /dev/null and b/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png differ diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index fa0952cf..e05a4cd2 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -449,7 +450,7 @@ void test_HYDROData_LandCoverMap::test_merge_faces_circles() } } -void test_HYDROData_LandCoverMap::test_land_cover_prs() +void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); @@ -475,7 +476,41 @@ void test_HYDROData_LandCoverMap::test_land_cover_prs() Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap ); aPrs->SetTable( aTable ); - TestViewer::show( aPrs, AIS_Shaded, 1, true ); + TestViewer::show( aPrs, AIS_Shaded, 1, true, "LandCoverMap_PrsByTypes" ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} + +void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_StricklerTable) aTable = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) ); + + Handle(HYDROData_LandCoverMap) aMap = + Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) ); + + TopoDS_Face aLC1 = LandCover( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) ); + + TopoDS_Face aLC2 = LandCover( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << + 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << + 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << + 31 << 114 ); + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) ); + + TopoDS_Face aLC3 = LandCover( QList() << 4 << 54 << 1 << 47 << 51 << 45 << + 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) ); + + Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap ); + aPrs->SetTable( aTable ); + aPrs->SetColorScale( TestViewer::showColorScale() ); + TestViewer::show( aPrs, AIS_Shaded, 1, true, "LandCoverMap_PrsByCoeff" ); + CPPUNIT_ASSERT_IMAGES aDoc->Close(); } diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h index bf28ae68..cbe08770 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h @@ -32,7 +32,8 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture CPPUNIT_TEST( test_remove ); CPPUNIT_TEST( test_merge_faces_boxes ); CPPUNIT_TEST( test_merge_faces_circles ); - CPPUNIT_TEST( test_land_cover_prs ); + CPPUNIT_TEST( test_land_cover_prs_by_types ); + CPPUNIT_TEST( test_land_cover_prs_by_coeff ); CPPUNIT_TEST_SUITE_END(); public: @@ -43,7 +44,8 @@ public: void test_remove(); void test_merge_faces_boxes(); void test_merge_faces_circles(); - void test_land_cover_prs(); + void test_land_cover_prs_by_types(); + void test_land_cover_prs_by_coeff(); }; CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );