1 #pragma once 2 3 #include <cstring> 4 #include "linalg.h" 5 6 #define FLAG(var, flag, on) on ? (var |= flag) : (var &= ~flag) 7 8 class State 9 { 10 public: State(const class AbstractNode * parent)11 State(const class AbstractNode *parent) 12 : flags(NONE), parentnode(parent), numchildren(0) { 13 this->matrix_ = Transform3d::Identity(); 14 this->color_.fill(-1.0f); 15 } ~State()16 virtual ~State() {} 17 setPrefix(bool on)18 void setPrefix(bool on) { FLAG(this->flags, PREFIX, on); } setPostfix(bool on)19 void setPostfix(bool on) { FLAG(this->flags, POSTFIX, on); } setHighlight(bool on)20 void setHighlight(bool on) { FLAG(this->flags, HIGHLIGHT, on); } setBackground(bool on)21 void setBackground(bool on) { FLAG(this->flags, BACKGROUND, on); } setNumChildren(unsigned int numc)22 void setNumChildren(unsigned int numc) { this->numchildren = numc; } setParent(const AbstractNode * parent)23 void setParent(const AbstractNode *parent) { this->parentnode = parent; } setMatrix(const Transform3d & m)24 void setMatrix(const Transform3d &m) { this->matrix_ = m; } setColor(const Color4f & c)25 void setColor(const Color4f &c) { this->color_ = c; } setPreferNef(bool on)26 void setPreferNef(bool on) { FLAG(this->flags, PREFERNEF, on); } preferNef()27 bool preferNef() const { return this->flags & PREFERNEF; } 28 isPrefix()29 bool isPrefix() const { return this->flags & PREFIX; } isPostfix()30 bool isPostfix() const { return this->flags & POSTFIX; } isHighlight()31 bool isHighlight() const { return this->flags & HIGHLIGHT; } isBackground()32 bool isBackground() const { return this->flags & BACKGROUND; } numChildren()33 unsigned int numChildren() const { return this->numchildren; } parent()34 const AbstractNode *parent() const { return this->parentnode; } matrix()35 const Transform3d &matrix() const { return this->matrix_; } color()36 const Color4f &color() const { return this->color_; } 37 38 private: 39 enum StateFlags { 40 NONE = 0x00, 41 PREFIX = 0x01, 42 POSTFIX = 0x02, 43 PREFERNEF = 0x04, 44 HIGHLIGHT = 0x08, 45 BACKGROUND = 0x10 46 }; 47 48 unsigned int flags; 49 const AbstractNode * parentnode; 50 unsigned int numchildren; 51 52 // Transformation matrix and color. FIXME: Generalize such state variables? 53 Transform3d matrix_; 54 Color4f color_; 55 }; 56