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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_UsedPointsFilter.cxx
28 #include "VISU_UsedPointsFilter.hxx"
30 #include <vtkObjectFactory.h>
31 #include <vtkUnstructuredGrid.h>
32 #include <vtkPointData.h>
33 #include <vtkCellData.h>
35 #include <vtkIdList.h>
39 vtkStandardNewMacro(VISU_UsedPointsFilter);
42 VISU_UsedPointsFilter::VISU_UsedPointsFilter()
46 VISU_UsedPointsFilter::~VISU_UsedPointsFilter()
50 void VISU_UsedPointsFilter::Execute(){
51 vtkDataSet *anInput = this->GetInput();
52 vtkUnstructuredGrid *anOutput = this->GetOutput();
54 typedef std::map<vtkIdType, vtkIdType> TId2IdMap;
57 vtkPointData *aPointData = anOutput->GetPointData();
58 aPointData->CopyAllocate(anInput->GetPointData());
60 vtkPoints* aUsedPoints = vtkPoints::New();
61 vtkIdList *anIdList = vtkIdList::New();
62 vtkIdType iEnd = anInput->GetNumberOfPoints();
63 for(vtkIdType aPointId = 0; aPointId < iEnd; aPointId++){
64 anInput->GetPointCells(aPointId,anIdList);
65 if(anIdList->GetNumberOfIds() > 0){
66 vtkIdType aNewPointId = aUsedPoints->InsertNextPoint(anInput->GetPoint(aPointId));
67 aPointData->CopyData(anInput->GetPointData(), aPointId, aNewPointId);
68 aId2IdMap[aPointId] = aNewPointId;
71 aPointData->Squeeze();
72 anOutput->SetPoints(aUsedPoints);
73 aUsedPoints->Delete();
76 vtkCellData *aCellData = anOutput->GetCellData();
77 aCellData->CopyAllocate(anInput->GetCellData());
79 anOutput->Allocate(anInput->GetNumberOfCells());
80 vtkIdList *anOldPointsIds = vtkIdList::New();
81 vtkIdList *aNewPointsIds = vtkIdList::New();
82 aNewPointsIds->Allocate(VTK_CELL_SIZE);
83 iEnd = anInput->GetNumberOfCells();
84 for(vtkIdType aCellId = 0; aCellId < iEnd; aCellId++){
85 anInput->GetCellPoints(aCellId, anOldPointsIds);
86 vtkIdType aNbPointsInCell = anOldPointsIds->GetNumberOfIds();
87 aNewPointsIds->Reset();
88 for(vtkIdType i = 0; i < aNbPointsInCell; i++){
89 vtkIdType anOldId = anOldPointsIds->GetId(i);
90 TId2IdMap::iterator anIter = aId2IdMap.find(anOldId);
91 if(anIter == aId2IdMap.end())
93 vtkIdType aNewId = anIter->second;
94 aNewPointsIds->InsertNextId(aNewId);
97 vtkIdType aNewCellId = anOutput->InsertNextCell(anInput->GetCellType(aCellId), aNewPointsIds);
98 aCellData->CopyData(anInput->GetCellData(), aCellId, aNewCellId);
103 aCellData->Squeeze();
104 anOldPointsIds->Delete();
105 aNewPointsIds->Delete();