SCM Library
Spherical Cube Map rendering library
 All Classes Files Functions Variables Friends Pages
scm-system.hpp
1 // Copyright (C) 2011-2014 Robert Kooima
2 //
3 // LIBSCM is free software; you can redistribute it and/or modify it under the
4 // terms of the GNU General Public License as published by the Free Software
5 // Foundation; either version 2 of the License, or (at your option) any later
6 // version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITH-
9 // OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 
13 #ifndef SCM_SYSTEM_HPP
14 #define SCM_SYSTEM_HPP
15 
16 #include <map>
17 #include <set>
18 
19 #include <SDL.h>
20 #include <SDL_thread.h>
21 
22 #include "scm-file.hpp"
23 #include "scm-step.hpp"
24 
84 //------------------------------------------------------------------------------
85 
86 class scm_scene;
87 class scm_cache;
88 class scm_sphere;
89 class scm_render;
90 
91 typedef std::vector<scm_step *> scm_step_v;
92 typedef std::vector<scm_step *>::iterator scm_step_i;
93 
94 typedef std::vector<scm_scene *> scm_scene_v;
95 typedef std::vector<scm_scene *>::iterator scm_scene_i;
96 
97 //------------------------------------------------------------------------------
99 
102 
103 struct active_pair
104 {
105  active_pair() : file(0), cache(0) { }
106  active_pair(scm_file *f, scm_cache *c) : file(f), cache(c) { }
107 
108  scm_file *file;
109  scm_cache *cache;
110 };
111 
112 typedef std::map<int, active_pair> active_pair_m;
113 
115 
116 struct active_file
117 {
118  active_file() : file(0), uses(0), index(-1) { }
119 
120  scm_file *file;
121  int uses;
122  int index;
123 };
124 
125 typedef std::map<std::string, active_file> active_file_m;
126 
128 
129 struct active_cache
130 {
131  active_cache() : cache(0), uses(0) { }
132 
133  scm_cache *cache;
134  int uses;
135 };
136 
139 
140 struct cache_param
141 {
142  cache_param(scm_file *file) : n(int(file->get_w()) - 2),
143  c(int(file->get_c())),
144  b(int(file->get_b())) { }
145 
146  int n; // Page size
147  int c; // Channels per pixel
148  int b; // Bits per channel
149 
150  bool operator<(const cache_param& that) const {
151  if (n < that.n) return true;
152  else if (n > that.n) return false;
153  else if (c < that.c) return true;
154  else if (c > that.c) return false;
155  else if (b < that.b) return true;
156  else return false;
157  }
158 };
159 
160 typedef std::map<cache_param, active_cache> active_cache_m;
161 typedef std::map<cache_param, active_cache>::iterator active_cache_i;
162 
164 //------------------------------------------------------------------------------
165 
174 
176 {
177 public:
178 
179  scm_system(int w, int h, int d, int l);
180  ~scm_system();
181 
182  void render_sphere(const double *, const double *, int) const;
183 
186 
187  scm_sphere *get_sphere() const;
188  scm_render *get_render() const;
189  scm_scene *get_fore() const;
190  scm_scene *get_back() const;
191 
195 
196  int add_scene(int i);
197  void del_scene(int i);
198  scm_scene *get_scene(int i);
199 
200  int get_scene_count() const;
201  double set_scene_blend(double);
202 
206 
207  int add_step(int i);
208  void del_step(int i);
209  scm_step *get_step(int i);
210 
211  int get_step_count() const;
212  scm_step get_step_blend(double) const;
213 
217 
218  void import_queue(const std::string&);
219  void export_queue( std::string&);
220  void append_queue(scm_step *);
221  void flush_queue();
222 
226 
227  void update_cache();
228  void render_cache();
229  void flush_cache();
230 
231  void set_synchronous(bool);
232  bool get_synchronous() const;
233 
237 
238  float get_current_ground(const double *) const;
239  float get_minimum_ground() const;
240 
244 
245  int acquire_scm(const std::string&);
246  int release_scm(const std::string&);
247 
248  scm_scene *find_scene(const std::string&) const;
249  scm_cache *get_cache(int);
250  scm_file *get_file (int);
251 
252  float get_page_sample(int f, const double *v);
253  bool get_page_status(int f, long long i);
254  void get_page_bounds(int f, long long i, float& r0, float& r1);
255 
257 
258 private:
259 
260  SDL_mutex *mutex;
261 
262  scm_step_v steps;
263  scm_step_v queue;
264  scm_scene_v scenes;
265 
266  scm_render *render;
267  scm_sphere *sphere;
268  scm_scene *fore0;
269  scm_scene *fore1;
270  scm_scene *back0;
271  scm_scene *back1;
272 
273  active_file_m files;
274  active_cache_m caches;
275  active_pair_m pairs;
276 
277  int serial;
278  int frame;
279  bool sync;
280  double fade;
281 };
282 
283 //------------------------------------------------------------------------------
284 
285 #endif
bool get_page_status(int f, long long i)
Return true if a page is present in the SCM file. O(log n).
Definition: scm-system.cpp:648
void update_cache()
Update all image caches. This is among the most significant entry points of the SCM API as it handles...
Definition: scm-system.cpp:395
float get_minimum_ground() const
Return the minimum ground level of the current scene, e.g. the radius of the planet at the bottom of ...
Definition: scm-system.cpp:464
int get_scene_count() const
Return the number of scenes in the collection.
Definition: scm-system.cpp:174
scm_sphere * get_sphere() const
Return a pointer to the sphere geometry handler.
Definition: scm-system.cpp:100
void del_step(int i)
Delete the step at index i.
Definition: scm-system.cpp:227
void del_scene(int i)
Delete the scene at index i.
Definition: scm-system.cpp:149
An scm_render manages the rendering of background and foreground spheres.
Definition: scm-render.hpp:39
scm_cache * get_cache(int)
Return the cache associated with the given file index.
Definition: scm-system.cpp:589
bool get_synchronous() const
Return the synchronous flag.
Definition: scm-system.cpp:437
An scm_step defines a view configuration.
Definition: scm-step.hpp:32
An scm_scene encapsulates the definition of a sphere and its parameters.
Definition: scm-scene.hpp:40
scm_render * get_render() const
Return a pointer to the render manager.
Definition: scm-system.cpp:107
scm_file * get_file(int)
Return the file associated with the given file index.
Definition: scm-system.cpp:599
void flush_cache()
Flush all image caches. All pages are ejected from all caches.
Definition: scm-system.cpp:420
An scm_file encapsulates an open SCM data file.
Definition: scm-file.hpp:37
float get_current_ground(const double *) const
Return the ground level of current scene at the given location. O(log n). This may incur data access ...
Definition: scm-system.cpp:449
scm_step * get_step(int i)
Return a pointer to the step at index i.
Definition: scm-system.cpp:237
An scm_sphere generates the adaptive rendered geometry of the 3D sphere.
Definition: scm-sphere.hpp:30
scm_system(int w, int h, int d, int l)
Create a new empty SCM system. Instantiate a render handler and a sphere handler. ...
Definition: scm-system.cpp:47
void append_queue(scm_step *)
Take ownership of the given step and append it to the current queue.
Definition: scm-system.cpp:373
float get_page_sample(int f, const double *v)
Sample an SCM file at the given location. O(log n). This may incur data access in the render thread...
Definition: scm-system.cpp:615
int get_step_count() const
Return the number of steps in the collection.
Definition: scm-system.cpp:247
void import_queue(const std::string &)
Parse the given string as a series of camera states. Enqueue each. This function ingests Maya MOV exp...
Definition: scm-system.cpp:296
int acquire_scm(const std::string &)
Internal: Load the named SCM file, if not already loaded.
Definition: scm-system.cpp:485
void set_synchronous(bool)
In synchronous mode, scm_cache::update will block until all background input handling is complete...
Definition: scm-system.cpp:430
int release_scm(const std::string &)
Release the named SCM file.
Definition: scm-system.cpp:535
scm_step get_step_blend(double) const
Compute the interpolated values of the current step queue at the given time. Extrapolate the first an...
Definition: scm-system.cpp:280
double set_scene_blend(double)
Set the scene caches and fade coefficient to produce a rendering of the current step queue at time t...
Definition: scm-system.cpp:182
void export_queue(std::string &)
Print all steps on the current queue to the given string using the same format expected by import_que...
Definition: scm-system.cpp:339
void render_cache()
Render a 2D overlay of the contents of all caches. This can be a helpful visual debugging tool as wel...
Definition: scm-system.cpp:406
int add_step(int i)
Allocate and insert a new step before index i. Return its index.
Definition: scm-system.cpp:211
void get_page_bounds(int f, long long i, float &r0, float &r1)
Determine the minimum and maximum values of an SCM file page. O(log n).
Definition: scm-system.cpp:631
scm_scene * get_scene(int i)
Return a pointer to the scene at index i, or 0 if i is out-of-range.
Definition: scm-system.cpp:164
scm_scene * get_back() const
Return a pointer to the current background scene.
Definition: scm-system.cpp:121
~scm_system()
Finalize all SCM system state.
Definition: scm-system.cpp:63
scm_scene * get_fore() const
Return a pointer to the current foreground scene.
Definition: scm-system.cpp:114
void render_sphere(const double *, const double *, int) const
Render the sphere. This is among the most significant entry points of the SCM API as it is the simple...
Definition: scm-system.cpp:89
An scm_system encapsulates all of the state of an SCM renderer. Its interface is the primary API of t...
Definition: scm-system.hpp:175
int add_scene(int i)
Allocate and insert a new scene before index i. Return its index.
Definition: scm-system.cpp:130
void flush_queue()
Flush the current step queue, deleting all steps in it.
Definition: scm-system.cpp:380
scm_scene * find_scene(const std::string &) const
Return the scene with the given name.
Definition: scm-system.cpp:578
An scm_cache is a virtual texture, demand-paged with threaded data access, represented as a single la...
Definition: scm-cache.hpp:35