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