File: TestHyperTreeGridThresholdMethods.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (89 lines) | stat: -rw-r--r-- 3,514 bytes parent folder | download | duplicates (3)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

#include "vtkCellData.h"
#include "vtkDataArray.h"
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGridNonOrientedGeometryCursor.h"
#include "vtkHyperTreeGridThreshold.h"
#include "vtkNew.h"
#include "vtkRandomHyperTreeGridSource.h"
#include "vtkTestUtilities.h"

#include <chrono>

/**
 * Test that all 3 methods for HTG thresholding give an equivalent analytic result
 */
int TestHyperTreeGridThresholdMethods(int, char*[])
{
  constexpr double THRESHOLD_MIN = 0.0;
  constexpr double THRESHOLD_MAX = 5.0;

  vtkNew<vtkRandomHyperTreeGridSource> source;
  source->SetDimensions(3, 3, 3);
  source->SetMaxDepth(5);
  source->SetMaskedFraction(0.2);
  source->SetSeed(3);
  source->SetSplitFraction(0.8);
  source->Update();

  vtkHyperTreeGrid* inputHTG = source->GetHyperTreeGridOutput();
  inputHTG->GetCellData()->SetScalars(inputHTG->GetCellData()->GetArray("Depth"));

  // Threshold using masks
  std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
  vtkNew<vtkHyperTreeGridThreshold> thresholdMask;
  thresholdMask->SetInputConnection(source->GetOutputPort());
  thresholdMask->SetMemoryStrategy(vtkHyperTreeGridThreshold::MaskInput);
  thresholdMask->ThresholdBetween(THRESHOLD_MIN, THRESHOLD_MAX);
  thresholdMask->Update();
  vtkHyperTreeGrid* htgMask = thresholdMask->GetHyperTreeGridOutput();

  std::chrono::duration<double> elapsed_seconds = std::chrono::system_clock::now() - start;
  std::cout << "Mask threshold method took " << elapsed_seconds.count() << "s" << std::endl;

  // Threshold using deep copy of structure
  start = std::chrono::system_clock::now();
  vtkNew<vtkHyperTreeGridThreshold> thresholdCopy;
  thresholdCopy->SetInputConnection(source->GetOutputPort());
  thresholdCopy->SetMemoryStrategy(vtkHyperTreeGridThreshold::DeepThreshold);
  thresholdCopy->ThresholdBetween(THRESHOLD_MIN, THRESHOLD_MAX);
  thresholdCopy->Update();
  vtkHyperTreeGrid* htgCopy = thresholdCopy->GetHyperTreeGridOutput();

  elapsed_seconds = std::chrono::system_clock::now() - start;
  std::cout << "Deep copy threshold method took " << elapsed_seconds.count() << "s" << std::endl;

  // Threshold using indexed arrays
  start = std::chrono::system_clock::now();
  vtkNew<vtkHyperTreeGridThreshold> thresholdIndex;
  thresholdIndex->SetInputConnection(source->GetOutputPort());
  thresholdIndex->SetMemoryStrategy(vtkHyperTreeGridThreshold::CopyStructureAndIndexArrays);
  thresholdIndex->ThresholdBetween(THRESHOLD_MIN, THRESHOLD_MAX);
  thresholdIndex->Update();
  vtkHyperTreeGrid* htgIndex = thresholdIndex->GetHyperTreeGridOutput();

  elapsed_seconds = std::chrono::system_clock::now() - start;
  std::cout << "Indexed arrays threshold method took " << elapsed_seconds.count() << "s"
            << std::endl;

  if (!vtkTestUtilities::CompareDataObjects(htgMask, htgCopy))
  {
    std::cerr << "Mask and copy method do not give the same result" << std::endl;
    return EXIT_FAILURE;
  }
  else if (!vtkTestUtilities::CompareDataObjects(htgMask, htgIndex))
  {
    std::cerr << "Mask and copy index array do not give the same result" << std::endl;
    return EXIT_FAILURE;
  }
  else if (!vtkTestUtilities::CompareDataObjects(htgIndex, htgCopy))
  {
    // Technically redundant
    std::cerr << "Index array and copy method do not give the same result" << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}