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
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
// .SECTION Thanks
// This test was written by Philippe Pebay, 2016
// This work was supported by Commissariat a l'Energie Atomique (CEA/DIF)
#include "vtkCamera.h"
#include "vtkCellData.h"
#include "vtkDataSetMapper.h"
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGridContour.h"
#include "vtkHyperTreeGridGeometry.h"
#include "vtkHyperTreeGridSource.h"
#include "vtkNew.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
int TestHyperTreeGridBinary2DContour(int argc, char* argv[])
{
// Hyper tree grid
vtkNew<vtkHyperTreeGridSource> htGrid;
int maxLevel = 6;
htGrid->SetMaxDepth(maxLevel);
htGrid->SetDimensions(3, 4, 1); // Dimension 2 in xy plane GridCell 2, 3
htGrid->SetGridScale(1.5, 1., 10.); // this is to test that orientation fixes scale
htGrid->SetBranchFactor(2);
htGrid->SetDescriptor("RRRRR.|.... .R.. RRRR R... R...|.R.. ...R ..RR .R.. R... .... ....|.... "
"...R ..R. .... .R.. R...|.... .... .R.. ....|....");
htGrid->Update();
vtkHyperTreeGrid* htg = vtkHyperTreeGrid::SafeDownCast(htGrid->GetOutput());
htg->GetCellData()->SetScalars(htg->GetCellData()->GetArray("Depth"));
// Contour
vtkNew<vtkHyperTreeGridContour> contour;
int nContours = 3;
contour->SetNumberOfContours(nContours);
contour->SetInputConnection(htGrid->GetOutputPort());
double resolution = (maxLevel - 1) / (nContours + 1.);
double isovalue = resolution;
for (int i = 0; i < nContours; ++i, isovalue += resolution)
{
contour->SetValue(i, isovalue);
}
// Geometry
vtkNew<vtkHyperTreeGridGeometry> geometry;
geometry->SetInputConnection(htGrid->GetOutputPort());
geometry->Update();
vtkPolyData* pd = geometry->GetPolyDataOutput();
// Mappers
vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
vtkNew<vtkPolyDataMapper> mapper1;
mapper1->SetInputConnection(geometry->GetOutputPort());
mapper1->SetScalarRange(pd->GetCellData()->GetArray("Depth")->GetRange());
vtkNew<vtkPolyDataMapper> mapper2;
mapper2->SetInputConnection(geometry->GetOutputPort());
mapper2->ScalarVisibilityOff();
vtkNew<vtkPolyDataMapper> mapper3;
mapper3->SetInputConnection(contour->GetOutputPort());
mapper3->ScalarVisibilityOff();
// Actors
vtkNew<vtkActor> actor1;
actor1->SetMapper(mapper1);
vtkNew<vtkActor> actor2;
actor2->SetMapper(mapper2);
actor2->GetProperty()->SetRepresentationToWireframe();
actor2->GetProperty()->SetColor(.7, .7, .7);
vtkNew<vtkActor> actor3;
actor3->SetMapper(mapper3);
actor3->GetProperty()->SetColor(.8, .4, .3);
actor3->GetProperty()->SetLineWidth(3);
// Camera
double bd[6];
pd->GetBounds(bd);
vtkNew<vtkCamera> camera;
camera->SetClippingRange(1., 100.);
camera->SetFocalPoint(pd->GetCenter());
camera->SetPosition(.5 * bd[1], .5 * bd[3], 6.);
// Renderer
vtkNew<vtkRenderer> renderer;
renderer->SetActiveCamera(camera);
renderer->SetBackground(1., 1., 1.);
renderer->AddActor(actor1);
renderer->AddActor(actor2);
renderer->AddActor(actor3);
// Render window
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(renderer);
renWin->SetSize(400, 400);
renWin->SetMultiSamples(0);
// Interactor
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
// Render and test
renWin->Render();
int retVal = vtkRegressionTestImageThreshold(renWin, 0.05);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
|