Salome HOME
Update copyright information
[modules/visu.git] / src / CONVERTOR / VISU_MergeFilter.cxx
1 // Copyright (C) 2007-2012  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 //  SALOME VTKViewer : build VTK viewer into Salome desktop
24 //  File   : 
25 //  Author : 
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include "VISU_MergeFilter.hxx"
30 #include "VISU_MergeFilterUtilities.hxx"
31
32 #include <vtkObjectFactory.h>
33 #include <vtkUnstructuredGrid.h>
34 #include <vtkPolyData.h>
35
36 #include <vtkExecutive.h>
37 #include <vtkInformation.h>
38 #include <vtkInformationVector.h>
39 #include <vtkStreamingDemandDrivenPipeline.h>
40
41
42 //------------------------------------------------------------------------------
43 vtkStandardNewMacro(VISU_MergeFilter);
44
45 //------------------------------------------------------------------------------
46 VISU_MergeFilter
47 ::VISU_MergeFilter():
48   myIsMergingInputs(false)
49 {
50   this->FieldList = new VISU::TFieldList;
51   this->SetNumberOfInputPorts(6);
52 }
53
54 //------------------------------------------------------------------------------
55 VISU_MergeFilter::~VISU_MergeFilter()
56 {
57   delete this->FieldList;
58 }
59
60 //------------------------------------------------------------------------------
61 void VISU_MergeFilter::SetGeometry(vtkDataSet *input)
62 {
63   this->Superclass::SetInput(input);
64 }
65
66 //------------------------------------------------------------------------------
67 vtkDataSet *VISU_MergeFilter::GetGeometry()
68 {
69   if (this->GetNumberOfInputConnections(0) < 1)
70     {
71     return NULL;
72     }
73   return vtkDataSet::SafeDownCast(
74     this->GetExecutive()->GetInputData(0, 0));
75 }
76
77 //------------------------------------------------------------------------------
78 void VISU_MergeFilter::SetScalars(vtkDataSet *input)
79 {
80   this->SetInput(1, input);
81 }
82
83 //------------------------------------------------------------------------------
84 vtkDataSet *VISU_MergeFilter::GetScalars()
85 {
86   if (this->GetNumberOfInputConnections(1) < 1)
87     {
88     return NULL;
89     }
90   return vtkDataSet::SafeDownCast(
91     this->GetExecutive()->GetInputData(1, 0));
92 }
93
94 //------------------------------------------------------------------------------
95 void VISU_MergeFilter::SetVectors(vtkDataSet *input)
96 {
97   this->SetInput(2, input);
98 }
99
100 //------------------------------------------------------------------------------
101 vtkDataSet *VISU_MergeFilter::GetVectors()
102 {
103   if (this->GetNumberOfInputConnections(2) < 1)
104     {
105     return NULL;
106     }
107   return vtkDataSet::SafeDownCast(
108     this->GetExecutive()->GetInputData(2, 0));
109 }
110
111 //------------------------------------------------------------------------------
112 void VISU_MergeFilter::SetNormals(vtkDataSet *input)
113 {
114   this->SetInput(3, input);
115 }
116
117 //------------------------------------------------------------------------------
118 vtkDataSet *VISU_MergeFilter::GetNormals()
119 {
120   if (this->GetNumberOfInputConnections(3) < 1)
121     {
122     return NULL;
123     }
124   return vtkDataSet::SafeDownCast(
125     this->GetExecutive()->GetInputData(3, 0));
126 }
127
128 //------------------------------------------------------------------------------
129 void VISU_MergeFilter::SetTCoords(vtkDataSet *input)
130 {
131   this->SetInput(4, input);
132 }
133
134 //------------------------------------------------------------------------------
135 vtkDataSet *VISU_MergeFilter::GetTCoords()
136 {
137   if (this->GetNumberOfInputConnections(4) < 1)
138     {
139     return NULL;
140     }
141   return vtkDataSet::SafeDownCast(
142     this->GetExecutive()->GetInputData(4, 0));
143 }
144
145 //------------------------------------------------------------------------------
146 void VISU_MergeFilter::SetTensors(vtkDataSet *input)
147 {
148   this->SetInput(5, input);
149 }
150
151 //------------------------------------------------------------------------------
152 vtkDataSet *VISU_MergeFilter::GetTensors()
153 {
154   if (this->GetNumberOfInputConnections(5) < 1)
155     {
156     return NULL;
157     }
158   return vtkDataSet::SafeDownCast(
159     this->GetExecutive()->GetInputData(5, 0));
160 }
161
162 //------------------------------------------------------------------------------
163 void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input)
164 {
165   this->FieldList->Add(name, input);
166 }
167
168 //------------------------------------------------------------------------------
169 void VISU_MergeFilter::RemoveFields()
170 {
171   delete this->FieldList;
172   this->FieldList = new VISU::TFieldList;
173 }
174
175
176 //---------------------------------------------------------------
177 void
178 VISU_MergeFilter
179 ::SetMergingInputs(bool theIsMergingInputs)
180 {
181   if(myIsMergingInputs == theIsMergingInputs)
182     return;
183
184   myIsMergingInputs = theIsMergingInputs;
185   Modified();
186 }
187
188   
189 //---------------------------------------------------------------
190 bool
191 VISU_MergeFilter
192 ::IsMergingInputs()
193 {
194   return myIsMergingInputs;
195 }
196   
197
198 //---------------------------------------------------------------
199 int
200 VISU_MergeFilter
201 ::RequestData(vtkInformation *theRequest,
202               vtkInformationVector **theInputVector,
203               vtkInformationVector *theOutputVector)
204 {
205   if(vtkUnstructuredGrid *anInput = dynamic_cast<vtkUnstructuredGrid*>(this->GetInput())){
206     vtkUnstructuredGrid *anOutput = dynamic_cast<vtkUnstructuredGrid*>(this->GetOutput());
207     return VISU::Execute(anInput,
208                          anOutput,
209                          this->GetScalars(),
210                          this->GetVectors(),
211                          this->GetNormals(),
212                          this->GetTCoords(),
213                          this->GetTensors(),
214                          this->FieldList,
215                          IsMergingInputs());
216   }else if(vtkPolyData *anInput = dynamic_cast<vtkPolyData*>(this->GetInput())){
217     vtkPolyData *anOutput = dynamic_cast<vtkPolyData*>(this->GetOutput());
218     return VISU::Execute(anInput,
219                          anOutput,
220                          this->GetScalars(),
221                          this->GetVectors(),
222                          this->GetNormals(),
223                          this->GetTCoords(),
224                          this->GetTensors(),
225                          this->FieldList,
226                          IsMergingInputs());
227   }
228
229   return Superclass::RequestData(theRequest,
230                                  theInputVector,
231                                  theOutputVector);
232 }
233
234 //----------------------------------------------------------------------------
235 //  Trick:  Abstract data types that may or may not be the same type
236 // (structured/unstructured), but the points/cells match up.
237 // Output/Geometry may be structured while ScalarInput may be 
238 // unstructured (but really have same triagulation/topology as geometry).
239 // Just request all the input. Always generate all of the output (todo).
240 int
241 VISU_MergeFilter
242 ::RequestUpdateExtent(vtkInformation *vtkNotUsed(request),
243                       vtkInformationVector **inputVector,
244                       vtkInformationVector *vtkNotUsed(outputVector))
245 {
246   vtkInformation *inputInfo;
247   int idx;
248   
249   for (idx = 0; idx < 6; ++idx)
250     {
251     inputInfo = inputVector[idx]->GetInformationObject(0);
252     if (inputInfo)
253       {
254       inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(),
255                      0);
256       inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
257                      1);
258       inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
259                      0);
260       inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
261       }
262     }
263   return 1;
264 }
265
266
267 //----------------------------------------------------------------------------
268 int
269 VISU_MergeFilter
270 ::FillInputPortInformation(int port, vtkInformation *info)
271 {
272   int retval = this->Superclass::FillInputPortInformation(port, info);
273   if (port > 0)
274     {
275     info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
276     }
277   return retval;
278 }
279