MCPcopy Create free account
hub / github.com/OctoMap/octomap / writeColorHistogram

Method writeColorHistogram

octomap/src/ColorOcTree.cpp:208–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206 }
207
208 void ColorOcTree::writeColorHistogram(std::string filename) {
209
210#ifdef _MSC_VER
211 fprintf(stderr, "The color histogram uses gnuplot, this is not supported under windows.\n");
212#else
213 // build RGB histogram
214 std::vector<int> histogram_r (256,0);
215 std::vector<int> histogram_g (256,0);
216 std::vector<int> histogram_b (256,0);
217 for(ColorOcTree::tree_iterator it = this->begin_tree(),
218 end=this->end_tree(); it!= end; ++it) {
219 if (!it.isLeaf() || !this->isNodeOccupied(*it)) continue;
220 ColorOcTreeNode::Color& c = it->getColor();
221 ++histogram_r[c.r];
222 ++histogram_g[c.g];
223 ++histogram_b[c.b];
224 }
225 // plot data
226 FILE *gui = popen("gnuplot ", "w");
227 fprintf(gui, "set term postscript eps enhanced color\n");
228 fprintf(gui, "set output \"%s\"\n", filename.c_str());
229 fprintf(gui, "plot [-1:256] ");
230 fprintf(gui,"'-' w filledcurve lt 1 lc 1 tit \"r\",");
231 fprintf(gui, "'-' w filledcurve lt 1 lc 2 tit \"g\",");
232 fprintf(gui, "'-' w filledcurve lt 1 lc 3 tit \"b\",");
233 fprintf(gui, "'-' w l lt 1 lc 1 tit \"\",");
234 fprintf(gui, "'-' w l lt 1 lc 2 tit \"\",");
235 fprintf(gui, "'-' w l lt 1 lc 3 tit \"\"\n");
236
237 for (int i=0; i<256; ++i) fprintf(gui,"%d %d\n", i, histogram_r[i]);
238 fprintf(gui,"0 0\n"); fprintf(gui, "e\n");
239 for (int i=0; i<256; ++i) fprintf(gui,"%d %d\n", i, histogram_g[i]);
240 fprintf(gui,"0 0\n"); fprintf(gui, "e\n");
241 for (int i=0; i<256; ++i) fprintf(gui,"%d %d\n", i, histogram_b[i]);
242 fprintf(gui,"0 0\n"); fprintf(gui, "e\n");
243 for (int i=0; i<256; ++i) fprintf(gui,"%d %d\n", i, histogram_r[i]);
244 fprintf(gui, "e\n");
245 for (int i=0; i<256; ++i) fprintf(gui,"%d %d\n", i, histogram_g[i]);
246 fprintf(gui, "e\n");
247 for (int i=0; i<256; ++i) fprintf(gui,"%d %d\n", i, histogram_b[i]);
248 fprintf(gui, "e\n");
249 fflush(gui);
250#endif
251 }
252
253 std::ostream& operator<<(std::ostream& out, ColorOcTreeNode::Color const& c) {
254 return out << '(' << (unsigned int)c.r << ' ' << (unsigned int)c.g << ' ' << (unsigned int)c.b << ')';

Callers 1

mainFunction · 0.80

Calls 4

begin_treeMethod · 0.80
end_treeMethod · 0.80
isNodeOccupiedMethod · 0.80
getColorMethod · 0.80

Tested by

no test coverage detected