Commit 2423c239 authored by Sujin Philip's avatar Sujin Philip Committed by Kitware Robot

Merge topic 'add-ResampleWithDataset-PassArrayOptions'

32c0145a vtkResampleWithDataSet pass input arrays
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1903
parents 1cb5a963 32c0145a
Pipeline #24825 running with stage
in 93 minutes and 33 seconds
......@@ -16,6 +16,7 @@
#include "vtkResampleWithDataSet.h"
#include "vtkActor.h"
#include "vtkCellData.h"
#include "vtkCompositeDataGeometryFilter.h"
#include "vtkCompositePolyDataMapper.h"
#include "vtkCylinder.h"
......@@ -23,6 +24,7 @@
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkRandomAttributeGenerator.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
......@@ -70,6 +72,13 @@ void CreateInputDataSet(vtkMultiBlockDataSet* dataset, int numberOfBlocks)
transFilter->SetInputConnection(clipSphr->GetOutputPort());
transFilter->SetTransform(transform.GetPointer());
vtkNew<vtkRandomAttributeGenerator> randomAttrs;
randomAttrs->SetInputConnection(transFilter->GetOutputPort());
randomAttrs->GenerateAllPointDataOn();
randomAttrs->GenerateAllCellDataOn();
randomAttrs->GenerateFieldArrayOn();
randomAttrs->SetNumberOfTuples(100);
for (int i = 0; i < numberOfBlocks; ++i)
{
int blockExtent[6];
......@@ -79,10 +88,10 @@ void CreateInputDataSet(vtkMultiBlockDataSet* dataset, int numberOfBlocks)
wavelet->UpdateExtent(blockExtent);
clipCyl->SetInputData(wavelet->GetOutputDataObject(0));
transFilter->Update();
randomAttrs->Update();
vtkDataObject *block = transFilter->GetOutputDataObject(0)->NewInstance();
block->DeepCopy(transFilter->GetOutputDataObject(0));
vtkDataObject *block = randomAttrs->GetOutputDataObject(0)->NewInstance();
block->DeepCopy(randomAttrs->GetOutputDataObject(0));
dataset->SetBlock(i, block);
block->Delete();
}
......@@ -132,8 +141,45 @@ int TestResampleWithDataSet(int argc, char *argv[])
vtkNew<vtkResampleWithDataSet> resample;
resample->SetInputData(input.GetPointer());
resample->SetSourceData(source.GetPointer());
// test default output
resample->Update();
vtkMultiBlockDataSet *result = static_cast<vtkMultiBlockDataSet*>(resample->GetOutput());
vtkDataSet *block = static_cast<vtkDataSet*>(result->GetBlock(0));
if (block->GetFieldData()->GetNumberOfArrays() != 1 ||
block->GetCellData()->GetNumberOfArrays() != 1 ||
block->GetPointData()->GetNumberOfArrays() != 3)
{
std::cout << "Unexpected number of arrays in default output" << std::endl;
return !vtkTesting::FAILED;
}
// pass point and cell arrays
resample->PassCellArraysOn();
resample->PassPointArraysOn();
resample->Update();
result = static_cast<vtkMultiBlockDataSet*>(resample->GetOutput());
block = static_cast<vtkDataSet*>(result->GetBlock(0));
if (block->GetFieldData()->GetNumberOfArrays() != 1 ||
block->GetCellData()->GetNumberOfArrays() != 6 ||
block->GetPointData()->GetNumberOfArrays() != 8)
{
std::cout << "Unexpected number of arrays in output with pass cell and point arrays" << std::endl;
return !vtkTesting::FAILED;
}
// dont pass field arrays
resample->PassFieldArraysOff();
resample->Update();
result = static_cast<vtkMultiBlockDataSet*>(resample->GetOutput());
block = static_cast<vtkDataSet*>(result->GetBlock(0));
if (block->GetFieldData()->GetNumberOfArrays() != 0 ||
block->GetCellData()->GetNumberOfArrays() != 6 ||
block->GetPointData()->GetNumberOfArrays() != 8)
{
std::cout << "Unexpected number of arrays in output with pass field arrays off" << std::endl;
return !vtkTesting::FAILED;
}
// Render
vtkNew<vtkCompositeDataGeometryFilter> toPoly;
......
......@@ -142,14 +142,18 @@ void vtkProbeFilter::PassAttributeData(
int numPtArrays = input->GetPointData()->GetNumberOfArrays();
for (int i=0; i<numPtArrays; ++i)
{
output->GetPointData()->AddArray(input->GetPointData()->GetArray(i));
vtkDataArray *da = input->GetPointData()->GetArray(i);
if (!output->GetPointData()->HasArray(da->GetName()))
{
output->GetPointData()->AddArray(da);
}
}
// Set active attributes in the output to the active attributes in the input
for (int i = 0; i < vtkDataSetAttributes::NUM_ATTRIBUTES; ++i)
{
vtkAbstractArray* da = input->GetPointData()->GetAttribute(i);
if (da)
if (da && da->GetName() && !output->GetPointData()->GetAttribute(i))
{
output->GetPointData()->SetAttribute(da, i);
}
......@@ -162,14 +166,18 @@ void vtkProbeFilter::PassAttributeData(
int numCellArrays = input->GetCellData()->GetNumberOfArrays();
for (int i=0; i<numCellArrays; ++i)
{
output->GetCellData()->AddArray(input->GetCellData()->GetArray(i));
vtkDataArray *da = input->GetCellData()->GetArray(i);
if (!output->GetCellData()->HasArray(da->GetName()))
{
output->GetCellData()->AddArray(da);
}
}
// Set active attributes in the output to the active attributes in the input
for (int i = 0; i < vtkDataSetAttributes::NUM_ATTRIBUTES; ++i)
{
vtkAbstractArray* da = input->GetCellData()->GetAttribute(i);
if (da)
if (da && da->GetName() && !output->GetCellData()->GetAttribute(i))
{
output->GetCellData()->SetAttribute(da, i);
}
......
......@@ -14,6 +14,7 @@
=========================================================================*/
#include "vtkResampleWithDataSet.h"
#include "vtkCellData.h"
#include "vtkCharArray.h"
#include "vtkCompositeDataProbeFilter.h"
#include "vtkCompositeDataIterator.h"
......@@ -65,6 +66,45 @@ void vtkResampleWithDataSet::SetSourceData(vtkDataObject *input)
this->SetInputData(1, input);
}
//----------------------------------------------------------------------------
void vtkResampleWithDataSet::SetPassCellArrays(bool arg)
{
this->Prober->SetPassCellArrays(arg);
}
bool vtkResampleWithDataSet::GetPassCellArrays()
{
// work arround for Visual Studio warning C4800:
// 'int' : forcing value to bool 'true' or 'false' (performance warning)
return this->Prober->GetPassCellArrays() ? true : false;
}
void vtkResampleWithDataSet::SetPassPointArrays(bool arg)
{
this->Prober->SetPassPointArrays(arg);
}
bool vtkResampleWithDataSet::GetPassPointArrays()
{
return this->Prober->GetPassPointArrays() ? true : false;
}
void vtkResampleWithDataSet::SetPassFieldArrays(bool arg)
{
this->Prober->SetPassFieldArrays(arg);
}
bool vtkResampleWithDataSet::GetPassFieldArrays()
{
return this->Prober->GetPassFieldArrays() ? true : false;
}
//----------------------------------------------------------------------------
vtkMTimeType vtkResampleWithDataSet::GetMTime()
{
return std::max(this->Superclass::GetMTime(), this->Prober->GetMTime());
}
//-----------------------------------------------------------------------------
int vtkResampleWithDataSet::RequestUpdateExtent(vtkInformation *,
vtkInformationVector **inputVector,
......@@ -166,10 +206,11 @@ int vtkResampleWithDataSet::RequestData(vtkInformation *vtkNotUsed(request),
vtkDataObject *source = sourceInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDataObject *inDataObject = inInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDataObject *outDataObject = outInfo->Get(vtkDataObject::DATA_OBJECT());
if (inDataObject->IsA("vtkDataSet"))
{
vtkDataSet *input = vtkDataSet::SafeDownCast(inDataObject);
vtkDataSet *output = vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDataSet *output = vtkDataSet::SafeDownCast(outDataObject);
this->Prober->SetInputData(input);
this->Prober->SetSourceData(source);
......@@ -180,8 +221,7 @@ int vtkResampleWithDataSet::RequestData(vtkInformation *vtkNotUsed(request),
else if (inDataObject->IsA("vtkCompositeDataSet"))
{
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(inDataObject);
vtkCompositeDataSet *output = vtkCompositeDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkCompositeDataSet *output = vtkCompositeDataSet::SafeDownCast(outDataObject);
output->CopyStructure(input);
this->Prober->SetSourceData(source);
......
......@@ -57,6 +57,29 @@ public:
// vectors, etc. for the output points based on the point locations.
void SetSourceConnection(vtkAlgorithmOutput* algOutput);
// Description:
// Shallow copy the input cell data arrays to the output.
// Off by default.
void SetPassCellArrays(bool arg);
bool GetPassCellArrays();
vtkBooleanMacro(PassCellArrays, bool);
// Description:
// Shallow copy the input point data arrays to the output
// Off by default.
void SetPassPointArrays(bool arg);
bool GetPassPointArrays();
vtkBooleanMacro(PassPointArrays, bool);
// Description:
// Set whether to pass the field-data arrays from the Input i.e. the input
// providing the geometry to the output. On by default.
void SetPassFieldArrays(bool arg);
bool GetPassFieldArrays();
vtkBooleanMacro(PassFieldArrays, bool);
virtual vtkMTimeType GetMTime();
protected:
vtkResampleWithDataSet();
~vtkResampleWithDataSet();
......
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