[Insight-users] WriteFile() error
wordon
m9421001 at gmail.com
Thu Nov 3 08:26:00 EST 2005
Hi,all:
I am trying my program as follows,
but when I write data into file....
it can't process correctly.
I think the matter maybe in 'SetObject'..
but I can not set it correctly.
Please help me and give me some point.
Thanks. : )
My code :
======================================
#include "itkPolygonGroupSpatialObject.h"
#include "itkPolygonSpatialObject.h"
#include <iostream>
#include "itkPolygonGroupSpatialObjectXMLFile.h"
#include <itksys/SystemTools.hxx>
static float points[11][2] =
{
{1,1},{1,2},{1.25,2},{1.25,1.25},{1.75,1.25},
{1.75,1.5},{1.5,1.5},{1.5,2},{2,2},{2,1},{1,1}
};
typedef itk::PolygonSpatialObject<3> Polygon3DType;
typedef itk::PolygonGroupSpatialObject<3> PolygonGroup3DType;
typedef PolygonGroup3DType::Pointer PolygonGroup3DPointer;
int buildPolygonGroup(PolygonGroup3DPointer &PolygonGroup)
{
try
{
for(float z = 0.0; z <= 10.0; z += 1.0)
{
itk::PolygonSpatialObject<3>::Pointer strand
= itk::PolygonSpatialObject<3>::New();
if(!PolygonGroup->AddStrand(strand))
{
std::cerr << "Error adding point" << std::endl;
return EXIT_FAILURE;
}
strand->SetThickness(1.0);
//
// add all points to this strand.
for(int i = 0; i < 11; i++)
{
double pos[3];
pos[0] = points[i][0];
pos[1] = points[i][1];
pos[2] = z;
itk::PolygonSpatialObject<3>::PointType curpoint(pos);
if(!strand->AddPoint(curpoint))
{
std::cerr << "Error adding point" << std::endl;
return EXIT_FAILURE;
}
}
}
}
catch(itk::ExceptionObject &)
{
std::cerr << "Error creating PolygonGroup" << std::endl;
return EXIT_FAILURE;
}
std::cout<<"buildGroupOK!"<<std::endl;
return EXIT_SUCCESS;
}
int itkPolygonGroupSpatialObjectXMLFileTest()
{
PolygonGroup3DPointer PolygonGroup = PolygonGroup3DType::New();
// PolygonGroup3DPointer PGroupFromFile;
if(buildPolygonGroup(PolygonGroup) != 0 || PolygonGroup.IsNull())
{
std::cerr << "Error building polygon group" << std::endl;
return EXIT_FAILURE;
}
std::string xmlfilename("out");
xmlfilename = xmlfilename + "/PolygonGroupSpatialObjectXMLFileTest.xml";
try
{
itk::PolygonGroupSpatialObjectXMLFileWriter::Pointer pw =
itk::PolygonGroupSpatialObjectXMLFileWriter::New();
std::cout<<"a"<<std::endl;
pw->SetFilename(xmlfilename.c_str());
std::cout<<"b"<<std::endl;
pw->SetObject(&(*PolygonGroup));
std::cout<<"c"<<std::endl;
pw->WriteFile();
std::cout<<"d"<<std::endl;
}
catch(itk::ExceptionObject &)
{
std::cerr << "Error Creating file" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
void main()
{
itkPolygonGroupSpatialObjectXMLFileTest();
}
================================================
More information about the Insight-users
mailing list