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();
112 //==================================================================
113 // function: DoMapping
115 //==================================================================
117 VTKViewer_AppendFilter
120 myNodeRanges.clear();
121 myCellRanges.clear();
123 vtkIdType aPntStartId = 0;
124 vtkIdType aCellStartId = 0;
126 for(vtkIdType aDataSetId = 0; aDataSetId < this->NumberOfInputs; ++aDataSetId){
127 vtkDataSet* aDataSet = (vtkDataSet *)(this->Inputs[aDataSetId]);
128 // Do mapping of the nodes
129 if(!myPoints.GetPointer()){
130 vtkIdType aNbPnts = aDataSet->GetNumberOfPoints();
131 myNodeRanges.push_back(aPntStartId + aNbPnts);
132 aPntStartId += aNbPnts;
134 // Do mapping of the cells
135 vtkIdType aNbCells = aDataSet->GetNumberOfCells();
136 myCellRanges.push_back(aCellStartId + aNbCells);
137 aCellStartId += aNbCells;
141 //---------------------------------------------------------------
146 GetOutputID(vtkIdType theInputID,
147 vtkIdType theInputDataSetID,
148 const VTKViewer_AppendFilter::TVectorIds& theRanges)
150 theInputID = theInputDataSetID = -1;
152 vtkIdType aNbInputs = theRanges.size();
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(myPoints.GetPointer())
169 return GetOutputID(theInputID,theInputDataSetID,myNodeRanges);
173 //---------------------------------------------------------------
175 VTKViewer_AppendFilter
176 ::GetCellOutputID(vtkIdType theInputID,
177 vtkIdType theInputDataSetID)
179 if(myPoints.GetPointer())
182 return GetOutputID(theInputID,theInputDataSetID,myCellRanges);
186 //---------------------------------------------------------------
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(myPoints.GetPointer()) {
228 theStartID = theInputDataSetID = 0;
229 theInputID = theOutputID;
233 ::GetInputID(theOutputID,
241 //---------------------------------------------------------------
243 VTKViewer_AppendFilter
244 ::GetCellInputID(vtkIdType theOutputID,
245 vtkIdType& theInputID,
246 vtkIdType& theStartID,
247 vtkIdType& theInputDataSetID)
249 ::GetInputID(theOutputID,
257 //---------------------------------------------------------------
259 VTKViewer_AppendFilter
263 vtkIdType numPts, numCells, newCellId, cellId;
267 vtkUnstructuredGrid *output = this->GetOutput();
269 numPts = myPoints->GetNumberOfPoints();
275 for (idx = 0; idx < this->NumberOfInputs; ++idx) {
276 ds = (vtkDataSet *)(this->Inputs[idx]);
278 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) {
279 continue; //no input, just skip
281 numCells += ds->GetNumberOfCells();
282 }//if non-empty dataset
288 // Now can allocate memory
289 output->Allocate(numCells);
290 ptIds = vtkIdList::New();
291 ptIds->Allocate(VTK_CELL_SIZE);
293 // Append each input dataset together
296 output->SetPoints(myPoints.GetPointer());
298 for (idx = 0; idx < this->NumberOfInputs; ++idx) {
299 ds = (vtkDataSet *)(this->Inputs[idx]);
301 numCells = ds->GetNumberOfCells();
302 cd = ds->GetCellData();
303 // copy cell and cell data
304 for (cellId=0; cellId<numCells; cellId++) {
305 ds->GetCellPoints(cellId, ptIds);
306 newCellId = output->InsertNextCell(ds->GetCellType(cellId), ptIds);