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