Developer Documentation

RendererInfo.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 #include <OpenFlipper/common/RendererInfo.hh>
44
45 static RenderManager renderManager_;
46 static PostProcessorManager postProcessorManager_;
47
48 RenderManager& renderManager() {
49 return renderManager_;
50 }
51
52 PostProcessorManager& postProcessorManager() {
53 return postProcessorManager_;
54 }
55
56 RendererInfo::RendererInfo():
57 plugin(0),
58 name(""),
59 optionsAction(0)
60 {
61 }
62
63 RendererInfo::RendererInfo(RenderInterface* _plugin,QString _name) :
64 plugin(_plugin),
65 name(_name),
66 optionsAction(0)
67 {
68 }
69
70
71 RenderManager::RenderManager()
72 {
73 availableRenderers_.clear();
74 availableRenderers_.push_back(RendererInfo(0,"Default internal renderer"));
75
76 activeRenderers_.clear();
77 }
78
79 bool RenderManager::rendererExists(QString _name) {
80
81 for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
82 if ( availableRenderers_[i].name == _name)
83 return true;
84
85 return false;
86
87 }
88
89 RendererInfo* RenderManager::newRenderer(QString _name) {
90
91 for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
92 if ( availableRenderers_[i].name == _name)
93 return &availableRenderers_[i];
94
95 availableRenderers_.push_back(RendererInfo());
96 availableRenderers_[availableRenderers_.size()-1].name = _name;
97
98 return &availableRenderers_[availableRenderers_.size()-1];
99 }
100
101 RendererInfo* RenderManager::getRenderer(QString _name) {
102
103 for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
104 if ( availableRenderers_[i].name == _name)
105 return &availableRenderers_[i];
106
107 return 0;
108 }
109
110 int RenderManager::getRendererId(QString _name) {
111
112 for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
113 if ( availableRenderers_[i].name == _name)
114 return i;
115
116 return -1;
117 }
118
119 int RenderManager::countRenderers(ACG::SceneGraph::DrawModes::DrawMode _mode) {
120
121 int renderers = 0;
122
123 // Skip first one as it is the default renderer
124 for ( unsigned int i = 1 ; i < availableRenderers_.size() ; ++i)
125 if ( (availableRenderers_[i].modes & _mode) )
126 renderers++;
127
128 return renderers;
129 }
130
131 RendererInfo* RenderManager::operator[](unsigned int _id) {
132
133 if ( _id >= availableRenderers_.size())
134 return 0;
135 else
136 return &availableRenderers_[_id];
137
138 }
139
140 size_t RenderManager::available() {
141 return availableRenderers_.size();
142 }
143
144
145 void RenderManager::setActive(unsigned int _active, int _id) {
146
147 if ( _id < 0 ) {
148 std::cerr << "RenderManager::setActive illegal viewer id: " << _id << std::endl;
149 return;
150 }
151
152 // Increase vector size
153 if ( _id >= (int)activeRenderers_.size() )
154 activeRenderers_.resize(_id +1 );
155
156 if ( _active < availableRenderers_.size() )
157 activeRenderers_[_id] = _active;
158 else
159 std::cerr << "Out of range error when setting active renderer" << std::endl;
160 }
161
162 void RenderManager::setActive(QString _active, int _id) {
163
164 if ( _id < 0 ) {
165 std::cerr << "RenderManager::setActive illegal viewer id: " << _id << std::endl;
166 return;
167 }
168
169 // Increase vector size
170 if ( _id >= (int)activeRenderers_.size() ) {
171 activeRenderers_.resize(_id +1 );
172
173 }
174
175 for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
176 if ( availableRenderers_[i].name == _active) {
177 activeRenderers_[_id] = i;
178 }
179
180 }
181
182 RendererInfo* RenderManager::active( int _id) {
183
184 // Temporary viewer with no fixed id, return first renderer
185 if ( _id < 0 )
186 return 0;
187
188 // Increase vector size
189 if ( _id >= (int)activeRenderers_.size() )
190 activeRenderers_.resize(_id +1 );
191
192 return &availableRenderers_[activeRenderers_[_id]];
193 }
194
195 unsigned int RenderManager::activeId( int _id) {
196
197 // Temporary viewer with no fixed id, return first renderer
198 if ( _id < 0 )
199 return 0;
200
201 // Increase vector size
202 if ( _id >= (int)activeRenderers_.size() )
203 activeRenderers_.resize(_id +1 );
204
205 return activeRenderers_[_id];
206 }
207
208 //===================================================================
209
210 PostProcessorInfo::PostProcessorInfo(PostProcessorInterface* _plugin, QString _name) :
211 plugin(_plugin),
212 name(_name),
213 optionsAction(0)
214 {
215 }
216
217 PostProcessorInfo::PostProcessorInfo():
218 plugin(0),
219 name(""),
220 optionsAction(0)
221 {
222 }
223
224
225 PostProcessorManager::PostProcessorManager()
226 {
227 availablePostProcessors_.clear();
228 availablePostProcessors_.push_back(PostProcessorInfo(0,"Default internal post processor"));
229
230 activePostProcessors_.clear();
231 }
232
233
234 bool PostProcessorManager::postProcessorExists(QString _name) {
235
236 for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
237 if ( availablePostProcessors_[i].name == _name)
238 return true;
239
240 return false;
241
242 }
243
244 PostProcessorInfo* PostProcessorManager::newPostProcessor(QString _name) {
245
246 for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
247 if ( availablePostProcessors_[i].name == _name)
248 return &availablePostProcessors_[i];
249
250 availablePostProcessors_.push_back(PostProcessorInfo());
251 availablePostProcessors_[availablePostProcessors_.size()-1].name = _name;
252
253 return &availablePostProcessors_[availablePostProcessors_.size()-1];
254 }
255
256 PostProcessorInfo* PostProcessorManager::getPostProcessor(QString _name) {
257
258 for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
259 if ( availablePostProcessors_[i].name == _name)
260 return &availablePostProcessors_[i];
261
262 return 0;
263 }
264
265 PostProcessorInfo* PostProcessorManager::operator[](unsigned int _id ) {
266
267 if ( _id >= availablePostProcessors_.size())
268 return 0;
269 else
270 return &availablePostProcessors_[_id];
271
272 }
273
274 size_t PostProcessorManager::available() {
275 return availablePostProcessors_.size();
276 }
277
278 void PostProcessorManager::setActive(unsigned int _active, int _viewerId ) {
279
280 // Temporary viewer with no fixed id
281 if ( _viewerId < 0 ) {
282 std::cerr << "PostProcessorManager::setActive illegal viewer id: " << _viewerId << std::endl;
283 return;
284 }
285
286 // Increase vector size
287 if ( _viewerId >= (int)activePostProcessors_.size() )
288 activePostProcessors_.resize(_viewerId +1 );
289
290 // clear chain and add postprocessor
291 activePostProcessors_[_viewerId].clear();
292 activePostProcessors_[_viewerId].push_back(_active);
293 }
294
295 void PostProcessorManager::setActive(QString _active, int _id ) {
296
297 // Temporary viewer with no fixed id
298 if ( _id < 0 ) {
299 std::cerr << "PostProcessorManager::setActive illegal viewer id: " << _id << std::endl;
300 return;
301 }
302
303 // Increase vector size
304 if ( _id >= (int)activePostProcessors_.size() )
305 activePostProcessors_.resize(_id +1 );
306
307 for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
308 if ( availablePostProcessors_[i].name == _active) {
309
310 // clear chain and add postprocessor
311 activePostProcessors_[_id].clear();
312 activePostProcessors_[_id].push_back(i);
313 }
314
315 }
316
317 PostProcessorInfo* PostProcessorManager::active( int _id, int _chainIdx ) {
318
319 // Temporary viewer with no fixed id, return first post processor
320 if ( _id < 0 )
321 return 0;
322
323 // Increase vector size
324 if ( _id >= (int)activePostProcessors_.size() )
325 activePostProcessors_.resize(_id +1 );
326
327 if ( (int)activePostProcessors_[_id].size() <= _chainIdx)
328 return 0;
329
330 return &availablePostProcessors_[activePostProcessors_[_id][_chainIdx]];
331 }
332
333 unsigned int PostProcessorManager::activeId( int _id, int _chainIdx ) {
334
335 // Temporary viewer with no fixed id, return first post processor
336 if ( _id < 0 )
337 return 0;
338
339 // Increase vector size
340 if ( _id >= (int)activePostProcessors_.size() )
341 activePostProcessors_.resize(_id +1 );
342
343 if ( (int)activePostProcessors_[_id].size() <= _chainIdx)
344 return 0;
345
346 return activePostProcessors_[_id][_chainIdx];
347 }
348
349 int PostProcessorManager::numActive( int _id ) {
350
351 // Temporary viewer with no fixed id, return first post processor
352 if ( _id < 0 )
353 return 0;
354
355 // Increase vector size
356 if ( _id >= (int)activePostProcessors_.size() )
357 activePostProcessors_.resize(_id +1 );
358
359 return (int)activePostProcessors_[_id].size();
360 }
361
362 void PostProcessorManager::append( unsigned int _active, int _viewerId ) {
363
364 // Temporary viewer with no fixed id
365 if ( _viewerId < 0 ) {
366 std::cerr << "PostProcessorManager::append illegal viewer id: " << _viewerId << std::endl;
367 return;
368 }
369
370 // Increase vector size
371 if ( _viewerId >= (int)activePostProcessors_.size() )
372 activePostProcessors_.resize(_viewerId +1 );
373
374 if ( _active < availablePostProcessors_.size() )
375 activePostProcessors_[_viewerId].push_back(_active);
376 else
377 std::cerr << "Out of range error when setting active post processor" << std::endl;
378
379 }
380
381 void PostProcessorManager::append( QString _active, int _id ) {
382
383 // Temporary viewer with no fixed id
384 if ( _id < 0 ) {
385 std::cerr << "PostProcessorManager::append illegal viewer id: " << _id << std::endl;
386 return;
387 }
388
389 // Increase vector size
390 if ( _id >= (int)activePostProcessors_.size() )
391 activePostProcessors_.resize(_id +1 );
392
393 for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
394 if ( availablePostProcessors_[i].name == _active) {
395 activePostProcessors_[_id].push_back(i);
396 }
397
398 }
399
400
401 void PostProcessorManager::insert( unsigned int _active, int _chainIdx, int _viewerId ) {
402
403 // Temporary viewer with no fixed id
404 if ( _viewerId < 0 ) {
405 std::cerr << "PostProcessorManager::insert illegal viewer id: " << _viewerId << std::endl;
406 return;
407 }
408
409 // Increase vector size
410 if ( _viewerId >= (int)activePostProcessors_.size() )
411 activePostProcessors_.resize(_viewerId +1 );
412
413 if ( _active < availablePostProcessors_.size() )
414 activePostProcessors_[_viewerId].insert(activePostProcessors_[_viewerId].begin() + _chainIdx, _active);
415 else
416 std::cerr << "Out of range error when setting active post processor" << std::endl;
417
418 }
419
420 void PostProcessorManager::insert( QString _active, int _chainIdx, int _id ) {
421
422 // Temporary viewer with no fixed id
423 if ( _id < 0 ) {
424 std::cerr << "PostProcessorManager::insert illegal viewer id: " << _id << std::endl;
425 return;
426 }
427
428 // Increase vector size
429 if ( _id >= (int)activePostProcessors_.size() )
430 activePostProcessors_.resize(_id +1 );
431
432 for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
433 if ( availablePostProcessors_[i].name == _active) {
434 activePostProcessors_[_id].insert(activePostProcessors_[_id].begin() + _chainIdx, i);
435 }
436
437 }
438
439 void PostProcessorManager::remove( int _id, int _chainIdx ) {
440
441 // Temporary viewer with no fixed id, return first post processor
442 if ( _id < 0 )
443 return;
444
445 // Increase vector size
446 if ( _id >= (int)activePostProcessors_.size() )
447 activePostProcessors_.resize(_id +1 );
448
449 if ( (int)activePostProcessors_[_id].size() <= _chainIdx)
450 return;
451
452 activePostProcessors_[_id].erase(activePostProcessors_[_id].begin() + _chainIdx);
453
454 }
455
456
457
PostProcessorManager::getPostProcessor
PostProcessorInfo * getPostProcessor(QString _name)
get post processor with the given name
Definition: RendererInfo.cc:256
PostProcessorManager::active
PostProcessorInfo * active(int _id, int _chainIdx=0)
Get the current active post processor for viewer at chain index.
Definition: RendererInfo.cc:317
RendererInfo::name
QString name
Name of the plugin ( requested from the plugin on load)
Definition: RendererInfo.hh:67
RenderManager::setActive
void setActive(unsigned int _active, int _id)
set the active renderer
Definition: RendererInfo.cc:145
RenderManager::getRendererId
int getRendererId(QString _name)
get renderer id with the given name
Definition: RendererInfo.cc:110
PostProcessorManager::available
size_t available()
number of available post processor
Definition: RendererInfo.cc:274
RenderManager::active
RendererInfo * active(int _id)
Get the current active renderer.
Definition: RendererInfo.cc:182
RendererInfo
Definition: RendererInfo.hh:55
PostProcessorManager::remove
void remove(int _id, int _chainIdx)
Remove a post processor at the specified chain index.
Definition: RendererInfo.cc:439
PostProcessorManager::postProcessorExists
bool postProcessorExists(QString _name)
Check if a post processor with the given name exists.
Definition: RendererInfo.cc:234
PostProcessorInfo::name
QString name
Name of the plugin ( requested from the plugin on load)
Definition: RendererInfo.hh:196
PostProcessorManager::newPostProcessor
PostProcessorInfo * newPostProcessor(QString _name)
Get a new post processor Instance.
Definition: RendererInfo.cc:244
PostProcessorManager::append
void append(unsigned int _active, int _viewerId)
Append the active post processor to the chain for viewer.
Definition: RendererInfo.cc:362
PostProcessorInfo
Definition: RendererInfo.hh:184
PostProcessorManager::insert
void insert(unsigned int _active, int _chainIdx, int _viewerId)
Insert the active post processor to the chain for viewer.
Definition: RendererInfo.cc:401
RenderManager::rendererExists
bool rendererExists(QString _name)
Check if a renderer with the given name exists.
Definition: RendererInfo.cc:79
PostProcessorInterface
Interface to add global image post processor functions from within plugins.
Definition: PostProcessorInterface.hh:147
RenderManager::newRenderer
RendererInfo * newRenderer(QString _name)
Get a new renderer Instance.
Definition: RendererInfo.cc:89
PostProcessorManager::activeId
unsigned int activeId(int _id, int _chainIdx=0)
Get the id of the active post processor for viewer at chain index.
Definition: RendererInfo.cc:333
PostProcessorManager
Definition: RendererInfo.hh:210
PostProcessorManager::setActive
void setActive(unsigned int _active, int _viewerId)
set the active post processor for viewer
Definition: RendererInfo.cc:278
RenderManager
Definition: RendererInfo.hh:83
RenderManager::operator[]
RendererInfo * operator[](unsigned int _id)
Get the renderer with the given id.
Definition: RendererInfo.cc:131
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
PostProcessorManager::operator[]
PostProcessorInfo * operator[](unsigned int _id)
Get the post processor with the given id.
Definition: RendererInfo.cc:265
RenderManager::activeId
unsigned int activeId(int _id)
Get the id of the active renderer.
Definition: RendererInfo.cc:195
PostProcessorManager::numActive
int numActive(int _id)
Get the number of active post processors for viewer.
Definition: RendererInfo.cc:349
RenderManager::countRenderers
int countRenderers(ACG::SceneGraph::DrawModes::DrawMode _mode)
count renderers for a DrawMode (excluding the default renderer)
Definition: RendererInfo.cc:119
RenderManager::available
size_t available()
number of available renderers
Definition: RendererInfo.cc:140
RenderInterface
Interface to add additional rendering functions from within plugins.
Definition: RenderInterface.hh:60
RenderManager::getRenderer
RendererInfo * getRenderer(QString _name)
get renderer with the given name
Definition: RendererInfo.cc:101