Commit 8cf19f54 authored by David Lonie's avatar David Lonie Committed by Kitware Robot
Browse files

Merge topic 'count_cell_verts'

1d9ed078

 Add filter to count cell vertices.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarDavid Lonie <david.lonie@kitware.com>
Merge-request: !1890
parents 281b09c1 1d9ed078
Pipeline #24006 failed with stage
in 0 seconds
......@@ -18,6 +18,7 @@ set(Module_SRCS
vtkCoincidentPoints.cxx
vtkContourTriangulator.cxx
vtkCountFaces.cxx
vtkCountVertices.cxx
vtkCursor2D.cxx
vtkCursor3D.cxx
vtkCurvatures.cxx
......
......@@ -22,6 +22,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestContourTriangulator.cxx
TestContourTriangulatorMarching.cxx
TestCountFaces.cxx,NO_VALID
TestCountVertices.cxx,NO_VALID
TestDeformPointSet.cxx
TestDensifyPolyData.cxx
TestDistancePolyDataFilter.cxx
......
/*=========================================================================
Program: Visualization Toolkit
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 "vtkCountVertices.h"
#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkNew.h"
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"
int TestCountVertices(int, char*[])
{
vtkNew<vtkUnstructuredGrid> data;
vtkNew<vtkPoints> points;
vtkNew<vtkIdList> cell;
vtkNew<vtkCountVertices> filter;
// Need 12 points to test all cell types:
for (int i = 0; i < 12; ++i)
{
points->InsertNextPoint(0., 0., 0.);
}
data->SetPoints(points.Get());
// Insert the following cell types and verify the number of verts computed
// by the filter:
// VTK_VERTEX = 1
// VTK_LINE = 2
// VTK_TRIANGLE = 3
// VTK_TETRA = 4
// VTK_PYRAMID = 5
// VTK_WEDGE = 6
// VTK_VOXEL = 8
// VTK_HEXAHEDRON = 8
// VTK_PENTAGONAL_PRISM = 10
// VTK_HEXAGONAL_PRISM = 12
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_VERTEX, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_LINE, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_TRIANGLE, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_TETRA, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_PYRAMID, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_WEDGE, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_VOXEL, cell.Get());
data->InsertNextCell(VTK_HEXAHEDRON, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_PENTAGONAL_PRISM, cell.Get());
cell->InsertNextId(cell->GetNumberOfIds());
cell->InsertNextId(cell->GetNumberOfIds());
data->InsertNextCell(VTK_HEXAGONAL_PRISM, cell.Get());
filter->SetInputData(data.Get());
filter->Update();
vtkUnstructuredGrid *output =
vtkUnstructuredGrid::SafeDownCast(filter->GetOutput());
if (!output)
{
std::cerr << "No output data!\n";
return EXIT_FAILURE;
}
vtkIdTypeArray *verts =
vtkIdTypeArray::SafeDownCast(
output->GetCellData()->GetArray(
filter->GetOutputArrayName()));
if (!verts)
{
std::cerr << "No output array!\n";
return EXIT_FAILURE;
}
if (verts->GetNumberOfComponents() != 1)
{
std::cerr << "Invalid number of components in output array: "
<< verts->GetNumberOfComponents() << "\n";
return EXIT_FAILURE;
}
if (verts->GetNumberOfTuples() != 10)
{
std::cerr << "Invalid number of components in output array: "
<< verts->GetNumberOfTuples() << "\n";
return EXIT_FAILURE;
}
#define TEST_VERTICES(idx, expected) \
{ \
vtkIdType numVerts = verts->GetTypedComponent(idx, 0); \
if (numVerts != expected) \
{ \
std::cerr << "Expected cell @idx=" << idx << " to have " << expected \
<< " vertices, but found " << numVerts<< "\n"; \
return EXIT_FAILURE; \
} \
}
int idx = 0;
// VTK_VERTEX = 1
TEST_VERTICES(idx++, 1);
// VTK_LINE = 2
TEST_VERTICES(idx++, 2);
// VTK_TRIANGLE = 3
TEST_VERTICES(idx++, 3);
// VTK_TETRA = 4
TEST_VERTICES(idx++, 4);
// VTK_PYRAMID = 5
TEST_VERTICES(idx++, 5);
// VTK_WEDGE = 6
TEST_VERTICES(idx++, 6);
// VTK_VOXEL = 8
TEST_VERTICES(idx++, 8);
// VTK_HEXAHEDRON = 8
TEST_VERTICES(idx++, 8);
// VTK_PENTAGONAL_PRISM = 10
TEST_VERTICES(idx++, 10);
// VTK_HEXAGONAL_PRISM = 12
TEST_VERTICES(idx++, 12);
#undef TEST_VERTICES
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCountVertices.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 "vtkCountVertices.h"
#include "vtkCellData.h"
#include "vtkCellIterator.h"
#include "vtkDataSet.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkCountVertices)
//------------------------------------------------------------------------------
void vtkCountVertices::PrintSelf(std::ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "OutputArrayName: "
<< (this->OutputArrayName ? this->OutputArrayName : "(NULL)") << "\n";
}
//------------------------------------------------------------------------------
vtkCountVertices::vtkCountVertices()
: OutputArrayName(NULL)
{
this->SetOutputArrayName("Vertex Count");
}
//------------------------------------------------------------------------------
vtkCountVertices::~vtkCountVertices()
{
this->SetOutputArrayName(NULL);
}
//------------------------------------------------------------------------------
int vtkCountVertices::RequestData(vtkInformation *,
vtkInformationVector **inInfoVec,
vtkInformationVector *outInfoVec)
{
// get the info objects
vtkInformation *inInfo = inInfoVec[0]->GetInformationObject(0);
vtkInformation *outInfo = outInfoVec->GetInformationObject(0);
// get the input and output
vtkDataSet *input = vtkDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDataSet *output = vtkDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
assert(input && output);
output->ShallowCopy(input);
vtkNew<vtkIdTypeArray> vertCount;
vertCount->Allocate(input->GetNumberOfCells());
vertCount->SetName(this->OutputArrayName);
output->GetCellData()->AddArray(vertCount.Get());
vtkCellIterator *it = input->NewCellIterator();
for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell())
{
vertCount->InsertNextValue(it->GetNumberOfPoints());
}
it->Delete();
return 1;
}
//------------------------------------------------------------------------------
int vtkCountVertices::FillOutputPortInformation(int, vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataSet");
return 1;
}
//------------------------------------------------------------------------------
int vtkCountVertices::FillInputPortInformation(int, vtkInformation *info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCountVertices.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.
=========================================================================*/
// .NAME vtkCountVertices - Add a cell data array containing the number of
// vertices per cell.
//
// .SECTION Description
// This filter adds a cell data array containing the number of vertices per
// cell.
#ifndef vtkCountVertices_h
#define vtkCountVertices_h
#include "vtkFiltersGeneralModule.h" // For export macro
#include "vtkPassInputTypeAlgorithm.h"
class VTKFILTERSGENERAL_EXPORT vtkCountVertices: public vtkPassInputTypeAlgorithm
{
public:
static vtkCountVertices* New();
vtkTypeMacro(vtkCountVertices, vtkPassInputTypeAlgorithm)
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// The name of the new output array containing the vertex counts.
vtkSetStringMacro(OutputArrayName)
vtkGetStringMacro(OutputArrayName)
protected:
vtkCountVertices();
~vtkCountVertices();
int RequestData(vtkInformation* request, vtkInformationVector **inInfoVec,
vtkInformationVector *outInfoVec);
int FillOutputPortInformation(int port, vtkInformation* info);
int FillInputPortInformation(int port, vtkInformation* info);
char *OutputArrayName;
private:
vtkCountVertices(const vtkCountVertices&) VTK_DELETE_FUNCTION;
void operator=(const vtkCountVertices&) VTK_DELETE_FUNCTION;
};
#endif // vtkCountVertices_h
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