From 591a7ad01db542058bd2cb75be3617bb9c3dfa29 Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 30 Aug 2016 20:05:36 +0300 Subject: [PATCH] classifier draft --- src/HYDROData/CMakeLists.txt | 4 + .../HYDROData_LCM_FaceClassifier.cxx | 127 ++++++++++++++++++ src/HYDROData/HYDROData_LCM_FaceClassifier.h | 103 ++++++++++++++ src/HYDROData/HYDROData_LandCoverMap.cxx | 7 + src/HYDROData/HYDROData_LandCoverMap.h | 4 + 5 files changed, 245 insertions(+) create mode 100644 src/HYDROData/HYDROData_LCM_FaceClassifier.cxx create mode 100644 src/HYDROData/HYDROData_LCM_FaceClassifier.h diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 52048bcc..86edacf8 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -62,6 +62,8 @@ set(PROJECT_HEADERS HYDROData_SinusX.h HYDROData_ShapeFile.h HYDROData_LandCoverMap.h + HYDROData_LCM_FaceClassifier.h + ) set(PROJECT_SOURCES @@ -122,6 +124,8 @@ set(PROJECT_SOURCES HYDROData_SinusX.cxx HYDROData_ShapeFile.cxx HYDROData_LandCoverMap.cxx + HYDROData_LCM_FaceClassifier.cxx + ) add_definitions( diff --git a/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx b/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx new file mode 100644 index 00000000..b801df77 --- /dev/null +++ b/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx @@ -0,0 +1,127 @@ +// Copyright (C) 2014-2015 EDF-R&D +// 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 +// + +#include "HYDROData_LCM_FaceClassifier.h" + +#include +#include +#include +#include +#include +#include +#include +#include + + +Standard_Boolean HYDROData_FaceClassifier_BndBoxTreeSelector::Accept (const Standard_Integer& theObj) +{ + if (theObj > myMapF2Class2d.Extent()) + return Standard_False; + + const TopoDS_Face& f = TopoDS::Face(myMapF2Class2d.FindKey(theObj)); + if(f.IsNull()) + return Standard_False; + + BRepTopAdaptor_FClass2d* class2d = myMapF2Class2d.FindFromKey(f); + + TopAbs_State aState = class2d->Perform( myP, Standard_False ); + + if (aState == TopAbs_IN) + { + myResFaces.Append(f); + myStop = 1; //no more faces includes this point; quit + return Standard_True; + } + else if (aState == TopAbs_ON) + { + myResFaces.Append(f); + return Standard_True; + } + + return Standard_False; + +} + +void HYDROData_LCM_FaceClassifier::Classify( const std::vector& thePoints, + std::vector >& theTypes, + std::vector >* theFaces) const +{ + HYDROData_LandCoverMap::Explorer anIt( *myLCM ); + HYDROData_MapOfFaceToStricklerType aMapF2ST; + TopTools_IndexedMapOfShape aFaces; + for( ; anIt.More(); anIt.Next() ) + { + const TopoDS_Face& F = anIt.Face(); + aMapF2ST.Add(F, anIt.StricklerType()); + aFaces.Add(F); + } + + HYDROData_FaceClassifier_BndBoxTree aTree; + NCollection_UBTreeFiller aTreeFiller (aTree); + NCollection_IndexedDataMap aMapF2Class2d; + + int NbF= aFaces.Extent(); + std::vector fclass2dpointers; + fclass2dpointers.reserve(NbF); + + for (int i = 1; i < NbF; i++) + { + Bnd_Box2d B; + const TopoDS_Face& F = TopoDS::Face(aFaces(i)); + BRepTools::AddUVBounds(F, B); + aTreeFiller.Add(i, B); + BRepTopAdaptor_FClass2d* aClass2d = new BRepTopAdaptor_FClass2d( F, 0 ); + aMapF2Class2d.Add(F, aClass2d); + fclass2dpointers.push_back(aClass2d); + } + + aTreeFiller.Fill(); + + size_t pntsize = thePoints.size(); + theTypes.resize(pntsize); + if (theFaces) + theFaces->resize(pntsize); + + Standard_Integer aSel = 0; + for (size_t i = 0; i < pntsize; i++ ) + { + HYDROData_FaceClassifier_BndBoxTreeSelector aSelector(aMapF2Class2d); + const gp_Pnt2d& pnt2d = thePoints[i]; + aSelector.SetCurrentPoint(pnt2d); + aSel = aTree.Select(aSelector); + if (aSel > 0) + { + const NCollection_List& rf = aSelector.GetResFaces(); + NCollection_List::Iterator it(rf); + for (;it.More();it.Next()) + { + const TopoDS_Face& f = it.Value(); + QString aST = aMapF2ST.FindFromKey(f); + theTypes[i].insert(aST); + if (theFaces) + (*theFaces)[i].Add(f); + } + } + } + + for (size_t i = 0; i < fclass2dpointers.size(); i++) + delete fclass2dpointers[i]; + +} + + diff --git a/src/HYDROData/HYDROData_LCM_FaceClassifier.h b/src/HYDROData/HYDROData_LCM_FaceClassifier.h new file mode 100644 index 00000000..6afd303d --- /dev/null +++ b/src/HYDROData/HYDROData_LCM_FaceClassifier.h @@ -0,0 +1,103 @@ +// Copyright (C) 2014-2015 EDF-R&D +// 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 +// + +#ifndef HYDRODATA_LCM_FACECLASSIFIER_H +#define HYDRODATA_LCM_FACECLASSIFIER_H + +#include +#include +#include +#include + +#include "Bnd_Box2d.hxx" +#include +#include +#include +#include +#include + +class BRepTopAdaptor_FClass2d; +class HYDROData_LandCoverMap; + +typedef NCollection_UBTree HYDROData_FaceClassifier_BndBoxTree; + +class HYDROData_FaceClassifier_BndBoxTreeSelector : public HYDROData_FaceClassifier_BndBoxTree::Selector +{ +public: + HYDROData_FaceClassifier_BndBoxTreeSelector(const NCollection_IndexedDataMap& theMapOfShape) + : HYDROData_FaceClassifier_BndBoxTreeSelector::Selector(), myMapF2Class2d (theMapOfShape) + {} + + Standard_Boolean Reject (const Bnd_Box2d& theBox) const + { + return (theBox.IsOut (myP)); + } + + Standard_Boolean Accept (const Standard_Integer& theObj); + + const NCollection_List& GetResFaces () const + { + return myResFaces; + } + + const TopoDS_Face& GetFirstFace() const + { + if (!myResFaces.IsEmpty()) + return myResFaces.First(); + else + TopoDS_Face(); + } + + void SetCurrentPoint (const gp_Pnt2d& theP) + { + myP = theP; + } + +private: + HYDROData_FaceClassifier_BndBoxTreeSelector(const HYDROData_FaceClassifier_BndBoxTreeSelector& ); + HYDROData_FaceClassifier_BndBoxTreeSelector& operator=(const HYDROData_FaceClassifier_BndBoxTreeSelector& ); + +private: + const NCollection_IndexedDataMap& myMapF2Class2d; + gp_Pnt2d myP; + NCollection_List myResFaces; +}; + +class HYDRODATA_EXPORT HYDROData_LCM_FaceClassifier +{ + +public: + + HYDROData_LCM_FaceClassifier(const HYDROData_LandCoverMap* const theLCM) : myLCM(theLCM) + {}; + + ~HYDROData_LCM_FaceClassifier() + {}; + + void Classify( const std::vector& thePoints, + std::vector >& theTypes, + std::vector >* theFaces) const; + + +private: + const HYDROData_LandCoverMap* const myLCM; + +}; + + +#endif diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 4ad73502..7afb3132 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -61,6 +61,7 @@ #include #include #include +#include #include @@ -1257,3 +1258,9 @@ void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy ) TopoDS_Shape aLocatedShape = HYDROData_ShapesTool::Translated( aShape, theDx, theDy, 0 ); SetShape( aLocatedShape ); } + +void HYDROData_LandCoverMap::ClassifyPoints( const std::vector& thePoints, std::vector >& theTypes ) const +{ + HYDROData_LCM_FaceClassifier FC(this); + FC.Classify(thePoints, theTypes, NULL); +} diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 6827d52a..43c074ba 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include class Handle_HYDROData_StricklerTable; #include @@ -148,6 +150,8 @@ public: HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy ); + HYDRODATA_EXPORT void ClassifyPoints( const std::vector& thePoints, std::vector >& theTypes ) const; + protected: void SetShape( const TopoDS_Shape& ); -- 2.39.2