Commit 92d005d2 authored by Andrew Bauer's avatar Andrew Bauer

Adding option to vtkCellSizeFilter to sum cell sizes over the dataset.

Summed cell sizes are returned in field data and this works for composite
datasets as well. Also adding an option to make the vtkCellSizeFilter only
compute cell sizes for the highest dimension cells in the vtkDataSet so
that for composite datasets that desired cell sizes are computed.
Also getting rid of some compiler warnings in vtkPUnstructuredGridConnectivity.

Addresses paraview/paraview#10433.
parent c94d5bb3
......@@ -798,7 +798,7 @@ void vtkPUnstructuredGridConnectivity::FillGhostZoneCells(
#ifndef NDEBUG
assert("pre: numtuples mismatch!" &&
(numGhostCells==ghostArray->GetNumberOfTuples()));
(numGhostCells==static_cast<unsigned int>(ghostArray->GetNumberOfTuples())));
#endif
vtkDataArray* targetArray = CD->GetArray( ghostArray->GetName() );
......@@ -849,7 +849,7 @@ void vtkPUnstructuredGridConnectivity::FillGhostZoneNodes(
#ifndef NDEBUG
assert("pre: numtuples mismatch!" &&
(numGhostNodes==ghostArray->GetNumberOfTuples()));
(numGhostNodes==static_cast<unsigned int>(ghostArray->GetNumberOfTuples())));
#endif
vtkDataArray* targetArray = PD->GetArray( ghostArray->GetName() );
......@@ -2007,7 +2007,7 @@ void vtkPUnstructuredGridConnectivity::DeSerializeUnstructuredGrid(
double* nodes = static_cast<double*>(pnts->GetVoidPointer(0));
N = 3*numPoints;
assert( N==3*numPoints );
assert( N==static_cast<unsigned int>(3*numPoints) );
bytestream.Pop(nodes,N);
g->SetPoints( pnts );
......
set(Module_SRCS
vtkPCellSizeFilter.cxx
)
vtk_module_library(vtkFiltersParallelVerdict ${Module_SRCS})
include(vtkMPI)
set(PCellSizeFilter_NUMPROCS 2)
vtk_add_test_mpi(${vtk-module}CxxTests-MPI tests PCellSizeFilter.cxx,TESTING_DATA,NO_VALID)
vtk_test_mpi_executable(${vtk-module}CxxTests-MPI tests
PCellSizeFilter.cxx)
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkMPIController.h"
#include "vtkNew.h"
#include "vtkPCellSizeFilter.h"
#include "vtkTestUtilities.h"
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridReader.h"
int PCellSizeFilter( int argc, char* argv[] )
{
vtkMPIController* contr = vtkMPIController::New();
contr->Initialize(&argc, &argv);
contr->SetGlobalController(contr);
contr->CreateOutputWindow();
vtkNew<vtkUnstructuredGridReader> reader;
vtkNew<vtkPCellSizeFilter> filter;
char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/uGridEx.vtk");
reader->SetFileName( fname );
delete [] fname;
filter->SetInputConnection( reader->GetOutputPort() );
filter->ComputeSumOn();
filter->Update();
vtkDoubleArray* sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetCellData()->GetArray("size"));
if (!sizes)
{
vtkGenericWarningMacro("Cannot find expected array output ('size') from vtkPCellSizeFilter");
return EXIT_FAILURE;
}
// types are hex, hex, tet, tet, polygon, triangle-strip, quad, triangle,
// triangle, line, line, vertex
double correctValues[12] = {1, 1, .16667, .16667, 2, 2, 1, .5, .5, 1, 1, 1};
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (fabs(sizes->GetValue(i)-correctValues[i]) > .0001)
{
vtkGenericWarningMacro("Wrong size for cell " << i);
return EXIT_FAILURE;
}
}
double correctSumValues[4] = {
correctValues[11], correctValues[10]+correctValues[9],
correctValues[8]+correctValues[7]+correctValues[6]+correctValues[5]+correctValues[4],
correctValues[3]+correctValues[2]+correctValues[1]+correctValues[0] };
// each process is reading in so we multiply the serial values by the number of processes for the sum
int numProcs = contr->GetNumberOfProcesses();
for (int i=0;i<4;i++)
{
correctSumValues[i] *= numProcs;
}
sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetFieldData()->GetArray("size"));
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (fabs(sizes->GetValue(i)-correctSumValues[i]) > .0001)
{
vtkGenericWarningMacro("Wrong size sum for dimension " << i);
return EXIT_FAILURE;
}
}
// only compute for the highest dimension cells (e.g. 3D cells)
filter->ComputeSumOff();
filter->ComputeHighestDimensionOn();
filter->Update();
sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetCellData()->GetArray("size"));
for (int i=4;i<12;i++)
{
correctValues[i] = 0.;
}
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (fabs(sizes->GetValue(i)-correctValues[i]) > .0001)
{
if (i<4)
{
vtkGenericWarningMacro("Wrong size for volumetric cell " << i);
}
else
{
vtkGenericWarningMacro("Should be skipping size computation for non-3D cell "
<< i << " but did not");
}
return EXIT_FAILURE;
}
}
if (vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetFieldData()->GetArray("size"))
{
vtkGenericWarningMacro("Should not be computing sum of sizes but it is being done");
return EXIT_FAILURE;
}
const char name[] = "mysize";
filter->SetArrayName(name);
filter->ComputeHighestDimensionOff();
filter->ComputePointOff();
filter->ComputeLengthOff();
filter->ComputeAreaOff();
filter->ComputeVolumeOff();
filter->Update();
sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetCellData()->GetArray(name));
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (sizes->GetValue(i) )
{
vtkGenericWarningMacro("Should be skipping size computation for cell "<<i<<" but did not");
return EXIT_FAILURE;
}
}
contr->Finalize();
contr->Delete();
return EXIT_SUCCESS;
}
vtk_module(vtkFiltersParallelVerdict
GROUPS
MPI
TEST_DEPENDS
vtkParallelMPI
vtkIOLegacy
vtkTestingCore
KIT
vtkParallel
DEPENDS
vtkFiltersVerdict
vtkParallelCore
)
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPCellSizeFilter.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 "vtkPCellSizeFilter.h"
#include "vtkCommunicator.h"
#include "vtkDoubleArray.h"
#include "vtkMultiProcessController.h"
vtkStandardNewMacro(vtkPCellSizeFilter);
//-----------------------------------------------------------------------------
vtkPCellSizeFilter::vtkPCellSizeFilter()
{
}
//-----------------------------------------------------------------------------
vtkPCellSizeFilter::~vtkPCellSizeFilter()
{
}
//-----------------------------------------------------------------------------
void vtkPCellSizeFilter::ComputeGlobalSum(vtkDoubleArray* sum)
{
vtkMultiProcessController* controller = vtkMultiProcessController::GetGlobalController();
if (controller->GetNumberOfProcesses() > 1)
{
double localSum[4];
for (int i=0;i<4;i++)
{
localSum[i] = sum->GetValue(i);
}
double globalSum[4];
controller->AllReduce(localSum, globalSum, 4, vtkCommunicator::SUM_OP);
for (int i=0;i<4;i++)
{
sum->SetValue(i, globalSum[i]);
}
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPCellSizeFilter.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 vtkPCellSizeFilter
* @brief Computes cell sizes in parallel.
*
* Computes the cell sizes for all types of cells in parallel in VTK. For
* triangles, quads, tets and hexes the static methods in vtkMeshQuality are
* used. This is done through Verdict for higher accuracy.
* Other cell types are individually done analytically where possible
* and breaking into triangles or tets when not possible. When cells are
* broken into triangles or tets the accuracy may be diminished. By default
* all sizes are computed but point, length, area and volumetric cells
* can each be optionally ignored. For dimensions of cells that do not
* have their size computed, a value of 0 will be given. For cells that
* should have their size computed but can't, the filter will return -1.
*/
#ifndef vtkPCellSizeFilter_h
#define vtkPCellSizeFilter_h
#include "vtkFiltersParallelVerdictModule.h" // For export macro
#include "vtkCellSizeFilter.h"
class VTKFILTERSPARALLELVERDICT_EXPORT vtkPCellSizeFilter : public vtkCellSizeFilter
{
public:
vtkTypeMacro(vtkPCellSizeFilter, vtkCellSizeFilter);
static vtkPCellSizeFilter* New();
protected:
vtkPCellSizeFilter();
~vtkPCellSizeFilter() VTK_OVERRIDE;
//@{
/**
* Method to compute the global sum information.
*/
virtual void ComputeGlobalSum(vtkDoubleArray*) VTK_OVERRIDE;
//@}
private:
vtkPCellSizeFilter(const vtkPCellSizeFilter&) VTK_DELETE_FUNCTION;
void operator=(const vtkPCellSizeFilter&) VTK_DELETE_FUNCTION;
};
#endif
......@@ -15,11 +15,11 @@ int CellSizeFilter( int argc, char* argv[] )
reader->SetFileName( fname );
delete [] fname;
filter->SetInputConnection( reader->GetOutputPort() );
filter->ComputeSumOn();
filter->Update();
vtkDoubleArray* sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())
->GetCellData()->GetArray("size"));
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetCellData()->GetArray("size"));
if (!sizes)
{
......@@ -37,21 +37,71 @@ int CellSizeFilter( int argc, char* argv[] )
return EXIT_FAILURE;
}
}
double correctSumValues[4] = {
correctValues[11], correctValues[10]+correctValues[9],
correctValues[8]+correctValues[7]+correctValues[6]+correctValues[5]+correctValues[4],
correctValues[3]+correctValues[2]+correctValues[1]+correctValues[0] };
sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetFieldData()->GetArray("size"));
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (fabs(sizes->GetValue(i)-correctSumValues[i]) > .0001)
{
vtkGenericWarningMacro("Wrong size sum for dimension " << i);
return EXIT_FAILURE;
}
}
// only compute for the highest dimension cells (e.g. 3D cells)
filter->ComputeSumOff();
filter->ComputeHighestDimensionOn();
filter->Update();
sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetCellData()->GetArray("size"));
for (int i=4;i<12;i++)
{
correctValues[i] = 0.;
}
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (fabs(sizes->GetValue(i)-correctValues[i]) > .0001)
{
if (i<4)
{
vtkGenericWarningMacro("Wrong size for volumetric cell " << i);
}
else
{
vtkGenericWarningMacro("Should be skipping size computation for non-3D cell "
<< i << " but did not");
}
return EXIT_FAILURE;
}
}
if (vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetFieldData()->GetArray("size"))
{
vtkGenericWarningMacro("Should not be computing sum of sizes but it is being done");
return EXIT_FAILURE;
}
const char name[] = "mysize";
filter->SetArrayName(name);
filter->ComputeHighestDimensionOff();
filter->ComputePointOff();
filter->ComputeLengthOff();
filter->ComputeAreaOff();
filter->ComputeVolumeOff();
filter->Update();
sizes = vtkDoubleArray::SafeDownCast(
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())
->GetCellData()->GetArray("size"));
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput())->GetCellData()->GetArray(name));
for (vtkIdType i=0;i<sizes->GetNumberOfTuples();i++)
{
if (sizes->GetValue(i) )
{
vtkGenericWarningMacro("Should be skipping size computation for cell "
<< i << " but did not");
vtkGenericWarningMacro("Should be skipping size computation for cell "<<i<<" but did not");
return EXIT_FAILURE;
}
}
......
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include "vtkPassInputTypeAlgorithm.h"
class vtkDataSet;
class vtkDoubleArray;
class vtkIdList;
class vtkImageData;
class vtkPointSet;
......@@ -50,6 +51,7 @@ public:
/**
* Specify whether or not to compute sizes for vertex and polyvertex
* cells. The computed value is the number of points in the cell.
* This option is enabled by default.
*/
vtkSetMacro(ComputePoint, bool);
vtkGetMacro(ComputePoint, bool);
......@@ -60,6 +62,7 @@ public:
/**
* Specify whether or not to compute sizes for 1D cells
* cells. The computed value is the length of the cell.
* This option is enabled by default.
*/
vtkSetMacro(ComputeLength, bool);
vtkGetMacro(ComputeLength, bool);
......@@ -70,6 +73,7 @@ public:
/**
* Specify whether or not to compute sizes for 2D cells
* cells. The computed value is the area of the cell.
* This option is enabled by default.
*/
vtkSetMacro(ComputeArea, bool);
vtkGetMacro(ComputeArea, bool);
......@@ -80,12 +84,37 @@ public:
/**
* Specify whether or not to compute sizes for 3D cells
* cells. The computed value is the volume of the cell.
* This option is enabled by default.
*/
vtkSetMacro(ComputeVolume, bool);
vtkGetMacro(ComputeVolume, bool);
vtkBooleanMacro(ComputeVolume, bool);
//@}
//@{
/**
* Specify to compute sizes only for highest dimension cells in
* a vtkDataSet. If the input dataset is a composite dataset the
* highest cell dimension is computed individually for each leaf.
* If this option is enabled then the ComputePoint, ComputeLength,
* ComputeArea and ComputeVolume options are ignored. This option
* is disabled by default.
*/
vtkSetMacro(ComputeHighestDimension, bool);
vtkGetMacro(ComputeHighestDimension, bool);
vtkBooleanMacro(ComputeHighestDimension, bool);
//@}
//@{
/**
* Specify whether to sum the computed sizes and put the result in
* a field data array. This option is disabled by default.
*/
vtkSetMacro(ComputeSum, bool);
vtkGetMacro(ComputeSum, bool);
vtkBooleanMacro(ComputeSum, bool);
//@}
//@{
/**
* Set/Get the name of the computed array. Default name is "size".
......@@ -96,13 +125,20 @@ public:
protected:
vtkCellSizeFilter();
~vtkCellSizeFilter() override;
~vtkCellSizeFilter() VTK_OVERRIDE;
virtual int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) VTK_OVERRIDE;
bool ComputeDataSet(vtkDataSet* input, vtkDataSet* output, vtkDoubleArray* sum);
void IntegrateImageData(vtkImageData* input, vtkImageData* output);
void IntegrateImageData(vtkImageData* input, vtkImageData* output, vtkDoubleArray* sum);
void ExecuteBlock(vtkDataSet* input, vtkDataSet* output, vtkDoubleArray* sum);
//@{
/**
* Specify whether to sum the computed sizes and put the result in
* a field data array. This option is disabled by default.
*/
double IntegratePolyLine(vtkDataSet* input, vtkIdList* cellPtIds);
double IntegratePolygon(vtkPointSet* input, vtkIdList* cellPtIds);
double IntegrateTriangleStrip(vtkPointSet* input, vtkIdList* cellPtIds);
......@@ -111,17 +147,25 @@ protected:
double IntegrateGeneral1DCell(vtkDataSet* input, vtkIdList* cellPtIds);
double IntegrateGeneral2DCell(vtkPointSet* input, vtkIdList* cellPtIds);
double IntegrateGeneral3DCell(vtkPointSet* input, vtkIdList* cellPtIds);
//@}
//@{
/**
* Method to compute the global sum information. For serial operation this is a no-op.
*/
virtual void ComputeGlobalSum(vtkDoubleArray*) {};
//@}
private:
vtkCellSizeFilter(const vtkCellSizeFilter&) VTK_DELETE_FUNCTION;
void operator=(const vtkCellSizeFilter&) VTK_DELETE_FUNCTION;
void ExecuteBlock(vtkDataSet* input, vtkDataSet* output);
bool ComputePoint;
bool ComputeLength;
bool ComputeArea;
bool ComputeVolume;
bool ComputeHighestDimension;
bool ComputeSum;
char* ArrayName;
};
......
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