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