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