Updates the graphical object.
48{
49 vtkDebugMacro(<< "Executing VtkImageDataToSurfacePointsFilter");
50
51 vtkInformation* input_info = inputVector[0]->GetInformationObject(0);
52 vtkInformation* output_info = outputVector->GetInformationObject(0);
53 vtkImageData* input = vtkImageData::SafeDownCast(
54 input_info->Get(vtkDataObject::DATA_OBJECT()));
55 vtkPolyData* output = vtkPolyData::SafeDownCast(
56 output_info->Get(vtkDataObject::DATA_OBJECT()));
57
58 void* pixvals = input->GetScalarPointer();
59 int n_comp = input->GetNumberOfScalarComponents();
60 if (n_comp < 1)
61 {
62 vtkDebugMacro("Error reading number of components.");
63 }
64 if (n_comp > 2)
65 {
66 vtkDebugMacro(
67 "RGB colours detected. Using only first channel for computation.");
68 }
69
70 auto const n_points = static_cast<std::size_t>(input->GetNumberOfPoints());
71 if (n_points == 0)
72 {
73 vtkDebugMacro("No data found!");
74 return -1;
75 }
76
77 double spacing[3];
78 input->GetSpacing(spacing);
79 int dimensions[3];
80 input->GetDimensions(dimensions);
81 double origin[3];
82 input->GetOrigin(origin);
84 std::array<double, 3>{{origin[0], origin[1], origin[2]}});
85
86 std::vector<double> pixels;
87 pixels.reserve(n_points);
88 for (std::size_t i = 0; i < n_points; ++i)
89 {
90 if ((n_comp == 2 || n_comp == 4) &&
91 ((static_cast<float*>(pixvals))[(i + 1) * n_comp - 1] <
92 0.00000001f))
93 {
94 pixels.push_back(-9999);
95 }
96 else
97 {
98 pixels.push_back((static_cast<float*>(pixvals))[i * n_comp]);
99 }
100 }
102 {static_cast<std::size_t>(dimensions[0]),
103 static_cast<std::size_t>(dimensions[1]), 1, ll, spacing[0], -9999},
104 pixels.begin(),
105 pixels.end()));
106
107 vtkSmartPointer<vtkPoints> new_points = vtkSmartPointer<vtkPoints>::New();
109 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
111
112 double const half_cellsize(spacing[0] / 2.0);
113 std::size_t pnt_idx(0);
114 for (std::size_t i = 0; i < static_cast<std::size_t>(n_points); ++i)
115 {
116
117 if (n_comp == 2 || n_comp == 4)
118 {
119 if ((static_cast<float*>(pixvals))[(i + 1) * n_comp - 1] <
120 0.00000001f)
121 {
122 continue;
123 }
124 }
125
127 input->GetPoint(i, p);
129 {
p[0] - half_cellsize,
p[1] - half_cellsize, 0}}};
131 {
p[0] + half_cellsize,
p[1] + half_cellsize, 0}}};
133 new_points, cells, pnt_idx, min_pnt, max_pnt, *raster);
135 }
136
137 output->SetPoints(new_points);
138 output->SetVerts(cells);
139 output->Squeeze();
140
141 vtkDebugMacro(<< "Created " << new_points->GetNumberOfPoints()
142 << " points.");
143 return 1;
144}
Class Raster is used for managing raster data.
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.