<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[String zerlegen] Gibt&#x27;s das auch in hübsch?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich arbeite gerade an einem Loader für .obj 3D-Models. In der Datei sind Polygone in der Form &quot;Vertexindex/Texcoordindex/Normalenindex&quot; abgelegt, z.B.:</p>
<pre><code>f 106/1/1 108/2/2 271/3/3
</code></pre>
<p>Dazu habe ich mir gestern folgenden Code zum Laden zusammengefrickelt:<br />
(Der Einfachheit halber beschränke ich mich bei den Models auf Dreiecke)</p>
<pre><code class="language-cpp">else if(linetype == &quot;f&quot;)				//the line contains face data
			{
				//each face is specified by a triplet of vertex-, texcoord- and normal-indices
				//seperated by a single slash
				//i.e. 10/200/3
				std::string vertexstring;

				for(int ii=0; ii&lt;=2; ii++)
				{
					Vertex vertex;

					linestream &gt;&gt; vertexstring; //linestream ist ein istringstream, der mit der aktuellen Dateizeile gefüttert wird

					//seperate data by '/'
					std::string::size_type slashpos = vertexstring.find_first_of(&quot;/&quot;);

					//read vertex index
					std::istringstream vertex_stream(vertexstring.substr(0, slashpos ));

					vertex_stream &gt;&gt; vertex.v_index;
					vertex_stream.clear();

					//read texcoord index
					std::string::size_type slashpos2 = vertexstring.find_first_of(&quot;/&quot;, slashpos + 1);

					vertex_stream.str(vertexstring.substr(slashpos + 1 , slashpos2 - slashpos - 1 )); 

					vertex_stream &gt;&gt; vertex.uv_index;
					vertex_stream.clear();

					//read normal index 
					vertex_stream.str(vertexstring.substr(slashpos2 + 1, vertexstring.length() - 1 ));

					vertex_stream &gt;&gt; vertex.n_index;

					m_faces.push_back(vertex);
				}

			}
</code></pre>
<p>Wie man unschwer erkennen kann, ist das Ganze nicht besonders lesbar und durch das häufige String-Kopieren wahrscheinlich auch nicht sonderlich performant.<br />
Hat jemand eine Idee wie man das schöner und schneller gestalten könnte?</p>
<p>Grüße</p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/210390/string-zerlegen-gibt-s-das-auch-in-hübsch</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 13:38:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/210390.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Apr 2008 13:26:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [String zerlegen] Gibt&#x27;s das auch in hübsch? on Thu, 10 Apr 2008 13:26:56 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich arbeite gerade an einem Loader für .obj 3D-Models. In der Datei sind Polygone in der Form &quot;Vertexindex/Texcoordindex/Normalenindex&quot; abgelegt, z.B.:</p>
<pre><code>f 106/1/1 108/2/2 271/3/3
</code></pre>
<p>Dazu habe ich mir gestern folgenden Code zum Laden zusammengefrickelt:<br />
(Der Einfachheit halber beschränke ich mich bei den Models auf Dreiecke)</p>
<pre><code class="language-cpp">else if(linetype == &quot;f&quot;)				//the line contains face data
			{
				//each face is specified by a triplet of vertex-, texcoord- and normal-indices
				//seperated by a single slash
				//i.e. 10/200/3
				std::string vertexstring;

				for(int ii=0; ii&lt;=2; ii++)
				{
					Vertex vertex;

					linestream &gt;&gt; vertexstring; //linestream ist ein istringstream, der mit der aktuellen Dateizeile gefüttert wird

					//seperate data by '/'
					std::string::size_type slashpos = vertexstring.find_first_of(&quot;/&quot;);

					//read vertex index
					std::istringstream vertex_stream(vertexstring.substr(0, slashpos ));

					vertex_stream &gt;&gt; vertex.v_index;
					vertex_stream.clear();

					//read texcoord index
					std::string::size_type slashpos2 = vertexstring.find_first_of(&quot;/&quot;, slashpos + 1);

					vertex_stream.str(vertexstring.substr(slashpos + 1 , slashpos2 - slashpos - 1 )); 

					vertex_stream &gt;&gt; vertex.uv_index;
					vertex_stream.clear();

					//read normal index 
					vertex_stream.str(vertexstring.substr(slashpos2 + 1, vertexstring.length() - 1 ));

					vertex_stream &gt;&gt; vertex.n_index;

					m_faces.push_back(vertex);
				}

			}
</code></pre>
<p>Wie man unschwer erkennen kann, ist das Ganze nicht besonders lesbar und durch das häufige String-Kopieren wahrscheinlich auch nicht sonderlich performant.<br />
Hat jemand eine Idee wie man das schöner und schneller gestalten könnte?</p>
<p>Grüße</p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1489741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1489741</guid><dc:creator><![CDATA[JimmydaMage]]></dc:creator><pubDate>Thu, 10 Apr 2008 13:26:56 GMT</pubDate></item><item><title><![CDATA[Reply to [String zerlegen] Gibt&#x27;s das auch in hübsch? on Thu, 10 Apr 2008 13:33:17 GMT]]></title><description><![CDATA[<p>Hier gibts eine gute Lösung um Strings zu trennen:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-190246-and-postdays-is-0-and-postorder-is-asc-and-highlight-is-trenner-and-start-is-11.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-190246-and-postdays-is-0-and-postorder-is-asc-and-highlight-is-trenner-and-start-is-11.html</a><br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1489746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1489746</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Thu, 10 Apr 2008 13:33:17 GMT</pubDate></item></channel></rss>