#include "vtkImageReader.h"
#include "vtkImageCast.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkMedicalImageProperties.h"
int main(int, char *[])
{
const vtkIdType xSize = 512;
const vtkIdType ySize = 512;
const vtkIdType zSize = 512;
vtkImageData *image = vtkImageData::New();
image->SetDimensions(xSize,ySize,zSize);
image->SetOrigin(-350.684,350.0,890.76);
image->SetSpacing(5.4688,-5.4688,-3.27);
#if VTK_MAJOR_VERSION <= 5
image->SetNumberOfScalarComponents(1);
image->SetScalarTypeToDouble();
#else
image->AllocateScalars(VTK_DOUBLE ,1);
#endif
double pt[3];
for( int z = 0; z < zSize; ++z )
for( int y = 0; y < ySize; ++y )
for( int x = 0; x < xSize; ++x )
{
pt[0] = x;
pt[1] = y;
pt[2] = z;
pt[0] -= xSize / 2;
pt[1] -= ySize / 2;
pt[2] -= zSize / 2;
pt[0] /= xSize / 2;
pt[1] /= ySize / 2;
pt[2] /= zSize / 2;
const double unit = pt[0] * pt[0] + pt[1] * pt[1] + pt[2] * pt[2];
const double inval = unit <= 1. ? (3 * unit + 7) : 0.;
double* pixel= static_cast<double*>(image->GetScalarPointer(x,y,z));
pixel[0] = inval;
}
writer->SetFileDimensionality( 3 );
writer->SetFileName( "rtdose.dcm" );
#if (VTK_MAJOR_VERSION >= 6)
writer->SetInputData( image );
#else
writer->SetInput( image );
#endif
writer->GetMedicalImageProperties()->SetSliceThickness("1.5");
writer->GetMedicalImageProperties()->AddUserDefinedValue( "Dose Units", "GY");
writer->GetMedicalImageProperties()->AddUserDefinedValue( "Dose Summation Type", "PLAN");
writer->GetMedicalImageProperties()->AddUserDefinedValue( "Dose Type", "PHYSICAL");
writer->GetMedicalImageProperties()->AddUserDefinedValue( "Frame of Reference UID", "1.3.12.2.1107.5.6.1.68100.30270111041215391275000000001");
writer->GetMedicalImageProperties()->SetModality( "RTDOSE" );
writer->SetScale( 0.0042 );
image->Delete();
writer->Delete();
framePointer.SetNumberOfValues(1);
return 0;
}