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
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGridAxisClip.h"
#include "vtkHyperTreeGridOrientedGeometryCursor.h"
#include "vtkHyperTreeGridPreConfiguredSource.h"
#include "vtkIdTypeArray.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include <cstdlib>
#include <numeric>
namespace
{
constexpr double EPSILON = 0.1;
constexpr double CLIP_BOUNDS[6] = { -0.5, 0.5, 0., 1., -1., 0.1 };
bool CheckClippedBounds(vtkHyperTreeGrid* htg)
{
vtkNew<vtkHyperTreeGridAxisClip> clip;
clip->SetInputDataObject(htg);
clip->SetClipTypeToBox();
clip->SetBounds(::CLIP_BOUNDS);
clip->SetInsideOut(false);
clip->Update();
auto clipped = clip->GetOutputDataObject(0);
if (!clipped)
{
std::cerr << "Clipped is nullptr" << std::endl;
return false;
}
vtkHyperTreeGrid* out = vtkHyperTreeGrid::SafeDownCast(clipped);
if (!out)
{
std::cerr << "Clip failed to provide a vtkHyperTreeGrid" << std::endl;
return false;
}
double* bounds = out->GetBounds();
for (int idx = 0; idx < 6; idx++)
{
if (std::abs(bounds[idx] - ::CLIP_BOUNDS[idx]) > ::EPSILON)
{
std::cerr << "Clipped output does not have valid bounds." << std::endl;
return false;
}
}
return true;
}
}
int TestHyperTreeGridBounds(int, char*[])
{
vtkNew<vtkHyperTreeGridPreConfiguredSource> htgSrc;
htgSrc->SetHTGMode(vtkHyperTreeGridPreConfiguredSource::BALANCED_2DEPTH_3BRANCH_3X3X2);
htgSrc->Update();
vtkHyperTreeGrid* input = vtkHyperTreeGrid::SafeDownCast(htgSrc->GetOutputDataObject(0));
if (!input)
{
std::cerr << "Something went wrong with HTG generation, input is nullptr" << std::endl;
return EXIT_FAILURE;
}
bool res = ::CheckClippedBounds(input);
return res ? EXIT_SUCCESS : EXIT_FAILURE;
}
|