]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_ScalarMapPL.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 // File:    VISU_ScalarMapPL.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_ScalarMapPL.hxx"
30 #include "VISU_DataSetMapperHolder.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   myAppendFilter(VISU_AppendFilter::New()),
54   myMergeFilter(VISU_MergeFilter::New())
55 {
56   SetIsShrinkable(true);
57
58   myAppendFilter->SetMergingInputs(true);
59   myAppendFilter->Delete();
60
61   myMergeFilter->SetMergingInputs(true);
62   myMergeFilter->Delete();
63 }
64
65
66 //----------------------------------------------------------------------------
67 VISU_ScalarMapPL
68 ::~VISU_ScalarMapPL()
69 {}
70
71
72 //----------------------------------------------------------------------------
73 unsigned long int 
74 VISU_ScalarMapPL
75 ::GetMTime()
76 {
77   unsigned long int aTime = Superclass::GetMTime();
78
79   aTime = std::max(aTime, myAppendFilter->GetMTime());
80   aTime = std::max(aTime, myMergeFilter->GetMTime());
81
82   return aTime;
83 }
84
85
86 //----------------------------------------------------------------------------
87 void  
88 VISU_ScalarMapPL
89 ::OnCreateMapperHolder()
90 {
91   VISU_UnstructuredGridPL::OnCreateMapperHolder();
92 }
93
94
95 //----------------------------------------------------------------------------
96 void
97 VISU_ScalarMapPL
98 ::Build() 
99 {
100   Superclass::Build();
101
102   SetSourceGeometry();
103
104   myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
105
106   vtkDataSet* aDataSet = GetClippedInput();
107   myMergeFilter->SetScalars(aDataSet);
108   myMergeFilter->SetVectors(aDataSet);
109
110   myMergeFilter->RemoveFields();
111   myMergeFilter->AddField("VISU_FIELD", aDataSet);
112   myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
113   myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
114
115   GetDataSetMapper()->SetInput(InsertCustomPL());
116 }
117
118
119 //----------------------------------------------------------------------------
120 void
121 VISU_ScalarMapPL
122 ::Update() 
123 {
124   Superclass::Update();
125   //{
126   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput.vtk";
127   //  VISU::WriteToFile(GetFieldTransformFilter()->GetUnstructuredGridOutput(), aFileName);
128   //}
129   //{
130   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet.vtk";
131   //  VISU::WriteToFile(myAppendFilter->GetOutput(), aFileName);
132   //}
133   //{
134   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter.vtk";
135   //  VISU::WriteToFile(myMergeFilter->GetUnstructuredGridOutput(), aFileName);
136   //}
137 }
138
139
140 //----------------------------------------------------------------------------
141 void
142 VISU_ScalarMapPL
143 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
144                 bool theIsCopyInput)
145 {
146   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
147 }
148
149
150 //----------------------------------------------------------------------------
151 void
152 VISU_ScalarMapPL
153 ::SetSourceGeometry()
154 {
155   if(IsExternalGeometryUsed()){
156     ClearGeometry();
157     myAppendFilter->AddInput(GetClippedInput());
158   }
159 }
160
161
162 //----------------------------------------------------------------------------
163 int
164 VISU_ScalarMapPL
165 ::AddGeometry(vtkDataSet* theGeometry)
166 {
167   myAppendFilter->AddInput(theGeometry);
168   return GetNumberOfGeometry();
169 }
170
171
172 //----------------------------------------------------------------------------
173 vtkDataSet*
174 VISU_ScalarMapPL
175 ::GetGeometry(int theGeomNumber)
176 {
177   return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
178 }
179
180
181 //----------------------------------------------------------------------------
182 int
183 VISU_ScalarMapPL
184 ::GetNumberOfGeometry()
185 {
186   return myAppendFilter->GetNumberOfInputConnections(0);
187 }
188
189
190 //----------------------------------------------------------------------------
191 bool
192 VISU_ScalarMapPL
193 ::IsExternalGeometryUsed()
194 {
195   return myAppendFilter->GetInput() != GetClippedInput();
196 }
197
198
199 //----------------------------------------------------------------------------
200 void
201 VISU_ScalarMapPL
202 ::ClearGeometry()
203 {
204   myAppendFilter->RemoveAllInputs();
205 }
206
207
208 //----------------------------------------------------------------------------
209 vtkDataSet* 
210 VISU_ScalarMapPL
211 ::InsertCustomPL()
212 {
213   return GetMergedInput();
214 }
215
216
217 //----------------------------------------------------------------------------
218 vtkPointSet* 
219 VISU_ScalarMapPL
220 ::GetMergedInput()
221 {
222   if(myMergeFilter->GetInput())
223     myMergeFilter->Update();
224   return myMergeFilter->GetOutput();
225 }
226
227
228 //----------------------------------------------------------------------------