File: TestOBJReaderRelative.cxx

package info (click to toggle)
paraview 5.13.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 544,220 kB
  • sloc: cpp: 3,374,605; ansic: 1,332,409; python: 150,381; xml: 122,166; sql: 65,887; sh: 7,317; javascript: 5,262; yacc: 4,417; java: 3,977; perl: 2,363; lex: 1,929; f90: 1,397; makefile: 170; objc: 153; tcl: 59; pascal: 50; fortran: 29
file content (154 lines) | stat: -rw-r--r-- 6,953 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
// .NAME Test of vtkOBJReader
// .SECTION Description
//

#include "vtkDebugLeaks.h"
#include "vtkOBJReader.h"

#include "vtkCellArray.h"
#include "vtkPointData.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"

//------------------------------------------------------------------------------
int CheckArrayPointData(vtkDataArray* firstArray, vtkDataArray* secondArray, int idx)
{
  // Check that each component at a given index are the same in each array
  for (int compIdx = 0; compIdx < secondArray->GetNumberOfComponents(); ++compIdx)
  {
    if (firstArray->GetComponent(idx, compIdx) != secondArray->GetComponent(idx, compIdx))
    {
      cerr << "Error: different values for "
              "["
           << (idx) << "]_" << compIdx << endl;
      return 1;
    }
  }
  return 0;
}

//------------------------------------------------------------------------------
int TestOBJReaderRelative(int argc, char* argv[])
{
  int retVal = 0;

  // Create the reader.
  char* fname_rel = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/relative_indices.obj");
  vtkSmartPointer<vtkOBJReader> reader_rel = vtkSmartPointer<vtkOBJReader>::New();
  reader_rel->SetFileName(fname_rel);
  reader_rel->Update();
  delete[] fname_rel;

  // Create the reader.
  char* fname_abs = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/absolute_indices.obj");
  vtkSmartPointer<vtkOBJReader> reader_abs = vtkSmartPointer<vtkOBJReader>::New();
  reader_abs->SetFileName(fname_abs);
  reader_abs->Update();
  delete[] fname_abs;

  vtkPolyData* data_rel = reader_rel->GetOutput();
  vtkPolyData* data_abs = reader_abs->GetOutput();

#define CHECK(obj, method)                                                                         \
  do                                                                                               \
  {                                                                                                \
    if (obj##_rel->method != obj##_abs->method)                                                    \
    {                                                                                              \
      cerr << "Error: different values for " #obj "->" #method << endl;                            \
      retVal = 1;                                                                                  \
    }                                                                                              \
  } while (false)
#define CHECK_ARRAY(obj, idx)                                                                      \
  do                                                                                               \
  {                                                                                                \
    if (obj##_rel[idx] != obj##_abs[idx])                                                          \
    {                                                                                              \
      cerr << "Error: different values for " #obj "[" << (idx) << "]" << endl;                     \
      retVal = 1;                                                                                  \
    }                                                                                              \
  } while (false)
#define CHECK_SCALAR(obj)                                                                          \
  do                                                                                               \
  {                                                                                                \
    if (obj##_rel != obj##_abs)                                                                    \
    {                                                                                              \
      cerr << "Error: different values for " #obj << endl;                                         \
      retVal = 1;                                                                                  \
    }                                                                                              \
  } while (false)

#define CHECK_ARRAY_EXISTS(array)                                                                  \
  do                                                                                               \
  {                                                                                                \
    if (!(array))                                                                                  \
    {                                                                                              \
      cerr << "Array does not exist." << endl;                                                     \
      retVal = 1;                                                                                  \
    }                                                                                              \
  } while (false)

  CHECK(data, GetNumberOfVerts());
  CHECK(data, GetNumberOfLines());
  CHECK(data, GetNumberOfCells());
  CHECK(data, GetNumberOfStrips());

  vtkCellArray* polys_rel = data_rel->GetPolys();
  vtkCellArray* polys_abs = data_abs->GetPolys();

  CHECK(polys, GetNumberOfCells());

  vtkIdType npts_rel;
  vtkIdType npts_abs;
  const vtkIdType* pts_rel;
  const vtkIdType* pts_abs;

  polys_rel->InitTraversal();
  polys_abs->InitTraversal();

  // Get the texture and normal arrays to check
  vtkDataArray* tcoords_rel = data_rel->GetPointData()->GetTCoords();
  vtkDataArray* tcoords_abs = data_abs->GetPointData()->GetTCoords();

  CHECK_ARRAY_EXISTS(tcoords_rel);
  CHECK_ARRAY_EXISTS(tcoords_abs);

  int tcoordsNbComp_rel = tcoords_rel->GetNumberOfComponents();
  int tcoordsNbComp_abs = tcoords_abs->GetNumberOfComponents();

  vtkDataArray* normals_rel = data_rel->GetPointData()->GetNormals();
  vtkDataArray* normals_abs = data_abs->GetPointData()->GetNormals();

  CHECK_ARRAY_EXISTS(normals_rel);
  CHECK_ARRAY_EXISTS(normals_abs);

  int normalsNbComp_rel = normals_rel->GetNumberOfComponents();
  int normalsNbComp_abs = normals_abs->GetNumberOfComponents();

  CHECK_SCALAR(tcoordsNbComp);
  CHECK_SCALAR(normalsNbComp);

  while (polys_rel->GetNextCell(npts_rel, pts_rel) && polys_abs->GetNextCell(npts_abs, pts_abs))
  {
    CHECK_SCALAR(npts);

    for (vtkIdType i = 0; i < npts_rel && i < npts_abs; ++i)
    {
      CHECK_ARRAY(pts, i);

      // For each points, check if the point data associated with the points
      // from the OBJ using relative coordinates matches the ones from the
      // OBJ using absolute coordinates
      retVal = CheckArrayPointData(tcoords_rel, tcoords_abs, i) ||
        CheckArrayPointData(normals_rel, normals_abs, i);
    }
  }

#undef CHECK_ARRAY_EXISTS
#undef CHECK_SCALAR
#undef CHECK_ARRAY
#undef CHECK

  return retVal;
}