1 // Copyright (C) 2007-2012 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 case VTK_HEXAGONAL_PRISM: return MED::eOCTA12;
134 // QUADRATIC elements
135 case VTK_QUADRATIC_EDGE: return MED::eSEG3;
136 case VTK_QUADRATIC_TRIANGLE: return MED::eTRIA6;
137 case VTK_QUADRATIC_QUAD: return MED::eQUAD8;
138 case VTK_BIQUADRATIC_QUAD: return MED::eQUAD9;
139 case VTK_QUADRATIC_TETRA: return MED::eTETRA10;
140 case VTK_QUADRATIC_HEXAHEDRON:return MED::eHEXA20;
141 case VTK_TRIQUADRATIC_HEXAHEDRON :return MED::eHEXA27;
142 case VTK_CONVEX_POINT_SET: return MED::ePOLYEDRE;
149 \class VISU_Vtk2MedConvertor
150 \brief The general main of the class VISU_Vtk2MedConvertor is converting from
151 one or several VTK files to the one MED file...
153 The VISU_Vtk2MedConvertor interface allows us to create the MED file according
154 to VTK files in next ways:
155 - Extract geometry and fields from one VTK file.
156 - Extract geometry and fields from first VTK file and fields from others
157 VTK files (geometry ignoring). Also the fields which have same names join into
158 corresponding fields with different time stamp
163 - Sets default output mesh name
164 - Sets default version of output MED file.
165 - Sets default ignoring fields list
166 - Sets default points and cells ids mapping field names.
169 VISU_Vtk2MedConvertor
170 ::VISU_Vtk2MedConvertor():
171 myVersion(MED::eV2_2),
172 myMeshName("vtk2med")
174 myIgnoringFieldList.insert("VISU_POINTS_MAPPER");
175 myIgnoringFieldList.insert("VISU_CELLS_MAPPER");
176 myIgnoringFieldList.insert("VISU_FIELD");
177 setCellDataFieldNameIDS("VISU_CELLS_MAPPER");
178 setPointDataFieldNameIDS("VISU_POINTS_MAPPER");
183 - Sets default output mesh name
184 - Sets default version of output MED file.
185 - Sets default ignoring fields list
186 - Sets default points and cells ids mapping field names.
188 \param theMEDFileName output med file name
189 \param theFirstVTKFileName first vtk file name
191 VISU_Vtk2MedConvertor
192 ::VISU_Vtk2MedConvertor(const string theMEDFileName,
193 const string theFirstVTKFileName):
194 myVersion(MED::eV2_2),
195 myMeshName("vtk2med")
197 myMEDFileName = theMEDFileName;
198 myFirstVTKFileName = theFirstVTKFileName;
199 myIgnoringFieldList.insert("VISU_POINTS_MAPPER");
200 myIgnoringFieldList.insert("VISU_CELLS_MAPPER");
201 myIgnoringFieldList.insert("VISU_FIELD");
202 setCellDataFieldNameIDS("VISU_CELLS_MAPPER");
203 setPointDataFieldNameIDS("VISU_POINTS_MAPPER");
208 - Sets default output mesh name
209 - Sets default version of output MED file.
210 - Sets default ignoring fields list
211 - Sets default points and cells ids mapping field names.
213 \param theMEDFileName output med file name
214 \param theFirstVTKFileName first vtk file name
215 \param theDataVTKFileNames of vtk file names, which will be using as values on points and cells
217 VISU_Vtk2MedConvertor
218 ::VISU_Vtk2MedConvertor(const string theMEDFileName,
219 const string theFirstVTKFileName,
220 const TVectorString theDataVTKFileNames):
221 myVersion(MED::eV2_2),
222 myMeshName("vtk2med")
224 myMEDFileName = theMEDFileName;
225 myFirstVTKFileName = theFirstVTKFileName;
226 myDataVTKFileNames = theDataVTKFileNames;
227 myIgnoringFieldList.insert("VISU_POINTS_MAPPER");
228 myIgnoringFieldList.insert("VISU_CELLS_MAPPER");
229 myIgnoringFieldList.insert("VISU_FIELD");
230 setMeshName("vtk2med");
231 setCellDataFieldNameIDS("VISU_CELLS_MAPPER");
232 setPointDataFieldNameIDS("VISU_POINTS_MAPPER");
236 \brief Adds field names, which used as specific fields with ids or elements
237 (or something else). (Default: "VISU_CELLS_MAPPER","VISU_POINTS_MAPPER","VISU_FILED")
238 \param theFieldName field name
239 \sa eraseFromIgnoringFieldList()
242 VISU_Vtk2MedConvertor
243 ::addToIgnoringFieldList( const string& theFieldName )
245 myIgnoringFieldList.insert(theFieldName);
249 \brief Sets the output MED file name
250 \param theFileName file name
254 VISU_Vtk2MedConvertor
255 ::setMEDFileName( const string theFileName )
257 myMEDFileName=theFileName;
261 \brief Gets the output MED file name
262 \return output MED file name
266 VISU_Vtk2MedConvertor
267 ::getMEDFileName() const
269 return myMEDFileName;
273 \brief Sets the first input vtk file name
274 \param theFileName file name
275 \sa getFirstVTKFileName()
278 VISU_Vtk2MedConvertor
279 ::setFirstVTKFileName( const string theFileName )
281 myFirstVTKFileName=theFileName;
285 \brief Fets the first input vtk file name
286 \return first input vtk file name
287 \sa setFirstVTKFileName()
290 VISU_Vtk2MedConvertor
291 ::getFirstVTKFileName() const
293 return myFirstVTKFileName;
297 \brief Sets list of vtk file names, which will be using as values on points and cells
298 \param theFileNames list of vtk file names
299 \sa getDataVTKFileNames()
302 VISU_Vtk2MedConvertor
303 ::setDataVTKFileNames( const TVectorString theFileNames )
305 myDataVTKFileNames = theFileNames;
309 \brief Gets list of vtk file names, which will be using as values on points and cells
310 \param theFileNames out list of vtk file names
311 \sa setDataVTKFileNames()
314 VISU_Vtk2MedConvertor
315 ::getDataVTKFileNames( TVectorString& theDataVTKFileNames ) const
317 theDataVTKFileNames = myDataVTKFileNames;
321 \brief Sets version of the output MED file MED::V2_2(is default) or MED::V2_1
322 \param theVersion version of the output MED file
325 VISU_Vtk2MedConvertor
326 ::setVersion( const MED::EVersion theVersion )
328 myVersion = theVersion;
332 \brief Gets version of the output MED file MED::V2_2(is default) or MED::V2_1
333 \return version of the output MED file
336 VISU_Vtk2MedConvertor
343 \brief Sets output mesh name. ("vtk2med" - default)
344 \param theMeshName mesh name
348 VISU_Vtk2MedConvertor
349 ::setMeshName( const string theMeshName )
351 myMeshName = theMeshName;
355 \brief Gets output mesh name. ("vtk2med" - default)
360 VISU_Vtk2MedConvertor
361 ::getMeshName() const
367 \brief Sets field name with cell ids (Default - VISU_CELLS_MAPPER)
368 \param theFieldName field name
369 \sa getCellDataFieldNameIDS
372 VISU_Vtk2MedConvertor
373 ::setCellDataFieldNameIDS( const string& theFieldName )
375 myCellDataFieldNameIDS = theFieldName;
379 \brief Gets field name with cell ids (Default - VISU_CELLS_MAPPER)
381 \sa setCellDataFieldNameIDS()
384 VISU_Vtk2MedConvertor
385 ::getCellDataFieldNameIDS() const
387 return myCellDataFieldNameIDS;
391 \brief Erases field names which used as specific fields with ids or elements
393 \param theFieldName field name
394 \sa addToIgnoringFieldList()
397 VISU_Vtk2MedConvertor
398 ::eraseFromIgnoringFieldList(const string& theFieldName)
400 myIgnoringFieldList.erase(theFieldName);
404 \brief Gets list of field names which used as specific fields with ids or elements
405 \return list of field names
407 const std::set<std::string>&
408 VISU_Vtk2MedConvertor
409 ::getIgnoringFieldList() const
411 return myIgnoringFieldList;
415 \brief Sets field name with point ids
416 \param theFieldName field name
417 \sa getPointDataFieldNameIDS()
420 VISU_Vtk2MedConvertor
421 ::setPointDataFieldNameIDS( const string& theFieldName )
423 myPointDataFieldNameIDS = theFieldName;
427 \brief Gets field name with point ids
429 \sa setPointDataFieldNameIDS()
432 VISU_Vtk2MedConvertor
433 ::getPointDataFieldNameIDS() const
435 return myPointDataFieldNameIDS;
439 \brief Sets values of time stamps If this array is not specified values of time
440 stamps are generated automatically ( 0, 1, 2 ... )
441 \param theTStamps vector of time stamps
445 VISU_Vtk2MedConvertor
446 ::setTimeStamps( const TVectorDouble& theTStamps )
448 myTStamps = theTStamps;
452 \brief Gets values of time stamps If this array is not specified values of time
453 stamps are generated automatically ( 0, 1, 2 ... )
454 \param theTStamps out vector of time stamps
458 VISU_Vtk2MedConvertor
459 ::getTimeStamps( TVectorDouble& theTStamps ) const
461 theTStamps = myTStamps;
465 \brief Retrieves identifiers of cells from input data set corresponding to given type
466 \param theInput input data set
468 \param array out array
471 VISU_Vtk2MedConvertor
472 ::GetIdsOfCellsOfType(vtkDataSet* theInput,
476 for (int cellId = 0; cellId < theInput->GetNumberOfCells(); cellId++)
477 if (theInput->GetCellType(cellId) == type)
478 array->InsertNextValue(cellId);
482 \brief Creates elements (private auxiliary method)
483 \return 0 if operation has been completed successfully, 1 otherwise
486 VISU_Vtk2MedConvertor
487 ::CreateElements(vtkDataSet* theInput,
488 MED::PMeshInfo theMeshInfo,
489 MED::PWrapper theMed,
490 vtkIntArray* theCellsMapper,
491 MED::EEntiteMaillage theEntity,
494 std::vector<int>& theNumberingConvertor,
495 TGeom2CellIds& theGeom2CellIdMap)
497 bool aIdsConvert = (theNumberingConvertor.size() > 0);
498 vtkIntArray* aCellIds = vtkIntArray::New();
499 const MED::EConnectivite aConnType = MED::eNOD;
501 MED::TIntVector aConn;
502 MED::TIntVector aFamilyNums;// -1
503 MED::TIntVector aElemNums;
505 this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
506 int nbElems = aCellIds->GetNumberOfTuples();
507 if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
508 aConn.reserve(nbElems*nbPointsInGeom);
510 TCellIds& aCellIdsMapper = theGeom2CellIdMap[VTK2MED(theVTKGeom)];
511 int* aPointer = aCellIds->GetPointer(0);
512 for(int i=0;i<nbElems;i++,aPointer++){
513 int aCellId = *aPointer;
514 aCellIdsMapper.push_back(aCellId);
515 vtkCell* aCell = theInput->GetCell(aCellId);
516 int nbPointsInCell = aCell->GetNumberOfPoints();
517 if(nbPointsInCell!=nbPointsInGeom){
518 cout << "Error in file=|" << __FILE__<<"| line:[" << __LINE__ << "]" << endl;
519 cout << "Must be "<<nbPointsInGeom<<" nodes in VTK Geometry:"<<theVTKGeom<<" element" << endl;
523 aFamilyNums.push_back(-1);
524 for(int j=0;j<nbPointsInCell;j++){
526 aConn.push_back(aCell->GetPointId(theNumberingConvertor[j])+1);
528 aConn.push_back(aCell->GetPointId(j)+1);
531 if(theCellsMapper->GetNumberOfComponents()==2)
532 aElemNums.push_back(*theCellsMapper->GetPointer(aCellId*2));
533 else if(theCellsMapper->GetNumberOfComponents()==1)
534 aElemNums.push_back(*theCellsMapper->GetPointer(aCellId));
539 MED::PCellInfo aCellInfo = theMed->CrCellInfo(theMeshInfo,
546 theMed->SetCellInfo(aCellInfo);
555 \brief Creates polygons (private auxiliary method)
556 \return 0 if operation has been completed successfully, 1 otherwise
559 VISU_Vtk2MedConvertor
560 ::CreatePolygons(vtkDataSet* theInput,
561 MED::PMeshInfo theMeshInfo,
562 MED::PWrapper theMed,
563 vtkIntArray* theCellsMapper,
564 MED::EEntiteMaillage theEntity,
565 TGeom2CellIds& theGeom2CellIdMap)
567 int theVTKGeom = VTK_POLYGON;
568 vtkIntArray* aCellIds = vtkIntArray::New();
569 const MED::EConnectivite aConnType = MED::eNOD;
571 MED::TIntVector aConn;
572 MED::TIntVector aFamilyNums;// -1
573 MED::TIntVector aElemNums;
574 MED::TIntVector aPolygoneInds;
575 aPolygoneInds.push_back(1); // reference on the first element in the connectivities
577 this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
578 int nbElems = aCellIds->GetNumberOfTuples();
579 if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
581 TCellIds& aCellIdsMapper = theGeom2CellIdMap[VTK2MED(theVTKGeom)];
582 int* aPointer = aCellIds->GetPointer(0);
583 for(int i=0;i<nbElems;i++,aPointer++){
584 int aCellId = *aPointer;
585 aCellIdsMapper.push_back(aCellId);
586 vtkCell* aCell = theInput->GetCell(aCellId);
587 int nbPointsInCell = aCell->GetNumberOfPoints();
588 aFamilyNums.push_back(-1);
589 int aPrevPos = aPolygoneInds.back();
590 aPolygoneInds.push_back(aPrevPos+nbPointsInCell);
591 for(int j=0;j<nbPointsInCell;j++)
592 aConn.push_back(aCell->GetPointId(j)+1);
594 if(theCellsMapper->GetNumberOfComponents()==2)
595 aElemNums.push_back(*theCellsMapper->GetPointer(aCellId*2));
596 else if(theCellsMapper->GetNumberOfComponents()==1)
597 aElemNums.push_back(*theCellsMapper->GetPointer(aCellId));
602 MED::PPolygoneInfo aCellInfo = theMed->CrPolygoneInfo(theMeshInfo,
610 theMed->SetPolygoneInfo(aCellInfo);
619 \brief Creates polyedres (private auxiliary method)
620 \return 0 if operation has been completed successfully, 1 otherwise
623 VISU_Vtk2MedConvertor
624 ::CreatePolyedres(vtkDataSet* theInput,
625 MED::PMeshInfo theMeshInfo,
626 MED::PWrapper theMed,
627 vtkIntArray* theCellsMapper,
628 MED::EEntiteMaillage theEntity,
629 TGeom2CellIds& theGeom2CellIdMap)
631 int theVTKGeom = VTK_CONVEX_POINT_SET;
632 vtkIntArray* aCellIds = vtkIntArray::New();
633 const MED::EConnectivite aConnType = MED::eNOD;
635 MED::TIntVector aConn;
636 MED::TIntVector aFamilyNums;// -1
637 MED::TIntVector aElemNums;
638 MED::TIntVector aPolyedreInds;
639 MED::TIntVector aPolyedreFaces;
641 aPolyedreInds.push_back(1); // reference on the first element in the connectivities
642 aPolyedreFaces.push_back(1);
644 this->GetIdsOfCellsOfType(theInput,theVTKGeom,aCellIds);
645 int nbElems = aCellIds->GetNumberOfTuples();
646 if(MYDEBUG) cout << "\tnbElems in geom:"<<VTK2MED(theVTKGeom)<<" ="<<nbElems<<endl;
648 TCellIds& aCellIdsMapper = theGeom2CellIdMap[VTK2MED(theVTKGeom)];
649 int* aPointer = aCellIds->GetPointer(0);
650 for(int i=0;i<nbElems;i++,aPointer++){
651 int aCellId = *aPointer;
652 aCellIdsMapper.push_back(aCellId);
653 vtkCell* aCell = theInput->GetCell(aCellId);
654 int nbPointsInCell = aCell->GetNumberOfPoints();
655 for(int j=0;j<nbPointsInCell;j++)
656 aConn.push_back(aCell->GetPointId(j)+1);
657 int aPrevPos = aPolyedreFaces.back();
658 aPolyedreFaces.push_back(aPrevPos + nbPointsInCell);
659 aPrevPos = aPolyedreInds.back();
660 aPolyedreInds.push_back(aPrevPos + 1/*aNbFaces*/);
661 aFamilyNums.push_back(-1);
664 if(theCellsMapper->GetNumberOfComponents()==2)
665 aElemNums.push_back(*theCellsMapper->GetPointer(aCellId*2));
666 else if(theCellsMapper->GetNumberOfComponents()==1)
667 aElemNums.push_back(*theCellsMapper->GetPointer(aCellId));
672 MED::PPolyedreInfo aCellInfo = theMed->CrPolyedreInfo(theMeshInfo,
681 theMed->SetPolyedreInfo(aCellInfo);
690 \brief Converts geometry to med (private auxiliary method)
691 \return 0 if operation has been completed successfully, 1 otherwise
694 VISU_Vtk2MedConvertor
695 ::Geometry2MED(vtkDataSet* aInput,
697 MED::PMeshInfo aMeshInfo,
698 TGeom2CellIds& outGeom2CellIdMap)
700 int aNbNodes = aInput->GetNumberOfPoints();
701 int aMeshDimension = aMeshInfo->GetDim();
702 // ----------------------- NODES -------------------------
703 vtkIntArray* aPointsMapper;
704 if(aInput->GetPointData())
705 aPointsMapper = dynamic_cast<vtkIntArray*>(aInput->GetPointData()->GetArray(myPointDataFieldNameIDS.c_str()));
707 MED::TFloatVector aCoordinates(aNbNodes*aMeshDimension);
708 MED::TIntVector anElemNumsNodes; // takes from VISU_POINTS_MAPPER array
709 MED::TIntVector aFamilyNumsNodes;
710 MED::TStringVector aCoordNamesNodes;
711 MED::TStringVector aCoordUnitsNodes;
713 vtkFloatingPointType aPntCoord[3];
715 int nbComp = aPointsMapper->GetNumberOfComponents();
716 int *aPointsMapperPtr = aPointsMapper->GetPointer(0);
717 for(int i=0;i<aNbNodes;i++){
718 aInput->GetPoint(i,aPntCoord);
719 aCoordinates[i*3] = aPntCoord[0];
720 aCoordinates[i*3+1] = aPntCoord[1];
721 aCoordinates[i*3+2] = aPntCoord[2];
723 anElemNumsNodes.push_back(*aPointsMapperPtr);
724 aPointsMapperPtr++;aPointsMapperPtr++;
726 else if (nbComp == 1){
727 anElemNumsNodes.push_back(*aPointsMapperPtr);
731 cout << "Error in file=|" << __FILE__<<"| line:[" << __LINE__ << "]" << endl;
732 cout << "Code must be adapted for more than 2 components array |VISU_POINTS_MAPPER|" << endl;
738 for(int i=0;i<aNbNodes;i++){
739 aInput->GetPoint(i,aPntCoord);
740 aCoordinates[i*3] = aPntCoord[0];
741 aCoordinates[i*3+1] = aPntCoord[1];
742 aCoordinates[i*3+2] = aPntCoord[2];
747 MED::PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo,
749 MED::eFULL_INTERLACE,
755 myMed->SetNodeInfo(aNodeInfo);
757 vtkIntArray* aCellsMapper;
758 if(vtkCellData* aCD = aInput->GetCellData())
759 aCellsMapper = dynamic_cast<vtkIntArray*>(aCD->GetArray(myCellDataFieldNameIDS.c_str()));
764 // print all cell types in the input
765 vtkCellTypes* aCellTypes = vtkCellTypes::New();
766 aInput->GetCellTypes(aCellTypes);
767 cout << "Cell types in the input data:"<<endl;
768 for(int aNbCellType = 0;aNbCellType<aCellTypes->GetNumberOfTypes();aNbCellType++)
769 cout << (int)(aCellTypes->GetCellType(aNbCellType)) << endl;
770 aCellTypes->Delete();
773 //----------------------
774 // Entity EDGES (eARETE)
775 //----------------------
776 vector<int> aNumberingConvertor;
779 MED::EEntiteMaillage aEntity = MED::eMAILLE;//eARETE;
781 int nbPointsInGeom = 0;
783 // aNumberingConvertor NULL - OK
786 CreateElements(aInput,
796 // aNumberingConvertor NULL - OK
797 // debug info: checked - OK
798 aVTKGeom = VTK_QUADRATIC_EDGE;
800 CreateElements(aInput,
811 //----------------------------
812 // Entity FACES (eFACE)
813 // eTRIA3,eQUAD4,eTRIA6,eQUAD8
815 //----------------------------
818 MED::EEntiteMaillage aEntity = MED::eMAILLE;//MED::eFACE;
820 int nbPointsInGeom = 0;
822 // debug info: checked - OK
823 aVTKGeom = VTK_TRIANGLE;
824 aNumberingConvertor.clear();
826 CreateElements(aInput,
836 // debug info: checked - OK
839 aNumberingConvertor.clear();
840 CreateElements(aInput,
851 // debug info: checked - OK
852 aVTKGeom = VTK_QUADRATIC_TRIANGLE;
854 aNumberingConvertor.clear();
855 CreateElements(aInput,
865 aVTKGeom = VTK_QUADRATIC_QUAD;
867 aNumberingConvertor.clear();
869 CreateElements(aInput,
879 // debug info: checked - OK
880 CreatePolygons(aInput,
888 //----------------------------
889 // Entity CELLS (eMAILLE)
890 // eTETRA4,eHEXA8,ePENTA6,ePYRA5,
891 // eTETRA10,eHEXA20,ePOLYEDRE
892 //----------------------------
895 MED::EEntiteMaillage aEntity = MED::eMAILLE;
897 int nbPointsInGeom = 0;
899 aVTKGeom = VTK_TETRA;
901 aNumberingConvertor.clear();
902 aNumberingConvertor.push_back(0);
903 aNumberingConvertor.push_back(2);
904 aNumberingConvertor.push_back(1);
905 aNumberingConvertor.push_back(3);
906 CreateElements(aInput,
916 aVTKGeom = VTK_HEXAHEDRON;
918 aNumberingConvertor.clear();
920 CreateElements(aInput,
930 aVTKGeom = VTK_WEDGE;
932 aNumberingConvertor.clear();
933 CreateElements(aInput,
943 aVTKGeom = VTK_PYRAMID;
945 aNumberingConvertor.clear();
946 aNumberingConvertor.push_back(0);
947 aNumberingConvertor.push_back(3);
948 aNumberingConvertor.push_back(2);
949 aNumberingConvertor.push_back(1);
950 aNumberingConvertor.push_back(4);
951 CreateElements(aInput,
961 aVTKGeom = VTK_QUADRATIC_TETRA;
963 aNumberingConvertor.clear();
964 // 0,2,1,3,6,5,4,7,9,8
965 CreateElements(aInput,
976 aVTKGeom = VTK_QUADRATIC_HEXAHEDRON;
978 aNumberingConvertor.clear();
979 // 0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17
980 CreateElements(aInput,
990 // debug info: checked OK
991 CreatePolyedres(aInput,
1004 \brief Converts data to med (private auxiliary method)
1005 \return 0 if operation has been completed successfully, 1 otherwise
1008 VISU_Vtk2MedConvertor
1009 ::Data2MED(std::vector<vtkDataSet*> theListForAdd,
1010 MED::PWrapper myMed,
1011 MED::PMeshInfo theMeshInfo,
1012 TGeom2CellIds& theGeom2CellIdMap)
1014 typedef std::vector<vtkPointData*> TPDVec;
1015 typedef std::vector<vtkCellData*> TCDVec;
1016 typedef std::map<std::string,TPDVec> TNameToPointData;
1017 typedef std::map<std::string,TCDVec> TNameToCellData;
1019 TNameToPointData aName2PointData;
1020 TNameToCellData aName2CellData;
1022 MED::TErr* theErrCode = new MED::TErr();
1023 MED::EGeometrieElement geomType;
1024 MED::EEntiteMaillage entity;
1026 // prepare data to create time stamps
1027 const MED::TInt aNbGauss = 1;
1028 MED::TProfileInfo::TInfo aTInfo("",0);
1029 MED::PProfileInfo aPProfileInfo = myMed->CrProfileInfo( aTInfo );
1031 MED::TGeom2Size aGeom2Size;
1032 MED::TGeom2NbGauss aGeom2NbGauss;
1033 MED::TGeom2Profile aTGeom2Profile;
1035 int nbPointsInFirstData = 0;
1036 if(theListForAdd.size()>0)
1037 nbPointsInFirstData = (theListForAdd[0])->GetNumberOfPoints();
1039 int nbClasses = theListForAdd.size();
1041 for(int iClass=0;iClass<nbClasses;iClass++){
1042 vtkDataSet* aClassPtr = theListForAdd[iClass];
1043 if(aClassPtr->GetNumberOfPoints() != nbPointsInFirstData){
1044 cout << "Warning in PointData: Some vtk file consist of number of points( " <<aClassPtr->GetNumberOfPoints()
1045 << ") not equal number of points in first file("<<nbPointsInFirstData<<")"<<endl;
1046 cout << "This data will be lost." << endl;
1050 if(vtkPointData* aPD = aClassPtr->GetPointData()){
1051 int nbArrays = aPD->GetNumberOfArrays();
1053 for(int aArrNum=0;aArrNum<nbArrays;aArrNum++)
1055 vtkDataArray* aArr = aPD->GetArray(aArrNum);
1056 std::string aName = aArr->GetName();
1057 std::set<std::string>::const_iterator aIgnoreIter = myIgnoringFieldList.find(aName);
1058 if(aIgnoreIter!=myIgnoringFieldList.end())
1060 (aName2PointData[aName]).push_back(aPD);
1064 if(vtkCellData* aCD = aClassPtr->GetCellData()){
1065 int nbArrays = aCD->GetNumberOfArrays();
1067 for(int aArrNum=0;aArrNum<nbArrays;aArrNum++)
1069 vtkDataArray* aArr = aCD->GetArray(aArrNum);
1070 std::string aName = aArr->GetName();
1071 std::set<std::string>::const_iterator aIgnoreIter = myIgnoringFieldList.find(aName);
1072 if(aIgnoreIter!=myIgnoringFieldList.end())
1074 (aName2CellData[aName]).push_back(aCD);
1083 geomType = MED::ePOINT1;
1084 entity = MED::eNOEUD;
1085 aGeom2Size[geomType] = nbPointsInFirstData;
1086 aGeom2NbGauss[geomType] = aNbGauss;
1087 aTGeom2Profile[geomType]= aPProfileInfo;
1089 TNameToPointData::const_iterator aIter = aName2PointData.begin();
1090 for(int iField=1;aIter!=aName2PointData.end();aIter++,iField++){
1091 std::string aFieldName = aIter->first;
1092 TPDVec aPD2Vec = (aIter->second);
1094 if(aPD2Vec.size() >0 ){
1095 if(vtkPointData* aPD0 = aPD2Vec[0]){
1096 if(vtkDataArray* aArr0 = aPD0->GetArray(aFieldName.c_str()))
1097 nbComp = aArr0->GetNumberOfComponents();
1101 MED::PFieldInfo aFieldInfo = myMed->CrFieldInfo(theMeshInfo,
1104 string aFieldName_PD = "Point " + aFieldName;
1105 aFieldInfo->SetName(aFieldName_PD.c_str());
1107 myMed->SetFieldInfo(aFieldInfo);
1109 TPDVec::const_iterator aPDIter = aPD2Vec.begin();
1110 for(int iTStamp=0;aPDIter!=aPD2Vec.end();aPDIter++,iTStamp++){
1111 vtkPointData* aPD = *aPDIter;
1112 vtkDataArray* aArr = aPD->GetArray(aFieldName.c_str());
1113 MED::TFloat aTS = iTStamp < (int)myTStamps.size() ? myTStamps[ iTStamp ] : iTStamp;
1114 MED::PTimeStampInfo aTempTimeStampInfo = myMed->CrTimeStampInfo (aFieldInfo,
1122 MED::PTimeStampVal aTempTimeStampVal = myMed->CrTimeStampVal (aTempTimeStampInfo,
1125 MED::TMeshValue& aTMeshValue = aTempTimeStampVal->GetMeshValue(geomType);
1127 MED::TValue& aValue = aTMeshValue.myValue; // float
1128 int nbValues = aValue.size();
1129 for(int i=0;i<nbValues;i++){
1130 aValue[i] = *(float*)(aArr->GetVoidPointer(i));
1133 myMed->SetTimeStamp( aTempTimeStampVal, theErrCode);
1135 cout << "Error in "<<__FILE__<<"["<<__LINE__<<"] in method SetTimeStamp(...)"<<endl;
1139 aLastField = iField;
1144 MED::TEntityInfo aEntityInfo = myMed->GetEntityInfo(theMeshInfo);
1146 aGeom2NbGauss.clear();
1147 aTGeom2Profile.clear();
1148 aGeom2Size = aEntityInfo[ MED::eMAILLE ];
1149 entity = MED::eMAILLE;
1150 MED::TGeom2Size::iterator geom_nb;
1151 for ( geom_nb = aGeom2Size.begin(); geom_nb != aGeom2Size.end(); ++geom_nb ) { // loop on geometric types of cell
1152 aGeom2NbGauss[ geom_nb->first ] = aNbGauss;
1153 aTGeom2Profile[ geom_nb->first ] = aPProfileInfo;
1157 TNameToCellData::const_iterator aIter = aName2CellData.begin();
1158 for(int iField=1;aIter!=aName2CellData.end();aIter++,iField++){
1159 std::string aFieldName = aIter->first;
1160 TCDVec aCD2Vec = (aIter->second);
1162 if(aCD2Vec.size() >0 ){
1163 if(vtkCellData* aCD0 = aCD2Vec[0]){
1164 if(vtkDataArray* aArr0 = aCD0->GetArray(aFieldName.c_str()))
1165 nbComp = aArr0->GetNumberOfComponents();
1169 MED::PFieldInfo aFieldInfo = myMed->CrFieldInfo(theMeshInfo,
1172 string aFieldName_CD = "Cell " + aFieldName;
1173 aFieldInfo->SetName(aFieldName_CD.c_str());
1175 myMed->SetFieldInfo(aFieldInfo);
1177 TCDVec::const_iterator aCDIter = aCD2Vec.begin();
1178 for(int iTStamp=0;aCDIter!=aCD2Vec.end();aCDIter++,iTStamp++){
1179 vtkCellData* aCD = *aCDIter;
1180 vtkDataArray* aArr = aCD->GetArray(aFieldName.c_str());
1181 MED::TFloat aTS = iTStamp < (int)myTStamps.size() ? myTStamps[ iTStamp ] : iTStamp;
1182 MED::PTimeStampInfo aTempTimeStampInfo = myMed->CrTimeStampInfo (aFieldInfo,
1190 MED::PTimeStampVal aTempTimeStampVal = myMed->CrTimeStampVal (aTempTimeStampInfo,
1193 for ( geom_nb = aGeom2Size.begin(); geom_nb != aGeom2Size.end(); ++geom_nb ) { // loop on geometric types of cell
1194 geomType = geom_nb->first;
1195 TCellIds& aCellIds = theGeom2CellIdMap[geomType];
1197 MED::TMeshValue& aTMeshValue = aTempTimeStampVal->GetMeshValue(geomType);
1199 MED::TValue& aValue = aTMeshValue.myValue; // float
1200 int nbValues = aValue.size();
1201 int nbCellIds = aCellIds.size();
1202 if(nbValues!=nbCellIds*nbComp){
1203 cout << "Warning in "<<__FILE__<<"["<<__LINE__<<"] the data for geometry:"<<geomType<<" will be ignored"<<endl;
1206 if(MYDEBUG_VALUES) cout << "Geom["<<geomType<<"]"<<endl;
1207 for(int i=0;i<nbCellIds;i++){
1208 if(MYDEBUG_VALUES) cout << "\t|";
1209 for(int iComp=0;iComp<nbComp;iComp++){
1210 aValue[nbComp*i+iComp] = *(float*)(aArr->GetVoidPointer(nbComp*aCellIds[i]+iComp));
1211 if(MYDEBUG_VALUES) cout << aValue[nbComp*i+iComp] << " ";
1213 if(MYDEBUG_VALUES) cout << "|" << endl;
1216 myMed->SetTimeStamp( aTempTimeStampVal, theErrCode);
1218 cout << "Error in "<<__FILE__<<"["<<__LINE__<<"] in method SetTimeStamp(...)"<<endl;
1231 \brief Writes data to MED file
1232 \return 0 if operation has been completed successfully, 1 otherwise
1235 VISU_Vtk2MedConvertor
1239 if (myFirstVTKFileName.size() == 0 ||
1240 myMEDFileName.size() == 0)
1242 cout << "Error! Bad input file names output med file name or vtk file name."<<endl;
1243 cout << "Exit."<<endl;
1247 MED::PWrapper myMed;
1248 MED::PMeshInfo aMeshInfo;
1249 int aMeshDimension = 3;
1250 int aSpaceDimension = 3;
1251 myMed = CrWrapper(myMEDFileName.c_str(),myVersion);
1252 aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,myMeshName.c_str());
1253 myMed->SetMeshInfo(aMeshInfo);
1256 typedef vtkDataSetReader TReader;
1257 TReader* aReader = TReader::New();
1258 aReader->SetFileName(myFirstVTKFileName.c_str());
1260 TGeom2CellIds myGeom2CellIds;
1262 typedef std::vector<vtkDataSet*> TListUG;
1265 if(aReader->IsFilePolyData())
1267 if(MYDEBUG) cout << "PolyData" << endl;
1268 typedef vtkPolyData TCommonType;
1269 TCommonType* aInput = aReader->GetPolyDataOutput();
1271 aStatus = Geometry2MED(aInput,
1277 TCommonType* aUG1 = TCommonType::New();
1278 aUG1->ShallowCopy(aInput);
1279 vtkDataSet* aTmp1 = dynamic_cast<vtkDataSet*>(aUG1);
1280 aList.push_back(aTmp1);
1282 TVectorString::iterator aFilesIter = myDataVTKFileNames.begin();
1283 for(;aFilesIter!=myDataVTKFileNames.end();aFilesIter++){
1284 aReader->SetFileName((*aFilesIter).c_str());
1286 TCommonType* aUG2 = TCommonType::New();
1287 aUG2->ShallowCopy(aReader->GetPolyDataOutput());
1288 vtkDataSet* aTmp2 = dynamic_cast<vtkDataSet*>(aUG2);
1289 aList.push_back(aTmp2);
1291 } else if (aReader->IsFileUnstructuredGrid()){
1292 if (MYDEBUG) cout << "UnstructuredGrid" << endl;
1293 typedef vtkUnstructuredGrid TCommonType;
1294 TCommonType* aInput = aReader->GetUnstructuredGridOutput();
1296 aStatus = Geometry2MED(aInput,
1302 TCommonType* aUG1 = TCommonType::New();
1303 aUG1->ShallowCopy(aInput);
1304 vtkDataSet* aTmp1 = dynamic_cast<vtkDataSet*>(aUG1);
1305 aList.push_back(aTmp1);
1307 TVectorString::iterator aFilesIter = myDataVTKFileNames.begin();
1308 for(;aFilesIter!=myDataVTKFileNames.end();aFilesIter++){
1309 aReader->SetFileName((*aFilesIter).c_str());
1311 TCommonType* aUG2 = TCommonType::New();
1312 aUG2->ShallowCopy(aReader->GetUnstructuredGridOutput());
1313 vtkDataSet* aTmp2 = dynamic_cast<vtkDataSet*>(aUG2);
1314 aList.push_back(aTmp2);
1324 // clear aList by removing of unstructured grids
1325 TListUG::iterator aIter = aList.begin();
1326 for(;aIter!=aList.end();aIter++)