Skip to content

Instantly share code, notes, and snippets.

@daviddoria
Created March 8, 2017 14:17
Show Gist options
  • Save daviddoria/99fa99c52aa07ee78b7e7412e74d592f to your computer and use it in GitHub Desktop.
Save daviddoria/99fa99c52aa07ee78b7e7412e74d592f to your computer and use it in GitHub Desktop.
#include <vtkCellData.h>
#include <vtkSmartPointer.h>
#include <vtkUniformGrid.h>
#include <vtkUnsignedIntArray.h>
#include <vtkXMLImageDataWriter.h>
int main(int, char *[]) {
// Create a grid
vtkSmartPointer<vtkUniformGrid> uniformGrid =
vtkSmartPointer<vtkUniformGrid>::New();
unsigned int voxelsPerDimension = 2;
// The "+1"s are because this is setting how many points are in the grid, and
// the cells are implied by the points
uniformGrid->SetDimensions(voxelsPerDimension + 1, voxelsPerDimension + 1,
voxelsPerDimension + 1);
uniformGrid->SetSpacing(1., 1., 1.);
uniformGrid->SetOrigin(0.0, 0.0, 0.0);
uniformGrid->BlankCell(0);
uniformGrid->Modified();
vtkSmartPointer<vtkXMLImageDataWriter> imageDataWriter =
vtkXMLImageDataWriter::New();
imageDataWriter->SetInputData(uniformGrid);
imageDataWriter->SetFileName("uniformgrid.vti");
imageDataWriter->Write();
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment