1 // Copyright (C) 2007-2008 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
22 // SALOME OBJECT : kernel of SALOME component
23 // File : VTKViewer_GeometryFilter.cxx
28 #include "VTKViewer_AppendFilter.h"
31 #include <vtkCellData.h>
32 #include <vtkDataSetAttributes.h>
33 #include <vtkDataSetCollection.h>
34 #include <vtkObjectFactory.h>
35 #include <vtkPointData.h>
36 #include <vtkUnstructuredGrid.h>
37 #include <vtkInformation.h>
38 #include <vtkInformationVector.h>
40 #include <vtkPoints.h>
48 vtkCxxRevisionMacro(VTKViewer_AppendFilter, "$Revision$");
49 vtkStandardNewMacro(VTKViewer_AppendFilter);
51 VTKViewer_AppendFilter
52 ::VTKViewer_AppendFilter()
54 myDoMappingFlag = false;
57 VTKViewer_AppendFilter
58 ::~VTKViewer_AppendFilter()
62 VTKViewer_AppendFilter
63 ::SetDoMappingFlag(const bool theFlag)
65 if(myDoMappingFlag == theFlag)
68 myDoMappingFlag = theFlag;
74 VTKViewer_AppendFilter
75 ::DoMappingFlag() const
77 return myDoMappingFlag;
81 VTKViewer_AppendFilter
82 ::SetSharedPointsDataSet(vtkPointSet* thePointsDataSet)
84 if(GetSharedPointsDataSet() == thePointsDataSet)
87 mySharedPointsDataSet = thePointsDataSet;
93 VTKViewer_AppendFilter
94 ::GetSharedPointsDataSet()
96 return mySharedPointsDataSet.GetPointer();
100 VTKViewer_AppendFilter
102 vtkInformation *request,
103 vtkInformationVector **inputVector,
104 vtkInformationVector *outputVector)
107 if(GetSharedPointsDataSet())
108 aRet = MakeOutput(request,inputVector,outputVector);
110 aRet = Superclass::RequestData(request,inputVector,outputVector);
120 VTKViewer_AppendFilter
123 myNodeRanges.clear();
124 myCellRanges.clear();
126 vtkIdType aPntStartId = 0;
127 vtkIdType aCellStartId = 0;
129 for(vtkIdType aDataSetId = 0; aDataSetId < this->GetNumberOfInputPorts(); ++aDataSetId){
130 vtkDataSet* aDataSet = (vtkDataSet *)(this->GetInput(aDataSetId));
131 // Do mapping of the nodes
132 if(!GetSharedPointsDataSet()){
133 vtkIdType aNbPnts = aDataSet->GetNumberOfPoints();
134 myNodeRanges.push_back(aPntStartId + aNbPnts);
135 aPntStartId += aNbPnts;
137 // Do mapping of the cells
138 vtkIdType aNbCells = aDataSet->GetNumberOfCells();
139 myCellRanges.push_back(aCellStartId + aNbCells);
140 aCellStartId += aNbCells;
148 GetOutputID(vtkIdType theInputID,
149 vtkIdType theInputDataSetID,
150 const VTKViewer_AppendFilter::TVectorIds& theRanges)
152 theInputID = theInputDataSetID = -1;
154 vtkIdType aNbInputs = theRanges.size();
155 if(theInputDataSetID < 0 || theInputDataSetID >= aNbInputs)
158 vtkIdType aStartId = theRanges[theInputDataSetID];
159 return aStartId + theInputID;
164 VTKViewer_AppendFilter
165 ::GetPointOutputID(vtkIdType theInputID,
166 vtkIdType theInputDataSetID)
168 if(GetSharedPointsDataSet())
171 return GetOutputID(theInputID,theInputDataSetID,myNodeRanges);
176 VTKViewer_AppendFilter
177 ::GetCellOutputID(vtkIdType theInputID,
178 vtkIdType theInputDataSetID)
180 if(GetSharedPointsDataSet())
183 return GetOutputID(theInputID,theInputDataSetID,myCellRanges);
190 GetInputID(vtkIdType theOutputID,
191 vtkIdType& theInputID,
192 vtkIdType& theStartID,
193 vtkIdType& theInputDataSetID,
194 const VTKViewer_AppendFilter::TVectorIds& theRanges)
196 theInputID = theStartID = theInputDataSetID = -1;
198 if(theRanges.empty())
201 const vtkIdType& aRangeEnd = theRanges.back();
202 if(theOutputID < 0 || theOutputID >= aRangeEnd)
205 vtkIdType aStartId = 0;
206 vtkIdType aNbInputs = theRanges.size();
207 for(vtkIdType aDataSetId = 0; aDataSetId < aNbInputs; ++aDataSetId){
208 vtkIdType aRange = theRanges[aDataSetId];
209 if(aRange > theOutputID){
210 theInputID = theOutputID - aStartId;
211 theInputDataSetID = aDataSetId;
212 theStartID = aStartId;
221 VTKViewer_AppendFilter
222 ::GetPointInputID(vtkIdType theOutputID,
223 vtkIdType& theInputID,
224 vtkIdType& theStartID,
225 vtkIdType& theInputDataSetID)
227 if(GetSharedPointsDataSet()) {
228 theStartID = theInputDataSetID = 0;
229 theInputID = theOutputID;
233 ::GetInputID(theOutputID,
242 VTKViewer_AppendFilter
243 ::GetCellInputID(vtkIdType theOutputID,
244 vtkIdType& theInputID,
245 vtkIdType& theStartID,
246 vtkIdType& theInputDataSetID)
248 ::GetInputID(theOutputID,
257 VTKViewer_AppendFilter
259 vtkInformation *vtkNotUsed(request),
260 vtkInformationVector **inputVector,
261 vtkInformationVector *outputVector)
264 vtkIdType numPts, numCells, newCellId, cellId;
268 int numInputs = this->GetNumberOfInputConnections(0);
270 // get the output info object
271 vtkInformation *outInfo = outputVector->GetInformationObject(0);
274 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
275 outInfo->Get(vtkDataObject::DATA_OBJECT()));
277 numPts = mySharedPointsDataSet->GetNumberOfPoints();
283 vtkInformation *inInfo = 0;
284 for (idx = 0; idx < numInputs;++idx) {
285 inInfo = inputVector[0]->GetInformationObject(idx);
289 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
292 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) {
293 continue; //no input, just skip
295 numCells += ds->GetNumberOfCells();
296 }//if non-empty dataset
302 // Now can allocate memory
303 output->Allocate(numCells);
304 ptIds = vtkIdList::New();
305 ptIds->Allocate(VTK_CELL_SIZE);
307 // Append each input dataset together
310 output->SetPoints(GetSharedPointsDataSet()->GetPoints());
311 output->GetPointData()->PassData(GetSharedPointsDataSet()->GetPointData());
313 for (idx = 0; idx < numInputs; ++idx) {
314 inInfo = inputVector[0]->GetInformationObject(idx);
318 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
322 numCells = ds->GetNumberOfCells();
323 cd = ds->GetCellData();
324 // copy cell and cell data
325 for (cellId=0; cellId<numCells; cellId++) {
326 ds->GetCellPoints(cellId, ptIds);
327 newCellId = output->InsertNextCell(ds->GetCellType(cellId), ptIds);
336 int VTKViewer_AppendFilter::FillInputPortInformation(int, vtkInformation *info)
338 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
339 info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);