]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_DatConvertor.cxx
Salome HOME
DCQ : Merge with Ecole Ete a6.
[modules/visu.git] / src / CONVERTOR / VISU_DatConvertor.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : VISU_DatConvertor.cxx
6 //  Author : Alexey PETROV
7 //  Module : VISU
8
9 using namespace std;
10 #include "VISU_DatConvertor.hxx"
11 using namespace std;
12
13 #ifdef DEBUG
14 static int MYDEBUG = 1;
15 #else
16 static int MYDEBUG = 0;
17 #endif
18 static int PRECISION = 7;
19
20 extern "C"
21 VISU_Convertor* CreateDatConvertor(const string& theFileName) {
22   VISU_DatConvertor* aConvertor = new VISU_DatConvertor(theFileName);
23   aConvertor->Build();
24   return aConvertor;
25 }
26 VISU_DatConvertor::VISU_DatConvertor(const string& theFileName) {
27   myFileInfo.setFile(QString(theFileName.c_str()));
28   myName = (const char*)(myFileInfo.baseName());
29 }
30
31 VISU_Convertor* VISU_DatConvertor::Build() {
32   /*
33   ifstream stmIn(myFileInfo.absFilePath());
34   if(!stmIn.good())
35     throw std::runtime_error(string("VISU_DatConvertor::CreateResult() >> can't open file - ") + 
36                              (const char*)myFileInfo.absFilePath());
37   int aNbPoints, aNbCells, aNbFields;
38   ImportHead(&stmIn,&aNbPoints,&aNbCells,&aNbFields);
39   ImportPoints(&stmIn,aNbPoints);
40   vector<int> aCellsType(aNbCells);
41   ImportCells(&stmIn,&aCellsType);
42   for(int i = 0; i < aNbFields; i++)
43     ImportField(&stmIn,aNbPoints,&aCellsType);
44   myIsDone = true;
45   */
46   return this; 
47 }
48
49 int VISU_DatConvertor::ImportField(ifstream* pStmIn, int theNbPoints, vector<int>* pCellsType)
50 {
51   /*
52   ifstream &stmIn = *pStmIn;
53   vector<int>& aCellsType = *pCellsType;
54   int aNbCells = aCellsType.size();
55   string aName;  stmIn>>aName; stmIn>>aName; 
56   VISU::TMesh& aMesh = myMeshMap[myName];
57   VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY];
58   VISU::TField& aField = aMeshOnEntity.myFieldMap[aName];
59   aField.myMeshName = myName;
60   stmIn>>(aField.myNbComp); 
61   aField.myNbComp %= 100;
62   int iEnd;  stmIn>>iEnd; 
63   if(iEnd == theNbPoints)
64     aField.myEntity = VISU::NODE_ENTITY; 
65   else if(iEnd == aNbCells)
66     aField.myEntity = VISU::CELL_ENTITY;
67   else
68     throw std::runtime_error("ImportChamp >> elements doesn't connected to points or cells");
69   if(MYDEBUG)
70     MESSAGE("FieldInfo - myMeshName = "<<aField.myMeshName<<"; myNbComp = "<<aField.myNbComp);
71   for(int i = 0, tmp; i < iEnd; i++) {
72     stmIn>>tmp;
73     VISU::TField::TTime aTime(0.0,"");
74     VISU::TField::TValForCellsWithType &anArray = aField.myValField[aTime][aCellsType[i]];
75     for(int j = 0; j < aField.myNbComp; j++){
76       float tmp;  stmIn>>tmp;
77       anArray.push_back(tmp);
78     }
79   }
80   */
81   return 0; 
82 }
83
84 int VISU_DatConvertor::ImportHead(ifstream* pStmIn, int* theNbPoints, 
85                                   int* theNbCells, int* theNbFields) 
86 {
87   /*
88   ifstream &stmIn = *pStmIn;
89   const int BUFSIZE = 256;
90   char buf[BUFSIZE];
91   stmIn.getline(buf,BUFSIZE);
92   istrstream strIn(buf);
93   VISU::TMesh& aMesh = myMeshMap[myName];
94   *theNbFields = 0;
95   strIn>>(*theNbPoints); strIn>>(*theNbCells); strIn>>(*theNbFields);
96   if(MYDEBUG)
97     MESSAGE("ImportHead - theNbPoints = "<<(*theNbPoints)<<
98             "; theNbCells = "<<(*theNbCells)<<
99             "; theNbFields = "<<(*theNbFields));
100   */
101   return 0;
102 }
103
104 int VISU_DatConvertor::ImportPoints(ifstream* pStmIn, int theNbPoints) 
105 {
106   /*
107   ifstream &stmIn = *pStmIn;
108   VISU::TMesh& aMesh = myMeshMap[myName];
109   aMesh.myName = myName;
110   aMesh.myDim = 3;
111   int iEnd = aMesh.myDim*theNbPoints;
112   if(MYDEBUG) MESSAGE("ImportPoints - iEnd = "<<iEnd);
113   vector<float> &aPointsCoord = aMesh.myPointsCoord;
114   aPointsCoord.resize(iEnd);
115   for(int i = 0, tmp; i < iEnd;){
116     stmIn>>tmp;  
117     stmIn>>aPointsCoord[i++]; stmIn>>aPointsCoord[i++]; stmIn>>aPointsCoord[i++];
118   }
119   */
120   return 0;
121 }
122
123 int VISU_DatConvertor::ImportCells(ifstream* pStmIn, vector<int>* pCellsType) 
124 {
125   /*
126   ifstream &stmIn = *pStmIn;
127   vector<int>& aCellsType = *pCellsType;
128   int aNbCells = aCellsType.size();
129   if(MYDEBUG) MESSAGE("ImportCells - theNbCells - Beginning");
130   VISU::TMesh& aMesh = myMeshMap[myName];
131   VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY];
132   aMeshOnEntity.myEntity = VISU::CELL_ENTITY;
133   aMeshOnEntity.myMeshName = myName;
134   for(int i = 0, aMedType, aVtkType; i < aNbCells; i++){
135     stmIn>>aMedType; stmIn>>aMedType;
136     aCellsType[i] = aVtkType = med2vtkCellType(aMedType);
137     VISU::TMeshOnEntity::TConnForCellType& anArray = aMeshOnEntity.myCellsConn[aVtkType];
138     anArray.push_back(VISU::TMeshOnEntity::TConnect());
139     VISU::TMeshOnEntity::TConnect& aVector = anArray.back();
140     int jEnd = getNbMedNodes(aMedType);
141     aVector.resize(jEnd);
142     for(int j = 0, tmp; j < jEnd; j++){
143       stmIn>>tmp; 
144       aVector[j] = tmp - 1;
145     }
146   }
147   if(MYDEBUG) MESSAGE("ImportCells - theNbCells - End");
148   */
149   return 0;
150 }
151
152 /*
153 int VISU_Convertor_impl::ToDatFile(const string& theFileName) throw(std::runtime_error&){
154   if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - "<<theFileName);
155   if(!myIsDone && Build() != NULL) myIsDone = true;
156   ofstream stmOut(theFileName.c_str(),ios::out);
157   stmOut.precision(PRECISION);
158   stmOut.setf(ios::scientific,ios::floatfield);
159   
160   VISU::TMeshMap::const_iterator aMeshIter = myMeshMap.begin();
161   if(aMeshIter != myMeshMap.end()){
162     const VISU::TMesh &aMesh = aMeshIter->second;
163     if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - aMeshName = "<<aMeshIter->first);
164     VISU::TFieldMap aFieldMap = GetFieldMapForMesh(aMeshIter->first);
165     const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
166     VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(VISU::CELL_ENTITY);
167     if(aMeshOnEntityMapIter != aMeshOnEntityMap.end()){
168       const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
169       int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
170       int aNbCells = aMeshOnEntity.GetCellsDims().first;
171       stmOut<<aNbPoints<<"\t"<<aNbCells<<"\t"<<aFieldMap.size()<<endl;
172       if(MYDEBUG) 
173         MESSAGE("VISU_Convertor_impl::ToDatFile - aNbPoints = "<<aNbPoints<<
174                 "; aNbCells = "<<aNbCells<<"; aNbFields = "<<aFieldMap.size());
175       for(int i = 0, j = 0; i < aNbPoints; i++, j = 3*i){
176         stmOut<<(i+1)<<"\t"; 
177         stmOut<<aMesh.myPointsCoord[j]<<"\t"; 
178         stmOut<<aMesh.myPointsCoord[j+1]<<"\t";
179         stmOut<<aMesh.myPointsCoord[j+2]<<endl;
180       } 
181       const VISU::TMeshOnEntity::TCellsConn &aCellsConn = aMeshOnEntity.myCellsConn;
182       VISU::TMeshOnEntity::TCellsConn::const_iterator iter = aCellsConn.begin();
183       for(int i = 0; iter != aCellsConn.end(); iter++){
184         if(MYDEBUG) 
185           MESSAGE("VISU_Convertor_impl::ToDatFile - vtkCellType = "<<iter->first);
186         const VISU::TMeshOnEntity::TConnForCellType& anArray = iter->second;
187         for(int j = 0, jEnd = anArray.size(); j < jEnd; j++){
188           stmOut<<(++i)<<"\t";
189           stmOut<<vtk2medCellType(iter->first)<<"\t";
190           const vector<int>& aVector = anArray[j];
191           int kEnd = aVector.size();
192           for(int k = 0; k < kEnd; k++)
193             stmOut<<aVector[k]<<"\t";
194           stmOut<<endl;
195         }
196       }
197       if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - Beginning of Field Conversion");
198       VISU::TFieldMap::const_iterator aFieldIter = aFieldMap.begin();
199       for(int i = 0; aFieldIter != aFieldMap.end(); aFieldIter++){
200         const VISU::TField &aField = aFieldIter->second;
201         const VISU::TField::TValField &aValField = aField.myValField;
202         VISU::TField::TValField::const_reverse_iterator iter = aField.myValField.rbegin();
203         for(int i = 0; iter != aValField.rend(); iter++, i++) {
204           if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - aTime = "<<i);
205           const VISU::TField::TValForTime& aValForTime = iter->second;
206           VISU::TField::TValForTime::const_iterator jter = aValForTime.begin();
207           stmOut<<(++i)<<endl;
208           int prefix = (aField.myEntity == VISU::CELL_ENTITY? 100: 200);
209           int jEnd = (aField.myEntity == VISU::CELL_ENTITY? aNbCells: aNbPoints);
210           string aName = GenerateName((aFieldIter->first).c_str(),i);
211           stmOut<<aName<<endl;
212           stmOut<<(prefix + aField.myNbComp)<<"\t"<<jEnd<<endl;
213           if(MYDEBUG) 
214             MESSAGE("VISU_Convertor_impl::ToDatFile - aName = "<<aName<<"; jEnd = "<<jEnd);
215           for(int j = 0; jter != aValForTime.end(); jter++) {
216             const VISU::TField::TValForCellsWithType& anArray = jter->second;
217             int kEnd = anArray.size(), aVtkType = jter->first;
218             switch(aField.myNbComp) {
219             case 1:
220               for (int k = 0; k < kEnd;) {
221                 stmOut<<(++j)<<"\t";
222                 stmOut<<anArray[k++]<<"\n";
223               }
224               break;
225             case 2:
226               for (int k = 0; k < kEnd;){
227                 stmOut<<(++j)<<"\t";
228                 stmOut<<anArray[k++]<<"\t";
229                 stmOut<<anArray[k++]<<"\t";
230                 stmOut<<0.0<<"\n";
231               }
232               break;
233             case 3: 
234               for (int k = 0; k < kEnd;){
235                 stmOut<<(++j)<<"\t";
236                 stmOut<<anArray[k++]<<"\t";
237                 stmOut<<anArray[k++]<<"\t";
238                 stmOut<<anArray[k++]<<"\n";
239               }
240               break;
241             }
242           }
243         }
244       }
245     }
246   }
247   return 1;
248 }
249 */