1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
29 #include "VISU_MergeFilter.hxx"
30 #include "VISU_MergeFilterUtilities.hxx"
32 #include <vtkObjectFactory.h>
33 #include <vtkUnstructuredGrid.h>
34 #include <vtkPolyData.h>
36 #include <vtkExecutive.h>
37 #include <vtkInformation.h>
38 #include <vtkInformationVector.h>
39 #include <vtkStreamingDemandDrivenPipeline.h>
42 //------------------------------------------------------------------------------
43 vtkStandardNewMacro(VISU_MergeFilter);
45 //------------------------------------------------------------------------------
48 myIsMergingInputs(false)
50 this->FieldList = new VISU::TFieldList;
51 this->SetNumberOfInputPorts(6);
54 //------------------------------------------------------------------------------
55 VISU_MergeFilter::~VISU_MergeFilter()
57 delete this->FieldList;
60 //------------------------------------------------------------------------------
61 void VISU_MergeFilter::SetGeometry(vtkDataSet *input)
63 this->Superclass::SetInput(input);
66 //------------------------------------------------------------------------------
67 vtkDataSet *VISU_MergeFilter::GetGeometry()
69 if (this->GetNumberOfInputConnections(0) < 1)
73 return vtkDataSet::SafeDownCast(
74 this->GetExecutive()->GetInputData(0, 0));
77 //------------------------------------------------------------------------------
78 void VISU_MergeFilter::SetScalars(vtkDataSet *input)
80 this->SetInput(1, input);
83 //------------------------------------------------------------------------------
84 vtkDataSet *VISU_MergeFilter::GetScalars()
86 if (this->GetNumberOfInputConnections(1) < 1)
90 return vtkDataSet::SafeDownCast(
91 this->GetExecutive()->GetInputData(1, 0));
94 //------------------------------------------------------------------------------
95 void VISU_MergeFilter::SetVectors(vtkDataSet *input)
97 this->SetInput(2, input);
100 //------------------------------------------------------------------------------
101 vtkDataSet *VISU_MergeFilter::GetVectors()
103 if (this->GetNumberOfInputConnections(2) < 1)
107 return vtkDataSet::SafeDownCast(
108 this->GetExecutive()->GetInputData(2, 0));
111 //------------------------------------------------------------------------------
112 void VISU_MergeFilter::SetNormals(vtkDataSet *input)
114 this->SetInput(3, input);
117 //------------------------------------------------------------------------------
118 vtkDataSet *VISU_MergeFilter::GetNormals()
120 if (this->GetNumberOfInputConnections(3) < 1)
124 return vtkDataSet::SafeDownCast(
125 this->GetExecutive()->GetInputData(3, 0));
128 //------------------------------------------------------------------------------
129 void VISU_MergeFilter::SetTCoords(vtkDataSet *input)
131 this->SetInput(4, input);
134 //------------------------------------------------------------------------------
135 vtkDataSet *VISU_MergeFilter::GetTCoords()
137 if (this->GetNumberOfInputConnections(4) < 1)
141 return vtkDataSet::SafeDownCast(
142 this->GetExecutive()->GetInputData(4, 0));
145 //------------------------------------------------------------------------------
146 void VISU_MergeFilter::SetTensors(vtkDataSet *input)
148 this->SetInput(5, input);
151 //------------------------------------------------------------------------------
152 vtkDataSet *VISU_MergeFilter::GetTensors()
154 if (this->GetNumberOfInputConnections(5) < 1)
158 return vtkDataSet::SafeDownCast(
159 this->GetExecutive()->GetInputData(5, 0));
162 //------------------------------------------------------------------------------
163 void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input)
165 this->FieldList->Add(name, input);
168 //------------------------------------------------------------------------------
169 void VISU_MergeFilter::RemoveFields()
171 delete this->FieldList;
172 this->FieldList = new VISU::TFieldList;
176 //---------------------------------------------------------------
179 ::SetMergingInputs(bool theIsMergingInputs)
181 if(myIsMergingInputs == theIsMergingInputs)
184 myIsMergingInputs = theIsMergingInputs;
189 //---------------------------------------------------------------
194 return myIsMergingInputs;
198 //---------------------------------------------------------------
201 ::RequestData(vtkInformation *theRequest,
202 vtkInformationVector **theInputVector,
203 vtkInformationVector *theOutputVector)
205 if(vtkUnstructuredGrid *anInput = dynamic_cast<vtkUnstructuredGrid*>(this->GetInput())){
206 vtkUnstructuredGrid *anOutput = dynamic_cast<vtkUnstructuredGrid*>(this->GetOutput());
207 return VISU::Execute(anInput,
216 }else if(vtkPolyData *anInput = dynamic_cast<vtkPolyData*>(this->GetInput())){
217 vtkPolyData *anOutput = dynamic_cast<vtkPolyData*>(this->GetOutput());
218 return VISU::Execute(anInput,
229 return Superclass::RequestData(theRequest,
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).
242 ::RequestUpdateExtent(vtkInformation *vtkNotUsed(request),
243 vtkInformationVector **inputVector,
244 vtkInformationVector *vtkNotUsed(outputVector))
246 vtkInformation *inputInfo;
249 for (idx = 0; idx < 6; ++idx)
251 inputInfo = inputVector[idx]->GetInformationObject(0);
254 inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(),
256 inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
258 inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
260 inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
267 //----------------------------------------------------------------------------
270 ::FillInputPortInformation(int port, vtkInformation *info)
272 int retval = this->Superclass::FillInputPortInformation(port, info);
275 info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);