PDA

View Full Version : Draw 3D Ellipso´des-OpenGl



bibi2canon_lmd
07-04-2013, 08:21 AM
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

Carmine
07-05-2013, 04:39 PM
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.

bibi2canon_lmd
07-08-2013, 10:41 AM
Think's a lot
I think that should be work!

bibi2canon_lmd
07-09-2013, 08:10 AM
I tried by glutSolidSphere(1,30,30);
That doesn't work?
What do you mean by: "a unit sphere at the origin"?

Thank you.

bibi2canon_lmd
07-09-2013, 08:17 AM
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.

Carmine
07-09-2013, 06:36 PM
I tried by glutSolidSphere(1,30,30); That doesn't work?
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?

bibi2canon_lmd
07-10-2013, 04:06 AM
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.

GClements
07-10-2013, 10:32 AM
Now, I need to know how I can oriented the Ellipsoids according to the eigenvectors?
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.

bibi2canon_lmd
07-10-2013, 11:55 AM
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.

GClements
07-11-2013, 02:49 AM
Ok, but how I can use this matrix.
With glLoadMatrix() or glMultMatrix().

bibi2canon_lmd
07-11-2013, 07:04 AM
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.

GClements
07-11-2013, 07:14 AM
I tried with this:


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


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

bibi2canon_lmd
07-11-2013, 07:44 AM
1. You shouldn't be calling glMultMatrixf() twice..
Excuse me, I put it here by mistake!


2. You shouldn't be calling glTranslatef(), as the translation is included in the matrix.
I removed glTranslatef(), but its always not good!

bibi2canon_lmd
07-11-2013, 08:27 AM
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:)
1071