File: TestPixelExtent.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,984 kB
  • sloc: cpp: 2,336,570; 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: 181; javascript: 165; objc: 153; tcl: 59
file content (133 lines) | stat: -rw-r--r-- 2,511 bytes parent folder | download | duplicates (4)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkPixelExtent.h"
#include "vtkPixelExtentIO.h"

#include <deque>
#include <iostream>

using std::cerr;
using std::deque;
using std::endl;

int TestPixelExtent(int argc, char* argv[])
{
  (void)argc;
  (void)argv;

  cerr << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;

  // small extent in the middle of the region of interest
  vtkPixelExtent A(4, 8, 4, 8);

  // larger region that covers A
  vtkPixelExtent B(A);
  B.Grow(4);

  // shift C to origin
  vtkPixelExtent C(A);
  C.Shift();

  // shift D to upper right corner of larger region
  vtkPixelExtent D(A);
  int s1[2] = { 4, 4 };
  D.Shift(s1);

  bool testPass = true;

  vtkPixelExtent tmp1;
  vtkPixelExtent tmp2;
  vtkPixelExtent tmp3;

  // shift, intersect
  tmp1 = C;
  tmp2 = D;

  tmp1 &= tmp2;

  cerr << C << " & " << D << " = " << tmp1 << endl;

  if (!tmp1.Empty())
  {
    cerr << "Test empty intersection failed" << endl;
    testPass = false;
  }

  tmp1 = A;
  int s2[2] = { -2, -2 };
  tmp1.Shift(s2);

  tmp2 = A;
  int s3[2] = { 2, 2 };
  tmp2.Shift(s3);

  tmp3 = tmp1;
  tmp3 &= tmp2;

  cerr << tmp1 << " & " << tmp2 << " = " << tmp3 << endl;

  if (!(tmp3 == vtkPixelExtent(6, 6, 6, 6)))
  {
    cerr << "Test intersection failed" << endl;
    testPass = false;
  }

  // shift, grow, union
  tmp1 = C;
  tmp2 = D;
  tmp3 = tmp1;
  tmp3 |= tmp2;

  cerr << tmp1 << " | " << tmp2 << " = " << tmp3 << endl;

  if (!(tmp3 == B))
  {
    cerr << "Test union fails" << endl;
    testPass = false;
  }

  // subtraction
  deque<vtkPixelExtent> tmp4;
  vtkPixelExtent::Subtract(B, A, tmp4);

  deque<vtkPixelExtent> tmp5;
  tmp5.emplace_back(4, 8, 9, 12);
  tmp5.emplace_back(9, 12, 9, 12);
  tmp5.emplace_back(9, 12, 4, 8);
  tmp5.emplace_back(0, 3, 4, 8);
  tmp5.emplace_back(0, 3, 9, 12);
  tmp5.emplace_back(4, 8, 0, 3);
  tmp5.emplace_back(9, 12, 0, 3);
  tmp5.emplace_back(0, 3, 0, 3);

  size_t n = tmp4.size();
  for (size_t i = 0; i < n; ++i)
  {
    if (!(tmp4[i] == tmp5[i]))
    {
      cerr << "Test subtraction failed" << endl;
      testPass = false;
      break;
    }
  }

  cerr << B << " - " << A << " = ";
  if (n)
  {
    cerr << tmp4[0];
    for (size_t i = 1; i < n; ++i)
    {
      cerr << ", " << tmp4[i];
    }
  }
  cerr << endl;

  if (!testPass)
  {
    cerr << "Test fails" << endl;
    return 1;
  }

  cerr << "Test passes" << endl;
  return 0;
}