An update will be applied December 9th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit dc7f522b authored by Andrew Bauer's avatar Andrew Bauer
Browse files

Adding a source that can generate a variety of 1D, 2D and 3D cells

Generates linear and quadratic lines, triangles, quads, tets,
hexes, pyramids and wedges and cubic lines. Useful for testing
higher order cells.

Addresses paraview/paraview#17405
parent eb1557a1
......@@ -2,6 +2,7 @@ set(Module_SRCS
vtkArcSource.cxx
vtkArrowSource.cxx
vtkButtonSource.cxx
vtkCellTypeSource.cxx
vtkConeSource.cxx
vtkCubeSource.cxx
vtkCylinderSource.cxx
......
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestArcSource.cxx,NO_VALID
TestCellTypeSource.cxx,NO_VALID
TestConeSource.cxx,NO_VALID
TestCubeSource.cxx,NO_VALID
TestCylinderSource.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestCellTypeSource.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 <vtkCellData.h>
#include <vtkCellSizeFilter.h>
#include <vtkCellType.h>
#include <vtkCellTypeSource.h>
#include <vtkDataArray.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkUnstructuredGrid.h>
#include <cmath>
namespace
{
int CheckCells(int cellType, int blocksDimensions[3], int pointPrecision,
int expectedNumberOfPoints, int expectedNumberOfCells,
double* expectedSizeRange)
{
vtkNew<vtkCellTypeSource> cellSource;
cellSource->SetBlocksDimensions(blocksDimensions);
cellSource->SetOutputPointsPrecision(pointPrecision);
cellSource->SetCellType(cellType);
cellSource->Update();
vtkUnstructuredGrid* output = cellSource->GetOutput();
if( (pointPrecision == vtkAlgorithm::SINGLE_PRECISION &&
output->GetPoints()->GetDataType() != VTK_FLOAT) ||
(pointPrecision == vtkAlgorithm::DOUBLE_PRECISION &&
output->GetPoints()->GetDataType() != VTK_DOUBLE) )
{
cerr << "Wrong points precision\n";
return EXIT_FAILURE;
}
if(output->GetCellType(0) != cellType)
{
cerr << "Wrong cell type\n";
return EXIT_FAILURE;
}
if(output->GetNumberOfPoints() != expectedNumberOfPoints)
{
cerr << "Expected " << expectedNumberOfPoints << " points but got "
<< output->GetNumberOfPoints() << endl;
return EXIT_FAILURE;
}
if(output->GetNumberOfCells() != expectedNumberOfCells)
{
cerr << "Expected " << expectedNumberOfCells << " cells but got "
<< output->GetNumberOfCells() << endl;
return EXIT_FAILURE;
}
if(expectedSizeRange)
{
std::string arrayName = "size";
vtkNew<vtkCellSizeFilter> cellSize;
cellSize->SetInputConnection(cellSource->GetOutputPort());
cellSize->ComputeVolumeOn();
cellSize->SetArrayName(arrayName.c_str());
cellSize->Update();
output = vtkUnstructuredGrid::SafeDownCast(cellSize->GetOutput());
double sizeRange[2];
output->GetCellData()->GetArray(arrayName.c_str())->GetRange(sizeRange);
if(std::abs(sizeRange[0]-expectedSizeRange[0]) > .0001 ||
std::abs(sizeRange[1]-expectedSizeRange[1]) > .0001)
{
cerr << "Expected size range of " << expectedSizeRange[0] << " to "
<< expectedSizeRange[1] << " but got " << sizeRange[0] << " to "
<< sizeRange[1] << endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
}
int TestCellTypeSource(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
int dims[3] = {4, 5, 6};
double size[2] = {1, 1};
// test 1D cells
if(CheckCells(VTK_LINE, dims, vtkAlgorithm::SINGLE_PRECISION,
dims[0]+1, dims[0], size) == EXIT_FAILURE)
{
cerr << "Error with VTK_LINE\n";
return EXIT_FAILURE;
}
if(CheckCells(VTK_QUADRATIC_EDGE, dims, vtkAlgorithm::SINGLE_PRECISION,
dims[0]*2+1, dims[0], size) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_LINE\n";
return EXIT_FAILURE;
}
if(CheckCells(VTK_CUBIC_LINE, dims, vtkAlgorithm::SINGLE_PRECISION,
dims[0]*3+1, dims[0], size) == EXIT_FAILURE)
{
cerr << "Error with VTK_CUBIC_EDGE\n";
return EXIT_FAILURE;
}
// test 2D cells
size[0] = size[1] = .5;
if(CheckCells(VTK_TRIANGLE, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]+1)*(dims[1]+1), dims[0]*dims[1]*2, size) == EXIT_FAILURE)
{
cerr << "Error with VTK_TRIANGLE\n";
return EXIT_FAILURE;
}
if(CheckCells(VTK_QUADRATIC_TRIANGLE, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]*2+1)*(dims[1]*2+1), dims[0]*dims[1]*2, size) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_TRIANGLE\n";
return EXIT_FAILURE;
}
size[0] = size[1] = 1;
if(CheckCells(VTK_QUAD, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]+1)*(dims[1]+1), dims[0]*dims[1], size) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUAD\n";
return EXIT_FAILURE;
}
if(CheckCells(VTK_QUADRATIC_QUAD, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]*2+1)*(dims[1]*2+1)-dims[0]*dims[1],
dims[0]*dims[1], size) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_QUAD\n";
return EXIT_FAILURE;
}
// test 3D cells
size[0] = size[1] = 1./12.;
if(CheckCells(VTK_TETRA, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]+1)*(dims[1]+1)*(dims[2]+1)+dims[0]*dims[1]*dims[2],
dims[0]*dims[1]*dims[2]*12, size) == EXIT_FAILURE)
{
cerr << "Error with VTK_TETRA\n";
return EXIT_FAILURE;
}
if(CheckCells(VTK_QUADRATIC_TETRA, dims, vtkAlgorithm::DOUBLE_PRECISION, 2247,
dims[0]*dims[1]*dims[2]*12, size) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_TETRA\n";
return EXIT_FAILURE;
}
size[0] = size[1] = 1;
if(CheckCells(VTK_HEXAHEDRON, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]+1)*(dims[1]+1)*(dims[2]+1), dims[0]*dims[1]*dims[2], size) == EXIT_FAILURE)
{
cerr << "Error with VTK_HEXAHEDRON\n";
return EXIT_FAILURE;
}
// can't currently properly compute quadratic hex volumes
if(CheckCells(VTK_QUADRATIC_HEXAHEDRON, dims, vtkAlgorithm::DOUBLE_PRECISION, 733,
dims[0]*dims[1]*dims[2], nullptr) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_HEXAHEDRON\n";
return EXIT_FAILURE;
}
size[0] = size[1] = .5;
if(CheckCells(VTK_WEDGE, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]+1)*(dims[1]+1)*(dims[2]+1), dims[0]*dims[1]*dims[2]*2, size) == EXIT_FAILURE)
{
cerr << "Error with VTK_WEDGE\n";
return EXIT_FAILURE;
}
// can't currently properly compute quadratic wedge volumes
if(CheckCells(VTK_QUADRATIC_WEDGE, dims, vtkAlgorithm::DOUBLE_PRECISION,
733+dims[0]*dims[1]*(dims[2]+1), dims[0]*dims[1]*dims[2]*2, nullptr) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_WEDGE\n";
return EXIT_FAILURE;
}
size[0] = size[1] = 1./6.;
if(CheckCells(VTK_PYRAMID, dims, vtkAlgorithm::DOUBLE_PRECISION,
(dims[0]+1)*(dims[1]+1)*(dims[2]+1)+dims[0]*dims[1]*dims[2],
dims[0]*dims[1]*dims[2]*6, size) == EXIT_FAILURE)
{
cerr << "Error with VTK_PYRAMID\n";
return EXIT_FAILURE;
}
// can't currently properly compute quadratic pyramid volumes
if(CheckCells(VTK_QUADRATIC_PYRAMID, dims, vtkAlgorithm::DOUBLE_PRECISION,
733+9*dims[0]*dims[1]*dims[2],
dims[0]*dims[1]*dims[2]*6, nullptr) == EXIT_FAILURE)
{
cerr << "Error with VTK_QUADRATIC_PYRAMID\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -7,6 +7,7 @@ vtk_module(vtkFiltersSources
vtkInteractionStyle
vtkRendering${VTK_RENDERING_BACKEND}
vtkFiltersModeling
vtkFiltersVerdict
vtkIOXML
vtkIOParallel
KIT
......@@ -20,4 +21,4 @@ vtk_module(vtkFiltersSources
vtkCommonTransforms
vtkFiltersCore
vtkFiltersGeneral
)
\ No newline at end of file
)
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCellTypeSource.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 vtkCellTypeSource
* @brief Create cells of a given type
*
* vtkCellTypeSource is a source object that creates cells of the given
* input type. BlocksDimensions specifies the number of cell "blocks" in each
* direction. A cell block may be divided into multiple cells based on
* the chosen cell type (e.g. 6 pyramid cells make up a single cell block).
* If a 1D cell is selected then only the first dimension is
* used to specify how many cells are generated. If a 2D cell is
* selected then only the first and second dimensions are used to
* determine how many cells are created. The source respects pieces.
*/
#ifndef vtkCellTypeSource_h
#define vtkCellTypeSource_h
#include "vtkFiltersSourcesModule.h" // For export macro
#include "vtkUnstructuredGridAlgorithm.h"
class VTKFILTERSSOURCES_EXPORT vtkCellTypeSource : public vtkUnstructuredGridAlgorithm
{
public:
//@{
/**
* Standard methods for instantiation, obtaining type and printing instance values.
*/
static vtkCellTypeSource *New();
vtkTypeMacro(vtkCellTypeSource,vtkUnstructuredGridAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
//@}
//@{
/**
* Set/Get the type of cells to be generated.
*/
void SetCellType(int cellType);
vtkGetMacro(CellType, int);
//@}
//@{
/**
* Get the dimension of the cell blocks to be generated
*/
int GetCellDimension();
//@}
//@{
/**
* Set/get the desired precision for the output points.
* vtkAlgorithm::SINGLE_PRECISION - Output single-precision floating point.
* vtkAlgorithm::DOUBLE_PRECISION - Output double-precision floating point.
*/
vtkSetMacro(OutputPointsPrecision,int);
vtkGetMacro(OutputPointsPrecision,int);
//@}
//@{
/**
* Set the number of cells in each direction. If a 1D cell type is
* selected then only the first dimension is used and if a 2D cell
* type is selected then the first and second dimensions are used.
* Default is (1, 1, 1), which results in a single block of cells.
*/
void SetBlocksDimensions(int*);
void SetBlocksDimensions(int, int, int);
vtkGetVector3Macro(BlocksDimensions, int);
//@}
protected:
vtkCellTypeSource();
~vtkCellTypeSource() VTK_OVERRIDE {}
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) VTK_OVERRIDE;
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) VTK_OVERRIDE;
void GenerateTriangles(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuads(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuadraticTriangles(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuadraticQuads(vtkUnstructuredGrid*, int extent[6]);
void GenerateTetras(vtkUnstructuredGrid*, int extent[6]);
void GenerateHexahedron(vtkUnstructuredGrid*, int extent[6]);
void GenerateWedges(vtkUnstructuredGrid*, int extent[6]);
void GeneratePyramids(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuadraticTetras(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuadraticHexahedron(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuadraticWedges(vtkUnstructuredGrid*, int extent[6]);
void GenerateQuadraticPyramids(vtkUnstructuredGrid*, int extent[6]);
int BlocksDimensions[3];
int CellType;
int OutputPointsPrecision;
private:
vtkCellTypeSource(const vtkCellTypeSource&) VTK_DELETE_FUNCTION;
void operator=(const vtkCellTypeSource&) VTK_DELETE_FUNCTION;
};
#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