Menu

vector/vertex array data

pk_gsa
2005-06-21
2013-05-20
  • pk_gsa

    pk_gsa - 2005-06-21

    Hi all,

    Can anyone give me a tip on how to use TinyXML to output a series of cartesian coordinates. I have an std::vector of Wild Magic Vector3's and I'd like to take this code:

    TiXmlText text( ? );
    for ( std::vector<Wm3::Vector3>::iterator Iter = data.begin(); Iter != data.end(); Iter++ )
    {
      // Iter->X() etc..
    }

    e.InsertEndChild( text );  // TiXmlElement e

    to the point where it outputs something like:

    ...
    <vertices>
    ...
    1.2 3.4 5.6
    7.8 9.0 1.2
    2.3 3.4 5.6
    ...
    </vertices>
    ...

    Can anyone offer advice?
    Paul

     
    • Lee Thomason

      Lee Thomason - 2005-06-21

      I would think you would want a format something like this:

      <vertices>
      <vertex x="1" y="2" ="1" />
      <vertex x="1" y="2" ="1" />
      <vertex x="1" y="2" ="1" />
      </vertices>

      Have a "vertices" Element that contains any number of "vertex" elements, where each coordinate is an attribute. There may be standards on this sort of thing, but I'm not sure where to point you for that.

      lee

       
    • pk_gsa

      pk_gsa - 2005-07-01

      I'm keen to keep to the simpler formation to allow cut 'n' pasting from other text file sources, i.e I hope to keep the vertex list like:

      1.2 3.4 5.6
      7.8 9.0 1.2
      2.3 3.4 5.6

      which is similar to the collada format's method.

      Anyway, my code now looks like this:

      std::string DataString;
      TiXmlElement elemArray( ELEM_ARRAY_NAME );

      for ( int i = 0; i < iter->GetData().size(); i++ )
      {
      char buffer[255];
      sprintf( buffer, "%f %f %f\n", iter->GetData().at(i).X(), iter->GetData().at(i).Y(), iter->GetData().at(i).Z() );
      DataString += buffer;
      }

      TiXmlText textArray( DataString );
      elemArray.InsertEndChild( textArray );

      But when I examine the resulting XML file it contains &#x0A; instead of newlines. Can someone help me round this problem? Collada's XML files do not have this condition.

      Thankyou,
      Paul

       
      • Ellers

        Ellers - 2005-07-01

        The \x0A thing is surely half of a DOS newline \r\n pair?

        BTW if you're already using STL you could use ostrstream to output the numbers too. FWIW

        Although I'm no fan of STL and the stream operators in particular it can be a good way to write and read blocks of numbers like this (short of writing a C++ StreamTokenizer class, which is a better way IMO :)

        Ellers

         

Log in to post a comment.