1 // Copyright (C) 2007-2013 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>
33 #include <vtkInformation.h>
34 #include <vtkInformationVector.h>
38 vtkStandardNewMacro(VISU_UsedPointsFilter);
41 VISU_UsedPointsFilter::VISU_UsedPointsFilter()
45 VISU_UsedPointsFilter::~VISU_UsedPointsFilter()
50 int VISU_UsedPointsFilter::RequestData(
51 vtkInformation *vtkNotUsed(request),
52 vtkInformationVector **inputVector,
53 vtkInformationVector *outputVector)
55 // get the info objects
56 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
57 vtkInformation *outInfo = outputVector->GetInformationObject(0);
59 // get the input and ouptut
60 vtkDataSet *anInput = vtkDataSet::SafeDownCast(
61 inInfo->Get(vtkDataObject::DATA_OBJECT()));
62 vtkUnstructuredGrid *anOutput = vtkUnstructuredGrid::SafeDownCast(
63 outInfo->Get(vtkDataObject::DATA_OBJECT()));
65 typedef std::map<vtkIdType, vtkIdType> TId2IdMap;
68 vtkPointData *aPointData = anOutput->GetPointData();
69 aPointData->CopyAllocate(anInput->GetPointData());
71 vtkPoints* aUsedPoints = vtkPoints::New();
72 vtkIdList *anIdList = vtkIdList::New();
73 vtkIdType iEnd = anInput->GetNumberOfPoints();
74 for(vtkIdType aPointId = 0; aPointId < iEnd; aPointId++){
75 anInput->GetPointCells(aPointId,anIdList);
76 if(anIdList->GetNumberOfIds() > 0){
77 vtkIdType aNewPointId = aUsedPoints->InsertNextPoint(anInput->GetPoint(aPointId));
78 aPointData->CopyData(anInput->GetPointData(), aPointId, aNewPointId);
79 aId2IdMap[aPointId] = aNewPointId;
82 aPointData->Squeeze();
83 anOutput->SetPoints(aUsedPoints);
84 aUsedPoints->Delete();
87 vtkCellData *aCellData = anOutput->GetCellData();
88 aCellData->CopyAllocate(anInput->GetCellData());
90 anOutput->Allocate(anInput->GetNumberOfCells());
91 vtkIdList *anOldPointsIds = vtkIdList::New();
92 vtkIdList *aNewPointsIds = vtkIdList::New();
93 aNewPointsIds->Allocate(VTK_CELL_SIZE);
94 iEnd = anInput->GetNumberOfCells();
95 for(vtkIdType aCellId = 0; aCellId < iEnd; aCellId++){
96 anInput->GetCellPoints(aCellId, anOldPointsIds);
97 vtkIdType aNbPointsInCell = anOldPointsIds->GetNumberOfIds();
98 aNewPointsIds->Reset();
99 for(vtkIdType i = 0; i < aNbPointsInCell; i++){
100 vtkIdType anOldId = anOldPointsIds->GetId(i);
101 TId2IdMap::iterator anIter = aId2IdMap.find(anOldId);
102 if(anIter == aId2IdMap.end())
104 vtkIdType aNewId = anIter->second;
105 aNewPointsIds->InsertNextId(aNewId);
108 vtkIdType aNewCellId = anOutput->InsertNextCell(anInput->GetCellType(aCellId), aNewPointsIds);
109 aCellData->CopyData(anInput->GetCellData(), aCellId, aNewCellId);
114 aCellData->Squeeze();
115 anOldPointsIds->Delete();
116 aNewPointsIds->Delete();