[vtkusers] vtkPointCloudFilter changes type of data arrays to float

Bill Lorensen bill.lorensen at gmail.com
Wed Jan 18 09:50:37 EST 2017


Looks like a bug. I'll take a look today.


On Wed, Jan 18, 2017 at 5:46 AM, Sergey Alexandrov
<alexandrov88 at gmail.com> wrote:
> 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
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list