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;
136 typedef std::map<TEntity,TMeshOnEntity> TMeshOnEntityMap;
137 const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity,
138 const std::string& theFamilyName);
140 TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity,
141 const std::string& theFamilyName);
143 typedef std::pair<std::string,TEntity> TFamilyAndEntity;
144 typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
146 TVTKSource myStorage;
148 std::string myMeshName;
149 vtkIdType myNbCells, myCellsSize;
150 TGroup() : myNbCells(0), myCellsSize(0) {}
151 TFamilyAndEntitySet myFamilyAndEntitySet;
153 typedef std::map<std::string,TGroup> TGroupMap;
157 vtkIdType myDim, myNbPoints;
159 typedef float TCoord;
160 typedef std::vector<TCoord> TPointsCoord;
161 TPointsCoord myPointsCoord;
162 typedef std::vector<std::string> TPointsDim;
163 TPointsDim myPointsDim;
164 TMeshOnEntityMap myMeshOnEntityMap;
165 TGroupMap myGroupMap;
166 TMesh() : myDim(0), myNbPoints(0) {}
167 const TField* GetField(const std::string& theFieldName) const;
169 typedef std::map<std::string,TMesh> TMeshMap;
170 void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
173 class VISU_Convertor{
176 VISU::TMeshMap myMeshMap;
179 virtual ~VISU_Convertor(){};
180 virtual const std::string& GetName() { return myName;}
181 virtual int IsDone() const { return myIsDone;}
182 typedef vtkUnstructuredGrid TOutput;
184 virtual VISU_Convertor* Build() = 0;
185 virtual const VISU::TMeshMap& GetMeshMap() ;
186 virtual float GetSize() = 0;
188 virtual TOutput* GetMeshOnEntity(const std::string& theMeshName,
189 const VISU::TEntity& theEntity,
190 const std::string& theFamilyName = "") = 0;
192 virtual float GetMeshOnEntitySize(const std::string& theMeshName,
193 const VISU::TEntity& theEntity,
194 const std::string& theFamilyName = "") = 0;
196 virtual TOutput* GetMeshOnGroup(const std::string& theMeshName,
197 const std::string& theGroupName) = 0;
199 virtual float GetMeshOnGroupSize(const std::string& theMeshName,
200 const std::string& theGroupName) = 0;
202 virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName,
203 const VISU::TEntity& theEntity,
204 const std::string& theFieldName,
205 int theStampsNum) = 0;
207 virtual float GetTimeStampSize(const std::string& theMeshName,
208 const VISU::TEntity& theEntity,
209 const std::string& theFieldName,
210 int theStampsNum) = 0;
212 virtual float GetFieldOnMeshSize(const std::string& theMeshName,
213 const VISU::TEntity& theEntity,
214 const std::string& theFieldName) = 0;
216 virtual const VISU::TField& GetField(const std::string& theMeshName,
217 VISU::TEntity theEntity,
218 const std::string& theFieldName) = 0;
220 virtual const VISU::TField::TValForTime& GetTimeStamp(const std::string& theMeshName,
221 const VISU::TEntity& theEntity,
222 const std::string& theFieldName,
223 int theStampsNum) = 0;
225 static std::string GenerateName(const VISU::TField::TTime& aTime);
226 static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
227 static void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
231 VISU_Convertor* CreateMedConvertor(const std::string& theFileName) ;
232 VISU_Convertor* CreateDatConvertor(const std::string& theFileName) ;
233 VISU_Convertor* CreateConvertor(const std::string& theFileName) ;