[vtkusers] vtkPointCloudFilter changes type of data arrays to float

Sergey Alexandrov alexandrov88 at gmail.com
Wed Jan 18 05:46:46 EST 2017


Hey,

I was writing a custom point cloud filtering algorithm and came across the
vtkPointCloudFilter class,
which looks like a convenient base for this kind of filter. However, in my
opinion it behaves strangely
when it comes to the handling of data arrays bundled with the points. The
documentation says that
"The filter copies point attributes from input to output consistent with
the filtering operation", and
indeed it does, but while copying it changes the type of the attribute
arrays, everything becomes a
float! Here is a small example that uses vtkRadiusOutlierRemoval (derived
from vtkPointCloudFilter).
I create several points with an unsigned char attribute, and pass it
through the filter.


#include <iostream>

#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkSmartPointer.h>
#include <vtkUnsignedCharArray.h>
#include <vtkRadiusOutlierRemoval.h>

int main(int argc, const char** argv)
{
  const double pt1[3] = { 0, 0, 0};
  const double pt2[3] = { 1, 0, 0};
  const double pt3[3] = { 2, 0, 0};

  auto points = vtkSmartPointer<vtkPoints>::New();
  points->SetDataTypeToDouble();
  points->InsertNextPoint(pt1);
  points->InsertNextPoint(pt2);
  points->InsertNextPoint(pt3);

  auto labels = vtkSmartPointer<vtkUnsignedCharArray>::New();
  labels->SetName("label");
  labels->SetNumberOfComponents(1);
  labels->InsertNextValue(1);
  labels->InsertNextValue(2);
  labels->InsertNextValue(3);

  auto poly_data = vtkSmartPointer<vtkPolyData>::New();
  poly_data->SetPoints(points);
  poly_data->GetPointData()->AddArray(labels);

  auto outlier_removal = vtkSmartPointer<vtkRadiusOutlierRemoval>::New();
  outlier_removal->SetInputData(poly_data);
  outlier_removal->SetRadius(1.5);
  outlier_removal->SetNumberOfNeighbors(2);
  outlier_removal->Update();

  auto output = outlier_removal->GetOutputDataObject(0);
  auto attributes = output->GetAttributes(0);

  std::cout << "Output attributes: " << attributes->GetArrayName(0) << ",
type: " << attributes->GetArray(0)->GetDataTypeAsString() << std::endl;

  return 0;
}


This example prints

Output attributes: label, type: float


So what happens is that the "label" attribute, that was originally of type
unsigned char, becomes a
float attribute in the output of the filter.

It this behavior a bug or a feature? Or maybe I am missing a flag somewhere
which controls this
behavior?

Cheers,
Sergey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170118/d093a10a/attachment.html>


More information about the vtkusers mailing list