From bdb12be100fd21ca8e8a1b82ad064733d06ed033 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Tue, 21 Jun 2011 20:12:50 +0200 Subject: [PATCH] simple tool to create an image with a sphere - still to be improved --- tools/clitkMakeSphereImage.cxx | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/clitkMakeSphereImage.cxx diff --git a/tools/clitkMakeSphereImage.cxx b/tools/clitkMakeSphereImage.cxx new file mode 100644 index 0000000..f018b95 --- /dev/null +++ b/tools/clitkMakeSphereImage.cxx @@ -0,0 +1,63 @@ +#include "itkImage.h" +#include "itkSphereSpatialFunction.h" +#include +#include "itkImageFileWriter.h" + +int main(int argc, char** argv) { + + const unsigned int dim = 3; + typedef char PixelType; + typedef itk::Image ImageType; + typedef typename ImageType::IndexType IndexType; + typedef typename ImageType::PointType PointType; + typedef typename ImageType::SizeType SizeType; + typedef typename ImageType::RegionType RegionType; + + IndexType index; + index.Fill(0); + + SizeType size; + size[0] = atoi(argv[2]); + size[1] = atoi(argv[3]); + size[2] = atoi(argv[4]); + + PointType origin; + origin[0] = atoi(argv[5]); + origin[1] = atoi(argv[6]); + origin[2] = atoi(argv[7]); + + RegionType region; + region.SetIndex(index); + region.SetSize(size); + + typename ImageType::Pointer image = ImageType::New(); + image->SetRegions(region); + image->Allocate(); + + typedef itk::SphereSpatialFunction ShpereFunctionType; + typename ShpereFunctionType::Pointer sphere = ShpereFunctionType::New(); + + double radius = atof(argv[8])/2; + sphere->SetCenter(origin); + sphere->SetRadius(radius); + + PixelType max = itk::NumericTraits::max(); + typedef itk::ImageRegionIterator ImageIteratorType; + ImageIteratorType it(image, region); + PointType point; + for (it.GoToBegin(); !it.IsAtEnd(); ++it) { + image->TransformIndexToPhysicalPoint(it.GetIndex(), point); + if (sphere->Evaluate(point)) { + PixelType value = static_cast(max*(point - origin).GetNorm()/radius); + it.Set(value); + } + else + it.Set(0); + } + + typedef itk::ImageFileWriter ImageWriterType; + typename ImageWriterType::Pointer writer = ImageWriterType::New(); + writer->SetInput(image); + writer->SetFileName(argv[1]); + writer->Update(); +} \ No newline at end of file -- 2.47.1