#include <TestViewer.h>
-//#include <random.h>
+#include <HYDROData_Tool.h>
- #include <random.h>
#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewPort3d.h>
#ifdef WIN32
#pragma warning ( disable: 4251 )
#endif
return TestViewer::viewer()->getAISContext();
}
- QColor randomColor()
+ QColor TestViewer::GetColor(int i)
{
- int r = test_rand();
- int aHue = r%255;
- //std::cout << "hue: " << aHue << std::endl;
- QColor aColor = QColor::fromHsl( aHue, 255, 128 );
- return aColor;
+ QVector<QColor> aCV;
+ aCV << QColor(0,0,255)
+ << QColor(0,255,0)
+ << QColor(255,0,0)
+ << QColor(255,255,20)
+ << QColor(20,255,255)
+ << QColor(100,100,20)
+ << QColor(10,100,150);
+ return aCV[i];
}
-void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor )
+void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject,
+ int theMode, int theSelectionMode, bool isFitAll, const char* theKey )
{
- double r = theColor.red() / 255.0;
- double g = theColor.green() / 255.0;
- double b = theColor.blue() / 255.0;
+ context()->EraseAll( Standard_False );
+ context()->Display( theObject, theMode, theSelectionMode );
+
+ myKey = theKey;
+ if( isFitAll )
+ {
+ viewWindow()->onTopView();
+ viewWindow()->onFitAll();
+ }
+}
+
+void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor )
+{
Handle(AIS_Shape) aShape = new AIS_Shape( theShape );
aShape->SetMaterial( Graphic3d_NOM_PLASTIC );
- aShape->SetColor( Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
+ aShape->SetColor( HYDROData_Tool::toOccColor( theColor ) );
context()->Display( aShape, theMode, 0, Standard_False );
if( isFitAll )
void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey )
{
- context()->EraseAll();
+ context()->EraseAll( Standard_False );
myKey = theKey;
- test_srand( 0 );
- if( theShape.ShapeType()==TopAbs_COMPOUND )
+ int i = 0;
+ if( theShape.ShapeType()==TopAbs_SHELL )
{
TopoDS_Iterator anIt( theShape );
- for( ; anIt.More(); anIt.Next() )
- show( anIt.Value(), theMode, false, randomColor() );
+ for( ; anIt.More(); anIt.Next(), i++ )
+ show( anIt.Value(), theMode, false, GetColor(i) );
}
else
- show( theShape, theMode, false, randomColor() );
+ show( theShape, theMode, false, GetColor(0) );
if( isFitAll )
{
#include <TestViewer.h>
#include <TopTools_ListOfShape.hxx>
#include <AIS_DisplayMode.hxx>
+#include <Aspect_ColorScale.hxx>
#include <QString>
#include <QColor>
-
+ #include <QMap>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
CPPUNIT_ASSERT_IMAGES
CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
}
-}
+
+ }
+
+ void test_HYDROData_LandCoverMap::test_import_dbf()
+ {
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+ Handle(HYDROData_LandCoverMap) aMap =
+ Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+
+ CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
+ QString aFileName = REF_DATA_PATH + "/t1.dbf";
+ QStringList aDBFV;
+ QStringList aST;
+ aDBFV.append("100");
+ aDBFV.append("200");
+ aDBFV.append("300");
+ aST.append("water");
+ aST.append("forest");
+ aST.append("road");
+ // aST.size() == aDBFV.size()!!
+ Handle(HYDROData_PolylineXY) aPolyline =
+ Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+ TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire();
+ aPolyline->SetShape( aWire );
+ for (int i = 0; i < 3; i++)
+ aMap->Add(aPolyline, "");
+ TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+
+ CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
+ QMap<int, int> Inds;
+ Inds.insert(1, 1);
+ Inds.insert(2, 2);
+ Inds.insert(3, 3);
+ aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
+ HYDROData_LandCoverMap::Iterator anIt( aMap );
+
+ CPPUNIT_ASSERT_EQUAL(true, "water" == anIt.StricklerType());
+ anIt.Next();
+ CPPUNIT_ASSERT_EQUAL(true, "forest" == anIt.StricklerType());
+
+}
+
+void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()
+{
+ 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<double>() << 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<double>() << 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<double>() << 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 );
+ 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<double>() << 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<double>() << 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<double>() << 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();
+}
++