Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at this code : </p> <pre><code>//! Struct for a 2d marker struct Marker2d{ double x; //!&lt; x coordinate of marker in calibration phantom double y; //!&lt; y coordinate of marker in calibration phantom int id; //!&lt; some unique id (used for sequence id as well as for assigned 3d id) int code; //!&lt; type of marker (small = 0, large = 1) float size; //!&lt; real size of marker in 2D image (in pixel) double distanceToNearest; //!&lt; distance to nearest other marker /** * Overloaded stream insertion operator. Abbreviation for the output of 2d marker. \param output_out A reference to an std::ostream instance indicating the output stream \param marker_in A constant Marker2d reference indicating the 2d marker that we want to output \return a std::ostream reference containing the new output data */ friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; output_out, const Marker2d &amp; marker_in) { return output_out&lt;&lt; std::fixed &lt;&lt; std::setprecision(15) &lt;&lt;marker_in.x&lt;&lt;"\t"&lt;&lt;marker_in.y&lt;&lt;"\t"&lt;&lt;marker_in.id&lt;&lt;"\t" &lt;&lt;marker_in.code&lt;&lt;"\t"&lt;&lt;marker_in.size&lt;&lt;"\t"&lt;&lt;marker_in.distanceToNearest; } /** * Overloaded stream extraction operator. \param s_in A reference to an std::istream instance indicating the input stream \param marker_out A Marker2d reference indicating the 2d marker that will have its data members populated \return a std::istream reference indicating the input stream */ friend std::istream&amp; operator&gt;&gt;(std::istream&amp; s_in, Marker2d &amp; marker_out) { s_in &gt;&gt; marker_out.x &gt;&gt; marker_out.y &gt;&gt; marker_out.id &gt;&gt; marker_out.code &gt;&gt; marker_out.size &gt;&gt; marker_out.distanceToNearest; return s_in; } }; </code></pre> <p>This is a simple struct with overloaded >> and &lt;&lt; operators. This allows you to output to a file like myOfstreamFile &lt;&lt; obj; And read the other way around.</p> <p>If you have say, a thousand of objects stored in a file you can simply put them in a container like this : </p> <pre><code>std::vector&lt;Marker2d&gt; myMarkers; std::ifstream f( fileName_in.c_str() ); if(!f) throw std::exception(std::string("AX.Algorithms.ComputeAssignmentsTest::getMarkersFromFile - Could not open file : " + fileName_in + " for reading!").c_str()); //cool one liner to read objects from file... std::copy(std::istream_iterator&lt;AX::Calibration::Marker2d&gt;(f), std::istream_iterator&lt;AX::Calibration::Marker2d&gt;(), std::back_inserter(myMarkers)); </code></pre> <p>Of course you could provide other forms of input and output e.g. save to .xml format and parse it as a dom tree etc. This is just a sample.</p> <p><strong>EDIT : This will work for relatively simple objects. Look at serialization if you need something more complex</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload