[Insight-users] Using MetaIO for trees of TubeSpatialObjects
Dan Mueller
d.mueller at qut.edu.au
Fri Feb 3 02:17:58 EST 2006
Hi all,
I have some questions regarding the itk::SpatialObject classes.
I have a simple application which creates a tree of itk::TubeSpatialObjects (please find source code attached).
This application creates tube1 and tube1_1, calls tube1->AddSpatialObject(tube1_1), and uses the itk::MetaTubeConverter to save the object as a Meta file (*.mhd).
However, the itk::MetaTubeConverter does not write the itk:SpatialObject child nodes to the Meta file (see output Meta file below).
How do I save the entire tube network to a Meta file?
Am I missing something with the itk::SpatialObject::AddSpatialObject(..) call? I have tried using itk::TubeSpatialObject::SetParentPoint(..) and itk::TubeSpatialObject::SetRoot(..) but I can't seem to make them work either. Should I be using a different Meta converter class, like itk::MetaGroupConverter? Am I on the right track, or did I miss the point somewhere?
Any help would be appreciated!
Output Meta file (note that only tube1 is written):
--------------------
ObjectType = Tube
NDims = 3
Color = 1 0 0 1
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
ElementSpacing = 1 1 1
Root = False
PointDim = x y z r v1x v1y v1z v2x v2y v2z tx ty tz red green blue alpha id
NPoints = 5
Points =
10.5 10 15 4 0 0 0 0 0 0 0 0 0 1 0 0 1 -1
50 30.5 30 2 0 0 0 0 0 0 0 0 0 1 0 0 1 -1
65 45.5 30 3 0 0 0 0 0 0 0 0 0 1 0 0 1 -1
100 115 60 2 0 0 0 0 0 0 0 0 0 1 0 0 1 -1
170 60 200 1.55 0 0 0 0 0 0 0 0 0 1 0 0 1 -1
--------------------
Note: I am using Windows XP, ITK v2.4.1, VC++ 2003.
Cheers
Dan Mueller [d.mueller at qut.edu.au]
School of Engineering Systems
Faculty of Built Environment and Engineering
Queensland University of Technology (QUT)
Brisbane, Queensland, Australia
CRICOS No.: 00213J
-------------- next part --------------
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkGroupSpatialObject.h"
#include "itkLineSpatialObject.h"
#include "itkEllipseSpatialObject.h"
#include "itkLineSpatialObjectPoint.h"
#include "itkTubeSpatialObject.h"
#include "itkTubeSpatialObjectPoint.h"
#include "itkMetaTubeConverter.h"
int main(int argc, char * argv[])
{
try
{
//Check the input arguments:
// 0 = Application name
// 1 = Output meta file path
if (argc != 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " OutputMetaFile" << std::endl;
return EXIT_FAILURE;
}
//Declare pixel and image types
const unsigned int Dimension = 3;
typedef unsigned char PixelType;
typedef itk::Image<PixelType, Dimension> ImageType;
//Declare SpatialObject types
typedef itk::GroupSpatialObject<Dimension> GroupType;
typedef itk::EllipseSpatialObject<Dimension> EllipseType;
typedef itk::LineSpatialObject<Dimension> LineType;
typedef itk::LineSpatialObjectPoint<Dimension> LinePointType;
typedef itk::TubeSpatialObject<Dimension> TubeType;
typedef itk::TubeSpatialObjectPoint<Dimension> TubePointType;
//Create some tube points
TubePointType point1_1;
point1_1.SetPosition(10.5, 10.0, 15.0);
point1_1.SetRadius(4.0);
TubePointType point1_2;
point1_2.SetPosition(50, 30.5, 30.0);
point1_2.SetRadius(2.0);
TubePointType point1_3;
point1_3.SetPosition(65.0, 45.5, 30.0);
point1_3.SetRadius(3.0);
TubePointType point1_4;
point1_4.SetPosition(100.0, 115.0, 60.0);
point1_4.SetRadius(2.0);
TubePointType point1_5;
point1_5.SetPosition(170.0, 60.0, 200.0);
point1_5.SetRadius(1.55);
TubePointType point1_1_1;
point1_1_1.SetPosition(100.0, 115.0, 60.0);
point1_1_1.SetRadius(2.0);
TubePointType point1_1_2;
point1_1_2.SetPosition(65.0, 130.0, 60.0);
point1_1_2.SetRadius(1.0);
TubePointType point1_1_3;
point1_1_3.SetPosition(35.0, 130.0, 90.0);
point1_1_3.SetRadius(3.5);
//Create "root" tube
TubeType::Pointer tube1 = TubeType::New();
tube1->GetPoints().push_back(point1_1);
tube1->GetPoints().push_back(point1_2);
tube1->GetPoints().push_back(point1_3);
tube1->GetPoints().push_back(point1_4);
tube1->GetPoints().push_back(point1_5);
//Create the "child" tube
TubeType::Pointer tube1_1 = TubeType::New();
tube1_1->GetPoints().push_back(point1_1_1);
tube1_1->GetPoints().push_back(point1_1_2);
tube1_1->GetPoints().push_back(point1_1_3);
//Add child tube to root tube
tube1->SetRoot(true);
tube1->AddSpatialObject(tube1_1);
tube1->SetRoot(true);
tube1_1->SetParentPoint(3); //point1_4 is the parent point of tube1_1
//Print some debug info
char buffer[10];
std::cout << "Tube1 (the root) has " << itoa(tube1->GetNumberOfChildren(), buffer, 10) << " child\\children" << std::endl;
std::cout << "Tube1_1 (the child) HasParent=" << tube1_1->HasParent()<< std::endl;
//Write SpatialObject to Meta file
itk::MetaTubeConverter<Dimension> metaWriter;
metaWriter.WriteMeta(tube1, argv[1]);
}
catch (itk::ExceptionObject & err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}//end main()
More information about the Insight-users
mailing list