42 PortableServer::POA_var poa = _default_POA();
43 PortableServer::ObjectId_var
id = poa->servant_to_id(
this);
44 poa->deactivate_object(
id);
50 cout <<
"adding " << name <<
" ";
53 string bodyInfoId(
orb->object_to_string(bodyInfo));
56 cout <<
"BodyInfo CORBA ID of " << name <<
" is " << bodyInfoId << endl;
63 coldetBody->setName(name);
70 cout <<
"The model of the name " <<
name;
71 cout <<
" has already been registered. It is replaced." << endl;
75 cout <<
" is ok !" << endl;
81 (
const LinkPair& linkPair)
88 (
const LinkPair& linkPair, vector<ColdetModelPairExPtr>& io_coldetPairs)
90 const char* bodyName[2];
91 bodyName[0] = linkPair.charName1;
92 bodyName[1] = linkPair.charName2;
94 const char* linkName[2];
95 linkName[0] = linkPair.linkName1;
96 linkName[1] = linkPair.linkName2;
98 bool notFound =
false;
102 for(
int i=0;
i < 2; ++
i){
105 cout <<
"CollisionDetector::addCollisionPair : Body ";
106 cout << bodyName[
i] <<
" is not found." << endl;
109 coldetBody[
i] = it->second;
110 coldetModel[
i] = coldetBody[
i]->linkColdetModel(linkName[i]);
112 cout <<
"CollisionDetector::addCollisionPair : Link ";
113 cout << linkName[
i] <<
" is not found." << endl;
120 io_coldetPairs.push_back(
121 new ColdetModelPairEx(coldetBody[0], coldetModel[0], coldetBody[1], coldetModel[1], linkPair.tolerance));
127 (
const CharacterPositionSequence& characterPositions, CollisionSequence_out out_collisions)
135 (
const LinkPairSequence& checkPairs,
136 const CharacterPositionSequence& characterPositions,
137 CollisionSequence_out out_collisions)
141 vector<ColdetModelPairExPtr> tmpColdetPairs;
143 for(
unsigned int i=0;
i < checkPairs.length(); ++
i){
144 const LinkPair& linkPair = checkPairs[
i];
153 (
const CharacterPositionSequence& characterPositions)
155 for(
unsigned int i=0;
i < characterPositions.length();
i++){
156 const CharacterPosition& characterPosition = characterPositions[
i];
157 const string bodyName(characterPosition.characterName);
161 coldetBody->setLinkPositions(characterPosition.linkPositions);
168 (vector<ColdetModelPairExPtr>& coldetPairs, CollisionSequence_out& out_collisions)
170 bool detected =
false;
171 const int numColdetPairs = coldetPairs.size();
172 out_collisions =
new CollisionSequence;
173 out_collisions->length(numColdetPairs);
175 for(
int i=0;
i < numColdetPairs; ++
i){
178 Collision& collision = out_collisions[
i];
184 collision.pair.charName1 = CORBA::string_dup(coldetPair.
body0->name());
185 collision.pair.linkName1 = CORBA::string_dup(coldetPair.
model(0)->
name().c_str());
186 collision.pair.charName2 = CORBA::string_dup(coldetPair.
body1->name());
187 collision.pair.linkName2 = CORBA::string_dup(coldetPair.
model(1)->
name().c_str());
195 (
ColdetModelPairEx& coldetPair, CollisionPointSequence& out_collisionPoints,
const bool addCollisionPoints)
197 bool detected =
false;
202 for(
unsigned int i=0;
i < cdata.size();
i++) {
203 for(
int j=0;
j < cdata[
i].num_of_i_points;
j++){
204 if(cdata[
i].i_point_new[
j]){
211 if(addCollisionPoints){
212 out_collisionPoints.length(npoints);
214 for(
unsigned int i=0;
i < cdata.size();
i++) {
218 CollisionPoint& point = out_collisionPoints[index];
219 for(
int k=0; k < 3; k++){
222 for(
int k=0; k < 3; k++){
225 point.idepth = cd.
depth;
239 CORBA::Boolean checkAll,
240 const CharacterPositionSequence& characterPositions,
241 LinkPairSequence_out out_collidedPairs
251 CORBA::Boolean checkAll,
252 const LinkPairSequence& checkPairs,
253 const CharacterPositionSequence& characterPositions,
254 LinkPairSequence_out out_collidedPairs
259 vector<ColdetModelPairExPtr> tmpColdetPairs;
261 for(
unsigned int i=0;
i < checkPairs.length(); ++
i){
262 const LinkPair& linkPair = checkPairs[
i];
272 const CharacterPositionSequence& characterPositions,
273 DistanceSequence_out out_distances
283 const LinkPairSequence& checkPairs,
284 const CharacterPositionSequence& characterPositions,
285 DistanceSequence_out out_distances
290 vector<ColdetModelPairExPtr> tmpColdetPairs;
292 for(
unsigned int i=0;
i < checkPairs.length(); ++
i){
293 const LinkPair& linkPair = checkPairs[
i];
302 const DblArray3 point,
306 CORBA::Double D, minD=0;
310 std::cout << it->first << std::endl;
313 for (
unsigned int i=0;
i<body->numLinks();
i++){
314 D = body->linkColdetModel(
i)->computeDistanceWithRay(point, dir);
315 if ((minD==0&&D>0)||(minD>0&&D>0&&minD>D)) minD = D;
317 std::cout <<
"D = " << D << std::endl;
322 std::cout <<
"minD = " << minD << std::endl;
329 DblSequence *distances =
new DblSequence();
330 int scan_half = (
int)(range/2/step);
331 distances->length(scan_half*2+1);
335 for (
int i = -scan_half;
i<= scan_half;
i++){
337 local[0] = -sin(a); local[2] = -cos(a);
338 dir[0] = R[0]*local[0]+R[1]*local[1]+R[2]*local[2];
339 dir[1] = R[3]*local[0]+R[4]*local[1]+R[5]*local[2];
340 dir[2] = R[6]*local[0]+R[7]*local[1]+R[8]*local[2];
343 printf(
"angle = %8.3f, distance = %8.3f\n", a, (*distances)[
i+scan_half]);
351 (vector<ColdetModelPairExPtr>& coldetPairs, LinkPairSequence_out& out_collidedPairs,
const bool checkAll)
353 CollisionPointSequence dummy;
355 bool detected =
false;
357 vector<int> collidedPairIndices;
358 collidedPairIndices.reserve(coldetPairs.size());
360 for(
unsigned int i=0;
i < coldetPairs.size(); ++
i){
363 collidedPairIndices.push_back(i);
370 out_collidedPairs =
new LinkPairSequence();
371 out_collidedPairs->length(collidedPairIndices.size());
373 for(CORBA::ULong
i=0;
i < collidedPairIndices.size(); ++
i){
374 int pairIndex = collidedPairIndices[
i];
376 LinkPair& linkPair = out_collidedPairs[
i];
377 linkPair.charName1 = CORBA::string_dup(coldetPair.
body0->name());
378 linkPair.linkName1 = CORBA::string_dup(coldetPair.
model(0)->
name().c_str());
379 linkPair.charName2 = CORBA::string_dup(coldetPair.
body1->name());
380 linkPair.linkName2 = CORBA::string_dup(coldetPair.
model(1)->
name().c_str());
387 (vector<ColdetModelPairExPtr>& coldetPairs, LinkPairSequence_out& out_collidedPairs,
const bool checkAll)
389 bool detected =
false;
391 vector<int> collidedPairIndices;
392 collidedPairIndices.reserve(coldetPairs.size());
394 for(
unsigned int i=0;
i < coldetPairs.size(); ++
i){
395 if(coldetPairs[
i]->detectIntersection()){
397 collidedPairIndices.push_back(
i);
404 out_collidedPairs =
new LinkPairSequence();
405 out_collidedPairs->length(collidedPairIndices.size());
407 for(CORBA::ULong
i=0;
i < collidedPairIndices.size(); ++
i){
408 int pairIndex = collidedPairIndices[
i];
410 LinkPair& linkPair = out_collidedPairs[
i];
411 linkPair.charName1 = CORBA::string_dup(coldetPair.
body0->name());
412 linkPair.linkName1 = CORBA::string_dup(coldetPair.
model(0)->
name().c_str());
413 linkPair.charName2 = CORBA::string_dup(coldetPair.
body1->name());
414 linkPair.linkName2 = CORBA::string_dup(coldetPair.
model(1)->
name().c_str());
421 (vector<ColdetModelPairExPtr>& coldetPairs, DistanceSequence_out& out_distances)
423 out_distances =
new DistanceSequence();
424 out_distances->length(coldetPairs.size());
426 for(
unsigned int i=0;
i < coldetPairs.size(); ++
i){
428 Distance& dinfo = out_distances[
i];
430 LinkPair& linkPair = dinfo.pair;
431 linkPair.charName1 = CORBA::string_dup(coldetPair.
body0->name());
432 linkPair.linkName1 = CORBA::string_dup(coldetPair.
model(0)->
name().c_str());
433 linkPair.charName2 = CORBA::string_dup(coldetPair.
body1->name());
434 linkPair.linkName2 = CORBA::string_dup(coldetPair.
model(1)->
name().c_str());
448 PortableServer::POA_var poa = _default_POA();
449 PortableServer::ObjectId_var
id = poa->servant_to_id(
this);
450 poa->deactivate_object(
id);
457 PortableServer::ServantBase_var collisionDetectorrServant = collisionDetector;
458 PortableServer::POA_var poa = _default_POA();
459 PortableServer::ObjectId_var
id = poa->activate_object(collisionDetector);
460 return collisionDetector->_this();
466 orb->shutdown(
false);
virtual CORBA::Boolean queryIntersectionForGivenPairs(CORBA::Boolean checkAll, const LinkPairSequence &checkPairs, const CharacterPositionSequence &characterPositions, LinkPairSequence_out collidedPairs)
void computeDistances(vector< ColdetModelPairExPtr > &coldetPairs, DistanceSequence_out &out_distances)
boost::intrusive_ptr< ColdetBody > ColdetBodyPtr
bool detectCollisionsOfLinkPair(ColdetModelPairEx &coldetPair, CollisionPointSequence &out_collisionPoints, const bool addCollisionPoints)
bool detectCollidedLinkPairs(vector< ColdetModelPairExPtr > &coldetPairs, LinkPairSequence_out &out_collidedPairs, const bool checkAll)
CollisionDetectorFactory_impl(CORBA_ORB_ptr orb)
png_infop png_charpp name
bool detectAllCollisions(vector< ColdetModelPairExPtr > &coldetPairs, CollisionSequence_out &out_collisions)
void updateAllLinkPositions(const CharacterPositionSequence &characterPositions)
bool detectIntersectingLinkPairs(vector< ColdetModelPairExPtr > &coldetPairs, LinkPairSequence_out &out_collidedPairs, const bool checkAll)
void addCollisionPairSub(const LinkPair &linkPair, vector< ColdetModelPairExPtr > &io_coldetPairs)
~CollisionDetectorFactory_impl()
virtual void queryDistanceForGivenPairs(const LinkPairSequence &checkPairs, const CharacterPositionSequence &characterPositions, DistanceSequence_out distances)
double computeDistance(double *point0, double *point1)
~CollisionDetector_impl()
virtual void queryDistanceForDefinedPairs(const CharacterPositionSequence &characterPositions, DistanceSequence_out distances)
StringToColdetBodyMap nameToColdetBodyMap
def j(str, encoding="cp932")
virtual DblSequence * scanDistanceWithRay(const DblArray3 p, const DblArray9 R, CORBA::Double step, CORBA::Double range)
vector< ColdetModelPairExPtr > coldetModelPairs
virtual CORBA::Boolean queryIntersectionForDefinedPairs(CORBA::Boolean checkAll, const CharacterPositionSequence &characterPositions, LinkPairSequence_out collidedPairs)
ColdetModel * model(int index)
virtual CORBA::Boolean queryContactDeterminationForGivenPairs(const LinkPairSequence &checkPairs, const CharacterPositionSequence &characterPositions, CollisionSequence_out collisions)
CollisionDetector_ptr create()
virtual CORBA::Double queryDistanceWithRay(const DblArray3 point, const DblArray3 dir)
CollisionDetector_impl(CORBA_ORB_ptr orb)
virtual void addCollisionPair(const LinkPair &colPair)
const std::string & name() const
get name of this model
boost::intrusive_ptr< ColdetModel > ColdetModelPtr
virtual CORBA::Boolean queryContactDeterminationForDefinedPairs(const CharacterPositionSequence &characterPositions, CollisionSequence_out collisions)
virtual void registerCharacter(const char *name, BodyInfo_ptr bodyInfo)
std::vector< collision_data > & detectCollisions()