Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/distort/nonlinearImager.h

Go to the documentation of this file.
00001 // Filename: nonlinearImager.h
00002 // Created by:  drose (12Dec01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef NONLINEARIMAGER_H
00020 #define NONLINEARIMAGER_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "projectionScreen.h"
00025 #include "displayRegion.h"
00026 #include "camera.h"
00027 #include "texture.h"
00028 #include "pandaNode.h"
00029 #include "nodePath.h"
00030 #include "pointerTo.h"
00031 #include "pvector.h"
00032 
00033 class GraphicsEngine;
00034 class GraphicsStateGuardian;
00035 class GraphicsWindow;
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //       Class : NonlinearImager
00039 // Description : This class object combines the rendered output of a
00040 //               3-d from one or more linear (e.g. perspective)
00041 //               cameras, as seen through a single, possibly nonlinear
00042 //               camera.
00043 //
00044 //               This can be used to generate real-time imagery of a
00045 //               3-d scene using a nonlinear camera, for instance a
00046 //               fisheye camera, even though the underlying graphics
00047 //               engine may only support linear cameras.  It can also
00048 //               pre-distort imagery to compensate for off-axis
00049 //               projectors, and/or curved screens of any complexity.
00050 //
00051 //               
00052 //               A NonlinearImager may be visualized as a dark room
00053 //               into which a number of projection screens have been
00054 //               placed, of arbitrary size and shape and at any
00055 //               arbitrary position and orientation to each other.
00056 //               Onto each of these screens is projected the view as
00057 //               seen by a normal perspective camera that exists in
00058 //               the world (that is, under render).
00059 //
00060 //               There also exist in the room one or more (possibly
00061 //               nonlinear) cameras, called viewers, that observe
00062 //               these screens.  The image of the projection screens
00063 //               seen by each viewer is finally displayed on the
00064 //               viewer's associated DisplayRegion.  By placing the
00065 //               viewer(s) appropriately relative to the screens, and
00066 //               by choosing suitable lens properties for the
00067 //               viewer(s), you can achieve a wide variety of
00068 //               distortion effects.
00069 //
00070 //
00071 //               There are several different LensNode (Camera) objects
00072 //               involved at each stage in the process.  To help keep
00073 //               them all straight, different words are used to refer
00074 //               to each different kind of Camera used within this
00075 //               object.  The camera(s) under render, that capture the
00076 //               original view of the world to be projected onto the
00077 //               screens, are called source cameras, and are set per
00078 //               screen via set_source_camera().  The LensNode that is
00079 //               associated with each screen to project the image as
00080 //               seen from the screen's source camera is called a
00081 //               projector; these are set via the
00082 //               ProjectionScreen::set_projector() interface.
00083 //               Finally, the cameras that view the whole
00084 //               configuration of screens are called viewers; each of
00085 //               these is associated with a DisplayRegion, and they
00086 //               are set via set_viewer_camera().
00087 //
00088 //               Of all these lenses, only the source cameras must use
00089 //               linear (that is, perspective or orthographic) lenses.
00090 //               The projectors and viewers may be any arbitrary lens,
00091 //               linear or otherwise.
00092 ////////////////////////////////////////////////////////////////////
00093 class EXPCL_PANDAFX NonlinearImager {
00094 PUBLISHED:
00095   NonlinearImager();
00096   ~NonlinearImager();
00097 
00098   int add_screen(ProjectionScreen *screen);
00099   int find_screen(ProjectionScreen *screen) const;
00100   void remove_screen(int index);
00101   void remove_all_screens();
00102 
00103   int get_num_screens() const;
00104   ProjectionScreen *get_screen(int index) const;
00105   void set_texture_size(int index, int width, int height);
00106   void set_source_camera(int index, const NodePath &source_camera);
00107 
00108   void set_screen_active(int index, bool active);
00109   bool get_screen_active(int index) const;
00110 
00111   int add_viewer(DisplayRegion *dr);
00112   int find_viewer(DisplayRegion *dr) const;
00113   void remove_viewer(int index);
00114   void remove_all_viewers();
00115 
00116   void set_viewer_camera(int index, const NodePath &viewer_camera);
00117   NodePath get_viewer_camera(int index) const;
00118 
00119   NodePath get_internal_scene(int index) const;
00120 
00121   int get_num_viewers() const;
00122   DisplayRegion *get_viewer(int index) const;
00123 
00124   void recompute();
00125   void render(GraphicsEngine *engine);
00126 
00127 private:
00128   class Viewer {
00129   public:
00130     PT(DisplayRegion) _dr;
00131     PT(Camera) _internal_camera;
00132     NodePath _internal_scene;
00133     NodePath _viewer;
00134     PT(LensNode) _viewer_node;
00135     UpdateSeq _viewer_lens_change;
00136   };
00137   typedef pvector<Viewer> Viewers;
00138 
00139   class Mesh {
00140   public:
00141     NodePath _mesh;
00142     UpdateSeq _last_screen;
00143   };
00144   typedef pvector<Mesh> Meshes;
00145 
00146   class Screen {
00147   public:
00148     PT(ProjectionScreen) _screen;
00149     PT(Texture) _texture;
00150     NodePath _source_camera;
00151     int _tex_width, _tex_height;
00152     bool _active;
00153 
00154     // One mesh per viewer.
00155     Meshes _meshes;
00156   };
00157   typedef pvector<Screen> Screens;
00158 
00159   void recompute_if_stale();
00160   void recompute_screen(Screen &screen, size_t vi);
00161   void render_screen(GraphicsEngine *engine, Screen &screen);
00162 
00163   Viewers _viewers;
00164   Screens _screens;
00165   GraphicsStateGuardian *_gsg;
00166   GraphicsWindow *_win;
00167 
00168   bool _stale;
00169 };
00170 
00171 #include "nonlinearImager.I"
00172 
00173 #endif

Generated on Fri May 2 00:36:39 2003 for Panda by doxygen1.3