mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-06 07:21:31 +01:00
add VTK save early
This commit is contained in:
@@ -32,7 +32,8 @@ set(SOURCES VoxRaytracer.cpp
|
||||
Structured4DGrid.cpp)
|
||||
|
||||
set(LIBRARIES ${Eigen_LIBRARY}
|
||||
${ROOT_LIBRARIES})
|
||||
${ROOT_LIBRARIES}
|
||||
${VTK_LIBRARIES})
|
||||
|
||||
set(libname ${PACKAGE_LIBPREFIX}Math)
|
||||
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
|
||||
|
||||
@@ -30,9 +30,43 @@
|
||||
|
||||
#include "VoxImage.h"
|
||||
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkImageData.h>
|
||||
|
||||
#include <vtkXMLImageDataWriter.h>
|
||||
|
||||
|
||||
namespace uLib {
|
||||
|
||||
void Abstract::VoxImage::SaveToVtkVti (const char *file)
|
||||
{
|
||||
Abstract::VoxImage *voxels = this;
|
||||
|
||||
vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
|
||||
image->SetDimensions(voxels->GetDims()(0), voxels->GetDims()(1), voxels->GetDims()(2));
|
||||
image->SetSpacing(voxels->GetSpacing()(0), voxels->GetSpacing()(1), voxels->GetSpacing()(2));
|
||||
image->SetOrigin(voxels->GetOrigin()(0), voxels->GetOrigin()(1), voxels->GetOrigin()(2));
|
||||
image->AllocateScalars(VTK_FLOAT, 1);
|
||||
|
||||
int nx = voxels->GetDims()(0);
|
||||
int ny = voxels->GetDims()(1);
|
||||
int nz = voxels->GetDims()(2);
|
||||
|
||||
size_t npoints = nx*ny*nz;
|
||||
float *scalar = static_cast<float*>(image->GetScalarPointer());
|
||||
|
||||
for (size_t i = 0; i < npoints; i++) {
|
||||
scalar[i] = static_cast<float>(voxels->GetValue(i));
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
|
||||
writer->SetFileName(file);
|
||||
writer->SetInputData(image);
|
||||
writer->Write();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Abstract::VoxImage::ExportToVtk (const char *file, bool density_type)
|
||||
{
|
||||
FILE * vtk_file = fopen(file,"wb");
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
void ExportToVtk(const char *file, bool density_type = 0);
|
||||
void ExportToVtkXml(const char *file, bool density_type = 0);
|
||||
int ImportFromVtk(const char *file);
|
||||
void SaveToVtkVti (const char *file);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user