Panda3D
 All Classes Functions Variables Enumerations
nonlinearImager.h
1 // Filename: nonlinearImager.h
2 // Created by: drose (12Dec01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef NONLINEARIMAGER_H
16 #define NONLINEARIMAGER_H
17 
18 #include "pandabase.h"
19 
20 #include "projectionScreen.h"
21 #include "displayRegion.h"
22 #include "graphicsOutput.h"
23 #include "camera.h"
24 #include "texture.h"
25 #include "pandaNode.h"
26 #include "nodePath.h"
27 #include "pointerTo.h"
28 #include "pvector.h"
29 #include "graphicsEngine.h"
30 #include "callbackObject.h"
31 #include "asyncTask.h"
32 
33 class GraphicsEngine;
35 class GraphicsOutput;
36 class GenericAsyncTask;
37 
38 ////////////////////////////////////////////////////////////////////
39 // Class : NonlinearImager
40 // Description : This class object combines the rendered output of a
41 // 3-d from one or more linear (e.g. perspective)
42 // cameras, as seen through a single, possibly nonlinear
43 // camera.
44 //
45 // This can be used to generate real-time imagery of a
46 // 3-d scene using a nonlinear camera, for instance a
47 // fisheye camera, even though the underlying graphics
48 // engine may only support linear cameras. It can also
49 // pre-distort imagery to compensate for off-axis
50 // projectors, and/or curved screens of any complexity.
51 //
52 //
53 // A NonlinearImager may be visualized as a dark room
54 // into which a number of projection screens have been
55 // placed, of arbitrary size and shape and at any
56 // arbitrary position and orientation to each other.
57 // Onto each of these screens is projected the view as
58 // seen by a normal perspective camera that exists in
59 // the world (that is, under render).
60 //
61 // There also exist in the room one or more (possibly
62 // nonlinear) cameras, called viewers, that observe
63 // these screens. The image of the projection screens
64 // seen by each viewer is finally displayed on the
65 // viewer's associated DisplayRegion. By placing the
66 // viewer(s) appropriately relative to the screens, and
67 // by choosing suitable lens properties for the
68 // viewer(s), you can achieve a wide variety of
69 // distortion effects.
70 //
71 //
72 // There are several different LensNode (Camera) objects
73 // involved at each stage in the process. To help keep
74 // them all straight, different words are used to refer
75 // to each different kind of Camera used within this
76 // object. The camera(s) under render, that capture the
77 // original view of the world to be projected onto the
78 // screens, are called source cameras, and are set per
79 // screen via set_source_camera(). The LensNode that is
80 // associated with each screen to project the image as
81 // seen from the screen's source camera is called a
82 // projector; these are set via the
83 // ProjectionScreen::set_projector() interface.
84 // Finally, the cameras that view the whole
85 // configuration of screens are called viewers; each of
86 // these is associated with a DisplayRegion, and they
87 // are set via set_viewer_camera().
88 //
89 // Of all these lenses, only the source cameras must use
90 // linear (that is, perspective or orthographic) lenses.
91 // The projectors and viewers may be any arbitrary lens,
92 // linear or otherwise.
93 ////////////////////////////////////////////////////////////////////
94 class EXPCL_PANDAFX NonlinearImager {
95 PUBLISHED:
97  ~NonlinearImager();
98 
99  int add_screen(ProjectionScreen *screen);
100  int add_screen(const NodePath &screen, const string &name);
101  int find_screen(const NodePath &screen) const;
102  void remove_screen(int index);
103  void remove_all_screens();
104 
105  int get_num_screens() const;
106  NodePath get_screen(int index) const;
107  MAKE_SEQ(get_screens, get_num_screens, get_screen);
108  GraphicsOutput *get_buffer(int index) const;
109  MAKE_SEQ(get_buffers, get_num_screens, get_buffer);
110 
111  void set_texture_size(int index, int width, int height);
112  void set_source_camera(int index, const NodePath &source_camera);
113 
114  void set_screen_active(int index, bool active);
115  bool get_screen_active(int index) const;
116 
117  int add_viewer(DisplayRegion *dr);
118  int find_viewer(DisplayRegion *dr) const;
119  void remove_viewer(int index);
120  void remove_all_viewers();
121 
122  void set_viewer_camera(int index, const NodePath &viewer_camera);
123  NodePath get_viewer_camera(int index) const;
124  NodePath get_viewer_scene(int index) const;
125 
126  int get_num_viewers() const;
127  DisplayRegion *get_viewer(int index) const;
128  MAKE_SEQ(get_viewers, get_num_viewers, get_viewer);
129 
130  NodePath get_dark_room() const;
131  GraphicsEngine *get_graphics_engine() const;
132 
133  void recompute();
134 
135 public:
136  static AsyncTask::DoneStatus recompute_callback(GenericAsyncTask *task, void *data);
137  void recompute_if_stale();
138 
139 private:
140  class Viewer {
141  public:
142  PT(DisplayRegion) _dr;
143  PT(Camera) _internal_camera;
144  NodePath _internal_scene;
145  NodePath _viewer;
146  PT(LensNode) _viewer_node;
147  UpdateSeq _viewer_lens_change;
148  };
149  typedef pvector<Viewer> Viewers;
150 
151  class Mesh {
152  public:
153  NodePath _mesh;
154  UpdateSeq _last_screen;
155  };
156  typedef pvector<Mesh> Meshes;
157 
158  class Screen {
159  public:
160  NodePath _screen;
161  PT(ProjectionScreen) _screen_node;
162  string _name;
163  PT(GraphicsOutput) _buffer;
164  NodePath _source_camera;
165  int _tex_width, _tex_height;
166  bool _active;
167 
168  // One mesh per viewer.
169  Meshes _meshes;
170  };
171  typedef pvector<Screen> Screens;
172 
173  void recompute_screen(Screen &screen, size_t vi);
174  void render_screen(GraphicsEngine *engine, Screen &screen);
175 
176  Viewers _viewers;
177  Screens _screens;
178 
179  PT(GraphicsEngine) _engine;
180  PT(AsyncTask) _recompute_task;
181  NodePath _dark_room;
182 
183  bool _stale;
184 };
185 
186 #include "nonlinearImager.I"
187 
188 #endif
A node that contains a Lens.
Definition: lensNode.h:32
This class object combines the rendered output of a 3-d from one or more linear (e.g.
Associates a generic C-style function pointer with an AsyncTask object.
A ProjectionScreen implements a simple system for projective texturing.
This is a base class for the various different classes that represent the result of a frame of render...
This class represents a concrete task performed by an AsyncManager.
Definition: asyncTask.h:43
Encapsulates all the communication with a particular instance of a given rendering backend...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
This class is the main interface to controlling the render process.
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:37
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165