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
20 // VISU OBJECT : interactive object for VISU entities implementation
21 // File: VISU_StreamLinesPL.cxx
22 // Author: Alexey PETROV
25 #include "VISU_MaskPointsFilter.hxx"
27 #include <vtkObjectFactory.h>
28 #include <vtkPointSet.h>
29 #include <vtkPointData.h>
30 #include <vtkCellData.h>
31 #include <vtkPoints.h>
32 #include <vtkIdList.h>
33 #include <vtkInformation.h>
34 #include <vtkInformationVector.h>
36 vtkStandardNewMacro(VISU_MaskPointsFilter);
38 VISU_MaskPointsFilter::VISU_MaskPointsFilter(){
39 PercentsOfUsedPoints = 1.0;
42 VISU_MaskPointsFilter::~VISU_MaskPointsFilter(){}
44 int VISU_MaskPointsFilter::RequestData(
45 vtkInformation *vtkNotUsed(request),
46 vtkInformationVector **inputVector,
47 vtkInformationVector *outputVector)
49 // get the info objects
50 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
51 vtkInformation *outInfo = outputVector->GetInformationObject(0);
53 // get the input and ouptut
54 vtkPointSet *anInput = vtkPointSet::SafeDownCast(
55 inInfo->Get(vtkDataObject::DATA_OBJECT()));
56 vtkPointSet *anOutput = vtkPointSet::SafeDownCast(
57 outInfo->Get(vtkDataObject::DATA_OBJECT()));
59 anOutput->GetPointData()->CopyAllOff();
60 anOutput->GetCellData()->CopyAllOff();
61 anOutput->CopyStructure(anInput);
63 vtkPoints* aPoints = vtkPoints::New();
64 vtkIdList *anIdList = vtkIdList::New();
65 vtkIdType iEnd = anInput->GetNumberOfPoints();
66 for(vtkIdType i = 0; i < iEnd; i++){
67 anInput->GetPointCells(i,anIdList);
68 if(anIdList->GetNumberOfIds() > 0)
69 aPoints->InsertNextPoint(anInput->GetPoint(i));
71 vtkPoints* aNewPoints = vtkPoints::New();
72 iEnd = aPoints->GetNumberOfPoints();
73 if (PercentsOfUsedPoints > 0){
74 vtkIdType anOffset = vtkIdType(1.0/PercentsOfUsedPoints);
75 if(anOffset < 1) anOffset = 1;
76 for(vtkIdType i = 0; i < iEnd; i += anOffset)
77 aNewPoints->InsertNextPoint(aPoints->GetPoint(i));
79 anOutput->SetPoints(aNewPoints);