[Insight-users] Pointset File read and Write

TienGarry gjtian at hotmail.com
Fri Dec 12 03:12:37 EST 2008


Hi all,
I write a piont set by ofstream like this:
 
        typedef itk::PointSet< float, Dimension >   PointSetType;
 
        typedef PointSetType::PointType     PointType;
 
        std::cout << "begin write point set ..." << std::endl;
 
        std::ofstream skeltonPointsFile;        skeltonPointsFile.open( argv[7] );                typedef PointSetType::PointsContainer PointsContainer;        PointsContainer::Pointer points = SkelPointSet->GetPoints();        typedef PointsContainer::Iterator     PointsIterator;        PointsIterator  pointIterator = points->Begin();        PointsIterator end = points->End();        while( pointIterator != end )         {            PointType p = pointIterator.Value();   // access the point            skeltonPointsFile << p;           // print the point            ++pointIterator;        }                skeltonPointsFile.close();
        std::cout << "write point set done..." << std::endl;
 
 
I can open the pointset txt file, the points are saved as following format:
[-104.98, -144.511, -1035.9][133.301, -144.511, -1035.9]
 
when I want to read it out to a pointset, my code as folloing:
 
typedef itk::PointSet< float, Dimension >   PointSetType;
typedef PointSetType::PointType     PointType;
PointType fixedPoint;
 
 std::ifstream   fixedFile;    fixedFile.open( argv[1] );    if( fixedFile.fail() )    {        std::cerr << "Error opening points file with name : " << std::endl;        std::cerr << argv[1] << std::endl;        return 2;    }
unsigned int pointId = 0;    fixedFile >> fixedPoint;    while( !fixedFile.eof() )    {        fixedPointContainer->InsertElement( pointId, fixedPoint );        fixedFile >> fixedPoint;        pointId++;    }    fixedPointSet->SetPoints( fixedPointContainer );    std::cout <<         "Number of fixed Points = " << fixedPointSet->GetNumberOfPoints()         << std::endl;
 
But I can not read the points correctly, dose anyone can help me?
Thx.
_________________________________________________________________
新版客服页面提供最新MSN客服资讯,助您轻松解决问题。
http://help.cn.msn.com/Cs.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081212/173d09d8/attachment-0001.htm>


More information about the Insight-users mailing list