Sign in to follow this  
Olentzero

Scaling a 3D mesh (vertices, tetrahedra)

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

----------------------------------------------
[code lang=cpp]
scale()
{

std::vector < Polyhedron * const > ::iterator polyhedronIter;
float scale, oldScaledEdgeLength;

oldScaledEdgeLength = scaledPolyhedronEdgeLength;

scaledPolyhedronEdgeLength = scaledPolyhedronEdgeLength + value * polyhedronEdgeLength;

scaledPolyhedronEdgeLength = ( scaledPolyhedronEdgeLength / polyhedronEdgeLength ) <= 2.0 && ( scaledPolyhedronEdgeLength / polyhedronEdgeLength ) >= 0.5 ? scaledPolyhedronEdgeLength : oldScaledEdgeLength;

scale = scaledPolyhedronEdgeLength / oldScaledEdgeLength;

for( polyhedronIter = m_polyhedrons.begin();
polyhedronIter != m_polyhedrons.end();
++polyhedronIter )
{

Vertex * vx[4];
Vector vc0, vc1, vc2, vc3;

vx[0] = (*polyhedronIter)->getVertex(0);
vx[1] = (*polyhedronIter)->getVertex(1);
vx[2] = (*polyhedronIter)->getVertex(2);
vx[3] = (*polyhedronIter)->getVertex(3);

vc0 = *(vx[0]) * scale;
vc1 = *(vx[1]) * scale;
vc2 = *(vx[2]) * scale;
vc3 = *(vx[3]) * scale;

vx[0]->setCoordinates( vc0 );
vx[1]->setCoordinates( vc1 );
vx[2]->setCoordinates( vc2 );
vx[3]->setCoordinates( vc3 );
}
}
[/code]
------------------------------------------------------------------------------

so it does exactly what i wrote: just scaling the vertex-coords with the same scale factor.

Nevertheless it is producing bad scaled tetras. Here is one example for up- and one for downscaling:

http://www.innovasol.de/Scaling/scale_examples.png

Greets

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this