Hi there. Can’t make my VTK module write polydata. Any help welcome. Thanks.
/usr/bin/ld: CMakeFiles/createmesh.dir/MeshWriter.cxx.o: undefined reference to symbol “_ZN9vtkWriter12SetInputDataEP13vtkDataObject”
/usr/bin/ld: /home/3484681/Area de Trabalho/vtk-master/build/lib/libvtkIOCore-9.3.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/createmesh.dir/build.make:347: createmesh] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/createmesh.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
#include “MeshWriter.h” // Replace ‘path/to/’ with the actual path
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkPLYWriter.h>
#include <vtkSTLWriter.h>
#include <vtkOBJWriter.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyDataWriter.h>
#include
#include
#include <vtkPolyDataReader.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkSTLReader.h>
#include <vtkOBJReader.h>
#include
#include
#include <vtkAlgorithmOutput.h>
#include <vtkDataReader.h>
#include <vtkPolyDataReader.h>
std::string GetFileFormat(const std::string& filename) {
// Find the position of the last dot in the filename.
size_t dotPos = filename.find_last_of(‘.’);
// Check if a dot was found and extract the format if found.
if (dotPos != std::string::npos) {
// Use substr to get the characters following the last dot.
return filename.substr(dotPos + 1);
}
// If no dot is found, return an empty string to indicate no format.
return "";
}
MeshWriter::MeshWriter() {
// Constructor implementation, if needed
}
MeshWriter::~MeshWriter() {
// Destructor implementation, if needed
}
bool MeshWriter::WriteVTK(const vtkSmartPointer& polydata, const std::string& fileName) {
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetFileName(fileName.c_str());
writer->SetInputData(polydata);
return writer->Write();
}
bool MeshWriter::WriteVTP(const vtkSmartPointer& polydata, const std::string& fileName) {
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetFileName(fileName.c_str());
writer->SetInputData(polydata);
return writer->Write();
}
bool MeshWriter::WriteSTL(const vtkSmartPointer& polydata, const std::string& fileName) {
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetFileName(fileName.c_str());
writer->SetInputData(polydata);
return writer->Write();
}
bool MeshWriter::WriteOBJ(const vtkSmartPointer& polydata, const std::string& fileName) {
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetFileName(fileName.c_str());
writer->SetInputData(polydata);
return writer->Write();
}
bool MeshWriter::WritePLY(const vtkSmartPointer& polydata, const std::string& fileName) {
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetFileName(fileName.c_str());
writer->SetInputData(polydata);
return writer->Write();
}
bool MeshWriter::WriteMesh(const vtkSmartPointer& polydata, const std::string& fileName) {
vtkSmartPointer writer;
std::string format ;
format= GetFileFormat(fileName);
if (format == "vtk") {
return WriteVTK(polydata, fileName);
} else if (format == "vtp") {
return WriteVTP(polydata, fileName);
} else if (format == "stl") {
return WriteSTL(polydata, fileName);
} else if (format == "obj") {
return WriteOBJ(polydata, fileName);
} else {
return WritePLY(polydata, fileName);
}
}
MeshWriter.cxx (5.9 KB)
MeshWriter.h (1.5 KB)
CMakeLists.txt (2.6 KB)