[vtkusers] Get points within specific range
David Doria
daviddoria at gmail.com
Mon Feb 23 08:04:45 EST 2015
On Mon, Feb 23, 2015 at 5:09 AM, madz <madaramh at gmail.com> wrote:
> What method can I use to get the points between a specific X range with
> static Y and Z values?
>
> eg - Get point ids between the ranges of,
> p1 - 0.1 ,0.23, 0.78
> p2 - 123.0 ,0.23, 0.78
>
> Any help would be greatly appreciated.
>
One way to do this would be to select points inside a cube that is huge
(much much larger than your data) in two dimensions and with the bounds on
your X range as the third dimension. Then you could use something like the
following (though it is currently returning 0 points extracted, so you'll
have to figure out what is wrong):
#include <vtkCubeSource.h>
#include <vtkExtractSelectedFrustum.h>
#include <vtkPlanes.h>
#include <vtkPointSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
int main(int, char *[])
{
// Define your selection region
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->SetCenter(0,0,0);
cubeSource->SetXLength(1);
cubeSource->SetYLength(1);
cubeSource->SetZLength(1);
cubeSource->Update();
double bounds[6];
cubeSource->GetOutput()->GetBounds(bounds);
vtkSmartPointer<vtkPlanes> frustum =
vtkSmartPointer<vtkPlanes>::New();
frustum->SetBounds(bounds);
// Generate some points
vtkSmartPointer<vtkPointSource> pointSource =
vtkSmartPointer<vtkPointSource>::New();
pointSource->SetNumberOfPoints(500);
pointSource->SetCenter(0,0,0);
pointSource->SetRadius(5);
pointSource->Update();
std::cout << "There are " <<
pointSource->GetOutput()->GetNumberOfPoints() << " input points." <<
std::endl;
// Extract the points within the frustum
vtkSmartPointer<vtkExtractSelectedFrustum> extractSelectedFrustum =
vtkSmartPointer<vtkExtractSelectedFrustum>::New();
extractSelectedFrustum->SetFrustum(frustum);
extractSelectedFrustum->SetInputData(pointSource->GetOutput());
extractSelectedFrustum->Update();
std::cout << "There are " << vtkDataSet::SafeDownCast
(extractSelectedFrustum->GetOutput())->GetNumberOfPoints() << " output
points." << std::endl;
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150223/1f6aff7c/attachment.html>
More information about the vtkusers
mailing list