int main( int argc, char *argv[] )
{
if( argc != 2 )
{
std::cerr << "Usage: " << argv[0] << " outputimagefile " << std::endl;
return EXIT_FAILURE;
}
using PixelType = signed short;
GroupType, ImageType >;
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();
TubeType::Pointer tube1 = TubeType::New();
TubeType::Pointer tube2 = TubeType::New();
ellipse->SetRadiusInObjectSpace( size[0] * 0.2 * spacing[0] );
typename TubeType::TubePointType tubePoint;
typename TubeType::TubePointListType tubePointList;
point[0] = size[0] * 0.2 * spacing[0];
point[1] = size[1] * 0.2 * spacing[1];
tubePoint.SetPositionInObjectSpace( point );
tubePoint.SetRadiusInObjectSpace( size[0] * 0.05 * spacing[0] );
tubePointList.push_back( tubePoint );
point[0] = size[0] * 0.8 * spacing[0];
point[1] = size[1] * 0.2 * spacing[1];
tubePoint.SetPositionInObjectSpace( point );
tubePoint.SetRadiusInObjectSpace( size[0] * 0.05 * spacing[0] );
tubePointList.push_back( tubePoint );
tube1->SetPoints( tubePointList );
tubePointList.clear();
point[0] = size[0] * 0.2 * spacing[0];
point[1] = size[1] * 0.8 * spacing[1];
tubePoint.SetPositionInObjectSpace( point );
tubePoint.SetRadiusInObjectSpace( size[0] * 0.05 * spacing[0] );
tubePointList.push_back( tubePoint );
point[0] = size[0] * 0.8 * spacing[0];
point[1] = size[1] * 0.8 * spacing[1];
tubePoint.SetPositionInObjectSpace( point );
tubePoint.SetRadiusInObjectSpace( size[0] * 0.05 * spacing[0] );
tubePointList.push_back( tubePoint );
tube2->SetPoints( tubePointList );
using TransformType = GroupType::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;
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 );
tube1->SetObjectToParentTransform( transform2 );
tube2->SetObjectToParentTransform( transform3 );
GroupType::Pointer group = GroupType::New();
group->AddChild( ellipse );
group->AddChild( tube1 );
group->AddChild( tube2 );
ellipse->Update();
tube1->Update();
tube2->Update();
imageFilter->SetInput( group );
const PixelType airHounsfieldUnits = -1000;
constexpr PixelType boneHounsfieldUnits = 800;
ellipse->SetDefaultInsideValue( boneHounsfieldUnits );
tube1->SetDefaultInsideValue( boneHounsfieldUnits );
tube2->SetDefaultInsideValue( boneHounsfieldUnits );
ellipse->SetDefaultOutsideValue( airHounsfieldUnits );
tube1->SetDefaultOutsideValue( airHounsfieldUnits );
tube2->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;
}