8 #include <SDL/SDL_timer.h> 9 #include <hrpModel/ModelLoaderUtil.h> 10 #include "hrpsys/util/GLlink.h" 11 #include "hrpsys/util/GLbody.h" 12 #include "hrpsys/util/GLutil.h" 13 #include "hrpsys/util/SDLUtil.h" 21 std::cerr <<
"Usage:" << progname <<
" [model file] [options]" << std::endl;
22 std::cerr <<
"Options:" << std::endl;
23 std::cerr <<
" -size [pixels] : specify window size in pixels" << std::endl;
24 std::cerr <<
" -no-default-lights : disable ambient light (simulation environment will be dark)" << std::endl;
25 std::cerr <<
" -max-edge-length [value] : specify maximum length of polygon edge (if exceed, polygon will be divided to improve rendering quality)" << std::endl;
26 std::cerr <<
" -bg [r] [g] [b] : specify background color" << std::endl;
27 std::cerr <<
" -h --help : show this help message" << std::endl;
28 std::cerr <<
"Example:" << std::endl;
29 std::cerr <<
" run the view server and wait for the client to connect"<< std::endl;
30 std::cerr <<
" $ " << progname << std::endl;
31 std::cerr <<
" run the view server, load the pa10 robot model, set the background to green and wait for the client to connect"<< std::endl;
32 std::cerr <<
" $ " << progname <<
" /usr/share/OpenHRP-3.1/sample/model/PA10/pa10.main.wrl -bg 0 0.3 0"<< std::endl;
35 int main(
int argc,
char *argv[])
38 double maxEdgeLen=0.0;
39 bool useDefaultLights=
true;
40 float bgColor[3]={0,0,0};
42 for (
int i=1;
i<argc;
i++){
43 if (strcmp(argv[
i],
"-size")==0){
44 wsize = atoi(argv[++i]);
45 }
else if(strcmp(argv[i],
"-max-edge-length")==0){
46 maxEdgeLen = atof(argv[++i]);
47 }
else if(strcmp(argv[i],
"-no-default-lights")==0){
48 useDefaultLights=
false;
49 }
else if(strcmp(argv[i],
"-bg")==0){
50 bgColor[0] = atof(argv[++i]);
51 bgColor[1] = atof(argv[++i]);
52 bgColor[2] = atof(argv[++i]);
53 }
else if(strcmp(argv[i],
"-h")==0 || strcmp(argv[i],
"--help")==0){
59 CORBA::ORB_var orb = CORBA::ORB::_nil();
63 orb = CORBA::ORB_init(argc, argv);
65 CORBA::Object_var
obj;
67 obj = orb->resolve_initial_references(
"RootPOA");
68 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
69 if(CORBA::is_nil(poa)){
70 throw std::string(
"error: failed to narrow root POA.");
73 PortableServer::POAManager_var poaManager = poa->the_POAManager();
74 if(CORBA::is_nil(poaManager)){
75 throw std::string(
"error: failed to narrow root POA manager.");
85 poa->activate_object(OnlineViewerImpl);
86 OnlineViewer_var OnlineViewer = OnlineViewerImpl->_this();
87 OnlineViewerImpl->_remove_ref();
89 obj = orb->resolve_initial_references(
"NameService");
90 CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj);
91 if(CORBA::is_nil(namingContext)){
92 throw std::string(
"error: failed to narrow naming context.");
97 name[0].id = CORBA::string_dup(
"OnlineViewer");
98 name[0].kind = CORBA::string_dup(
"");
99 namingContext->rebind(name, OnlineViewer);
101 poaManager->activate();
103 if (argc >= 2 && argv[1][0] !=
'-'){
105 if (CORBA::is_nil(ml)){
106 std::cerr <<
"openhrp-model-loader is not running" << std::endl;
109 OpenHRP::ModelLoader::ModelLoadOption opt;
110 opt.readImage =
true;
111 opt.AABBdata.length(0);
112 opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
114 std::string url = argv[1];
115 if (argv[1][0] !=
'/'){
116 char buf[MAXPATHLEN];
117 std::string cwd = getcwd(buf, MAXPATHLEN);
118 url = cwd +
'/' + url;
121 body->setName(
"model");
122 OpenHRP::BodyInfo_var binfo = ml->getBodyInfoEx(url.c_str(), opt);
132 window.
init(wsize, wsize);
138 catch(OpenHRP::ModelLoader::ModelLoaderException ex){
139 std::cerr << ex.description << std::endl;
141 catch (CORBA::SystemException& ex) {
142 std::cerr << ex._rep_id() << std::endl;
144 catch (
const std::string&
error){
145 std::cerr << error << std::endl;
static void useAbsTransformToDraw()
HRPMODEL_API OpenHRP::ModelLoader_var getModelLoader(CosNaming::NamingContext_var cxt)
void addBody(GLbody *i_body)
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)())
hrp::Link * GLlinkFactory()
void defaultLights(bool flag)
static void useAbsTransformToDraw()
void print_usage(char *progname)
void maxEdgeLen(double i_len)
int main(int argc, char *argv[])