1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VISU_Vtk2MedConvertor.cxx
21 // Author : Eugeny NIKOLAEV, Open CASCADE SAS
23 #include "VISU_Vtk2MedConvertor.hxx"
27 #include <qfileinfo.h>
28 #include <qstringlist.h>
31 #include <vtkSmartPointer.h>
32 #include <vtkDataReader.h>
34 #include <vtkStructuredPointsReader.h>
35 #include <vtkStructuredGridReader.h>
36 #include <vtkRectilinearGridReader.h>
37 #include <vtkUnstructuredGridReader.h>
38 #include <vtkPolyDataReader.h>
39 #include <vtkDataSetReader.h>
41 #include <vtkPointSet.h>
42 #include <vtkDataSet.h>
43 #include <vtkPolyData.h>
44 #include <vtkDataObject.h>
45 #include <vtkCellTypes.h>
46 #include <vtkCellType.h>
48 #include <vtkCellData.h>
49 #include <vtkPointData.h>
51 #include <vtkUnstructuredGrid.h>
52 #include <vtkFloatArray.h>
54 // MED Warpper includes
55 #include "MED_Factory.hxx"
67 static int MYDEBUG = 0;
68 static int MYDEBUG_VALUES = 0;
70 static int MYDEBUG = 0;
71 static int MYDEBUG_VALUES = 0;
78 *>( );define VTK_EMPTY_CELL 0
80 #define VTK_POLY_VERTEX 2
82 #define VTK_POLY_LINE 4
83 #define VTK_TRIANGLE 5
84 #define VTK_TRIANGLE_STRIP 6
90 #define VTK_HEXAHEDRON 12
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
107 static MED::EGeometrieElement VTK2MED( const int theGeom )
109 // Ignoring vtk types:
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
123 MED::EGeometrieElement aEmptyGeom = MED::EGeometrieElement(-1);
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;
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...
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
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.
166 VISU_Vtk2MedConvertor
167 ::VISU_Vtk2MedConvertor():
168 myVersion(MED::eV2_2),
169 myMeshName("vtk2med")
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");
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.
185 \param theMEDFileName output med file name
186 \param theFirstVTKFileName first vtk file name
188 VISU_Vtk2MedConvertor
189 ::VISU_Vtk2MedConvertor(const string theMEDFileName,
190 const string theFirstVTKFileName):
191 myVersion(MED::eV2_2),
192 myMeshName("vtk2med")
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");
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.
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
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")
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");
233 \brief Adds field names, which used as specific fields with ids or elements
234 (or something else). (Default:
\93VISU_CELLS_MAPPER
\94,
\94VISU_POINTS_MAPPER
\94,
\94VISU_FILED
\94)
235 \param theFieldName field name
236 \sa eraseFromIgnoringFieldList()
239 VISU_Vtk2MedConvertor
240 ::addToIgnoringFieldList( const string& theFieldName )
242 myIgnoringFieldList.insert(theFieldName);
246 \brief Sets the output MED file name
247 \param theFileName file name
251 VISU_Vtk2MedConvertor
252 ::setMEDFileName( const string theFileName )
254 myMEDFileName=theFileName;
258 \brief Gets the output MED file name
259 \return output MED file name
263 VISU_Vtk2MedConvertor
264 ::getMEDFileName() const
266 return myMEDFileName;
270 \brief Sets the first input vtk file name
271 \param theFileName file name
272 \sa getFirstVTKFileName()
275 VISU_Vtk2MedConvertor
276 ::setFirstVTKFileName( const string theFileName )
278 myFirstVTKFileName=theFileName;
282 \brief Fets the first input vtk file name
283 \return first input vtk file name
284 \sa setFirstVTKFileName()
287 VISU_Vtk2MedConvertor
288 ::getFirstVTKFileName() const
290 return myFirstVTKFileName;
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()
299 VISU_Vtk2MedConvertor
300 ::setDataVTKFileNames( const TVectorString theFileNames )
302 myDataVTKFileNames = theFileNames;
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()
311 VISU_Vtk2MedConvertor
312 ::getDataVTKFileNames( TVectorString& theDataVTKFileNames ) const
314 theDataVTKFileNames = myDataVTKFileNames;
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
322 VISU_Vtk2MedConvertor
323 ::setVersion( const MED::EVersion theVersion )
325 myVersion = theVersion;
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
333 VISU_Vtk2MedConvertor
340 \brief Sets output mesh name. (
\93vtk2med
\94 - default)
341 \param theMeshName mesh name
345 VISU_Vtk2MedConvertor
346 ::setMeshName( const string theMeshName )
348 myMeshName = theMeshName;
352 \brief Gets output mesh name. (
\93vtk2med
\94 - default)
357 VISU_Vtk2MedConvertor
358 ::getMeshName() const
364 \brief Sets field name with cell ids (Default - VISU_CELLS_MAPPER)
365 \param theFieldName field name
366 \sa getCellDataFieldNameIDS
369 VISU_Vtk2MedConvertor
370 ::setCellDataFieldNameIDS( const string& theFieldName )
372 myCellDataFieldNameIDS = theFieldName;
376 \brief Gets field name with cell ids (Default - VISU_CELLS_MAPPER)
378 \sa setCellDataFieldNameIDS()
381 VISU_Vtk2MedConvertor
382 ::getCellDataFieldNameIDS() const
384 return myCellDataFieldNameIDS;
388 \brief Erases field names which used as specific fields with ids or elements
390 \param theFieldName field name
391 \sa addToIgnoringFieldList()
394 VISU_Vtk2MedConvertor
395 ::eraseFromIgnoringFieldList(const string& theFieldName)
397 myIgnoringFieldList.erase(theFieldName);
401 \brief Gets list of field names which used as specific fields with ids or elements
402 \return list of field names
404 const std::set<std::string>&
405 VISU_Vtk2MedConvertor
406 ::getIgnoringFieldList() const
408 return myIgnoringFieldList;
412 \brief Sets field name with point ids
413 \param theFieldName field name
414 \sa getPointDataFieldNameIDS()
417 VISU_Vtk2MedConvertor
418 ::setPointDataFieldNameIDS( const string& theFieldName )
420 myPointDataFieldNameIDS = theFieldName;
424 \brief Gets field name with point ids
426 \sa setPointDataFieldNameIDS()
429 VISU_Vtk2MedConvertor
430 ::getPointDataFieldNameIDS() const
432 return myPointDataFieldNameIDS;
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
442 VISU_Vtk2MedConvertor
443 ::setTimeStamps( const TVectorDouble& theTStamps )
445 myTStamps = theTStamps;
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
455 VISU_Vtk2MedConvertor
456 ::getTimeStamps( TVectorDouble& theTStamps ) const
458 theTStamps = myTStamps;
462 \brief Retrieves identifiers of cells from input data set corresponding to given type
463 \param theInput input data set
465 \param array out array
468 VISU_Vtk2MedConvertor
469 ::GetIdsOfCellsOfType(vtkDataSet* theInput,
473 for (int cellId = 0; cellId < theInput->GetNumberOfCells(); cellId++)
474 if (theInput->GetCellType(cellId) == type)
475 array->InsertNextValue(cellId);
479 \brief Creates elements (private auxiliary method)
480 \return 0 if operation has been completed successfully, 1 otherwise
483 VISU_Vtk2MedConvertor
484 ::CreateElements(vtkDataSet* theInput,
485 MED::PMeshInfo theMeshInfo,
486 MED::PWrapper theMed,
487 vtkIntArray* theCellsMapper,
488 MED::EEntiteMaillage theEntity,
491 std::vector<int>& theNumberingConvertor,
492 TGeom2CellIds& theGeom2CellIdMap)
494 bool aIdsConvert = (theNumberingConvertor.size() > 0);
495 vtkIntArray* aCellIds = vtkIntArray::New();
496 const MED::EConnectivite aConnType = MED::eNOD;
498 MED::TIntVector aConn;
499 MED::TIntVector aFamilyNums;// -1
500 MED::TIntVector aElemNums;
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);
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;
520 aFamilyNums.push_back(-1);
521 for(int j=0;j<nbPointsInCell;j++){
523 aConn.push_back(aCell->GetPointId(theNumberingConvertor[j])+1);
525 aConn.push_back(aCell->GetPointId(j)+1);
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));
536 MED::PCellInfo aCellInfo = theMed->CrCellInfo(theMeshInfo,
543 theMed->SetCellInfo(aCellInfo);
552 \brief Creates polygons (private auxiliary method)
553 \return 0 if operation has been completed successfully, 1 otherwise
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)
564 int theVTKGeom = VTK_POLYGON;
565 vtkIntArray* aCellIds = vtkIntArray::New();
566 const MED::EConnectivite aConnType = MED::eNOD;
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
574 this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
575 int nbElems = aCellIds->GetNumberOfTuples();
576 if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
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);
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));
599 MED::PPolygoneInfo aCellInfo = theMed->CrPolygoneInfo(theMeshInfo,
607 theMed->SetPolygoneInfo(aCellInfo);
616 \brief Creates polyedres (private auxiliary method)
617 \return 0 if operation has been completed successfully, 1 otherwise
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)
628 int theVTKGeom = VTK_CONVEX_POINT_SET;
629 vtkIntArray* aCellIds = vtkIntArray::New();
630 const MED::EConnectivite aConnType = MED::eNOD;
632 MED::TIntVector aConn;
633 MED::TIntVector aFamilyNums;// -1
634 MED::TIntVector aElemNums;
635 MED::TIntVector aPolyedreInds;
636 MED::TIntVector aPolyedreFaces;
638 aPolyedreInds.push_back(1); // reference on the first element in the connectivities
639 aPolyedreFaces.push_back(1);
641 this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
642 int nbElems = aCellIds->GetNumberOfTuples();
643 if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
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);
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));
669 MED::PPolyedreInfo aCellInfo = theMed->CrPolyedreInfo(theMeshInfo,
678 theMed->SetPolyedreInfo(aCellInfo);
687 \brief Converts geometry to med (private auxiliary method)
688 \return 0 if operation has been completed successfully, 1 otherwise
691 VISU_Vtk2MedConvertor
692 ::Geometry2MED(vtkDataSet* aInput,
694 MED::PMeshInfo aMeshInfo,
695 TGeom2CellIds& outGeom2CellIdMap)
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()));
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;
710 vtkFloatingPointType aPntCoord[3];
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];
720 anElemNumsNodes.push_back(*aPointsMapperPtr);
721 aPointsMapperPtr++;aPointsMapperPtr++;
723 else if (nbComp == 1){
724 anElemNumsNodes.push_back(*aPointsMapperPtr);
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;
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];
744 MED::PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo,
746 MED::eFULL_INTERLACE,
752 myMed->SetNodeInfo(aNodeInfo);
754 vtkIntArray* aCellsMapper;
755 if(vtkCellData* aCD = aInput->GetCellData())
756 aCellsMapper = dynamic_cast<vtkIntArray*>(aCD->GetArray(myCellDataFieldNameIDS.c_str()));
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();
770 //----------------------
771 // Entity EDGES (eARETE)
772 //----------------------
773 vector<int> aNumberingConvertor;
776 MED::EEntiteMaillage aEntity = MED::eMAILLE;//eARETE;
778 int nbPointsInGeom = 0;
780 // aNumberingConvertor NULL - OK
783 CreateElements(aInput,
793 // aNumberingConvertor NULL - OK
794 // debug info: checked - OK
795 aVTKGeom = VTK_QUADRATIC_EDGE;
797 CreateElements(aInput,
808 //----------------------------
809 // Entity FACES (eFACE)
810 // eTRIA3,eQUAD4,eTRIA6,eQUAD8
812 //----------------------------
815 MED::EEntiteMaillage aEntity = MED::eMAILLE;//MED::eFACE;
817 int nbPointsInGeom = 0;
819 // debug info: checked - OK
820 aVTKGeom = VTK_TRIANGLE;
821 aNumberingConvertor.clear();
823 CreateElements(aInput,
833 // debug info: checked - OK
836 aNumberingConvertor.clear();
837 CreateElements(aInput,
848 // debug info: checked - OK
849 aVTKGeom = VTK_QUADRATIC_TRIANGLE;
851 aNumberingConvertor.clear();
852 CreateElements(aInput,
862 aVTKGeom = VTK_QUADRATIC_QUAD;
864 aNumberingConvertor.clear();
866 CreateElements(aInput,
876 // debug info: checked - OK
877 CreatePolygons(aInput,
885 //----------------------------
886 // Entity CELLS (eMAILLE)
887 // eTETRA4,eHEXA8,ePENTA6,ePYRA5,
888 // eTETRA10,eHEXA20,ePOLYEDRE
889 //----------------------------
892 MED::EEntiteMaillage aEntity = MED::eMAILLE;
894 int nbPointsInGeom = 0;
896 aVTKGeom = VTK_TETRA;
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,
913 aVTKGeom = VTK_HEXAHEDRON;
915 aNumberingConvertor.clear();
917 CreateElements(aInput,
927 aVTKGeom = VTK_WEDGE;
929 aNumberingConvertor.clear();
930 CreateElements(aInput,
940 aVTKGeom = VTK_PYRAMID;
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,
958 aVTKGeom = VTK_QUADRATIC_TETRA;
960 aNumberingConvertor.clear();
961 // 0,2,1,3,6,5,4,7,9,8
962 CreateElements(aInput,
973 aVTKGeom = VTK_QUADRATIC_HEXAHEDRON;
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,
987 // debug info: checked OK
988 CreatePolyedres(aInput,
1001 \brief Converts data to med (private auxiliary method)
1002 \return 0 if operation has been completed successfully, 1 otherwise
1005 VISU_Vtk2MedConvertor
1006 ::Data2MED(std::vector<vtkDataSet*> theListForAdd,
1007 MED::PWrapper myMed,
1008 MED::PMeshInfo theMeshInfo,
1009 TGeom2CellIds& theGeom2CellIdMap)
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;
1016 TNameToPointData aName2PointData;
1017 TNameToCellData aName2CellData;
1019 MED::TErr* theErrCode = new MED::TErr();
1020 MED::EGeometrieElement geomType;
1021 MED::EEntiteMaillage entity;
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 );
1028 MED::TGeom2Size aGeom2Size;
1029 MED::TGeom2NbGauss aGeom2NbGauss;
1030 MED::TGeom2Profile aTGeom2Profile;
1032 int nbPointsInFirstData = 0;
1033 if(theListForAdd.size()>0)
1034 nbPointsInFirstData = (theListForAdd[0])->GetNumberOfPoints();
1036 int nbClasses = theListForAdd.size();
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;
1047 if(vtkPointData* aPD = aClassPtr->GetPointData()){
1048 int nbArrays = aPD->GetNumberOfArrays();
1050 for(int aArrNum=0;aArrNum<nbArrays;aArrNum++)
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())
1057 (aName2PointData[aName]).push_back(aPD);
1061 if(vtkCellData* aCD = aClassPtr->GetCellData()){
1062 int nbArrays = aCD->GetNumberOfArrays();
1064 for(int aArrNum=0;aArrNum<nbArrays;aArrNum++)
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())
1071 (aName2CellData[aName]).push_back(aCD);
1080 geomType = MED::ePOINT1;
1081 entity = MED::eNOEUD;
1082 aGeom2Size[geomType] = nbPointsInFirstData;
1083 aGeom2NbGauss[geomType] = aNbGauss;
1084 aTGeom2Profile[geomType]= aPProfileInfo;
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);
1091 if(aPD2Vec.size() >0 ){
1092 if(vtkPointData* aPD0 = aPD2Vec[0]){
1093 if(vtkDataArray* aArr0 = aPD0->GetArray(aFieldName.c_str()))
1094 nbComp = aArr0->GetNumberOfComponents();
1098 MED::PFieldInfo aFieldInfo = myMed->CrFieldInfo(theMeshInfo,
1101 string aFieldName_PD = "Point " + aFieldName;
1102 aFieldInfo->SetName(aFieldName_PD.c_str());
1104 myMed->SetFieldInfo(aFieldInfo);
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,
1119 MED::PTimeStampVal aTempTimeStampVal = myMed->CrTimeStampVal (aTempTimeStampInfo,
1122 MED::TMeshValue& aTMeshValue = aTempTimeStampVal->GetMeshValue(geomType);
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));
1130 myMed->SetTimeStamp( aTempTimeStampVal, theErrCode);
1132 cout << "Error in "<<__FILE__<<"["<<__LINE__<<"] in method SetTimeStamp(...)"<<endl;
1136 aLastField = iField;
1141 MED::TEntityInfo aEntityInfo = myMed->GetEntityInfo(theMeshInfo);
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;
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);
1159 if(aCD2Vec.size() >0 ){
1160 if(vtkCellData* aCD0 = aCD2Vec[0]){
1161 if(vtkDataArray* aArr0 = aCD0->GetArray(aFieldName.c_str()))
1162 nbComp = aArr0->GetNumberOfComponents();
1166 MED::PFieldInfo aFieldInfo = myMed->CrFieldInfo(theMeshInfo,
1169 string aFieldName_CD = "Cell " + aFieldName;
1170 aFieldInfo->SetName(aFieldName_CD.c_str());
1172 myMed->SetFieldInfo(aFieldInfo);
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,
1187 MED::PTimeStampVal aTempTimeStampVal = myMed->CrTimeStampVal (aTempTimeStampInfo,
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];
1194 MED::TMeshValue& aTMeshValue = aTempTimeStampVal->GetMeshValue(geomType);
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;
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] << " ";
1210 if(MYDEBUG_VALUES) cout << "|" << endl;
1213 myMed->SetTimeStamp( aTempTimeStampVal, theErrCode);
1215 cout << "Error in "<<__FILE__<<"["<<__LINE__<<"] in method SetTimeStamp(...)"<<endl;
1228 \brief Writes data to MED file
1229 \return 0 if operation has been completed successfully, 1 otherwise
1232 VISU_Vtk2MedConvertor
1236 if (myFirstVTKFileName.size() == 0 ||
1237 myMEDFileName.size() == 0)
1239 cout << "Error! Bad input file names output med file name or vtk file name."<<endl;
1240 cout << "Exit."<<endl;
1244 MED::PWrapper myMed;
1245 MED::PMeshInfo aMeshInfo;
1246 int aMeshDimension = 3;
1247 myMed = CrWrapper(myMEDFileName.c_str(),myVersion);
1248 aMeshInfo = myMed->CrMeshInfo(aMeshDimension,myMeshName.c_str());
1249 myMed->SetMeshInfo(aMeshInfo);
1252 typedef vtkDataSetReader TReader;
1253 TReader* aReader = TReader::New();
1254 aReader->SetFileName(myFirstVTKFileName.c_str());
1256 TGeom2CellIds myGeom2CellIds;
1258 typedef std::vector<vtkDataSet*> TListUG;
1261 if(aReader->IsFilePolyData())
1263 if(MYDEBUG) cout << "PolyData" << endl;
1264 typedef vtkPolyData TCommonType;
1265 TCommonType* aInput = aReader->GetPolyDataOutput();
1267 aStatus = Geometry2MED(aInput,
1273 TCommonType* aUG1 = TCommonType::New();
1274 aUG1->ShallowCopy(aInput);
1275 vtkDataSet* aTmp1 = dynamic_cast<vtkDataSet*>(aUG1);
1276 aList.push_back(aTmp1);
1278 TVectorString::iterator aFilesIter = myDataVTKFileNames.begin();
1279 for(;aFilesIter!=myDataVTKFileNames.end();aFilesIter++){
1280 aReader->SetFileName((*aFilesIter).c_str());
1282 TCommonType* aUG2 = TCommonType::New();
1283 aUG2->ShallowCopy(aReader->GetPolyDataOutput());
1284 vtkDataSet* aTmp2 = dynamic_cast<vtkDataSet*>(aUG2);
1285 aList.push_back(aTmp2);
1287 } else if (aReader->IsFileUnstructuredGrid()){
1288 if (MYDEBUG) cout << "UnstructuredGrid" << endl;
1289 typedef vtkUnstructuredGrid TCommonType;
1290 TCommonType* aInput = aReader->GetUnstructuredGridOutput();
1292 aStatus = Geometry2MED(aInput,
1298 TCommonType* aUG1 = TCommonType::New();
1299 aUG1->ShallowCopy(aInput);
1300 vtkDataSet* aTmp1 = dynamic_cast<vtkDataSet*>(aUG1);
1301 aList.push_back(aTmp1);
1303 TVectorString::iterator aFilesIter = myDataVTKFileNames.begin();
1304 for(;aFilesIter!=myDataVTKFileNames.end();aFilesIter++){
1305 aReader->SetFileName((*aFilesIter).c_str());
1307 TCommonType* aUG2 = TCommonType::New();
1308 aUG2->ShallowCopy(aReader->GetUnstructuredGridOutput());
1309 vtkDataSet* aTmp2 = dynamic_cast<vtkDataSet*>(aUG2);
1310 aList.push_back(aTmp2);
1320 // clear aList by removing of unstructured grids
1321 TListUG::iterator aIter = aList.begin();
1322 for(;aIter!=aList.end();aIter++)