Commit d6d0a46a authored by David E. DeMarle's avatar David E. DeMarle

backport masters merge blocks infrastructure for 5.6.1

This brings in VTK commit 67ec1f63 and subsequent changes
to the appendfilter over to the VTK branch that ParaView's
release branch uses in order to fix the merge blocks
filter in ParaView 5.6.x.

See paraview/paraview#18991
parent 1b16d6dc
set(Module_SRCS
vtkAppendArcLength.cxx
vtkAppendDataSets.cxx
vtkAppendFilter.cxx
vtkAppendPolyData.cxx
vtkAppendSelection.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAppendDataSets.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 "vtkAppendDataSets.h"
#include "vtkAppendFilter.h"
#include "vtkAppendPolyData.h"
#include "vtkBoundingBox.h"
#include "vtkCellData.h"
#include "vtkCell.h"
#include "vtkCleanPolyData.h"
#include "vtkDataObjectTypes.h"
#include "vtkDataSetCollection.h"
#include "vtkExecutive.h"
#include "vtkIncrementalOctreePointLocator.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkType.h"
#include "vtkUnstructuredGrid.h"
vtkStandardNewMacro(vtkAppendDataSets);
//----------------------------------------------------------------------------
vtkAppendDataSets::vtkAppendDataSets()
: MergePoints(false)
, Tolerance(0.0)
, ToleranceIsAbsolute(true)
, OutputDataSetType(VTK_UNSTRUCTURED_GRID)
, OutputPointsPrecision(DEFAULT_PRECISION)
{
}
//----------------------------------------------------------------------------
vtkAppendDataSets::~vtkAppendDataSets()
{
}
//----------------------------------------------------------------------------
int vtkAppendDataSets::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// Handle update requests
if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->RequestUpdateExtent(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
int vtkAppendDataSets::RequestDataObject(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if (!inInfo)
{
return 0;
}
if (this->OutputDataSetType != VTK_POLY_DATA &&
this->OutputDataSetType != VTK_UNSTRUCTURED_GRID)
{
vtkErrorMacro("Output type '"
<< vtkDataObjectTypes::GetClassNameFromTypeId(this->OutputDataSetType) << "' is not supported.");
return 0;
}
vtkDataObject* input = inInfo->Get(vtkDataObject::DATA_OBJECT());
if (input)
{
vtkInformation* info = outputVector->GetInformationObject(0);
vtkDataObject* output = info->Get(vtkDataObject::DATA_OBJECT());
if (!output ||
(vtkDataObjectTypes::GetTypeIdFromClassName(output->GetClassName()) != this->OutputDataSetType))
{
vtkSmartPointer<vtkDataObject> newOutput;
newOutput.TakeReference(vtkDataObjectTypes::NewDataObject(this->OutputDataSetType));
info->Set(vtkDataObject::DATA_OBJECT(), newOutput);
this->GetOutputPortInformation(0)->Set(
vtkDataObject::DATA_EXTENT_TYPE(), newOutput->GetExtentType());
}
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
// Append data sets into single unstructured grid
int vtkAppendDataSets::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the output info object
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the output
vtkPointSet* output = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkUnstructuredGrid* outputUG = vtkUnstructuredGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData* outputPD = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDebugMacro("Appending data together");
if (outputUG)
{
vtkNew<vtkAppendFilter> appender;
appender->SetOutputPointsPrecision(this->GetOutputPointsPrecision());
appender->SetMergePoints(this->GetMergePoints());
appender->SetToleranceIsAbsolute(this->GetToleranceIsAbsolute());
appender->SetTolerance(this->GetTolerance());
for (int cc = 0; cc < inputVector[0]->GetNumberOfInformationObjects(); cc++)
{
auto input = vtkDataSet::GetData(inputVector[0], cc);
appender->AddInputData(input);
}
if (appender->GetNumberOfInputConnections(0) > 0)
{
appender->Update();
outputUG->ShallowCopy(appender->GetOutput());
}
}
else if (outputPD)
{
vtkNew<vtkAppendPolyData> appender;
appender->SetOutputPointsPrecision(this->GetOutputPointsPrecision());
for (int cc = 0; cc < inputVector[0]->GetNumberOfInformationObjects(); cc++)
{
auto input = vtkPolyData::GetData(inputVector[0], cc);
if (input)
{
appender->AddInputData(input);
}
}
if (this->MergePoints)
{
if (appender->GetNumberOfInputConnections(0) > 0)
{
vtkNew<vtkCleanPolyData> cleaner;
cleaner->SetInputConnection(appender->GetOutputPort());
cleaner->PointMergingOn();
cleaner->ConvertLinesToPointsOff();
cleaner->ConvertPolysToLinesOff();
cleaner->ConvertStripsToPolysOff();
if (this->GetToleranceIsAbsolute())
{
cleaner->SetAbsoluteTolerance(this->GetTolerance());
cleaner->ToleranceIsAbsoluteOn();
}
else
{
cleaner->SetTolerance(this->GetTolerance());
cleaner->ToleranceIsAbsoluteOff();
}
cleaner->Update();
output->ShallowCopy(cleaner->GetOutput());
}
}
else
{
if (appender->GetNumberOfInputConnections(0) > 0)
{
appender->Update();
output->ShallowCopy(appender->GetOutput());
}
}
}
else
{
vtkErrorMacro("Unsupported output type.");
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkAppendDataSets::RequestUpdateExtent(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* vtkNotUsed(outputVector))
{
int numInputConnections = this->GetNumberOfInputConnections(0);
// Let downstream request a subset of connection 0, for connections >= 1
// send their WHOLE_EXTENT as UPDATE_EXTENT.
for (int idx = 1; idx < numInputConnections; ++idx)
{
vtkInformation * inputInfo = inputVector[0]->GetInformationObject(idx);
if (inputInfo->Has(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()))
{
int ext[6];
inputInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), ext);
inputInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), ext, 6);
}
}
return 1;
}
//----------------------------------------------------------------------------
int vtkAppendDataSets::FillInputPortInformation(int, vtkInformation *info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
return 1;
}
//----------------------------------------------------------------------------
void vtkAppendDataSets::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "MergePoints:" << (this->MergePoints?"On":"Off") << "\n";
os << indent << "Tolerance: " << this->Tolerance << "\n";
os << indent << "OutputDataSetType: "
<< vtkDataObjectTypes::GetClassNameFromTypeId(this->OutputDataSetType) << "\n";
os << indent << "OutputPointsPrecision: "
<< this->OutputPointsPrecision << "\n";
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAppendDataSets.h
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.
=========================================================================*/
/**
* @class vtkAppendDataSets
* @brief Appends one or more datasets together into a single output vtkPointSet.
*
* vtkAppendDataSets is a filter that appends one of more datasets into a single output
* point set. The type of the output is set with the OutputDataSetType option. Only inputs
* that can be converted to the selected output dataset type are appended to the output.
* By default, the output is vtkUnstructuredGrid, and all input types can be appended to it.
* If the OutputDataSetType is set to produce vtkPolyData, then only datasets that can be
* converted to vtkPolyData (i.e., vtkPolyData) are appended to the output.
*
* All cells are extracted and appended, but point and cell attributes (i.e., scalars,
* vectors, normals, field data, etc.) are extracted and appended only if all datasets
* have the same point and/or cell attributes available. (For example, if one dataset
* has scalars but another does not, scalars will not be appended.)
*
* @sa
* vtkAppendFilter vtkAppendPolyData
*/
#ifndef vtkAppendDataSets_h
#define vtkAppendDataSets_h
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkPointSetAlgorithm.h"
class vtkDataSet;
class vtkDataSetCollection;
class VTKFILTERSCORE_EXPORT vtkAppendDataSets : public vtkPointSetAlgorithm
{
public:
static vtkAppendDataSets *New();
vtkTypeMacro(vtkAppendDataSets, vtkPointSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
//@{
/**
* Get/Set if the filter should merge coincidental points
* Note: The filter will only merge points if the ghost cell array doesn't exist
* Defaults to Off
*/
vtkGetMacro(MergePoints, bool);
vtkSetMacro(MergePoints, bool);
vtkBooleanMacro(MergePoints, bool);
//@}
//@{
/**
* Get/Set the tolerance to use to find coincident points when `MergePoints`
* is `true`. Default is 0.0.
*
* This is simply passed on to the internal vtkLocator used to merge points.
* @sa `vtkLocator::SetTolerance`.
*/
vtkSetClampMacro(Tolerance, double, 0.0, VTK_DOUBLE_MAX);
vtkGetMacro(Tolerance, double);
//@}
//@{
/**
* Get/Set whether Tolerance is treated as an absolute or relative tolerance.
* The default is to treat it as an absolute tolerance.
*/
vtkSetMacro(ToleranceIsAbsolute, bool);
vtkGetMacro(ToleranceIsAbsolute, bool);
vtkBooleanMacro(ToleranceIsAbsolute, bool);
//@}
//@{
/**
* Get/Set the output type produced by this filter. Only input datasets compatible with the
* output type will be merged in the output. For example, if the output type is vtkPolyData, then
* blocks of type vtkImageData, vtkStructuredGrid, etc. will not be merged - only vtkPolyData
* can be merged into a vtkPolyData. On the other hand, if the output type is
* vtkUnstructuredGrid, then blocks of almost any type will be merged in the output.
* Valid values are VTK_POLY_DATA and VTK_UNSTRUCTURED_GRID defined in vtkType.h.
* Defaults to VTK_UNSTRUCTURED_GRID.
*/
vtkSetMacro(OutputDataSetType, int);
vtkGetMacro(OutputDataSetType, int);
//@}
//@{
/**
* Set/get the desired precision for the output types. See the documentation
* for the vtkAlgorithm::Precision enum for an explanation of the available
* precision settings.
*/
vtkSetClampMacro(OutputPointsPrecision, int, SINGLE_PRECISION, DEFAULT_PRECISION);
vtkGetMacro(OutputPointsPrecision, int);
//@}
/**
* see vtkAlgorithm for details
*/
int ProcessRequest(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*) override;
protected:
vtkAppendDataSets();
~vtkAppendDataSets() override;
// Usual data generation method
int RequestDataObject(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
virtual int RequestUpdateExtent(vtkInformation *,
vtkInformationVector **, vtkInformationVector *);
int FillInputPortInformation(int port, vtkInformation *info) override;
// If true we will attempt to merge points. Must also not have
// ghost cells defined.
bool MergePoints;
// Tolerance used for point merging
double Tolerance;
// If true, tolerance is multipled by the diagonal of the bounding box of the input.
bool ToleranceIsAbsolute;
// Output data set type.
int OutputDataSetType;
// Precision of output points.
int OutputPointsPrecision;
private:
vtkAppendDataSets(const vtkAppendDataSets&) = delete;
void operator=(const vtkAppendDataSets&) = delete;
// Get all input data sets that have points, cells, or both.
// Caller must delete the returned vtkDataSetCollection.
vtkDataSetCollection* GetNonEmptyInputs(vtkInformationVector ** inputVector);
};
#endif
......@@ -39,6 +39,8 @@ vtkAppendFilter::vtkAppendFilter()
this->InputList = nullptr;
this->MergePoints = 0;
this->OutputPointsPrecision = DEFAULT_PRECISION;
this->Tolerance = 0.0;
this->ToleranceIsAbsolute = true;
}
//----------------------------------------------------------------------------
......@@ -247,7 +249,15 @@ int vtkAppendFilter::RequestData(
outputBB.GetBounds(outputBounds);
ptInserter = vtkSmartPointer<vtkIncrementalOctreePointLocator>::New();
ptInserter->SetTolerance(0.0);
if (this->ToleranceIsAbsolute)
{
ptInserter->SetTolerance(this->Tolerance);
}
else
{
ptInserter->SetTolerance(this->Tolerance * outputBB.GetDiagonalLength());
}
ptInserter->InitPointInsertion(newPts, outputBounds);
}
......@@ -331,6 +341,14 @@ int vtkAppendFilter::RequestData(
ptOffset += dataSetNumPts;
}
// this filter can copy global ids except for global point ids when merging
// points (see paraview/paraview#18666).
// Note, not copying global ids is the default behavior.
if (reallyMergePoints == false)
{
output->GetPointData()->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
}
output->GetCellData()->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
// Now copy the array data
this->AppendArrays(
......@@ -416,7 +434,7 @@ void vtkAppendFilter::AppendArrays(int attributesType,
{
for (vtkIdType id=0; id < numberOfInputTuples; ++id)
{
fieldList.CopyData(inputIndex, inputData, id, outputData, offset + id);
fieldList.CopyData(inputIndex, inputData, id, outputData, globalIds[offset + id]);
}
}
else
......@@ -467,4 +485,5 @@ void vtkAppendFilter::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "MergePoints:" << (this->MergePoints?"On":"Off") << "\n";
os << indent << "OutputPointsPrecision: "
<< this->OutputPointsPrecision << "\n";
os << indent << "Tolerance: " << this->Tolerance << "\n";
}
......@@ -40,36 +40,49 @@ class VTKFILTERSCORE_EXPORT vtkAppendFilter : public vtkUnstructuredGridAlgorith
{
public:
static vtkAppendFilter *New();
vtkTypeMacro(vtkAppendFilter,vtkUnstructuredGridAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
//@{
/**
* Get any input of this filter.
*/
vtkDataSet *GetInput(int idx);
vtkDataSet *GetInput()
{return this->GetInput( 0 );}
vtkDataSet* GetInput() { return this->GetInput(0); }
//@}
//@{
/**
* Get if the filter should merge coincidental points
* Get/Set if the filter should merge coincidental points
* Note: The filter will only merge points if the ghost cell array doesn't exist
* Defaults to Off
*/
vtkGetMacro(MergePoints,vtkTypeBool);
vtkGetMacro(MergePoints, vtkTypeBool);
vtkSetMacro(MergePoints, vtkTypeBool);
vtkBooleanMacro(MergePoints, vtkTypeBool);
//@}
//@{
/**
* Set the filter to merge coincidental points.
* Note: The filter will only merge points if the ghost cell array doesn't exist
* Defaults to Off
* Get/Set the tolerance to use to find coincident points when `MergePoints`
* is `true`. Default is 0.0.
*
* This is simply passed on to the internal vtkLocator used to merge points.
* @sa `vtkLocator::SetTolerance`.
*/
vtkSetMacro(MergePoints,vtkTypeBool);
vtkSetClampMacro(Tolerance, double, 0.0, VTK_DOUBLE_MAX);
vtkGetMacro(Tolerance, double);
//@}
vtkBooleanMacro(MergePoints,vtkTypeBool);
//@{
/**
* Get/Set whether Tolerance is treated as an absolute or relative tolerance.
* The default is to treat it as an absolute tolerance.
*/
vtkSetMacro(ToleranceIsAbsolute, bool);
vtkGetMacro(ToleranceIsAbsolute, bool);
vtkBooleanMacro(ToleranceIsAbsolute, bool);
//@}
/**
* Remove a dataset from the list of data to append.
......@@ -111,6 +124,10 @@ protected:
vtkTypeBool MergePoints;
int OutputPointsPrecision;
double Tolerance;
// If true, tolerance is multipled by the diagonal of the bounding box of the input.
bool ToleranceIsAbsolute;
private:
vtkAppendFilter(const vtkAppendFilter&) = delete;
......@@ -129,5 +146,3 @@ private:
#endif
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