]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_ScalarMapPL.cxx
Salome HOME
Fix of issue 0017328: EDF 593 VISU : min and max scalar map of results given at gauss...
[modules/visu.git] / src / PIPELINE / VISU_ScalarMapPL.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_ScalarMapPL.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26 //
27 #include "VISU_ScalarMapPL.hxx"
28 #include "VISU_DataSetMapperHolder.hxx"
29 #include "VISU_ElnoAssembleFilter.hxx"
30 #include "VISU_Extractor.hxx"
31 #include "VISU_FieldTransform.hxx"
32
33 #include "VISU_AppendFilter.hxx"
34 #include "VISU_MergeFilter.hxx"
35 #include "VISU_ConvertorUtils.hxx"
36
37 #include <vtkDataSet.h>
38 #include <vtkPointSet.h>
39 #include <vtkUnstructuredGrid.h>
40
41 #include <vtkDataSetMapper.h>
42 #include <vtkObjectFactory.h>
43
44
45 //----------------------------------------------------------------------------
46 vtkStandardNewMacro(VISU_ScalarMapPL);
47
48
49 //----------------------------------------------------------------------------
50 VISU_ScalarMapPL
51 ::VISU_ScalarMapPL():
52   VISU_UnstructuredGridPL(this),
53   myElnoAssembleFilter( VISU_ElnoAssembleFilter::New() ),
54   myAppendFilter(VISU_AppendFilter::New()),
55   myMergeFilter(VISU_MergeFilter::New())
56 {
57   SetIsShrinkable(true);
58   SetIsFeatureEdgesAllowed(true);
59
60   SetElnoDisassembleState( false );
61
62   myElnoAssembleFilter->Delete();
63
64   myAppendFilter->SetMergingInputs(true);
65   myAppendFilter->Delete();
66
67   myMergeFilter->SetMergingInputs(true);
68   myMergeFilter->Delete();
69 }
70
71
72 //----------------------------------------------------------------------------
73 VISU_ScalarMapPL
74 ::~VISU_ScalarMapPL()
75 {}
76
77
78 //----------------------------------------------------------------------------
79 unsigned long int 
80 VISU_ScalarMapPL
81 ::GetMTime()
82 {
83   unsigned long int aTime = Superclass::GetMTime();
84
85   aTime = std::max(aTime, myAppendFilter->GetMTime());
86   aTime = std::max(aTime, myMergeFilter->GetMTime());
87
88   return aTime;
89 }
90
91
92 //----------------------------------------------------------------------------
93 void  
94 VISU_ScalarMapPL
95 ::OnCreateMapperHolder()
96 {
97   VISU_UnstructuredGridPL::OnCreateMapperHolder();
98 }
99
100
101 //----------------------------------------------------------------------------
102 void
103 VISU_ScalarMapPL
104 ::Build() 
105 {
106   Superclass::Build();
107
108   SetSourceGeometry();
109
110   myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
111
112   vtkDataSet* aDataSet = GetClippedInput();
113   myMergeFilter->SetScalars(aDataSet);
114   myMergeFilter->SetVectors(aDataSet);
115
116   myMergeFilter->RemoveFields();
117   myMergeFilter->AddField("VISU_FIELD", aDataSet);
118   myMergeFilter->AddField("VISU_FIELD_GAUSS_MIN", aDataSet);
119   myMergeFilter->AddField("VISU_FIELD_GAUSS_MAX", aDataSet);
120   myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
121   myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
122   myMergeFilter->AddField("ELNO_POINT_COORDS", aDataSet);
123
124   myElnoAssembleFilter->SetInput( InsertCustomPL() );
125
126   GetDataSetMapper()->SetInput( myElnoAssembleFilter->GetOutput() );
127 }
128
129
130 //----------------------------------------------------------------------------
131 void
132 VISU_ScalarMapPL
133 ::Update() 
134 {
135   Superclass::Update();
136   //{
137   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput.vtk";
138   //  VISU::WriteToFile(GetFieldTransformFilter()->GetUnstructuredGridOutput(), aFileName);
139   //}
140   //{
141   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet.vtk";
142   //  VISU::WriteToFile(myAppendFilter->GetOutput(), aFileName);
143   //}
144   //{
145   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter.vtk";
146   //  VISU::WriteToFile(myMergeFilter->GetUnstructuredGridOutput(), aFileName);
147   //}
148 }
149
150
151 //----------------------------------------------------------------------------
152 void
153 VISU_ScalarMapPL
154 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
155                 bool theIsCopyInput)
156 {
157   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
158   VISU_MergedPL::DoShallowCopy(thePipeLine, theIsCopyInput);
159
160   if(VISU_ScalarMapPL* aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine))
161     SetGaussMetric(aPipeLine->GetGaussMetric());
162 }
163
164
165 //----------------------------------------------------------------------------
166 void
167 VISU_ScalarMapPL
168 ::SetElnoDisassembleState( bool theIsShrunk )
169 {
170   GetDataSetMapperHolder()->SetElnoDisassembleState( theIsShrunk );
171   myElnoAssembleFilter->SetElnoAssembleState( theIsShrunk );
172 }
173
174 //----------------------------------------------------------------------------
175 void
176 VISU_ScalarMapPL
177 ::SetSourceGeometry()
178 {
179   if(IsExternalGeometryUsed()){
180     ClearGeometry();
181     myAppendFilter->AddInput(GetClippedInput());
182   }
183 }
184
185
186 //----------------------------------------------------------------------------
187 int
188 VISU_ScalarMapPL
189 ::AddGeometry(vtkDataSet* theGeometry, const VISU::TName& theGeomName)
190 {
191   // rnv: to fix issue 0020167 (AddMeshOnGroup is not fully taken into account)
192   // clear all inpust of the this->myAppendFilter in case if presentation 
193   // constructed on the entire mesh.
194   if(!IsExternalGeometryUsed())
195     ClearGeometry();
196   AddGeometryName(theGeomName);
197   myAppendFilter->AddInput(theGeometry);
198   return GetNumberOfGeometry();
199 }
200
201
202 //----------------------------------------------------------------------------
203 vtkDataSet*
204 VISU_ScalarMapPL
205 ::GetGeometry(int theGeomNumber, VISU::TName& theGeomName)
206 {
207   theGeomName = GetGeometryName(theGeomNumber);
208   return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
209 }
210
211
212 //----------------------------------------------------------------------------
213 int
214 VISU_ScalarMapPL
215 ::GetNumberOfGeometry()
216 {
217   return myAppendFilter->GetNumberOfInputConnections(0);
218 }
219
220
221 //----------------------------------------------------------------------------
222 bool
223 VISU_ScalarMapPL
224 ::IsExternalGeometryUsed()
225 {
226   return myAppendFilter->GetInput() != GetClippedInput();
227 }
228
229
230 //----------------------------------------------------------------------------
231 void
232 VISU_ScalarMapPL
233 ::ClearGeometry()
234 {
235   ClearGeometryNames();
236   myAppendFilter->RemoveAllInputs();
237 }
238
239
240 //----------------------------------------------------------------------------
241 void
242 VISU_ScalarMapPL
243 ::GetSourceRange(vtkFloatingPointType theRange[2])
244 {
245   if(!IsExternalGeometryUsed())
246     Superclass::GetSourceRange(theRange);
247   else
248     GetMergedInput()->GetScalarRange( theRange );
249 }
250
251
252 //----------------------------------------------------------------------------
253 void
254 VISU_ScalarMapPL
255 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric) 
256 {
257   if(GetGaussMetric() == theGaussMetric)
258     return;
259
260   GetExtractorFilter()->SetGaussMetric(theGaussMetric);
261 }
262
263
264 //----------------------------------------------------------------------------
265 VISU::TGaussMetric
266 VISU_ScalarMapPL
267 ::GetGaussMetric() 
268 {
269   return GetExtractorFilter()->GetGaussMetric();
270 }
271
272
273 //----------------------------------------------------------------------------
274 vtkDataSet* 
275 VISU_ScalarMapPL
276 ::InsertCustomPL()
277 {
278   return GetMergedInput();
279 }
280
281
282 //----------------------------------------------------------------------------
283 vtkPointSet* 
284 VISU_ScalarMapPL
285 ::GetMergedInput()
286 {
287   if(myMergeFilter->GetInput())
288     myMergeFilter->Update();
289   return myMergeFilter->GetOutput();
290 }
291
292
293 //----------------------------------------------------------------------------