Commit 1d9ed333 authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot

Merge topic '17457-transform-pass-tcoords'

4676742e vtkTransformFilter: set attributes in output
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: David E. DeMarle's avatarDavid E. DeMarle <dave.demarle@kitware.com>
Acked-by: Utkarsh Ayachit's avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !4996
parents 2d67238f 4676742e
......@@ -13,7 +13,9 @@
=========================================================================*/
#include <vtkFloatArray.h>
#include <vtkMinimalStandardRandomSequence.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkTransform.h>
......@@ -29,10 +31,12 @@ void InitializePointSet(vtkPointSet *pointSet, int dataType)
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
if(dataType == VTK_DOUBLE)
const int numPoints = 4;
if (dataType == VTK_DOUBLE)
{
points->SetDataType(VTK_DOUBLE);
for(unsigned int i = 0; i < 4; ++i)
for(unsigned int i = 0; i < numPoints; ++i)
{
double point[3];
for(unsigned int j = 0; j < 3; ++j)
......@@ -46,7 +50,7 @@ void InitializePointSet(vtkPointSet *pointSet, int dataType)
else
{
points->SetDataType(VTK_FLOAT);
for(unsigned int i = 0; i < 4; ++i)
for(unsigned int i = 0; i < numPoints; ++i)
{
float point[3];
for(unsigned int j = 0; j < 3; ++j)
......@@ -58,6 +62,15 @@ void InitializePointSet(vtkPointSet *pointSet, int dataType)
}
}
// Add texture coordinates. Values don't matter, we just want to make sure
// they are passed through the transform filter.
vtkSmartPointer<vtkFloatArray> tcoords = vtkSmartPointer<vtkFloatArray>::New();
tcoords->SetNumberOfComponents(2);
tcoords->SetNumberOfTuples(numPoints);
tcoords->FillComponent(0, 0.0);
tcoords->FillComponent(1, 1.0);
pointSet->GetPointData()->SetTCoords(tcoords);
points->Squeeze();
pointSet->SetPoints(points);
}
......@@ -78,7 +91,7 @@ void InitializeTransform(vtkTransform *transform)
}
}
int TransformPointSet(int dataType, int outputPointsPrecision)
vtkSmartPointer<vtkPointSet> TransformPointSet(int dataType, int outputPointsPrecision)
{
vtkSmartPointer<vtkPointSet> inputPointSet
= vtkSmartPointer<vtkPolyData>::New();
......@@ -90,6 +103,7 @@ int TransformPointSet(int dataType, int outputPointsPrecision)
vtkSmartPointer<vtkTransformFilter> transformFilter
= vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetTransformAllInputVectors(true);
transformFilter->SetOutputPointsPrecision(outputPointsPrecision);
transformFilter->SetTransform(transform);
......@@ -100,49 +114,55 @@ int TransformPointSet(int dataType, int outputPointsPrecision)
vtkSmartPointer<vtkPointSet> outputPointSet = transformFilter->GetOutput();
vtkSmartPointer<vtkPoints> points = outputPointSet->GetPoints();
return points->GetDataType();
return outputPointSet;
}
int TestTransformFilter(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
int dataType = TransformPointSet(VTK_FLOAT, vtkAlgorithm::DEFAULT_PRECISION);
vtkSmartPointer<vtkPointSet> pointSet = TransformPointSet(VTK_FLOAT, vtkAlgorithm::DEFAULT_PRECISION);
if(dataType != VTK_FLOAT)
if (pointSet->GetPoints()->GetDataType() != VTK_FLOAT)
{
return EXIT_FAILURE;
}
dataType = TransformPointSet(VTK_DOUBLE, vtkAlgorithm::DEFAULT_PRECISION);
pointSet = TransformPointSet(VTK_DOUBLE, vtkAlgorithm::DEFAULT_PRECISION);
if(dataType != VTK_DOUBLE)
if (pointSet->GetPoints()->GetDataType() != VTK_DOUBLE)
{
return EXIT_FAILURE;
}
dataType = TransformPointSet(VTK_FLOAT, vtkAlgorithm::SINGLE_PRECISION);
pointSet = TransformPointSet(VTK_FLOAT, vtkAlgorithm::SINGLE_PRECISION);
if (pointSet->GetPoints()->GetDataType() != VTK_FLOAT)
{
return EXIT_FAILURE;
}
if(dataType != VTK_FLOAT)
if (pointSet->GetPointData()->GetTCoords() == nullptr)
{
std::cerr << "TCoords were not passed through vtkTransformFilter." << std::endl;
return EXIT_FAILURE;
}
dataType = TransformPointSet(VTK_DOUBLE, vtkAlgorithm::SINGLE_PRECISION);
pointSet = TransformPointSet(VTK_DOUBLE, vtkAlgorithm::SINGLE_PRECISION);
if(dataType != VTK_FLOAT)
if (pointSet->GetPoints()->GetDataType() != VTK_FLOAT)
{
return EXIT_FAILURE;
}
dataType = TransformPointSet(VTK_FLOAT, vtkAlgorithm::DOUBLE_PRECISION);
pointSet = TransformPointSet(VTK_FLOAT, vtkAlgorithm::DOUBLE_PRECISION);
if(dataType != VTK_DOUBLE)
if (pointSet->GetPoints()->GetDataType() != VTK_DOUBLE)
{
return EXIT_FAILURE;
}
dataType = TransformPointSet(VTK_DOUBLE, vtkAlgorithm::DOUBLE_PRECISION);
pointSet = TransformPointSet(VTK_DOUBLE, vtkAlgorithm::DOUBLE_PRECISION);
if(dataType != VTK_DOUBLE)
if (pointSet->GetPoints()->GetDataType() != VTK_DOUBLE)
{
return EXIT_FAILURE;
}
......
......@@ -319,6 +319,13 @@ int vtkTransformFilter::RequestData(
if(!outPD->GetArray(pd->GetAbstractArray(i)->GetName()))
{
outPD->AddArray(pd->GetAbstractArray(i));
int attributeType = pd->IsArrayAnAttribute(i);
if (attributeType >= 0 &&
attributeType != vtkDataSetAttributes::VECTORS &&
attributeType != vtkDataSetAttributes::NORMALS)
{
outPD->SetAttribute(pd->GetAbstractArray(i), attributeType);
}
}
}
for (int i = 0; i < cd->GetNumberOfArrays(); i++)
......@@ -326,6 +333,13 @@ int vtkTransformFilter::RequestData(
if(!outCD->GetArray(cd->GetAbstractArray(i)->GetName()))
{
outCD->AddArray(cd->GetAbstractArray(i));
int attributeType = pd->IsArrayAnAttribute(i);
if (attributeType >= 0 &&
attributeType != vtkDataSetAttributes::VECTORS &&
attributeType != vtkDataSetAttributes::NORMALS)
{
outPD->SetAttribute(pd->GetAbstractArray(i), attributeType);
}
}
}
//TODO does order matters ?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment