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 : SALOME_GeometryFilter.cxx
25 // Author : Michael ZORIN
29 #include "VTKViewer_ShrinkFilter.h"
32 #include <vtkCellData.h>
33 #include <vtkIdList.h>
34 #include <vtkObjectFactory.h>
35 #include <vtkPointData.h>
36 #include <vtkUnstructuredGrid.h>
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 0;
42 static int MYDEBUG = 0;
43 static int MYDEBUGWITHFILES = 0;
46 vtkCxxRevisionMacro(VTKViewer_ShrinkFilter, "$Revision$");
47 vtkStandardNewMacro(VTKViewer_ShrinkFilter);
50 VTKViewer_ShrinkFilter::VTKViewer_ShrinkFilter():
55 VTKViewer_ShrinkFilter::~VTKViewer_ShrinkFilter()
59 void VTKViewer_ShrinkFilter::Execute()
62 int i, j, numIds, abort=0;
63 vtkIdType cellId, numCells, numPts;
64 vtkIdType oldId, newId;
65 float center[3], *p, pt[3];
66 vtkPointData *pd, *outPD;;
67 vtkIdList *ptIds, *newPtIds;
68 vtkDataSet *input= this->GetInput();
69 vtkUnstructuredGrid *output = this->GetOutput();
73 vtkDebugMacro(<<"Shrinking cells");
75 numCells=input->GetNumberOfCells();
76 numPts = input->GetNumberOfPoints();
77 if (numCells < 1 || numPts < 1)
79 vtkErrorMacro(<<"No data to shrink!");
83 ptIds = vtkIdList::New();
84 ptIds->Allocate(VTK_CELL_SIZE);
85 newPtIds = vtkIdList::New();
86 newPtIds->Allocate(VTK_CELL_SIZE);
88 output->Allocate(numCells);
89 newPts = vtkPoints::New();
90 newPts->Allocate(numPts*8,numPts);
91 pd = input->GetPointData();
92 outPD = output->GetPointData();
93 outPD->CopyAllocate(pd,numPts*8,numPts);
95 // Traverse all cells, obtaining node coordinates. Compute "center" of cell,
96 // then create new vertices shrunk towards center.
98 tenth = numCells/10 + 1;
101 myVTK2ObjIds.clear();
102 myVTK2ObjIds.reserve(numCells);
105 for (cellId=0; cellId < numCells && !abort; cellId++)
107 input->GetCellPoints(cellId, ptIds);
108 numIds = ptIds->GetNumberOfIds();
110 //abort/progress methods
111 if (cellId % tenth == 0)
114 this->UpdateProgress (decimal);
115 abort = this->GetAbortExecute();
118 // get the center of the cell
119 center[0] = center[1] = center[2] = 0.0;
120 for (i=0; i < numIds; i++)
122 p = input->GetPoint(ptIds->GetId(i));
123 for (j=0; j < 3; j++)
133 // Create new points and cells
135 for (i=0; i < numIds; i++)
137 p = input->GetPoint(ptIds->GetId(i));
138 for (j=0; j < 3; j++)
140 pt[j] = center[j] + this->ShrinkFactor*(p[j] - center[j]);
143 oldId = ptIds->GetId(i);
144 newId = newPts->InsertNextPoint(pt);
146 myVTK2ObjIds.push_back(oldId);
147 newPtIds->InsertId(i,newId);
149 outPD->CopyData(pd, oldId, newId);
151 output->InsertNextCell(input->GetCellType(cellId), newPtIds);
154 // Update ourselves and release memory
156 output->GetCellData()->PassData(input->GetCellData());
158 output->SetPoints(newPts);
167 void VTKViewer_ShrinkFilter::SetStoreMapping(int theStoreMapping){
168 myStoreMapping = theStoreMapping;
173 vtkIdType VTKViewer_ShrinkFilter::GetNodeObjId(int theVtkID){
174 if(myVTK2ObjIds.empty() || theVtkID > myVTK2ObjIds.size()) return -1;
175 return myVTK2ObjIds.at(theVtkID);