1 // Copyright (C) 2007-2010 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>
47 # if defined VTKEXPORT_EXPORTS || defined VTKExport_EXPORTS
48 # define VTKEXPORT_EXPORT __declspec( dllexport )
50 # define VTKEXPORT_EXPORT __declspec( dllimport )
53 # define VTKEXPORT_EXPORT
56 //=============================================================================
60 //=============================================================================
65 int Export(const TopoDS_Shape& theShape,
66 const TCollection_AsciiString& theFileName,
67 const TCollection_AsciiString& theFormatName)
69 MESSAGE("Export VTK into file " << theFileName.ToCString());
73 GEOM_VertexSource* myVertexSource = GEOM_VertexSource::New();
74 GEOM_EdgeSource* myIsolatedEdgeSource = GEOM_EdgeSource::New();
75 GEOM_EdgeSource* myOneFaceEdgeSource = GEOM_EdgeSource::New();
76 GEOM_EdgeSource* mySharedEdgeSource = GEOM_EdgeSource::New();
77 GEOM_WireframeFace* myWireframeFaceSource = GEOM_WireframeFace::New();
78 GEOM_ShadingFace* myShadingFaceSource = GEOM_ShadingFace::New();
80 vtkAppendPolyData* myAppendFilter = vtkAppendPolyData::New();
81 myAppendFilter->AddInput( myVertexSource->GetOutput() );
82 myAppendFilter->AddInput( myIsolatedEdgeSource->GetOutput() );
83 myAppendFilter->AddInput( myOneFaceEdgeSource->GetOutput() );
84 myAppendFilter->AddInput( mySharedEdgeSource->GetOutput() );
85 //myAppendFilter->AddInput( myWireframeFaceSource->GetOutput() ); // iso-lines are unnecessary
86 myAppendFilter->AddInput( myShadingFaceSource->GetOutput() );
88 float aDeflection = 1.0;
89 bool anIsForced = true;
90 bool anIsRelative = false;
91 bool anIsVector = false;
93 GEOM::MeshShape( theShape, aDeflection, anIsForced );
95 TopExp_Explorer aVertexExp( theShape, TopAbs_VERTEX );
96 for( ; aVertexExp.More(); aVertexExp.Next() )
98 const TopoDS_Vertex& aVertex = TopoDS::Vertex( aVertexExp.Current() );
99 myVertexSource->AddVertex( aVertex );
102 GEOM::MeshShape2( theShape, aDeflection, anIsRelative );
104 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
105 TopExp::MapShapesAndAncestors( theShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap );
107 GEOM::SetShape( theShape,
110 myIsolatedEdgeSource,
113 myWireframeFaceSource,
114 myShadingFaceSource );
116 myAppendFilter->Update();
118 // Set "C" numeric locale to save numbers correctly
119 Kernel_Utils::Localizer loc;
121 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
122 aWriter->SetInput( myAppendFilter->GetOutput() );
123 aWriter->SetFileName( theFileName.ToCString() );
127 myVertexSource->Delete();
128 myIsolatedEdgeSource->Delete();
129 myOneFaceEdgeSource->Delete();
130 mySharedEdgeSource->Delete();
131 myWireframeFaceSource->Delete();
132 myShadingFaceSource->Delete();
134 myAppendFilter->Delete();
138 catch(Standard_Failure)
140 //THROW_SALOME_CORBA_EXCEPTION("Exception catched in VTKExport", SALOME::BAD_PARAM);