#include <test_HYDROData_LandCoverMap.h>
#include <HYDROData_Document.h>
#include <HYDROData_LandCoverMap.h>
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_Tool.h>
#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
-#include <stdarg.h>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <TestViewer.h>
+#include <TopTools_ListOfShape.hxx>
+#include <AIS_DisplayMode.hxx>
+#include <QString>
+#include <QColor>
-TopoDS_Edge Spline( bool isClosed, double x, double y, ... )
+#include <BRepTools.hxx>
+
+TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
{
- va_list anArgs;
- va_start( anArgs, y );
- QList<gp_Pnt> aPointsList;
- while( true )
+ int n = theXYList.size()/2;
+ Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
+ for( int i=1; i<=n; i++ )
{
- double x = va_arg( anArgs, double );
- if( x <= 0 )
- break;
- double y = va_arg( anArgs, double );
+ double x = theXYList[2*i-2];
+ double y = theXYList[2*i-1];
gp_Pnt aPnt( x, y, 0 );
- aPointsList.append( aPnt );
+ aPointsArray->SetValue( i, aPnt );
}
- va_end( anArgs );
-
- int n = aPointsList.size();
- Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
- for( int i=1; i<=n; i++ )
- aPointsArray->SetValue( i, aPointsList[i-1] );
-
GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
anInterpolator.Perform();
bool aResult = anInterpolator.IsDone() == Standard_True;
return TopoDS_Edge();
}
-void test_HYDROData_LandCoverMap::test_local_partition()
+TopoDS_Face LandCover( const QList<double>& theXYList )
+{
+ TopoDS_Edge anEdge = Spline( theXYList, true );
+ if( anEdge.IsNull() )
+ return TopoDS_Face();
+
+ TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
+ TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face();
+ return aFace;
+}
+
+void test_HYDROData_LandCoverMap::test_add_2_objects()
+{
+ 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() );
+
+ TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+
+ TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
+
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ TestViewer::AssertEqual( "LandCoverMap_Add_2_Objects" );
+
+ HYDROData_LandCoverMap::Iterator anIt( aMap );
+ CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
+ CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
+ anIt.Next();
+ CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
+ CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
+ anIt.Next();
+ CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
+
+ aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_split()
+{
+ 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() );
+
+ TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
+
+ 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 );
+
+ CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
+
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ TestViewer::show( aWire, QColor(), 0 );
+ TestViewer::AssertEqual( "LandCoverMap_Split_1" );
+
+ HYDROData_LandCoverMap::Iterator anIt( aMap );
+ CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
+ CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
+ anIt.Next();
+ CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
+ CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
+ anIt.Next();
+ CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
+
+ aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_incomplete_split()
+{
+ 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() );
+
+ TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
+
+ 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 ) ).Wire();
+ aPolyline->SetShape( aWire );
+
+ CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
+
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ TestViewer::show( aWire, QColor(), 0 );
+ TestViewer::AssertEqual( "LandCoverMap_Split_2" );
+
+ HYDROData_LandCoverMap::Iterator anIt( aMap );
+ CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
+ CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
+ anIt.Next();
+ CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
+
+ aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_merge()
{
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
+ TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
+
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+
+ 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, "test2" ) );
+ 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, "test3" ) );
+
+ //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
+
+ //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
+
+ QString aType1, aType2;
+ gp_Pnt2d aPnt1( 25, 35 );
+ gp_Pnt2d aPnt2( 45, 55 );
+ //gp_Pnt2d aPnt3( 45, 10 );
+ //gp_Pnt2d aPnt4( 45, 80 );
+ TopTools_ListOfShape aList;
+ aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
+ aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
+
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
+ TestViewer::AssertEqual( "LandCoverMap_Merge_1" );
aDoc->Close();
}
+void test_HYDROData_LandCoverMap::test_remove()
+{
+ 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() );
+
+ TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
+
+ CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+
+ 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, "test2" ) );
+
+ 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, "test3" ) );
+
+ QString aType1, aType2;
+ gp_Pnt2d aPnt1( 25, 35 );
+ gp_Pnt2d aPnt2( 45, 55 );
+ TopTools_ListOfShape aList;
+ aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
+ aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
+ CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
+
+ TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+ TestViewer::AssertEqual( "LandCoverMap_Remove_1" );
+
+ aDoc->Close();
+}