OGS
VtkImageDataToSurfacePointsFilter Class Reference

Detailed Description

A VTK filter that creates a point cloud representing a surface defined by pixel values

Definition at line 16 of file VtkImageDataToSurfacePointsFilter.h.

#include <VtkImageDataToSurfacePointsFilter.h>

Inheritance diagram for VtkImageDataToSurfacePointsFilter:
[legend]
Collaboration diagram for VtkImageDataToSurfacePointsFilter:
[legend]

Public Member Functions

 vtkTypeMacro (VtkImageDataToSurfacePointsFilter, vtkPolyDataAlgorithm)
void PrintSelf (ostream &os, vtkIndent indent) override
 Prints information about itself.
 vtkGetMacro (PointsPerPixel, vtkIdType)
 vtkSetMacro (PointsPerPixel, vtkIdType)

Static Public Member Functions

static VtkImageDataToSurfacePointsFilterNew ()
 Create a new objects (required because of VTKs reference counting)

Protected Member Functions

 VtkImageDataToSurfacePointsFilter ()
 ~VtkImageDataToSurfacePointsFilter () override=default
int FillInputPortInformation (int port, vtkInformation *info) override
 Sets input port to vtkImageData.
int RequestData (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
 Updates the graphical object.

Private Member Functions

void createPointSurface (vtkSmartPointer< vtkPoints > &points, vtkSmartPointer< vtkCellArray > &cells, std::size_t pnt_idx, MathLib::Point3d const &min_pnt, MathLib::Point3d const &max_pnt, GeoLib::Raster const &raster)
 Creates the point objects based on the parameters set by the user.
double getRandomNumber (double const &min, double const &max) const
 Returns a random number in [min, max].

Private Attributes

vtkIdType PointsPerPixel {20}

Constructor & Destructor Documentation

◆ VtkImageDataToSurfacePointsFilter()

VtkImageDataToSurfacePointsFilter::VtkImageDataToSurfacePointsFilter ( )
protecteddefault

Referenced by New(), and vtkTypeMacro().

◆ ~VtkImageDataToSurfacePointsFilter()

VtkImageDataToSurfacePointsFilter::~VtkImageDataToSurfacePointsFilter ( )
overrideprotecteddefault

Member Function Documentation

◆ createPointSurface()

void VtkImageDataToSurfacePointsFilter::createPointSurface ( vtkSmartPointer< vtkPoints > & points,
vtkSmartPointer< vtkCellArray > & cells,
std::size_t pnt_idx,
MathLib::Point3d const & min_pnt,
MathLib::Point3d const & max_pnt,
GeoLib::Raster const & raster )
private

Creates the point objects based on the parameters set by the user.

Definition at line 139 of file VtkImageDataToSurfacePointsFilter.cpp.

146{
147 auto const n_points(static_cast<std::size_t>(this->GetPointsPerPixel()));
148 for (std::size_t i = 0; i < n_points; ++i)
149 {
150 double p[3];
151 p[0] = getRandomNumber(min_pnt[0], max_pnt[0]);
152 p[1] = getRandomNumber(min_pnt[1], max_pnt[1]);
153 p[2] = raster.interpolateValueAtPoint(
154 MathLib::Point3d(std::array<double, 3>{{p[0], p[1], 0}}));
155 points->SetPoint(pnt_idx + i, p);
156 cells->InsertNextCell(1);
157 cells->InsertCellPoint(pnt_idx + i);
158 }
159}
double getRandomNumber(double const &min, double const &max) const
Returns a random number in [min, max].

References getRandomNumber(), and GeoLib::Raster::interpolateValueAtPoint().

Referenced by RequestData().

◆ FillInputPortInformation()

int VtkImageDataToSurfacePointsFilter::FillInputPortInformation ( int port,
vtkInformation * info )
overrideprotected

Sets input port to vtkImageData.

Definition at line 30 of file VtkImageDataToSurfacePointsFilter.cpp.

32{
33 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
34 return 1;
35}

◆ getRandomNumber()

double VtkImageDataToSurfacePointsFilter::getRandomNumber ( double const & min,
double const & max ) const
private

Returns a random number in [min, max].

Definition at line 161 of file VtkImageDataToSurfacePointsFilter.cpp.

163{
164 return (static_cast<double>(std::rand()) / RAND_MAX) * (max - min) + min;
165}

Referenced by createPointSurface().

◆ New()

VtkImageDataToSurfacePointsFilter * VtkImageDataToSurfacePointsFilter::New ( )
static

Create a new objects (required because of VTKs reference counting)

References VtkImageDataToSurfacePointsFilter().

Referenced by VtkCompositeImageToSurfacePointsFilter::init().

◆ PrintSelf()

void VtkImageDataToSurfacePointsFilter::PrintSelf ( ostream & os,
vtkIndent indent )
override

Prints information about itself.

Definition at line 25 of file VtkImageDataToSurfacePointsFilter.cpp.

26{
27 this->Superclass::PrintSelf(os, indent);
28}

◆ RequestData()

int VtkImageDataToSurfacePointsFilter::RequestData ( vtkInformation * request,
vtkInformationVector ** inputVector,
vtkInformationVector * outputVector )
overrideprotected

Updates the graphical object.

Definition at line 37 of file VtkImageDataToSurfacePointsFilter.cpp.

41{
42 vtkDebugMacro(<< "Executing VtkImageDataToSurfacePointsFilter");
43
44 vtkInformation* input_info = inputVector[0]->GetInformationObject(0);
45 vtkInformation* output_info = outputVector->GetInformationObject(0);
46 vtkImageData* input = vtkImageData::SafeDownCast(
47 input_info->Get(vtkDataObject::DATA_OBJECT()));
48 vtkPolyData* output = vtkPolyData::SafeDownCast(
49 output_info->Get(vtkDataObject::DATA_OBJECT()));
50
51 void* pixvals = input->GetScalarPointer();
52 int n_comp = input->GetNumberOfScalarComponents();
53 if (n_comp < 1)
54 {
55 vtkDebugMacro("Error reading number of components.");
56 }
57 if (n_comp > 2)
58 {
59 vtkDebugMacro(
60 "RGB colours detected. Using only first channel for computation.");
61 }
62
63 auto const n_points = static_cast<std::size_t>(input->GetNumberOfPoints());
64 if (n_points == 0)
65 {
66 vtkDebugMacro("No data found!");
67 return -1;
68 }
69
70 double spacing[3];
71 input->GetSpacing(spacing);
72 int dimensions[3];
73 input->GetDimensions(dimensions);
74 double origin[3];
75 input->GetOrigin(origin);
76 MathLib::Point3d const ll(
77 std::array<double, 3>{{origin[0], origin[1], origin[2]}});
78
79 std::vector<double> pixels;
80 pixels.reserve(n_points);
81 for (std::size_t i = 0; i < n_points; ++i)
82 {
83 if ((n_comp == 2 || n_comp == 4) &&
84 ((static_cast<float*>(pixvals))[(i + 1) * n_comp - 1] <
85 0.00000001f))
86 {
87 pixels.push_back(-9999);
88 }
89 else
90 {
91 pixels.push_back((static_cast<float*>(pixvals))[i * n_comp]);
92 }
93 }
94 GeoLib::Raster const* const raster(new GeoLib::Raster(
95 {static_cast<std::size_t>(dimensions[0]),
96 static_cast<std::size_t>(dimensions[1]), 1, ll, spacing[0], -9999},
97 pixels.begin(),
98 pixels.end()));
99
100 vtkSmartPointer<vtkPoints> new_points = vtkSmartPointer<vtkPoints>::New();
101 new_points->SetNumberOfPoints(PointsPerPixel * n_points);
102 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
103 cells->Allocate(PointsPerPixel * n_points);
104
105 double const half_cellsize(spacing[0] / 2.0);
106 std::size_t pnt_idx(0);
107 for (std::size_t i = 0; i < static_cast<std::size_t>(n_points); ++i)
108 {
109 // Skip transparent pixels
110 if (n_comp == 2 || n_comp == 4)
111 {
112 if ((static_cast<float*>(pixvals))[(i + 1) * n_comp - 1] <
113 0.00000001f)
114 {
115 continue;
116 }
117 }
118
119 double p[3];
120 input->GetPoint(i, p);
121 MathLib::Point3d min_pnt{std::array<double, 3>{
122 {p[0] - half_cellsize, p[1] - half_cellsize, 0}}};
123 MathLib::Point3d max_pnt{std::array<double, 3>{
124 {p[0] + half_cellsize, p[1] + half_cellsize, 0}}};
126 new_points, cells, pnt_idx, min_pnt, max_pnt, *raster);
127 pnt_idx += PointsPerPixel;
128 }
129
130 output->SetPoints(new_points);
131 output->SetVerts(cells);
132 output->Squeeze();
133
134 vtkDebugMacro(<< "Created " << new_points->GetNumberOfPoints()
135 << " points.");
136 return 1;
137}
void createPointSurface(vtkSmartPointer< vtkPoints > &points, vtkSmartPointer< vtkCellArray > &cells, std::size_t pnt_idx, MathLib::Point3d const &min_pnt, MathLib::Point3d const &max_pnt, GeoLib::Raster const &raster)
Creates the point objects based on the parameters set by the user.

References createPointSurface(), and PointsPerPixel.

◆ vtkGetMacro()

VtkImageDataToSurfacePointsFilter::vtkGetMacro ( PointsPerPixel ,
vtkIdType  )

References PointsPerPixel.

◆ vtkSetMacro()

VtkImageDataToSurfacePointsFilter::vtkSetMacro ( PointsPerPixel ,
vtkIdType  )

References PointsPerPixel.

◆ vtkTypeMacro()

VtkImageDataToSurfacePointsFilter::vtkTypeMacro ( VtkImageDataToSurfacePointsFilter ,
vtkPolyDataAlgorithm  )

Member Data Documentation

◆ PointsPerPixel

vtkIdType VtkImageDataToSurfacePointsFilter::PointsPerPixel {20}
private

Definition at line 53 of file VtkImageDataToSurfacePointsFilter.h.

53{20};

Referenced by RequestData(), vtkGetMacro(), and vtkSetMacro().


The documentation for this class was generated from the following files: