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