[Insight-users] How to write a XML file ?

wordon m9421001 at gmail.com
Tue Nov 1 12:07:30 EST 2005


Hi,Luis and all:

I am writing a source code that based on
PolygonGroupSpatialObjectXMLFileTest.cxx in ITK.
The function in my code is input 3D coordinate from txt file and
output a XML format file.
I am using 'itk::PolygonSpatialObject<3>::PointType' to save values form file,
and using 'AddPoint' to add point into 'itk::PolygonSpatialObject<3>::Pointer'.
But I encounter some warning when I compiling this code under VC6.0.
I am so confusing regarding how to build a PloygonSpatialObject
and assign the object into PolygonGroupSpatialObjectXMLFileWriter.
Have any body can help me?

Kind Regards.

My source code:
===============================================================
#include <fstream>
#include <iostream>
#include "itkPolygonGroupSpatialObject.h"
#include "itkPolygonSpatialObject.h"
#include "itkPolygonGroupSpatialObjectXMLFile.h"
#include <itksys/SystemTools.hxx>


int main(int ac, char *av[])
{
	if(ac<2)
	{
		std::cerr<<"Usage:"<<av[0]<<" XMLfile\n";
		return	EXIT_FAILURE;
	}

	typedef itk::PolygonSpatialObject<3> Polygon3DType;
	typedef itk::PolygonGroupSpatialObject<3> PolygonGroup3DType;
	typedef PolygonGroup3DType::Pointer PolygonGroup3DPointer;

	const char* filename="C:\\tt.txt";
	std::ifstream inFile(filename);

	if(!inFile)
	{
		std::cout<<std::endl<<"Failed to open file"<<filename;
		return 1;
	}	

	double aprime=0;
	int count=0;
	double	apr_array[22];

	int i=0,j=0;

	while(!inFile.eof())
	{
		inFile>>aprime;
		apr_array[i]=aprime;
		i++;
	}//read value from file

	for(j=0;j<22;j++)
		std::cout<<apr_array[j]<<std::endl;//display value from array

//========================================================================================
   try	//build a PloygonSpatialObject
   {
	
	   itk::PolygonSpatialObject<3>::Pointer strand
		   =itk::PolygonSpatialObject<3>::New();  //***

	   strand->SetThickness(1.0);

	for(i=0;i<22;i=i+2)
	{
		double	pos[3];
		pos[0]=apr_array[i];
		pos[1]=apr_array[i+1];
		pos[2]=0;
		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 adding point"<<std::endl;
	   return EXIT_FAILURE;
   }
//===============================================================


   PolygonGroup3DPointer PolygonGroup=PolygonGroup3DType::New();


  	 std::string xmlfilename(av[1]);
 	 xmlfilename = xmlfilename + ".xml";
 	
	   try
	   {
		   itk::PolygonGroupSpatialObjectXMLFileWriter::Pointer pw
			   =itk::PolygonGroupSpatialObjectXMLFileWriter::New();

    	   pw->SetFilename(xmlfilename.c_str());
    	   pw->SetObject(&(*strand));
           pw->WriteFile();
	   }

  	catch(itk::ExceptionObject &)
    	 {
    	  std::cerr << "Error Creating file" << std::endl;
    	  return EXIT_FAILURE;
    	 }

	return EXIT_SUCCESS;


}

The warning as follows:
=================================================================
--------------------Configuration: p2x - Win32 Debug--------------------
Compiling...
PointToXML.cxx
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::binary_function<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> const ,itk::SmartPointer<itk::MetaDataObjectBase> >,std::pair<std
::basic_string<char,std::char_traits<char>,std::allocator<char> >
const ,itk::SmartPointer<itk::MetaDataObjectBase> >,bool>' :
identifier was truncated to '255' characters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> const
,itk::SmartPointer<itk::MetaDataObjectBase>
>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,s
td::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> > >' :
identifier was truncated to '255' ch
aracters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> const
,itk::SmartPointer<itk::MetaDataObjectBase>
>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,s
td::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::const_iterator' : identifier was trunc
ated to '255' characters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> const
,itk::SmartPointer<itk::MetaDataObjectBase>
>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,s
td::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::iterator' : identifier was truncated t
o '255' characters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> const
,itk::SmartPointer<itk::MetaDataObjectBase>
>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,s
td::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Node' : identifier was truncated to '
255' characters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> const
,itk::SmartPointer<itk::MetaDataObjectBase>
>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,s
td::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>
> >,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::_Redbl' : identifier was truncated to
'255' characters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_t
raits<char>,std::allocator<char> >
>,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> > >' :
identifier was truncated to '255' characters in the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_t
raits<char>,std::allocator<char> >
>,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> >
>::value_compare' : identifier was truncated to '255' characters in
the debug information
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(34) :
warning C4786: 'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,itk::SmartPointer<itk::MetaDataObjectBase>,std::less<std::basic_string<char,std::char_t
raits<char>,std::allocator<char> >
>,std::allocator<itk::SmartPointer<itk::MetaDataObjectBase> > >::_Kfn'
: identifier was truncated to '255' characters in the debug
information
Linking...
--------------------Configuration: ALL_BUILD - Win32 Debug--------------------
Building Custom Rule D:\ITK\itk_ex_2.2.0\PointToXML\bin\ALL_BUILD_force_1.rule
"Build all projects"
=================================================================


More information about the Insight-users mailing list