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
|
#include <vtkFileResourceStream.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkTestUtilities.h>
#include <vtkVersion.h>
#include "vtkF3DPLYReader.h"
#include <iostream>
int TestF3DPLYReader(int vtkNotUsed(argc), char* argv[])
{
std::string pathGaussians = std::string(argv[1]) + "data/bonsai_small.ply";
std::string pathSimplePoints = std::string(argv[1]) + "data/points.ply";
// check open from stream
{
vtkNew<vtkFileResourceStream> stream;
if (!stream->Open(pathGaussians.c_str()))
{
std::cerr << "Cannot open file" << std::endl;
return EXIT_FAILURE;
}
vtkNew<vtkF3DPLYReader> reader;
reader->ReadFromInputStreamOn();
reader->SetStream(stream);
reader->Update();
vtkIdType nbGaussians = reader->GetOutput()->GetNumberOfPoints();
if (nbGaussians != 2655)
{
std::cerr << "Incorrect number of gaussians: " << nbGaussians << std::endl;
return EXIT_FAILURE;
}
if (reader->GetOutput()->GetPointData()->GetArray("sh10") == nullptr)
{
std::cerr << "Cannot find spherical harmonics" << std::endl;
return EXIT_FAILURE;
}
}
// check open from string
{
std::ifstream file;
file.open(pathGaussians.c_str(), std::ios::binary);
if (!file.is_open())
{
std::cerr << "Cannot open file" << std::endl;
return EXIT_FAILURE;
}
std::string inputString(
(std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
vtkNew<vtkF3DPLYReader> reader;
reader->ReadFromInputStringOn();
reader->SetInputString(inputString);
reader->Update();
vtkIdType nbGaussians = reader->GetOutput()->GetNumberOfPoints();
if (nbGaussians != 2655)
{
std::cerr << "Incorrect number of gaussians: " << nbGaussians << std::endl;
return EXIT_FAILURE;
}
if (reader->GetOutput()->GetPointData()->GetArray("sh10") == nullptr)
{
std::cerr << "Cannot find spherical harmonics" << std::endl;
return EXIT_FAILURE;
}
}
// check not 3d gaussians
{
vtkNew<vtkF3DPLYReader> reader;
reader->SetFileName(pathSimplePoints.c_str());
reader->Update();
vtkIdType nbPoints = reader->GetOutput()->GetNumberOfPoints();
if (nbPoints != 5)
{
std::cerr << "Incorrect number of points: " << nbPoints << std::endl;
return EXIT_FAILURE;
}
if (reader->GetOutput()->GetPointData()->GetArray("sh10") != nullptr)
{
std::cerr << "Should not have spherical harmonics" << std::endl;
return EXIT_FAILURE;
}
}
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 5, 20250703) // a leak was fixed in this version
// check invalid
{
std::string pathInvalid = std::string(argv[1]) + "data/invalid.so";
vtkNew<vtkF3DPLYReader> reader;
reader->SetFileName(pathInvalid.c_str());
reader->Update();
vtkIdType nbPoints = reader->GetOutput()->GetNumberOfPoints();
if (nbPoints != 0)
{
std::cerr << "The file should be invalid" << std::endl;
return EXIT_FAILURE;
}
}
#endif
return EXIT_SUCCESS;
}
|