39 vtkInformationVector** inputVector,
40 vtkInformationVector* outputVector)
42 vtkDebugMacro(<<
"Executing VtkImageDataToPointCloudFilter");
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 if (input->GetScalarSize() !=
sizeof(
float))
54 "Existing data does not have float-type and cannot be processed. "
55 "Aborting filter process...");
58 float* pixvals =
static_cast<float*
>(input->GetScalarPointer());
59 int const n_comp = input->GetNumberOfScalarComponents();
62 vtkDebugMacro(
"Error reading number of components.");
67 "RGB colours detected. Using only first channel for computation.");
70 vtkIdType
const n_points = input->GetNumberOfPoints();
73 vtkDebugMacro(
"No data found!");
78 input->GetSpacing(spacing);
83 vtkPointData* input_data = input->GetPointData();
84 input_data->GetArray(0)->GetRange(range);
89 std::vector<vtkIdType> density;
90 density.reserve(n_points);
91 for (vtkIdType i = 0; i < n_points; ++i)
94 if (n_comp == 2 || n_comp == 4)
96 if (pixvals[(i + 1) * n_comp - 1] < 0.00000001f)
102 double const val(pixvals[i * n_comp]);
104 std::size_t
const pnts_per_cell =
106 density.push_back(
static_cast<vtkIdType
>(
107 std::floor(pnts_per_cell * GetPointScaleFactor())));
112 std::accumulate(density.begin(), density.end(), vtkIdType{0});
113 vtkSmartPointer<vtkPoints> new_points = vtkSmartPointer<vtkPoints>::New();
114 new_points->SetNumberOfPoints(sum);
115 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
116 cells->Allocate(sum);
117 vtkSmartPointer<vtkDoubleArray> intensity =
118 vtkSmartPointer<vtkDoubleArray>::New();
119 intensity->Allocate(sum);
120 intensity->SetName(
"Intensity");
121 double const half_cellsize(spacing[0] / 2.0);
122 std::size_t pnt_idx(0);
123 for (std::size_t i = 0; i < static_cast<std::size_t>(n_points); ++i)
130 input->GetPoint(i, p);
133 {p[0] - half_cellsize, p[1] - half_cellsize,
MinHeight}}};
135 {p[0] + half_cellsize, p[1] + half_cellsize,
MaxHeight}}};
136 createPoints(new_points, cells, pnt_idx, density[i], min_pnt, max_pnt);
137 for (vtkIdType j = 0; j < density[i]; ++j)
139 intensity->InsertValue(pnt_idx + j, pixvals[i * n_comp]);
141 pnt_idx += density[i];
144 output->SetPoints(new_points);
145 output->SetVerts(cells);
146 output->GetPointData()->AddArray(intensity);
147 output->GetPointData()->SetActiveAttribute(
"Intensity",
148 vtkDataSetAttributes::SCALARS);
151 vtkDebugMacro(<<
"Created " << new_points->GetNumberOfPoints()
157 vtkSmartPointer<vtkPoints>& points,
158 vtkSmartPointer<vtkCellArray>& cells,
160 std::size_t n_points,
164 for (std::size_t i = 0; i < n_points; ++i)
170 points->SetPoint(pnt_idx + i, p);
171 cells->InsertNextCell(1);
172 cells->InsertCellPoint(pnt_idx + i);
void createPoints(vtkSmartPointer< vtkPoints > &points, vtkSmartPointer< vtkCellArray > &cells, std::size_t pnt_idx, std::size_t n_points, MathLib::Point3d const &min_pnt, MathLib::Point3d const &max_pnt) const
Creates the point objects based on the parameters set by the user.