Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: NevilleKemp

26. May 2012, 06:27:28 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Coloring geometry depending on distance
Pages: [1]
Print
Author Topic: Coloring geometry depending on distance  (Read 114 times)
XamNiner
Just dropped in

Offline Offline

Posts: 8


View Profile Email
« on: 14. November 2011, 11:52:39 am »

Hello Xith Community. I'm pretty new to 3d graphical programming.
The testcases have been really helpful so far and I have learned a lot about displaying 3d models.
However I have run into a bit of a problem. It's kind of a special case of collision detection.

I have got 2 different 3d models I'm displaying right now. You can think of them as a hand and a glove. Now I'm moving the glove while the hand stays at the same position. For this I have adapted the collision test example.
My real problem is that I want to move the glove into position and look how good the glove is fitting my hand model. For this I want to paint my glove model with the corresponding colours (blue for glove model is bigger and red for glove is smaller or inside hand).
If anybody got a good idea how to evaluate the distance between the two models I would be really  grateful.
Logged
XamNiner
Just dropped in

Offline Offline

Posts: 8


View Profile Email
« Reply #1 on: 24. November 2011, 01:58:24 pm »

Okay I found a solution for placing my models and calculating the distances. First I load every vertex of the first model (geoLeft) into a new float array. I want to color every vertex of that first model white so I save the vertex number + the white color inside a new color array. After that I load the coordinates of the second model into my float array and look for the shortest distance of my model point to every other point of the first model using
Code:
distance = coordsNewGeoLeft[vertCountLeft].distance(coordsNewGeoLeft[j]);
Finally I use my minimum distance for that point to compute a new color wich i save into my color array. I then use both the coordinate and the color array to build a new geometry which will be displayed in the scene.
My biggest problem however is that finding the minimum distance for every model point is extremely taxing and takes quite a large amount of time. It would be great if anybody got an idea how to speed up the time it takes to compute all those distances.  Wink

Code:
public Geometry grading(Model modelLeft, Model modelRight){
Geometry geoLeft = modelLeft.getShape(0).getGeometry();
Geometry geoRight = modelRight.getShape(0).getGeometry();
int vertCountLeft= geoLeft.getValidVertexCount();
int vertCountRight = geoRight.getValidVertexCount();
//Zielgeometrie
TriangleArray tri = new TriangleArray(vertCountLeft+vertCountRight);
//Koordinaten eines Punktes
float [] coordsGeo = new float[3];
//Punktkoordinaten Array
Point3f [] coordsNewGeoLeft = new Point3f [vertCountLeft+vertCountRight];
Point3f [] coordsNewGeoRight = new Point3f [vertCountRight];

//Farben für Modellpunkte
Colorf [] colArray = new Colorf[vertCountLeft+vertCountRight];
//Koordinaten von geo in coordsNewGeo laden
for (int i = 0; i < vertCountLeft; i++){
geoLeft.getCoordinate(i, coordsGeo);
coordsNewGeoLeft[i] = new Point3f( coordsGeo[0], coordsGeo[1], coordsGeo[2]);
//Modell von linkem Bein weiß transparent
colArray[i] = Colorf.WHITE_TRANSPARENT;
}
//Koordinaten von geoRight in  coordsNewGeo2 laden
for (int j = 0; j < vertCountRight; j++ ){
geoRight.getCoordinate(j, coordsGeo);
coordsNewGeoRight[j] = new Point3f (coordsGeo[0], coordsGeo[1], coordsGeo[2]);
}

float minDist = 100;
int countFest = vertCountLeft;

for (int i = 0; i < vertCountRight; i++,vertCountLeft++, minDist=100 ){
coordsNewGeoLeft[vertCountLeft] = coordsNewGeoRight[i];
for (int j = 0 ; j < countFest; j++){
/*
* Berechne kleinsten Abstand von jedem Punkt
* von Modell_Links zu aktuellem Punkt von Modell_Rechts
*/
float distance = coordsNewGeoLeft[vertCountLeft].distance(coordsNewGeoLeft[j]);
if (distance < minDist){
minDist = distance;
}
//Punkt von Modell_Rechts liegt direkt auf Modell_Links
if (minDist == 0){
colArray[i+countFest] = Colorf.RED;
}
//Modellpunkt entsprechend der größe von minDist einfärben
if (minDist > 0 && minDist != 100){
float colAtr = (1/20f) * minDist;
colArray[i+countFest] = new Colorf((1-colAtr), 0.0f , (colAtr));
}
}
}

//Koordinaten und Farben für neue Geometrie setzen
tri.setCoordinates(0, coordsNewGeoLeft);
tri.setColors(0, colArray);
tri.calculateFaceNormals();
return (tri);
}
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic