3 #include <boost/bind.hpp> 4 #include <hrpModel/ModelLoaderUtil.h> 10 #include "hrpsys/util/ProjectUtil.h" 11 #include "hrpsys/util/GLbody.h" 12 #include "hrpsys/util/GLlink.h" 13 #include "hrpsys/util/GLutil.h" 14 #include "hrpsys/util/SDLUtil.h" 15 #include "hrpsys/util/LogManager.h" 16 #include "hrpsys/util/BVutil.h" 19 #include "hrpsys/idl/CollisionDetectorService.hh" 25 ModelLoader_ptr modelloader)
29 OpenHRP::ModelLoader::ModelLoadOption opt;
31 opt.AABBdata.length(0);
32 opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
33 binfo = modelloader->getBodyInfoEx(mitem.
url.c_str(), opt);
34 }
catch(OpenHRP::ModelLoader::ModelLoaderException ex){
35 std::cerr << ex.description << std::endl;
49 int main(
int argc,
char* argv[])
52 std::cerr <<
"Usage:" << argv[0] <<
" project.xml [-co CollisionDetector Component] [-size size] [-bg r g b]" << std::endl;
57 if (!prj.
parse(argv[1])){
58 std::cerr <<
"failed to parse " << argv[1] << std::endl;
62 const char *coname =
"co";
64 float bgColor[] = {0,0,0};
65 for (
int i = 2;
i<argc;
i++){
66 if (strcmp(argv[
i],
"-co")==0){
68 }
else if(strcmp(argv[i],
"-size")==0){
69 wsize = atoi(argv[++i]);
70 }
else if(strcmp(argv[i],
"-bg")==0){
71 bgColor[0] = atof(argv[++i]);
72 bgColor[1] = atof(argv[++i]);
73 bgColor[2] = atof(argv[++i]);
79 CosNaming::NamingContext_var namingContext;
82 orb = CORBA::ORB_init(argc, argv);
84 CORBA::Object_var
obj;
85 obj = orb->resolve_initial_references(
"RootPOA");
86 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
87 if(CORBA::is_nil(poa)){
88 throw std::string(
"error: failed to narrow root POA.");
91 PortableServer::POAManager_var poaManager = poa->the_POAManager();
92 if(CORBA::is_nil(poaManager)){
93 throw std::string(
"error: failed to narrow root POA manager.");
96 obj = orb->resolve_initial_references(
"NameService");
97 namingContext = CosNaming::NamingContext::_narrow(obj);
98 if(CORBA::is_nil(namingContext)){
99 throw std::string(
"error: failed to narrow naming context.");
102 poaManager->activate();
103 }
catch (CORBA::SystemException& ex) {
104 std::cerr << ex._rep_id() << std::endl;
105 }
catch (
const std::string&
error){
106 std::cerr << error << std::endl;
115 window.
init(wsize, wsize);
117 std::vector<hrp::ColdetLinkPairPtr> pairs;
119 if (CORBA::is_nil(modelloader)){
120 std::cerr <<
"openhrp-model-loader is not running" << std::endl;
131 OpenHRP::CollisionDetectorService_var coService;
136 if (CORBA::is_nil(coService)){
138 CosNaming::Name
name;
140 name[0].id = CORBA::string_dup(coname);
141 name[0].kind = CORBA::string_dup(
"rtc");
142 CORBA::Object_var
obj = namingContext->resolve(name);
143 RTC::RTObject_var rtc = RTC::RTObject::_narrow(obj);
145 coService = OpenHRP::CollisionDetectorService::_narrow(orb->string_to_object(ior));
147 std::cerr <<
"could not found collision detector component " << coname << std::endl;
152 OpenHRP::CollisionDetectorService::CollisionState co;
153 bool stateUpdate =
false;
154 if (!CORBA::is_nil(coService)){
156 OpenHRP::CollisionDetectorService::CollisionState_var t_co;
157 coService->getCollisionStatus(t_co);
161 std::cerr <<
"exception in getCollisionStatus()" << std::endl;
169 for (
size_t i=0;
i<co.collide.length();
i++) {
175 tp.
posture.resize(co.angle.length());
179 for (
size_t i=0;
i<co.lines.length();
i++) {
181 p0[0] = co.lines[
i][0][0];
182 p0[1] = co.lines[
i][0][1];
183 p0[2] = co.lines[
i][0][2];
184 p1[0] = co.lines[
i][1][0];
185 p1[1] = co.lines[
i][1][1];
186 p1[2] = co.lines[
i][1][2];
187 tp.
lines.push_back(std::make_pair(p0,p1));
192 std::cerr <<
"exceptoin in stateUpdate" << std::endl;
void enableRingBuffer(int len)
void showFloorGrid(bool flag)
HRPMODEL_API OpenHRP::ModelLoader_var getModelLoader(CosNaming::NamingContext_var cxt)
bool parse(const std::string &filename)
hrp::BodyPtr createBody(const std::string &name, const ModelItem &mitem, ModelLoader_ptr modelloader)
void setBackGroundColor(float rgb[3])
png_infop png_charpp name
bool init(int w=0, int h=0, bool resizable=true)
HRPMODEL_API bool loadBodyFromBodyInfo(BodyPtr body, OpenHRP::BodyInfo_ptr bodyInfo, bool loadGeometryForCollisionDetection=false, Link *(*f)()=NULL)
void error(char *msg) const
void loadShapeFromBodyInfo(GLbody *body, BodyInfo_var i_binfo, GLshape *(*shapeFactory)())
const char * getServiceIOR(RTC::RTObject_var rtc, const char *sname)
boost::shared_ptr< Body > BodyPtr
hrp::Link * GLlinkFactory()
void convertToConvexHull(hrp::BodyPtr i_body)
Link * link(int index) const
int main(int argc, char *argv[])
std::vector< std::pair< hrp::Vector3, hrp::Vector3 > > lines
boost::function2< hrp::BodyPtr, const std::string &, const ModelItem & > BodyFactory
void initWorld(Project &prj, BodyFactory &factory, hrp::World< hrp::ConstraintForceSolver > &world, std::vector< hrp::ColdetLinkPairPtr > &pairs)
std::vector< double > posture