Commit e7caf7e2 authored by Bill Lorensen's avatar Bill Lorensen

ENH: Improve coverage of vtkGenericGeometryFilter

A unit test that increases coverage from 77 percent to 98 percent. The
remaining uncovered lines of code are difficult to exercise.

While writing this unit test, we discovered that ExtentClipping
was not implemented. This patch repairs that defect.
parent d3454b17
......@@ -8,6 +8,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestGenericGlyph3DFilter.cxx
TestGenericProbeFilter.cxx
otherCreation.cxx,NO_VALID
UnitTestGenericGeometryFilter.cxx,NO_VALID,NO_DATA
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests)
/*=========================================================================
Program: Visualization Toolkit
Module: UnitTestGenericGeometryFilter.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 "vtkSmartPointer.h"
#include "vtkGenericGeometryFilter.h"
#include "vtkBridgeDataSet.h"
#include "vtkPlaneSource.h"
#include "vtkVertex.h"
#include "vtkTetra.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkPointLocator.h"
#include "vtkTestErrorObserver.h"
#include <sstream>
static vtkSmartPointer<vtkBridgeDataSet> CreatePolyData(const int xres, const int yres);
static vtkSmartPointer<vtkBridgeDataSet> CreateVertexData();
static vtkSmartPointer<vtkBridgeDataSet> CreateTetraData();
#define CHECK_ERROR_MSG(errorObserver, msg, status) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()
int UnitTestGenericGeometryFilter(int, char*[])
{
const int xres = 20, yres = 10;
int status = EXIT_SUCCESS;
{
std::cout << "Testing empty print...";
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
std::ostringstream emptyPrint;
filter->Print(emptyPrint);
std::cout << "PASSED." << std::endl;
}
{
std::cout << "Testing default settings...";
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
filter->SetInputData (CreatePolyData(xres, yres));
filter->Update();
int got = filter->GetOutput()->GetNumberOfCells();
std::cout << "# of cells: " << got;
int expected = xres * yres;
if (expected != got)
{
std::cout << " Expected " << expected << " cells"
<< " but got " << got << " cells."
<< " FAILED." << std::endl;
status++;
}
else
{
std::cout << " PASSED." << std::endl;
}
}
{
std::cout << "Testing PointClippingOn()...";
vtkSmartPointer<vtkPointLocator> locator =
vtkSmartPointer<vtkPointLocator>::New();
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
filter->SetInputData (CreatePolyData(xres, yres));
filter->SetLocator(locator);
filter->MergingOff();
filter->PointClippingOn();
filter->CellClippingOff();
filter->ExtentClippingOff();
filter->SetPointMinimum(0);
filter->SetPointMaximum((xres+1)*(yres+1)-1);
filter->Update();
int got = filter->GetOutput()->GetNumberOfCells();
std::cout << "# of cells: " << got;
int expected = xres * yres;
if (expected != got)
{
std::cout << " Expected " << expected << " cells"
<< " but got " << got << " cells."
<< " FAILED." << std::endl;
status++;
}
else
{
std::cout << " PASSED." << std::endl;
}
std::ostringstream fullPrint;
filter->Print(fullPrint);
}
{
std::cout << "Testing CellClippingOn()...";
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
filter->SetInputData (CreatePolyData(xres, yres));
filter->PointClippingOff();
filter->CellClippingOn();
filter->ExtentClippingOff();
filter->SetCellMinimum(xres);
filter->SetCellMaximum(xres + 9);
filter->Update();
int got = filter->GetOutput()->GetNumberOfCells();
std::cout << "# of cells: " << got;
int expected = filter->GetCellMaximum() - filter->GetCellMinimum() + 1;
if (expected != got)
{
std::cout << " Expected " << expected << " cells"
<< " but got " << got << " cells."
<< " FAILED" << std::endl;
status++;
}
else
{
std::cout << " PASSED." << std::endl;
}
}
{
std::cout << "Testing ExtentClippingOn()...";
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
filter->MergingOn();
filter->SetInputData (CreatePolyData(xres, yres));
filter->PointClippingOff();
filter->CellClippingOff();
filter->ExtentClippingOn();
filter->PassThroughCellIdsOn();
filter->SetExtent(.4, -.4, .4, -.4, .4, -.4);
filter->SetExtent(-.499, .499, -.499, .499, 0.0, 0.0);
filter->SetExtent(-.499, .499, -.499, .499, 0.0, 0.0);
filter->Update();
int got = filter->GetOutput()->GetNumberOfCells();
std::cout << "# of cells: " << got;
int expected = (xres * yres) - 2 * xres - 2 * (yres - 2);
if (expected != got)
{
std::cout << " Expected " << expected << " cells"
<< " but got " << got << " cells."
<< " FAILED." << std::endl;
status++;
}
else if (filter->GetOutput()->GetCellData()->GetArray("vtkOriginalCellIds") == NULL)
{
std::cout << " PassThroughCellIdsOn should produce vtkOriginalCellIds, but did not." << std::endl;
std::cout << " FAILED." << std::endl;
status++;
}
else
{
std::cout << " PASSED." << std::endl;
}
}
{
std::cout << "Testing with TetraData...";
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
filter->SetInputData (CreateTetraData());
filter->PointClippingOff();
filter->CellClippingOff();
filter->ExtentClippingOff();
filter->PassThroughCellIdsOn();
filter->Update();
int got = filter->GetOutput()->GetNumberOfCells();
std::cout << "# of cells: " << got;
int expected = 4;
if (expected != got)
{
std::cout << " Expected " << expected << " cells"
<< " but got " << got << " cells."
<< " FAILED." << std::endl;
status++;
}
else
{
std::cout << " PASSED." << std::endl;
}
}
{
std::cout << "Testing errors...";
vtkSmartPointer<vtkTest::ErrorObserver> errorObserver =
vtkSmartPointer<vtkTest::ErrorObserver>::New();
vtkSmartPointer<vtkGenericGeometryFilter> filter =
vtkSmartPointer<vtkGenericGeometryFilter>::New();
filter->AddObserver(vtkCommand::ErrorEvent, errorObserver);
filter->SetInputData (vtkSmartPointer<vtkBridgeDataSet>::New());
filter->Update();
CHECK_ERROR_MSG(errorObserver, "Number of cells is zero, no data to process.", status);
filter->SetInputData (CreateVertexData());
filter->Update();
CHECK_ERROR_MSG(errorObserver, "Cell of dimension 0 not handled yet.", status);
if (status)
{
std::cout << "FAILED." << std::endl;
}
else
{
std::cout << "PASSED." << std::endl;
}
}
return status;
}
vtkSmartPointer<vtkBridgeDataSet> CreatePolyData(const int xres, const int yres)
{
vtkSmartPointer<vtkPlaneSource> plane =
vtkSmartPointer<vtkPlaneSource>::New();
plane->SetXResolution(xres);
plane->SetYResolution(yres);
plane->Update();
vtkSmartPointer<vtkIntArray> cellData =
vtkSmartPointer<vtkIntArray>::New();
cellData->SetNumberOfTuples(xres * yres);
cellData->SetName("CellDataTestArray");
vtkIdType c = 0;
for (int j = 0; j < yres; ++j)
{
for (int i = 0; i <xres; ++i)
{
cellData->SetTuple1(c++, i);
}
}
vtkSmartPointer<vtkIntArray> pointData =
vtkSmartPointer<vtkIntArray>::New();
pointData->SetNumberOfTuples((xres + 1) * (yres + 1));
pointData->SetName("PointDataTestArray");
c = 0;
for (int j = 0; j < yres + 1; ++j)
{
for (int i = 0; i <xres + 1; ++i)
{
pointData->SetTuple1(c++, i);
}
}
vtkSmartPointer<vtkPolyData> pd =
vtkSmartPointer<vtkPolyData>::New();
pd = plane->GetOutput();
pd->GetPointData()->SetScalars(pointData);
pd->GetCellData()->SetScalars(cellData);
vtkSmartPointer<vtkBridgeDataSet> bridge =
vtkSmartPointer<vtkBridgeDataSet>::New();
bridge->SetDataSet(plane->GetOutput());
return bridge;
}
vtkSmartPointer<vtkBridgeDataSet> CreateVertexData()
{
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0,0,0);
vtkSmartPointer<vtkVertex> vertex =
vtkSmartPointer<vtkVertex>::New();
vertex->GetPointIds()->SetId(0, 0);
vtkSmartPointer<vtkCellArray> vertices =
vtkSmartPointer<vtkCellArray>::New();
vertices->InsertNextCell(vertex);
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->SetVerts(vertices);
vtkSmartPointer<vtkBridgeDataSet> bridge =
vtkSmartPointer<vtkBridgeDataSet>::New();
bridge->SetDataSet(polydata);
return bridge;
}
vtkSmartPointer<vtkBridgeDataSet> CreateTetraData()
{
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>:: New();
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(1, 1, 0);
points->InsertNextPoint(0, 1, 1);
points->InsertNextPoint(5, 5, 5);
points->InsertNextPoint(6, 5, 5);
points->InsertNextPoint(6, 6, 5);
points->InsertNextPoint(5, 6, 6);
vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid =
vtkSmartPointer<vtkUnstructuredGrid>::New();
unstructuredGrid->SetPoints(points);
vtkSmartPointer<vtkTetra> tetra =
vtkSmartPointer<vtkTetra>::New();
tetra->GetPointIds()->SetId(0, 4);
tetra->GetPointIds()->SetId(1, 5);
tetra->GetPointIds()->SetId(2, 6);
tetra->GetPointIds()->SetId(3, 7);
vtkSmartPointer<vtkCellArray> cellArray =
vtkSmartPointer<vtkCellArray>::New();
cellArray->InsertNextCell(tetra);
unstructuredGrid->SetCells(VTK_TETRA, cellArray);
vtkSmartPointer<vtkIntArray> pointData =
vtkSmartPointer<vtkIntArray>::New();
pointData->SetNumberOfTuples(unstructuredGrid->GetNumberOfPoints());
pointData->SetName("PointDataTestArray");
int c = 0;
for (vtkIdType id = 0; id < tetra->GetNumberOfPoints(); ++id)
{
pointData->SetTuple1(c++, id);
}
unstructuredGrid->GetPointData()->SetScalars(pointData);
vtkSmartPointer<vtkBridgeDataSet> bridge =
vtkSmartPointer<vtkBridgeDataSet>::New();
bridge->SetDataSet(unstructuredGrid);
return bridge;
}
......@@ -33,6 +33,7 @@
#include "vtkWedge.h"
#include "vtkDoubleArray.h"
#include "vtkGenericCellIterator.h"
#include "vtkGenericPointIterator.h"
#include "vtkGenericAdaptorCell.h"
#include "vtkGenericDataSet.h"
#include "vtkGenericAttributeCollection.h"
......@@ -140,26 +141,21 @@ int vtkGenericGeometryFilter::RequestData(
vtkIdType cellId;
int i, j;
// vtkGenericDataSet *input= this->GetInput();
vtkIdType numPts = input->GetNumberOfPoints();
vtkIdType numCells = input->GetNumberOfCells();
char *cellVis;
vtkGenericAdaptorCell *cell;
double x[3]={0,0,0};
//vtkIdList *ptIds;
vtkIdType ptIds[4];
vtkIdType ptId;
//int npts;
//vtkIdType pt=0;
int allVisible;
// vtkPolyData *output = this->GetOutput();
vtkPointData *outputPD = output->GetPointData();
vtkCellData *outputCD = output->GetCellData();
if (numCells == 0)
{
vtkErrorMacro(<<"No data to clip");
vtkErrorMacro(<<"Number of cells is zero, no data to process.");
return 1;
}
......@@ -193,19 +189,25 @@ int vtkGenericGeometryFilter::RequestData(
}
else
{
//ptIds = cell->GetPointIds();
vtkGenericPointIterator *pointIt = input->NewPointIterator();
cell->GetPointIterator(pointIt);
pointIt->Begin();
cell->GetPointIds( ptIds );
for (i=0; i < cell->GetNumberOfPoints(); i++)
{
ptId = ptIds[i];
//input->GetPoint(ptId, x);
// Get point coordinate
pointIt->GetPosition(x);
pointIt->Next();
if ( (this->PointClipping && (ptId < this->PointMinimum ||
ptId > this->PointMaximum) ) ||
(this->ExtentClipping &&
(x[0] < this->Extent[0] || x[0] > this->Extent[1] ||
x[1] < this->Extent[2] || x[1] > this->Extent[3] ||
x[2] < this->Extent[4] || x[2] > this->Extent[5] )) )
x[1] < this->Extent[2] || x[1] > this->Extent[3] ||
x[2] < this->Extent[4] || x[2] > this->Extent[5] )) )
{
cellVis[cellId] = 0;
break;
......@@ -215,6 +217,7 @@ int vtkGenericGeometryFilter::RequestData(
{
cellVis[cellId] = 1;
}
pointIt->Delete();
}
}
}
......@@ -230,11 +233,9 @@ int vtkGenericGeometryFilter::RequestData(
output->Allocate(numCells);
vtkPoints *newPts = vtkPoints::New();
//FB vtkDoubleArray *newScalars = vtkDoubleArray::New();
vtkCellArray *cellArray = vtkCellArray::New();
newPts->Allocate(estimatedSize,numPts);
//FB newScalars->Allocate(estimatedSize, 5*numPts);
cellArray->Allocate(numCells);
......@@ -337,7 +338,7 @@ int vtkGenericGeometryFilter::RequestData(
{
// create new points and then cell
case 0: case 1:
vtkErrorMacro( "Cell not handled yet" );
vtkErrorMacro( "Cell of dimension " << cell->GetDimension() << " not handled yet." );
break;
case 2:
if ( cell->IsOnBoundary() )
......@@ -392,12 +393,9 @@ int vtkGenericGeometryFilter::RequestData(
//
output->SetPoints(newPts);
output->SetPolys(cellArray);
//FB newScalars->SetNumberOfTuples( newPts->GetNumberOfPoints() );
//FB outputPD->SetScalars(newScalars);
cellArray->Delete();
newPts->Delete();
//FB newScalars->Delete();
faceList->Delete();
//free storage
......@@ -440,32 +438,32 @@ void vtkGenericGeometryFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Point Minimum : " << this->PointMinimum << "\n";
os << indent << "Point Maximum : " << this->PointMaximum << "\n";
os << indent << "Point Minimum : " << this->GetPointMinimum() << "\n";
os << indent << "Point Maximum : " << this->GetPointMaximum() << "\n";
os << indent << "Cell Minimum : " << this->CellMinimum << "\n";
os << indent << "Cell Maximum : " << this->CellMaximum << "\n";
os << indent << "Cell Minimum : " << this->GetCellMinimum() << "\n";
os << indent << "Cell Maximum : " << this->GetCellMaximum() << "\n";
os << indent << "Extent: \n";
os << indent << " Xmin,Xmax: (" << this->Extent[0] << ", " << this->Extent[1] << ")\n";
os << indent << " Ymin,Ymax: (" << this->Extent[2] << ", " << this->Extent[3] << ")\n";
os << indent << " Zmin,Zmax: (" << this->Extent[4] << ", " << this->Extent[5] << ")\n";
os << indent << "PointClipping: " << (this->PointClipping ? "On\n" : "Off\n");
os << indent << "CellClipping: " << (this->CellClipping ? "On\n" : "Off\n");
os << indent << "ExtentClipping: " << (this->ExtentClipping ? "On\n" : "Off\n");
os << indent << "PointClipping: " << (this->GetPointClipping() ? "On\n" : "Off\n");
os << indent << "CellClipping: " << (this->GetCellClipping() ? "On\n" : "Off\n");
os << indent << "ExtentClipping: " << (this->GetExtentClipping() ? "On\n" : "Off\n");
os << indent << "Merging: " << (this->Merging ? "On\n" : "Off\n");
if ( this->Locator )
os << indent << "Merging: " << (this->GetMerging() ? "On\n" : "Off\n");
if ( this->GetLocator() )
{
os << indent << "Locator: " << this->Locator << "\n";
os << indent << "Locator: " << this->GetLocator() << "\n";
}
else
{
os << indent << "Locator: (none)\n";
}
os << indent << "PassThroughCellIds: " << (this->PassThroughCellIds ? "On\n" : "Off\n");
os << indent << "PassThroughCellIds: " << (this->GetPassThroughCellIds() ? "On\n" : "Off\n");
}
......@@ -516,21 +514,3 @@ int vtkGenericGeometryFilter::RequestUpdateExtent(
return 1;
}
//----------------------------------------------------------------------------
int vtkGenericGeometryFilter::RequestInformation(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *vtkNotUsed(outputVector))
{
// get the info objects
// vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
// vtkInformation *outInfo = outputVector->GetInformationObject(0);
if (this->GetInput() == NULL)
{
vtkErrorMacro("No Input");
return 1;
}
return 1;
}
......@@ -145,7 +145,6 @@ protected:
void UnstructuredGridExecute();
void StructuredGridExecute();
int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
int FillInputPortInformation(int, vtkInformation*);
......
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