int main( int argc, char *argv[] )
{
if( argc != 2 )
{
std::cerr << "Usage: " << argv[0] << " outputimagefile " << std::endl;
return EXIT_FAILURE;
}
typedef signed short PixelType;
GroupType, ImageType > SpatialObjectToImageFilterType;
SpatialObjectToImageFilterType::Pointer imageFilter =
SpatialObjectToImageFilterType::New();
size[ 0 ] = 50;
size[ 1 ] = 50;
size[ 2 ] = 200;
ImageType::SpacingType spacing;
spacing[0] = 100.0 / size[0];
spacing[1] = 100.0 / size[1];
spacing[2] = 400.0 / size[2];
imageFilter->SetSpacing( spacing );
MetaBallType::Pointer metaBall1 = MetaBallType::New();
MetaBallType::Pointer metaBall2 = MetaBallType::New();
MetaBallType::Pointer metaBall3 = MetaBallType::New();
metaBall1->SetRadius( size[0] * spacing[0] * 0.2 );
metaBall2->SetRadius( size[0] * spacing[0] * 0.2 );
metaBall3->SetRadius( size[0] * spacing[0] * 0.2 );
metaBall1->SetMaximum( 1000.0 );
metaBall2->SetMaximum( 1000.0 );
metaBall3->SetMaximum( 1000.0 );
typedef GroupType::TransformType TransformType;
TransformType::Pointer transform1 = TransformType::New();
TransformType::Pointer transform2 = TransformType::New();
TransformType::Pointer transform3 = TransformType::New();
transform1->SetIdentity();
transform2->SetIdentity();
transform3->SetIdentity();
TransformType::OutputVectorType translation;
TransformType::CenterType center;
translation[ 0 ] = size[0] * spacing[0] / 2.0;
translation[ 1 ] = size[1] * spacing[1] / 4.0;
translation[ 2 ] = size[2] * spacing[2] / 2.0;
transform1->Translate( translation, false );
translation[ 1 ] = size[1] * spacing[1] / 2.0;
translation[ 2 ] = size[2] * spacing[2] * 0.22;
transform2->Translate( translation, false );
translation[ 2 ] = size[2] * spacing[2] * 0.78;
transform3->Translate( translation, false );
metaBall1->SetObjectToParentTransform( transform1 );
metaBall2->SetObjectToParentTransform( transform2 );
metaBall3->SetObjectToParentTransform( transform3 );
GroupType::Pointer group = GroupType::New();
group->AddSpatialObject( metaBall1 );
group->AddSpatialObject( metaBall2 );
group->AddSpatialObject( metaBall3 );
imageFilter->SetInput( group );
const PixelType airHounsfieldUnits = -1000;
imageFilter->SetUseObjectValue( true );
imageFilter->SetOutsideValue( airHounsfieldUnits );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[1] );
writer->SetInput( imageFilter->GetOutput() );
try
{
imageFilter->Update();
writer->Update();
}
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}