Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ColorStack.hh
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  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS ColorStack
55 //
56 //=============================================================================
57 
58 #ifndef ACG_COLORSTACK_HH
59 #define ACG_COLORSTACK_HH
60 
61 
62 //== INCLUDES =================================================================
63 
64 #include <vector>
65 
66 #include <ACG/GL/gl.hh>
67 #include <ACG/Math/VectorT.hh>
68 #include "ColorTranslator.hh"
69 
70 
71 //== NAMESPACES ===============================================================
72 
73 
74 namespace ACG {
75 
76 
77 //== CLASS DEFINITION =========================================================
78 
79 
82 class ACGDLLEXPORT ColorStack
83 {
84 public:
85 
87  ColorStack();
89  ~ColorStack();
90 
91 
93  void initialize();
95  bool initialized() const { return initialized_; }
96 
98  bool setMaximumIndex (unsigned int _idx);
99 
101  void setIndex (unsigned int _idx);
102 
104  Vec4uc getIndexColor (unsigned int _idx);
105 
107  void pushIndex (unsigned int _idx);
108 
110  void popIndex ();
111 
113  std::vector<unsigned int> colorToStack (Vec4uc _rgba) const;
114 
116  unsigned int freeIndicies () const;
117 
119  bool error () const { return error_ && initialized_; };
120 
122  unsigned int currentIndex () const;
123 
124 private:
125 
126  // Internal class used realize the color stack
127 
128  class Node {
129  public:
130  Node (unsigned int _idx, Node *_parent, ColorTranslator *_ct);
131  ~Node ();
132 
134  bool setMaximumIndex (unsigned int _idx);
135 
137  bool setIndex (unsigned int _idx) const;
138 
140  bool getIndexColor (unsigned int _idx, Vec4uc &_rgba) const;
141 
143  Node * pushIndex (unsigned int _idx);
144 
146  Node * popIndex ();
147 
148  void colorToStack (std::vector<unsigned int> &_stack, unsigned int _index);
149 
150  unsigned int startIndex () { return startIdx_; };
151  unsigned int endIndex () { return endIdx_; };
152  unsigned int colorIndex () { return colorStartIdx_; };
153 
154  private:
155  Node *parent_;
156  unsigned int index_;
157  ColorTranslator *translator_;
158  std::vector<Node *> nodes_;
159 
160  unsigned int startIdx_;
161  unsigned int endIdx_;
162  unsigned int colorStartIdx_;
163  unsigned int colorEndIdx_;
164 
165  };
166 
167  bool initialized_;
168  ColorTranslator translator_;
169  Node *root_;
170  Node *currentNode_;
171  bool error_;
172 };
173 
174 
175 //=============================================================================
176 } // namespace ACG
177 //=============================================================================
178 #endif // ACG_COLORSTACK_HH defined
179 //=============================================================================
180 
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
bool initialized() const
has it been initialized?
Definition: ColorStack.hh:95
bool error() const
Did an error occur during picking.
Definition: ColorStack.hh:119