Salome HOME
Issue 0019818: EDF 703 SMESH VISU : Display Mesh Groups names in viewer (as a caption)
[modules/visu.git] / src / PIPELINE / VISU_IsoSurfacesPL.cxx
1 //  Copyright (C) 2007-2008  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 // File:    VISU_PipeLine.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26 //
27 #include "VISU_IsoSurfacesPL.hxx"
28 #include "VISU_LookupTable.hxx"
29
30 #include "VISU_PipeLineUtils.hxx"
31 #include "VISU_LabelPointsFilter.hxx"
32
33 #include <vtkContourFilter.h>
34
35
36
37 //----------------------------------------------------------------------------
38 vtkStandardNewMacro(VISU_IsoSurfacesPL);
39
40
41 //----------------------------------------------------------------------------
42 VISU_IsoSurfacesPL
43 ::VISU_IsoSurfacesPL()
44 {
45   SetIsShrinkable(false);
46   SetIsFeatureEdgesAllowed(false);
47
48   SetElnoDisassembleState( true );
49
50   myContourFilter = vtkContourFilter::New();
51
52   myCellDataToPointData = vtkCellDataToPointData::New();
53 }
54
55
56 //----------------------------------------------------------------------------
57 VISU_IsoSurfacesPL
58 ::~VISU_IsoSurfacesPL()
59 {
60   myContourFilter->Delete();
61   myContourFilter = NULL;
62
63   myCellDataToPointData->Delete();
64   myCellDataToPointData = NULL;
65 }
66
67
68 //----------------------------------------------------------------------------
69 unsigned long int 
70 VISU_IsoSurfacesPL
71 ::GetMTime()
72 {
73   unsigned long int aTime = Superclass::GetMTime();
74
75   aTime = std::max(aTime, myCellDataToPointData->GetMTime());
76   aTime = std::max(aTime, myContourFilter->GetMTime());
77
78   return aTime;
79 }
80
81
82 //----------------------------------------------------------------------------
83 void
84 VISU_IsoSurfacesPL
85 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
86                 bool theIsCopyInput)
87 {
88   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
89
90   if(VISU_IsoSurfacesPL *aPipeLine = dynamic_cast<VISU_IsoSurfacesPL*>(thePipeLine)){
91     SetNbParts(aPipeLine->GetNbParts());
92     vtkFloatingPointType aRange[2] = {aPipeLine->GetMin(), aPipeLine->GetMax()};
93     SetRange(aRange);
94   }
95 }
96
97
98 //----------------------------------------------------------------------------
99 int
100 VISU_IsoSurfacesPL
101 ::GetNbParts() 
102 {
103   return myContourFilter->GetNumberOfContours();
104 }
105
106 //----------------------------------------------------------------------------
107 vtkFloatingPointType
108 VISU_IsoSurfacesPL
109 ::GetValue(int i) 
110 {
111   return myContourFilter->GetValue(i);
112 }
113
114
115 //----------------------------------------------------------------------------
116 void
117 VISU_IsoSurfacesPL
118 ::SetNbParts(int theNb) 
119 {
120   myContourFilter->SetNumberOfContours(theNb);
121 }
122
123
124 //----------------------------------------------------------------------------
125 void
126 VISU_IsoSurfacesPL
127 ::SetScalarRange( vtkFloatingPointType theRange[2] ) 
128 {
129   Superclass::SetScalarRange( theRange );
130   SetRange(myRange);
131 }
132
133
134 //----------------------------------------------------------------------------
135 void
136 VISU_IsoSurfacesPL
137 ::SetRange(vtkFloatingPointType theRange[2])
138 {
139   if(VISU::CheckIsSameRange(myRange, theRange))
140     return;
141
142   if(theRange[0] <= theRange[1]){
143     myRange[0] = theRange[0];  
144     myRange[1] = theRange[1];
145     vtkFloatingPointType aRange[2] = {theRange[0], theRange[1]};
146     if(GetScaling() == VTK_SCALE_LOG10)
147       VISU_LookupTable::ComputeLogRange(theRange, aRange);
148     myContourFilter->GenerateValues(GetNbParts(), aRange);
149   }
150 }
151
152
153 //----------------------------------------------------------------------------
154 vtkFloatingPointType
155 VISU_IsoSurfacesPL
156 ::GetMin() 
157 {
158   return myRange[0];
159 }
160
161
162 //----------------------------------------------------------------------------
163 vtkFloatingPointType
164 VISU_IsoSurfacesPL
165 ::GetMax() 
166 {
167   return myRange[1];
168 }
169
170
171 void
172 //----------------------------------------------------------------------------
173 VISU_IsoSurfacesPL
174 ::Init()
175 {
176   Superclass::Init();
177
178   SetNbParts(10);
179
180   vtkFloatingPointType aScalarRange[2];
181   GetSourceRange(aScalarRange);
182   SetRange(aScalarRange);
183 }
184
185 //----------------------------------------------------------------------------
186 void
187 VISU_IsoSurfacesPL
188 ::Build()
189 {
190   Superclass::Build();
191
192   VISU::CellDataToPoint(myContourFilter,
193                         myCellDataToPointData,
194                         GetMergedInput());
195
196 }
197
198
199 //----------------------------------------------------------------------------
200
201 vtkDataSet* 
202 VISU_IsoSurfacesPL
203 ::InsertCustomPL()
204 {
205   return myContourFilter->GetOutput();
206 }
207
208
209 //----------------------------------------------------------------------------
210 unsigned long int
211 VISU_IsoSurfacesPL
212 ::GetMemorySize()
213 {
214   unsigned long int aSize = Superclass::GetMemorySize();
215
216   if(vtkDataSet* aDataSet = myContourFilter->GetOutput())
217     aSize += aDataSet->GetActualMemorySize() * 1024;
218   
219   if(myCellDataToPointData->GetInput())
220     if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
221       aSize += aDataSet->GetActualMemorySize() * 1024;
222
223   return aSize;
224 }
225
226
227 //----------------------------------------------------------------------------
228 void
229 VISU_IsoSurfacesPL
230 ::SetMapScale(vtkFloatingPointType theMapScale)
231 {
232   Superclass::SetMapScale(theMapScale);
233
234   vtkFloatingPointType aRange[2] = {GetMax() - theMapScale*(GetMax()-GetMin()), GetMax()};
235   vtkFloatingPointType aNewRange[2] = {aRange[0], aRange[1]};
236   if(GetScaling() == VTK_SCALE_LOG10)
237     VISU_LookupTable::ComputeLogRange(aRange,aNewRange);
238   myContourFilter->GenerateValues(GetNbParts(), aNewRange);
239 }
240
241
242 //----------------------------------------------------------------------------