1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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 OBJECT : kernel of SALOME component
24 // File : VTKViewer_GeometryFilter.cxx
27 #include "VTKViewer_AppendFilter.h"
30 #include <vtkCellData.h>
31 #include <vtkDataSetAttributes.h>
32 #include <vtkDataSetCollection.h>
33 #include <vtkObjectFactory.h>
34 #include <vtkPointData.h>
35 #include <vtkUnstructuredGrid.h>
36 #include <vtkInformation.h>
37 #include <vtkInformationVector.h>
39 #include <vtkPoints.h>
47 vtkStandardNewMacro(VTKViewer_AppendFilter)
49 VTKViewer_AppendFilter
50 ::VTKViewer_AppendFilter()
52 myDoMappingFlag = false;
55 VTKViewer_AppendFilter
56 ::~VTKViewer_AppendFilter()
60 VTKViewer_AppendFilter
61 ::SetDoMappingFlag(const bool theFlag)
63 if(myDoMappingFlag == theFlag)
66 myDoMappingFlag = theFlag;
72 VTKViewer_AppendFilter
73 ::DoMappingFlag() const
75 return myDoMappingFlag;
79 VTKViewer_AppendFilter
80 ::SetSharedPointsDataSet(vtkPointSet* thePointsDataSet)
82 if(GetSharedPointsDataSet() == thePointsDataSet)
85 mySharedPointsDataSet = thePointsDataSet;
91 VTKViewer_AppendFilter
92 ::GetSharedPointsDataSet()
94 return mySharedPointsDataSet.GetPointer();
98 VTKViewer_AppendFilter
100 vtkInformation *request,
101 vtkInformationVector **inputVector,
102 vtkInformationVector *outputVector)
105 if(GetSharedPointsDataSet())
106 aRet = MakeOutput(request,inputVector,outputVector);
108 aRet = Superclass::RequestData(request,inputVector,outputVector);
118 VTKViewer_AppendFilter
121 myNodeRanges.clear();
122 myCellRanges.clear();
124 vtkIdType aPntStartId = 0;
125 vtkIdType aCellStartId = 0;
127 for(vtkIdType aDataSetId = 0; aDataSetId < this->GetNumberOfInputPorts(); ++aDataSetId){
128 vtkDataSet* aDataSet = (vtkDataSet *)(this->GetInput(aDataSetId));
129 // Do mapping of the nodes
130 if(!GetSharedPointsDataSet()){
131 vtkIdType aNbPnts = aDataSet->GetNumberOfPoints();
132 myNodeRanges.push_back(aPntStartId + aNbPnts);
133 aPntStartId += aNbPnts;
135 // Do mapping of the cells
136 vtkIdType aNbCells = aDataSet->GetNumberOfCells();
137 myCellRanges.push_back(aCellStartId + aNbCells);
138 aCellStartId += aNbCells;
146 GetOutputID(vtkIdType theInputID,
147 vtkIdType theInputDataSetID,
148 const VTKViewer_AppendFilter::TVectorIds& theRanges)
150 theInputID = theInputDataSetID = -1;
152 vtkIdType aNbInputs = (int)theRanges.size(); //!< TODO: conversion from size_t to int
153 if(theInputDataSetID < 0 || theInputDataSetID >= aNbInputs)
156 vtkIdType aStartId = theRanges[theInputDataSetID];
157 return aStartId + theInputID;
162 VTKViewer_AppendFilter
163 ::GetPointOutputID(vtkIdType theInputID,
164 vtkIdType theInputDataSetID)
166 if(GetSharedPointsDataSet())
169 return GetOutputID(theInputID,theInputDataSetID,myNodeRanges);
174 VTKViewer_AppendFilter
175 ::GetCellOutputID(vtkIdType theInputID,
176 vtkIdType theInputDataSetID)
178 if(GetSharedPointsDataSet())
181 return GetOutputID(theInputID,theInputDataSetID,myCellRanges);
188 GetInputID(vtkIdType theOutputID,
189 vtkIdType& theInputID,
190 vtkIdType& theStartID,
191 vtkIdType& theInputDataSetID,
192 const VTKViewer_AppendFilter::TVectorIds& theRanges)
194 theInputID = theStartID = theInputDataSetID = -1;
196 if(theRanges.empty())
199 const vtkIdType& aRangeEnd = theRanges.back();
200 if(theOutputID < 0 || theOutputID >= aRangeEnd)
203 vtkIdType aStartId = 0;
204 vtkIdType aNbInputs = (int)theRanges.size(); //!< TODO: conversion from size_t to int
205 for(vtkIdType aDataSetId = 0; aDataSetId < aNbInputs; ++aDataSetId){
206 vtkIdType aRange = theRanges[aDataSetId];
207 if(aRange > theOutputID){
208 theInputID = theOutputID - aStartId;
209 theInputDataSetID = aDataSetId;
210 theStartID = aStartId;
219 VTKViewer_AppendFilter
220 ::GetPointInputID(vtkIdType theOutputID,
221 vtkIdType& theInputID,
222 vtkIdType& theStartID,
223 vtkIdType& theInputDataSetID)
225 if(GetSharedPointsDataSet()) {
226 theStartID = theInputDataSetID = 0;
227 theInputID = theOutputID;
231 ::GetInputID(theOutputID,
240 VTKViewer_AppendFilter
241 ::GetCellInputID(vtkIdType theOutputID,
242 vtkIdType& theInputID,
243 vtkIdType& theStartID,
244 vtkIdType& theInputDataSetID)
246 ::GetInputID(theOutputID,
255 VTKViewer_AppendFilter
257 vtkInformation *vtkNotUsed(request),
258 vtkInformationVector **inputVector,
259 vtkInformationVector *outputVector)
262 vtkIdType numPts, numCells, cellId;
266 int numInputs = this->GetNumberOfInputConnections(0);
268 // get the output info object
269 vtkInformation *outInfo = outputVector->GetInformationObject(0);
272 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
273 outInfo->Get(vtkDataObject::DATA_OBJECT()));
275 numPts = mySharedPointsDataSet->GetNumberOfPoints();
281 vtkInformation *inInfo = 0;
282 for (idx = 0; idx < numInputs;++idx) {
283 inInfo = inputVector[0]->GetInformationObject(idx);
287 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
290 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) {
291 continue; //no input, just skip
293 numCells += ds->GetNumberOfCells();
294 }//if non-empty dataset
300 // Now can allocate memory
301 output->Allocate(numCells);
302 ptIds = vtkIdList::New();
303 ptIds->Allocate(VTK_CELL_SIZE);
305 // Append each input dataset together
308 output->SetPoints(GetSharedPointsDataSet()->GetPoints());
309 output->GetPointData()->PassData(GetSharedPointsDataSet()->GetPointData());
311 for (idx = 0; idx < numInputs; ++idx) {
312 inInfo = inputVector[0]->GetInformationObject(idx);
316 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
320 numCells = ds->GetNumberOfCells();
321 // cd = ds->GetCellData();
322 // copy cell and cell data
323 for (cellId=0; cellId<numCells; cellId++) {
324 ds->GetCellPoints(cellId, ptIds);
325 output->InsertNextCell(ds->GetCellType(cellId), ptIds);
334 int VTKViewer_AppendFilter::FillInputPortInformation(int, vtkInformation *info)
336 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
337 info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);