Salome HOME
Merge from OCC_development_generic_2006
[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_GaussPointsPL.hxx"
37 #include "VISU_Plot3DPL.hxx"
38
39 typedef VISU_GaussPointsPL TPresent;
40
41 #include <vtkUnstructuredGrid.h>
42 #include <vtkDataSetMapper.h>
43
44 #include <vtkRenderWindowInteractor.h>
45 #include <vtkRenderWindow.h>
46 #include <vtkImageData.h>
47 #include <vtkRenderer.h>
48 #include <vtkCamera.h>
49 #include <vtkActor.h>
50
51 #include <vtkProperty.h>
52
53 #include "utilities.h"
54
55 using namespace std;
56
57 static int isOnlyMesh = false;
58
59 int main(int argc, char** argv){
60   try{
61     if(argc > 1){
62       vtkRenderWindow *renWin = vtkRenderWindow::New();
63       vtkRenderer *ren = vtkRenderer::New();
64       renWin->AddRenderer(ren);
65       ren->GetActiveCamera()->ParallelProjectionOn();
66       vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
67       iren->SetRenderWindow(renWin);
68       VISU_Convertor* aConvertor = CreateConvertor(argv[1]);
69       aConvertor->BuildEntities();
70       aConvertor->BuildFields();
71       aConvertor->BuildMinMax();
72       const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap();
73       VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
74       if(aMeshMapIter == aMeshMap.end()) return 0;
75       const string& aMeshName = aMeshMapIter->first;
76       const VISU::PMesh aMesh = aMeshMapIter->second;
77       const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
78       VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
79       if(isOnlyMesh){
80         const VISU::TEntity& anEntity = VISU::CELL_ENTITY;
81         aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
82
83         VISU::PIDMapper anIDMapper = 
84           aConvertor->GetMeshOnEntity(aMeshName,anEntity);
85         VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput();
86
87         VISU_MeshPL* aPresent = VISU_MeshPL::New();
88         aPresent->SetInput(aDataSet);
89         aPresent->Build();
90
91         vtkActor* aActor = vtkActor::New();
92         aActor->SetMapper(aPresent->GetMapper());
93         aActor->GetProperty()->SetRepresentation(VTK_WIREFRAME);
94         //ren->ResetCameraClippingRange();
95
96         ren->AddActor(aActor);
97
98         renWin->Render();
99         iren->Start();
100         return 0;
101       }
102       //Import fields
103       aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
104       for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
105         const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
106         const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
107         const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
108         VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
109         for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
110           const VISU::PField aField = aFieldMapIter->second;
111           /*
112           if(aField->myNbComp == 1) 
113             continue;
114           */
115           const string& aFieldName = aFieldMapIter->first;
116           const VISU::TValField& aValField = aField->myValField;
117           VISU::TValField::const_iterator aValFieldIter = aValField.begin();
118           if(aValFieldIter == aValField.end()) return 0;
119           int aTimeStamp = aValFieldIter->first;
120
121           TPresent* aPresent = TPresent::New();
122           VISU::PIDMapper anIDMapper;
123           if(anEntity != VISU::NODE_ENTITY){
124             VISU::PGaussPtsIDMapper aGaussPtsIDMapper = aConvertor->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp);
125             aPresent->SetGaussPtsIDMapper(aGaussPtsIDMapper);
126           }else{
127             continue;
128             VISU::PIDMapper anIDMapper = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
129             aPresent->SetIDMapper(anIDMapper);
130           }
131
132           aPresent->Build();
133           aPresent->Init();
134
135           char aMainTexture[80];
136           strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) );
137           strcat( aMainTexture, "/share/salome/resources/sprite_texture.vti" );
138           //cout << aMainTexture << endl;
139
140           char anAlphaTexture[80];
141           strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) );
142           strcat( anAlphaTexture, "/share/salome/resources/sprite_alpha.vti" );
143           //cout << anAlphaTexture << endl;
144
145           vtkSmartPointer<vtkImageData> aTextureValue = VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture );
146           aPresent->SetImageData( aTextureValue.GetPointer() );
147
148           aPresent->Update();
149
150           vtkActor* anActor = vtkActor::New();
151           anActor->SetMapper(aPresent->GetMapper());
152
153           VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
154           aScalarBar->SetLookupTable(aPresent->GetBarTable());
155
156           ren->AddActor(anActor);
157           ren->AddActor2D(aScalarBar);
158
159           renWin->Render();
160           ren->ResetCamera();
161
162           iren->Start();
163           return 0;
164         }
165       }
166     }
167   }catch(std::exception& exc){
168     MESSAGE("Follow exception was occured :\n"<<exc.what());
169   }catch(...){
170     MESSAGE("Unknown exception was occured in VISU_Convertor_impl");
171   }
172   return 1;
173 }