39 vtkInformationVector** inputVector,
40 vtkInformationVector* outputVector)
42 vtkDebugMacro(<<
"Executing VtkImageDataToSurfacePointsFilter");
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()));
51 void* pixvals = input->GetScalarPointer();
52 int n_comp = input->GetNumberOfScalarComponents();
55 vtkDebugMacro(
"Error reading number of components.");
60 "RGB colours detected. Using only first channel for computation.");
63 auto const n_points =
static_cast<std::size_t
>(input->GetNumberOfPoints());
66 vtkDebugMacro(
"No data found!");
71 input->GetSpacing(spacing);
73 input->GetDimensions(dimensions);
75 input->GetOrigin(origin);
77 std::array<double, 3>{{origin[0], origin[1], origin[2]}});
79 std::vector<double> pixels;
80 pixels.reserve(n_points);
81 for (std::size_t i = 0; i < n_points; ++i)
83 if ((n_comp == 2 || n_comp == 4) &&
84 ((
static_cast<float*
>(pixvals))[(i + 1) * n_comp - 1] <
87 pixels.push_back(-9999);
91 pixels.push_back((
static_cast<float*
>(pixvals))[i * n_comp]);
95 {
static_cast<std::size_t
>(dimensions[0]),
96 static_cast<std::size_t
>(dimensions[1]), 1, ll, spacing[0], -9999},
100 vtkSmartPointer<vtkPoints> new_points = vtkSmartPointer<vtkPoints>::New();
102 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
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)
110 if (n_comp == 2 || n_comp == 4)
112 if ((
static_cast<float*
>(pixvals))[(i + 1) * n_comp - 1] <
120 input->GetPoint(i, p);
122 {p[0] - half_cellsize, p[1] - half_cellsize, 0}}};
124 {p[0] + half_cellsize, p[1] + half_cellsize, 0}}};
126 new_points, cells, pnt_idx, min_pnt, max_pnt, *raster);
130 output->SetPoints(new_points);
131 output->SetVerts(cells);
134 vtkDebugMacro(<<
"Created " << new_points->GetNumberOfPoints()
140 vtkSmartPointer<vtkPoints>& points,
141 vtkSmartPointer<vtkCellArray>& cells,
147 auto const n_points(
static_cast<std::size_t
>(this->GetPointsPerPixel()));
148 for (std::size_t i = 0; i < n_points; ++i)
155 points->SetPoint(pnt_idx + i, p);
156 cells->InsertNextCell(1);
157 cells->InsertCellPoint(pnt_idx + i);
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.