1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : VISU_Convertor.hxx
6 // Author : Alexey PETROV
9 #ifndef VISU_Convertor_HeaderFile
10 #define VISU_Convertor_HeaderFile
28 #include "utilities.h"
30 #define MESSAGE(msg) cout<<msg<<endl
34 //class vtkUnstructuredGridReader;
35 #include "vtkUnstructuredGridReader.h"
41 TVtkCellInfo(const char* theName, int theSize) :
42 myName(theName), mySize(theSize) {}
46 typedef std::map<int,TVtkCellInfo> TVtkCellInfoMap;
47 extern TVtkCellInfoMap aVtkCellInfoMap;
49 enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
50 //enum TEntity {CELL_ENTITY, FACE_ENTITY, EDGE_ENTITY, NODE_ENTITY};
51 template <class _Tp> class vtk_ptr {
55 typedef _Tp element_type;
56 explicit vtk_ptr(_Tp* __p = 0) : _M_ptr(__p) {}
57 vtk_ptr(const vtk_ptr& __a) : _M_ptr(0) {}
58 vtk_ptr(vtk_ptr& __a) : _M_ptr(__a.release()) {}
59 vtk_ptr& operator=(const vtk_ptr& __a) { return *this;}
60 vtk_ptr& operator=(vtk_ptr& __a) {
62 if(_M_ptr) _M_ptr->Delete();
63 _M_ptr = __a.release();
68 if(_M_ptr) _M_ptr->Delete();
71 _Tp& operator*() const { return *_M_ptr;}
72 _Tp* operator->() const { return _M_ptr;}
73 _Tp* get() const { return _M_ptr;}
79 void reset(_Tp* __p = 0) {
80 if(_M_ptr) _M_ptr->Delete();
84 typedef vtk_ptr<vtkUnstructuredGridReader> TVTKReader;
86 typedef std::set<std::string> TBindGroups;
94 typedef std::set<int> TSubMeshOnCellType;
95 typedef std::map<int,TSubMeshOnCellType> TSubMesh;
98 typedef std::map<std::string,TFamily> TFamilyMap;
106 typedef std::vector<float> TValForCellsWithType;
107 typedef std::map<int,TValForCellsWithType> TValForCells;
108 typedef std::pair<double,std::string> TTime;
109 typedef std::vector<string> TCompNames;
110 typedef std::vector<string> TUnitNames;
112 TVTKReader myStorage;
115 TValForCells myValForCells;
117 typedef std::map<int,TValForTime> TValField;
118 TValField myValField;
119 TCompNames myCompNames;
120 TUnitNames myUnitNames;
121 void ShallowCopy(const TField& aField);
123 typedef map<string,TField> TFieldMap;
125 struct TMeshOnEntity{
126 TVTKReader myStorage;
129 typedef vector<int> TConnect;
130 typedef vector<TConnect> TConnForCellType;
131 typedef map<int,TConnForCellType> TCellsConn;
132 TCellsConn myCellsConn;
133 TFamilyMap myFamilyMap;
134 TFieldMap myFieldMap;
135 pair<int,int> GetCellsDims(const string& theFamilyName = "") const
136 throw(std::runtime_error&);
138 typedef std::map<TEntity,TMeshOnEntity> TMeshOnEntityMap;
139 const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity,
140 const string& theFamilyName)
141 throw(std::runtime_error&);
142 TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity,
143 const string& theFamilyName)
144 throw(std::runtime_error&);
146 typedef std::pair<std::string,TEntity> TFamilyAndEntity;
147 typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
149 TVTKReader myStorage;
152 TFamilyAndEntitySet myFamilyAndEntitySet;
154 typedef std::map<std::string,TGroup> TGroupMap;
159 typedef vector<float> TPointsCoord;
160 TPointsCoord myPointsCoord;
161 TMeshOnEntityMap myMeshOnEntityMap;
162 TGroupMap myGroupMap;
163 void CreateMeshOnNodes();
164 const TField* GetField(const string& theFieldName) const;
166 typedef std::map<std::string,TMesh> TMeshMap;
169 class VISU_Convertor{
172 VISU::TMeshMap myMeshMap;
175 virtual ~VISU_Convertor(){};
176 virtual const string& GetName() { return myName;}
177 virtual int IsDone() const { return myIsDone;}
178 typedef vtkUnstructuredGridReader OutputType;
179 virtual VISU_Convertor* Build() throw (std::runtime_error&) = 0;
180 virtual OutputType* GetMeshOnEntity(const string& theMeshName,
181 const VISU::TEntity& theEntity,
182 const string& theFamilyName = "")
183 throw(std::runtime_error&) = 0;
184 virtual OutputType* GetMeshOnGroup(const string& theMeshName,
185 const string& theGroupName)
186 throw(std::runtime_error&) = 0;
187 virtual OutputType* GetFieldOnMesh(const string& theMeshName,
188 const VISU::TEntity& theEntity,
189 const string& theFieldName,
191 throw(std::runtime_error&) = 0;
192 virtual const VISU::TMeshMap& GetMeshMap() throw(std::runtime_error&);
193 virtual const VISU::TField& GetField(const string& theMeshName, VISU::TEntity theEntity,
194 const string& theFieldName)
195 throw(std::runtime_error&);
196 static string GenerateName(const VISU::TField::TTime& aTime);
197 static string GenerateName(const string& theName, unsigned int theTimeId);
200 template<class T> std::string dtos(const string& fmt, T val){
201 static QString aString;
202 aString.sprintf(fmt.c_str(),val);
203 return aString.latin1();
206 VISU_Convertor* CreateMedConvertor(const std::string& theFileName) throw(std::runtime_error&);
207 VISU_Convertor* CreateDatConvertor(const std::string& theFileName) throw(std::runtime_error&);
208 VISU_Convertor* CreateConvertor(const std::string& theFileName) throw(std::runtime_error&);