Salome HOME
MPV: Merge V1_2d
[modules/visu.git] / src / PIPELINE / VISU_UsedPointsFilter.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 // File:    VISU_StreamLinesPL.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26
27
28 #include "VISU_UsedPointsFilter.hxx"
29
30 #include <vtkObjectFactory.h>
31 #include <vtkPointSet.h>
32 #include <vtkPointData.h>
33 #include <vtkCellData.h>
34 #include <vtkPoints.h>
35 #include <vtkIdList.h>
36
37 #ifdef _DEBUG_
38 static int MYDEBUG = 0;
39 #else
40 static int MYDEBUG = 0;
41 #endif
42
43 vtkStandardNewMacro(VISU_UsedPointsFilter);
44
45 VISU_UsedPointsFilter::VISU_UsedPointsFilter(){
46   PercentsOfUsedPoints = 1.0;
47 }
48
49 VISU_UsedPointsFilter::~VISU_UsedPointsFilter(){}
50
51 void VISU_UsedPointsFilter::Execute(){
52   vtkPointSet *anInput = this->GetInput(), *anOutput = this->GetOutput();
53   anOutput->GetPointData()->CopyAllOff();
54   anOutput->GetCellData()->CopyAllOff();
55   anOutput->CopyStructure(anInput);
56
57   vtkPoints* aPoints = vtkPoints::New();
58   vtkIdType aCellSize = anInput->GetMaxCellSize();
59   vtkIdList *anIdList = vtkIdList::New(); 
60   vtkIdType iEnd = anInput->GetNumberOfPoints();
61   for(vtkIdType i = 0; i < iEnd; i++){
62     anInput->GetPointCells(i,anIdList);
63     if(anIdList->GetNumberOfIds() > 0)
64       aPoints->InsertNextPoint(anInput->GetPoint(i));
65   }
66   vtkPoints* aNewPoints = vtkPoints::New();
67   iEnd = aPoints->GetNumberOfPoints();
68   if (PercentsOfUsedPoints > 0){
69     vtkIdType anOffset = vtkIdType(1.0/PercentsOfUsedPoints);
70     if(anOffset < 1) anOffset = 1;
71     for(vtkIdType i = 0; i < iEnd; i += anOffset)
72       aNewPoints->InsertNextPoint(aPoints->GetPoint(i));
73   }
74   anOutput->SetPoints(aNewPoints);
75   aNewPoints->Delete();
76   aPoints->Delete();
77 }