1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestReflectionFilter.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.
=========================================================================*/
// This tests vtkReflectionFilter
#include <vtkSmartPointer.h>
#include <vtkNew.h>
#include <vtkUnstructuredGrid.h>
#include <vtkCellType.h>
#include <vtkIdList.h>
#include <vtkReflectionFilter.h>
#include <iostream>
#include <cassert>
#define AssertMacro(b) if(!(b)){std::cerr <<"Failed to reflect pyramid"<<std::endl;return EXIT_FAILURE;}
int TestReflectionFilter(int, char *[])
{
vtkSmartPointer<vtkUnstructuredGrid> pyramid = vtkSmartPointer<vtkUnstructuredGrid>::New();
{
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(-1,-1,-1);
points->InsertNextPoint( 1,-1,-1);
points->InsertNextPoint( 1, 1,-1);
points->InsertNextPoint(-1, 1,-1);
points->InsertNextPoint(0,0,1);
pyramid->SetPoints(points);
}
vtkNew<vtkIdList> verts;
verts->InsertNextId(0);
verts->InsertNextId(1);
verts->InsertNextId(2);
verts->InsertNextId(3);
verts->InsertNextId(4);
pyramid->InsertNextCell(VTK_PYRAMID,verts.GetPointer());
for(int i=0; i<2; i++)
{
vtkSmartPointer<vtkReflectionFilter> reflectionFilter = vtkSmartPointer<vtkReflectionFilter>::New();
reflectionFilter->SetInputData(pyramid.GetPointer());
i==0? reflectionFilter->CopyInputOff() : reflectionFilter->CopyInputOn();
reflectionFilter->SetPlaneToZMin();
reflectionFilter->Update();
vtkUnstructuredGrid* pyramid1 = vtkUnstructuredGrid::SafeDownCast(reflectionFilter->GetOutput());
vtkNew<vtkIdList> cellIds;
if(i==0)
{
AssertMacro(pyramid1->GetNumberOfCells()==1);
}
else
{
AssertMacro(pyramid1->GetNumberOfCells()==2);
}
pyramid1->GetCellPoints(i, cellIds.GetPointer());
int apex = cellIds->GetId(4);
int offset = i==0? 0 : 5;
AssertMacro(apex==4+offset);
for(int j=0; j<4; j++)
{
int next = cellIds->GetId((j+1)%4);
int nextExpected = (cellIds->GetId(j)-offset+3)%4+offset;
AssertMacro(next ==nextExpected);
}
}
return EXIT_SUCCESS;
}
|