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
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#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;
}
|