Salome HOME
Fix for Bug PAL8597:
[modules/visu.git] / src / PIPELINE / VISUPipeLine.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 // File:    VISU_PipeLine.hxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26
27 #include "VISU_Convertor.hxx"
28 #include "VISU_MeshPL.hxx"
29 #include "VISU_ScalarMapPL.hxx"
30 #include "VISU_IsoSurfacesPL.hxx"
31 #include "VISU_CutPlanesPL.hxx"
32 #include "VISU_CutLinesPL.hxx"
33 #include "VISU_DeformedShapePL.hxx"
34 #include "VISU_VectorsPL.hxx"
35 #include "VISU_StreamLinesPL.hxx"
36 #include "VISU_Plot3DPL.hxx"
37
38 typedef VISU_Plot3DPL TPresent;
39
40 #include <vtkUnstructuredGrid.h>
41 #include <vtkDataSetMapper.h>
42
43 #include <vtkRenderWindowInteractor.h>
44 #include <vtkRenderWindow.h>
45 #include <vtkRenderer.h>
46 #include <vtkCamera.h>
47 #include <vtkActor.h>
48
49 #include <vtkProperty.h>
50
51 #include "utilities.h"
52
53 using namespace std;
54
55 static int isOnlyMesh = false;
56
57 int main(int argc, char** argv){
58   try{
59     if(argc > 1){
60       vtkRenderWindow *renWin = vtkRenderWindow::New();
61       vtkRenderer *ren = vtkRenderer::New();
62       renWin->AddRenderer(ren);
63       ren->GetActiveCamera()->ParallelProjectionOn();
64       vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
65       iren->SetRenderWindow(renWin);
66       VISU_Convertor* aConvertor = CreateConvertor(argv[1]);
67       const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap();
68       VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
69       if(aMeshMapIter == aMeshMap.end()) return 0;
70       const string& aMeshName = aMeshMapIter->first;
71       const VISU::PMesh aMesh = aMeshMapIter->second;
72       const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
73       VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
74       if(isOnlyMesh){
75         const VISU::TEntity& anEntity = VISU::CELL_ENTITY;
76         aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
77         vtkUnstructuredGrid* aDataSet = aConvertor->GetMeshOnEntity(aMeshName,anEntity);
78
79         VISU_MeshPL* aPresent = VISU_MeshPL::New();
80         aPresent->SetInput(aDataSet);
81         aPresent->Build();
82
83         vtkActor* aActor = vtkActor::New();
84         aActor->SetMapper(aPresent->GetMapper());
85         aActor->GetProperty()->SetRepresentation(VTK_WIREFRAME);
86         //ren->ResetCameraClippingRange();
87
88         ren->AddActor(aActor);
89
90         renWin->Render();
91         iren->Start();
92         return 0;
93       }
94       //Import fields
95       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
96       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
97         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
98         const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
99         const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
100         VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
101         for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
102           const VISU::PField aField = aFieldMapIter->second;
103           if(aField->myNbComp == 1) continue;
104           const string& aFieldName = aFieldMapIter->first;
105           const VISU::TValField& aValField = aField->myValField;
106           VISU::TValField::const_iterator aValFieldIter = aValField.begin();
107           if(aValFieldIter == aValField.end()) return 0;
108           int aTimeStamp = aValFieldIter->first;
109           vtkUnstructuredGrid* aDataSet = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
110
111           TPresent* aPresent = TPresent::New();
112           aPresent->SetInput(aDataSet);
113           aPresent->Build();
114           aPresent->Init();
115           aPresent->SetSourceRange();
116           //aPresent->SetNumberOfContours(50);
117           //aPresent->SetNbParts(1);
118           //aPresent->SetOrientation(VISU_CutPlanesPL::XY,0.0,0.0);
119           //aPresent->SetScaling(VTK_SCALE_LOG10);
120           aPresent->Update();
121
122           vtkActor* anActor = vtkActor::New();
123           anActor->SetMapper(aPresent->GetMapper());
124
125           VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
126           aScalarBar->SetLookupTable(aPresent->GetBarTable());
127
128           aPresent->Build();
129
130           ren->AddActor(anActor);
131           ren->AddActor2D(aScalarBar);
132
133           renWin->Render();
134           ren->ResetCamera();
135
136           iren->Start();
137           return 0;
138         }
139       }
140     }
141   }catch(std::exception& exc){
142     MESSAGE("Follow exception was occured :\n"<<exc.what());
143   }catch(...){
144     MESSAGE("Unknown exception was occured in VISU_Convertor_impl");
145   }
146   return 1;
147 }