46 vtkInformationVector** inputVector,
47 vtkInformationVector* outputVector)
49 vtkDebugMacro(<<
"Executing VtkImageDataToPointCloudFilter");
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()));
58 if (input->GetScalarSize() !=
sizeof(
float))
61 "Existing data does not have float-type and cannot be processed. "
62 "Aborting filter process...");
65 float* pixvals =
static_cast<float*
>(input->GetScalarPointer());
66 int const n_comp = input->GetNumberOfScalarComponents();
69 vtkDebugMacro(
"Error reading number of components.");
74 "RGB colours detected. Using only first channel for computation.");
77 vtkIdType
const n_points = input->GetNumberOfPoints();
80 vtkDebugMacro(
"No data found!");
85 input->GetSpacing(spacing);
90 vtkPointData* input_data = input->GetPointData();
91 input_data->GetArray(0)->GetRange(range);
96 std::vector<vtkIdType> density;
97 density.reserve(n_points);
98 for (vtkIdType i = 0; i < n_points; ++i)
101 if (n_comp == 2 || n_comp == 4)
103 if (pixvals[(i + 1) * n_comp - 1] < 0.00000001f)
105 density.push_back(0);
109 double const val(pixvals[i * n_comp]);
111 std::size_t
const pnts_per_cell =
113 density.push_back(
static_cast<vtkIdType
>(
114 std::floor(pnts_per_cell * GetPointScaleFactor())));
119 std::accumulate(density.begin(), density.end(), vtkIdType{0});
120 vtkSmartPointer<vtkPoints> new_points = vtkSmartPointer<vtkPoints>::New();
121 new_points->SetNumberOfPoints(sum);
122 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
123 cells->Allocate(sum);
124 vtkSmartPointer<vtkDoubleArray> intensity =
125 vtkSmartPointer<vtkDoubleArray>::New();
126 intensity->Allocate(sum);
127 intensity->SetName(
"Intensity");
128 double const half_cellsize(spacing[0] / 2.0);
129 std::size_t pnt_idx(0);
130 for (std::size_t i = 0; i < static_cast<std::size_t>(n_points); ++i)
137 input->GetPoint(i, p);
140 {p[0] - half_cellsize, p[1] - half_cellsize,
MinHeight}}};
142 {p[0] + half_cellsize, p[1] + half_cellsize,
MaxHeight}}};
143 createPoints(new_points, cells, pnt_idx, density[i], min_pnt, max_pnt);
144 for (vtkIdType j = 0; j < density[i]; ++j)
146 intensity->InsertValue(pnt_idx + j, pixvals[i * n_comp]);
148 pnt_idx += density[i];
151 output->SetPoints(new_points);
152 output->SetVerts(cells);
153 output->GetPointData()->AddArray(intensity);
154 output->GetPointData()->SetActiveAttribute(
"Intensity",
155 vtkDataSetAttributes::SCALARS);
158 vtkDebugMacro(<<
"Created " << new_points->GetNumberOfPoints()
164 vtkSmartPointer<vtkPoints>& points,
165 vtkSmartPointer<vtkCellArray>& cells,
167 std::size_t n_points,
171 for (std::size_t i = 0; i < n_points; ++i)
177 points->SetPoint(pnt_idx + i, p);
178 cells->InsertNextCell(1);
179 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.