]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
classifier draft
authorisn <isn@opencascade.com>
Tue, 30 Aug 2016 17:05:36 +0000 (20:05 +0300)
committerisn <isn@opencascade.com>
Wed, 31 Aug 2016 08:57:16 +0000 (11:57 +0300)
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_LCM_FaceClassifier.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_LCM_FaceClassifier.h [new file with mode: 0644]
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h

index 52048bcc41bb0c903959a8dc7b2f6b2d5535ebef..86edacf83dfe9c2622c16467b8f4432798e678e6 100644 (file)
@@ -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 (file)
index 0000000..b801df7
--- /dev/null
@@ -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 <HYDROData_LandCoverMap.h>
+#include <Bnd_Box2d.hxx> 
+#include <BRepTools.hxx>
+#include <NCollection_UBTree.hxx>
+#include <NCollection_UBTreeFiller.hxx>
+#include <BRepTopAdaptor_FClass2d.hxx>
+#include <TopoDS.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+
+
+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<gp_Pnt2d>& thePoints, 
+                                             std::vector<std::set <QString> >& theTypes,
+                                             std::vector<NCollection_Map<TopoDS_Face> >* 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 <Standard_Integer, Bnd_Box2d> aTreeFiller (aTree);
+  NCollection_IndexedDataMap<TopoDS_Face, BRepTopAdaptor_FClass2d*> aMapF2Class2d;
+
+  int NbF= aFaces.Extent();
+  std::vector<BRepTopAdaptor_FClass2d*> 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<TopoDS_Face>& rf = aSelector.GetResFaces();
+      NCollection_List<TopoDS_Face>::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 (file)
index 0000000..6afd303
--- /dev/null
@@ -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 <HYDROData.h>
+#include <vector>
+#include <set>
+#include <QString>
+
+#include "Bnd_Box2d.hxx" 
+#include <NCollection_UBTree.hxx>
+#include <NCollection_List.hxx>
+#include <NCollection_IndexedDataMap.hxx>
+#include <TopoDS_Face.hxx>
+#include <NCollection_Map.hxx>
+
+class BRepTopAdaptor_FClass2d;
+class HYDROData_LandCoverMap;
+
+typedef NCollection_UBTree <Standard_Integer, Bnd_Box2d> HYDROData_FaceClassifier_BndBoxTree;
+
+class HYDROData_FaceClassifier_BndBoxTreeSelector : public HYDROData_FaceClassifier_BndBoxTree::Selector
+{
+public:
+  HYDROData_FaceClassifier_BndBoxTreeSelector(const NCollection_IndexedDataMap<TopoDS_Face, BRepTopAdaptor_FClass2d*>& 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<TopoDS_Face>& 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<TopoDS_Face, BRepTopAdaptor_FClass2d*>& myMapF2Class2d;
+  gp_Pnt2d myP;
+  NCollection_List<TopoDS_Face> 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<gp_Pnt2d>& thePoints, 
+    std::vector<std::set <QString> >& theTypes, 
+    std::vector<NCollection_Map <TopoDS_Face> >* theFaces) const;
+
+
+private:
+  const HYDROData_LandCoverMap* const myLCM;
+
+};
+
+
+#endif
index 4ad735022b32330c1219f570afdd3ff2d35b437f..7afb3132cdb25b1224543faf1a4c08cd5adc8872 100644 (file)
@@ -61,6 +61,7 @@
 #include <Geom_TrimmedCurve.hxx>
 #include <TopTools_DataMapOfShapeListOfShape.hxx>
 #include <NCollection_DoubleMap.hxx>
+#include <HYDROData_LCM_FaceClassifier.h>
 
 #include <stdexcept>
 
@@ -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<gp_Pnt2d>& thePoints, std::vector<std::set <QString> >& theTypes ) const
+{
+  HYDROData_LCM_FaceClassifier FC(this);
+  FC.Classify(thePoints, theTypes, NULL);
+}
index 6827d52a0924f46d58d9a61e6e34a5cedc3f7579..43c074ba183ce89522b36b0d440385079b1c01fd 100644 (file)
@@ -25,6 +25,8 @@
 #include <QString>
 #include <TopoDS_Face.hxx>
 #include <TopExp_Explorer.hxx>
+#include <vector>
+#include <set>
 
 class Handle_HYDROData_StricklerTable;
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
@@ -148,6 +150,8 @@ public:
 
   HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
 
+  HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_Pnt2d>& thePoints, std::vector<std::set <QString> >& theTypes ) const;
+
 protected:
   void SetShape( const TopoDS_Shape& );