diff --git a/examples/3d_point_cloud_ex.cpp b/examples/3d_point_cloud_ex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3cb7d09fa0688d5f34ff9643121c35982b231f32 --- /dev/null +++ b/examples/3d_point_cloud_ex.cpp @@ -0,0 +1,48 @@ +// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt +/* + + 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. + +*/ + +#include <dlib/gui_widgets.h> +#include <dlib/image_transforms.h> + +using namespace dlib; + +// ---------------------------------------------------------------------------------------- + +int main() +{ + // Let's make a point cloud that looks like a 3D spiral. + std::vector<perspective_window::overlay_dot> points; + dlib::rand rnd; + for (double i = 0; i < 20; i+=0.001) + { + // Get a point on a spiral + dlib::vector<double> val(sin(i),cos(i),i/4); + + // Now add some random noise to it + dlib::vector<double> temp(rnd.get_random_gaussian(), + rnd.get_random_gaussian(), + rnd.get_random_gaussian()); + val += temp/20; + + // Pick a color based on how far we are along the spiral + rgb_pixel color = colormap_jet(i,0,20); + + // And add the point to the list of points we will display + points.push_back(perspective_window::overlay_dot(val, color)); + } + + // Now finally display the point cloud. + perspective_window win; + win.set_title("perspective_window 3D point cloud"); + win.add_overlay(points); + win.wait_until_closed(); +} + +// ---------------------------------------------------------------------------- + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 392341ae783c77aecd89db2038c2145ab614a6ba..1e0a150fb6bbc220bb0532a6df1a9a092060151d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -31,6 +31,7 @@ ENDMACRO() #here we apply our macros +add_example(3d_point_cloud_ex) add_example(bayes_net_ex) add_example(bayes_net_from_disk_ex) add_example(bayes_net_gui_ex)