Salome HOME
test Strickler
[modules/hydro.git] / src / HYDROData / HYDROData_LCM_FaceClassifier.cxx
index faf7678ff23cec6c5e38216e84c1be623b092255..adfa27e3ed1c03fc99b3385bff2abd1c80e8232a 100644 (file)
 #include <BRepTopAdaptor_FClass2d.hxx>
 #include <TopoDS.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
-
+#include <Geom_Plane.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Surface.hxx>
+#include <ElSLib.hxx>
 
 Standard_Boolean HYDROData_FaceClassifier_BndBoxTreeSelector::Accept (const Standard_Integer& theObj)
 {
@@ -37,9 +40,12 @@ Standard_Boolean HYDROData_FaceClassifier_BndBoxTreeSelector::Accept (const Stan
   if(f.IsNull()) 
     return Standard_False;
 
-  BRepTopAdaptor_FClass2d* class2d = myMapF2Class2d.FindFromKey(f);
+  BRepTopAdaptor_FClass2d* class2d = myMapF2Class2d.FindFromKey(f);  
 
-  TopAbs_State aState = class2d->Perform( myP, Standard_False );
+  Handle(Geom_Plane) Pl = HYDROData_LCM_FaceClassifier::GetPlane(f);
+  Standard_Real u, v;
+  ElSLib::Parameters(Pl->Pln(), gp_Pnt(myP.X(), myP.Y(), 0.0), u, v);
+  TopAbs_State aState = class2d->Perform( gp_Pnt2d(u, v), Standard_False );
 
   if (aState == TopAbs_IN)
   {
@@ -57,7 +63,15 @@ Standard_Boolean HYDROData_FaceClassifier_BndBoxTreeSelector::Accept (const Stan
 
 }
 
-void HYDROData_LCM_FaceClassifier::Classify( const std::vector<gp_Pnt2d>& thePoints, 
+Handle(Geom_Plane) HYDROData_LCM_FaceClassifier::GetPlane(const TopoDS_Face& F)
+{
+  TopLoc_Location L;
+  Handle(Geom_Surface) S = BRep_Tool::Surface(F, L);
+  Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(S->Transformed(L.Transformation()));
+  return Pl;
+}
+
+void HYDROData_LCM_FaceClassifier::Classify( const std::vector<gp_XY>& thePoints, 
                                              std::vector<std::set <QString> >& theTypes,
                                              std::vector<NCollection_Map<TopoDS_Face> >* theFaces) const
 {
@@ -84,8 +98,25 @@ void HYDROData_LCM_FaceClassifier::Classify( const std::vector<gp_Pnt2d>& thePoi
     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 );
+
+    //convert 2d space of planar face to the 3d space of given points 
+    //this is more faster way then getting of bnd3d of faces and project them on plane...
+    Handle(Geom_Plane) Pl = HYDROData_LCM_FaceClassifier::GetPlane(F);
+    gp_Trsf RT;
+    RT.SetTransformation(Pl->Position());
+    RT.Invert();
+    double xmin, ymin, xmax, ymax; 
+    B.Get(xmin, ymin, xmax, ymax);
+    gp_Pnt MinP(xmin, ymin, 0), MaxP(xmax, ymax, 0);
+    MinP.Transform(RT);
+    MaxP.Transform(RT);
+    gp_Pnt2d MinPT(MinP.X(), MinP.Y());
+    gp_Pnt2d MaxPT(MaxP.X(), MaxP.Y());
+    Bnd_Box2d NB;
+    NB.Update(MinPT.X(), MinPT.Y(), MaxPT.X(), MaxPT.Y() );
+
+    aTreeFiller.Add(i, NB);
+    BRepTopAdaptor_FClass2d* aClass2d = new BRepTopAdaptor_FClass2d( F, 1E-7 );
     aMapF2Class2d.Add(F, aClass2d);
     fclass2dpointers.push_back(aClass2d);
   }