1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkMaskPoints.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkMaskPoints.h"
#include "vtkCellArray.h"
#include "vtkDataSet.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
vtkCxxRevisionMacro(vtkMaskPoints, "$Revision: 1.45 $");
vtkStandardNewMacro(vtkMaskPoints);
//----------------------------------------------------------------------------
vtkMaskPoints::vtkMaskPoints()
{
this->OnRatio = 2;
this->Offset = 0;
this->RandomMode = 0;
this->MaximumNumberOfPoints = VTK_LARGE_ID;
this->GenerateVertices = 0;
}
//----------------------------------------------------------------------------
void vtkMaskPoints::Execute()
{
vtkPoints *newPts;
vtkPointData *pd;
vtkIdType numNewPts;
double x[3];
vtkIdType ptId, id;
vtkPolyData *output = this->GetOutput();
vtkPointData *outputPD = output->GetPointData();
vtkDataSet *input= this->GetInput();
vtkIdType numPts=input->GetNumberOfPoints();
// Check input
//
vtkDebugMacro(<<"Masking points");
if ( numPts < 1 )
{
return;
}
pd = input->GetPointData();
id = 0;
// Allocate space
//
numNewPts = numPts / this->OnRatio;
if (numNewPts > this->MaximumNumberOfPoints)
{
numNewPts = this->MaximumNumberOfPoints;
}
newPts = vtkPoints::New();
newPts->Allocate(numNewPts);
outputPD->CopyAllocate(pd);
// Traverse points and copy
//
int abort=0;
vtkIdType progressInterval=numPts/20 +1;
if ( this->RandomMode ) // retro mode
{
double cap;
if (((double)numPts/this->OnRatio) > this->MaximumNumberOfPoints)
{
cap = 2.0*numPts/this->MaximumNumberOfPoints - 1;
}
else
{
cap = 2.0*this->OnRatio - 1;
}
for (ptId = this->Offset;
(ptId < numPts) && (id < this->MaximumNumberOfPoints) && !abort;
ptId += (1 + (int)((double)vtkMath::Random()*cap)) )
{
input->GetPoint(ptId, x);
id = newPts->InsertNextPoint(x);
outputPD->CopyData(pd,ptId,id);
if ( ! (id % progressInterval) ) //abort/progress
{
this->UpdateProgress (0.5*id/numPts);
abort = this->GetAbortExecute();
}
}
}
else // a.r. mode
{
for ( ptId = this->Offset;
(ptId < numPts) && (id < (this->MaximumNumberOfPoints-1)) && !abort;
ptId += this->OnRatio )
{
input->GetPoint(ptId, x);
id = newPts->InsertNextPoint(x);
outputPD->CopyData(pd,ptId,id);
if ( ! (id % progressInterval) ) //abort/progress
{
this->UpdateProgress (0.5*id/numPts);
abort = this->GetAbortExecute();
}
}
}
// Generate vertices if requested
//
if ( this->GenerateVertices )
{
vtkCellArray *verts = vtkCellArray::New();
verts->Allocate(verts->EstimateSize(1,id+1));
verts->InsertNextCell(id+1);
for ( ptId=0; ptId<(id+1) && !abort; ptId++)
{
if ( ! (ptId % progressInterval) ) //abort/progress
{
this->UpdateProgress (0.5+0.5*ptId/(id+1));
abort = this->GetAbortExecute();
}
verts->InsertCellPoint(ptId);
}
output->SetVerts(verts);
verts->Delete();
}
// Update ourselves
//
output->SetPoints(newPts);
newPts->Delete();
output->Squeeze();
vtkDebugMacro(<<"Masked " << numPts << " original points to "
<< id+1 << " points");
}
//----------------------------------------------------------------------------
void vtkMaskPoints::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Generate Vertices: "
<< (this->GenerateVertices ? "On\n" : "Off\n");
os << indent << "MaximumNumberOfPoints: "
<< this->MaximumNumberOfPoints << "\n";
os << indent << "On Ratio: " << this->OnRatio << "\n";
os << indent << "Offset: " << this->Offset << "\n";
os << indent << "Random Mode: " << (this->RandomMode ? "On\n" : "Off\n");
}
|