4141
4242namespace octomap {
4343
44+ // forward declaraton for "friend"
45+ class ColorOcTree ;
46+
4447 // node definition
4548 class ColorOcTreeNode : public OcTreeNode {
4649 public:
50+ friend class ColorOcTree ; // needs access to node children (inherited)
4751
4852 class Color {
4953 public:
5054 Color () : r(255 ), g(255 ), b(255 ) {}
51- Color (unsigned char _r, unsigned char _g, unsigned char _b)
55+ Color (uint8_t _r, uint8_t _g, uint8_t _b)
5256 : r(_r), g(_g), b(_b) {}
5357 inline bool operator == (const Color &other) const {
5458 return (r==other.r && g==other.g && b==other.b );
5559 }
5660 inline bool operator != (const Color &other) const {
5761 return (r!=other.r || g!=other.g || b!=other.b );
5862 }
59- unsigned char r, g, b;
63+ uint8_t r, g, b;
6064 };
6165
6266 public:
@@ -68,26 +72,14 @@ namespace octomap {
6872 return (rhs.value == value && rhs.color == color);
6973 }
7074
71- // children
72- inline ColorOcTreeNode* getChild (unsigned int i) {
73- return static_cast <ColorOcTreeNode*> (OcTreeNode::getChild (i));
74- }
75- inline const ColorOcTreeNode* getChild (unsigned int i) const {
76- return static_cast <const ColorOcTreeNode*> (OcTreeNode::getChild (i));
75+ void copyData (const ColorOcTreeNode& from){
76+ OcTreeNode::copyData (from);
77+ this ->color = from.getColor ();
7778 }
78-
79- bool createChild (unsigned int i) {
80- if (children == NULL ) allocChildren ();
81- children[i] = new ColorOcTreeNode ();
82- return true ;
83- }
84-
85- bool pruneNode ();
86- void expandNode ();
87-
79+
8880 inline Color getColor () const { return color; }
8981 inline void setColor (Color c) {this ->color = c; }
90- inline void setColor (unsigned char r, unsigned char g, unsigned char b) {
82+ inline void setColor (uint8_t r, uint8_t g, uint8_t b) {
9183 this ->color = Color (r,g,b);
9284 }
9385
@@ -104,8 +96,8 @@ namespace octomap {
10496 ColorOcTreeNode::Color getAverageChildColor () const ;
10597
10698 // file I/O
107- std::istream& readValue (std::istream &s);
108- std::ostream& writeValue (std::ostream &s) const ;
99+ std::istream& readData (std::istream &s);
100+ std::ostream& writeData (std::ostream &s) const ;
109101
110102 protected:
111103 Color color;
@@ -124,38 +116,48 @@ namespace octomap {
124116 ColorOcTree* create () const {return new ColorOcTree (resolution); }
125117
126118 std::string getTreeType () const {return " ColorOcTree" ;}
127-
119+
120+ /* *
121+ * Prunes a node when it is collapsible. This overloaded
122+ * version only considers the node occupancy for pruning,
123+ * different colors of child nodes are ignored.
124+ * @return true if pruning was successful
125+ */
126+ virtual bool pruneNode (ColorOcTreeNode* node);
127+
128+ virtual bool isNodeCollapsible (const ColorOcTreeNode* node) const ;
129+
128130 // set node color at given key or coordinate. Replaces previous color.
129- ColorOcTreeNode* setNodeColor (const OcTreeKey& key, const unsigned char & r,
130- const unsigned char & g, const unsigned char & b);
131+ ColorOcTreeNode* setNodeColor (const OcTreeKey& key, uint8_t r,
132+ uint8_t g, uint8_t b);
131133
132- ColorOcTreeNode* setNodeColor (const float & x, const float & y,
133- const float & z, const unsigned char & r,
134- const unsigned char & g, const unsigned char & b) {
134+ ColorOcTreeNode* setNodeColor (float x, float y,
135+ float z, uint8_t r,
136+ uint8_t g, uint8_t b) {
135137 OcTreeKey key;
136138 if (!this ->coordToKeyChecked (point3d (x,y,z), key)) return NULL ;
137139 return setNodeColor (key,r,g,b);
138140 }
139141
140142 // integrate color measurement at given key or coordinate. Average with previous color
141- ColorOcTreeNode* averageNodeColor (const OcTreeKey& key, const unsigned char & r,
142- const unsigned char & g, const unsigned char & b);
143+ ColorOcTreeNode* averageNodeColor (const OcTreeKey& key, uint8_t r,
144+ uint8_t g, uint8_t b);
143145
144- ColorOcTreeNode* averageNodeColor (const float & x, const float & y,
145- const float & z, const unsigned char & r,
146- const unsigned char & g, const unsigned char & b) {
146+ ColorOcTreeNode* averageNodeColor (float x, float y,
147+ float z, uint8_t r,
148+ uint8_t g, uint8_t b) {
147149 OcTreeKey key;
148150 if (!this ->coordToKeyChecked (point3d (x,y,z), key)) return NULL ;
149151 return averageNodeColor (key,r,g,b);
150152 }
151153
152154 // integrate color measurement at given key or coordinate. Average with previous color
153- ColorOcTreeNode* integrateNodeColor (const OcTreeKey& key, const unsigned char & r,
154- const unsigned char & g, const unsigned char & b);
155+ ColorOcTreeNode* integrateNodeColor (const OcTreeKey& key, uint8_t r,
156+ uint8_t g, uint8_t b);
155157
156- ColorOcTreeNode* integrateNodeColor (const float & x, const float & y,
157- const float & z, const unsigned char & r,
158- const unsigned char & g, const unsigned char & b) {
158+ ColorOcTreeNode* integrateNodeColor (float x, float y,
159+ float z, uint8_t r,
160+ uint8_t g, uint8_t b) {
159161 OcTreeKey key;
160162 if (!this ->coordToKeyChecked (point3d (x,y,z), key)) return NULL ;
161163 return integrateNodeColor (key,r,g,b);
@@ -181,6 +183,7 @@ namespace octomap {
181183 public:
182184 StaticMemberInitializer () {
183185 ColorOcTree* tree = new ColorOcTree (0.1 );
186+ tree->clearKeyRays ();
184187 AbstractOcTree::registerTreeType (tree);
185188 }
186189
0 commit comments