62 #include "ColorStack.hh"
142 return Vec4uc (0, 0, 0, 0);
150 currentNode_ = currentNode_->
pushIndex (_idx);
158 currentNode_ = currentNode_->
popIndex ();
165 std::vector<size_t> rv(0);
166 if (initialized_ && !error_)
168 const size_t idx = translator_.
color2index (_rgba);
169 if (idx >= root_->startIndex () && idx < root_->endIndex ())
170 root_->colorToStack (rv, idx);
181 return translator_.
max_index () - currentNode_->endIndex ();
193 return currentNode_->colorIndex ();
201 ColorStack::Node::Node (
size_t _idx, Node *_parent,
ColorTranslator *_ct) :
209 startIdx_ = endIdx_ = parent_->endIndex ();
211 startIdx_ = endIdx_ = 1;
216 ColorStack::Node::~Node ()
218 for (std::vector<Node *>::iterator it = nodes_.begin (); it != nodes_.end(); ++it)
229 if (colorStartIdx_ == 0 && translator_->
max_index () > endIdx_ + _idx)
231 colorStartIdx_ = endIdx_;
232 endIdx_ = colorEndIdx_ = colorStartIdx_ + _idx;
242 if (colorStartIdx_ && colorStartIdx_ + _idx < colorEndIdx_)
254 if (colorStartIdx_ && colorStartIdx_ + _idx < colorEndIdx_)
256 _rgba = translator_->
index2color(colorStartIdx_ + _idx);
267 nodes_.push_back (n);
275 parent_->endIdx_ = endIdx_;
281 void ColorStack::Node::colorToStack (std::vector<size_t> &_stack,
size_t _index)
283 if (_index >= colorStartIdx_ && _index < colorEndIdx_)
285 _stack.push_back (_index - colorStartIdx_);
289 for (std::vector<Node *>::iterator it = nodes_.begin (); it != nodes_.end(); ++it)
292 if (_index >= n->startIndex () && _index < n->endIndex ())
293 n->colorToStack (_stack, _index);
296 _stack.push_back (index_);
std::vector< size_t > colorToStack(Vec4uc _rgba) const
converts the given color to index values on the stack
bool setMaximumIndex(size_t _idx)
sets the maximum index number used in current node
void pushIndex(size_t _idx)
creates a new node the stack (like glPushName)
Namespace providing different geometric functions concerning angles.
Node * popIndex()
pops the current node from the stack (like glPopName)
ColorStack()
Default constructor.
bool setIndex(size_t _idx) const
sets the current color the given index (like glLoadName)
size_t color2index(const Vec4uc _rgba) const
color -> index (one buffer)
void setIndex(size_t _idx)
sets the current color the given index (like glLoadName)
void initialize()
init (takes current GL context/ like glInitNames (); glPushName (0))
size_t freeIndicies() const
returns maximal available index count
size_t max_index() const
returns maximal convertible index
Node * pushIndex(size_t _idx)
creates a new node the stack (like glPushName)
bool setMaximumIndex(size_t _idx)
sets the maximum index number used in current node
Vec4uc getIndexColor(size_t _idx)
gets the color instead of setting it directly
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
VectorT< unsigned char, 4 > Vec4uc
bool getIndexColor(size_t _idx, Vec4uc &_rgba) const
gets the color instead of setting it directly
size_t currentIndex() const
returns the current color index
Vec4uc index2color(const size_t _idx) const
index -> color (one buffer)
void popIndex()
pops the current node from the stack (like glPopName)