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_impl.cxx
24 // Author : Alexey PETROV
27 #include "VISU_Convertor_impl.hxx"
28 #include "VISU_ConvertorUtils.hxx"
30 #include <vtkIdList.h>
31 #include <vtkCellType.h>
32 #include <vtkIntArray.h>
33 #include <vtkCellArray.h>
34 #include <vtkFloatArray.h>
35 #include <vtkUnsignedCharArray.h>
36 #include <vtkPointData.h>
37 #include <vtkCellData.h>
38 #include <vtkCellLinks.h>
40 #include <vtkMergeDataObjectFilter.h>
42 #include <vtkUnstructuredGridWriter.h>
45 #include <qfileinfo.h>
52 static float ERR_SIZE_CALC = 1.00;
54 static int MYVTKDEBUG = 0;
57 static int MYDEBUG = 0;
58 static int MYDEBUGWITHFILES = 0;
60 static int MYDEBUG = 0;
61 static int MYDEBUGWITHFILES = 0;
64 void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){
65 //vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
66 //if(MYVTKDEBUG) aWriter->DebugOn();
67 ////aWriter->SetFileType(VTK_BINARY);
68 //aWriter->SetFileName(theFileName.c_str());
69 //aWriter->SetInput(theDataSet);
75 void GetPoints(VISU::TVTKSource& theStorage, VISU::TMesh& theMesh)
76 throw (std::runtime_error&)
78 vtkPoints* aPoints = theMesh.myPoints.GetPointer();
80 aPoints = vtkPoints::New();
81 if(MYVTKDEBUG) aPoints->DebugOn();
82 const VISU::TMesh::TPointsCoord& anArray = theMesh.myPointsCoord;
83 vtkIdType iEnd = theMesh.myPointsCoord.size();
84 vtkIdType aNbPoints = iEnd / theMesh.myDim;
85 aPoints->SetNumberOfPoints(aNbPoints);
87 MESSAGE("GetPoints - aNbPoints = "<<aNbPoints<<"; myDim = "<<theMesh.myDim);
88 switch(theMesh.myDim) {
90 for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
91 aPoints->SetPoint(j,anArray[i],0.0,0.0);
94 for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
95 aPoints->SetPoint(j,anArray[i],anArray[i+1],0.0);
98 for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
99 aPoints->SetPoint(j,anArray[i],anArray[i+1],anArray[i+2]);
102 theMesh.myPoints = aPoints;
104 theStorage->SetPoints(aPoints);
108 inline void PrintCells(int& theStartId,
109 vtkCellArray* theConnectivity,
110 const VISU::TMeshOnEntity::TConnect& theVector)
112 vtkIdList *anIdList = vtkIdList::New();
113 int kEnd = theVector.size();
114 anIdList->SetNumberOfIds(kEnd);
115 for(int k = 0; k < kEnd; k++)
116 anIdList->SetId(k,theVector[k]);
117 theConnectivity->InsertNextCell(anIdList);
121 void GetCellsOnEntity(VISU::TVTKSource& theStorage,
122 const VISU::TMeshOnEntity& theMeshOnEntity,
123 const string& theFamilyName)
124 throw (std::runtime_error&)
126 //Check on existing family
127 const VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
128 bool isFamilyPresent = (pFamily != NULL);
129 const VISU::TFamily& aFamily = *pFamily;
131 pair<int,int> aCellsDim = theMeshOnEntity.GetCellsDims(theFamilyName);
132 int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second;
133 vtkCellArray* aConnectivity = vtkCellArray::New();
134 aConnectivity->Allocate(aCellsSize,0);
135 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
136 aCellTypesArray->SetNumberOfComponents(1);
137 aCellTypesArray->SetNumberOfTuples(aNbCells);
138 if(MYDEBUG) MESSAGE("GetCellsOnEntity - isFamilyPresent = "<<isFamilyPresent);
139 const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn;
140 VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin();
141 for(int i = 0, j = 0; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){
142 const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second;
143 int aVtkType = aCellsConnIter->first;
145 MESSAGE("GetCellsOnEntity - aVtkType = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
147 for(int k = 0, kEnd = anArray.size(); k < kEnd; k++, i++){
148 PrintCells(i,aConnectivity,anArray[k]);
149 aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
152 const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
154 throw std::runtime_error(EXCEPTION("GetCells >> There is no elements on the family !!!"));
155 VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType);
156 if(aSubMeshIter == aSubMesh.end()) continue;
157 const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
159 MESSAGE("GetCellsOnEntity - aSubMeshOnCellType.size() = "<<aSubMeshOnCellType.size());
160 VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
161 for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++, i++){
162 PrintCells(i,aConnectivity,anArray[*aSubMeshOnCellTypeIter]);
163 aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
167 vtkIdType *pts = 0, npts = 0;
168 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
169 aCellLocationsArray->SetNumberOfComponents(1);
170 aCellLocationsArray->SetNumberOfTuples(aNbCells);
171 aConnectivity->InitTraversal();
172 for(int i=0; aConnectivity->GetNextCell(npts,pts); i++)
173 aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
174 theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
175 if(MYVTKDEBUG) aConnectivity->DebugOn();
176 aCellLocationsArray->Delete();
177 aCellTypesArray->Delete();
178 aConnectivity->Delete();
182 void GetCellsOnGroup(VISU::TVTKSource& theStorage,
183 const VISU::TMesh& theMesh,
184 const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
185 throw (std::runtime_error&)
187 //Calculate dimentions of the group
188 int aNbCells = 0, aCellsSize = 0;
189 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
190 for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
191 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
192 const string& aFamilyName = aFamilyAndEntity.first;
193 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
194 const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second;
195 pair<int,int> aCellsDim = aMeshOnEntity.GetCellsDims(aFamilyName);
196 aNbCells += aCellsDim.first;
197 aCellsSize += aCellsDim.second;
199 vtkCellArray* aConnectivity = vtkCellArray::New();
200 aConnectivity->Allocate(aCellsSize,0);
201 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
202 aCellTypesArray->SetNumberOfComponents(1);
203 aCellTypesArray->SetNumberOfTuples(aNbCells);
204 aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
205 for(int i = 0, j = 0; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
206 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
207 const string& aFamilyName = aFamilyAndEntity.first;
208 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
209 const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second;
210 const VISU::TFamily& aFamily = *(VISU::GetFamily(aMeshOnEntity,aFamilyName));
211 const VISU::TMeshOnEntity::TCellsConn &aCellsConn = aMeshOnEntity.myCellsConn;
212 VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin();
213 for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){
214 const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second;
215 int aVtkType = aCellsConnIter->first;
217 MESSAGE("GetCellsOnGroup - aVtkType = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
218 const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
220 throw std::runtime_error(EXCEPTION("GetCells >> There is no elements on the family !!!"));
221 VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType);
222 if(aSubMeshIter == aSubMesh.end()) continue;
223 const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
225 MESSAGE("GetCellsOnGroup - aSubMeshOnCellType.size() = "<<aSubMeshOnCellType.size());
226 VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
227 for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++, i++){
228 PrintCells(i,aConnectivity,anArray[*aSubMeshOnCellTypeIter]);
229 aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
233 vtkIdType *pts = 0, npts = 0;
234 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
235 aCellLocationsArray->SetNumberOfComponents(1);
236 aCellLocationsArray->SetNumberOfTuples(aNbCells);
237 aConnectivity->InitTraversal();
238 for(int i = 0; aConnectivity->GetNextCell(npts,pts); i++)
239 aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
240 theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
241 aCellLocationsArray->Delete();
242 aCellTypesArray->Delete();
243 aConnectivity->Delete();
247 void InitProfile(VISU::TVTKExtractFilter& theFilter,
248 const VISU::TMeshOnEntity& theMeshOnEntity,
249 const VISU::TField::TValForTime& theValForTime)
250 throw (std::runtime_error&)
252 const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells;
253 const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn;
254 VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin();
255 for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){
256 const vtkIdType& aCellType = aCellsConnIter->first;
257 if(aValForCells.find(aCellType) == aValForCells.end())
258 theFilter->RemoveCellsWithType(aCellType);
263 void GetValsOnTimeStamp(vtkFloatArray *theFloatArray,
264 const vtkIdType& theNumberOfTuples,
265 const std::string& theFieldName,
266 const VISU::TField& theField,
267 const VISU::TField::TValForTime& theValForTime)
268 throw (std::runtime_error&)
270 //theFloatArray->DebugOn();
271 theFloatArray->SetNumberOfTuples(theNumberOfTuples);
272 theFloatArray->SetName(theFieldName.c_str());
273 if(MYDEBUG) MESSAGE("GetValsOnTimeStamp - theNumberOfTuples = "<<theNumberOfTuples);
274 const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells;
275 VISU::TField::TValForCells::const_iterator aValForCellsIter = aValForCells.begin();
276 for(int k = 0; aValForCellsIter != aValForCells.end(); aValForCellsIter++) {
277 const VISU::TField::TValForCellsWithType& anArray = aValForCellsIter->second;
278 int iEnd = anArray.size()/theField.myNbComp;
279 int aVtkType = aValForCellsIter->first;
280 if(MYDEBUG) MESSAGE("GetValsOnTimeStamp - iEnd = "<<iEnd<<"; aVtkType = "<<aVtkType);
281 switch(theField.myNbComp) {
283 for (int i = 0; i < iEnd; i++)
284 theFloatArray->SetTuple1(k++,anArray[i]);
287 for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*2)
288 theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+1],0.0);
291 for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*3)
292 theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+1],anArray[ji+2]);
295 for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*4)
296 theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+2],0.0);
299 for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*4)
300 theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+2],anArray[ji+5]);
303 throw std::runtime_error(EXCEPTION("GetValsOnTimeStamp - There is no an algorithm for representation of the field !!!"));
308 string GenerateFieldName(const VISU::TField& theField,
309 const VISU::TField::TValForTime& theValForTime)
311 const VISU::TField::TTime& aTime = theValForTime.myTime;
312 string aFieldName = theField.myMeshName + ", " + theField.myName + ": " +
313 VISU_Convertor::GenerateName(aTime);
317 void GetTimeStamp(VISU::TVTKSource& theStorage,
318 const VISU::TMesh& theMesh,
319 const VISU::TMeshOnEntity& theMeshOnEntity,
320 const VISU::TField& theField,
321 const VISU::TField::TValForTime& theValForTime)
322 throw (std::runtime_error&)
324 int aNumberOfTuples = theField.myDataSize/theField.myNbComp;
325 string aFieldName = GenerateFieldName(theField,theValForTime);
327 MESSAGE("GetTimeStamp(TVTKSource) - aFieldName = "<<aFieldName<<
328 "; aNumberOfTuples = "<<aNumberOfTuples);
330 vtkDataSetAttributes* aDataSetAttributes;
331 switch(theField.myEntity){
332 case VISU::NODE_ENTITY :
333 aDataSetAttributes = theStorage->GetPointData();
336 aDataSetAttributes = theStorage->GetCellData();
339 vtkFloatArray *aFloatArray = vtkFloatArray::New();
340 switch(theField.myNbComp) {
342 aFloatArray->SetNumberOfComponents(1);
343 aDataSetAttributes->SetScalars(aFloatArray);
346 aFloatArray->SetNumberOfComponents(3);
347 aDataSetAttributes->SetVectors(aFloatArray);
350 GetValsOnTimeStamp(aFloatArray,aNumberOfTuples,aFieldName,theField,theValForTime);
353 void GetTimeStamp(VISU::TVTKAttribyteFilter& theAttribyteFilter,
354 VISU::TVTKMergetFilter& theMergeFilter,
355 VISU::TVTKExtractFilter& theExtractFilter,
356 const VISU::TMesh& theMesh,
357 const VISU::TMeshOnEntity& theMeshOnEntity,
358 const VISU::TField& theField,
359 const VISU::TField::TValForTime& theValForTime)
360 throw (std::runtime_error&)
362 int aNumberOfTuples = theField.myDataSize/theField.myNbComp;
363 string aFieldName = GenerateFieldName(theField,theValForTime);
365 MESSAGE("GetTimeStamp(TVTKAttribyteFilter) - aFieldName = "<<aFieldName<<
366 "; aNumberOfTuples = "<<aNumberOfTuples);
368 vtkDataObject* aDataObject = vtkDataObject::New();
369 theMergeFilter->SetDataObject(aDataObject);
370 aDataObject->Delete();
372 theMergeFilter->SetInput(theExtractFilter->GetOutput());
373 theAttribyteFilter->SetInput(theMergeFilter->GetOutput());
375 switch(theField.myEntity){
376 case VISU::NODE_ENTITY :
377 theMergeFilter->SetOutputFieldToPointDataField();
378 theAttribyteFilter->SetInputFieldToPointDataField();
379 theAttribyteFilter->SetOutputAttributeDataToPointData();
382 theMergeFilter->SetOutputFieldToCellDataField();
383 theAttribyteFilter->SetInputFieldToCellDataField();
384 theAttribyteFilter->SetOutputAttributeDataToCellData();
387 vtkFloatArray *aFloatArray = vtkFloatArray::New();
388 switch(theField.myNbComp) {
390 aFloatArray->SetNumberOfComponents(1);
391 theAttribyteFilter->SetScalarComponent(0,aFieldName.c_str(),0);
394 aFloatArray->SetNumberOfComponents(3);
395 theAttribyteFilter->SetVectorComponent(0,aFieldName.c_str(),0);
396 theAttribyteFilter->SetVectorComponent(1,aFieldName.c_str(),1);
397 theAttribyteFilter->SetVectorComponent(2,aFieldName.c_str(),2);
400 vtkFieldData* aFieldData = aDataObject->GetFieldData();
401 aFieldData->AddArray(aFloatArray);
402 aFloatArray->Delete();
404 GetValsOnTimeStamp(aFloatArray,aNumberOfTuples,aFieldName,theField,theValForTime);
408 VISU_Convertor_impl::VISU_Convertor_impl() {
412 VISU_Convertor_impl::~VISU_Convertor_impl() {}
414 VISU_Convertor::TOutput*
415 VISU_Convertor_impl::GetMeshOnEntity(const string& theMeshName,
416 const VISU::TEntity& theEntity,
417 const string& theFamilyName)
418 throw (std::runtime_error&)
421 MESSAGE("GetMeshOnEntity - theMeshName = '"<<theMeshName<<
422 "'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
423 //Cheching possibility do the query
424 VISU::TMesh* pMesh = NULL;
425 VISU::TFamily* pFamily = NULL;
426 VISU::TMeshOnEntity* pMeshOnEntity = NULL;
427 FindMeshOnEntity(theMeshName,pMesh,theEntity,pMeshOnEntity,theFamilyName,pFamily);
428 VISU::TMesh& aMesh = *pMesh;
429 VISU::TMeshOnEntity& aMeshOnEntity = *pMeshOnEntity;
430 VISU::TVTKSource* pSource;
432 pSource = &(pFamily->myStorage);
434 pSource = &(aMeshOnEntity.myStorage);
435 VISU::TVTKSource& aSource = *pSource;
438 if(aSource.GetPointer() == NULL){
439 aSource = TOutput::New();
441 if(MYVTKDEBUG) aSource->DebugOn();
442 LoadMeshOnEntity(aMeshOnEntity,theFamilyName);
443 GetPoints(aSource,aMesh);
444 GetCellsOnEntity(aSource,aMeshOnEntity,theFamilyName);
445 if(MYDEBUGWITHFILES){
446 string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
447 string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1();
448 string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-";
449 aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFamilyName + "-Conv.vtk";
450 VISU::WriteToFile(aSource.GetPointer(),aFileName);
454 GetMeshOnEntitySize(theMeshName,theEntity,theFamilyName);
455 vtkUnstructuredGrid* aDataSet = aSource.GetPointer();
457 MESSAGE("GetMeshOnEntity - GetPoints() = "<<float(aDataSet->GetPoints()->GetActualMemorySize()*1000));
458 MESSAGE("GetMeshOnEntity - GetCells() = "<<float(aDataSet->GetCells()->GetActualMemorySize()*1000));
459 MESSAGE("GetMeshOnEntity - GetCellTypesArray() = "<<float(aDataSet->GetCellTypesArray()->GetActualMemorySize()*1000));
460 MESSAGE("GetMeshOnEntity - GetCellLocationsArray() = "<<float(aDataSet->GetCellLocationsArray()->GetActualMemorySize()*1000));
461 aDataSet->BuildLinks();
462 MESSAGE("GetMeshOnEntity - GetCellLinks() = "<<float(aDataSet->GetCellLinks()->GetActualMemorySize()*1000));
463 MESSAGE("GetMeshOnEntity - GetActualMemorySize() = "<<float(aDataSet->GetActualMemorySize()*1000));
466 aSource = vtkSmartPointerBase();
469 return aSource.GetPointer();
472 VISU_Convertor::TOutput*
473 VISU_Convertor_impl::GetMeshOnGroup(const string& theMeshName,
474 const string& theGroupName)
475 throw(std::runtime_error&)
477 if(MYDEBUG) MESSAGE("GetMeshOnGroup - theMeshName = '"<<theMeshName<<
478 "'; theGroupName = '"<<theGroupName<<"'");
479 //Cheching possibility do the query
480 VISU::TMesh* pMesh = NULL;
481 VISU::TGroup* pGroup = NULL;
482 FindMeshOnGroup(theMeshName,pMesh,theGroupName,pGroup);
483 VISU::TMesh& aMesh = *pMesh;
484 VISU::TGroup& aGroup = *pGroup;
485 const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup.myFamilyAndEntitySet;
486 VISU::TVTKSource& aSource = aGroup.myStorage;
489 if(aSource.GetPointer() == NULL){
490 aSource = TOutput::New();
492 LoadMeshOnGroup(aMesh,aFamilyAndEntitySet);
493 GetPoints(aSource,aMesh);
494 GetCellsOnGroup(aSource,aMesh,aFamilyAndEntitySet);
495 if(MYDEBUGWITHFILES){
496 string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
497 string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1();
498 string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-";
499 aFileName += aMeshName + "-" + aGroupName + "-Conv.vtk";
500 VISU::WriteToFile(aSource.GetPointer(),aFileName);
504 aSource = vtkSmartPointerBase();
507 return aSource.GetPointer();
510 VISU_Convertor::TOutput*
511 VISU_Convertor_impl::GetTimeStampOnMesh(const string& theMeshName,
512 const VISU::TEntity& theEntity,
513 const string& theFieldName,
515 throw(std::runtime_error&)
518 MESSAGE("GetTimeStampOnMesh - theMeshName = '"<<theMeshName<<"; theEntity = "<<theEntity);
519 MESSAGE("GetTimeStampOnMesh - theFieldName = '"<<theFieldName<<"'; theStampsNum = "<<theStampsNum);
521 //Cheching possibility do the query
522 VISU::TMesh* pMesh = NULL;
523 VISU::TField* pField = NULL;
524 VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL;
525 VISU::TField::TValForTime* pValForTime = NULL;
526 FindTimeStamp(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity,
527 theFieldName,pField,theStampsNum,pValForTime);
528 VISU::TMesh& aMesh = *pMesh;
529 VISU::TMeshOnEntity& aMeshOnEntity = *pMeshOnEntity;
530 VISU::TField& aField = *pField;
531 VISU::TField::TValForTime& aValForTime = *pValForTime;
532 VISU::TVTKAttribyteFilter& anAttribyteFilter = aValForTime.myAttribyteFilter;
533 VISU::TVTKSource& aSource = aValForTime.myStorage;
534 TOutput* anOutput = NULL;
537 if(aSource.GetPointer())
538 return aSource.GetPointer();
539 else if(anAttribyteFilter.GetPointer())
540 return anAttribyteFilter->GetUnstructuredGridOutput();
542 LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime);
544 VISU::TVTKExtractFilter& anExtractFilter = aField.myExtractFilter;
545 if(anExtractFilter.GetPointer() == NULL){
546 anExtractFilter = VISU_ExtractUnstructuredGrid::New();
547 anExtractFilter->Delete();
548 //anExtractFilter->DebugOn();
550 LoadMeshOnEntity(*pVTKMeshOnEntity);
551 }catch(std::runtime_error& exc){
552 pVTKMeshOnEntity = pMeshOnEntity;
553 MESSAGE("Follow exception was accured :\n"<<exc.what());
555 pVTKMeshOnEntity = pMeshOnEntity;
556 MESSAGE("Unknown exception was accured!");
558 GetMeshOnEntity(pVTKMeshOnEntity->myMeshName,pVTKMeshOnEntity->myEntity);
560 anExtractFilter->SetInput(pVTKMeshOnEntity->myStorage.GetPointer());
561 ::InitProfile(anExtractFilter,*pMeshOnEntity,aValForTime);
563 if(!anExtractFilter->IsRemoving()){
564 aSource = TOutput::New();
566 aSource->ShallowCopy(pVTKMeshOnEntity->myStorage.GetPointer());
567 ::GetTimeStamp(aSource,aMesh,*pVTKMeshOnEntity,aField,aValForTime);
568 anOutput = aSource.GetPointer();
570 anAttribyteFilter = vtkFieldDataToAttributeDataFilter::New();
571 anAttribyteFilter->Delete();
572 //anAttribyteFilter->DebugOn();
574 VISU::TVTKMergetFilter& aMergeFilter = aValForTime.myMergeFilter;
575 aMergeFilter = vtkMergeDataObjectFilter::New();
576 aMergeFilter->Delete();
577 //aMergeFilter->DebugOn();
579 ::GetTimeStamp(anAttribyteFilter,aMergeFilter,anExtractFilter,
580 aMesh,*pVTKMeshOnEntity,aField,aValForTime);
581 anOutput = anAttribyteFilter->GetUnstructuredGridOutput();
583 if(MYDEBUGWITHFILES){
584 string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
585 string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1();
586 string aPrefix = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-";
587 string aFileName = aPrefix + aMeshName + dtos("-%d-",int(theEntity)) +
588 aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk";
589 VISU::WriteToFile(anOutput,aFileName);
592 GetTimeStampSize(theMeshName,theEntity,theFieldName,theStampsNum);
593 vtkUnstructuredGrid *aDataSet = anAttribyteFilter->GetUnstructuredGridOutput();
595 if(theEntity == VISU::NODE_ENTITY)
596 MESSAGE("GetTimeStampOnMesh - GetData() = "<<float(aDataSet->GetPointData()->GetActualMemorySize()*1000));
598 MESSAGE("GetMeshOnEntity - GetData() = "<<float(aDataSet->GetCellData()->GetActualMemorySize()*1000));
599 MESSAGE("GetTimeStampOnMesh - GetActualMemorySize() = "<<float(aDataSet->GetActualMemorySize()*1000));
603 aSource = vtkSmartPointerBase();
604 anAttribyteFilter = vtkSmartPointerBase();
610 void VISU_Convertor_impl::FindMesh(const string& theMeshName, VISU::TMesh*& theMesh)
611 throw (std::runtime_error&)
614 if(myMeshMap.find(theMeshName) == myMeshMap.end())
615 throw std::runtime_error(EXCEPT("FindMesh >> There is no mesh with the name - '%1'!!!").
616 arg(theMeshName.c_str()).latin1());
617 theMesh = &myMeshMap[theMeshName];
621 void VISU_Convertor_impl::FindMeshOnEntity(const string& theMeshName,
622 VISU::TMesh*& theMesh,
623 const VISU::TEntity& theEntity,
624 VISU::TMeshOnEntity*& theMeshOnEntity,
625 const string& theFamilyName,
626 VISU::TFamily*& theFamily)
627 throw (std::runtime_error&)
629 FindMesh(theMeshName,theMesh);
630 VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
631 if(aMeshOnEntityMap.find(theEntity) == aMeshOnEntityMap.end())
632 throw std::runtime_error(EXCEPT("FindMeshOnEntity >> There is no mesh on the entity - %1!!!").
633 arg(int(theEntity)).latin1());
634 theMeshOnEntity = &aMeshOnEntityMap[theEntity];
635 theFamily = VISU::GetFamily(*theMeshOnEntity,theFamilyName);
639 float VISU_Convertor_impl::GetSize() throw (std::runtime_error&){
641 const VISU::TMeshMap& aMeshMap = GetMeshMap();
642 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
643 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
644 const string& aMeshName = aMeshMapIter->first;
645 const VISU::TMesh& aMesh = aMeshMapIter->second;
646 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
647 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
649 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
650 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
651 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
652 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
653 const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
654 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
655 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
656 const string& aFieldName = aFieldMapIter->first;
657 const VISU::TField& aField = aFieldMapIter->second;
658 const VISU::TField::TValField& aValField = aField.myValField;
659 VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
660 for(; aValFieldIter != aValField.end(); aValFieldIter++){
661 int aTimeStamp = aValFieldIter->first;
662 aResult += GetTimeStampSize(aMeshName,anEntity,aFieldName,aTimeStamp);
666 const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
667 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
668 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
669 const string& aGroupName = aGroupMapIter->first;
670 aResult += GetMeshOnGroupSize(aMeshName,aGroupName);
673 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
674 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
675 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
676 const string& aFamilyName = aFamilyMapIter->first;
677 aResult += GetMeshOnEntitySize(aMeshName,anEntity,aFamilyName);
679 //Import mesh on entity
680 aResult += GetMeshOnEntitySize(aMeshName,anEntity);
684 MESSAGE("GetSize - aResult = "<<float(aResult));
689 float VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName,
690 const VISU::TEntity& theEntity,
691 const std::string& theFamilyName)
692 throw (std::runtime_error&)
694 VISU::TMesh* pMesh = NULL;
695 VISU::TFamily* pFamily = NULL;
696 VISU::TMeshOnEntity* pMeshOnEntity = NULL;
697 FindMeshOnEntity(theMeshName,pMesh,theEntity,pMeshOnEntity,theFamilyName,pFamily);
698 vtkIdType aPointsSize = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord);
699 vtkIdType aNbCells, aCellsSize;
701 aNbCells = pMeshOnEntity->myNbCells;
702 aCellsSize = pMeshOnEntity->myCellsSize;
704 aNbCells = pFamily->myNbCells;
705 aCellsSize = pFamily->myCellsSize;
707 vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType);
708 vtkIdType aTypesSize = aNbCells*sizeof(char);
709 vtkIdType aLocationsSize = aNbCells*sizeof(int);
710 float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
711 vtkIdType aLinksSize = pMesh->myNbPoints *
712 (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link));
714 vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize;
717 MESSAGE("GetMeshOnEntitySize - aPointsSize = "<<float(aPointsSize));
718 MESSAGE("GetMeshOnEntitySize - aConnectivitySize = "<<float(aConnectivitySize));
719 MESSAGE("GetMeshOnEntitySize - aTypesSize = "<<float(aTypesSize));
720 MESSAGE("GetMeshOnEntitySize - aLocationsSize = "<<float(aLocationsSize));
721 MESSAGE("GetMeshOnEntitySize - aLinksSize = "<<float(aLinksSize));
723 MESSAGE("GetMeshOnEntitySize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<
724 "'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
726 aResult = vtkIdType(aResult*ERR_SIZE_CALC);
731 void VISU_Convertor_impl::FindMeshOnGroup(const std::string& theMeshName, VISU::TMesh*& theMesh,
732 const std::string& theGroupName, VISU::TGroup*& theGroup)
733 throw (std::runtime_error&)
735 FindMesh(theMeshName,theMesh);
736 VISU::TGroupMap& aGroupMap = theMesh->myGroupMap;
737 VISU::TGroupMap::iterator aGroupMapIter = aGroupMap.find(theGroupName);
738 if(aGroupMapIter == aGroupMap.end())
739 throw std::runtime_error(EXCEPT("FindMesh >> There is no the group in the mesh!!! - '%1'").arg(theGroupName.c_str()).latin1());
740 theGroup = &aGroupMapIter->second;
744 float VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName,
745 const std::string& theGroupName)
746 throw (std::runtime_error&)
748 VISU::TMesh* pMesh = NULL;
749 VISU::TGroup* pGroup = NULL;
750 FindMeshOnGroup(theMeshName,pMesh,theGroupName,pGroup);
751 vtkIdType aPointsSize = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord);
752 vtkIdType aNbCells = pGroup->myNbCells, aCellsSize = pGroup->myCellsSize;
753 vtkIdType aConnectivityAndTypesSize = aCellsSize*sizeof(vtkIdType);
754 vtkIdType aLocationsSize = aNbCells*sizeof(int);
755 float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
756 vtkIdType aLinksSize = pMesh->myNbPoints *
757 (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short));
759 vtkIdType aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize;
762 MESSAGE("GetMeshOnGroupSize - aPointsSize = "<<float(aPointsSize));
763 MESSAGE("GetMeshOnGroupSize - aConnectivityAndTypesSize = "<<float(aConnectivityAndTypesSize));
764 MESSAGE("GetMeshOnGroupSize - aLocationsSize = "<<float(aLocationsSize));
765 MESSAGE("GetMeshOnGroupSize - aLinksSize = "<<float(aLinksSize));
767 MESSAGE("GetMeshOnGroupSize - aResult = "<<float(aResult)<<"; theMeshName = '"
768 <<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
770 aResult = vtkIdType(aResult*ERR_SIZE_CALC);
775 void VISU_Convertor_impl::FindField(const string& theMeshName, VISU::TMesh*& theMesh,
776 const VISU::TEntity& theEntity,
777 VISU::TMeshOnEntity*& theMeshOnEntity,
778 VISU::TMeshOnEntity*& theVTKMeshOnEntity,
779 const string& theFieldName, VISU::TField*& theField)
780 throw (std::runtime_error&)
782 VISU::TFamily* pFamily = NULL;
783 VISU::TMeshOnEntity* pMeshOnEntity = NULL;
784 FindMeshOnEntity(theMeshName,theMesh,theEntity,pMeshOnEntity,"",pFamily);
785 theMeshOnEntity = pMeshOnEntity;
786 VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
787 if(theEntity == VISU::NODE_ENTITY){
788 if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) != aMeshOnEntityMap.end())
789 pMeshOnEntity = &aMeshOnEntityMap[VISU::CELL_ENTITY];
790 else if(aMeshOnEntityMap.find(VISU::FACE_ENTITY) != aMeshOnEntityMap.end())
791 pMeshOnEntity = &aMeshOnEntityMap[VISU::FACE_ENTITY];
792 else if(aMeshOnEntityMap.find(VISU::NODE_ENTITY) != aMeshOnEntityMap.end())
793 pMeshOnEntity = &aMeshOnEntityMap[VISU::EDGE_ENTITY];
795 theVTKMeshOnEntity = pMeshOnEntity;
796 VISU::TFieldMap& aFieldMap = theMeshOnEntity->myFieldMap;
797 if(aFieldMap.find(theFieldName) == aFieldMap.end())
798 throw std::runtime_error(EXCEPTION("FindField >> There is no field on the mesh!!!"));
799 theField = &aFieldMap[theFieldName];
803 float VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName,
804 const VISU::TEntity& theEntity,
805 const std::string& theFieldName)
806 throw(std::runtime_error&)
808 VISU::TMesh* pMesh = NULL;
809 VISU::TField* pField = NULL;
810 VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL;
811 FindField(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity,
812 theFieldName,pField);
813 float aMeshSize = GetMeshOnEntitySize(theMeshName,pVTKMeshOnEntity->myEntity);
814 float aFieldOnMeshSize = float(pField->myDataSize*sizeof(float)*pField->myNbValField * ERR_SIZE_CALC);
815 float aResult = aMeshSize + aFieldOnMeshSize;
818 MESSAGE("GetFieldOnMeshSize - aFieldOnMeshSize = "<<float(aFieldOnMeshSize));
819 MESSAGE("GetFieldOnMeshSize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<
820 "'; theEntity = "<<theEntity<<"; theFieldName = '"<<theFieldName<<"'");
826 void VISU_Convertor_impl::FindTimeStamp(const std::string& theMeshName, VISU::TMesh*& theMesh,
827 const VISU::TEntity& theEntity,
828 VISU::TMeshOnEntity*& theMeshOnEntity,
829 VISU::TMeshOnEntity*& theVTKMeshOnEntity,
830 const std::string& theFieldName, VISU::TField*& theField,
831 int theStampsNum, VISU::TField::TValForTime*& theValForTime)
832 throw (std::runtime_error&)
834 FindField(theMeshName,theMesh,theEntity,theMeshOnEntity,theVTKMeshOnEntity,theFieldName,theField);
835 VISU::TField::TValField& aValField = theField->myValField;
836 if(aValField.find(theStampsNum) == aValField.end())
837 throw std::runtime_error(EXCEPTION("FindTimeStamp >> There is no field with the timestamp!!!"));
838 theValForTime = &aValField[theStampsNum];
842 float VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName,
843 const VISU::TEntity& theEntity,
844 const std::string& theFieldName,
846 throw (std::runtime_error&)
848 VISU::TMesh* pMesh = NULL;
849 VISU::TField* pField = NULL;
850 VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL;
851 VISU::TField::TValForTime* pValForTime = NULL;
852 FindTimeStamp(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity,
853 theFieldName,pField,theStampsNum,pValForTime);
854 float aMeshSize = GetMeshOnEntitySize(theMeshName,pVTKMeshOnEntity->myEntity);
855 float aTimeStampSize = float(pField->myDataSize*sizeof(float) * ERR_SIZE_CALC);
856 float aResult = aMeshSize + aTimeStampSize;
859 MESSAGE("GetTimeStampSize - aTimeStampSize = "<<float(aTimeStampSize));
860 MESSAGE("GetTimeStampSize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<
861 "; theFieldName = '"<<theFieldName<<"'; theStampsNum = "<<theStampsNum);
868 VISU_Convertor_impl::GetField(const string& theMeshName,
869 VISU::TEntity theEntity,
870 const string& theFieldName)
871 throw (std::runtime_error&)
873 VISU::TMesh* pMesh = NULL;
874 VISU::TField* pField = NULL;
875 VISU::TFamily* pFamily = NULL;
876 VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL;
877 FindField(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity,
878 theFieldName,pField);
883 const VISU::TField::TValForTime&
884 VISU_Convertor_impl::GetTimeStamp(const std::string& theMeshName,
885 const VISU::TEntity& theEntity,
886 const std::string& theFieldName,
888 throw (std::runtime_error&)
890 VISU::TMesh* pMesh = NULL;
891 VISU::TField* pField = NULL;
892 VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL;
893 VISU::TField::TValForTime* pValForTime = NULL;
894 FindTimeStamp(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity,
895 theFieldName,pField,theStampsNum,pValForTime);