[Insight-users] Programming challenges with QT, VTK, and ITK

Stuart Golodetz itk at gxstudios.net
Wed Oct 27 09:22:57 EDT 2010


On 27/10/2010 02:06, Xiaopeng Yang wrote:
>
> Dear Luis,
>
> How are you doing? Thank you very much for your help so far. Sorry to 
> ask you a question again.
>
> I am now developing a liver segmentation program using QT, VTK, and 
> ITK based on CT images. In my program, fast marching algorithm is used 
> to extract the liver by multiple seed points. To pick the positions of 
> the seed points, vtkImagePlaneWidget is applied. The problem is how to 
> save the multiple seed points I selected by left-clicking of the mouse 
> so that I do not need to type those positions into the code, which is 
> time consuming.
>
> Please provide me with your suggestions. I working on this for almost 
> one week still I cannot figure it out.
>
> Thanks,
>
> Xiaopeng
>

Hi Xiaopeng,

Luis may well have a simpler/better way of doing this, but for what it's 
worth in the meantime -- if you know how to access the seed points in 
the code, then you can just save/load them the way you'd save/load 
anything else. In other words, just use normal C++ file handling. 
There's an example below (you'd need to work out what format your seeds 
are in and adapt things accordingly).

There may be a more "ITK/VTK" way of handling this, in which case you 
might want to use that instead, but it's perfectly ok to just use the 
standard library for things like this.

Cheers,
Stu

#include <fstream>
#include <iostream>
#include <string>

#include <boost/lexical_cast.hpp>

struct Seed
{
     int x;
     int y;
     Seed() : x(0), y(0) {}
     Seed(int x_, int y_) : x(x_), y(y_) {}
};

std::ostream& operator<<(std::ostream& os, const Seed& rhs)
{
     os << rhs.x << ' ' << rhs.y;
     return os;
}

std::istream& operator>>(std::istream& is, Seed& rhs)
{
     char dummy;
     is >> rhs.x >> dummy >> rhs.y;
     return is;
}

void output_seeds(const std::string& filename)
{
     // More error-handling is needed here, this is just an example.
     std::ifstream fs(filename.c_str());
     std::string line;
     while(std::getline(fs, line))
     {
         try
         {
             std::cout << "Seed: " << boost::lexical_cast<Seed>(line) << 
'\n';
         }
         catch(boost::bad_lexical_cast&) {}
     }
}

void write_seeds(const std::string& filename)
{
     std::ofstream fs(filename.c_str());
     fs << Seed(23,9) << '\n';
     fs << Seed(24,12) << '\n';
}

int main()
{
     write_seeds("seeds.txt");
     output_seeds("seeds.txt");
     return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101027/1e427bf3/attachment.htm>


More information about the Insight-users mailing list