arViewer.cpp
Go to the documentation of this file.
00001 /*
00002         Original version for VRML97-0.8.7 by Hirokazu Kato.
00003  
00004         Updated for OpenVRML-0.14.3 by Raphael Grasset.
00005         -remove vrmlScene since we use reference now.
00006         -remove culling pb
00007 
00008         Updated for OpenVRML-0.16.1 by Philip Lamb. 2006-11-15.
00009         - add arVrmlBrowser class and Boost dependencies.
00010 */
00011 /*
00012  * 
00013  * This file is part of ARToolKit.
00014  * 
00015  * ARToolKit is free software; you can redistribute it and/or modify
00016  * it under the terms of the GNU General Public License as published by
00017  * the Free Software Foundation; either version 2 of the License, or
00018  * (at your option) any later version.
00019  * 
00020  * ARToolKit is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  * 
00025  * You should have received a copy of the GNU General Public License
00026  * along with ARToolKit; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  * 
00029  */
00030 
00031 #include <iostream>
00032 #include <math.h>
00033 #ifdef __APPLE__
00034 #  include <GLUT/glut.h>
00035 #else
00036 #  include <GL/glut.h>
00037 #endif
00038 #include "arViewer.h"
00039 
00040 using namespace openvrml;
00041 
00042 arVrmlBrowser::arVrmlBrowser(): openvrml::browser(std::cout, std::cerr)
00043 {
00044 }
00045 
00046 std::auto_ptr<openvrml::resource_istream>
00047 arVrmlBrowser::do_get_resource(const std::string & uri)
00048 {
00049         using std::auto_ptr;
00050         using std::invalid_argument;
00051         using std::string;
00052         using openvrml::resource_istream;
00053         
00054         class file_resource_istream : public resource_istream {
00055                 std::string url_;
00056                 std::filebuf buf_;
00057                 
00058         public:
00059                 explicit file_resource_istream(const std::string & path): resource_istream(&this->buf_)
00060                 {
00061                         if (!this->buf_.open(path.c_str(), ios_base::in)) {
00062                                 this->setstate(ios_base::failbit);
00063                         }
00064                 }
00065                         
00066                 void url(const std::string & str) throw (std::bad_alloc)
00067                 {
00068                         this->url_ = str;
00069                 }
00070                         
00071         private:
00072                 virtual const std::string do_url() const throw ()
00073                 {
00074                         return this->url_;
00075                 }
00076                         
00077                 virtual const std::string do_type() const throw ()
00078                 {
00079                         //
00080                         // A real application should use OS facilities for this.  This
00081                         // is a crude hack.
00082                         //
00083                         using std::find;
00084                         using std::string;
00085                         using boost::algorithm::iequals;
00086                         using boost::next;
00087                         string media_type = "application/octet-stream";
00088                         const string::const_reverse_iterator dot_pos =
00089                                 find(this->url_.rbegin(), this->url_.rend(), '.');
00090                         if (dot_pos == this->url_.rend()
00091                                 || next(dot_pos.base()) == this->url_.end()) {
00092                                 return media_type;
00093                         }
00094                         const string::const_iterator hash_pos =
00095                                 find(next(dot_pos.base()), this->url_.end(), '#');
00096                         const string ext(dot_pos.base(), hash_pos);
00097                         if (iequals(ext, "wrl")) {
00098                                 media_type = "model/vrml";
00099                         } else if (iequals(ext, "x3dv")) {
00100                                 media_type = "model/x3d+vrml";
00101                         } else if (iequals(ext, "png")) {
00102                                 media_type = "image/png";
00103                         } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) {
00104                                 media_type = "image/jpeg";
00105                         }
00106                         return media_type;
00107                 }
00108                         
00109                 virtual bool do_data_available() const throw ()
00110                 {
00111                         return !!(*this);
00112                 }
00113         }; // class file_resource_istream
00114         
00115         const string scheme = uri.substr(0, uri.find_first_of(':'));
00116         if (scheme != "file") {
00117                 throw invalid_argument('\"' + scheme + "\" URI scheme not supported");
00118         }
00119         //
00120         // file://
00121         //        ^
00122         // 01234567
00123         //
00124         string path = uri.substr(uri.find_first_of('/', 7));
00125         
00126         auto_ptr<resource_istream> in(new file_resource_istream(path));
00127         static_cast<file_resource_istream *>(in.get())->url(uri);
00128         
00129         return in;
00130 }
00131 
00132 
00133 arVrmlViewer::arVrmlViewer() : gl::viewer::viewer()
00134 {
00135     internal_light = true;
00136 
00137     translation[0] = 0.0;
00138     translation[1] = 0.0;
00139     translation[2] = 0.0;
00140 
00141     rotation[0] = 0.0;
00142     rotation[1] = 0.0;
00143     rotation[2] = 0.0;
00144     rotation[3] = 0.0;
00145 
00146     scale[0] = 1.0;
00147     scale[1] = 1.0;
00148     scale[2] = 1.0;
00149 }
00150 
00151 arVrmlViewer::~arVrmlViewer() throw()
00152 {
00153   
00154 }
00155 
00156 void arVrmlViewer::timerUpdate()
00157 { 
00158         this->update(0.0);
00159 }
00160 
00161 
00162 
00163 void arVrmlViewer::setInternalLight(bool flag)
00164 {
00165     internal_light = flag;
00166 }
00167 
00168 void arVrmlViewer::redraw()
00169 {
00170         //double start = browser::current_time();
00171     glMatrixMode(GL_MODELVIEW);
00172     glPushMatrix();
00173     glTranslated( translation[0], translation[1], translation[2] );
00174     if (rotation[0] != 0.0) {
00175         glRotated(rotation[0], rotation[1], rotation[2], rotation[3]);
00176     }
00177     glScaled(scale[0], scale[1], scale[2]);
00178         
00179 #if USE_STENCIL_SHAPE
00180     glEnable(GL_STENCIL_TEST);
00181     glStencilFunc(GL_ALWAYS, 1, 1);
00182     glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
00183 #endif
00184     glEnable(GL_DEPTH_TEST);
00185     glDepthFunc(GL_LEQUAL);
00186     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00187     glDisable(GL_FOG);          // this is a global attribute
00188     //glDisable(GL_TEXTURE_2D);
00189     glEnable(GL_CULL_FACE);
00190     glFrontFace(GL_CCW);
00191     glCullFace(GL_BACK);
00192         
00193         if (internal_light) {
00194                 if (lit) glEnable(GL_LIGHTING);
00195                 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00196                 glEnable(GL_NORMALIZE);
00197                 glDisable(GL_COLOR_MATERIAL);
00198                 glDisable(GL_BLEND);
00199                 glShadeModel(GL_SMOOTH);
00200                 
00201                 for (int i = 0; i < max_lights; ++i) {
00202                         light_info_[i].type = light_unused;
00203                         GLenum light = (GLenum) (GL_LIGHT0 + i);
00204                         glDisable(light);
00205                 }
00206         }
00207         
00208     objects = 0;
00209     nested_objects = 0;
00210     sensitive = 0;
00211         
00212     browser()->render();
00213         
00214         if (internal_light) {
00215                 if (lit) glDisable(GL_LIGHTING);
00216         }
00217     glDisable(GL_BLEND);
00218     glDisable(GL_CULL_FACE);
00219     //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00220         
00221     glMatrixMode(GL_MODELVIEW);
00222     glPopMatrix();
00223 }
00224 
00225 void  arVrmlViewer::post_redraw()
00226 {
00227 
00228 }
00229 void  arVrmlViewer::set_cursor(cursor_style c)
00230 {
00231 
00232 }
00233 
00234 void  arVrmlViewer::swap_buffers()
00235 {
00236 
00237 }
00238 
00239 void  arVrmlViewer::set_timer(double t)
00240 {
00241 
00242 }
00243 
00244 
00245 void arVrmlViewer::set_viewpoint(const openvrml::vec3f & position,
00246                                  const openvrml::rotation & orientation,
00247                                  float fieldOfView,
00248                                  float avatarSize,
00249                                  float visibilityLimit)
00250 {
00251 
00252 }
00253 
00254 viewer::object_t arVrmlViewer::insert_background(const std::vector<float> & groundAngle,
00255                                                                                                  const std::vector<color> & groundColor,
00256                                                                                                  const std::vector<float> & skyAngle,
00257                                                                                                  const std::vector<color> & skyColor,
00258                                                                                                  const image & front,
00259                                                                                                  const image & back,
00260                                                                                                  const image & left,
00261                                                                                                  const image & right,
00262                                                                                                  const image & top,
00263                                                                                                  const image & bottom)
00264 {
00265         return 0;
00266 }
00267 
00268 viewer::object_t arVrmlViewer::insert_dir_light(float ambientIntensity,
00269                                   float intensity,
00270                                   const openvrml::color & color,
00271                                   const openvrml::vec3f & direction)
00272 {
00273     if (internal_light) return gl::viewer::insert_dir_light(ambientIntensity, intensity, color, direction);
00274     return 0;
00275 }
00276 
00277 viewer::object_t arVrmlViewer::insert_point_light(float ambientIntensity,
00278                                     const openvrml::vec3f & attenuation,
00279                                     const openvrml::color & color,
00280                                     float intensity,
00281                                     const openvrml::vec3f & location,
00282                                     float radius)
00283 {
00284         if (internal_light) return gl::viewer::insert_point_light(ambientIntensity, attenuation, color, intensity, location, radius);
00285 
00286     return 0;
00287 }
00288 
00289  
00290 viewer::object_t arVrmlViewer::insert_spot_light(float ambientIntensity,
00291                                    const openvrml::vec3f & attenuation,
00292                                    float beamWidth,
00293                                    const openvrml::color & color,
00294                                    float cutOffAngle,
00295                                    const openvrml::vec3f & direction,
00296                                    float intensity,
00297                                    const openvrml::vec3f & location,
00298                                    float radius)
00299 {
00300     if (internal_light) return gl::viewer::insert_spot_light(ambientIntensity, attenuation, beamWidth, color,cutOffAngle, direction, intensity, location, radius);
00301     return 0;
00302 }
00303 
00304  bounding_volume::intersection
00305 arVrmlViewer::intersect_view_volume(const bounding_volume & bvolume) const
00306 {
00307   // if( d_cull ) {
00308   //return  openvrml::viewer::intersect_view_volume(bvolume);
00309         // }
00310         // else {
00311          return bounding_volume::inside;
00312         //}
00313 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:14:59