2 #include <boost/bind.hpp> 3 #include <boost/function.hpp> 6 #include <hrpModel/ModelLoaderUtil.h> 12 #include <SDL_thread.h> 13 #include "hrpsys/util/GLbodyRTC.h" 14 #include "hrpsys/util/GLlink.h" 15 #include "hrpsys/util/GLutil.h" 16 #include "hrpsys/util/Project.h" 17 #include "hrpsys/util/OpenRTMUtil.h" 18 #include "hrpsys/util/SDLUtil.h" 19 #include "hrpsys/util/BVutil.h" 31 std::cout <<
"createBody(" << name <<
"," << mitem.
url <<
")" << std::endl;
33 std::string args =
"GLbodyRTC?instance_name="+name;
38 OpenHRP::ModelLoader::ModelLoadOption opt;
40 opt.AABBdata.length(0);
41 opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
42 binfo = modelloader->getBodyInfoEx(mitem.
url.c_str(), opt);
43 }
catch(OpenHRP::ModelLoader::ModelLoaderException ex){
44 std::cerr << ex.description << std::endl;
48 std::cerr <<
"failed to load model[" << mitem.
url <<
"]" << std::endl;
52 for (std::map<std::string, JointItem>::const_iterator it2=mitem.
joint.begin();
53 it2 != mitem.
joint.end(); it2++){
57 if (it2->second.collisionShape ==
""){
59 }
else if (it2->second.collisionShape ==
"convex hull"){
61 }
else if (it2->second.collisionShape ==
"AABB"){
64 std::cerr <<
"unknown value of collisionShape property:" 65 << it2->second.collisionShape << std::endl;
85 std::cerr <<
"Usage:" << progname <<
" [project file] [options]" << std::endl;
86 std::cerr <<
"Options:" << std::endl;
87 std::cerr <<
" -nodisplay : headless mode" << std::endl;
88 std::cerr <<
" -realtime : syncronize to real world time" << std::endl;
89 std::cerr <<
" -usebbox : use bounding box for collision detection" << std::endl;
90 std::cerr <<
" -endless : endless mode" << std::endl;
91 std::cerr <<
" -showsensors : visualize sensors" << std::endl;
92 std::cerr <<
" -size [pixels] : specify window size in pixels" << std::endl;
93 std::cerr <<
" -no-default-lights : disable ambient light (simulation environment will be dark)" << std::endl;
94 std::cerr <<
" -max-edge-length [value] : specify maximum length of polygon edge (if exceed, polygon will be divided to improve rendering quality)" << std::endl;
95 std::cerr <<
" -max-log-length [value] : specify maximum size of the log" << std::endl;
96 std::cerr <<
" -exit-on-finish : exit the program when the simulation finish" << std::endl;
97 std::cerr <<
" -record : record the simulation as movie" << std::endl;
98 std::cerr <<
" -bg [r] [g] [b] : specify background color" << std::endl;
99 std::cerr <<
" -h --help : show this help message" << std::endl;
102 int main(
int argc,
char* argv[])
104 bool display =
true, usebbox=
false;
105 bool showsensors =
false;
107 bool useDefaultLights =
true;
108 double maxEdgeLen = 0;
109 bool exitOnFinish =
false;
111 double maxLogLen = 60;
112 bool realtime =
false;
113 bool endless =
false;
120 float bgColor[]={0,0,0};
121 for (
int i=1;
i<argc;
i++){
122 if (strcmp(
"-nodisplay",argv[
i])==0){
124 }
else if(strcmp(
"-realtime", argv[i])==0){
126 }
else if(strcmp(
"-usebbox", argv[i])==0){
128 }
else if(strcmp(
"-endless", argv[i])==0){
130 }
else if(strcmp(
"-showsensors", argv[i])==0){
132 }
else if(strcmp(
"-size", argv[i])==0){
133 wsize = atoi(argv[++i]);
134 }
else if(strcmp(
"-no-default-lights", argv[i])==0){
135 useDefaultLights =
false;
136 }
else if(strcmp(
"-max-edge-length", argv[i])==0){
137 maxEdgeLen = atof(argv[++i]);
138 }
else if(strcmp(
"-max-log-length", argv[i])==0){
139 maxLogLen = atof(argv[++i]);
140 }
else if(strcmp(
"-exit-on-finish", argv[i])==0){
142 }
else if(strcmp(
"-record", argv[i])==0){
145 }
else if(strcmp(
"-bg", argv[i])==0){
146 bgColor[0] = atof(argv[++i]);
147 bgColor[1] = atof(argv[++i]);
148 bgColor[2] = atof(argv[++i]);
149 }
else if(strcmp(
"-h", argv[i])==0 || strcmp(
"--help", argv[i])==0){
156 if (!prj.
parse(argv[1])){
157 std::cerr <<
"failed to parse " << argv[1] << std::endl;
170 std::vector<char *> rtmargv;
171 for (
int i=1;
i<argc;
i++){
172 if (strcmp(argv[
i],
"-nodisplay")
173 && strcmp(argv[i],
"-realtime")
174 && strcmp(argv[i],
"-usebbox")
175 && strcmp(argv[i],
"-endless")
176 && strcmp(argv[i],
"-showsensors")
177 && strcmp(argv[i],
"-size")
178 && strcmp(argv[i],
"-no-default-lights")
179 && strcmp(argv[i],
"-max-edge-length")
180 && strcmp(argv[i],
"-max-log-length")
181 && strcmp(argv[i],
"-exit-on-finish")
182 && strcmp(argv[i],
"-record")
183 && strcmp(argv[i],
"-bg")
185 rtmargv.push_back(argv[i]);
190 manager->
init(rtmargc, rtmargv.data());
195 std::string nameServer = manager->
getConfig()[
"corba.nameservers"];
196 int comPos = nameServer.find(
",");
198 comPos = nameServer.length();
200 nameServer = nameServer.substr(0, comPos);
203 ModelLoader_var modelloader =
getModelLoader(CosNaming::NamingContext::_duplicate(
naming.getRootContext()));
204 if (CORBA::is_nil(modelloader)){
205 std::cerr <<
"openhrp-model-loader is not running" << std::endl;
217 SDLwindow window(&scene, &log, &simulator);
219 window.
init(wsize, wsize);
227 simulator.
init(prj, factory);
232 std::cout <<
"timestep = " << prj.
timeStep() <<
", total time = " 238 if (exitOnFinish && !simulator.
isRunning())
break;
void convertToAABB(hrp::BodyPtr i_body)
void createInPort(const std::string &config)
void enableRingBuffer(int len)
void print_usage(char *progname)
RTObject_impl * createComponent(const char *comp_args)
void deleteComponent(RTObject_impl *comp)
void showFloorGrid(bool flag)
HRPMODEL_API OpenHRP::ModelLoader_var getModelLoader(CosNaming::NamingContext_var cxt)
bool parse(const std::string &filename)
void addBody(GLbody *i_body)
int main(int argc, char *argv[])
void setBackGroundColor(float rgb[3])
void runManager(bool no_block=false)
RTC::ReturnCode_t setup()
bool init(int w=0, int h=0, bool resizable=true)
void showSensors(bool flag)
sample RT component which has one data input port and one data output port
void loadShapeFromBodyInfo(GLbody *body, BodyInfo_var i_binfo, GLshape *(*shapeFactory)())
std::vector< std::string > outports
static Manager & instance()
boost::shared_ptr< Body > BodyPtr
void setView(double T[16])
static void moduleInit(RTC::Manager *)
void init(Project &prj, BodyFactory &factory)
coil::Properties & getConfig()
hrp::Link * GLlinkFactory()
void convertToConvexHull(hrp::BodyPtr i_body)
static Manager * init(int argc, char **argv)
void defaultLights(bool flag)
void showCollision(bool flag)
bool record(double i_fps)
std::vector< std::string > inports
std::map< std::string, JointItem > joint
void maxEdgeLen(double i_len)
int loadBodyFromBodyInfo(::World *world, const char *_name, BodyInfo_ptr bodyInfo)
boost::function2< hrp::BodyPtr, const std::string &, const ModelItem & > BodyFactory
hrp::BodyPtr createBody(const std::string &name, const ModelItem &mitem, ModelLoader_ptr modelloader, GLscene *scene, bool usebbox)
void createOutPort(const std::string &config)