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"
31 #include "VTKViewer_ConvexTool.h"
33 #include <vtkSmartPointer.h>
34 #include <vtkCellArray.h>
35 #include <vtkCellData.h>
36 #include <vtkGenericCell.h>
37 #include <vtkHexahedron.h>
38 #include <vtkMergePoints.h>
39 #include <vtkObjectFactory.h>
40 #include <vtkPointData.h>
41 #include <vtkPolyData.h>
42 #include <vtkPyramid.h>
43 #include <vtkStructuredGrid.h>
45 #include <vtkUnsignedCharArray.h>
46 #include <vtkUnstructuredGrid.h>
49 #include <vtkDataSetCollection.h>
57 //static int MYDEBUG = 0;
58 //static int MYDEBUGWITHFILES = 0;
60 //static int MYDEBUG = 0;
61 //static int MYDEBUGWITHFILES = 0;
70 vtkCxxRevisionMacro(VTKViewer_AppendFilter, "$Revision$");
71 vtkStandardNewMacro(VTKViewer_AppendFilter);
73 VTKViewer_AppendFilter
74 ::VTKViewer_AppendFilter()
76 myDoMappingFlag=false;
79 VTKViewer_AppendFilter
80 ::~VTKViewer_AppendFilter()
84 VTKViewer_AppendFilter
85 ::SetDoMappingFlag(const bool theFlag)
87 myDoMappingFlag=theFlag;
91 VTKViewer_AppendFilter
92 ::DoMappingFlag() const
94 return myDoMappingFlag;
98 VTKViewer_AppendFilter
99 ::SetPoints(vtkPoints* thePoints)
101 myPoints = thePoints;
105 VTKViewer_AppendFilter
108 return myPoints.GetPointer();
112 VTKViewer_AppendFilter
115 if (myPoints.GetPointer()) {
119 vtkAppendFilter::Execute();
121 if (myDoMappingFlag){
127 VTKViewer_AppendFilter
132 myNodeRanges.clear();
133 myCellRanges.clear();
134 myNodeMapObjIDVtkID.clear();
135 myCellMapObjIDVtkID.clear();
137 //==================================================================
138 // function: DoMapping
140 //==================================================================
142 VTKViewer_AppendFilter
145 int i, j, i1, i2, iNodeCnt, iCellCnt;
146 IteratorOfDataMapOfIntegerInteger aMapIt;
147 vtkIdType aNbPnts, aNbCells, aId;
154 for (i=0; i<NumberOfInputs; ++i) {
155 pDS=(vtkDataSet *)Inputs[i];
158 if (!myPoints.GetPointer()) {
159 aNbPnts=pDS->GetNumberOfPoints();
162 myNodeRanges.push_back(i1);
163 myNodeRanges.push_back(i2);
165 for(j=0; j<aNbPnts; ++j) {
167 myNodeIds.push_back(aId);
169 aMapIt=myNodeMapObjIDVtkID.find(aId);
170 if (aMapIt==myNodeMapObjIDVtkID.end()) {
172 myNodeMapObjIDVtkID[aId]=iNodeCnt;
179 aNbCells=pDS->GetNumberOfCells();
182 myCellRanges.push_back(i1);
183 myCellRanges.push_back(i2);
184 for(j=0; j<aNbCells; ++j) {
186 myCellIds.push_back(aId);
188 aMapIt=myCellMapObjIDVtkID.find(aId);
189 if (aMapIt==myCellMapObjIDVtkID.end()) {
191 myCellMapObjIDVtkID[aId]=iCellCnt;
198 //---------------------------------------------------------------
200 VTKViewer_AppendFilter
201 ::GetPointOutputID(vtkIdType theInputID)
203 if (myPoints.GetPointer()) {
208 IteratorOfDataMapOfIntegerInteger aMapIt;
210 aMapIt=myNodeMapObjIDVtkID.find(theInputID);
211 if (aMapIt!=myNodeMapObjIDVtkID.end()) {
213 PairOfDataMapOfIntegerInteger& aPair=(*aMapIt);
220 //---------------------------------------------------------------
222 VTKViewer_AppendFilter
223 ::GetCellOutputID(vtkIdType theInputID)
226 IteratorOfDataMapOfIntegerInteger aMapIt;
228 aMapIt=myCellMapObjIDVtkID.find(theInputID);
229 if (aMapIt!=myCellMapObjIDVtkID.end()) {
231 PairOfDataMapOfIntegerInteger& aPair=(*aMapIt);
238 //---------------------------------------------------------------
240 VTKViewer_AppendFilter
241 ::GetPointInputID(vtkIdType theOutputID,
242 vtkIdType& theInputDataSetID)
244 if (myPoints.GetPointer()) {
249 int aNb, aNbRanges, aRetID, i, i1, i2, j;
252 theInputDataSetID=-1;
254 aNb=myNodeIds.size();
255 if (theOutputID<0 || theOutputID>=aNb) {
259 aRetID=(int)myNodeIds[theOutputID];
261 aNbRanges=myNodeRanges.size()/2;
262 for (i=0; i<aNbRanges; ++i) {
265 i2=myNodeRanges[j+1];
266 if (theOutputID>=i1 && theOutputID<=i2) {
275 //---------------------------------------------------------------
277 VTKViewer_AppendFilter
278 ::GetCellInputID(vtkIdType theOutputID,
279 vtkIdType& theInputDataSetID)
281 int aNb, aNbRanges, aRetID, i, i1, i2, j;
284 theInputDataSetID=-1;
286 aNb=myCellIds.size();
287 if (theOutputID<0 || theOutputID>=aNb) {
291 aRetID=(int)myCellIds[theOutputID];
293 aNbRanges=myCellRanges.size()/2;
294 for (i=0; i<aNbRanges; ++i) {
297 i2=myCellRanges[j+1];
298 if (theOutputID>=i1 && theOutputID<=i2) {
307 //---------------------------------------------------------------
309 VTKViewer_AppendFilter
313 vtkIdType numPts, numCells, newCellId, cellId;
317 vtkUnstructuredGrid *output = this->GetOutput();
319 numPts = myPoints->GetNumberOfPoints();
325 for (idx = 0; idx < this->NumberOfInputs; ++idx) {
326 ds = (vtkDataSet *)(this->Inputs[idx]);
328 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 ) {
329 continue; //no input, just skip
331 numCells += ds->GetNumberOfCells();
332 }//if non-empty dataset
338 // Now can allocate memory
339 output->Allocate(numCells);
340 ptIds = vtkIdList::New();
341 ptIds->Allocate(VTK_CELL_SIZE);
343 // Append each input dataset together
346 output->SetPoints(myPoints.GetPointer());
348 for (idx = 0; idx < this->NumberOfInputs; ++idx) {
349 ds = (vtkDataSet *)(this->Inputs[idx]);
351 numCells = ds->GetNumberOfCells();
352 cd = ds->GetCellData();
353 // copy cell and cell data
354 for (cellId=0; cellId<numCells; cellId++) {
355 ds->GetCellPoints(cellId, ptIds);
356 newCellId = output->InsertNextCell(ds->GetCellType(cellId), ptIds);