1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: VTKExport.cxx
24 // Author: Oleg UVAROV
26 #include "utilities.h"
28 #include <Basics_Utils.hxx>
30 #include <OCC2VTK_Tools.h>
32 #include <GEOM_VertexSource.h>
33 #include <GEOM_EdgeSource.h>
34 #include <GEOM_WireframeFace.h>
35 #include <GEOM_ShadingFace.h>
37 #include <vtkAppendPolyData.h>
38 #include <vtkPolyDataWriter.h>
40 #include <TCollection_AsciiString.hxx>
42 #include <TopExp_Explorer.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <Poly_Triangulation.hxx>
46 #include <BRep_Tool.hxx>
47 #include <BRepTools.hxx>
50 # if defined VTKEXPORT_EXPORTS || defined VTKExport_EXPORTS
51 # define VTKEXPORT_EXPORT __declspec( dllexport )
53 # define VTKEXPORT_EXPORT __declspec( dllimport )
56 # define VTKEXPORT_EXPORT
59 //=============================================================================
63 //=============================================================================
68 int Export(const TopoDS_Shape& theShape,
69 const TCollection_AsciiString& theFileName,
70 const TCollection_AsciiString& theFormatName)
72 MESSAGE("Export VTK into file " << theFileName.ToCString());
76 GEOM_VertexSource* myVertexSource = GEOM_VertexSource::New();
77 GEOM_EdgeSource* myIsolatedEdgeSource = GEOM_EdgeSource::New();
78 GEOM_EdgeSource* myOneFaceEdgeSource = GEOM_EdgeSource::New();
79 GEOM_EdgeSource* mySharedEdgeSource = GEOM_EdgeSource::New();
80 GEOM_WireframeFace* myWireframeFaceSource = GEOM_WireframeFace::New();
81 GEOM_ShadingFace* myShadingFaceSource = GEOM_ShadingFace::New();
83 vtkAppendPolyData* myAppendFilter = vtkAppendPolyData::New();
84 myAppendFilter->AddInput( myVertexSource->GetOutput() );
85 myAppendFilter->AddInput( myIsolatedEdgeSource->GetOutput() );
86 myAppendFilter->AddInput( myOneFaceEdgeSource->GetOutput() );
87 myAppendFilter->AddInput( mySharedEdgeSource->GetOutput() );
88 //myAppendFilter->AddInput( myWireframeFaceSource->GetOutput() ); // iso-lines are unnecessary
89 myAppendFilter->AddInput( myShadingFaceSource->GetOutput() );
91 float aDeflection = 0.001;
92 bool anIsVector = false;
94 // Is shape triangulated?
95 bool wasMeshed = true;
98 for (ex.Init(theShape, TopAbs_FACE); ex.More(); ex.Next()) {
99 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
100 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
107 GEOM::MeshShape( theShape, aDeflection );
109 TopExp_Explorer aVertexExp( theShape, TopAbs_VERTEX );
110 for( ; aVertexExp.More(); aVertexExp.Next() )
112 const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() );
113 myVertexSource->AddVertex( aVertex );
116 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
117 TopExp::MapShapesAndAncestors( theShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap );
119 GEOM::SetShape( theShape,
122 myIsolatedEdgeSource,
125 myWireframeFaceSource,
126 myShadingFaceSource );
128 myAppendFilter->Update();
130 // Set "C" numeric locale to save numbers correctly
131 Kernel_Utils::Localizer loc;
133 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
134 aWriter->SetInput( myAppendFilter->GetOutput() );
135 aWriter->SetFileName( theFileName.ToCString() );
139 myVertexSource->Delete();
140 myIsolatedEdgeSource->Delete();
141 myOneFaceEdgeSource->Delete();
142 mySharedEdgeSource->Delete();
143 myWireframeFaceSource->Delete();
144 myShadingFaceSource->Delete();
146 myAppendFilter->Delete();
149 BRepTools::Clean(theShape);
153 catch(Standard_Failure)
155 //THROW_SALOME_CORBA_EXCEPTION("Exception catched in VTKExport", SALOME::BAD_PARAM);