[vtkusers] vtkPointCloudFilter changes type of data arrays to float

Bill Lorensen bill.lorensen at gmail.com
Wed Jan 18 11:47:00 EST 2017


PointCloudFilter was promoting all integral arrays to float.
I am working on a patch and test.

In the meantime you could apply the following changes:
diff --git a/Filters/Points/vtkPointCloudFilter.cxx
b/Filters/Points/vtkPointCloudFilter.cxx
index d9b3b6f..63fa046 100644
--- a/Filters/Points/vtkPointCloudFilter.cxx
+++ b/Filters/Points/vtkPointCloudFilter.cxx
@@ -48,7 +48,7 @@ struct MapPoints
             vtkIdType *map, vtkPointData *inPD, vtkPointData *outPD) :
     InPoints(inPts), OutPoints(outPts), PointMap(map)
   {
-      this->Arrays.AddArrays(numOutPts, inPD, outPD);
+    this->Arrays.AddArrays(numOutPts, inPD, outPD, 0.0, false);
   }

   void operator() (vtkIdType ptId, vtkIdType endPtId)
@@ -97,7 +97,7 @@ struct MapOutliers
               vtkIdType *map, vtkPointData *inPD, vtkPointData *outPD2) :
     InPoints(inPts), OutPoints(outPts), PointMap(map)
   {
-      this->Arrays.AddArrays(numOutPts, inPD, outPD2);
+    this->Arrays.AddArrays(numOutPts, inPD, outPD2, 0.0, false);
   }


On Wed, Jan 18, 2017 at 9:50 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> 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



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list