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 ] = 150;
ImageType::SpacingType spacing;
spacing[0] = 100.0 / size[0];
spacing[1] = 100.0 / size[1];
spacing[2] = 300.0 / size[2];
imageFilter->SetSpacing( spacing );
EllipseType::Pointer ellipse = EllipseType::New();
CylinderType::Pointer cylinder1 = CylinderType::New();
CylinderType::Pointer cylinder2 = CylinderType::New();
ellipse->SetRadius( size[0] * 0.2 * spacing[0] );
cylinder1->SetRadius( size[0] * 0.2 * spacing[0] );
cylinder2->SetRadius( size[0] * 0.2 * spacing[0] );
cylinder1->SetHeight( size[2] * 0.30 * spacing[2]);
cylinder2->SetHeight( size[2] * 0.30 * spacing[2]);
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 );
ellipse->SetObjectToParentTransform( transform1 );
cylinder1->SetObjectToParentTransform( transform2 );
cylinder2->SetObjectToParentTransform( transform3 );
GroupType::Pointer group = GroupType::New();
group->AddSpatialObject( ellipse );
group->AddSpatialObject( cylinder1 );
group->AddSpatialObject( cylinder2 );
imageFilter->SetInput( group );
const PixelType airHounsfieldUnits = -1000;
const PixelType boneHounsfieldUnits = 800;
ellipse->SetDefaultInsideValue( boneHounsfieldUnits );
cylinder1->SetDefaultInsideValue( boneHounsfieldUnits );
cylinder2->SetDefaultInsideValue( boneHounsfieldUnits );
ellipse->SetDefaultOutsideValue( airHounsfieldUnits );
cylinder1->SetDefaultOutsideValue( airHounsfieldUnits );
cylinder2->SetDefaultOutsideValue( airHounsfieldUnits );
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;
}