#include <TopoDS_Face.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Shell.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <QString>
IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
-class HYDROData_MapOfShapeToStricklerType : public NCollection_IndexedDataMap<TopoDS_Shape, QString>
+class HYDROData_MapOfFaceToStricklerType : public NCollection_IndexedDataMap<TopoDS_Face, QString>
{
};
*/
void HYDROData_LandCoverMap::Iterator::Init( const HYDROData_LandCoverMap& theMap )
{
- myIterator = new TopoDS_Iterator( theMap.GetShape() );
+ TopoDS_Shape aShape = theMap.GetShape();
+ if( aShape.IsNull() )
+ myIterator = 0;
+ else
+ myIterator = new TopoDS_Iterator( aShape );
myIndex = 0;
theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
}
*/
bool HYDROData_LandCoverMap::Iterator::More() const
{
- return !myArray.IsNull() && myIterator->More();
+ return !myArray.IsNull() && myIterator && myIterator->More();
}
/**
*/
void HYDROData_LandCoverMap::Iterator::Next()
{
- myIterator->Next();
+ if( myIterator )
+ myIterator->Next();
}
/**
*/
TopoDS_Face HYDROData_LandCoverMap::Iterator::Face() const
{
- return TopoDS::Face( myIterator->Value() );
+ if( myIterator )
+ return TopoDS::Face( myIterator->Value() );
+ else
+ return TopoDS_Face();
}
/**
*/
bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
{
+ if( theNewShape.IsNull() )
+ return false;
+
BOPCol_ListOfShape aShapesList;
BOPAlgo_PaveFiller aPaveFiller;
+ HYDROData_MapOfFaceToStricklerType aNewFaces;
// add faces to shapes list
Iterator anIt( *this );
aShapesList.Append( anIt.Face() );
aShapesList.Append( theNewShape );
+ if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
+ {
+ aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
+ StoreLandCovers( aNewFaces );
+ return true;
+ }
+
// prepare pave filler
aPaveFiller.SetArguments( aShapesList );
aPaveFiller.Perform();
return false;
// analysis of the history
- BOPCol_DataMapOfShapeListOfShape aSplits = aBuilder.Splits();
+ // a. to fill map of shapes which come from the new face
+ NCollection_IndexedMap<TopoDS_Shape> aShapesFromNewFace;
+ //std::cout << "new: " << theNewShape << " " << theNewType << std::endl;
+ TopTools_ListOfShape aModified = aBuilder.Modified( theNewShape );
+ TopTools_ListIteratorOfListOfShape aMIt( aModified );
+ for( ; aMIt.More(); aMIt.Next() )
+ {
+ //std::cout << " " << aMIt.Value() << std::endl;
+ aShapesFromNewFace.Add( aMIt.Value() );
+ }
- // a. fill map of shape => type for initial faces
- HYDROData_MapOfShapeToStricklerType anOldFaces;
+ // b. to fill map of parts except parts from new face
anIt.Init( *this );
for( ; anIt.More(); anIt.Next() )
- anOldFaces.Add( anIt.Face(), anIt.StricklerType() );
-
- // b. fill map of shape => type for split faces without the new face
- HYDROData_MapOfShapeToStricklerType aNewFaces;
- BOPCol_DataMapOfShapeListOfShape::Iterator aSplitIt( aSplits );
- for( ; aSplitIt.More(); aSplitIt.Next() )
{
- TopoDS_Shape anInitial = aSplitIt.Key();
- if( anInitial==theNewShape )
- continue;
- QString aType = anOldFaces.FindFromKey( anInitial );
- BOPCol_ListOfShape aSplitFaces = aSplitIt.Value();
- BOPCol_ListOfShape::Iterator aSFIt( aSplitFaces );
- for( ; aSFIt.More(); aSFIt.Next() )
- aNewFaces.Add( aSFIt.Value(), aType );
+ QString aSType = anIt.StricklerType();
+ //std::cout << anIt.Face() << " " << anIt.StricklerType() << std::endl;
+ TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
+ TopTools_ListIteratorOfListOfShape aMIt( aModified );
+ for( ; aMIt.More(); aMIt.Next() )
+ {
+ TopoDS_Shape aShape = aMIt.Value();
+ bool isFace = aShape.ShapeType()==TopAbs_FACE;
+ bool isAlsoFromNew = aShapesFromNewFace.Contains( aShape );
+ //std::cout << " " << aShape << " " << isAlsoFromNew << std::endl;
+ if( isFace && !isAlsoFromNew )
+ aNewFaces.Add( TopoDS::Face( aShape ), aSType );
+ }
}
// c. add the new shape if it is face with its type
if( theNewShape.ShapeType()==TopAbs_FACE )
- aNewFaces.Add( theNewShape, theNewType );
+ aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
// convert map of shape to type to compound and list of types
StoreLandCovers( aNewFaces );
Replace the set of land covers in the land cover map
@param theMap the map of shape (face) to Strickler type (string)
*/
-void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfShapeToStricklerType& theMap )
+void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& theMap )
{
TopoDS_Compound aCompound;
BRep_Builder aCompoundBuilder;
int n = theMap.Size();
Handle( TDataStd_ExtStringArray ) aTypes =
TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
- HYDROData_MapOfShapeToStricklerType::Iterator aNFIt( theMap );
+ HYDROData_MapOfFaceToStricklerType::Iterator aNFIt( theMap );
for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
{
aCompoundBuilder.Add( aCompound, aNFIt.Key() );
class TopTools_ListOfShape;
class Handle( HYDROData_Polyline );
class Handle( HYDROData_Object );
-class HYDROData_MapOfShapeToStricklerType;
+class HYDROData_MapOfFaceToStricklerType;
class HYDROData_LandCoverMap : public HYDROData_Entity
{
void SetShape( const TopoDS_Shape& );
bool LocalPartition( const TopoDS_Shape&, const QString& theNewType );
- void StoreLandCovers( const HYDROData_MapOfShapeToStricklerType& );
+ void StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& );
public:
DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );
private:
friend class Iterator;
+ friend class test_HYDROData_LandCoverMap;
};
#endif
#include <OCCViewer_ViewWindow.h>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
+#include <TopoDS_Iterator.hxx>
#include <QDir>
OCCViewer_ViewManager* TestViewer::myViewManager = 0;
return TestViewer::viewer()->getAISContext();
}
-void TestViewer::show( const TopoDS_Shape& theShape, bool isFitAll )
+void TestViewer::show( const TopoDS_Shape& theShape, const QColor& theColor, int theMode )
{
- context()->EraseAll();
+ QColor aColor = theColor;
+ if( !aColor.isValid() )
+ {
+ // random color
+ int aHue = rand()%255;
+ aColor = QColor::fromHsl( aHue, 255, 128 );
+ }
+
+ double r = aColor.red() / 255.0;
+ double g = aColor.green() / 255.0;
+ double b = aColor.blue() / 255.0;
+
Handle(AIS_Shape) aShape = new AIS_Shape( theShape );
- context()->Display( aShape, AIS_Shaded, 0, Standard_False );
+ aShape->SetMaterial( Graphic3d_NOM_PLASTIC );
+ aShape->SetColor( Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
+ context()->Display( aShape, theMode, 0, Standard_False );
+}
+
+void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll )
+{
+ context()->EraseAll();
+
+ if( theShape.ShapeType()==TopAbs_COMPOUND )
+ {
+ TopoDS_Iterator anIt( theShape );
+ for( ; anIt.More(); anIt.Next() )
+ show( anIt.Value(), QColor(), theMode );
+ }
+ else
+ show( theShape, QColor(), theMode );
viewWindow()->onTopView();
viewWindow()->onFitAll();
}
-void TestViewer::dump( const TopoDS_Shape& theShape, const QString& theName )
+void TestViewer::dump( const TopoDS_Shape& theShape, int theMode, const QString& theName )
{
- show( theShape );
+ show( theShape, theMode, true );
QImage anImage = viewWindow()->dumpView();
QString aPath = QDir::tempPath() + "/" + theName + ".png";
class OCCViewer_ViewWindow;
class TopoDS_Shape;
class QString;
+class QColor;
class TestViewer
{
static OCCViewer_Viewer* viewer();
static OCCViewer_ViewWindow* viewWindow();
- static void show( const TopoDS_Shape& theShape, bool isFitAll = true );
- static void dump( const TopoDS_Shape& theShape, const QString& theName );
+ static void show( const TopoDS_Shape& theShape, const QColor& theColor, int theMode );
+ static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll = true );
+ static void dump( const TopoDS_Shape& theShape, int theMode, const QString& theName );
private:
static OCCViewer_ViewManager* myViewManager;
#include <HYDROData_Document.h>
#include <HYDROData_LandCoverMap.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 <AIS_DisplayMode.hxx>
+#include <QString>
-TopoDS_Edge Spline( bool isClosed, double x, double y, ... )
+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();
}
+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_local_partition()
{
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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 );
aDoc->Close();
}