Salome HOME
Merge from V6_4_BR 05/12/2011
[modules/visu.git] / src / VISU_SWIG / VISU_Gen_s.cc
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_Gen_s.cc
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_Gen_s.hh"
29
30 #include "VISU_Convertor.hxx"
31 #include "VISU_ScalarMapPL.hxx"
32 #include "VISU_ScalarBarActor.hxx"
33
34 #include <vtkUnstructuredGrid.h>
35 #include <vtkDataSetMapper.h>
36
37 #include <vtkRenderWindowInteractor.h>
38 #include <vtkRenderWindow.h> 
39 #include <vtkRenderer.h>
40 #include <vtkCamera.h>
41 #include <vtkActor.h>
42
43 using namespace std;
44
45 Convertor::Convertor(const char* theFileName) : myConvertor(CreateConvertor(theFileName)){}
46
47
48 ScalarMap::ScalarMap(Convertor* theConvertor, const char* theMeshName, int theEntity, 
49                      const char* theFieldName, int theIteration)
50   : myScalarMap(NULL)
51 {
52   if(VISU_Convertor* aConvertor = theConvertor->GetImpl()){
53     VISU::PUnstructuredGridIDMapper anIDMapper = 
54       aConvertor->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration);
55     if(anIDMapper){
56       myScalarMap = VISU_ScalarMapPL::New();
57       myScalarMap->SetUnstructuredGridIDMapper(anIDMapper);
58     }
59   }
60 }
61
62
63 View3D::View3D(){
64   myRen = vtkRenderer::New();
65   myRenWin = vtkRenderWindow::New();
66   myRenWin->AddRenderer(myRen);
67   myRenWin->SetSize(300, 300);
68   myRen->Delete();
69   myRen->GetActiveCamera()->ParallelProjectionOn();
70   myIRen = vtkRenderWindowInteractor::New();
71   myIRen->SetRenderWindow(myRenWin);
72   myRenWin->Delete();
73 }
74
75 void View3D::SetPosition(int theX, int theY) {
76   myRenWin->SetPosition(theX, theY);
77 }
78
79 View3D::~View3D(){
80   myIRen->Delete();
81 }
82
83 void View3D::Display(ScalarMap* theScalarMap){
84   if(VISU_ScalarMapPL* aScalarMap = theScalarMap->GetImpl()){
85     aScalarMap->Update();
86     
87     myRen->RemoveAllViewProps();
88     vtkActor* anActor = vtkActor::New();
89     anActor->SetMapper(aScalarMap->GetMapper());
90     
91     VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
92     aScalarBar->SetLookupTable(aScalarMap->GetBarTable());
93     
94     myRen->AddActor(anActor);
95     myRen->AddActor2D(aScalarBar);
96     myRen->ResetCameraClippingRange();
97     
98     myRenWin->Render();
99   }
100 }