1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : VISU_Convertor.cxx
6 // Author : Alexey PETROV
10 #include "VISU_Convertor.hxx"
13 #include <vtkCellType.h>
15 #include <qfileinfo.h>
16 #include <qstringlist.h>
21 static int MYDEBUG = 1;
23 static int MYDEBUG = 1;
27 TVtkCellInfoMap aVtkCellInfoMap;
29 aVtkCellInfoMap[VTK_VERTEX] = TVtkCellInfo("VTK_VERTEX",1),
30 aVtkCellInfoMap[VTK_LINE] = TVtkCellInfo("VTK_LINE",2),
31 aVtkCellInfoMap[VTK_TRIANGLE] = TVtkCellInfo("VTK_TRIANGLE",3),
32 aVtkCellInfoMap[VTK_QUAD] = TVtkCellInfo("VTK_QUAD",4),
33 aVtkCellInfoMap[VTK_TETRA] = TVtkCellInfo("VTK_TETRA",4),
34 aVtkCellInfoMap[VTK_HEXAHEDRON] = TVtkCellInfo("VTK_HEXAHEDRON",8),
35 aVtkCellInfoMap[VTK_WEDGE] = TVtkCellInfo("VTK_WEDGE",6),
36 aVtkCellInfoMap[VTK_PYRAMID] = TVtkCellInfo("VTK_PYRAMID",5),
39 pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
40 throw(std::runtime_error&)
42 bool isFamilyPresent = (theFamilyName != "");
43 int aNbCells = 0, aCellsSize = 0;
45 TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin();
46 for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){
47 const TConnForCellType& aConnForCellType = aCellsConnIter->second;
48 if(!aConnForCellType.empty()){
49 aNbCells += aConnForCellType.size();
50 aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1);
54 TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
55 if(aFamilyMapIter == myFamilyMap.end())
56 throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
57 const TFamily& aFamily = aFamilyMapIter->second;
58 const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
59 TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin();
60 for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){
61 const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
62 if(!aSubMeshOnCellType.empty()){
63 int tmp = aSubMeshOnCellType.size();
65 int aVtkType = aSubMeshIter->first;
66 int aVtkSize = aVtkCellInfoMap[aVtkType].mySize;
67 aCellsSize += tmp*(aVtkSize+1);
71 return make_pair(aNbCells,aCellsSize);
74 void TMesh::CreateMeshOnNodes(){
75 TMeshOnEntity& aMeshOnEntity = myMeshOnEntityMap[NODE_ENTITY];
76 TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
77 int jEnd = myPointsCoord.size()/myDim;
78 aConnForCellType.resize(jEnd);
79 for (int j = 0; j < jEnd; j++) aConnForCellType[j] = TMeshOnEntity::TConnect(1,j);
82 const TField* TMesh::GetField(const string& theFieldName) const {
83 TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin();
84 for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
85 const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap;
86 TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
87 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++)
88 if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second);
93 const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
94 throw(std::runtime_error&)
96 if(theFamilyName == "") return NULL;
97 const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
98 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
99 if(aFamilyMapIter == aFamilyMap.end())
100 throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
101 const VISU::TFamily& aFamily = aFamilyMapIter->second;
105 TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
106 throw(std::runtime_error&)
108 if(theFamilyName == "") return NULL;
109 VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
110 VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
111 if(aFamilyMapIter == aFamilyMap.end())
112 throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
113 VISU::TFamily& aFamily = aFamilyMapIter->second;
117 void TField::ShallowCopy(const TField& aField){
118 myEntity = aField.myEntity;
119 myMeshName = aField.myMeshName;
120 myNbComp = aField.myNbComp;
121 VISU::TField::TValField::const_iterator iter = aField.myValField.begin();
122 for(; iter != aField.myValField.end(); iter++)
123 myValField[iter->first];
127 const VISU::TMeshMap& VISU_Convertor::GetMeshMap() throw(std::runtime_error&){
128 if(!myIsDone) { myIsDone = true; Build();}
132 const VISU::TField& VISU_Convertor::GetField(const string& theMeshName,
133 VISU::TEntity theEntity,
134 const string& theFieldName)
135 throw (std::runtime_error&)
137 if(!myIsDone) { myIsDone = true; Build();}
138 VISU::TMeshMap::const_iterator aMeshMapIter = myMeshMap.find(theMeshName);
139 if(aMeshMapIter == myMeshMap.end())
140 throw std::runtime_error("GetField >> There is no mesh with the name !!!");
141 const VISU::TMesh& aMesh = aMeshMapIter->second;
142 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMesh.myMeshOnEntityMap.find(theEntity);
143 if(aMeshOnEntityMapIter == aMesh.myMeshOnEntityMap.end())
144 throw std::runtime_error("GetField >> There is no mesh with the entity !!!");
145 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
146 const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
147 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.find(theFieldName);
148 if(aFieldMapIter == aFieldMap.end())
149 throw std::runtime_error("GetField >> There is no field with the name !!!");
150 return aFieldMapIter->second;
153 string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){
154 static QString aName;
155 const string aUnits = aTime.second, tmp(aUnits.size(),' ');
156 if(aUnits == "" || aUnits == tmp)
157 aName.sprintf("%g, -",aTime.first);
159 aName.sprintf("%g, %s",aTime.first,aTime.second.c_str());
160 aName = aName.simplifyWhiteSpace();
161 return aName.latin1();
164 string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) {
165 static QString aName;
166 aName = QString(theName.c_str()).simplifyWhiteSpace();
167 int iEnd = strlen(aName);
168 static int VtkHighLevelLength = 12; //25
169 if(iEnd > VtkHighLevelLength) iEnd = VtkHighLevelLength;
170 char aNewName[iEnd+1];
171 aNewName[iEnd] = '\0';
172 strncpy(aNewName,aName,iEnd);
173 replace(aNewName,aNewName+iEnd,' ','_');
174 if(true || theTimeId == 0)
177 aName.sprintf("%s_%d",aNewName,theTimeId);
178 return aName.latin1();
182 void parseFile(const char* theFileName) throw(std::runtime_error&){
184 auto_ptr<VISU_Convertor> aCon(CreateConvertor(theFileName));
185 const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap();
186 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
187 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
188 const string& aMeshName = aMeshMapIter->first;
189 const VISU::TMesh& aMesh = aMeshMapIter->second;
190 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
191 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
193 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
194 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
195 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
196 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
197 const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
198 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
199 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
200 const string& aFieldName = aFieldMapIter->first;
201 const VISU::TField& aField = aFieldMapIter->second;
202 const VISU::TField::TValField& aValField = aField.myValField;
203 VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
204 for(; aValFieldIter != aValField.end(); aValFieldIter++){
205 int aTimeStamp = aValFieldIter->first;
206 aCon->GetFieldOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
211 const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
212 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
213 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
214 const string& aGroupName = aGroupMapIter->first;
215 aCon->GetMeshOnGroup(aMeshName,aGroupName);
218 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
219 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
220 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
221 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
222 //aCon->GetMeshOnEntity(aMeshName,anEntity);
223 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
224 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
225 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
226 const string& aFamilyName = aFamilyMapIter->first;
227 aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
230 //Import mesh on entity
231 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
232 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
233 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
234 aCon->GetMeshOnEntity(aMeshName,anEntity);
237 }catch(std::runtime_error& exc){
238 MESSAGE("Follow exception was accured in file:"<<theFileName<<"\n"<<exc.what());
240 MESSAGE("Unknown exception was accured in VISU_Convertor_impl in file:"<<theFileName);
244 int main(int argc, char** argv){
247 for(int i = 0; i < 1; i++){
248 QFileInfo fi(argv[1]);
251 QDir aDir(fi.absFilePath());
252 cout<<aDir.absPath()<<endl;
253 QStringList aStringList = aDir.entryList("*.med",QDir::Files);
254 int jEnd = aStringList.count();
255 for(int j = 0; j < jEnd; j++)
256 parseFile(aDir.filePath(aStringList[j]).latin1());
263 }catch(std::runtime_error& exc){
264 cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
266 cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
275 vector<float> myValues;
280 vector<string> myColumnUnits;
281 vector<string> myColumnTitles;
285 vector<TTable2D> aTables;
287 int GetLine(ifstream& theStmIn, QString& theString){
290 while(theStmIn.get(tmp)){
292 if(tmp == '\n') break;
295 auto_ptr<char> aRet(aStrOut.str());
296 theString = aRet.get();
297 return !theStmIn.eof();
300 int main(int argc, char** argv){
304 aStmIn.open(argv[1]);
306 while(!aStmIn.eof()){
307 //Find beginning of Table
308 while(GetLine(aStmIn,aTmp) && aTmp.find("#TITLE:") != 0);
309 if(aStmIn.eof()) return 0;
310 cout<<"\n There is new Table2D with Title = ";
312 while(!aStmIn.eof() && aTmp != "\n"){
313 if(aTmp.find("#TITLE:") == 0){
314 int aLen = aTmp.find(":") + 1;
316 QString aTitle = aTmp.stripWhiteSpace();
317 aTable2D.myTitle = aTitle;
319 }else if(aTmp.find("#COLUMN_TITLES:") == 0){
320 int aLen = aTmp.find(":") + 1;
322 QStringList aStrList = QStringList::split("|",aTmp);
323 cout<<"Its Column Titles : ";
324 for(int i = 0; i < aStrList.count(); i++){
325 aTmp = aStrList[i].stripWhiteSpace();
326 aTable2D.myColumnTitles.push_back(aTmp.latin1());
330 }else if(aTmp.find("#COLUMN_UNITS:") == 0){
331 int aLen = aTmp.find(":") + 1;
333 QStringList aStrList = QStringList::split(" ",aTmp);
334 cout<<"Its Column Units : ";
335 for(int i = 0; i < aStrList.count(); i++){
336 aTmp = aStrList[i].stripWhiteSpace();
337 aTable2D.myColumnUnits.push_back(aTmp.latin1());
341 }else if(aTmp.find("#") == 0){
343 }else if(aTmp.find("#TITLE:") > 0){
344 QStringList aStrList = QStringList::split("#TITLE:",aTmp);
345 QString aTitle = aStrList[1].stripWhiteSpace();
347 aRow.myTitle = aTitle;
349 QStringList aValList = QStringList::split(" ",aStrList[0]);
350 for(int i = 0; i < aValList.count(); i++){
351 float aVal = aValList[i].toFloat();
352 aRow.myValues.push_back(aVal);
355 aTable2D.myRows.push_back(aRow);
358 QStringList aValList = QStringList::split(" ",aTmp);
360 for(int i = 0; i < aValList.count(); i++){
361 float aVal = aValList[i].toFloat();
362 aRow.myValues.push_back(aVal);
365 aTable2D.myRows.push_back(aRow);
368 GetLine(aStmIn,aTmp);
374 }catch(std::runtime_error& exc){
375 cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
377 cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
383 #include "VISU_Extractor.hxx"
384 #include "VISU_FieldTransform.hxx"
385 #include "VISU_LookupTable.hxx"
386 #include "VISU_ScalarBarActor.hxx"
388 #include <vtkRenderWindow.h>
389 #include <vtkRenderer.h>
390 #include <vtkRenderWindowInteractor.h>
391 #include <vtkActor.h>
393 #include <vtkUnstructuredGridReader.h>
394 #include <vtkDataSetMapper.h>
395 #include <vtkUnstructuredGrid.h>
396 #include <vtkDataSet.h>
397 #include <vtkUnstructuredGridWriter.h>
399 #include <vtkAppendPolyData.h>
400 #include <vtkCutter.h>
401 #include <vtkPlane.h>
402 #include <vtkCellDataToPointData.h>
403 #include <vtkPolyDataWriter.h>
405 static float EPS = 1.0E-3;
406 const float PI = 3.1415;
407 extern float* GetIdent(float theR[3][3]);
408 extern float* GetRx(float theRx[3][3], float thaAng);
409 extern float* GetRy(float theRy[3][3], float thaAng);
410 extern float* GetRz(float theRz[3][3], float thaAng);
411 extern void MulMatrix(float C[3][3], const float A[3][3], const float B[3][3]); // C = A*B;
412 extern void Sub(float C[3], const float A[3], float B[3]); // AxB
413 extern float DotMul(const float A[3], const float B[3]); // A*B;
414 extern void Mul(float C[3], const float A[3], float B[3]); // AxB
415 extern void Mul(float C[3], const float A[3], float B); // A*B;
416 extern void CorrectPnt(float thePnt[3], const float BoundPrj[3]);
417 extern void GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]);
419 typedef map<float,float> TXYMap;
420 typedef vector<TXYMap> TCurveVect;
422 void FillCurveXYMap(float theBasePnt[3], float theDir[3], float theBndDist,
423 vtkPolyData* thePolyData, TXYMap& theXYMap)
425 int aNbPoints = thePolyData->GetNumberOfPoints();
426 //cout<<"aNbPoints = "<<aNbPoints<<"\n";
427 vtkPointData *aPointData = thePolyData->GetPointData();
428 vtkScalars *aScalars = aPointData->GetScalars();
429 float aPnt[3], aVect[3], aDist;
430 for(int i = 0; i < aNbPoints; i++){
431 thePolyData->GetPoint(i,aPnt);
432 Sub(aVect,theBasePnt,aPnt);
433 aDist = DotMul(aVect,theDir) / theBndDist;
435 if(aDist < 0.0) aDist = 0.0;
436 if(aDist > 1.0) aDist = 1.0;
437 theXYMap[aDist] = aScalars->GetScalar(i);
438 //cout<<aDist<<"\t"<<theXYMap[aDist]<<endl;
442 void PrintTable(const TCurveVect& theCurveVect){
445 for(int i = 0, iEnd = theCurveVect.size(); i < iEnd; i++){
446 aFileName.sprintf("/users/%s/aCurve_%d.xls",getenv("USER"),i);
447 aStm.open(aFileName.latin1());
448 const TXYMap& aXYMap = theCurveVect[i];
449 TXYMap::const_iterator aXYMapIter = aXYMap.begin();
450 for(; aXYMapIter != aXYMap.end(); aXYMapIter++){
451 float aX = aXYMapIter->first, aY = aXYMapIter->second;
452 aStm<<aX<<"\t"<<aY<<endl;
458 int main(int argc, char** argv){
461 vtkRenderWindow *renWin = vtkRenderWindow::New();
462 vtkRenderer *ren = vtkRenderer::New();
463 renWin->AddRenderer(ren);
464 ren->GetActiveCamera()->ParallelProjectionOn();
465 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
466 iren->SetRenderWindow(renWin);
467 VISU_Convertor* aConvertor = CreateConvertor(argv[1]);
468 const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap();
469 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
470 if(aMeshMapIter == aMeshMap.end()) return 0;
471 const string& aMeshName = aMeshMapIter->first;
472 const VISU::TMesh& aMesh = aMeshMapIter->second;
473 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
474 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
476 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
477 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
478 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
479 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
480 const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
481 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
482 if(aFieldMapIter == aFieldMap.end()) return 0;
483 const string& aFieldName = aFieldMapIter->first;
484 const VISU::TField& aField = aFieldMapIter->second;
485 const VISU::TField::TValField& aValField = aField.myValField;
486 VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
487 if(aValFieldIter == aValField.end()) return 0;
488 int aTimeStamp = aValFieldIter->first;
489 vtkUnstructuredGridReader* aReader =
490 aConvertor->GetFieldOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
491 VISU_Extractor *anExtractor = VISU_Extractor::New();
492 anExtractor->Extract(aReader,aFieldName,0,aField.myNbComp,anEntity);
493 vtkUnstructuredGrid *aDataSet = anExtractor->GetUnstructuredGridOutput();
494 VISU_FieldTransform* aFieldTransform = VISU_FieldTransform::New();
495 aFieldTransform->SetInput(aDataSet);
496 //if(argc > 2) aFieldTransform->SetTransformFunction(&log10);
497 vtkDataSetMapper *aMapper = vtkDataSetMapper::New();
498 float aScalarRange[2], myBounds[6];
499 anExtractor->GetUnstructuredGridOutput()->GetScalarRange(aScalarRange);
500 int aNumberOfColors = 64, aNumberOfLabels = 5;
501 aDataSet->GetBounds(myBounds);
502 cout<<"myBounds : \n";
503 cout<<myBounds[0]<<"\t"<<myBounds[2]<<"\t"<<myBounds[4]<<endl;
504 cout<<myBounds[1]<<"\t"<<myBounds[3]<<"\t"<<myBounds[5]<<endl;
505 //Reused from CutPlanes
506 //---------------------------------------------------------------------
507 float myRotation[3][3];
508 float myAng[3] = {0.0, 0.0, 0.0}, myDir[3], myInvDir[3], myBoundPrj[3], myDBPrj;
509 int myNbPlanes = 1, myBasePlane = 0; //XY;
510 if(argc > 2) myBasePlane = atoi(argv[2]);
511 vtkAppendPolyData *myAppendPolyData = vtkAppendPolyData::New();
513 float aRx[3][3], aRy[3][3], aRz[3][3];
515 if(myBasePlane == 0){ // X-Y
516 if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
517 if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
518 ::MulMatrix(myRotation,aRx,aRy);
520 }else if(myBasePlane == 1){ // Y-Z
521 if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
522 if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
523 ::MulMatrix(myRotation,aRy,aRz);
525 }else if(myBasePlane == 2){ // Z-X
526 if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
527 if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
528 ::MulMatrix(myRotation,aRz,aRx);
531 for(int i = 0; i < 3; i++) myDir[i] = myRotation[i][iPlane];
532 ::Mul(myInvDir,myDir,-1.0);
533 ::GetBoundProject(myBoundPrj, myBounds, myDir);
534 if(MYDEBUG) MESSAGE("myDir "<<myDir[0]<<"; "<<myDir[1]<<"; "<<myDir[2]);
536 myDBPrj = 0.5*myBoundPrj[2];
537 vtkCutter *aCutPlane = vtkCutter::New();
538 aCutPlane->SetInput(aFieldTransform->GetUnstructuredGridOutput());
539 vtkPlane *aPlane = vtkPlane::New();
542 Mul(aOrig,myDir,myBoundPrj[0] + i*myDBPrj);
543 if(0 && MYDEBUG) MESSAGE("aOrig["<<i<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
544 aPlane->SetOrigin(aOrig);
545 if(i == 0) aPlane->SetNormal(myInvDir);
546 else aPlane->SetNormal(myDir);
547 aCutPlane->SetCutFunction(aPlane);
549 myAppendPolyData->AddInput(aCutPlane->GetOutput());
553 //---------------------------------------------------------------------
554 float myDirPln[3], myDirLn[3], myBoundPrjLn[3], myBasePnt[3];
555 if(argc > 3) myBasePlane = atoi(argv[3]);
556 else myBasePlane = myBasePlane + 1;
557 if(argc > 4) myNbPlanes = atoi(argv[4]);
558 TCurveVect aCurveVect(myNbPlanes); //Declaration of Curve container
559 vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
560 if(myBasePlane == 0){ // X-Y
561 if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
562 if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
563 ::MulMatrix(myRotation,aRx,aRy);
565 }else if(myBasePlane == 1){ // Y-Z
566 if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
567 if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
568 ::MulMatrix(myRotation,aRy,aRz);
570 }else if(myBasePlane == 2){ // Z-X
571 if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
572 if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
573 ::MulMatrix(myRotation,aRz,aRx);
576 for(int i = 0; i < 3; i++) myDirPln[i] = myRotation[i][iPlane];
577 // Get Direction of CutLines and its Bounds
578 ::Mul(myDirLn,myDirPln,myDir);
579 ::GetBoundProject(myBoundPrjLn, myBounds, myDirLn);
580 Mul(myBasePnt,myDirLn,myBoundPrjLn[0]);
581 CorrectPnt(myBasePnt,myBounds);
582 cout<<"myBasePnt : "<<myBasePnt[0]<<"\t"<<myBasePnt[1]<<"\t"<<myBasePnt[2]<<endl;
583 cout<<"myDirLn : "<<myDirLn[0]<<"\t"<<myDirLn[1]<<"\t"<<myDirLn[2]<<endl;
584 //-----------------------------------------
585 ::Mul(myInvDir,myDirPln,-1.0);
586 ::GetBoundProject(myBoundPrj, myBounds, myDirPln);
587 int aNbPlanes = myNbPlanes;
588 if (aNbPlanes > 1 ) {
589 myDBPrj = myBoundPrj[2]/(aNbPlanes - 1);
590 for (int i = 0; i < aNbPlanes; i++){
591 vtkCutter *aCutPlane = vtkCutter::New();
592 aCutPlane->SetInput(myAppendPolyData->GetOutput());
593 vtkPlane *aPlane = vtkPlane::New();
595 Mul(aOrig,myDirPln,myBoundPrj[0] + i*myDBPrj);
596 if(0 && MYDEBUG) MESSAGE("aOrig["<<i<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
597 aPlane->SetOrigin(aOrig);
598 if(i == 0) aPlane->SetNormal(myInvDir);
599 else aPlane->SetNormal(myDirPln);
600 aCutPlane->SetCutFunction(aPlane);
602 vtkPolyData *aPolyData = aCutPlane->GetOutput();
604 anAppendPolyData->AddInput(aPolyData);
605 FillCurveXYMap(myBasePnt,myDirLn,myBoundPrjLn[2],aPolyData,aCurveVect[i]);
607 string aFileName("/users/");
608 aFileName = aFileName + getenv("USER") + "/" + "CutLine" + dtos("-%d.vtk",i);
609 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
610 aWriter->SetFileName(aFileName.c_str());
611 aWriter->SetInput(anAppendPolyData->GetInput(i));
612 //aWriter->SetInput(aCutPlane->GetOutput());
617 myDBPrj = myBoundPrj[2]/2.0;
619 vtkCutter *aCutPlane = vtkCutter::New();
620 aCutPlane->SetInput(myAppendPolyData->GetOutput());
621 vtkPlane *aPlane = vtkPlane::New();
623 Mul(aOrig,myDirPln,myBoundPrj[0] + i*myDBPrj);
624 if(0 && MYDEBUG) MESSAGE("aOrig["<<i<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
625 aPlane->SetOrigin(aOrig);
626 if(i == 0) aPlane->SetNormal(myInvDir);
627 else aPlane->SetNormal(myDirPln);
628 aCutPlane->SetCutFunction(aPlane);
630 vtkPolyData *aPolyData = aCutPlane->GetOutput();
632 anAppendPolyData->AddInput(aPolyData);
633 FillCurveXYMap(myBasePnt,myDirLn,myBoundPrjLn[2],aPolyData,aCurveVect[i]);
637 PrintTable(aCurveVect);
638 aMapper->SetInput(anAppendPolyData->GetOutput());
640 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
641 string aFileName("/users/");
642 aFileName = aFileName + getenv("USER") + "/" + "CutLines.vtk";
643 aWriter->SetFileName(aFileName.c_str());
644 aWriter->SetInput(anAppendPolyData->GetOutput());
648 //aMapper->SetInput(myAppendPolyData->GetOutput());
650 //aMapper->SetInput(aFieldTransform->GetUnstructuredGridOutput());
651 aMapper->ScalarVisibilityOn();
652 VISU_LookupTable* aActorLookupTbl = VISU_LookupTable::New();
653 //if(argc > 2) aActorLookupTbl->SetLog(true);
654 aActorLookupTbl->SetHueRange(0.667,0.0);
655 aActorLookupTbl->SetNumberOfColors(aNumberOfColors);
656 aActorLookupTbl->SetTableRange(aScalarRange[0],aScalarRange[1]); //
657 aActorLookupTbl->SetMapScale(1.);
658 aActorLookupTbl->Build();
659 aMapper->SetLookupTable(aActorLookupTbl);
660 aMapper->SetScalarRange(aScalarRange);
661 aActorLookupTbl->Delete();
663 vtkActor* aActor = vtkActor::New();
664 aActor->SetMapper(aMapper);
666 VISU_ScalarBarActor* aBar = VISU_ScalarBarActor::New();
667 VISU_LookupTable* aBarLookupTbl = VISU_LookupTable::New();
668 //if(argc > 2) aBarLookupTbl->SetLog(true);
669 aBarLookupTbl->SetHueRange(0.667,0.0);
670 aBarLookupTbl->SetNumberOfColors(aNumberOfColors);
671 aBarLookupTbl->SetTableRange(aScalarRange[0],aScalarRange[1]); //
672 aBarLookupTbl->Build();
673 aBar->SetLookupTable(aBarLookupTbl);
674 aBarLookupTbl->Delete();
676 aBar->SetTitle(aFieldName.c_str());
677 aBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
678 aBar->SetNumberOfLabels(aNumberOfLabels);
680 vtkProperty* aProperty = aActor->GetProperty();
681 aProperty->SetSpecularColor( 1, 1, 1);
682 aProperty->SetSpecular( 0.3 );
683 aProperty->SetSpecularPower( 20 );
684 aProperty->SetAmbient( 0.2);
685 aProperty->SetDiffuse( 0.8 );
686 aProperty->EdgeVisibilityOn();
688 ren->AddActor(aActor);
689 ren->AddActor2D(aBar);
696 }catch(std::runtime_error& exc){
697 cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
699 cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;