|
<html><head><title>dlib C++ Library - 3d_point_cloud_ex.cpp</title></head><body bgcolor='white'><pre> |
|
<font color='#009900'>// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt |
|
</font><font color='#009900'>/* |
|
|
|
This is an example illustrating the use of the perspective_window tool |
|
in the dlib C++ Library. It is a simple tool for displaying 3D point |
|
clouds on the screen. |
|
|
|
*/</font> |
|
|
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>dlib<font color='#5555FF'>/</font>gui_widgets.h<font color='#5555FF'>></font> |
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>dlib<font color='#5555FF'>/</font>image_transforms.h<font color='#5555FF'>></font> |
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>cmath<font color='#5555FF'>></font> |
|
|
|
<font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib; |
|
<font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>int</u></font> <b><a name='main'></a>main</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// Let's make a point cloud that looks like a 3D spiral. |
|
</font> std::vector<font color='#5555FF'><</font>perspective_window::overlay_dot<font color='#5555FF'>></font> points; |
|
dlib::rand rnd; |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> <font color='#979000'>20</font>; i<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>0.001</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// Get a point on a spiral |
|
</font> dlib::vector<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>val</font><font face='Lucida Console'>(</font><font color='#BB00BB'>sin</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>,<font color='#BB00BB'>cos</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>,i<font color='#5555FF'>/</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// Now add some random noise to it |
|
</font> dlib::vector<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>></font> <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font>rnd.<font color='#BB00BB'>get_random_gaussian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rnd.<font color='#BB00BB'>get_random_gaussian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rnd.<font color='#BB00BB'>get_random_gaussian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
val <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp<font color='#5555FF'>/</font><font color='#979000'>20</font>; |
|
|
|
<font color='#009900'>// Pick a color based on how far we are along the spiral |
|
</font> rgb_pixel color <font color='#5555FF'>=</font> <font color='#BB00BB'>colormap_jet</font><font face='Lucida Console'>(</font>i,<font color='#979000'>0</font>,<font color='#979000'>20</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// And add the point to the list of points we will display |
|
</font> points.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>perspective_window::<font color='#BB00BB'>overlay_dot</font><font face='Lucida Console'>(</font>val, color<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// Now finally display the point cloud. |
|
</font> perspective_window win; |
|
win.<font color='#BB00BB'>set_title</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>perspective_window 3D point cloud</font>"<font face='Lucida Console'>)</font>; |
|
win.<font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>points<font face='Lucida Console'>)</font>; |
|
win.<font color='#BB00BB'>wait_until_closed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------- |
|
</font> |
|
|
|
</pre></body></html> |