Salome HOME
sources v1.2c
[modules/visu.git] / src / PIPELINE / VISU_ScalarMapPL.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 //
24 // File:    VISU_PipeLine.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_ScalarMapPL.hxx"
30 #include "VISU_PipeLineUtils.hxx"
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 1;
34 #else
35 static int MYDEBUG = 0;
36 #endif
37
38 vtkStandardNewMacro(VISU_ScalarMapPL);
39
40
41 VISU_ScalarMapPL::VISU_ScalarMapPL(){
42   myFieldTransform = VISU_FieldTransform::New();
43
44   myMapperTable = VISU_LookupTable::New();
45   myMapperTable->SetScale(VTK_SCALE_LINEAR);
46   myMapperTable->SetHueRange(0.667,0.0);
47
48   myBarTable = VISU_LookupTable::New();
49   myBarTable->SetScale(VTK_SCALE_LINEAR);
50   myBarTable->SetHueRange(0.667,0.0);
51
52   myExtractor = VISU_Extractor::New();
53 }
54
55
56 VISU_ScalarMapPL::~VISU_ScalarMapPL(){
57   myFieldTransform->Delete();
58   myMapperTable->Delete();;
59   myBarTable->Delete();
60   myExtractor->Delete();
61 }
62
63
64 void VISU_ScalarMapPL::ShallowCopy(VISU_PipeLine *thePipeLine){
65   VISU_PipeLine::ShallowCopy(thePipeLine);
66   if(VISU_ScalarMapPL *aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine)){
67     SetScalarRange(aPipeLine->GetScalarRange());
68     SetScalarMode(aPipeLine->GetScalarMode());
69     SetNbColors(aPipeLine->GetNbColors());
70     SetScaling(aPipeLine->GetScaling());
71     //Update();
72   }
73 }
74
75
76 int VISU_ScalarMapPL::GetScalarMode(){
77   return myExtractor->GetScalarMode();
78 }
79 void VISU_ScalarMapPL::SetScalarMode(int theScalarMode){
80   myExtractor->SetScalarMode(theScalarMode);
81   Modified();
82 }
83
84
85 int VISU_ScalarMapPL::GetScaling() { 
86   return myBarTable->GetScale();
87 }
88 void VISU_ScalarMapPL::SetScaling(int theScaling) {
89   myBarTable->SetScale(theScaling);
90   if(theScaling == VTK_SCALE_LOG10)
91     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
92   else
93     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
94   Modified();
95 }
96
97
98 float* VISU_ScalarMapPL::GetScalarRange() { 
99   return myFieldTransform->GetScalarRange();
100 }  
101 void VISU_ScalarMapPL::SetScalarRange(float theRange[2]){
102   myFieldTransform->SetScalarRange(theRange);
103   myBarTable->SetRange(theRange);
104   Modified();
105 }
106 void VISU_ScalarMapPL::SetScalarMin(float theValue){
107   float aScalarRange[2] = {theValue, GetScalarRange()[1]};
108   SetScalarRange(aScalarRange);
109 }
110 void VISU_ScalarMapPL::SetScalarMax(float theValue){
111   float aScalarRange[2] = {GetScalarRange()[0], theValue};
112   SetScalarRange(aScalarRange);
113 }
114
115
116 void VISU_ScalarMapPL::SetNbColors(int theNbColors) { 
117   myMapperTable->SetNumberOfColors(theNbColors);
118   myBarTable->SetNumberOfColors(theNbColors);
119   Modified();
120 }
121 int VISU_ScalarMapPL::GetNbColors() { 
122   return myMapperTable->GetNumberOfColors();
123 }
124
125
126 VISU_ScalarMapPL::THook* VISU_ScalarMapPL::DoHook(){
127   myMapper->SetColorModeToMapScalars();
128   myMapper->ScalarVisibilityOn();
129   return myFieldTransform->GetUnstructuredGridOutput();
130 }
131
132
133 void VISU_ScalarMapPL::Init(){
134   //SetSourceRange();
135 }
136
137
138 void VISU_ScalarMapPL::Build() { 
139   myExtractor->SetInput(myInput);
140   myFieldTransform->SetInput(myExtractor->GetOutput());
141   myMapper->SetInput(DoHook());
142 }
143
144
145 void VISU_ScalarMapPL::Update() {
146   float *aRange = myFieldTransform->GetScalarRange();
147   float aScalarRange[2] = {aRange[0], aRange[1]};
148   if(myBarTable->GetScale() == VTK_SCALE_LOG10)
149     VISU_LookupTable::ComputeLogRange(aRange,aScalarRange);
150   myMapperTable->SetRange(aScalarRange);
151   myMapperTable->SetMapScale(1.0);
152
153   myMapperTable->Build();
154   myBarTable->Build();
155
156   myMapper->SetLookupTable(myMapperTable);   
157   myMapper->SetScalarRange(aScalarRange);
158
159   myFieldTransform->Update();
160
161   VISU_PipeLine::Update();
162 }
163
164
165 void VISU_ScalarMapPL::SetMapScale(float theMapScale){
166   myMapperTable->SetMapScale(theMapScale);
167   myMapperTable->Build();
168 }
169 float VISU_ScalarMapPL::GetMapScale(){
170   return myMapperTable->GetMapScale();
171 }
172
173
174 void VISU_ScalarMapPL::GetSourceRange(float theRange[2]){
175   myExtractor->Update();
176   myExtractor->GetOutput()->GetScalarRange(theRange);
177 }
178
179 void VISU_ScalarMapPL::SetSourceRange(){
180   float aRange[2];
181   GetSourceRange(aRange);
182   SetScalarRange(aRange);
183 }