File: TestOBJReaderMultiTexture.cxx

package info (click to toggle)
paraview 5.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 367,928 kB
  • sloc: cpp: 2,870,477; ansic: 1,329,317; python: 132,607; xml: 98,045; sh: 5,265; java: 4,541; yacc: 4,385; f90: 3,099; perl: 2,363; lex: 1,950; javascript: 1,574; objc: 143; makefile: 135; tcl: 59; pascal: 50; fortran: 27
file content (106 lines) | stat: -rw-r--r-- 3,123 bytes parent folder | download | duplicates (5)
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestOBJReaderMultiTexture.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkDebugLeaks.h"
#include "vtkOBJReader.h"

#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkTestUtilities.h"

//------------------------------------------------------------------------------
int TestOBJReaderMultiTexture(int argc, char* argv[])
{
  // Create the reader.
  char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/obj_multitexture.obj");

  vtkNew<vtkOBJReader> reader;
  reader->SetFileName(fname);
  reader->Update();

  vtkPolyData* data = reader->GetOutput();

  delete[] fname;

  if (!data)
  {
    std::cerr << "Could not read data" << std::endl;
    return EXIT_FAILURE;
  }

  // The OBJ file has 3 cells and 8 points.
  // 4 of those points have 2 textures associated, thus the reader output
  // must have 12 points.
  if (data->GetNumberOfPoints() != 12 && data->GetNumberOfCells() == 3)
  {
    std::cerr << "Invalid number of points or cells" << std::endl;
    return EXIT_FAILURE;
  }

  // The output must have 2 arrays, texture_0 & texture_1. texture_0 has
  // (-1, -1) for indices 4 to 7. texture_1 has (-1, -1) for every indices but
  // those between 4 and 7

  // Check the number of arrays
  if (data->GetPointData()->GetNumberOfArrays() != 2)
  {
    std::cerr << "Invalid number of arrays" << std::endl;
    return EXIT_FAILURE;
  }

  vtkDataArray* texture0 = data->GetPointData()->GetArray("texture_0");
  vtkDataArray* texture1 = data->GetPointData()->GetArray("texture_1");
  // Check if the arrays are named correctly
  if (!texture0)
  {
    std::cerr << "Could not find texture_0 array" << std::endl;
    return EXIT_FAILURE;
  }

  if (!texture1)
  {
    std::cerr << "Could not find texture_1 array" << std::endl;
    return EXIT_FAILURE;
  }

  // Check the values
  for (int i = 0; i < 12; ++i)
  {
    double* currentTCoord0 = texture0->GetTuple2(i);
    double* currentTCoord1 = texture1->GetTuple2(i);

    // Testing values outside [4, 7]
    if (i < 4 || i > 7)
    {
      if ((currentTCoord0[0] == -1 && currentTCoord0[1] == -1) ||
        !(currentTCoord1[0] == -1 && currentTCoord1[1] == -1))
      {
        std::cerr << "Unexpected texture values" << std::endl;
        return EXIT_FAILURE;
      }
    }
    // Testing values inside [4, 7]
    else
    {
      if (!(currentTCoord0[0] == -1 && currentTCoord0[1] == -1) ||
        (currentTCoord1[0] == -1 && currentTCoord1[1] == -1))
      {
        std::cerr << "Unexpected texture values" << std::endl;
        return EXIT_FAILURE;
      }
    }
  }

  return EXIT_SUCCESS;
}