Salome HOME
Fix for the "0051899: curves are not shown in opened study" issue.
[modules/visu.git] / src / CONVERTOR / VISU_MergeFilter.cxx
1 // Copyright (C) 2007-2013  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::SetGeometryConnection(vtkAlgorithmOutput *input)
62 {
63   this->Superclass::SetInputConnection(input);
64 }
65
66 //------------------------------------------------------------------------------
67 void VISU_MergeFilter::SetGeometryData(vtkDataSet *input)
68 {
69   this->Superclass::SetInputData(input);
70 }
71
72 //------------------------------------------------------------------------------
73 void VISU_MergeFilter::SetScalarsData(vtkDataSet *input)
74 {
75   this->SetInputData(1, input);
76 }
77
78 //------------------------------------------------------------------------------
79 void VISU_MergeFilter::SetScalarsConnection(vtkAlgorithmOutput *input)
80 {
81   this->SetInputConnection(1, input);
82 }
83
84 //------------------------------------------------------------------------------
85 void VISU_MergeFilter::SetVectorsData(vtkDataSet *input)
86 {
87   this->SetInputData(2, input);
88 }
89
90 //------------------------------------------------------------------------------
91 void VISU_MergeFilter::SetVectorsConnection(vtkAlgorithmOutput *input)
92 {
93   this->SetInputConnection(2, input);
94 }
95
96 //------------------------------------------------------------------------------
97 void VISU_MergeFilter::SetNormals(vtkAlgorithmOutput *input)
98 {
99   this->SetInputConnection(3, input);
100 }
101
102 //------------------------------------------------------------------------------
103 void VISU_MergeFilter::SetTCoords(vtkAlgorithmOutput *input)
104 {
105   this->SetInputConnection(4, input);
106 }
107
108 //------------------------------------------------------------------------------
109 void VISU_MergeFilter::SetTensors(vtkAlgorithmOutput *input)
110 {
111   this->SetInputConnection(5, input);
112 }
113
114 //------------------------------------------------------------------------------
115 void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input)
116 {
117   this->FieldList->Add(name, input);
118 }
119
120 //------------------------------------------------------------------------------
121 void VISU_MergeFilter::RemoveFields()
122 {
123   delete this->FieldList;
124   this->FieldList = new VISU::TFieldList;
125 }
126
127
128 //---------------------------------------------------------------
129 void
130 VISU_MergeFilter
131 ::SetMergingInputs(bool theIsMergingInputs)
132 {
133   if(myIsMergingInputs == theIsMergingInputs)
134     return;
135
136   myIsMergingInputs = theIsMergingInputs;
137   Modified();
138 }
139
140   
141 //---------------------------------------------------------------
142 bool
143 VISU_MergeFilter
144 ::IsMergingInputs()
145 {
146   return myIsMergingInputs;
147 }
148   
149
150 //---------------------------------------------------------------
151 int
152 VISU_MergeFilter
153 ::RequestData(vtkInformation *theRequest,
154               vtkInformationVector **theInputVector,
155               vtkInformationVector *theOutputVector)
156 {
157   vtkInformation *inInfo0 = theInputVector[0]->GetInformationObject(0);
158   vtkInformation *inInfo1 = theInputVector[1]->GetInformationObject(0);
159   vtkInformation *inInfo2 = theInputVector[2]->GetInformationObject(0);
160   vtkInformation *inInfo3 = theInputVector[3]->GetInformationObject(0);
161   vtkInformation *inInfo4 = theInputVector[4]->GetInformationObject(0);
162   vtkInformation *inInfo5 = theInputVector[5]->GetInformationObject(0);
163   vtkInformation *outInfo = theOutputVector->GetInformationObject(0);
164
165   // get the input and output
166   vtkDataSet *anInput = vtkDataSet::SafeDownCast(inInfo0->Get(vtkDataObject::DATA_OBJECT()));
167   vtkDataSet *aScalars = theInputVector[1]->GetNumberOfInformationObjects() > 0 ?
168     vtkDataSet::SafeDownCast(inInfo1->Get(vtkDataObject::DATA_OBJECT())) : NULL;
169   vtkDataSet *aVectors = theInputVector[2]->GetNumberOfInformationObjects() > 0 ?
170     vtkDataSet::SafeDownCast(inInfo2->Get(vtkDataObject::DATA_OBJECT())) : NULL;
171   vtkDataSet *aNormals = theInputVector[3]->GetNumberOfInformationObjects() > 0 ?
172     vtkDataSet::SafeDownCast(inInfo3->Get(vtkDataObject::DATA_OBJECT())) : NULL;
173   vtkDataSet *aTCoords = theInputVector[4]->GetNumberOfInformationObjects() > 0 ?
174     vtkDataSet::SafeDownCast(inInfo4->Get(vtkDataObject::DATA_OBJECT())) : NULL;
175   vtkDataSet *aTensors = theInputVector[5]->GetNumberOfInformationObjects() > 0 ?
176     vtkDataSet::SafeDownCast(inInfo5->Get(vtkDataObject::DATA_OBJECT())) : NULL;
177   vtkDataSet *anOutput = vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
178
179   if(vtkUnstructuredGrid *anInputUG = dynamic_cast<vtkUnstructuredGrid*>(anInput)){
180     vtkUnstructuredGrid *anOutputUG = dynamic_cast<vtkUnstructuredGrid*>(anOutput);
181     return VISU::Execute(anInputUG,
182                          anOutputUG,
183                          aScalars,
184                          aVectors,
185                          aNormals,
186                          aTCoords,
187                          aTensors,
188                          this->FieldList,
189                          IsMergingInputs());
190   }else if(vtkPolyData *anInputPD = dynamic_cast<vtkPolyData*>(anInput)){
191     vtkPolyData *anOutputPD =  dynamic_cast<vtkPolyData*>(anOutput);
192     return VISU::Execute(anInputPD,
193                          anOutputPD,
194                          aScalars,
195                          aVectors,
196                          aNormals,
197                          aTCoords,
198                          aTensors,
199                          this->FieldList,
200                          IsMergingInputs());
201   }
202
203   return Superclass::RequestData(theRequest,
204                                  theInputVector,
205                                  theOutputVector);
206 }
207
208 //----------------------------------------------------------------------------
209 //  Trick:  Abstract data types that may or may not be the same type
210 // (structured/unstructured), but the points/cells match up.
211 // Output/Geometry may be structured while ScalarInput may be 
212 // unstructured (but really have same triagulation/topology as geometry).
213 // Just request all the input. Always generate all of the output (todo).
214 int
215 VISU_MergeFilter
216 ::RequestUpdateExtent(vtkInformation *vtkNotUsed(request),
217                       vtkInformationVector **inputVector,
218                       vtkInformationVector *vtkNotUsed(outputVector))
219 {
220   vtkInformation *inputInfo;
221   int idx;
222   
223   for (idx = 0; idx < 6; ++idx)
224     {
225     inputInfo = inputVector[idx]->GetInformationObject(0);
226     if (inputInfo)
227       {
228       inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(),
229                      0);
230       inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
231                      1);
232       inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
233                      0);
234       inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
235       }
236     }
237   return 1;
238 }
239
240
241 //----------------------------------------------------------------------------
242 int
243 VISU_MergeFilter
244 ::FillInputPortInformation(int port, vtkInformation *info)
245 {
246   int retval = this->Superclass::FillInputPortInformation(port, info);
247   if (port > 0)
248     {
249     info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
250     }
251   return retval;
252 }
253