Hi there,
First of all, thanks for providing this very useful toolkit!
I have a question regarding the way to write legacy PolyData files at the old 4.2 format: I am trying to call the SetFileVersion method of the vtkDataWriter object but my mesh seems to still be saved at format 5.1 and I don’t understand what is wrong in my code.
I am using vtk-9.2.5 on MacOS Monterey (12.6).
Please find below a minimal reproducer.
cat > vtkDataSetWriter.cxx <<EOF
#include <vtkCellArray.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkQuad.h>
#include <vtkCellArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetWriter.h>
int main(int, char*[])
{
// Create a grid
auto dataSet = vtkSmartPointer<vtkUnstructuredGrid> :: New();
auto points = vtkSmartPointer<vtkPoints> :: New();
auto cellArray = vtkSmartPointer<vtkCellArray> :: New();
// Add points
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(0, 1, 0);
points->InsertNextPoint(1, 1, 0);
dataSet->SetPoints(points);
// Add quad
auto quad = vtkSmartPointer<vtkQuad> :: New();
quad->GetPointIds()->SetId(0, 0);
quad->GetPointIds()->SetId(1, 1);
quad->GetPointIds()->SetId(2, 2);
quad->GetPointIds()->SetId(3, 3);
cellArray->InsertNextCell(quad);
dataSet->SetCells(VTK_QUAD,cellArray);
// Write file
vtkNew<vtkDataSetWriter> writer;
#if VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1
// Set writer version 4.2
cout << "Force saving at format 4.2" << std::endl;
writer->SetFileVersion(42);
#endif
writer->SetFileName("output.vtk");
writer->SetInputData(dataSet);
writer->Write();
return EXIT_SUCCESS;
}
EOF
cat > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(vtkDataSetWriter)
find_package(VTK COMPONENTS
CommonCore
CommonDataModel
IOLegacy
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "XMLStructuredGridWriter: Unable to find the VTK build folder.")
endif()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(vtkDataSetWriter MACOSX_BUNDLE vtkDataSetWriter.cxx )
target_link_libraries(vtkDataSetWriter PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS vtkDataSetWriter
MODULES ${VTK_LIBRARIES}
)
EOF
When executing the code, the Force saving at format 4.2
output is printed in my prompt but
the output file I obain contains the # vtk DataFile Version 5.1
header line and keywords not recognized by reader 4.2.
Thanks by advance for any help,
Best Regards,