1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : VISU_UsedPointsFilter.cxx
25 #include "VISU_UsedPointsFilter.hxx"
27 #include <vtkObjectFactory.h>
28 #include <vtkUnstructuredGrid.h>
29 #include <vtkPointData.h>
30 #include <vtkCellData.h>
32 #include <vtkIdList.h>
36 vtkStandardNewMacro(VISU_UsedPointsFilter);
39 VISU_UsedPointsFilter::VISU_UsedPointsFilter()
43 VISU_UsedPointsFilter::~VISU_UsedPointsFilter()
47 void VISU_UsedPointsFilter::Execute(){
48 vtkDataSet *anInput = this->GetInput();
49 vtkUnstructuredGrid *anOutput = this->GetOutput();
51 typedef std::map<vtkIdType, vtkIdType> TId2IdMap;
54 vtkPointData *aPointData = anOutput->GetPointData();
55 aPointData->CopyAllocate(anInput->GetPointData());
57 vtkPoints* aUsedPoints = vtkPoints::New();
58 vtkIdList *anIdList = vtkIdList::New();
59 vtkIdType iEnd = anInput->GetNumberOfPoints();
60 for(vtkIdType aPointId = 0; aPointId < iEnd; aPointId++){
61 anInput->GetPointCells(aPointId,anIdList);
62 if(anIdList->GetNumberOfIds() > 0){
63 vtkIdType aNewPointId = aUsedPoints->InsertNextPoint(anInput->GetPoint(aPointId));
64 aPointData->CopyData(anInput->GetPointData(), aPointId, aNewPointId);
65 aId2IdMap[aPointId] = aNewPointId;
68 aPointData->Squeeze();
69 anOutput->SetPoints(aUsedPoints);
70 aUsedPoints->Delete();
73 vtkCellData *aCellData = anOutput->GetCellData();
74 aCellData->CopyAllocate(anInput->GetCellData());
76 anOutput->Allocate(anInput->GetNumberOfCells());
77 vtkIdList *anOldPointsIds = vtkIdList::New();
78 vtkIdList *aNewPointsIds = vtkIdList::New();
79 aNewPointsIds->Allocate(VTK_CELL_SIZE);
80 iEnd = anInput->GetNumberOfCells();
81 for(vtkIdType aCellId = 0; aCellId < iEnd; aCellId++){
82 anInput->GetCellPoints(aCellId, anOldPointsIds);
83 vtkIdType aNbPointsInCell = anOldPointsIds->GetNumberOfIds();
84 aNewPointsIds->Reset();
85 for(vtkIdType i = 0; i < aNbPointsInCell; i++){
86 vtkIdType anOldId = anOldPointsIds->GetId(i);
87 TId2IdMap::iterator anIter = aId2IdMap.find(anOldId);
88 if(anIter == aId2IdMap.end())
90 vtkIdType aNewId = anIter->second;
91 aNewPointsIds->InsertNextId(aNewId);
94 vtkIdType aNewCellId = anOutput->InsertNextCell(anInput->GetCellType(aCellId), aNewPointsIds);
95 aCellData->CopyData(anInput->GetCellData(), aCellId, aNewCellId);
100 aCellData->Squeeze();
101 anOldPointsIds->Delete();
102 aNewPointsIds->Delete();