Hello,I have an cube in obj format with content like this:
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 0.0000 -1.0000
s off
f 1//1 5//1 7//1 3//1
f 4//2 3//2 7//2 8//2
f 8//3 7//3 5//3 6//3
f 6//4 2//4 4//4 8//4
f 2//3 4//3 3//3 1//3
f 6//5 5//5 1//5 2//5
Below code:
#include <vtkOBJReader.h>
#include <vtkNew.h>
#include <vtkCleanPolyData.h>
int main(int, char*[]) {
auto fileName = "/path/to/above/objFile.obj";
vtkNew<vtkOBJReader> reader;
reader->SetFileName(fileName);
reader->Update();
auto rawPD = reader->GetOutput();
std::cout << "Point number before clean: " << rawPD->GetNumberOfPoints() << std::endl << std::endl;
vtkNew<vtkCleanPolyData> clean;
clean->SetInputData(rawPD);
clean->SetTolerance(0.0);
clean->PointMergingOn();
clean->Update();
auto pd=clean->GetOutput();
std::cout << "Point number after clean: " << pd->GetNumberOfPoints() << std::endl << std::endl;
}
Outputs:
Point number before clean: 24
Point number after clean: 8
Why?