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 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 vtkCxxRevisionMacro(VTKViewer_AppendFilter, "$Revision$");
48 vtkStandardNewMacro(VTKViewer_AppendFilter);
50 VTKViewer_AppendFilter
51 ::VTKViewer_AppendFilter()
53 myDoMappingFlag = false;
56 VTKViewer_AppendFilter
57 ::~VTKViewer_AppendFilter()
61 VTKViewer_AppendFilter
62 ::SetDoMappingFlag(const bool theFlag)
64 if(myDoMappingFlag == theFlag)
67 myDoMappingFlag = theFlag;
73 VTKViewer_AppendFilter
74 ::DoMappingFlag() const
76 return myDoMappingFlag;
80 VTKViewer_AppendFilter
81 ::SetSharedPointsDataSet(vtkPointSet* thePointsDataSet)
83 if(GetSharedPointsDataSet() == thePointsDataSet)
86 mySharedPointsDataSet = thePointsDataSet;
92 VTKViewer_AppendFilter
93 ::GetSharedPointsDataSet()
95 return mySharedPointsDataSet.GetPointer();
99 VTKViewer_AppendFilter
101 vtkInformation *request,
102 vtkInformationVector **inputVector,
103 vtkInformationVector *outputVector)
106 if(GetSharedPointsDataSet())
107 aRet = MakeOutput(request,inputVector,outputVector);
109 aRet = Superclass::RequestData(request,inputVector,outputVector);
119 VTKViewer_AppendFilter
122 myNodeRanges.clear();
123 myCellRanges.clear();
125 vtkIdType aPntStartId = 0;
126 vtkIdType aCellStartId = 0;
128 for(vtkIdType aDataSetId = 0; aDataSetId < this->GetNumberOfInputPorts(); ++aDataSetId){
129 vtkDataSet* aDataSet = (vtkDataSet *)(this->GetInput(aDataSetId));
130 // Do mapping of the nodes
131 if(!GetSharedPointsDataSet()){
132 vtkIdType aNbPnts = aDataSet->GetNumberOfPoints();
133 myNodeRanges.push_back(aPntStartId + aNbPnts);
134 aPntStartId += aNbPnts;
136 // Do mapping of the cells
137 vtkIdType aNbCells = aDataSet->GetNumberOfCells();
138 myCellRanges.push_back(aCellStartId + aNbCells);
139 aCellStartId += aNbCells;
147 GetOutputID(vtkIdType theInputID,
148 vtkIdType theInputDataSetID,
149 const VTKViewer_AppendFilter::TVectorIds& theRanges)
151 theInputID = theInputDataSetID = -1;
153 vtkIdType aNbInputs = theRanges.size();
154 if(theInputDataSetID < 0 || theInputDataSetID >= aNbInputs)
157 vtkIdType aStartId = theRanges[theInputDataSetID];
158 return aStartId + theInputID;
163 VTKViewer_AppendFilter
164 ::GetPointOutputID(vtkIdType theInputID,
165 vtkIdType theInputDataSetID)
167 if(GetSharedPointsDataSet())
170 return GetOutputID(theInputID,theInputDataSetID,myNodeRanges);
175 VTKViewer_AppendFilter
176 ::GetCellOutputID(vtkIdType theInputID,
177 vtkIdType theInputDataSetID)
179 if(GetSharedPointsDataSet())
182 return GetOutputID(theInputID,theInputDataSetID,myCellRanges);
189 GetInputID(vtkIdType theOutputID,
190 vtkIdType& theInputID,
191 vtkIdType& theStartID,
192 vtkIdType& theInputDataSetID,
193 const VTKViewer_AppendFilter::TVectorIds& theRanges)
195 theInputID = theStartID = theInputDataSetID = -1;
197 if(theRanges.empty())
200 const vtkIdType& aRangeEnd = theRanges.back();
201 if(theOutputID < 0 || theOutputID >= aRangeEnd)
204 vtkIdType aStartId = 0;
205 vtkIdType aNbInputs = theRanges.size();
206 for(vtkIdType aDataSetId = 0; aDataSetId < aNbInputs; ++aDataSetId){
207 vtkIdType aRange = theRanges[aDataSetId];
208 if(aRange > theOutputID){
209 theInputID = theOutputID - aStartId;
210 theInputDataSetID = aDataSetId;
211 theStartID = aStartId;
220 VTKViewer_AppendFilter
221 ::GetPointInputID(vtkIdType theOutputID,
222 vtkIdType& theInputID,
223 vtkIdType& theStartID,
224 vtkIdType& theInputDataSetID)
226 if(GetSharedPointsDataSet()) {
227 theStartID = theInputDataSetID = 0;
228 theInputID = theOutputID;
232 ::GetInputID(theOutputID,
241 VTKViewer_AppendFilter
242 ::GetCellInputID(vtkIdType theOutputID,
243 vtkIdType& theInputID,
244 vtkIdType& theStartID,
245 vtkIdType& theInputDataSetID)
247 ::GetInputID(theOutputID,
256 VTKViewer_AppendFilter
258 vtkInformation *vtkNotUsed(request),
259 vtkInformationVector **inputVector,
260 vtkInformationVector *outputVector)
263 vtkIdType numPts, numCells, cellId;
267 int numInputs = this->GetNumberOfInputConnections(0);
269 // get the output info object
270 vtkInformation *outInfo = outputVector->GetInformationObject(0);
273 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
274 outInfo->Get(vtkDataObject::DATA_OBJECT()));
276 numPts = mySharedPointsDataSet->GetNumberOfPoints();
282 vtkInformation *inInfo = 0;
283 for (idx = 0; idx < numInputs;++idx) {
284 inInfo = inputVector[0]->GetInformationObject(idx);
288 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
291 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) {
292 continue; //no input, just skip
294 numCells += ds->GetNumberOfCells();
295 }//if non-empty dataset
301 // Now can allocate memory
302 output->Allocate(numCells);
303 ptIds = vtkIdList::New();
304 ptIds->Allocate(VTK_CELL_SIZE);
306 // Append each input dataset together
309 output->SetPoints(GetSharedPointsDataSet()->GetPoints());
310 output->GetPointData()->PassData(GetSharedPointsDataSet()->GetPointData());
312 for (idx = 0; idx < numInputs; ++idx) {
313 inInfo = inputVector[0]->GetInformationObject(idx);
317 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
321 numCells = ds->GetNumberOfCells();
322 // cd = ds->GetCellData();
323 // copy cell and cell data
324 for (cellId=0; cellId<numCells; cellId++) {
325 ds->GetCellPoints(cellId, ptIds);
326 output->InsertNextCell(ds->GetCellType(cellId), ptIds);
335 int VTKViewer_AppendFilter::FillInputPortInformation(int, vtkInformation *info)
337 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
338 info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);