25 #include "biasGLviewerGLUT.hh"
28 #include <Utils/IOUtils.hh>
30 #ifdef BIAS_HAVE_OPENSCENEGRAPH
31 #include <osg/ShapeDrawable>
33 #endif //BIAS_HAVE_OPENSCENEGRAPH
38 void AnimFuncWrapper();
42 biasGLviewerGLUT(
int argc,
char* argv[])
47 renderBoundingBoxes_ =
false;
51 contextPointer_ = NULL;
54 int groupID = GetFreeGroupID();
59 useFlyMode_ = AddParamBool(
60 "fly",
"set mouse control to fly mode",
false, 0 ,groupID);
61 useRotMode_ = AddParamBool(
62 "onlyRot",
"turn only rotation for mouse control on",
false, 0, groupID);
63 SetGroupName(groupID,
"Animation / Control");
66 groupID = GetFreeGroupID();
67 zNear_ = AddParamDouble(
68 "zNear",
"set near clipping plane distance, overrides autoClipping", 0.001, 0.000001, DBL_MAX, 0 ,groupID);
69 zFar_ = AddParamDouble(
70 "zFar",
"set near clipping plane distance, overrides autoClipping", 10000, 0.00001, DBL_MAX, 0, groupID);
71 fov_ = AddParamDouble(
72 "fov",
"field of view in degree", 0, 0, 359.9, 0, groupID);
73 autoClipping_ = AddParamBool(
74 "autoClipping",
"turns auto clipping on/off",
true, 0 , groupID);
75 backfaceCulling_ = AddParamBool(
76 "backfaceCulling",
"do not draw back faces of triangles?",
false, 0, groupID);
77 teapot_ = AddParamBool(
78 "teapot",
"Add a glut teapot to scene",
false, 0, groupID);
80 "cube",
"Add a glut cube to scene",
false, 0, groupID);
81 tetrahedron_ = AddParamBool(
82 "tetrahedron",
"Add a glut tetrahedron to scene",
false, 0, groupID);
83 icosahedron_ = AddParamBool(
84 "icosahedron",
"Add a glut icosahedron to scene",
false, 0, groupID);
86 SetGroupName(groupID,
"View");
89 groupID = GetFreeGroupID();
90 projectionFile_ = AddParamString(
91 "projection",
"load camera parameters from this file, sets findSceneCenter to false if useJustIntrinsics is false (default)",
93 useSceneCenter_ = AddParamBool(
94 "findSceneCenter",
"sets camera to center of scene",
96 useJustIntrinsics_ = AddParamBool(
97 "useJustIntrinsics",
"uses only intrinsics from loaded projection",
101 std::vector<std::string> reshapeBehaviour;
102 reshapeBehaviour.push_back(
"Deny");
103 reshapeBehaviour.push_back(
"AutoRescaleParams");
104 reshapeBehaviour.push_back(
"AutoCutImage");
105 reshapeBehaviour.push_back(
"AutoSimplePerspectiveCam");
107 autoReshapeBehaviour_ = AddParamEnum(
108 "reshapeBehaviour",
"sets the automatic reshape behaviour of the camera",
109 reshapeBehaviour, 1,NULL, 0, groupID);
110 SetGroupName(groupID,
"Camera");
113 groupID = GetFreeGroupID();
114 winwidth_ = AddParamInt(
115 "winwidth",
"window width", 640, 0, INT_MAX,
'w', groupID);
116 winheight_ = AddParamInt(
117 "winheight",
"window width", 480, 0, INT_MAX,
'h', groupID);
118 screenShotName_ = AddParamString(
119 "screenShotName",
"name for screenshots default is 'screenShot'",
"screenShot", 0, groupID);
120 backGroundColor_ = AddParamVecDbl(
121 "bgColor",
"set background clear color",
"200.0 230.0 230.0", 0, groupID);
123 bool ret = IOUtils::ParseCommandLineEvalHelp(*
this,argc, argv,firstUnkownParam_);
124 if(!ret) BIASWARN(
"Parsing command line arguments failed. Please check them!");
130 void biasGLviewerGLUT::
134 unsigned int winwidth = *winwidth_, winheight = *winheight_;
135 if(*projectionFile_ ==
"") {
140 cout<<
"Setting simple perspective camera with: 65 degrees fov and:"
141 <<winwidth<<
"x"<<winheight<<
" pixel."<<endl;
143 camera_.Assign(*ppp);
147 if (!(*useJustIntrinsics_)) {
148 *useSceneCenter_ =
false;
152 #ifdef BIAS_HAVE_XML2
153 if (proj.
XMLRead(*projectionFile_) != 0) {
155 if (proj.
Load(*projectionFile_) != 0) {
157 BIASERR(
"could not read projection file!\n");
163 unsigned int width, height;
164 camera_.GetMyselfAsProjectionParameterBase()->GetImageSize(width, height);
174 "BIASOpenGLViewerGlut", NULL, &argc_, argv_);
177 if(*zFar_ != 10000 || *zNear_ != 0.001)
178 contextPointer_->SetAutoClipping(
false);
180 contextPointer_->SetAutoClipping(*autoClipping_);
184 (
float)((*backGroundColor_)[1]),
185 (
float)((*backGroundColor_)[2]),
187 contextPointer_->SetClearColor(clearColor);
190 camera_.SetZClippingPlanes(*zNear_, *zFar_);
193 screenShotControl_.Init(contextPointer_, *screenShotName_,
"ppm",
"",
true);
195 sceneLight_.SetLightAsHeadLight(
false);
196 sceneLight_.SetDrawLightPosition(
false);
200 contextPointer_->AppendScene(&sceneLight_);
202 #ifdef BIAS_HAVE_OPENSCENEGRAPH
205 bool hasModel =
false;
207 if(argc_ - firstUnkownParam_ >= 1 && firstUnkownParam_ > 0) {
208 for(
int i=0;i< (argc_ - firstUnkownParam_);i++){
209 cout<<
"loading "<<argv_[firstUnkownParam_+i]<<
"... \n"; cout.flush();
210 if(scene_.AppendSubTreeFromFile(argv_[firstUnkownParam_+i])!=0)
219 if(!hasModel && ! (*teapot_) && ! (*cube_)
220 && ! (*icosahedron_) && ! (*tetrahedron_)) {
221 osg::ShapeDrawable *sphere =
222 new osg::ShapeDrawable(
new osg::Sphere(
osg::Vec3(0., 0., 0.), 2.0));
223 const osg::Vec4 color(139.0/255.0,248.0/255.0,244.0/255.0,0);
224 sphere->setColor(color);
225 osg::Geode *n =
new osg::Geode;
226 n->addDrawable(sphere);
227 scene_.AppendNode(n);
230 contextPointer_->AppendScene(&scene_);
235 sceneGlut_.SetDrawTeapot(*teapot_,0.4);
236 sceneGlut_.SetDrawCube(*cube_,0.4);
237 sceneGlut_.SetDrawIcosahedron(*icosahedron_);
238 sceneGlut_.SetDrawTetrahedron(*tetrahedron_);
239 contextPointer_->AppendScene(&sceneGlut_);
244 switch(*autoReshapeBehaviour_)
247 camera_.SetAutoReshapeBehaviour(GLProjectionParametersInterface::Deny);
250 camera_.SetAutoReshapeBehaviour(GLProjectionParametersInterface::AutoCutImage);
253 camera_.SetAutoReshapeBehaviour(GLProjectionParametersInterface::AutoSimplePerspectiveCam);
256 camera_.SetAutoReshapeBehaviour(GLProjectionParametersInterface::AutoRescaleParams);
262 contextPointer_->SetGLProjectionParametersInterface(&camera_);
264 if(*useFlyMode_ && ! *useRotMode_) {
265 contextPointer_->SetControl(&flyControl_);
267 else if (!*useFlyMode_ && ! *useRotMode_ ) {
268 contextPointer_->SetControl(&control_);
270 contextPointer_->AppendScene(&control_);
273 contextPointer_->SetControl(&rotControl_);
277 contextPointer_->AppendAdditionalListener(&screenShotControl_);
278 contextPointer_->AppendAdditionalListener(
this);
281 if(*useSceneCenter_) {
283 if (!contextPointer_->GetSceneCenter(SceneCenter, radius))
284 BIASERR(
"could not retrieve bounding box from scene");
286 CameraCenter = SceneCenter + 1.1 * radius;
287 cout<<
"using scene center "<<SceneCenter<<
" and new camera center "
288 <<CameraCenter <<endl;
290 if ((CameraCenter-SceneCenter).NormL2()>0.001) {
291 camera_.GetMyselfAsProjectionParameterBase()->SetC(CameraCenter);
292 control_.SetPointOfInterest(SceneCenter);
294 cerr<<
"could not set poi, empty scene ?"<<endl;
299 if (*backfaceCulling_)
300 glEnable(GL_CULL_FACE);
302 glDisable(GL_CULL_FACE);
307 void biasGLviewerGLUT::
310 if (initialized_) glutMainLoop();
311 else cout <<
"Run Init() first!" << endl;
315 bool biasGLviewerGLUT::
316 StandardKeyPressed(
unsigned char key,
int,
int)
318 static int pointSizeG = 1;
319 static bool twosided =
false;
322 renderBoundingBoxes_ = !renderBoundingBoxes_;
323 cout<<
"switched bounding box rendering "
324 << (renderBoundingBoxes_?
"on" :
"off")<<endl;
325 contextPointer_->GlobalBoundingBoxSwitch(renderBoundingBoxes_);
332 cout<<
"camera->SetActiveSlot(0)"<<endl;
334 case 'z': glPolygonMode( GL_FRONT_AND_BACK, GL_POINT);
335 cout <<
"PolygonMode: Point." << endl;
337 case 'x': glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);
338 cout <<
"PolygonMode: Line." << endl;
340 case 'c': glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
341 cout <<
"PolygonMode: Fill." << endl;
343 case 'Z': glShadeModel(GL_SMOOTH);
344 cout <<
"Shading Smooth." << endl;
346 case 'X': glShadeModel(GL_FLAT);
347 cout <<
"Shading Flat." << endl;
351 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
354 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
357 cout <<
"Two-sided lighting is " << (twosided ?
"on" :
"off")
363 cout<<
"Point/Line Size increasing:"<<pointSizeG<<endl;
364 glPointSize(pointSizeG);
365 glLineWidth(pointSizeG);
369 if (pointSizeG<1) pointSizeG=1;
370 cout<<
"Point/Line Size decreasing:"<<pointSizeG<<endl;
371 glPointSize(pointSizeG);
372 glLineWidth(pointSizeG);
374 case 'G':SceneBase::SetAnimationSpeed(1.0);
375 cout<<
"Enabling Animation/Collision in SceneBase. Speed = 1"<<endl;
377 case 'g':SceneBase::SetAnimationSpeed(0.0);
378 cout<<
"Disabling Animation/Collision in SceneBase."<<endl;
382 glutIdleFunc(AnimFuncWrapper);
389 toggleStoreToDisc_();
392 cout<<
"\n Application specific controls: \n\n";
393 cout<<
"\t + : Increase TimeStep\n";
394 cout<<
"\t - : Decrease TimeStep\n";
395 cout<<
"\t n : switch view to next slot\n";
396 cout<<
"\t 0 : switch view to slot 0\n";
397 cout<<
"\t a : start/resume animation\n";
398 cout<<
"\t s : stop animation\n";
399 cout<<
"\t g/G : enable/disable SceneBase animation/collision"<<endl;
400 cout<<
"\t S : store images to disc, resume with next slot when done\n";
401 cout<<
"\t T : toggle two-sided lighting\n";
402 cout<<
"\t m : toggle the distance measurement control\n";
403 cout<<
"\t P : Print current camera info \n";
404 cout<<
"\t q : quit \n";
405 cout<<
"\t b : toggle bounding box rendering\n";
406 cout<<
"\t [] : increase/decrease point/line size\n";
407 cout<<
"\t zxc : toggle polygon mode\n";
408 cout<<
"\t </> : decrerase/increase zFar \n";
409 cout<<
"\t ,/. : decrerase/increase zNear \n";
410 cout<<
"\t F5 : screenshot + depth\n";
411 cout<<
"\t F6 : camera params\n";
414 control_.SetDistanceMeasure(! control_.GetDistanceMeasure());
417 cout<<
"Current Camera:"<<camera_<<endl;
420 *zFar_ *= (12.0)/(10.0);
421 camera_.SetZClippingPlanes(*zNear_, *zFar_);
422 cout<<
"zFar = "<<*zFar_<<endl;
425 *zFar_ *= (10.0)/(12.0);
426 cout<<
"zFar = "<<*zFar_<<endl;
427 camera_.SetZClippingPlanes(*zNear_, *zFar_);
430 *zNear_ *= (10.0)/(12.0);
431 cout<<
"zNear = "<<*zNear_<<endl;
432 camera_.SetZClippingPlanes(*zNear_, *zFar_);
435 *zNear_ *= (12.0)/(10.0);
436 cout<<
"zNear = "<<*zNear_<<endl;
437 camera_.SetZClippingPlanes(*zNear_, *zFar_);
447 void biasGLviewerGLUT::
477 void AnimFuncWrapper() {
478 (*viewerObjPointer).AnimationFunc();
483 void biasGLviewerGLUT::
484 toggleStoreToDisc_() {
485 storeToDisc_ = !storeToDisc_;
487 cout<<
"WRITING to disc ENABLED!\n";
489 cout<<
"WRITING to disc DISABLED!\n";
492 int main(
int argc,
char* argv[])
495 viewerObjPointer = &viewer;
int SetSimplePerspectiveCam(double fovyDEG, int imageWidth=-1, int imageHeight=-1)
int XMLRead(const std::string &Filename)
derived classes must implement the function XMLIn which is called by this function XMLRead to read ev...
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
class for rendering with projection parameters of ProjectionParametersPerspective ...
virtual int SetExtrinsics(const BIAS::HomgPoint3D &C, const BIAS::RMatrix &R)