1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File: VISU_Convertor.cxx
24 // Author: Alexey PETROV
27 #include "VISU_Convertor.hxx"
28 #include "VISU_ConvertorUtils.hxx"
30 #include <vtkUnstructuredGridWriter.h>
35 static int MYDEBUG = 0;
37 static int MYDEBUG = 0;
41 VISU_Convertor* CreateConvertor(const string& theFileName) throw(std::runtime_error&){
42 if(QFileInfo(theFileName.c_str()).extension(false) == "med")
43 return CreateMedConvertor(theFileName);
45 return CreateDatConvertor(theFileName);
49 void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){
50 // vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
51 // //aWriter->DebugOn();
52 // //aWriter->SetFileType(VTK_BINARY);
53 // aWriter->SetFileName(theFileName.c_str());
54 // aWriter->SetInput(theDataSet);
55 // //aWriter->Print(cout);
61 TVtkCellInfoMap aVtkCellInfoMap;
63 aVtkCellInfoMap[VTK_VERTEX] = TVtkCellInfo("VTK_VERTEX",1),
64 aVtkCellInfoMap[VTK_LINE] = TVtkCellInfo("VTK_LINE",2),
65 aVtkCellInfoMap[VTK_TRIANGLE] = TVtkCellInfo("VTK_TRIANGLE",3),
66 aVtkCellInfoMap[VTK_QUAD] = TVtkCellInfo("VTK_QUAD",4),
67 aVtkCellInfoMap[VTK_TETRA] = TVtkCellInfo("VTK_TETRA",4),
68 aVtkCellInfoMap[VTK_HEXAHEDRON] = TVtkCellInfo("VTK_HEXAHEDRON",8),
69 aVtkCellInfoMap[VTK_WEDGE] = TVtkCellInfo("VTK_WEDGE",6),
70 aVtkCellInfoMap[VTK_PYRAMID] = TVtkCellInfo("VTK_PYRAMID",5),
73 pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
74 throw(std::runtime_error&)
76 bool isFamilyPresent = (theFamilyName != "");
77 int aNbCells = 0, aCellsSize = 0;
79 TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin();
80 for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){
81 const TConnForCellType& aConnForCellType = aCellsConnIter->second;
82 if(!aConnForCellType.empty()){
83 aNbCells += aConnForCellType.size();
84 aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1);
88 TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
89 if(aFamilyMapIter == myFamilyMap.end())
90 throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
91 const TFamily& aFamily = aFamilyMapIter->second;
92 const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
93 TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin();
94 for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){
95 const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
96 if(!aSubMeshOnCellType.empty()){
97 int tmp = aSubMeshOnCellType.size();
99 int aVtkType = aSubMeshIter->first;
100 int aVtkSize = aVtkCellInfoMap[aVtkType].mySize;
101 aCellsSize += tmp*(aVtkSize+1);
105 return make_pair(aNbCells,aCellsSize);
108 const TField* TMesh::GetField(const string& theFieldName) const {
109 TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin();
110 for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
111 const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap;
112 TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
113 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++)
114 if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second);
119 const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
120 throw(std::runtime_error&)
122 if(theFamilyName == "") return NULL;
123 const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
124 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
125 if(aFamilyMapIter == aFamilyMap.end())
126 throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
127 const VISU::TFamily& aFamily = aFamilyMapIter->second;
131 TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
132 throw(std::runtime_error&)
134 if(theFamilyName == "") return NULL;
135 VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
136 VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
137 if(aFamilyMapIter == aFamilyMap.end())
138 throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
139 VISU::TFamily& aFamily = aFamilyMapIter->second;
143 void TField::ShallowCopy(const TField& aField){
144 myEntity = aField.myEntity;
145 myMeshName = aField.myMeshName;
146 myNbComp = aField.myNbComp;
147 VISU::TField::TValField::const_iterator iter = aField.myValField.begin();
148 for(; iter != aField.myValField.end(); iter++)
149 myValField[iter->first];
154 const VISU::TMeshMap& VISU_Convertor::GetMeshMap() throw(std::runtime_error&){
155 if(!myIsDone) { myIsDone = true; Build();}
160 string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){
161 static QString aName;
162 const string aUnits = aTime.second, tmp(aUnits.size(),' ');
163 if(aUnits == "" || aUnits == tmp)
164 aName.sprintf("%g, -",aTime.first);
166 aName.sprintf("%g, %s",aTime.first,aTime.second.c_str());
167 aName = aName.simplifyWhiteSpace();
168 return aName.latin1();
171 string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) {
172 static QString aName;
173 aName = QString(theName.c_str()).simplifyWhiteSpace();
174 int iEnd = strlen(aName);
175 static int VtkHighLevelLength = 12; //25
176 if(iEnd > VtkHighLevelLength) iEnd = VtkHighLevelLength;
177 char aNewName[iEnd+1];
178 aNewName[iEnd] = '\0';
179 strncpy(aNewName,aName,iEnd);
180 replace(aNewName,aNewName+iEnd,' ','_');
181 if(true || theTimeId == 0)
184 aName.sprintf("%s_%d",aNewName,theTimeId);
185 return aName.latin1();