3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_Convertor.hxx
24 // Author : Alexey PETROV
27 #ifndef VISU_Convertor_HeaderFile
28 #define VISU_Convertor_HeaderFile
43 #include <vtkPoints.h>
44 #include <vtkSystemIncludes.h>
45 #include <vtkUnstructuredGrid.h>
46 #include <vtkMergeDataObjectFilter.h>
47 #include <vtkFieldDataToAttributeDataFilter.h>
49 #include "VISU_ExtractUnstructuredGrid.hxx"
51 #include <vtkSmartPointer.h>
54 enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
56 typedef vtkSmartPointer<vtkPoints> TVTKPoints;
57 typedef vtkSmartPointer<vtkUnstructuredGrid> TVTKSource;
58 typedef vtkSmartPointer<vtkMergeDataObjectFilter> TVTKMergetFilter;
59 typedef vtkSmartPointer<VISU_ExtractUnstructuredGrid> TVTKExtractFilter;
60 typedef vtkSmartPointer<vtkFieldDataToAttributeDataFilter> TVTKAttribyteFilter;
61 typedef std::set<std::string> TBindGroups;
69 vtkIdType myNbCells, myCellsSize;
70 typedef std::set<vtkIdType> TSubMeshOnCellType;
71 typedef std::map<vtkIdType,TSubMeshOnCellType> TSubMesh;
73 TFamily() : myNbCells(0), myCellsSize(0) {}
75 typedef std::map<std::string,TFamily> TFamilyMap;
78 TVTKExtractFilter myExtractFilter;
82 std::string myMeshName;
83 vtkIdType myNbComp, myNbValField, myDataSize, myIsTrimmed;
84 typedef std::vector<float> TValForCellsWithType;
85 typedef std::map<vtkIdType,TValForCellsWithType> TValForCells;
86 typedef std::pair<double,std::string> TTime;
87 typedef std::vector<std::string> TCompNames;
88 typedef std::vector<std::string> TUnitNames;
90 TVTKAttribyteFilter myAttribyteFilter;
91 TVTKMergetFilter myMergeFilter;
94 std::string myMeshName;
96 std::string myFieldName;
99 TValForCells myValForCells;
100 TValForTime() : myNbComp(0) {}
102 if(myMergeFilter.GetPointer())
103 myMergeFilter->UnRegisterAllOutputs();
104 if(myAttribyteFilter.GetPointer())
105 myAttribyteFilter->UnRegisterAllOutputs();
108 typedef std::map<vtkIdType,TValForTime> TValField;
109 TValField myValField;
110 TCompNames myCompNames;
111 TUnitNames myUnitNames;
112 TField() : myNbComp(0), myNbValField(0), myDataSize(0), myIsTrimmed(0) {}
113 void ShallowCopy(const TField& aField);
115 if(myExtractFilter.GetPointer())
116 myExtractFilter->UnRegisterAllOutputs();
119 typedef std::map<std::string,TField> TFieldMap;
121 struct TMeshOnEntity{
122 TVTKSource myStorage;
123 std::string myMeshName;
125 vtkIdType myNbCells, myCellsSize;
126 typedef std::vector<vtkIdType> TConnect;
127 typedef std::vector<TConnect> TConnForCellType;
128 typedef std::map<vtkIdType,TConnForCellType> TCellsConn;
129 TCellsConn myCellsConn;
130 TFamilyMap myFamilyMap;
131 TFieldMap myFieldMap;
132 TMeshOnEntity() : myNbCells(0), myCellsSize(0) {}
133 std::pair<vtkIdType,vtkIdType> GetCellsDims(const std::string& theFamilyName = "") const
134 throw(std::runtime_error&);
136 typedef std::map<TEntity,TMeshOnEntity> TMeshOnEntityMap;
137 const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity,
138 const std::string& theFamilyName)
139 throw(std::runtime_error&);
140 TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity,
141 const std::string& theFamilyName)
142 throw(std::runtime_error&);
144 typedef std::pair<std::string,TEntity> TFamilyAndEntity;
145 typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
147 TVTKSource myStorage;
149 std::string myMeshName;
150 vtkIdType myNbCells, myCellsSize;
151 TGroup() : myNbCells(0), myCellsSize(0) {}
152 TFamilyAndEntitySet myFamilyAndEntitySet;
154 typedef std::map<std::string,TGroup> TGroupMap;
158 vtkIdType myDim, myNbPoints;
160 typedef float TCoord;
161 typedef std::vector<TCoord> TPointsCoord;
162 TPointsCoord myPointsCoord;
163 TMeshOnEntityMap myMeshOnEntityMap;
164 TGroupMap myGroupMap;
165 TMesh() : myDim(0), myNbPoints(0) {}
166 const TField* GetField(const std::string& theFieldName) const;
168 typedef std::map<std::string,TMesh> TMeshMap;
169 void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
172 class VISU_Convertor{
175 VISU::TMeshMap myMeshMap;
178 virtual ~VISU_Convertor(){};
179 virtual const std::string& GetName() { return myName;}
180 virtual int IsDone() const { return myIsDone;}
181 typedef vtkUnstructuredGrid TOutput;
183 virtual VISU_Convertor* Build() throw (std::runtime_error&) = 0;
184 virtual const VISU::TMeshMap& GetMeshMap() throw(std::runtime_error&);
185 virtual float GetSize() throw (std::runtime_error&) = 0;
187 virtual TOutput* GetMeshOnEntity(const std::string& theMeshName,
188 const VISU::TEntity& theEntity,
189 const std::string& theFamilyName = "")
190 throw(std::runtime_error&) = 0;
191 virtual float GetMeshOnEntitySize(const std::string& theMeshName,
192 const VISU::TEntity& theEntity,
193 const std::string& theFamilyName = "")
194 throw (std::runtime_error&) = 0;
197 virtual TOutput* GetMeshOnGroup(const std::string& theMeshName,
198 const std::string& theGroupName)
199 throw(std::runtime_error&) = 0;
200 virtual float GetMeshOnGroupSize(const std::string& theMeshName,
201 const std::string& theGroupName)
202 throw(std::runtime_error&) = 0;
205 virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName,
206 const VISU::TEntity& theEntity,
207 const std::string& theFieldName,
209 throw(std::runtime_error&) = 0;
210 virtual float GetTimeStampSize(const std::string& theMeshName,
211 const VISU::TEntity& theEntity,
212 const std::string& theFieldName,
214 throw(std::runtime_error&) = 0;
215 virtual float GetFieldOnMeshSize(const std::string& theMeshName,
216 const VISU::TEntity& theEntity,
217 const std::string& theFieldName)
218 throw(std::runtime_error&) = 0;
219 virtual const VISU::TField& GetField(const std::string& theMeshName,
220 VISU::TEntity theEntity,
221 const std::string& theFieldName)
222 throw(std::runtime_error&) = 0;
223 virtual const VISU::TField::TValForTime& GetTimeStamp(const std::string& theMeshName,
224 const VISU::TEntity& theEntity,
225 const std::string& theFieldName,
227 throw(std::runtime_error&) = 0;
229 static std::string GenerateName(const VISU::TField::TTime& aTime);
230 static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
231 static void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
235 VISU_Convertor* CreateMedConvertor(const std::string& theFileName) throw(std::runtime_error&);
236 VISU_Convertor* CreateDatConvertor(const std::string& theFileName) throw(std::runtime_error&);
237 VISU_Convertor* CreateConvertor(const std::string& theFileName) throw(std::runtime_error&);