当前位置:网站首页>Description of octomap averagenodecolor function

Description of octomap averagenodecolor function

2022-07-06 07:37:00 Blue feather birds

averageNodeColor yes ColorOcTreeNode The function in , Parameter is x,y,z,r,g,b
 Insert picture description here
But the official website didn't say how this function works average color Of , So we have to start with the source code
According to the tips on the official website , This function is in the Definition at line 144 of file ColorOcTree.h.

00144     ColorOcTreeNode* averageNodeColor(const float& x, const float& y, 
00145                                       const float& z, const unsigned char& r, 
00146                                       const unsigned char& g, const unsigned char& b) {
    
00147       OcTreeKey key;
00148       if (!this->coordToKeyChecked(point3d(x,y,z), key)) return NULL;
00149       return averageNodeColor(key,r,g,b);
00150     }

You can see the call averageNodeColor(key, r, g, b), So look at the code of this overloaded function

00145   ColorOcTreeNode* ColorOcTree::averageNodeColor(const OcTreeKey& key, 
00146                                                  const unsigned char& r, 
00147                                                  const unsigned char& g, 
00148                                                  const unsigned char& b) {
    
00149     ColorOcTreeNode* n = search (key);
00150     if (n != 0) {
    
00151       if (n->isColorSet()) {
    
00152         ColorOcTreeNode::Color prev_color = n->getColor();
00153         n->setColor((prev_color.r + r)/2, (prev_color.g + g)/2, (prev_color.b + b)/2); 
00154       }
00155       else {
    
00156         n->setColor(r, g, b);
00157       }
00158     }
00159     return n;
00160   }

You can see that every new color comes (r, g, b), Just average the previous color with the new color , It is equivalent to averaging all colors at this point .

原网站

版权声明
本文为[Blue feather birds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060731357152.html