Salome HOME
Merge from PortingMED3 07Apr11
[modules/visu.git] / src / CONVERTOR / VISU_Vtk2MedConvertor.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VISU_Vtk2MedConvertor.cxx
21 //  Author : Eugeny NIKOLAEV, Open CASCADE SAS
22 //
23 #include "VISU_Vtk2MedConvertor.hxx"
24
25 // QT includes
26 #include <qdir.h>
27 #include <qfileinfo.h>
28 #include <qstringlist.h>
29
30 // VTK includes
31 #include <vtkSmartPointer.h>
32 #include <vtkDataReader.h>
33
34 #include <vtkStructuredPointsReader.h>
35 #include <vtkStructuredGridReader.h>
36 #include <vtkRectilinearGridReader.h>
37 #include <vtkUnstructuredGridReader.h>
38 #include <vtkPolyDataReader.h>
39 #include <vtkDataSetReader.h>
40
41 #include <vtkPointSet.h>
42 #include <vtkDataSet.h>
43 #include <vtkPolyData.h>
44 #include <vtkDataObject.h>
45 #include <vtkCellTypes.h>
46 #include <vtkCellType.h>
47 #include <vtkCell.h>
48 #include <vtkCellData.h>
49 #include <vtkPointData.h>
50
51 #include <vtkUnstructuredGrid.h>
52 #include <vtkFloatArray.h>
53
54 // MED Warpper includes
55 #include "MED_Factory.hxx"
56
57 // STL includes
58 #include <string>
59 #include <vector>
60 #include <iostream>
61 #include <sstream>
62 #include <set>
63 #include <map>
64 //#include <pair.h>
65
66 #ifdef _DEBUG_
67 static int MYDEBUG = 0;
68 static int MYDEBUG_VALUES = 0;
69 #else
70 static int MYDEBUG = 0;
71 static int MYDEBUG_VALUES = 0;
72 #endif
73
74 using namespace std;
75
76 /*
77 # = dynamic_cast</*
78 *>(  );define   VTK_EMPTY_CELL   0
79 #define         VTK_VERTEX   1
80 #define         VTK_POLY_VERTEX   2
81 #define         VTK_LINE   3
82 #define         VTK_POLY_LINE   4
83 #define         VTK_TRIANGLE   5
84 #define         VTK_TRIANGLE_STRIP   6
85 #define         VTK_POLYGON   7
86 #define         VTK_PIXEL   8
87 #define         VTK_QUAD   9
88 #define         VTK_TETRA   10
89 #define         VTK_VOXEL   11
90 #define         VTK_HEXAHEDRON   12
91 #define         VTK_WEDGE   13
92 #define         VTK_PYRAMID   14
93 #define         VTK_QUADRATIC_EDGE   21
94 #define         VTK_QUADRATIC_TRiTSIANGLE   22
95 #define         VTK_QUADRATIC_QUAD   23
96 #define         VTK_QUADRATIC_TETRA   24
97 #define         VTK_QUADRATIC_HEXAHEDRON   25
98 #define         VTK_CONVEX_POINT_SET   41
99 #define         VTK_PARAMETRIC_CURVE   51
100 #define         VTK_PARAMETRIC_SURFACE   52
101 #define         VTK_PARAMETRIC_TRI_SURFACE   53
102 #define         VTK_PARAMETRIC_QUAD_SURFACE   54
103 #define         VTK_PARAMETRIC_TETRA_REGION   55
104 #define         VTK_PARAMETRIC_HEX_REGION   56
105 */
106
107 static MED::EGeometrieElement VTK2MED( const int theGeom )
108 {
109   // Ignoring vtk types:
110   // VTK_PIXEL,
111   // VTK_VERTEX,
112   // VTK_POLY_VERTEX
113   // VTK_VOXEL
114   // VTK_POLY_LINE       
115   // VTK_TRIANGLE_STRIP  
116   // VTK_PARAMETRIC_CURVE 
117   // VTK_PARAMETRIC_SURFACE
118   // VTK_PARAMETRIC_TRI_SURFACE
119   // VTK_PARAMETRIC_QUAD_SURFACE
120   // VTK_PARAMETRIC_TETRA_REGION
121   // VTK_PARAMETRIC_HEX_REGION
122   
123   MED::EGeometrieElement aEmptyGeom = MED::EGeometrieElement(-1);
124   switch(theGeom){
125   case VTK_LINE:             return MED::eSEG2;
126   case VTK_TRIANGLE:         return MED::eTRIA3;
127   case VTK_POLYGON:          return MED::ePOLYGONE;
128   case VTK_QUAD:             return MED::eQUAD4;
129   case VTK_TETRA:            return MED::eTETRA4;
130   case VTK_HEXAHEDRON:       return MED::eHEXA8;
131   case VTK_WEDGE:            return MED::ePENTA6;
132   case VTK_PYRAMID:          return MED::ePYRA5;
133   // QUADRATIC elements
134   case VTK_QUADRATIC_EDGE:      return MED::eSEG3;
135   case VTK_QUADRATIC_TRIANGLE:  return MED::eTRIA6;
136   case VTK_QUADRATIC_QUAD:      return MED::eQUAD8;
137   case VTK_QUADRATIC_TETRA:     return MED::eTETRA10;
138   case VTK_QUADRATIC_HEXAHEDRON:return MED::eHEXA20;
139   case VTK_CONVEX_POINT_SET:    return MED::ePOLYEDRE;
140   }
141   
142   return aEmptyGeom;
143 }
144
145 /*!
146   \class VISU_Vtk2MedConvertor
147   \brief The general main of the class VISU_Vtk2MedConvertor is converting from 
148   one or several VTK files to the one MED file...
149
150   The VISU_Vtk2MedConvertor interface allows us to create the MED file according 
151   to VTK files in next ways:
152   - Extract geometry and fields from one VTK file.
153   - Extract geometry and fields from first VTK file and fields from others 
154   VTK files (geometry ignoring). Also the fields which have same names join into 
155   corresponding fields with different time stamp
156 */
157
158 /*!
159   \brief Constructor
160   - Sets default output mesh name
161   - Sets default version of output MED file.
162   - Sets default ignoring fields list
163   - Sets default points and cells ids mapping field names.
164
165 */
166 VISU_Vtk2MedConvertor
167 ::VISU_Vtk2MedConvertor():
168   myVersion(MED::eV2_2),
169   myMeshName("vtk2med")
170 {
171   myIgnoringFieldList.insert("VISU_POINTS_MAPPER");
172   myIgnoringFieldList.insert("VISU_CELLS_MAPPER");
173   myIgnoringFieldList.insert("VISU_FIELD");
174   setCellDataFieldNameIDS("VISU_CELLS_MAPPER");
175   setPointDataFieldNameIDS("VISU_POINTS_MAPPER");
176 }
177                     
178 /*!
179   \brief Constructor
180   - Sets default output mesh name
181   - Sets default version of output MED file.
182   - Sets default ignoring fields list
183   - Sets default points and cells ids mapping field names.
184
185   \param theMEDFileName output med file name
186   \param theFirstVTKFileName first vtk file name
187 */
188 VISU_Vtk2MedConvertor
189 ::VISU_Vtk2MedConvertor(const string theMEDFileName,
190                     const string theFirstVTKFileName):
191   myVersion(MED::eV2_2),
192   myMeshName("vtk2med")
193 {
194   myMEDFileName   = theMEDFileName;
195   myFirstVTKFileName = theFirstVTKFileName;
196   myIgnoringFieldList.insert("VISU_POINTS_MAPPER");
197   myIgnoringFieldList.insert("VISU_CELLS_MAPPER");
198   myIgnoringFieldList.insert("VISU_FIELD");
199   setCellDataFieldNameIDS("VISU_CELLS_MAPPER");
200   setPointDataFieldNameIDS("VISU_POINTS_MAPPER");
201 }
202
203 /*!
204   \brief Constructor
205   - Sets default output mesh name
206   - Sets default version of output MED file.
207   - Sets default ignoring fields list
208   - Sets default points and cells ids mapping field names.
209
210   \param theMEDFileName output med file name
211   \param theFirstVTKFileName first vtk file name
212   \param theDataVTKFileNames of vtk file names, which will be using as values on points and cells
213 */
214 VISU_Vtk2MedConvertor
215 ::VISU_Vtk2MedConvertor(const string theMEDFileName,
216                     const string theFirstVTKFileName,
217                     const TVectorString theDataVTKFileNames):
218   myVersion(MED::eV2_2),
219   myMeshName("vtk2med")
220 {
221   myMEDFileName      = theMEDFileName;
222   myFirstVTKFileName = theFirstVTKFileName;
223   myDataVTKFileNames = theDataVTKFileNames;
224   myIgnoringFieldList.insert("VISU_POINTS_MAPPER");
225   myIgnoringFieldList.insert("VISU_CELLS_MAPPER");
226   myIgnoringFieldList.insert("VISU_FIELD");
227   setMeshName("vtk2med");
228   setCellDataFieldNameIDS("VISU_CELLS_MAPPER");
229   setPointDataFieldNameIDS("VISU_POINTS_MAPPER");
230 }
231
232 /*!
233   \brief Adds field names, which used as specific fields with ids or elements 
234   (or something else). (Default: "VISU_CELLS_MAPPER","VISU_POINTS_MAPPER","VISU_FILED")
235   \param theFieldName field name
236   \sa eraseFromIgnoringFieldList()
237 */
238 void
239 VISU_Vtk2MedConvertor
240 ::addToIgnoringFieldList( const string& theFieldName )
241 {
242   myIgnoringFieldList.insert(theFieldName);
243 }
244
245 /*!
246   \brief Sets the output MED file name
247   \param theFileName file name
248   \sa getMEDFileName()
249 */
250 void 
251 VISU_Vtk2MedConvertor
252 ::setMEDFileName( const string theFileName )
253
254   myMEDFileName=theFileName;
255 };
256
257 /*!
258   \brief Gets the output MED file name
259   \return output MED file name
260   \sa setMEDFileName()
261 */
262 string 
263 VISU_Vtk2MedConvertor
264 ::getMEDFileName() const 
265 {
266   return myMEDFileName;
267 }
268
269 /*!
270   \brief Sets the first input vtk file name
271   \param theFileName file name
272   \sa getFirstVTKFileName()
273 */
274 void 
275 VISU_Vtk2MedConvertor
276 ::setFirstVTKFileName( const string theFileName )
277
278   myFirstVTKFileName=theFileName;
279 };
280
281 /*!
282   \brief Fets the first input vtk file name
283   \return first input vtk file name
284   \sa setFirstVTKFileName()
285 */
286 string 
287 VISU_Vtk2MedConvertor
288 ::getFirstVTKFileName() const 
289 {
290   return myFirstVTKFileName;
291 }
292
293 /*!
294   \brief Sets list of vtk file names, which will be using as values on points and cells
295   \param theFileNames list of vtk file names
296   \sa getDataVTKFileNames()
297 */
298 void 
299 VISU_Vtk2MedConvertor
300 ::setDataVTKFileNames( const TVectorString theFileNames )
301
302   myDataVTKFileNames = theFileNames;
303 };
304
305 /*!
306   \brief Gets list of vtk file names, which will be using as values on points and cells
307   \param theFileNames out list of vtk file names
308   \sa setDataVTKFileNames()
309 */
310 void 
311 VISU_Vtk2MedConvertor
312 ::getDataVTKFileNames( TVectorString& theDataVTKFileNames ) const 
313
314   theDataVTKFileNames = myDataVTKFileNames; 
315 };
316
317 /*!
318   \brief Sets version of the output MED file MED::V2_2(is default) or MED::V2_1
319   \param theVersion version of the output MED file 
320 */
321 void 
322 VISU_Vtk2MedConvertor
323 ::setVersion( const MED::EVersion theVersion )
324 {
325   myVersion = theVersion; 
326 }
327
328 /*!
329   \brief Gets version of the output MED file MED::V2_2(is default) or MED::V2_1
330   \return version of the output MED file 
331 */
332 MED::EVersion 
333 VISU_Vtk2MedConvertor
334 ::getVersion() const 
335 {
336   return myVersion;
337 }
338
339 /*!
340   \brief Sets output mesh name. ("vtk2med" - default)
341   \param theMeshName mesh name
342   \sa getMeshName()
343 */
344 void 
345 VISU_Vtk2MedConvertor
346 ::setMeshName( const string theMeshName ) 
347 {
348   myMeshName = theMeshName;
349 }
350
351 /*!
352   \brief Gets output mesh name. ("vtk2med" - default)
353   \return mesh name
354   \sa setMeshName()
355 */
356 string 
357 VISU_Vtk2MedConvertor
358 ::getMeshName() const
359 {
360   return myMeshName;
361 }
362
363 /*!
364   \brief Sets field name with cell ids (Default - VISU_CELLS_MAPPER)
365   \param theFieldName field name 
366   \sa getCellDataFieldNameIDS
367 */
368 void 
369 VISU_Vtk2MedConvertor
370 ::setCellDataFieldNameIDS( const string& theFieldName )
371 {
372   myCellDataFieldNameIDS = theFieldName;
373 }
374
375 /*!
376   \brief Gets field name with cell ids (Default - VISU_CELLS_MAPPER)
377   \return field name 
378   \sa setCellDataFieldNameIDS()
379 */
380 const string& 
381 VISU_Vtk2MedConvertor
382 ::getCellDataFieldNameIDS() const
383 {
384   return myCellDataFieldNameIDS;
385 }
386
387 /*!
388   \brief Erases field names which used as specific fields with ids or elements 
389   (or something else)
390   \param theFieldName field name
391   \sa addToIgnoringFieldList()
392 */
393 void
394 VISU_Vtk2MedConvertor
395 ::eraseFromIgnoringFieldList(const string& theFieldName)
396 {
397   myIgnoringFieldList.erase(theFieldName);
398 }
399
400 /*!
401   \brief Gets list of field names which used as specific fields with ids or elements 
402   \return list of field names 
403 */
404 const std::set<std::string>& 
405 VISU_Vtk2MedConvertor
406 ::getIgnoringFieldList() const
407 {
408   return myIgnoringFieldList;
409 }
410
411 /*!
412   \brief Sets field name with point ids
413   \param theFieldName field name
414   \sa getPointDataFieldNameIDS()
415 */
416 void 
417 VISU_Vtk2MedConvertor
418 ::setPointDataFieldNameIDS( const string& theFieldName )
419 {
420   myPointDataFieldNameIDS = theFieldName;
421 }
422
423 /*!
424   \brief Gets field name with point ids
425   \return field name
426   \sa setPointDataFieldNameIDS()
427 */
428 const string& 
429 VISU_Vtk2MedConvertor
430 ::getPointDataFieldNameIDS() const
431 {
432   return myPointDataFieldNameIDS;
433 }
434
435 /*!
436   \brief Sets values of time stamps If this array is not specified values of time 
437   stamps are generated automatically ( 0, 1, 2 ... )
438   \param theTStamps vector of time stamps
439   \sa getTimeStamps()
440 */
441 void 
442 VISU_Vtk2MedConvertor
443 ::setTimeStamps( const TVectorDouble& theTStamps )
444 {
445   myTStamps = theTStamps;
446 }
447
448 /*!
449   \brief Gets values of time stamps If this array is not specified values of time 
450   stamps are generated automatically ( 0, 1, 2 ... )
451   \param theTStamps out vector of time stamps
452   \sa setTimeStamps()
453 */
454 void 
455 VISU_Vtk2MedConvertor
456 ::getTimeStamps( TVectorDouble& theTStamps ) const
457 {
458   theTStamps = myTStamps;
459 }
460
461 /*!
462   \brief Retrieves identifiers of cells from input data set corresponding to given type
463   \param theInput input data set
464   \param type type
465   \param array out array
466 */
467 void
468 VISU_Vtk2MedConvertor
469 ::GetIdsOfCellsOfType(vtkDataSet* theInput,
470                       const int type,
471                       vtkIntArray *array)
472 {
473   for (int cellId = 0; cellId < theInput->GetNumberOfCells(); cellId++)
474     if (theInput->GetCellType(cellId) == type)
475       array->InsertNextValue(cellId);
476 }
477
478 /*!
479   \brief Creates elements (private auxiliary method)
480   \return 0 if operation has been completed successfully, 1 otherwise
481 */
482 int
483 VISU_Vtk2MedConvertor
484 ::CreateElements(vtkDataSet* theInput,
485                  MED::PMeshInfo theMeshInfo,
486                  MED::PWrapper  theMed,
487                  vtkIntArray* theCellsMapper,
488                  MED::EEntiteMaillage theEntity,
489                  int theVTKGeom,
490                  int nbPointsInGeom,
491                  std::vector<int>& theNumberingConvertor,
492                  TGeom2CellIds& theGeom2CellIdMap)
493 {
494   bool aIdsConvert = (theNumberingConvertor.size() > 0);
495   vtkIntArray* aCellIds = vtkIntArray::New();
496   const MED::EConnectivite aConnType = MED::eNOD;
497
498   MED::TIntVector aConn;
499   MED::TIntVector aFamilyNums;// -1
500   MED::TIntVector aElemNums;
501   
502   this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
503   int nbElems = aCellIds->GetNumberOfTuples();
504   if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
505   aConn.reserve(nbElems*nbPointsInGeom);
506   if(nbElems>0){
507     TCellIds& aCellIdsMapper = theGeom2CellIdMap[VTK2MED(theVTKGeom)];
508     int* aPointer = aCellIds->GetPointer(0);
509     for(int i=0;i<nbElems;i++,aPointer++){
510       int aCellId = *aPointer;
511       aCellIdsMapper.push_back(aCellId);
512       vtkCell* aCell = theInput->GetCell(aCellId);
513       int nbPointsInCell = aCell->GetNumberOfPoints();
514       if(nbPointsInCell!=nbPointsInGeom){
515         cout << "Error in file=|" << __FILE__<<"| line:[" << __LINE__ << "]" << endl;
516         cout << "Must be "<<nbPointsInGeom<<" nodes in VTK Geometry:"<<theVTKGeom<<" element" << endl;
517         aCellIds->Delete();
518         return 1; // exit
519       }
520       aFamilyNums.push_back(-1);
521       for(int j=0;j<nbPointsInCell;j++){
522         if (aIdsConvert)
523           aConn.push_back(aCell->GetPointId(theNumberingConvertor[j])+1);
524         else
525           aConn.push_back(aCell->GetPointId(j)+1);
526       }
527       if(theCellsMapper){
528         if(theCellsMapper->GetNumberOfComponents()==2)
529           aElemNums.push_back(*theCellsMapper->GetPointer(aCellId*2));
530         else if(theCellsMapper->GetNumberOfComponents()==1)
531           aElemNums.push_back(*theCellsMapper->GetPointer(aCellId));
532       }
533     }
534     
535     
536     MED::PCellInfo aCellInfo = theMed->CrCellInfo(theMeshInfo,
537                                                   theEntity,
538                                                   VTK2MED(theVTKGeom),
539                                                   aConn,
540                                                   aConnType,
541                                                   aFamilyNums,
542                                                   aElemNums);
543     theMed->SetCellInfo(aCellInfo);
544   }
545   
546   aCellIds->Delete();
547   
548   return 0;
549 }
550
551 /*!
552   \brief Creates polygons (private auxiliary method)
553   \return 0 if operation has been completed successfully, 1 otherwise
554 */
555 int
556 VISU_Vtk2MedConvertor
557 ::CreatePolygons(vtkDataSet* theInput,
558                  MED::PMeshInfo theMeshInfo,
559                  MED::PWrapper  theMed,
560                  vtkIntArray* theCellsMapper,
561                  MED::EEntiteMaillage theEntity,
562                  TGeom2CellIds& theGeom2CellIdMap)
563 {
564   int theVTKGeom = VTK_POLYGON;
565   vtkIntArray* aCellIds = vtkIntArray::New();
566   const MED::EConnectivite aConnType = MED::eNOD;
567   
568   MED::TIntVector aConn;
569   MED::TIntVector aFamilyNums;// -1
570   MED::TIntVector aElemNums;
571   MED::TIntVector aPolygoneInds;
572   aPolygoneInds.push_back(1); // reference on the first element in the connectivities
573   
574   this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
575   int nbElems = aCellIds->GetNumberOfTuples();
576   if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
577   if(nbElems>0){
578     TCellIds& aCellIdsMapper = theGeom2CellIdMap[VTK2MED(theVTKGeom)];
579     int* aPointer = aCellIds->GetPointer(0);
580     for(int i=0;i<nbElems;i++,aPointer++){
581       int aCellId = *aPointer;
582       aCellIdsMapper.push_back(aCellId);
583       vtkCell* aCell = theInput->GetCell(aCellId);
584       int nbPointsInCell = aCell->GetNumberOfPoints();
585       aFamilyNums.push_back(-1);
586       int aPrevPos = aPolygoneInds.back();
587       aPolygoneInds.push_back(aPrevPos+nbPointsInCell);
588       for(int j=0;j<nbPointsInCell;j++)
589         aConn.push_back(aCell->GetPointId(j)+1);
590       if(theCellsMapper){
591         if(theCellsMapper->GetNumberOfComponents()==2)
592           aElemNums.push_back(*theCellsMapper->GetPointer(aCellId*2));
593         else if(theCellsMapper->GetNumberOfComponents()==1)
594           aElemNums.push_back(*theCellsMapper->GetPointer(aCellId));
595       }
596     }
597     
598     
599     MED::PPolygoneInfo aCellInfo = theMed->CrPolygoneInfo(theMeshInfo,
600                                                           theEntity,
601                                                           VTK2MED(theVTKGeom),
602                                                           aPolygoneInds,
603                                                           aConn,
604                                                           aConnType,
605                                                           aFamilyNums,
606                                                           aElemNums);
607     theMed->SetPolygoneInfo(aCellInfo);
608   }
609   
610   aCellIds->Delete();
611   
612   return 0;
613 }
614
615 /*!
616   \brief Creates polyedres (private auxiliary method)
617   \return 0 if operation has been completed successfully, 1 otherwise
618 */
619 int
620 VISU_Vtk2MedConvertor
621 ::CreatePolyedres(vtkDataSet* theInput,
622                   MED::PMeshInfo theMeshInfo,
623                   MED::PWrapper  theMed,
624                   vtkIntArray* theCellsMapper,
625                   MED::EEntiteMaillage theEntity,
626                   TGeom2CellIds& theGeom2CellIdMap)
627 {
628   int theVTKGeom = VTK_CONVEX_POINT_SET;
629   vtkIntArray* aCellIds = vtkIntArray::New();
630   const MED::EConnectivite aConnType = MED::eNOD;
631   
632   MED::TIntVector aConn;
633   MED::TIntVector aFamilyNums;// -1
634   MED::TIntVector aElemNums;
635   MED::TIntVector aPolyedreInds;
636   MED::TIntVector aPolyedreFaces;
637   
638   aPolyedreInds.push_back(1); // reference on the first element in the connectivities
639   aPolyedreFaces.push_back(1);
640   
641   this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
642   int nbElems = aCellIds->GetNumberOfTuples();
643   if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
644   if(nbElems>0){
645     TCellIds& aCellIdsMapper = theGeom2CellIdMap[VTK2MED(theVTKGeom)];
646     int* aPointer = aCellIds->GetPointer(0);
647     for(int i=0;i<nbElems;i++,aPointer++){
648       int aCellId = *aPointer;
649       aCellIdsMapper.push_back(aCellId);
650       vtkCell* aCell = theInput->GetCell(aCellId);
651       int nbPointsInCell = aCell->GetNumberOfPoints();
652       for(int j=0;j<nbPointsInCell;j++)
653         aConn.push_back(aCell->GetPointId(j)+1);
654       int aPrevPos = aPolyedreFaces.back();
655       aPolyedreFaces.push_back(aPrevPos + nbPointsInCell);
656       aPrevPos = aPolyedreInds.back();
657       aPolyedreInds.push_back(aPrevPos + 1/*aNbFaces*/);
658       aFamilyNums.push_back(-1);
659
660       if(theCellsMapper){
661         if(theCellsMapper->GetNumberOfComponents()==2)
662           aElemNums.push_back(*theCellsMapper->GetPointer(aCellId*2));
663         else if(theCellsMapper->GetNumberOfComponents()==1)
664           aElemNums.push_back(*theCellsMapper->GetPointer(aCellId));
665       }
666     }
667     
668     
669     MED::PPolyedreInfo aCellInfo = theMed->CrPolyedreInfo(theMeshInfo,
670                                                           theEntity,
671                                                           VTK2MED(theVTKGeom),
672                                                           aPolyedreInds,
673                                                           aPolyedreFaces,
674                                                           aConn,
675                                                           aConnType,
676                                                           aFamilyNums,
677                                                           aElemNums);
678     theMed->SetPolyedreInfo(aCellInfo);
679   }
680   
681   aCellIds->Delete();
682   
683   return 0;
684 }
685
686 /*!
687   \brief Converts geometry to med (private auxiliary method)
688   \return 0 if operation has been completed successfully, 1 otherwise
689 */
690 int
691 VISU_Vtk2MedConvertor
692 ::Geometry2MED(vtkDataSet* aInput,
693                MED::PWrapper myMed,
694                MED::PMeshInfo aMeshInfo,
695                TGeom2CellIds& outGeom2CellIdMap)
696 {
697   int aNbNodes = aInput->GetNumberOfPoints();
698   int aMeshDimension = aMeshInfo->GetDim();
699   // ----------------------- NODES -------------------------
700   vtkIntArray* aPointsMapper;
701   if(aInput->GetPointData())
702     aPointsMapper = dynamic_cast<vtkIntArray*>(aInput->GetPointData()->GetArray(myPointDataFieldNameIDS.c_str()));
703   
704   MED::TFloatVector aCoordinates(aNbNodes*aMeshDimension);
705   MED::TIntVector   anElemNumsNodes; // takes from VISU_POINTS_MAPPER array
706   MED::TIntVector  aFamilyNumsNodes;
707   MED::TStringVector aCoordNamesNodes;
708   MED::TStringVector aCoordUnitsNodes;
709
710   vtkFloatingPointType aPntCoord[3];
711   if(aPointsMapper){
712     int nbComp = aPointsMapper->GetNumberOfComponents();
713     int *aPointsMapperPtr = aPointsMapper->GetPointer(0);
714     for(int i=0;i<aNbNodes;i++){
715       aInput->GetPoint(i,aPntCoord);
716       aCoordinates[i*3]   = aPntCoord[0];
717       aCoordinates[i*3+1] = aPntCoord[1];
718       aCoordinates[i*3+2] = aPntCoord[2];
719       if(nbComp == 2){
720         anElemNumsNodes.push_back(*aPointsMapperPtr);
721         aPointsMapperPtr++;aPointsMapperPtr++;
722       }
723       else if (nbComp == 1){
724         anElemNumsNodes.push_back(*aPointsMapperPtr);
725         aPointsMapperPtr++;
726       }
727       else{
728         cout << "Error in file=|" << __FILE__<<"| line:[" << __LINE__ << "]" << endl;
729         cout << "Code must be adapted for more than 2 components array |VISU_POINTS_MAPPER|" << endl;
730         return 1;
731       }
732
733     }
734   } else {
735     for(int i=0;i<aNbNodes;i++){
736       aInput->GetPoint(i,aPntCoord);
737       aCoordinates[i*3]   = aPntCoord[0];
738       aCoordinates[i*3+1] = aPntCoord[1];
739       aCoordinates[i*3+2] = aPntCoord[2];
740     }
741   }
742   
743   
744   MED::PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo,
745                                                aCoordinates,
746                                                MED::eFULL_INTERLACE,
747                                                MED::eCART,
748                                                aCoordNamesNodes,
749                                                aCoordUnitsNodes,
750                                                aFamilyNumsNodes,
751                                                anElemNumsNodes);
752   myMed->SetNodeInfo(aNodeInfo);
753
754   vtkIntArray* aCellsMapper;
755   if(vtkCellData* aCD = aInput->GetCellData())
756     aCellsMapper = dynamic_cast<vtkIntArray*>(aCD->GetArray(myCellDataFieldNameIDS.c_str()));
757
758   if(MYDEBUG)
759   {
760     // debug info
761     // print all cell types in the input
762     vtkCellTypes* aCellTypes = vtkCellTypes::New();
763     aInput->GetCellTypes(aCellTypes);
764     cout << "Cell types in the input data:"<<endl;
765     for(int aNbCellType = 0;aNbCellType<aCellTypes->GetNumberOfTypes();aNbCellType++)
766       cout << (int)(aCellTypes->GetCellType(aNbCellType)) << endl;
767     aCellTypes->Delete();
768   }
769   
770   //----------------------
771   // Entity EDGES (eARETE)
772   //----------------------
773   vector<int> aNumberingConvertor;
774   {
775     // aVTKGeom->eSEG2
776     MED::EEntiteMaillage aEntity = MED::eMAILLE;//eARETE;
777     int aVTKGeom = 0;
778     int nbPointsInGeom = 0;
779
780     // aNumberingConvertor NULL - OK
781     aVTKGeom       = VTK_LINE;
782     nbPointsInGeom = 2;
783     CreateElements(aInput,
784                    aMeshInfo,
785                    myMed,
786                    aCellsMapper,
787                    aEntity,
788                    aVTKGeom,
789                    nbPointsInGeom,
790                    aNumberingConvertor,
791                    outGeom2CellIdMap);
792
793     // aNumberingConvertor NULL - OK
794     // debug info: checked - OK
795     aVTKGeom       = VTK_QUADRATIC_EDGE;
796     nbPointsInGeom = 3;
797     CreateElements(aInput,
798                    aMeshInfo,
799                    myMed,
800                    aCellsMapper,
801                    aEntity,
802                    aVTKGeom,
803                    nbPointsInGeom,
804                    aNumberingConvertor,
805                    outGeom2CellIdMap);
806     
807   }
808   //----------------------------
809   // Entity FACES (eFACE)
810   // eTRIA3,eQUAD4,eTRIA6,eQUAD8
811   // ePOLYGONE
812   //----------------------------
813   {
814     
815     MED::EEntiteMaillage aEntity = MED::eMAILLE;//MED::eFACE;
816     int aVTKGeom = 0;
817     int nbPointsInGeom = 0;
818
819     // debug info: checked - OK
820     aVTKGeom       = VTK_TRIANGLE;
821     aNumberingConvertor.clear();
822     nbPointsInGeom = 3;
823     CreateElements(aInput,
824                    aMeshInfo,
825                    myMed,
826                    aCellsMapper,
827                    aEntity,
828                    aVTKGeom,
829                    nbPointsInGeom,
830                    aNumberingConvertor,
831                    outGeom2CellIdMap);
832
833     // debug info: checked - OK
834     aVTKGeom       = VTK_QUAD;
835     nbPointsInGeom = 4;
836     aNumberingConvertor.clear();
837     CreateElements(aInput,
838                    aMeshInfo,
839                    myMed,
840                    aCellsMapper,
841                    aEntity,
842                    aVTKGeom,
843                    nbPointsInGeom,
844                    aNumberingConvertor,
845                    outGeom2CellIdMap);
846
847
848     // debug info: checked - OK
849     aVTKGeom       = VTK_QUADRATIC_TRIANGLE;
850     nbPointsInGeom = 6;
851     aNumberingConvertor.clear();
852     CreateElements(aInput,
853                    aMeshInfo,
854                    myMed,
855                    aCellsMapper,
856                    aEntity,
857                    aVTKGeom,
858                    nbPointsInGeom,
859                    aNumberingConvertor,
860                    outGeom2CellIdMap);
861
862     aVTKGeom       = VTK_QUADRATIC_QUAD;
863     nbPointsInGeom = 8;
864     aNumberingConvertor.clear();
865     // 0,3,2,1,7,6,5,4
866     CreateElements(aInput,
867                    aMeshInfo,
868                    myMed,
869                    aCellsMapper,
870                    aEntity,
871                    aVTKGeom,
872                    nbPointsInGeom,
873                    aNumberingConvertor,
874                    outGeom2CellIdMap);
875
876     // debug info: checked - OK
877     CreatePolygons(aInput,
878                    aMeshInfo,
879                    myMed,
880                    aCellsMapper,
881                    aEntity,
882                    outGeom2CellIdMap);
883     
884   }
885   //----------------------------
886   // Entity CELLS (eMAILLE)
887   // eTETRA4,eHEXA8,ePENTA6,ePYRA5,
888   // eTETRA10,eHEXA20,ePOLYEDRE
889   //----------------------------
890   {
891     
892     MED::EEntiteMaillage aEntity = MED::eMAILLE;
893     int aVTKGeom = 0;
894     int nbPointsInGeom = 0;
895
896     aVTKGeom       = VTK_TETRA;
897     nbPointsInGeom = 4;
898     aNumberingConvertor.clear();
899     aNumberingConvertor.push_back(0);
900     aNumberingConvertor.push_back(2);
901     aNumberingConvertor.push_back(1);
902     aNumberingConvertor.push_back(3);
903     CreateElements(aInput,
904                    aMeshInfo,
905                    myMed,
906                    aCellsMapper,
907                    aEntity,
908                    aVTKGeom,
909                    nbPointsInGeom,
910                    aNumberingConvertor,
911                    outGeom2CellIdMap);
912     
913     aVTKGeom       = VTK_HEXAHEDRON;
914     nbPointsInGeom = 8;
915     aNumberingConvertor.clear();
916     // 0,3,2,1,4,7,6,5
917     CreateElements(aInput,
918                    aMeshInfo,
919                    myMed,
920                    aCellsMapper,
921                    aEntity,
922                    aVTKGeom,
923                    nbPointsInGeom,
924                    aNumberingConvertor,
925                    outGeom2CellIdMap);
926
927     aVTKGeom       = VTK_WEDGE;
928     nbPointsInGeom = 6;
929     aNumberingConvertor.clear();
930     CreateElements(aInput,
931                    aMeshInfo,
932                    myMed,
933                    aCellsMapper,
934                    aEntity,
935                    aVTKGeom,
936                    nbPointsInGeom,
937                    aNumberingConvertor,
938                    outGeom2CellIdMap);
939     
940     aVTKGeom       = VTK_PYRAMID;
941     nbPointsInGeom = 5;
942     aNumberingConvertor.clear();
943     aNumberingConvertor.push_back(0);
944     aNumberingConvertor.push_back(3);
945     aNumberingConvertor.push_back(2);
946     aNumberingConvertor.push_back(1);
947     aNumberingConvertor.push_back(4);
948     CreateElements(aInput,
949                    aMeshInfo,
950                    myMed,
951                    aCellsMapper,
952                    aEntity,
953                    aVTKGeom,
954                    nbPointsInGeom,
955                    aNumberingConvertor,
956                    outGeom2CellIdMap);
957
958     aVTKGeom       = VTK_QUADRATIC_TETRA;
959     nbPointsInGeom = 10;
960     aNumberingConvertor.clear();
961     // 0,2,1,3,6,5,4,7,9,8
962     CreateElements(aInput,
963                    aMeshInfo,
964                    myMed,
965                    aCellsMapper,
966                    aEntity,
967                    aVTKGeom,
968                    nbPointsInGeom,
969                    aNumberingConvertor,
970                    outGeom2CellIdMap);
971     
972     
973     aVTKGeom       = VTK_QUADRATIC_HEXAHEDRON;
974     nbPointsInGeom = 20;
975     aNumberingConvertor.clear();
976     // 0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17
977     CreateElements(aInput,
978                    aMeshInfo,
979                    myMed,
980                    aCellsMapper,
981                    aEntity,
982                    aVTKGeom,
983                    nbPointsInGeom,
984                    aNumberingConvertor,
985                    outGeom2CellIdMap);
986
987     // debug info: checked OK
988     CreatePolyedres(aInput,
989                     aMeshInfo,
990                     myMed,
991                     aCellsMapper,
992                     aEntity,
993                     outGeom2CellIdMap);
994   }
995   
996
997   return 0;
998 }
999
1000 /*!
1001   \brief Converts data to med (private auxiliary method)
1002   \return 0 if operation has been completed successfully, 1 otherwise
1003 */
1004 int
1005 VISU_Vtk2MedConvertor
1006 ::Data2MED(std::vector<vtkDataSet*> theListForAdd,
1007            MED::PWrapper myMed,
1008            MED::PMeshInfo theMeshInfo,
1009            TGeom2CellIds& theGeom2CellIdMap)
1010 {
1011   typedef std::vector<vtkPointData*> TPDVec;
1012   typedef std::vector<vtkCellData*> TCDVec;  
1013   typedef std::map<std::string,TPDVec> TNameToPointData;
1014   typedef std::map<std::string,TCDVec> TNameToCellData;
1015
1016   TNameToPointData aName2PointData;
1017   TNameToCellData  aName2CellData;
1018   
1019   MED::TErr* theErrCode = new MED::TErr();
1020   MED::EGeometrieElement geomType;
1021   MED::EEntiteMaillage   entity;
1022
1023   // prepare data to create time stamps
1024   const MED::TInt aNbGauss = 1;
1025   MED::TProfileInfo::TInfo aTInfo("",0);
1026   MED::PProfileInfo aPProfileInfo = myMed->CrProfileInfo( aTInfo );
1027   
1028   MED::TGeom2Size    aGeom2Size;
1029   MED::TGeom2NbGauss aGeom2NbGauss;
1030   MED::TGeom2Profile aTGeom2Profile;
1031
1032   int nbPointsInFirstData = 0;
1033   if(theListForAdd.size()>0)
1034     nbPointsInFirstData = (theListForAdd[0])->GetNumberOfPoints();
1035
1036   int nbClasses = theListForAdd.size();
1037   
1038   for(int iClass=0;iClass<nbClasses;iClass++){
1039     vtkDataSet* aClassPtr = theListForAdd[iClass];
1040     if(aClassPtr->GetNumberOfPoints() != nbPointsInFirstData){
1041       cout << "Warning in PointData: Some vtk file consist of number of points( " <<aClassPtr->GetNumberOfPoints()
1042            << ") not equal number of points in first file("<<nbPointsInFirstData<<")"<<endl;
1043       cout << "This data will be lost." << endl;
1044       continue;
1045     }
1046
1047     if(vtkPointData* aPD = aClassPtr->GetPointData()){
1048       int nbArrays = aPD->GetNumberOfArrays();
1049       
1050       for(int aArrNum=0;aArrNum<nbArrays;aArrNum++)
1051       {
1052         vtkDataArray* aArr = aPD->GetArray(aArrNum);
1053         std::string aName = aArr->GetName();
1054         std::set<std::string>::const_iterator aIgnoreIter = myIgnoringFieldList.find(aName);
1055         if(aIgnoreIter!=myIgnoringFieldList.end())
1056           continue;
1057         (aName2PointData[aName]).push_back(aPD);
1058       }
1059     }
1060
1061     if(vtkCellData* aCD = aClassPtr->GetCellData()){
1062       int nbArrays = aCD->GetNumberOfArrays();
1063       
1064       for(int aArrNum=0;aArrNum<nbArrays;aArrNum++)
1065       {
1066         vtkDataArray* aArr = aCD->GetArray(aArrNum);
1067         std::string aName = aArr->GetName();
1068         std::set<std::string>::const_iterator aIgnoreIter = myIgnoringFieldList.find(aName);
1069         if(aIgnoreIter!=myIgnoringFieldList.end())
1070           continue;
1071         (aName2CellData[aName]).push_back(aCD);
1072       }
1073     }
1074   }
1075
1076
1077   // PointData
1078   int aLastField = 0;
1079   {
1080     geomType = MED::ePOINT1;
1081     entity   = MED::eNOEUD;
1082     aGeom2Size[geomType]    = nbPointsInFirstData;
1083     aGeom2NbGauss[geomType] = aNbGauss;
1084     aTGeom2Profile[geomType]= aPProfileInfo;
1085     
1086     TNameToPointData::const_iterator aIter = aName2PointData.begin();
1087     for(int iField=1;aIter!=aName2PointData.end();aIter++,iField++){
1088       std::string aFieldName = aIter->first;
1089       TPDVec aPD2Vec = (aIter->second);
1090       int nbComp = 0;
1091       if(aPD2Vec.size() >0 ){
1092         if(vtkPointData* aPD0  = aPD2Vec[0]){
1093           if(vtkDataArray* aArr0 = aPD0->GetArray(aFieldName.c_str()))
1094             nbComp = aArr0->GetNumberOfComponents();
1095         }
1096       }
1097       
1098       MED::PFieldInfo aFieldInfo = myMed->CrFieldInfo(theMeshInfo,
1099                                                       nbComp);
1100
1101       string aFieldName_PD = "Point " + aFieldName;
1102       aFieldInfo->SetName(aFieldName_PD.c_str());
1103       
1104       myMed->SetFieldInfo(aFieldInfo);
1105
1106       TPDVec::const_iterator aPDIter = aPD2Vec.begin();
1107       for(int iTStamp=0;aPDIter!=aPD2Vec.end();aPDIter++,iTStamp++){
1108         vtkPointData* aPD = *aPDIter;
1109         vtkDataArray* aArr = aPD->GetArray(aFieldName.c_str());
1110         MED::TFloat aTS = iTStamp < (int)myTStamps.size() ? myTStamps[ iTStamp ] : iTStamp;
1111         MED::PTimeStampInfo aTempTimeStampInfo = myMed->CrTimeStampInfo (aFieldInfo,
1112                                                                          entity,
1113                                                                          aGeom2Size,
1114                                                                          aGeom2NbGauss,
1115                                                                          iTStamp,
1116                                                                          iTStamp,
1117                                                                          aTS);
1118         
1119         MED::PTimeStampVal aTempTimeStampVal = myMed->CrTimeStampVal (aTempTimeStampInfo,
1120                                                                       aTGeom2Profile);
1121         
1122         MED::TMeshValue& aTMeshValue = aTempTimeStampVal->GetMeshValue(geomType);
1123         
1124         MED::TValue& aValue = aTMeshValue.myValue; // float
1125         int nbValues = aValue.size();
1126         for(int i=0;i<nbValues;i++){
1127           aValue[i] = *(float*)(aArr->GetVoidPointer(i));
1128         }
1129         
1130         myMed->SetTimeStamp( aTempTimeStampVal, theErrCode);
1131         if(*theErrCode==0){
1132           cout << "Error in "<<__FILE__<<"["<<__LINE__<<"] in method SetTimeStamp(...)"<<endl;
1133           return 1;
1134         }
1135       }
1136       aLastField = iField;
1137     }
1138   }
1139   // CellData
1140   {
1141     MED::TEntityInfo aEntityInfo = myMed->GetEntityInfo(theMeshInfo);
1142     aGeom2Size.clear();
1143     aGeom2NbGauss.clear();
1144     aTGeom2Profile.clear();
1145     aGeom2Size = aEntityInfo[ MED::eMAILLE ];
1146     entity   = MED::eMAILLE;
1147     MED::TGeom2Size::iterator geom_nb;
1148     for ( geom_nb = aGeom2Size.begin(); geom_nb != aGeom2Size.end(); ++geom_nb ) { // loop on geometric types of cell
1149       aGeom2NbGauss[ geom_nb->first ] = aNbGauss;
1150       aTGeom2Profile[ geom_nb->first ] = aPProfileInfo;
1151     }
1152
1153     
1154     TNameToCellData::const_iterator aIter = aName2CellData.begin();
1155     for(int iField=1;aIter!=aName2CellData.end();aIter++,iField++){
1156       std::string aFieldName = aIter->first;
1157       TCDVec aCD2Vec = (aIter->second);
1158       int nbComp = 0;
1159       if(aCD2Vec.size() >0 ){
1160         if(vtkCellData* aCD0  = aCD2Vec[0]){
1161           if(vtkDataArray* aArr0 = aCD0->GetArray(aFieldName.c_str()))
1162             nbComp = aArr0->GetNumberOfComponents();
1163         }
1164       }
1165       
1166       MED::PFieldInfo aFieldInfo = myMed->CrFieldInfo(theMeshInfo,
1167                                                       nbComp);
1168
1169       string aFieldName_CD = "Cell " + aFieldName;
1170       aFieldInfo->SetName(aFieldName_CD.c_str());
1171       
1172       myMed->SetFieldInfo(aFieldInfo);
1173
1174       TCDVec::const_iterator aCDIter = aCD2Vec.begin();
1175       for(int iTStamp=0;aCDIter!=aCD2Vec.end();aCDIter++,iTStamp++){
1176         vtkCellData* aCD = *aCDIter;
1177         vtkDataArray* aArr = aCD->GetArray(aFieldName.c_str());
1178         MED::TFloat aTS = iTStamp < (int)myTStamps.size() ? myTStamps[ iTStamp ] : iTStamp;
1179         MED::PTimeStampInfo aTempTimeStampInfo = myMed->CrTimeStampInfo (aFieldInfo,
1180                                                                          entity,
1181                                                                          aGeom2Size,
1182                                                                          aGeom2NbGauss,
1183                                                                          iTStamp,
1184                                                                          iTStamp,
1185                                                                          aTS);
1186         
1187         MED::PTimeStampVal aTempTimeStampVal = myMed->CrTimeStampVal (aTempTimeStampInfo,
1188                                                                       aTGeom2Profile);
1189
1190         for ( geom_nb = aGeom2Size.begin(); geom_nb != aGeom2Size.end(); ++geom_nb ) { // loop on geometric types of cell
1191           geomType = geom_nb->first;
1192           TCellIds& aCellIds = theGeom2CellIdMap[geomType];
1193           
1194           MED::TMeshValue& aTMeshValue = aTempTimeStampVal->GetMeshValue(geomType);
1195           
1196           MED::TValue& aValue = aTMeshValue.myValue; // float
1197           int nbValues = aValue.size();
1198           int nbCellIds = aCellIds.size();
1199           if(nbValues!=nbCellIds*nbComp){
1200             cout << "Warning in "<<__FILE__<<"["<<__LINE__<<"] the data for geometry:"<<geomType<<" will be ignored"<<endl;
1201             continue;
1202           }
1203           if(MYDEBUG_VALUES) cout << "Geom["<<geomType<<"]"<<endl;
1204           for(int i=0;i<nbCellIds;i++){
1205             if(MYDEBUG_VALUES) cout << "\t|";
1206             for(int iComp=0;iComp<nbComp;iComp++){
1207               aValue[nbComp*i+iComp] = *(float*)(aArr->GetVoidPointer(nbComp*aCellIds[i]+iComp));
1208               if(MYDEBUG_VALUES) cout << aValue[nbComp*i+iComp] << "   ";
1209             }
1210             if(MYDEBUG_VALUES) cout << "|" << endl;
1211           }
1212           
1213           myMed->SetTimeStamp( aTempTimeStampVal, theErrCode);
1214           if(*theErrCode==0){
1215             cout << "Error in "<<__FILE__<<"["<<__LINE__<<"] in method SetTimeStamp(...)"<<endl;
1216             return 1;
1217           }
1218         }
1219       }
1220     }
1221   }
1222   
1223   
1224   return 0;
1225 }
1226
1227 /*!
1228   \brief Writes data to MED file
1229   \return 0 if operation has been completed successfully, 1 otherwise
1230 */
1231 int
1232 VISU_Vtk2MedConvertor
1233 ::Execute()
1234 {
1235   int aStatus = 1;
1236   if (myFirstVTKFileName.size() == 0 ||
1237       myMEDFileName.size() == 0)
1238   {
1239     cout << "Error! Bad input file names output med file name or vtk file name."<<endl;
1240     cout << "Exit."<<endl;
1241     return 1;
1242   }
1243   
1244   MED::PWrapper myMed;
1245   MED::PMeshInfo aMeshInfo;
1246   int aMeshDimension = 3;
1247   int aSpaceDimension = 3;
1248   myMed = CrWrapper(myMEDFileName.c_str(),myVersion);
1249   aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,myMeshName.c_str());
1250   myMed->SetMeshInfo(aMeshInfo);
1251     
1252   {
1253     typedef vtkDataSetReader TReader;
1254     TReader* aReader = TReader::New();
1255     aReader->SetFileName(myFirstVTKFileName.c_str());
1256     aReader->Update();
1257     TGeom2CellIds myGeom2CellIds;
1258     
1259     typedef std::vector<vtkDataSet*> TListUG;
1260     TListUG aList;
1261
1262     if(aReader->IsFilePolyData())
1263     {
1264       if(MYDEBUG) cout << "PolyData" << endl;
1265       typedef vtkPolyData TCommonType;
1266       TCommonType* aInput = aReader->GetPolyDataOutput();
1267
1268       aStatus = Geometry2MED(aInput,
1269                              myMed,
1270                              aMeshInfo,
1271                              myGeom2CellIds);
1272       
1273     
1274       TCommonType* aUG1 = TCommonType::New();
1275       aUG1->ShallowCopy(aInput);
1276       vtkDataSet* aTmp1 = dynamic_cast<vtkDataSet*>(aUG1);
1277       aList.push_back(aTmp1);
1278
1279       TVectorString::iterator aFilesIter = myDataVTKFileNames.begin();
1280       for(;aFilesIter!=myDataVTKFileNames.end();aFilesIter++){
1281         aReader->SetFileName((*aFilesIter).c_str());
1282         aReader->Update();
1283         TCommonType* aUG2 = TCommonType::New();
1284         aUG2->ShallowCopy(aReader->GetPolyDataOutput());
1285         vtkDataSet* aTmp2 = dynamic_cast<vtkDataSet*>(aUG2);
1286         aList.push_back(aTmp2);
1287       }
1288     } else if (aReader->IsFileUnstructuredGrid()){
1289       if (MYDEBUG) cout << "UnstructuredGrid" << endl;
1290       typedef vtkUnstructuredGrid TCommonType;
1291       TCommonType* aInput = aReader->GetUnstructuredGridOutput();
1292
1293       aStatus = Geometry2MED(aInput,
1294                              myMed,
1295                              aMeshInfo,
1296                              myGeom2CellIds);
1297       
1298     
1299       TCommonType* aUG1 = TCommonType::New();
1300       aUG1->ShallowCopy(aInput);
1301       vtkDataSet* aTmp1 = dynamic_cast<vtkDataSet*>(aUG1);
1302       aList.push_back(aTmp1);
1303
1304       TVectorString::iterator aFilesIter = myDataVTKFileNames.begin();
1305       for(;aFilesIter!=myDataVTKFileNames.end();aFilesIter++){
1306         aReader->SetFileName((*aFilesIter).c_str());
1307         aReader->Update();
1308         TCommonType* aUG2 = TCommonType::New();
1309         aUG2->ShallowCopy(aReader->GetUnstructuredGridOutput());
1310         vtkDataSet* aTmp2 = dynamic_cast<vtkDataSet*>(aUG2);
1311         aList.push_back(aTmp2);
1312       }
1313     } 
1314
1315     Data2MED(aList,
1316              myMed,
1317              aMeshInfo,
1318              myGeom2CellIds);
1319     
1320     
1321     // clear aList by removing of unstructured grids
1322     TListUG::iterator aIter = aList.begin();
1323     for(;aIter!=aList.end();aIter++)
1324       (*aIter)->Delete();
1325     
1326     aReader->Delete();
1327   }
1328   
1329   return aStatus;
1330 }