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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: VISU_PipeLine.hxx
24 // Author: Alexey PETROV
27 #include "VISU_MeshPL.hxx"
28 #include "VISU_ScalarMapPL.hxx"
29 #include "VISU_IsoSurfacesPL.hxx"
30 #include "VISU_CutPlanesPL.hxx"
31 #include "VISU_CutLinesPL.hxx"
32 #include "VISU_DeformedShapePL.hxx"
33 #include "VISU_VectorsPL.hxx"
34 #include "VISU_StreamLinesPL.hxx"
35 #include "VISU_GaussPointsPL.hxx"
36 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
37 #include "VISU_Plot3DPL.hxx"
38 #include "VISU_ScalarBarActor.hxx"
40 #include "VISU_OpenGLPointSpriteMapper.hxx"
41 #include "VTKViewer_GeometryFilter.h"
42 #include <vtkMaskPoints.h>
44 #include "VISU_Convertor.hxx"
45 #include "VISU_ConvertorUtils.hxx"
47 typedef VISU_GaussPointsPL TPresent;
49 #include <vtkUnstructuredGrid.h>
50 #include <vtkDataSetMapper.h>
52 #include <vtkInteractorStyleTrackballCamera.h>
53 #include <vtkRenderWindowInteractor.h>
54 #include <vtkRenderWindow.h>
55 #include <vtkImageData.h>
56 #include <vtkRenderer.h>
57 #include <vtkCamera.h>
59 #include <vtk3DWidget.h>
61 #include <vtkProperty.h>
63 static int isOnlyMesh = false;
65 //#define _DEBUG_ID_MAPPING_
67 //----------------------------------------------------------------------------
68 template<class TPipeLine>
70 CreateColoredPL(VISU_Convertor* theConvertor,
71 const std::string& theMeshName,
72 const VISU::TEntity& theEntity,
73 const std::string& theFieldName,
74 int theTimeStampNumber);
77 //----------------------------------------------------------------------------
80 CreateColoredPL<VISU_GaussPointsPL>(VISU_Convertor* theConvertor,
81 const std::string& theMeshName,
82 const VISU::TEntity& theEntity,
83 const std::string& theFieldName,
84 int theTimeStampNumber)
86 VISU_GaussPointsPL* aPresent = VISU_GaussPointsPL::New();
87 VISU::PGaussPtsIDMapper aGaussPtsIDMapper =
88 theConvertor->GetTimeStampOnGaussPts(theMeshName,
92 aPresent->SetGaussPtsIDMapper(aGaussPtsIDMapper);
94 char aMainTexture[80];
95 strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) );
96 strcat( aMainTexture, "/share/salome/resources/visu/sprite_texture.bmp" );
98 char anAlphaTexture[80];
99 strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) );
100 strcat( anAlphaTexture, "/share/salome/resources/visu/sprite_alpha.bmp" );
102 vtkSmartPointer<vtkImageData> aTextureValue =
103 VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture );
104 aPresent->SetImageData( aTextureValue.GetPointer() );
108 #ifdef _DEBUG_ID_MAPPING_
109 vtkDataSet* aDataSet = aPresent->GetOutput();
111 int aNbCells = aDataSet->GetNumberOfCells();
112 cout<<"aNbCells = "<<aNbCells<<endl;
113 for(int anCellId = 0; anCellId < aNbCells; anCellId++){
114 vtkIdType anObjID = aPresent->GetNodeObjID(anCellId);
115 vtkIdType aVtkID = aPresent->GetNodeVTKID(anObjID);
116 cout<<anObjID<<"; "<<aVtkID<<"; - ";
117 vtkFloatingPointType* aCoord = aPresent->GetNodeCoord(anObjID);
118 cout<<aCoord[0]<<"; "<<aCoord[1]<<"; "<<aCoord[2]<<endl;
126 //----------------------------------------------------------------------------
127 template<class TPipeLine>
129 CreateColoredPL(VISU_Convertor* theConvertor,
130 const std::string& theMeshName,
131 const VISU::TEntity& theEntity,
132 const std::string& theFieldName,
133 int theTimeStampNumber)
135 TPipeLine* aPresent = TPipeLine::New();
136 VISU::PUnstructuredGridIDMapper anUnstructuredGridIDMapper =
137 theConvertor->GetTimeStampOnMesh(theMeshName,
141 aPresent->SetUnstructuredGridIDMapper(anUnstructuredGridIDMapper);
143 //aPresent->ClearGeometry();
145 // VISU::PUnstructuredGridIDMapper anIDMapper =
146 // theConvertor->GetMeshOnGroup(theMeshName,
148 // aPresent->AddGeometry(anIDMapper->GetOutput());
151 // VISU::PUnstructuredGridIDMapper anIDMapper =
152 // theConvertor->GetMeshOnGroup(theMeshName,
154 // aPresent->AddGeometry(anIDMapper->GetOutput());
157 // VISU::PUnstructuredGridIDMapper anIDMapper =
158 // theConvertor->GetMeshOnGroup(theMeshName,
160 // aPresent->AddGeometry(anIDMapper->GetOutput());
167 //----------------------------------------------------------------------------
169 main(int argc, char** argv)
173 vtkRenderWindow *aWindow = vtkRenderWindow::New();
174 vtkRenderer *aRenderer = vtkRenderer::New();
176 aWindow->AddRenderer(aRenderer);
177 aRenderer->GetActiveCamera()->ParallelProjectionOn();
179 vtkRenderWindowInteractor *anInteractor = vtkRenderWindowInteractor::New();
180 anInteractor->SetRenderWindow(aWindow);
183 vtkInteractorStyle* aStyle = vtkInteractorStyleTrackballCamera::New();
184 anInteractor->SetInteractorStyle(aStyle);
187 VISU_Convertor* aConvertor = CreateConvertor(argv[1]);
188 aConvertor->BuildEntities();
189 aConvertor->BuildGroups();
190 aConvertor->BuildFields();
191 aConvertor->BuildMinMax();
192 const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap();
193 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
194 if(aMeshMapIter == aMeshMap.end()) return 0;
195 const std::string& aMeshName = aMeshMapIter->first;
196 const VISU::PMesh aMesh = aMeshMapIter->second;
197 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
198 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
200 const VISU::TEntity& anEntity = VISU::CELL_ENTITY;
201 aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity);
203 VISU::PNamedIDMapper anIDMapper =
204 aConvertor->GetMeshOnEntity(aMeshName,anEntity);
206 VISU_MeshPL* aPresent = VISU_MeshPL::New();
207 aPresent->SetUnstructuredGridIDMapper(anIDMapper);
209 vtkActor* aActor = vtkActor::New();
210 aActor->SetMapper(aPresent->GetMapper());
211 aActor->GetProperty()->SetRepresentation(VTK_WIREFRAME);
212 //aRenderer->ResetCameraClippingRange();
214 aRenderer->AddActor(aActor);
217 anInteractor->Start();
221 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
222 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
223 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
224 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
225 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
226 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
227 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
228 const VISU::PField aField = aFieldMapIter->second;
229 // if(aField->myNbComp == 1)
231 const std::string& aFieldName = aFieldMapIter->first;
232 const VISU::TValField& aValField = aField->myValField;
233 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
234 if(aValFieldIter == aValField.end()) return 0;
235 int aTimeStamp = aValFieldIter->first;
237 vtkActor* anActor = vtkActor::New();
238 VISU_ColoredPL* aPresent = NULL;
239 if(anEntity != VISU::NODE_ENTITY){
240 aPresent = CreateColoredPL<TPresent>(aConvertor,
246 anActor->SetMapper(aPresent->GetMapper());
249 aPresent = CreateColoredPL<TPresent>(aConvertor,
255 VTKViewer_GeometryFilter* aGeometryFilter = VTKViewer_GeometryFilter::New();
256 aGeometryFilter->SetInput(aPresent->GetOutput());
257 aGeometryFilter->SetInside(true);
259 vtkMaskPoints* aMaskPoints = vtkMaskPoints::New();
260 aMaskPoints->SetInput(aGeometryFilter->GetOutput());
261 aMaskPoints->SetGenerateVertices(true);
262 aMaskPoints->SetOnRatio(1);
264 VISU_OpenGLPointSpriteMapper* aMapper = VISU_OpenGLPointSpriteMapper::New();
265 aMapper->SetAverageCellSize( VISU_DeformedShapePL::GetScaleFactor( aPresent->GetOutput() ) );
267 char aMainTexture[80];
268 strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) );
269 strcat( aMainTexture, "/share/salome/resources/visu/sprite_texture.vti" );
271 char anAlphaTexture[80];
272 strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) );
273 strcat( anAlphaTexture, "/share/salome/resources/visu/sprite_alpha.vti" );
275 vtkSmartPointer<vtkImageData> aTextureValue =
276 VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture );
277 aMapper->SetImageData( aTextureValue.GetPointer() );
279 //vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
280 aMapper->SetLookupTable(aPresent->GetMapperTable());
281 aMapper->SetUseLookupTableScalarRange(true);
282 aMapper->SetColorModeToMapScalars();
283 aMapper->SetScalarVisibility(true);
285 aMapper->SetInput(aMaskPoints->GetOutput());
286 aGeometryFilter->Delete();
288 anActor->SetMapper(aMapper);
292 VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
293 aScalarBar->SetLookupTable(aPresent->GetBarTable());
295 aRenderer->AddActor(anActor);
296 aRenderer->AddActor2D(aScalarBar);
299 aRenderer->ResetCamera();
301 anInteractor->Start();
306 }catch(std::exception& exc){
307 MSG(true, "Follow exception was occured :\n"<<exc.what());
309 MSG(true, "Unknown exception was occured in VISU_Convertor_impl");