[ITK] itk::Point extraction operator

Wood, Tobias tobias.wood at kcl.ac.uk
Tue Jan 19 06:09:09 EST 2016


Thanks for replying Dženan. In this case I was trying to print an itk::Point (an image origin) from one utility and read it in another using a shell script. For other reasons I ended up re-writing the first utility so it prints without the [,] format, so it now works.

Toby

From: Dženan Zukić <dzenanz at gmail.com<mailto:dzenanz at gmail.com>>
Date: Monday, 18 January 2016 16:25
To: Tobias Wood <tobias.wood at kcl.ac.uk<mailto:tobias.wood at kcl.ac.uk>>
Cc: "community at itk.org<mailto:community at itk.org>" <community at itk.org<mailto:community at itk.org>>
Subject: Re: [ITK] itk::Point extraction operator

Hi Tobias,

the >> operator is meant to be used for human provided input, while << operator tries to have a nice formatting. Correctly passing points through streams was obviously not considered frequent/important use-case.

Regards,
Dženan

On Mon, Jan 18, 2016 at 5:19 AM, Wood, Tobias <tobias.wood at kcl.ac.uk<mailto:tobias.wood at kcl.ac.uk>> wrote:
Hello,

While trying to read an itk::Point from stdin, I noticed that the insertion and extraction operators are asymmetric. The insertion operator adds [] round the point and uses commas for delimiters. The extraction operator only expects numbers with white-space as the delimiter. Hence the following code:

itk::Point<float, 3> A; A[0] = 1.; A[1] = 2.; A[2] = 3.;
        itk::Point<float, 3> B;
        std::stringstream stream;
        stream << A;
        stream >> B;
        std::cout << "A = " << A << std::endl;
        std::cout << "B = " << B << std::endl;


Produces this as output:

A = [1, 2, 3]
B = [0, 0, 0]


with no errors or exceptions thrown.

Is this intended behaviour? It was counter-intuitive to me - but in my experience dealing with formatted input via the extraction operator is a complete pain so I can understand why it was written like this! I found an interesting workaround which involves a custom locale on this Stack Overflow page - http://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring

Best wishes,
Toby
_______________________________________________
Community mailing list
Community at itk.org<mailto:Community at itk.org>
http://public.kitware.com/mailman/listinfo/community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160119/4ae4e711/attachment.html>


More information about the Community mailing list