GDCM  2.4.3
CreateFakeRTDOSE.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkImageReader.h"
#include "vtkImageCast.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkMedicalImageProperties.h"
#include "gdcmTrace.h"
/*
* Minimal example to create a fake RTDOSE file. The data contains a sphere
* just for testing.
* The vtkMedicalImageProperties is not properly filled, but only contains a
* single field which is required to set the proper SOP Class
*/
int main(int, char *[])
{
//gdcm::Trace::DebugOn();
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.; // just for fun => max == 10.
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()->SetModality( "RTDOSE" );
writer->SetScale( 0.0042 ); // why not
writer->Write();
image->Delete();
writer->Delete();
return 0;
}