20 static PQP_REAL T[3], RR[3][3];
21 static PQP_REAL P1[3], P2[3];
22 fVec3 pos(joint->abs_pos);
23 fMat33 att(joint->abs_att);
48 static PQP_REAL R1[3][3];
49 static PQP_REAL T1[3];
50 static PQP_REAL R2[3][3];
51 static PQP_REAL T2[3];
52 fVec3 p1(models[0]->joint->abs_pos);
53 fMat33 r1(models[0]->joint->abs_att);
54 fVec3 p2(models[1]->joint->abs_pos);
55 fMat33 r2(models[1]->joint->abs_att);
84 R1, T1, models[0]->model,
85 R2, T2, models[1]->model);
88 int ColPair::Distance(PQP_DistanceResult& dres,
89 PQP_REAL rel_error, PQP_REAL abs_error,
92 static PQP_REAL R1[3][3];
93 static PQP_REAL T1[3];
94 static PQP_REAL R2[3][3];
95 static PQP_REAL T2[3];
96 fVec3 p1(models[0]->joint->abs_pos);
97 fMat33 r1(models[0]->joint->abs_att);
98 fVec3 p2(models[1]->joint->abs_pos);
99 fMat33 r2(models[1]->joint->abs_att);
127 return PQP_Distance(&dres,
128 R1, T1, models[0]->model,
129 R2, T2, models[1]->model,
130 rel_error, abs_error,
134 int ColPair::Tolerance(PQP_ToleranceResult& tres,
137 static PQP_REAL R1[3][3];
138 static PQP_REAL T1[3];
139 static PQP_REAL R2[3][3];
140 static PQP_REAL T2[3];
141 fVec3 p1(models[0]->joint->abs_pos);
142 fMat33 r1(models[0]->joint->abs_att);
143 fVec3 p2(models[1]->joint->abs_pos);
144 fMat33 r2(models[1]->joint->abs_att);
172 return PQP_Tolerance(&tres,
173 R1, T1, models[0]->model,
174 R2, T2, models[1]->model,
183 static float fscale[3];
185 tnode->getScale(fscale);
194 static float fpos[3];
195 static float frot[4];
196 tnode->getTranslation(fpos);
197 tnode->getRotation(frot);
207 int ColModel::add_triangles(TransformNode* tnode)
212 add_triangles(tnode, (Node*)tnode);
216 cerr <<
"add_triangles(" << tnode->getName() <<
")" << endl;
222 cerr <<
" total " << n_triangle <<
" triangles" << endl;
228 int ColModel::add_triangles(TransformNode* tnode, Node* cur)
231 add_triangles_sub(tnode, cur->getChildNodes());
235 int ColModel::add_triangles_sub(TransformNode* tnode, Node* cur)
239 if(cur->isIndexedFaceSetNode())
240 add_triangles_face(tnode, (IndexedFaceSetNode*)cur);
243 add_triangles_sub(tnode, cur->next());
244 add_triangles_sub(tnode, cur->getChildNodes());
249 int ColModel::add_triangles_face(TransformNode* tnode, IndexedFaceSetNode* inode)
251 CoordinateNode* cnode = inode->getCoordinateNodes();
252 if(!cnode)
return -1;
253 int n_my_vertex = cnode->getNPoints();
254 int n_index = inode->getNCoordIndexes();
255 if(n_my_vertex == 0 || n_index == 0)
return 0;
257 int vertex_id_base = n_vertex;
258 n_vertex += n_my_vertex;
261 fVec3* tmp_vertices = vertices;
262 vertices =
new fVec3 [n_vertex];
265 for(i=0; i<vertex_id_base; i++)
266 vertices[i].
set(tmp_vertices[i]);
267 delete[] tmp_vertices;
270 fVec3* tmp_vertices = 0;
273 tmp_vertices =
new fVec3 [vertex_id_base];
274 for(i=0; i<vertex_id_base; i++)
275 tmp_vertices[i].
set(vertices[i]);
278 vertices =
new fVec3 [n_vertex];
279 for(i=0; i<vertex_id_base; i++)
280 vertices[i].
set(tmp_vertices[i]);
281 if(tmp_vertices)
delete[] tmp_vertices;
284 for(i=0; i<n_my_vertex; i++)
286 cnode->getPoint(i, fp);
287 vertices[i+vertex_id_base](0) = fp[0];
288 vertices[i+vertex_id_base](1) = fp[1];
289 vertices[i+vertex_id_base](2) = fp[2];
290 apply_all_transforms(tnode, (Node*)cnode, vertices[i+vertex_id_base]);
293 int ccw = inode->getCCW();
294 for(i=0; i<n_index; i++)
297 c1 = inode->getCoordIndex(i);
299 while( (c2 = inode->getCoordIndex(i)) != -1 &&
300 (c3 = inode->getCoordIndex(i+1)) != -1 )
302 TriangleInfo* ti = 0;
303 if(ccw) ti =
new TriangleInfo(c1+vertex_id_base, c2+vertex_id_base, c3+vertex_id_base);
304 else ti =
new TriangleInfo(c1+vertex_id_base, c3+vertex_id_base, c2+vertex_id_base);
305 triangles.append(ti);
314 void ColModel::apply_all_transforms(TransformNode* tnode, Node* cur,
fVec3& pos)
317 int scale_only =
false;
318 for(node=cur; node; node=node->getParentNode())
320 if(node->isTransformNode())
330 int ColModel::create_pqp_model()
332 PQP_REAL p1[3], p2[3], p3[3];
333 PQP_REAL q1[3], q2[3], q3[3];
334 tListElement<TriangleInfo>* ti;
335 for(ti=triangles.first(); ti; ti=ti->next())
337 TriangleInfo* tri = ti->body();
338 tri->neighbor_vertex[0] = -1;
339 tri->neighbor_vertex[1] = -1;
340 tri->neighbor_vertex[2] = -1;
341 tri->neighbor_tri[0] = -1;
342 tri->neighbor_tri[1] = -1;
343 tri->neighbor_tri[2] = -1;
344 int c1 = tri->index[0];
345 int c2 = tri->index[1];
346 int c3 = tri->index[2];
347 tListElement<TriangleInfo>*
a;
349 for(a=triangles.first(); a; a=a->next())
353 if((vert = a->body()->have_edge(c1, c2)) >= 0)
355 tri->neighbor_vertex[0] = vert;
356 tri->neighbor_tri[0] = a->id();
358 else if((vert = a->body()->have_edge(c2, c3)) >= 0)
360 tri->neighbor_vertex[1] = vert;
361 tri->neighbor_tri[1] = a->id();
363 else if((vert = a->body()->have_edge(c3, c1)) >= 0)
365 tri->neighbor_vertex[2] = vert;
366 tri->neighbor_tri[2] = a->id();
369 if(tri->neighbor_vertex[0] >= 0 &&
370 tri->neighbor_vertex[1] >= 0 &&
371 tri->neighbor_vertex[2] >= 0)
374 p1[0] = (PQP_REAL)vertices[c1](0);
375 p1[1] = (PQP_REAL)vertices[c1](1);
376 p1[2] = (PQP_REAL)vertices[c1](2);
377 p2[0] = (PQP_REAL)vertices[c2](0);
378 p2[1] = (PQP_REAL)vertices[c2](1);
379 p2[2] = (PQP_REAL)vertices[c2](2);
380 p3[0] = (PQP_REAL)vertices[c3](0);
381 p3[1] = (PQP_REAL)vertices[c3](1);
382 p3[2] = (PQP_REAL)vertices[c3](2);
383 if(tri->neighbor_vertex[0] >= 0)
385 q1[0] = (PQP_REAL)vertices[tri->neighbor_vertex[0]](0);
386 q1[1] = (PQP_REAL)vertices[tri->neighbor_vertex[0]](1);
387 q1[2] = (PQP_REAL)vertices[tri->neighbor_vertex[0]](2);
389 if(tri->neighbor_vertex[1] >= 0)
391 q2[0] = (PQP_REAL)vertices[tri->neighbor_vertex[1]](0);
392 q2[1] = (PQP_REAL)vertices[tri->neighbor_vertex[1]](1);
393 q2[2] = (PQP_REAL)vertices[tri->neighbor_vertex[1]](2);
395 if(tri->neighbor_vertex[2] >= 0)
397 q3[0] = (PQP_REAL)vertices[tri->neighbor_vertex[2]](0);
398 q3[1] = (PQP_REAL)vertices[tri->neighbor_vertex[2]](1);
399 q3[2] = (PQP_REAL)vertices[tri->neighbor_vertex[2]](2);
401 int vertex_id[3] = { c1, c2, c3 };
402 model->AddTri(p1, p2, p3, q1, q2, q3, vertex_id, tri->neighbor_tri, ti->id());
404 cerr <<
"triangle " << ti->id() <<
": [" << c1 <<
", " << c2 <<
", " << c3 <<
"], neighbors = [" << tri->neighbor_tri[0] <<
", " << tri->neighbor_tri[1] <<
", " << tri->neighbor_tri[2] <<
"]" << endl;
405 cerr << vertices[c1] << endl;
406 cerr << vertices[c2] << endl;
407 cerr << vertices[c3] << endl;
418 if(n_pairs == n_allocated_pairs) allocate_pair(n_allocated_pairs + 10);
425 if(n_models == n_allocated_models) allocate_model(n_allocated_models + 10);
426 models[n_models] = m;
428 n_total_tri += m->n_triangle;
433 cerr <<
"AddCharPairs(" << char1 <<
", " << char2 <<
")" << endl;
434 add_char_pairs(chain->
Root(), char1, char2, chain, sg);
442 if((charname = cur->
CharName()) && !strcmp(charname, char1))
444 add_char_pairs(cur, chain->
Root(), char2, sg);
446 add_char_pairs(cur->
brother, char1, char2, chain, sg);
447 add_char_pairs(cur->
child, char1, char2, chain, sg);
455 if((charname = j2->
CharName()) && !strcmp(charname, char2) && j1 != j2)
457 add_joint_pair(j1, j2, sg);
459 add_char_pairs(j1, j2->
brother, char2, sg);
460 add_char_pairs(j1, j2->
child, char2, sg);
469 if(!j1 || !j2)
return 0;
470 if(j1 == j2)
return 0;
471 add_joint_pair(j1, j2, sg);
477 if(
Pair(j1, j2))
return 0;
482 m1 =
new ColModel(j1, sg);
488 m2 =
new ColModel(j2, sg);
491 if(m1->n_triangle == 0 || m2->n_triangle == 0)
return -1;
494 cerr <<
"add joint pair: " << j1->
name <<
", " << j2->
name << endl;
505 ret =
new ColModel(jref, sg);
506 if(ret->n_triangle > 0)
void add(const fVec3 &vec1, const fVec3 &vec2)
Joint * child
pointer to the child joint
int n_dof
degrees of freedom (0/1/3/6)
int AddCharPairs(const char *char1, const char *char2, Chain *chain, SceneGraph *sg)
ColModel * AddModel(Joint *jref, SceneGraph *sg)
int PQP_Collide(PQP_CollideResult *result, PQP_REAL R1[3][3], PQP_REAL T1[3], PQP_Model *o1, PQP_REAL R2[3][3], PQP_REAL T2[3], PQP_Model *o2, int flag=PQP_ALL_CONTACTS)
int AddJointPair(const char *joint1, const char *joint2, Chain *chain, SceneGraph *sg)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void add_pair(ColPair *p)
png_infop png_bytep * trans
void rot2mat(const fVec3 &, double)
Converts from/to equivalent rotation axis and angle.
int add_char_pairs(Joint *cur, const char *char1, const char *char2, Chain *chain, SceneGraph *sg)
char * CharName() const
Returns the character name.
char * name
joint name (including the character name)
Joint * brother
pointer to the brother joint
int add_joint_pair(Joint *j1, Joint *j2, SceneGraph *sg)
static void apply_transform(TransformNode *tnode, fVec3 &pos, int scale_only=false)
The class representing the whole mechanism. May contain multiple characters.
void add_model(ColModel *m)
Joint * FindJoint(const char *jname, const char *charname=0)
Find a joint from name.
ColPair(Chain *chain, const char *jointname1, const char *charname1, const char *jointname2, const char *charname2)
void mul(const fVec3 &vec, double d)
The class for representing a joint.
int PQP_TriLineIntersect(PQP_CollideResult *result, PQP_REAL RR[3][3], PQP_REAL T[3], PQP_Model *o1, PQP_REAL P1[3], PQP_REAL P2[3], int flag=PQP_ALL_CONTACTS)
Joint * parent
pointer to the parent joint
A generic couple structure.