Scaling a 3D mesh (vertices, tetrahedra)

Started by
2 comments, last by Morrandir 15 years, 11 months ago
Hi guys, I am currently implementing an isosurface extracting algorithm for a 3D mesh (made of vertices and vertices collections -> tetrahedra). In order to add some flexibility i want to write a scale function that allows scaling up and down the length of the edges of the tetrahedra. My first attempt was taking the current edge length of the mesh (same for all edges), e.g. edgeLength = 1, scaling it up by 10% to 1.1, dividing new edgeLength by old edgeLength = 1.1/1 and using this scaleFactor to multiply with the coordinates of every vertex of the mesh: v_new.x = v_old.x * scaleFactor; v_new.y = v_old.y * scaleFactor; v_new.z = v_old.z * scaleFactor; This was apparently a foolish attempt. Are there any suggestions how to scale a mesh consistently. Thanks and greets
Advertisement
Hi,

could you clarify what is wrong with your method? As far as I can see, it should work perfectly if the mesh is centered at the origin, and should work in other cases as well, with the problem of offsetting the whole mesh somewhat.
Your question is absolutely right. I have to admit that i am using a mesh of tetrahedra of two shapes: one part is regular and the other has a rectangular form (meaning there are angles of 90 and 45 in it). The center point of the coordinate system lies inside, but anyway, as you mentioned, this should "only" offset the tetrahedron but not change its shape (except scaling it bigger). My function looks as that:

----------------------------------------------
<br>scale()<br>{<br><br> std::vector &lt; Polyhedron * const &gt; ::iterator polyhedronIter;<br> float scale, oldScaledEdgeLength;<br> <br> oldScaledEdgeLength = scaledPolyhedronEdgeLength;<br><br> scaledPolyhedronEdgeLength = scaledPolyhedronEdgeLength + value * polyhedronEdgeLength;<br><br> scaledPolyhedronEdgeLength = ( scaledPolyhedronEdgeLength / polyhedronEdgeLength ) &lt;= 2.0 && ( scaledPolyhedronEdgeLength / polyhedronEdgeLength ) &gt;= 0.5 ? scaledPolyhedronEdgeLength : oldScaledEdgeLength;<br><br> scale = scaledPolyhedronEdgeLength / oldScaledEdgeLength;<br> <br> for( polyhedronIter = m_polyhedrons.begin();<br> polyhedronIter != m_polyhedrons.end();<br> ++polyhedronIter )<br> {<br> <br> Vertex * vx[4];<br> Vector vc0, vc1, vc2, vc3;<br><br> vx[0] = (*polyhedronIter)-&gt;getVertex(0);<br> vx[1] = (*polyhedronIter)-&gt;getVertex(1);<br> vx[2] = (*polyhedronIter)-&gt;getVertex(2);<br> vx[3] = (*polyhedronIter)-&gt;getVertex(3);<br> <br> vc0 = *(vx[0]) * scale;<br> vc1 = *(vx[1]) * scale;<br> vc2 = *(vx[2]) * scale;<br> vc3 = *(vx[3]) * scale;<br><br> vx[0]-&gt;setCoordinates( vc0 );<br> vx[1]-&gt;setCoordinates( vc1 );<br> vx[2]-&gt;setCoordinates( vc2 );<br> vx[3]-&gt;setCoordinates( vc3 );<br> }<br>}<br></code><br>------------------------------------------------------------------------------<br><br>so it does exactly what i wrote: just scaling the vertex-coords with the same scale factor.<br><br>Nevertheless it is producing bad scaled tetras. Here is &#111;ne example for up- and &#111;ne for downscaling:<br><br>http://www.innovasol.de/Scaling/scale_examples.png<br><br>Greets<br><br>
The relative position of the vertices shouldn't affect anything, the method should work for any type of shapes.

The mistake has to be in your code somewhere, although I'm having trouble finding it. Your "rectangular tetrahedron" still has 4 vertices right? Did you copy/paste the code here - is it exactly the same code that produced the results on the screenshot? On the screenshot, the scaling looks obviously non-uniform, maybe it would help to further localize the problem if you could show a screenshot with only 1 tetrahedron and a more radical scaling value (e.g. 1.5 and 0.5).

This topic is closed to new replies.

Advertisement