Developer Documentation

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 // CLASS ColorStack
45 //
46 //=============================================================================
47
48 #ifndef ACG_COLORSTACK_HH
49 #define ACG_COLORSTACK_HH
50
51
52 //== INCLUDES =================================================================
53
54 #include <vector>
55
56 #include <ACG/GL/gl.hh>
57 #include <ACG/Math/VectorT.hh>
58 #include "ColorTranslator.hh"
59
60
61 //== NAMESPACES ===============================================================
62
63
64 namespace ACG {
65
66 class GLState;
67
68 //== CLASS DEFINITION =========================================================
69
70
73 class ACGDLLEXPORT ColorStack
74 {
75 public:
76
78 ColorStack();
80 ~ColorStack();
81
83 void initialize(ACG::GLState*);
85 bool initialized() const { return initialized_; }
86
88 bool setMaximumIndex (size_t _idx);
89
91 void setIndex (size_t _idx);
92
94 Vec4uc getIndexColor (size_t _idx);
95
97 void pushIndex (size_t _idx);
98
100 void popIndex ();
101
103 std::vector<size_t> colorToStack (Vec4uc _rgba) const;
104
106 size_t freeIndicies () const;
107
109 bool error () const { return error_ && initialized_; };
110
112 size_t currentIndex () const;
113
114 private:
115
116 // Internal class used realize the color stack
117
118 class Node {
119 public:
120 Node (size_t _idx, Node *_parent, ColorTranslator *_ct);
121 ~Node ();
122
124 bool setMaximumIndex (size_t _idx);
125
127 bool setIndex (size_t _idx) const;
128
130 bool getIndexColor (size_t _idx, Vec4uc &_rgba) const;
131
133 Node * pushIndex (size_t _idx);
134
136 Node * popIndex ();
137
138 void colorToStack (std::vector<size_t> &_stack, size_t size_t);
139
140 size_t startIndex () const { return startIdx_; };
141 size_t endIndex () const { return endIdx_; };
142 size_t colorIndex () const { return colorStartIdx_; };
143
144 private:
145 Node *parent_;
146 size_t index_;
147 ColorTranslator *translator_;
148 std::vector<Node *> nodes_;
149
150 size_t startIdx_;
151 size_t endIdx_;
152 size_t colorStartIdx_;
153 size_t colorEndIdx_;
154
155 };
156
157 bool initialized_;
158 ColorTranslator translator_;
159 Node *root_;
160 Node *currentNode_;
161 bool error_;
162 };
163
164
165 //=============================================================================
166 } // namespace ACG
167 //=============================================================================
168 #endif // ACG_COLORSTACK_HH defined
169 //=============================================================================
170
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::ColorStack::initialized
bool initialized() const
has it been initialized?
Definition: ColorStack.hh:85
ACG::GLState
Definition: GLState.hh:213
ACG::ColorStack
Definition: ColorStack.hh:73
ACG::ColorTranslator
Definition: ColorTranslator.hh:75
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::ColorStack::error
bool error() const
Did an error occur during picking.
Definition: ColorStack.hh:109
ACG::ColorStack::Node
Definition: ColorStack.hh:118