1 // SALOME OBJECT : kernel of SALOME component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VTKViewer_GeometryFilter.cxx
29 #include "VTKViewer_AppendFilter.h"
32 #include <vtkCellData.h>
33 #include <vtkDataSetAttributes.h>
34 #include <vtkDataSetCollection.h>
35 #include <vtkObjectFactory.h>
36 #include <vtkPointData.h>
37 #include <vtkUnstructuredGrid.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 ::SetPoints(vtkPoints* thePoints)
83 if(GetPoints() == thePoints)
92 VTKViewer_AppendFilter
95 return myPoints.GetPointer();
99 VTKViewer_AppendFilter
102 if(myPoints.GetPointer())
105 Superclass::Execute();
113 VTKViewer_AppendFilter
116 myNodeRanges.clear();
117 myCellRanges.clear();
119 vtkIdType aPntStartId = 0;
120 vtkIdType aCellStartId = 0;
122 for(vtkIdType aDataSetId = 0; aDataSetId < this->NumberOfInputs; ++aDataSetId){
123 vtkDataSet* aDataSet = (vtkDataSet *)(this->Inputs[aDataSetId]);
124 // Do mapping of the nodes
125 if(!myPoints.GetPointer()){
126 vtkIdType aNbPnts = aDataSet->GetNumberOfPoints();
127 myNodeRanges.push_back(aPntStartId + aNbPnts);
128 aPntStartId += aNbPnts;
130 // Do mapping of the cells
131 vtkIdType aNbCells = aDataSet->GetNumberOfCells();
132 myCellRanges.push_back(aCellStartId + aNbCells);
133 aCellStartId += aNbCells;
141 GetOutputID(vtkIdType theInputID,
142 vtkIdType theInputDataSetID,
143 const VTKViewer_AppendFilter::TVectorIds& theRanges)
145 theInputID = theInputDataSetID = -1;
147 vtkIdType aNbInputs = theRanges.size();
148 if(theInputDataSetID < 0 || theInputDataSetID >= aNbInputs)
151 vtkIdType aStartId = theRanges[theInputDataSetID];
152 return aStartId + theInputID;
157 VTKViewer_AppendFilter
158 ::GetPointOutputID(vtkIdType theInputID,
159 vtkIdType theInputDataSetID)
161 if(myPoints.GetPointer())
164 return GetOutputID(theInputID,theInputDataSetID,myNodeRanges);
169 VTKViewer_AppendFilter
170 ::GetCellOutputID(vtkIdType theInputID,
171 vtkIdType theInputDataSetID)
173 if(myPoints.GetPointer())
176 return GetOutputID(theInputID,theInputDataSetID,myCellRanges);
183 GetInputID(vtkIdType theOutputID,
184 vtkIdType& theInputID,
185 vtkIdType& theStartID,
186 vtkIdType& theInputDataSetID,
187 const VTKViewer_AppendFilter::TVectorIds& theRanges)
189 theInputID = theStartID = theInputDataSetID = -1;
191 if(theRanges.empty())
194 const vtkIdType& aRangeEnd = theRanges.back();
195 if(theOutputID < 0 || theOutputID >= aRangeEnd)
198 vtkIdType aStartId = 0;
199 vtkIdType aNbInputs = theRanges.size();
200 for(vtkIdType aDataSetId = 0; aDataSetId < aNbInputs; ++aDataSetId){
201 vtkIdType aRange = theRanges[aDataSetId];
202 if(aRange > theOutputID){
203 theInputID = theOutputID - aStartId;
204 theInputDataSetID = aDataSetId;
205 theStartID = aStartId;
214 VTKViewer_AppendFilter
215 ::GetPointInputID(vtkIdType theOutputID,
216 vtkIdType& theInputID,
217 vtkIdType& theStartID,
218 vtkIdType& theInputDataSetID)
220 if(myPoints.GetPointer()) {
221 theStartID = theInputDataSetID = 0;
222 theInputID = theOutputID;
226 ::GetInputID(theOutputID,
235 VTKViewer_AppendFilter
236 ::GetCellInputID(vtkIdType theOutputID,
237 vtkIdType& theInputID,
238 vtkIdType& theStartID,
239 vtkIdType& theInputDataSetID)
241 ::GetInputID(theOutputID,
250 VTKViewer_AppendFilter
254 vtkIdType numPts, numCells, newCellId, cellId;
258 vtkUnstructuredGrid *output = this->GetOutput();
260 numPts = myPoints->GetNumberOfPoints();
266 for (idx = 0; idx < this->NumberOfInputs; ++idx) {
267 ds = (vtkDataSet *)(this->Inputs[idx]);
269 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) {
270 continue; //no input, just skip
272 numCells += ds->GetNumberOfCells();
273 }//if non-empty dataset
279 // Now can allocate memory
280 output->Allocate(numCells);
281 ptIds = vtkIdList::New();
282 ptIds->Allocate(VTK_CELL_SIZE);
284 // Append each input dataset together
287 output->SetPoints(myPoints.GetPointer());
289 for (idx = 0; idx < this->NumberOfInputs; ++idx) {
290 ds = (vtkDataSet *)(this->Inputs[idx]);
292 numCells = ds->GetNumberOfCells();
293 cd = ds->GetCellData();
294 // copy cell and cell data
295 for (cellId=0; cellId<numCells; cellId++) {
296 ds->GetCellPoints(cellId, ptIds);
297 newCellId = output->InsertNextCell(ds->GetCellType(cellId), ptIds);