Draw 3D Ellipsoïdes-OpenGl

hello,

I develop an algorithm which allows to decompose 3D models into different parts.
I need to represent each part (points cloud) with an ellipsoid. The center of the Ellipsoid is the gravity center of the cloud’s part, and the diamers of its axis corresponding to the eigenvalues of the covariance matrix?

Think you.
Bil

Start with a unit sphere at the origin.
Scale it by the eigenvalues.
Then translate it to the gravity center.

Something like :


   glTranslatef (gx, gy, gz);     // Translate to gravity center.
   glScalef (e1, e2, e3);         // Scale on each axis by eigenvalue
   Unit_Sphere ();                // Draw unit sphere at origin

This code assumes that the ellipsoid axes are parallel to the world axes.

Think’s a lot
I think that should be work!

I tried by glutSolidSphere(1,30,30);
That doesn’t work?
What do you mean by: “a unit sphere at the origin”?

Thank you.

I have to draw one ellipsoid on each gravity center of the classe.
ex: 3 classes -> 3 ellipsoids!
So, the gravity ccenter of each classe define the position of the corresponding ellipsoid.

Think’s.

Actually, that should give you a unit sphere centered at the origin.
What do you mean when you say ‘That doesn’t work’? Do you see anything at all?
First goal is to get a sphere of radius 1, centered at the origin to show up in a window.
Are you able to do that?

Hello!

Before, I got spheres placed in a rang positiions!
I find the problem. I forgot to put glPushMatrix() and glPushMatrix() before and after each ellipsoid drawing.
Now, I need to know how I can oriented the Ellipsoids according to the eigenvectors?

Think’s a lot for you collaboration.

Construct the matrix:


x1 x2 x3 cx
y1 y2 y3 cy
z1 z2 z3 cz
 0  0  0  1

where [x1 y1 z1], [x2 y2 z2], and [x3 y3 z3] are the axes and [cx cy cz] is the centroid.

Bear in mind that OpenGL uses column-major order by default.

Ok, but how I can use this matrix.
I mean that I have use it with glRotatef(angle,x,y,z) or what?

Think you.

With glLoadMatrix() or glMultMatrix().

I tried with this:



GLfloat mat[]={
                     
                     vec[0].x,vec[0].y,vec[0].z,0,
                     vec[1].x,vec[1].y,vec[1].z,0,
                     vec[2].x,vec[2].y,vec[2].z,0,
                     cg.x,cg.y,cg.z,1
                   };

glPushMatrix();

glMultMatrix(mat);
glTranslatef (cg.x, cg.y,cg.z);
glScalef (vp[0], vp[1], vp[2]);
glMultMatrixf(mat);
glutSolidSphere(1,30,30);

 glPopMatrix();

I get Ellipsoid in the right position, but it’s not oriented correctly!
You can see that on the attached images.

[QUOTE=bibi2canon_lmd;1252594]I tried with this:


glMultMatrix(mat);
glTranslatef (cg.x, cg.y,cg.z);
glScalef (vp[0], vp[1], vp[2]);
glMultMatrixf(mat);

[/QUOTE]

  1. You shouldn’t be calling glMultMatrixf() twice.
  2. You shouldn’t be calling glTranslatef(), as the translation is included in the matrix.

Excuse me, I put it here by mistake!

I removed glTranslatef(), but its always not good!

I found the error!
I have to add glFlush() at the end!

This the code. it work correctly.


 	 for(size_t i=0;i<n;i++)  // n is the number of ellipsoids.
	 {
                             glPushMatrix();

		             GLfloat mat[]={
		             vec[i][0].x,vec[i][0].y,vec[i][0].z,0,   // vecteur1
			     vec[i][1].x,vec[i][1].y,vec[i][1].z,0,   // vecteur2
		             vec[i][2].x,vec[i][2].y,vec[i][2].z,0,   // vecteur3
		             cg.x,cg.y,cg.z,1
		                        };

			    glScalef (vp[0], vp[1], vp[2]);   //eigenvalues
			    glMultMatrixf(mat);
			    glutSolidSphere(1,30,30);//drawCloudObj(pointsObjVox);
			    glPopMatrix();
			    glFlush();
	}

Think’s a lot:)
[ATTACH=CONFIG]458[/ATTACH]