1 // Copyright (C) 2007-2013 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::SetGeometryConnection(vtkAlgorithmOutput *input)
63 this->Superclass::SetInputConnection(input);
66 //------------------------------------------------------------------------------
67 void VISU_MergeFilter::SetGeometryData(vtkDataSet *input)
69 this->Superclass::SetInputData(input);
72 //------------------------------------------------------------------------------
73 void VISU_MergeFilter::SetScalarsData(vtkDataSet *input)
75 this->SetInputData(1, input);
78 //------------------------------------------------------------------------------
79 void VISU_MergeFilter::SetScalarsConnection(vtkAlgorithmOutput *input)
81 this->SetInputConnection(1, input);
84 //------------------------------------------------------------------------------
85 void VISU_MergeFilter::SetVectorsData(vtkDataSet *input)
87 this->SetInputData(2, input);
90 //------------------------------------------------------------------------------
91 void VISU_MergeFilter::SetVectorsConnection(vtkAlgorithmOutput *input)
93 this->SetInputConnection(2, input);
96 //------------------------------------------------------------------------------
97 void VISU_MergeFilter::SetNormals(vtkAlgorithmOutput *input)
99 this->SetInputConnection(3, input);
102 //------------------------------------------------------------------------------
103 void VISU_MergeFilter::SetTCoords(vtkAlgorithmOutput *input)
105 this->SetInputConnection(4, input);
108 //------------------------------------------------------------------------------
109 void VISU_MergeFilter::SetTensors(vtkAlgorithmOutput *input)
111 this->SetInputConnection(5, input);
114 //------------------------------------------------------------------------------
115 void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input)
117 this->FieldList->Add(name, input);
120 //------------------------------------------------------------------------------
121 void VISU_MergeFilter::RemoveFields()
123 delete this->FieldList;
124 this->FieldList = new VISU::TFieldList;
128 //---------------------------------------------------------------
131 ::SetMergingInputs(bool theIsMergingInputs)
133 if(myIsMergingInputs == theIsMergingInputs)
136 myIsMergingInputs = theIsMergingInputs;
141 //---------------------------------------------------------------
146 return myIsMergingInputs;
150 //---------------------------------------------------------------
153 ::RequestData(vtkInformation *theRequest,
154 vtkInformationVector **theInputVector,
155 vtkInformationVector *theOutputVector)
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);
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()));
179 if(vtkUnstructuredGrid *anInputUG = dynamic_cast<vtkUnstructuredGrid*>(anInput)){
180 vtkUnstructuredGrid *anOutputUG = dynamic_cast<vtkUnstructuredGrid*>(anOutput);
181 return VISU::Execute(anInputUG,
190 }else if(vtkPolyData *anInputPD = dynamic_cast<vtkPolyData*>(anInput)){
191 vtkPolyData *anOutputPD = dynamic_cast<vtkPolyData*>(anOutput);
192 return VISU::Execute(anInputPD,
203 return Superclass::RequestData(theRequest,
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).
216 ::RequestUpdateExtent(vtkInformation *vtkNotUsed(request),
217 vtkInformationVector **inputVector,
218 vtkInformationVector *vtkNotUsed(outputVector))
220 vtkInformation *inputInfo;
223 for (idx = 0; idx < 6; ++idx)
225 inputInfo = inputVector[idx]->GetInformationObject(0);
228 inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(),
230 inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
232 inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
234 inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
241 //----------------------------------------------------------------------------
244 ::FillInputPortInformation(int port, vtkInformation *info)
246 int retval = this->Superclass::FillInputPortInformation(port, info);
249 info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);