2 #include "itkSphereSpatialFunction.h"
3 #include <itkImageRegionIterator.h>
4 #include "itkImageFileWriter.h"
6 int main(int argc, char** argv) {
8 const unsigned int dim = 3;
9 typedef char PixelType;
10 typedef itk::Image<PixelType, dim> ImageType;
11 typedef ImageType::IndexType IndexType;
12 typedef ImageType::PointType PointType;
13 typedef ImageType::SizeType SizeType;
14 typedef ImageType::RegionType RegionType;
20 size[0] = atoi(argv[2]);
21 size[1] = atoi(argv[3]);
22 size[2] = atoi(argv[4]);
25 origin[0] = atoi(argv[5]);
26 origin[1] = atoi(argv[6]);
27 origin[2] = atoi(argv[7]);
30 region.SetIndex(index);
33 ImageType::Pointer image = ImageType::New();
34 image->SetRegions(region);
37 typedef itk::SphereSpatialFunction<dim, PointType> ShpereFunctionType;
38 ShpereFunctionType::Pointer sphere = ShpereFunctionType::New();
40 double radius = atof(argv[8])/2;
41 sphere->SetCenter(origin);
42 sphere->SetRadius(radius);
44 PixelType max = itk::NumericTraits<PixelType>::max();
45 typedef itk::ImageRegionIterator<ImageType> ImageIteratorType;
46 ImageIteratorType it(image, region);
48 for (it.GoToBegin(); !it.IsAtEnd(); ++it) {
49 image->TransformIndexToPhysicalPoint(it.GetIndex(), point);
50 if (sphere->Evaluate(point)) {
51 PixelType value = static_cast<PixelType>(max*(point - origin).GetNorm()/radius);
58 typedef itk::ImageFileWriter<ImageType> ImageWriterType;
59 ImageWriterType::Pointer writer = ImageWriterType::New();
60 writer->SetInput(image);
61 writer->SetFileName(argv[1]);