Skip to content

Commit

Permalink
Merge topic 'PointCloudFilterAttributeBug'
Browse files Browse the repository at this point in the history
5a3bd06 BUG: PointCloudFilter was promoting attributes to float

Acked-by: Kitware Robot <[email protected]>
Merge-request: !2393
  • Loading branch information
lorensen authored and kwrobot committed Jan 19, 2017
2 parents 4116668 + 5a3bd06 commit f1c257e
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 2 deletions.
1 change: 1 addition & 0 deletions Filters/Points/Testing/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
UnitTestKernels.cxx,NO_VALID
TestSPHKernels.cxx,NO_VALID
PlotSPHKernels.cxx
TestPointCloudFilterArrays.cxx,NO_VALID,NO_DATA
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
RENDERING_FACTORY
Expand Down
123 changes: 123 additions & 0 deletions Filters/Points/Testing/Cxx/TestPointCloudFilterArrays.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*=========================================================================
Program: Visualization Toolkit
Module: TestPointCloudFilterArrays.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/

#include <vtkSmartPointer.h>
#include <vtkRadiusOutlierRemoval.h>

#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>

#include <vtkUnsignedCharArray.h>
#include <vtkCharArray.h>
#include <vtkUnsignedShortArray.h>
#include <vtkShortArray.h>
#include <vtkUnsignedIntArray.h>
#include <vtkIntArray.h>
#include <vtkUnsignedLongArray.h>
#include <vtkLongArray.h>

template<typename T> vtkSmartPointer<T> MakeArray (const std::string &name);

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

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

// Generate arrays of integral types
vtkSmartPointer<vtkUnsignedCharArray> uca =
MakeArray<vtkUnsignedCharArray> ("uca");
vtkSmartPointer<vtkCharArray> ca =
MakeArray<vtkCharArray> ("ca");

vtkSmartPointer<vtkUnsignedShortArray> usa =
MakeArray<vtkUnsignedShortArray> ("usa");
vtkSmartPointer<vtkShortArray> sa =
MakeArray<vtkShortArray> ("sa");

vtkSmartPointer<vtkUnsignedIntArray> uia =
MakeArray<vtkUnsignedIntArray> ("uia");
vtkSmartPointer<vtkIntArray> ia =
MakeArray<vtkIntArray> ("ia");

vtkSmartPointer<vtkUnsignedLongArray> ula =
MakeArray<vtkUnsignedLongArray> ("ula");
vtkSmartPointer<vtkLongArray> la =
MakeArray<vtkLongArray> ("la");

vtkSmartPointer<vtkPolyData> polyData =
vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);
polyData->GetPointData()->AddArray(uca);
polyData->GetPointData()->AddArray(ca);
polyData->GetPointData()->AddArray(usa);
polyData->GetPointData()->AddArray(sa);
polyData->GetPointData()->AddArray(uia);
polyData->GetPointData()->AddArray(ia);
polyData->GetPointData()->AddArray(ula);
polyData->GetPointData()->AddArray(la);

vtkSmartPointer<vtkRadiusOutlierRemoval> outlierRemoval =
vtkSmartPointer<vtkRadiusOutlierRemoval>::New();
outlierRemoval->SetInputData(polyData);
outlierRemoval->SetRadius(1.5);
outlierRemoval->SetNumberOfNeighbors(2);
outlierRemoval->Update();

vtkPointData *inPD = polyData->GetPointData();
vtkPointData *outPD = outlierRemoval->GetOutput()->GetPointData();
// Number of arrays should match
if (inPD->GetNumberOfArrays() != outPD->GetNumberOfArrays())
{
std::cout << "ERROR: Number of input arrays : " << inPD->GetNumberOfArrays()
<< " != " << outPD->GetNumberOfArrays() << std::endl;
return EXIT_FAILURE;
}
// Types should not change
int status = 0;
for (int i = 0; i < outPD->GetNumberOfArrays(); ++i)
{
vtkDataArray *outArray = outPD->GetArray(i);
vtkDataArray *inArray = inPD->GetArray(i);
if (inArray->GetDataType() != outArray->GetDataType())
{
std::cout << "ERROR: Output array: " << outArray->GetName() << ", type: " << outArray->GetDataTypeAsString()
<< " does not match "
<< "Input array: " << inArray->GetName() << ", type: " << inArray->GetDataTypeAsString()
<< std::endl;
++status;
}
}
return status == 0 ? EXIT_SUCCESS: EXIT_FAILURE;
}

template<typename T> vtkSmartPointer<T> MakeArray (const std::string &name)
{
vtkSmartPointer<T> array = vtkSmartPointer<T>::New();
array->SetName(name.c_str());
array->SetNumberOfComponents(1);
array->InsertNextValue(1);
array->InsertNextValue(2);
array->InsertNextValue(3);
return array;
}
4 changes: 2 additions & 2 deletions Filters/Points/vtkPointCloudFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

void operator() (vtkIdType ptId, vtkIdType endPtId)
Expand Down

0 comments on commit f1c257e

Please sign in to comment.