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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestDelaunay2D.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 test draws a square usinng 4 triangles defined by 9 points and
// an edge-flag array which allows to hide internal edges.
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTestUtilities.h"
#include "vtkUnsignedCharArray.h"
// on the old OpenGL this test fails on Mesa
// so we just return true in that case
#ifndef VTK_OPENGL2
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLExtensionManager.h"
bool IsDriverMesa(vtkRenderWindow *renwin)
{
vtkOpenGLRenderWindow *context
= vtkOpenGLRenderWindow::SafeDownCast(renwin);
return context->GetExtensionManager()->DriverIsMesa();
}
#endif
int TestEdgeFlags(int argc, char *argv[])
{
vtkNew<vtkPoints> pts;
pts->SetNumberOfPoints(9);
// Define 9 points, the 4 first points of the square are repeated
// twice because 2 edges start from them and we will have to attach an
// edge flags to each point. The last center point is not duplicated
// as its edge flag will always be 0 (edge hidden).
const double pcoords[] =
{
0.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.5, 0.5, 0.0
};
for (int i = 0; i < 9; i++)
{
pts->SetPoint(i, pcoords + 3 * i);
}
// Define the 4 triangles
vtkNew<vtkCellArray> cells;
const vtkIdType tris[] = { 0,5,8, 1,6,8, 2,7,8, 3,4,8 };
for (int i = 0; i < 4; i++)
{
cells->InsertNextCell(3, tris + 3 * i);
}
// Set the point-edge flags in such a way that only the edges of the
// boundary of the square are considered as edges.
vtkNew<vtkUnsignedCharArray> edgeflags;
edgeflags->SetName("vtkEdgeFlags");
edgeflags->SetNumberOfComponents(1);
edgeflags->SetNumberOfTuples(9);
// Tip: Turn the last flag on to simulate test failure
const unsigned char flags[] = { 1, 1, 1, 1, 0, 0, 0, 0, 0 };
for (int i = 0; i < 9; i++)
{
edgeflags->SetValue(i, flags[i]);
}
vtkNew<vtkPolyData> pd;
pd->SetPoints(pts.Get());
pd->SetPolys(cells.Get());
vtkPointData* pointData = pd->GetPointData();
pointData->AddArray(edgeflags.Get());
pointData->SetActiveAttribute(
edgeflags->GetName(), vtkDataSetAttributes::EDGEFLAG);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(pd.Get());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.Get());
actor->SetPosition(-0.75,0,0);
actor->RotateZ(45.0);
vtkProperty* property = actor->GetProperty();
property->SetColor(1.0, 0.0, 0.0);
property->SetRepresentationToWireframe();
property->SetLineWidth(4.0);
// Define the 4 triangles
vtkNew<vtkCellArray> cells2;
const vtkIdType polys [] = { 0,1,6,8,3 };
cells2->InsertNextCell(5, polys);
vtkNew<vtkPolyData> pd2;
pd2->SetPoints(pts.Get());
pd2->SetPolys(cells2.Get());
pointData = pd2->GetPointData();
pointData->AddArray(edgeflags.Get());
pointData->SetActiveAttribute(
edgeflags->GetName(), vtkDataSetAttributes::EDGEFLAG);
vtkNew<vtkPolyDataMapper> mapper2;
mapper2->SetInputData(pd2.Get());
vtkNew<vtkActor> actor2;
actor2->SetMapper(mapper2.Get());
actor2->SetPosition(0.75,0,0);
vtkProperty* property2 = actor2->GetProperty();
property2->SetColor(0.0, 1.0, 0.0);
property2->SetRepresentationToWireframe();
property2->SetLineWidth(2.0);
// Render image
vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor.Get());
renderer->AddActor(actor2.Get());
renderer->SetBackground(1.0, 1.0, 1.0);
renderer->SetBackground2(0.0, 0.0, 0.0);
renderer->GradientBackgroundOn();
vtkNew<vtkRenderWindow> renWin;
renWin->SetMultiSamples(1);
renWin->SetSize(600, 300);
renWin->AddRenderer(renderer.Get());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin.Get());
renWin->Render();
// on the old OpenGL this test fails on Mesa
// so we just return true in that case
#ifndef VTK_OPENGL2
if (IsDriverMesa(renWin.Get()))
{
// Mesa support for edge flags is buggy.
std::cout << "Mesa detected. Skip the test." << std::endl;
return !vtkRegressionTester::PASSED;
}
#endif
// Compare image
int retVal = vtkRegressionTestImage(renWin.Get());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
|