]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISUPipeLine.cxx
Salome HOME
Add test function : QApplication::postEvent(SALOME_Event)
[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
37 typedef VISU_ScalarMapPL TPresent;
38
39 #include <vtkUnstructuredGrid.h>
40 #include <vtkDataSetMapper.h>
41
42 #include <vtkRenderWindowInteractor.h>
43 #include <vtkRenderWindow.h> 
44 #include <vtkRenderer.h>
45 #include <vtkCamera.h>
46 #include <vtkActor.h>
47
48 using namespace std;
49
50 static int isOnlyMesh = false;
51
52 int main(int argc, char** argv){ 
53   try{
54     if(argc > 1){
55       vtkRenderWindow *renWin = vtkRenderWindow::New();
56       vtkRenderer *ren = vtkRenderer::New();
57       renWin->AddRenderer(ren);
58       ren->GetActiveCamera()->ParallelProjectionOn();
59       vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
60       iren->SetRenderWindow(renWin);
61       VISU_Convertor* aConvertor = CreateConvertor(argv[1]);
62       const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap();
63       VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
64       if(aMeshMapIter == aMeshMap.end()) return 0;
65       const string& aMeshName = aMeshMapIter->first;
66       const VISU::TMesh& aMesh = aMeshMapIter->second;
67       const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
68       VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
69       if(isOnlyMesh){
70         const VISU::TEntity& anEntity = VISU::CELL_ENTITY;
71         aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
72         vtkUnstructuredGrid* aDataSet = aConvertor->GetMeshOnEntity(aMeshName,anEntity);
73         
74         VISU_MeshPL* aPresent = VISU_MeshPL::New();
75         aPresent->SetInput(aDataSet);
76         aPresent->Build();
77         
78         vtkActor* aActor = vtkActor::New();
79         aActor->SetMapper(aPresent->GetMapper());
80         aActor->GetProperty()->SetRepresentation(VTK_WIREFRAME);
81         //ren->ResetCameraClippingRange();
82         
83         ren->AddActor(aActor);
84         
85         renWin->Render();
86         iren->Start();
87         return 0;
88       }
89       //Import fields
90       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
91       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
92         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
93         const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
94         const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
95         VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
96         for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
97           const VISU::TField& aField = aFieldMapIter->second;
98           if(aField.myNbComp == 1) continue;
99           const string& aFieldName = aFieldMapIter->first;
100           const VISU::TField::TValField& aValField = aField.myValField;
101           VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
102           if(aValFieldIter == aValField.end()) return 0;
103           int aTimeStamp = aValFieldIter->first;
104           vtkUnstructuredGrid* aDataSet = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
105           
106           TPresent* aPresent = TPresent::New();
107           aPresent->SetInput(aDataSet);
108           aPresent->Build();
109           aPresent->Init();
110           aPresent->SetSourceRange();
111           //aPresent->SetPartDefault(0);
112           //aPresent->SetScalarMin(0.01);
113           //aPresent->SetScaling(VTK_SCALE_LOG10);
114           aPresent->Update();
115           
116           vtkActor* anActor = vtkActor::New();
117           anActor->SetMapper(aPresent->GetMapper());
118           
119           VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
120           aScalarBar->SetLookupTable(aPresent->GetBarTable());
121
122           aPresent->Build();
123
124           ren->AddActor(anActor);
125           ren->AddActor2D(aScalarBar);
126           ren->ResetCameraClippingRange();
127           
128           renWin->Render();
129           iren->Start();
130           return 0;
131         }
132       }
133     }
134   }catch(std::runtime_error& exc){
135     cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
136   }catch(...){
137     cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
138   } 
139   return 1;
140 }