Salome HOME
0021514: EDF GEOM: Partition failure. A fix by PKV.
[modules/geom.git] / src / VTKExport / VTKExport.cxx
index 4d0f3ac7a618c3885c8e9f8740c9fe91cb90b29c..4b2f27b5cf78e9570d6dcc0004023357f2cd6e05 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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.
 //
-//  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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // File:        VTKExport.cxx
@@ -42,6 +42,9 @@
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
+#include <Poly_Triangulation.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepTools.hxx>
 
 #ifdef WIN32
 # if defined VTKEXPORT_EXPORTS || defined VTKExport_EXPORTS
@@ -85,12 +88,23 @@ extern "C"
       //myAppendFilter->AddInput( myWireframeFaceSource->GetOutput() ); // iso-lines are unnecessary
       myAppendFilter->AddInput( myShadingFaceSource->GetOutput() );
 
-      float aDeflection = 1.0;
-      bool anIsForced = true;
-      bool anIsRelative = false;
+      float aDeflection = 0.001;
       bool anIsVector = false;
 
-      GEOM::MeshShape( theShape, aDeflection, anIsForced );
+      // Is shape triangulated?
+      bool wasMeshed = true;
+      TopExp_Explorer ex;
+      TopLoc_Location aLoc;
+      for (ex.Init(theShape, TopAbs_FACE); ex.More(); ex.Next()) {
+       const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
+       Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
+       if(aPoly.IsNull()) { 
+         wasMeshed = false;
+         break; 
+       }
+      }
+
+      GEOM::MeshShape( theShape, aDeflection );
 
       TopExp_Explorer aVertexExp( theShape, TopAbs_VERTEX );
       for( ; aVertexExp.More(); aVertexExp.Next() )
@@ -99,8 +113,6 @@ extern "C"
         myVertexSource->AddVertex( aVertex );
       }
 
-      GEOM::MeshShape2( theShape, aDeflection, anIsRelative );
-
       TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
       TopExp::MapShapesAndAncestors( theShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap );
   
@@ -133,6 +145,9 @@ extern "C"
 
       myAppendFilter->Delete();
 
+      if(!wasMeshed)
+       BRepTools::Clean(theShape);
+
       return 1;
     }
     catch(Standard_Failure)