Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 #include <OpenFlipper/common/RendererInfo.hh>
53 
54 static RenderManager renderManager_;
55 static PostProcessorManager postProcessorManager_;
56 
57 RenderManager& renderManager() {
58  return renderManager_;
59 }
60 
61 PostProcessorManager& postProcessorManager() {
62  return postProcessorManager_;
63 }
64 
65 RendererInfo::RendererInfo():
66  plugin(0),
67  name(""),
68  optionsAction(0)
69 {
70 }
71 
72 RendererInfo::RendererInfo(RenderInterface* _plugin,QString _name) :
73  plugin(_plugin),
74  name(_name),
75  optionsAction(0)
76 {
77 }
78 
79 
80 RenderManager::RenderManager()
81 {
82  availableRenderers_.clear();
83  availableRenderers_.push_back(RendererInfo(0,"Default internal renderer"));
84 
85  activeRenderers_.clear();
86 }
87 
88 bool RenderManager::rendererExists(QString _name) {
89 
90  for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
91  if ( availableRenderers_[i].name == _name)
92  return true;
93 
94  return false;
95 
96 }
97 
99 
100  for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
101  if ( availableRenderers_[i].name == _name)
102  return &availableRenderers_[i];
103 
104  availableRenderers_.push_back(RendererInfo());
105  availableRenderers_[availableRenderers_.size()-1].name = _name;
106 
107  return &availableRenderers_[availableRenderers_.size()-1];
108 }
109 
111 
112  for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
113  if ( availableRenderers_[i].name == _name)
114  return &availableRenderers_[i];
115 
116  return 0;
117 }
118 
119 int RenderManager::getRendererId(QString _name) {
120 
121  for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
122  if ( availableRenderers_[i].name == _name)
123  return i;
124 
125  return -1;
126 }
127 
129 
130  int renderers = 0;
131 
132  // Skip first one as it is the default renderer
133  for ( unsigned int i = 1 ; i < availableRenderers_.size() ; ++i)
134  if ( (availableRenderers_[i].modes & _mode) )
135  renderers++;
136 
137  return renderers;
138 }
139 
141 
142  if ( _id >= availableRenderers_.size())
143  return 0;
144  else
145  return &availableRenderers_[_id];
146 
147 }
148 
149 unsigned int RenderManager::available() {
150  return availableRenderers_.size();
151 }
152 
153 
154 void RenderManager::setActive(unsigned int _active, int _id) {
155 
156  if ( _id < 0 ) {
157  std::cerr << "RenderManager::setActive illegal viewer id: " << _id << std::endl;
158  return;
159  }
160 
161  // Increase vector size
162  if ( _id >= (int)activeRenderers_.size() )
163  activeRenderers_.resize(_id +1 );
164 
165  if ( _active < availableRenderers_.size() )
166  activeRenderers_[_id] = _active;
167  else
168  std::cerr << "Out of range error when setting active renderer" << std::endl;
169 }
170 
171 void RenderManager::setActive(QString _active, int _id) {
172 
173  if ( _id < 0 ) {
174  std::cerr << "RenderManager::setActive illegal viewer id: " << _id << std::endl;
175  return;
176  }
177 
178  // Increase vector size
179  if ( _id >= (int)activeRenderers_.size() ) {
180  activeRenderers_.resize(_id +1 );
181 
182  }
183 
184  for ( unsigned int i = 0 ; i < availableRenderers_.size() ; ++i)
185  if ( availableRenderers_[i].name == _active) {
186  activeRenderers_[_id] = i;
187  }
188 
189 }
190 
192 
193  // Temporary viewer with no fixed id, return first renderer
194  if ( _id < 0 )
195  return 0;
196 
197  // Increase vector size
198  if ( _id >= (int)activeRenderers_.size() )
199  activeRenderers_.resize(_id +1 );
200 
202 }
203 
204 unsigned int RenderManager::activeId( int _id) {
205 
206  // Temporary viewer with no fixed id, return first renderer
207  if ( _id < 0 )
208  return 0;
209 
210  // Increase vector size
211  if ( _id >= (int)activeRenderers_.size() )
212  activeRenderers_.resize(_id +1 );
213 
214  return activeRenderers_[_id];
215 }
216 
217 //===================================================================
218 
219 PostProcessorInfo::PostProcessorInfo(PostProcessorInterface* _plugin, QString _name) :
220  plugin(_plugin),
221  name(_name),
222  optionsAction(0)
223 {
224 }
225 
226 PostProcessorInfo::PostProcessorInfo():
227  plugin(0),
228  name(""),
229  optionsAction(0)
230 {
231 }
232 
233 
234 PostProcessorManager::PostProcessorManager()
235 {
236  availablePostProcessors_.clear();
237  availablePostProcessors_.push_back(PostProcessorInfo(0,"Default internal post processor"));
238 
239  activePostProcessors_.clear();
240 }
241 
242 
244 
245  for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
246  if ( availablePostProcessors_[i].name == _name)
247  return true;
248 
249  return false;
250 
251 }
252 
254 
255  for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
256  if ( availablePostProcessors_[i].name == _name)
257  return &availablePostProcessors_[i];
258 
260  availablePostProcessors_[availablePostProcessors_.size()-1].name = _name;
261 
263 }
264 
266 
267  for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
268  if ( availablePostProcessors_[i].name == _name)
269  return &availablePostProcessors_[i];
270 
271  return 0;
272 }
273 
275 
276  if ( _id >= availablePostProcessors_.size())
277  return 0;
278  else
279  return &availablePostProcessors_[_id];
280 
281 }
282 
284  return availablePostProcessors_.size();
285 }
286 
287 void PostProcessorManager::setActive(unsigned int _active, int _viewerId ) {
288 
289  // Temporary viewer with no fixed id
290  if ( _viewerId < 0 ) {
291  std::cerr << "PostProcessorManager::setActive illegal viewer id: " << _viewerId << std::endl;
292  return;
293  }
294 
295  // Increase vector size
296  if ( _viewerId >= (int)activePostProcessors_.size() )
297  activePostProcessors_.resize(_viewerId +1 );
298 
299  // clear chain and add postprocessor
300  activePostProcessors_[_viewerId].clear();
301  activePostProcessors_[_viewerId].push_back(_active);
302 }
303 
304 void PostProcessorManager::setActive(QString _active, int _id ) {
305 
306  // Temporary viewer with no fixed id
307  if ( _id < 0 ) {
308  std::cerr << "PostProcessorManager::setActive illegal viewer id: " << _id << std::endl;
309  return;
310  }
311 
312  // Increase vector size
313  if ( _id >= (int)activePostProcessors_.size() )
314  activePostProcessors_.resize(_id +1 );
315 
316  for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
317  if ( availablePostProcessors_[i].name == _active) {
318 
319  // clear chain and add postprocessor
320  activePostProcessors_[_id].clear();
321  activePostProcessors_[_id].push_back(i);
322  }
323 
324 }
325 
327 
328  // Temporary viewer with no fixed id, return first post processor
329  if ( _id < 0 )
330  return 0;
331 
332  // Increase vector size
333  if ( _id >= (int)activePostProcessors_.size() )
334  activePostProcessors_.resize(_id +1 );
335 
336  if ( (int)activePostProcessors_[_id].size() <= _chainIdx)
337  return 0;
338 
339  return &availablePostProcessors_[activePostProcessors_[_id][_chainIdx]];
340 }
341 
342 unsigned int PostProcessorManager::activeId( int _id, int _chainIdx ) {
343 
344  // Temporary viewer with no fixed id, return first post processor
345  if ( _id < 0 )
346  return 0;
347 
348  // Increase vector size
349  if ( _id >= (int)activePostProcessors_.size() )
350  activePostProcessors_.resize(_id +1 );
351 
352  if ( (int)activePostProcessors_[_id].size() <= _chainIdx)
353  return 0;
354 
355  return activePostProcessors_[_id][_chainIdx];
356 }
357 
359 
360  // Temporary viewer with no fixed id, return first post processor
361  if ( _id < 0 )
362  return 0;
363 
364  // Increase vector size
365  if ( _id >= (int)activePostProcessors_.size() )
366  activePostProcessors_.resize(_id +1 );
367 
368  return (int)activePostProcessors_[_id].size();
369 }
370 
371 void PostProcessorManager::append( unsigned int _active, int _viewerId ) {
372 
373  // Temporary viewer with no fixed id
374  if ( _viewerId < 0 ) {
375  std::cerr << "PostProcessorManager::append illegal viewer id: " << _viewerId << std::endl;
376  return;
377  }
378 
379  // Increase vector size
380  if ( _viewerId >= (int)activePostProcessors_.size() )
381  activePostProcessors_.resize(_viewerId +1 );
382 
383  if ( _active < availablePostProcessors_.size() )
384  activePostProcessors_[_viewerId].push_back(_active);
385  else
386  std::cerr << "Out of range error when setting active post processor" << std::endl;
387 
388 }
389 
390 void PostProcessorManager::append( QString _active, int _id ) {
391 
392  // Temporary viewer with no fixed id
393  if ( _id < 0 ) {
394  std::cerr << "PostProcessorManager::append illegal viewer id: " << _id << std::endl;
395  return;
396  }
397 
398  // Increase vector size
399  if ( _id >= (int)activePostProcessors_.size() )
400  activePostProcessors_.resize(_id +1 );
401 
402  for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
403  if ( availablePostProcessors_[i].name == _active) {
404  activePostProcessors_[_id].push_back(i);
405  }
406 
407 }
408 
409 
410 void PostProcessorManager::insert( unsigned int _active, int _chainIdx, int _viewerId ) {
411 
412  // Temporary viewer with no fixed id
413  if ( _viewerId < 0 ) {
414  std::cerr << "PostProcessorManager::insert illegal viewer id: " << _viewerId << std::endl;
415  return;
416  }
417 
418  // Increase vector size
419  if ( _viewerId >= (int)activePostProcessors_.size() )
420  activePostProcessors_.resize(_viewerId +1 );
421 
422  if ( _active < availablePostProcessors_.size() )
423  activePostProcessors_[_viewerId].insert(activePostProcessors_[_viewerId].begin() + _chainIdx, _active);
424  else
425  std::cerr << "Out of range error when setting active post processor" << std::endl;
426 
427 }
428 
429 void PostProcessorManager::insert( QString _active, int _chainIdx, int _id ) {
430 
431  // Temporary viewer with no fixed id
432  if ( _id < 0 ) {
433  std::cerr << "PostProcessorManager::insert illegal viewer id: " << _id << std::endl;
434  return;
435  }
436 
437  // Increase vector size
438  if ( _id >= (int)activePostProcessors_.size() )
439  activePostProcessors_.resize(_id +1 );
440 
441  for ( unsigned int i = 0 ; i < availablePostProcessors_.size() ; ++i)
442  if ( availablePostProcessors_[i].name == _active) {
443  activePostProcessors_[_id].insert(activePostProcessors_[_id].begin() + _chainIdx, i);
444  }
445 
446 }
447 
448 void PostProcessorManager::remove( int _id, int _chainIdx ) {
449 
450  // Temporary viewer with no fixed id, return first post processor
451  if ( _id < 0 )
452  return;
453 
454  // Increase vector size
455  if ( _id >= (int)activePostProcessors_.size() )
456  activePostProcessors_.resize(_id +1 );
457 
458  if ( (int)activePostProcessors_[_id].size() <= _chainIdx)
459  return;
460 
461  activePostProcessors_[_id].erase(activePostProcessors_[_id].begin() + _chainIdx);
462 
463 }
464 
465 
466 
int countRenderers(ACG::SceneGraph::DrawModes::DrawMode _mode)
count renderers for a DrawMode (excluding the default renderer)
void remove(int _id, int _chainIdx)
Remove a post processor at the specified chain index.
std::vector< std::vector< unsigned int > > activePostProcessors_
The currently active post processor chain.
unsigned int available()
number of available post processor
std::vector< PostProcessorInfo > availablePostProcessors_
Vector holding all available post processors.
bool postProcessorExists(QString _name)
Check if a post processor with the given name exists.
void append(unsigned int _active, int _viewerId)
Append the active post processor to the chain for viewer.
PostProcessorInfo * getPostProcessor(QString _name)
get post processor with the given name
Interface to add additional rendering functions from within plugins.
void setActive(unsigned int _active, int _viewerId)
set the active post processor for viewer
PostProcessorInfo * operator[](unsigned int _id)
Get the post processor with the given id.
PostProcessorInfo * newPostProcessor(QString _name)
Get a new post processor Instance.
RendererInfo * active(int _id)
Get the current active renderer.
void insert(unsigned int _active, int _chainIdx, int _viewerId)
Insert the active post processor to the chain for viewer.
unsigned int available()
number of available renderers
int numActive(int _id)
Get the number of active post processors for viewer.
RendererInfo * operator[](unsigned int _id)
Get the renderer with the given id.
bool rendererExists(QString _name)
Check if a renderer with the given name exists.
Definition: RendererInfo.cc:88
RendererInfo * newRenderer(QString _name)
Get a new renderer Instance.
Definition: RendererInfo.cc:98
unsigned int activeId(int _id)
Get the id of the active renderer.
PostProcessorInfo * active(int _id, int _chainIdx=0)
Get the current active post processor for viewer at chain index.
Interface to add global image post processor functions from within plugins.
std::vector< unsigned int > activeRenderers_
The currently active renderer ids.
int getRendererId(QString _name)
get renderer id with the given name
void setActive(unsigned int _active, int _id)
set the active renderer
RendererInfo * getRenderer(QString _name)
get renderer with the given name
unsigned int activeId(int _id, int _chainIdx=0)
Get the id of the active post processor for viewer at chain index.
std::vector< RendererInfo > availableRenderers_
Vector holding all available renderers.