Commit 79baeb0e authored by Philip ABBET's avatar Philip ABBET

New release from sandbox

parent 1ec8d0d8
......@@ -94,17 +94,19 @@ set(GFX2_SUPPORT_SOURCES
)
# Declare the support files needed for OpenGL3 (using GLSL & gfx3.h) demos
set(GFX3_SUPPORT_SOURCES
${PROJECT_SOURCE_DIR}/src/utils/imgui_impl_glfw_gl3.cpp
${PROJECT_SOURCE_DIR}/src/utils/imgui.cpp
${PROJECT_SOURCE_DIR}/src/utils/imgui_draw.cpp
${PROJECT_SOURCE_DIR}/src/utils/gfx_ui.cpp
${PROJECT_SOURCE_DIR}/src/utils/gfx3.cpp
# Executables
add_executable(demo_ergodicControl_2D01
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_ergodicControl_2D01.cpp
${PROJECT_SOURCE_DIR}/src/utils/mpc_utils.cpp
)
target_link_libraries(demo_ergodicControl_2D01
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIB}
${ARMADILLO_LIBRARIES}
)
# Executables
add_executable(demo_GMR01
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_GMR01.cpp
......@@ -116,19 +118,53 @@ target_link_libraries(demo_GMR01
${ARMADILLO_LIBRARIES}
)
add_executable(demo_infHorLQR01_glsl
${GFX3_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_infHorLQR01_glsl.cpp
add_executable(demo_GPR01
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_GPR01.cpp
)
target_link_libraries(demo_infHorLQR01_glsl
target_link_libraries(demo_GPR01
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIB}
${ARMADILLO_LIBRARIES}
)
add_executable(demo_HSMM_batchLQR01
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_HSMM_batchLQR01.cpp
)
target_link_libraries(demo_HSMM_batchLQR01
${OPENGL_LIBRARIES}
${ARMADILLO_LIBRARIES}
${GLFW_LIB}
${GLEW_LIBRARIES}
)
add_executable(demo_LWR_batch01
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_LWR_batch01.cpp
)
target_link_libraries(demo_LWR_batch01
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIB}
${ARMADILLO_LIBRARIES}
)
add_executable(demo_LWR_iterative01
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_LWR_iterative01.cpp
)
target_link_libraries(demo_LWR_iterative01
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIB}
${ARMADILLO_LIBRARIES}
)
add_executable(demo_MPC_batch01
${GL2_SUPPORT_SOURCES}
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_MPC_batch01.cpp
${PROJECT_SOURCE_DIR}/src/utils/mpc_utils.cpp
${PROJECT_SOURCE_DIR}/src/utils/gl2ps.c
......@@ -138,10 +174,11 @@ target_link_libraries(demo_MPC_batch01
${OPENGL_LIBRARIES}
${ARMADILLO_LIBRARIES}
${GLFW_LIB}
${GLEW_LIBRARIES}
)
add_executable(demo_MPC_iterative01
${GL2_SUPPORT_SOURCES}
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_MPC_iterative01.cpp
${PROJECT_SOURCE_DIR}/src/utils/mpc_utils.cpp
)
......@@ -150,10 +187,11 @@ target_link_libraries(demo_MPC_iterative01
${OPENGL_LIBRARIES}
${ARMADILLO_LIBRARIES}
${GLFW_LIB}
${GLEW_LIBRARIES}
)
add_executable(demo_MPC_semitied01
${GL2_SUPPORT_SOURCES}
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_MPC_semitied01.cpp
${PROJECT_SOURCE_DIR}/src/utils/mpc_utils.cpp
${PROJECT_SOURCE_DIR}/src/utils/gl2ps.c
......@@ -162,10 +200,11 @@ target_link_libraries(demo_MPC_semitied01
${OPENGL_LIBRARIES}
${ARMADILLO_LIBRARIES}
${GLFW_LIB}
${GLEW_LIBRARIES}
)
add_executable(demo_MPC_velocity01
${GL2_SUPPORT_SOURCES}
${GFX2_SUPPORT_SOURCES}
${PROJECT_SOURCE_DIR}/src/demo_MPC_velocity01.cpp
${PROJECT_SOURCE_DIR}/src/utils/mpc_utils.cpp
${PROJECT_SOURCE_DIR}/src/utils/gl2ps.c
......@@ -174,6 +213,7 @@ target_link_libraries(demo_MPC_velocity01
${OPENGL_LIBRARIES}
${ARMADILLO_LIBRARIES}
${GLFW_LIB}
${GLEW_LIBRARIES}
)
add_executable(demo_online_GMM01
......
# PbDlib-cpp-sandbox
# PbDlib-cpp
PbDlib-cpp-sandbox is a set of tools in C++ combining statistical learning, optimal control and differential geometry for programming-by-demonstration applications.
PbDlib-cpp is a set of tools in C++ combining statistical learning, optimal control and differential geometry for programming-by-demonstration applications.
Other versions of the library are available at http://www.idiap.ch/software/pbdlib/ (in Matlab, C++ and Python).
......@@ -13,8 +13,14 @@ This work was in part supported by the DexROV project through the EC H2020 progr
### Prerequisite
The program requires glfw3 (lightweight and portable library for managing OpenGL contexts, windows and inputs) and
Armadillo (C++ library for linear algebra & scientific computing). Instructions are given below.
The program requires:
- *glfw3* (lightweight and portable library for managing OpenGL contexts, windows and inputs)
- *GLEW* (The OpenGL Extension Wrangler Library)
- *LAPACK* (Linear Algebra PACKage)
- *Armadillo* (C++ library for linear algebra & scientific computing)
Instructions are given below.
ImGui (graphical user interface library for C++, [https://github.com/ocornut/imgui](https://github.com/ocornut/imgui)) and
gfx_ui (a minimal geometry editing UI, [https://github.com/colormotor/gfx\_ui](https://github.com/colormotor/gfx_ui)), are also
......@@ -34,10 +40,10 @@ make
### glfw3 installation
**On Debian:**
**On Debian and Ubuntu:**
```
sudo apt-get install libglfw3-dev
sudo apt-get install libglfw3-dev
```
**Installation from source**
......@@ -59,6 +65,24 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
static library.
### GLEW installation
**On Debian and Ubuntu:**
```
sudo apt-get install libglew-dev
```
### LAPACK installation
**On Debian and Ubuntu:**
```
sudo apt-get install liblapack-dev
```
### Armadillo installation
See [http://arma.sourceforge.net/download.html](http://arma.sourceforge.net/download.html)
......@@ -78,6 +102,12 @@ See [examples.md](./examples.md)
***
[demo\_GPR01.cpp](./src/demo_GPR01.cpp)
![](https://gitlab.idiap.ch/rli/pbdlib-cpp/raw/master/images/demo_GPR01.gif)
***
[demo\_MPC\_batch01.cpp](./src/demo_MPC_batch01.cpp)
![](https://gitlab.idiap.ch/rli/pbdlib-cpp/raw/master/images/demo_MPC_batch01.gif)
......
ARMA_MAT_TXT_FN008
4 8
9.52582433819771e-02 2.64691840857267e-02 9.51822921633720e-02 1.13339841365814e-01 9.53103303909302e-02 2.15707466006279e-01 9.53146666288376e-02 2.37892791628838e-01
4.58216160535812e-01 1.68154299259186e-01 4.58710938692093e-01 7.65657573938370e-02 4.58629548549652e-01 1.57467454671860e-01 4.58499342203140e-01 3.23121756315231e-01
0.00000000000000e+00 -1.08463540673256e-02 0.00000000000000e+00 9.67881933320314e-04 0.00000000000000e+00 1.50325521826744e-02 0.00000000000000e+00 1.82703994214535e-02
2.50000003725290e-02 -1.44889326766133e-02 2.50000003725290e-02 -1.40039063990116e-02 2.50000003725290e-02 -1.41308596357703e-02 2.50000003725290e-02 1.55143225565553e-02
This diff is collapsed.
ARMA_MAT_TXT_FN008
4 8
1.66666671633720e-01 7.77777805924416e-02 1.66666671633720e-01 9.77777764201164e-02 1.66666671633720e-01 5.38888871669769e-02 1.66666671633720e-01 6.61111101508141e-02
4.58333343267441e-01 1.31666660308838e-01 4.58333343267441e-01 1.39166668057442e-01 4.58333343267441e-01 1.35000005364418e-01 4.58333343267441e-01 1.10833331942558e-01
0.00000000000000e+00 -5.55555569007993e-04 0.00000000000000e+00 -1.11111113801599e-03 0.00000000000000e+00 -1.11111113801599e-03 0.00000000000000e+00 -5.55555569007993e-04
2.50000003725290e-02 -2.08333339542150e-02 2.50000003725290e-02 -1.49999996647239e-02 2.50000003725290e-02 -1.16666667163372e-02 2.50000003725290e-02 -1.33333336561918e-02
This diff is collapsed.
ARMA_MAT_TXT_FN008
4 10
1.66483521461487e-01 2.16262057423592e-01 1.66483521461487e-01 6.82893320918083e-02 1.66483521461487e-01 8.84615406394005e-02 1.66483521461487e-01 2.68131881952286e-01 1.66483521461487e-01 1.46153852343559e-01
4.58745867013931e-01 1.20309405028820e-01 4.58745867013931e-01 8.72561037540436e-02 4.58745867013931e-01 2.02970296144485e-01 4.58745867013931e-01 2.15346530079842e-01 4.58745867013931e-01 1.33663371205330e-01
0.00000000000000e+00 -3.75198520487174e-04 0.00000000000000e+00 -2.24803457967937e-03 0.00000000000000e+00 1.85198104009032e-03 0.00000000000000e+00 2.19112867489457e-03 0.00000000000000e+00 -1.08944403473288e-03
2.47524753212929e-02 -9.23957489430904e-03 2.47524753212929e-02 -8.34755878895521e-03 2.47524753212929e-02 -1.21426973491907e-02 2.47524753212929e-02 -9.19921137392521e-03 2.47524753212929e-02 -1.49771561846137e-02
This diff is collapsed.
images/demo_GMR01.gif

280 KB | W: | H:

images/demo_GMR01.gif

296 KB | W: | H:

images/demo_GMR01.gif
images/demo_GMR01.gif
images/demo_GMR01.gif
images/demo_GMR01.gif
  • 2-up
  • Swipe
  • Onion skin
images/demo_TPGMMProduct01.gif

119 KB | W: | H:

images/demo_TPGMMProduct01.gif

126 KB | W: | H:

images/demo_TPGMMProduct01.gif
images/demo_TPGMMProduct01.gif
images/demo_TPGMMProduct01.gif
images/demo_TPGMMProduct01.gif
  • 2-up
  • Swipe
  • Onion skin
images/demo_TPbatchLQR01.gif

571 KB | W: | H:

images/demo_TPbatchLQR01.gif

228 KB | W: | H:

images/demo_TPbatchLQR01.gif
images/demo_TPbatchLQR01.gif
images/demo_TPbatchLQR01.gif
images/demo_TPbatchLQR01.gif
  • 2-up
  • Swipe
  • Onion skin
......@@ -105,8 +105,15 @@ namespace gfx2
// Converts some coordinates from UI-space to OpenGL-space
//
// UI coordinates range from (0, 0) to (win_width, win_height)
// OpenGL coordinates range from (-fb_width / 2, fb_height / 2) to
// (fb_width / 2, -fb_height / 2)
// OpenGL coordinates range from (0, fb_height) to (fb_width, 0)
//-------------------------------------------------------------------------
arma::vec ui2fb(const arma::vec& coords, const window_size_t& window_size);
//-------------------------------------------------------------------------
// Converts some coordinates from UI-space to OpenGL-space
//
// UI coordinates range from (0, 0) to (win_width, win_height)
// OpenGL coordinates range from (0, fb_height) to (fb_width, 0)
//-------------------------------------------------------------------------
arma::vec ui2fb(const arma::vec& coords, int win_width, int win_height,
int fb_width, int fb_height);
......@@ -118,7 +125,17 @@ namespace gfx2
// OpenGL coordinates range from (-fb_width / 2, fb_height / 2) to
// (fb_width / 2, -fb_height / 2)
//-------------------------------------------------------------------------
arma::vec ui2fb(const arma::vec& coords, const window_size_t& window_size);
arma::vec ui2fb_centered(const arma::vec& coords, const window_size_t& window_size);
//-------------------------------------------------------------------------
// Converts some coordinates from UI-space to OpenGL-space
//
// UI coordinates range from (0, 0) to (win_width, win_height)
// OpenGL coordinates range from (-fb_width / 2, fb_height / 2) to
// (fb_width / 2, -fb_height / 2)
//-------------------------------------------------------------------------
arma::vec ui2fb_centered(const arma::vec& coords, int win_width, int win_height,
int fb_width, int fb_height);
//-------------------------------------------------------------------------
// Converts some coordinates from OpenGL-space to UI-space
......@@ -133,11 +150,28 @@ namespace gfx2
//-------------------------------------------------------------------------
// Converts some coordinates from OpenGL-space to UI-space
//
// OpenGL coordinates range from (0, fb_height) to (fb_width, 0)
// UI coordinates range from (0, 0) to (win_width, win_height)
//-------------------------------------------------------------------------
arma::vec fb2ui(const arma::vec& coords, const window_size_t& window_size);
//-------------------------------------------------------------------------
// Converts some coordinates from OpenGL-space to UI-space
//
// OpenGL coordinates range from (0, fb_height) to (fb_width, 0)
// UI coordinates range from (0, 0) to (win_width, win_height)
//-------------------------------------------------------------------------
arma::vec fb2ui_centered(const arma::vec& coords, int win_width, int win_height,
int fb_width, int fb_height);
//-------------------------------------------------------------------------
// Converts some coordinates from OpenGL-space to UI-space
//
// OpenGL coordinates range from (-fb_width / 2, fb_height / 2) to
// (fb_width / 2, -fb_height / 2)
// UI coordinates range from (0, 0) to (win_width, win_height)
//-------------------------------------------------------------------------
arma::vec fb2ui(const arma::vec& coords, const window_size_t& window_size);
arma::vec fb2ui_centered(const arma::vec& coords, const window_size_t& window_size);
/*********************** PROJECTION & VIEW MATRICES **********************/
......@@ -240,6 +274,35 @@ namespace gfx2
typedef std::vector<point_light_t> light_list_t;
/******************************** TEXTURES *******************************/
//-------------------------------------------------------------------------
// Holds all the needed informations about a texture
//-------------------------------------------------------------------------
struct texture_t {
GLuint id;
GLuint width;
GLuint height;
GLenum format;
GLenum type;
union {
float* pixels_f;
unsigned char* pixels_b;
};
};
//-------------------------------------------------------------------------
// Create a texture
//-------------------------------------------------------------------------
texture_t create_texture(int width, int height, GLenum format, GLenum type);
//-------------------------------------------------------------------------
// Create a texture
//-------------------------------------------------------------------------
void destroy(texture_t &texture);
/********************************* MESHES ********************************/
//-------------------------------------------------------------------------
......@@ -262,6 +325,7 @@ namespace gfx2
arma::fvec diffuse_color;
arma::fvec specular_color;
float specular_power;
texture_t texture;
// Other
bool lightning_enabled;
......@@ -269,6 +333,11 @@ namespace gfx2
};
//-------------------------------------------------------------------------
// Represent a list of models
//-------------------------------------------------------------------------
typedef std::vector<gfx2::model_t> model_list_t;
//-------------------------------------------------------------------------
// Create a rectangular mesh, colored (no lightning)
//-------------------------------------------------------------------------
model_t create_rectangle(const arma::fvec& color, float width, float height,
......@@ -277,6 +346,14 @@ namespace gfx2
transforms_t* parent_transforms = 0);
//-------------------------------------------------------------------------
// Create a rectangular mesh, textured (no lightning)
//-------------------------------------------------------------------------
model_t create_rectangle(const texture_t& texture, float width, float height,
const arma::fvec& position = arma::zeros<arma::fvec>(3),
const arma::fmat& rotation = arma::eye<arma::fmat>(4, 4),
transforms_t* parent_transforms = 0);
//-------------------------------------------------------------------------
// Create a square mesh, colored (no lightning)
//-------------------------------------------------------------------------
model_t create_square(const arma::fvec& color, float size,
......@@ -342,7 +419,7 @@ namespace gfx2
//-------------------------------------------------------------------------
// Release the OpenGL resources used by the model
//-------------------------------------------------------------------------
void destroy(const model_t& model);
void destroy(model_t &model);
/******************************* RENDERING *******************************/
......@@ -369,6 +446,13 @@ namespace gfx2
const arma::fmat& rotation = arma::eye<arma::fmat>(4, 4));
//-------------------------------------------------------------------------
// Render a rectangular mesh, textured (no lightning)
//-------------------------------------------------------------------------
bool draw_rectangle(const texture_t& texture, float width, float height,
const arma::fvec& position = arma::zeros<arma::fvec>(3),
const arma::fmat& rotation = arma::eye<arma::fmat>(4, 4));
//-------------------------------------------------------------------------
// Render a line, colored (no lightning), from a matrix containing the
// point coordinates
//-------------------------------------------------------------------------
......
This diff is collapsed.
// ImGui GLFW binding with OpenGL3 + shaders
// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.)
// Implemented features:
// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Gamepad navigation mapping. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
// https://github.com/ocornut/imgui
struct GLFWwindow;
IMGUI_API bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks, const char* glsl_version = NULL);
IMGUI_API void ImGui_ImplGlfwGL3_Shutdown();
IMGUI_API void ImGui_ImplGlfwGL3_NewFrame();
IMGUI_API void ImGui_ImplGlfwGL3_RenderDrawData(ImDrawData* draw_data);
// Use if you want to reset your rendering device without losing ImGui state.
IMGUI_API void ImGui_ImplGlfwGL3_InvalidateDeviceObjects();
IMGUI_API bool ImGui_ImplGlfwGL3_CreateDeviceObjects();
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
// Provided here if you want to chain callbacks.
// You can also handle inputs yourself and use those as a reference.
IMGUI_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
IMGUI_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
IMGUI_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
IMGUI_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
......@@ -67,8 +67,18 @@ struct model_t {
};
//-----------------------------------------------
//-----------------------------------------------------------------------------
// Likelihood of datapoint(s) to be generated by a Gaussian parameterized by
// center and covariance.
//
// Inputs:
// - Data: D x N array representing N datapoints of D dimensions.
// - Mu: D x 1 vector representing the center of the Gaussian.
// - Sigma: D x D array representing the covariance matrix of the Gaussian.
//
// Output:
// - prob: 1 x N vector representing the likelihood of the N datapoints.
//-----------------------------------------------------------------------------
arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
int nbVar = Data.n_rows;
......@@ -77,7 +87,7 @@ arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
vec prob = sum((Data * inv(Sigma)) % Data, 1);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + 2.2251E-308);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + DBL_MIN);
return prob;
}
......@@ -330,16 +340,13 @@ arma::vec fb2ui(const arma::vec& coords, const gfx2::window_size_t& window_size,
// Colors of the displayed lines and gaussians
//-----------------------------------------------------------------------------
const mat COLORS({
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.5, 0.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, 0.75, 0.75 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.5, 0.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, 0.75, 0.75 },
{ 0.75, 0.0, 0.75 },
{ 0.75, 0.75, 0.0 },
{ 0.25, 0.25, 0.25 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.5, 0.0 },
{ 1.0, 0.0, 0.0 },
});
......@@ -454,7 +461,7 @@ void draw_demos_viewport(const viewport_t& viewport,
gfx2::draw_line(color, datapoints);
++color_index;
if (color_index >= demonstrations.size())
if (color_index >= COLORS.n_rows)
color_index = 0;
}
}
......@@ -488,7 +495,9 @@ void draw_GMR_viewport(const viewport_t& viewport, const mat& points,
glClear(GL_DEPTH_BUFFER_BIT);
gfx2::draw_line(arma::fvec({0.0f, 0.0f, 0.0f}), points);
glLineWidth(4.0f);
gfx2::draw_line(arma::fvec({0.0f, 0.4f, 0.0f}), points);
glLineWidth(1.0f);
}
}
......@@ -616,7 +625,8 @@ void draw_timeline_viewport(const gfx2::window_size_t& window_size,
sigma(0, 1) = sigma(0, 1) * scale_x;
sigma(1, 0) = sigma(1, 0) * scale_x;
gfx2::draw_gaussian(conv_to<fvec>::from(COLORS.row(i % 10).t()), mu, sigma);
gfx2::draw_gaussian(conv_to<fvec>::from(COLORS.row(i % 10).t()), mu, sigma,
true, false);
}
glClear(GL_DEPTH_BUFFER_BIT);
......@@ -634,7 +644,7 @@ void draw_timeline_viewport(const gfx2::window_size_t& window_size,
gfx2::draw_line(color, datapoints);
++color_index;
if (color_index >= demonstrations.size())
if (color_index >= COLORS.n_rows)
color_index = 0;
}
......@@ -646,7 +656,9 @@ void draw_timeline_viewport(const gfx2::window_size_t& window_size,
points(0, span::all) = points(0, span::all) * scale_x - plot_dimensions(0) / 2;
points(1, span::all) *= scale_y;
gfx2::draw_line(arma::fvec({0.0f, 0.0f, 0.0f}), points);
glLineWidth(4.0f);
gfx2::draw_line(arma::fvec({0.0f, 0.4f, 0.0f}), points);
glLineWidth(1.0f);
}
......@@ -970,7 +982,7 @@ int main(int argc, char **argv) {
break;
if (!gui_state.is_drawing_demonstration) {
if (!gui_state.is_drawing_demonstration && !gui_state.is_parameters_dialog_displayed) {
// Left click: start a new demonstration (only if not on the UI and in the
// demonstrations viewport)
if (ImGui::IsMouseClicked(GLFW_MOUSE_BUTTON_1)) {
......@@ -986,7 +998,7 @@ int main(int argc, char **argv) {
current_trajectory.push_back(coords);
}
}
} else {
} else if (gui_state.is_drawing_demonstration) {
double mouse_x, mouse_y;
glfwGetCursorPos(window, &mouse_x, &mouse_y);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -28,8 +28,8 @@ void trans2d_to_gauss(const ui::Trans2d& gaussian_transforms,
const gfx2::window_size_t& window_size,
arma::vec &mu, arma::mat &sigma) {
mu = gfx2::ui2fb(vec({ gaussian_transforms.pos.x, gaussian_transforms.pos.y }),
window_size);
mu = gfx2::ui2fb_centered(vec({ gaussian_transforms.pos.x, gaussian_transforms.pos.y }),
window_size);
vec t_x({
gaussian_transforms.x.x * window_size.scale_x(),
......
......@@ -9,6 +9,7 @@
#include <stdio.h>
#include <armadillo>
#include <cfloat>
using namespace arma;
......@@ -197,7 +198,7 @@ arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
vec prob = sum((Data * inv(Sigma)) % Data, 1);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + 2.2251E-308);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + DBL_MIN);
return prob;
}
......
......@@ -197,7 +197,7 @@ arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
vec prob = sum((Data * inv(Sigma)) % Data, 1);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma)); // + 2.2251E-308);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma)); // + DBL_MIN);
return prob;
}
......
......@@ -222,7 +222,7 @@ arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
vec prob = sum((Data * inv(Sigma)) % Data, 1);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + 2.2251E-308);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + DBL_MIN);
return prob;
}
......
......@@ -210,7 +210,7 @@ arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
vec prob = sum((Data * inv(Sigma)) % Data, 1);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + 2.2251E-308);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + DBL_MIN);
return prob;
}
......
......@@ -185,7 +185,7 @@ arma::vec gaussPDF(mat Data, colvec Mu, mat Sigma) {
vec prob = sum((Data * inv(Sigma)) % Data, 1);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + 2.2251E-308);
prob = exp(-0.5 * prob) / sqrt(pow((2 * datum::pi), nbVar) * det(Sigma) + DBL_MIN);
return prob;
}
......
......@@ -14,6 +14,10 @@
#include <math.h>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_internal.h>
#include <imgui_impl_glfw_gl2.h>
#include <gfx_ui.h>
#include <window_utils.h>
namespace linmath{
......@@ -35,6 +39,9 @@ using namespace arma;
#define DIST_BALL (RADIUS * 2.f + RADIUS * 0.1f)
#define VIEW_SCENE_DIST (DIST_BALL * 3.f + 200.f)
#define MARGIN 50
/* Vertex type */
typedef struct {float x; float y; float z;} vertex_t;
......@@ -219,36 +226,112 @@ arma::mat logmap(arma::mat x, arma::vec mu)
//-----------------------------------------------
void DrawTarget(int nbData)
void DrawResults(int nbData, int nbRepros, const arma::mat& x_y,
const window_size_t& window_size)
{
const int plot_width = (window_size.win_width - 3 * MARGIN) / 2;
const int plot_height = (window_size.win_height - 3 * MARGIN) / 2;
const float scale_x = (float) plot_width / (nbData - 1);
const float scale_y = (float) plot_height / 2;
// Draw the plot backgrounds
glColor3f(0.95f, 0.95f, 0.95f);
glBegin (GL_QUADS);
glVertex2f(MARGIN, window_size.win_height - MARGIN);
glVertex2f(MARGIN, window_size.win_height - (MARGIN + plot_height));
glVertex2f(MARGIN + plot_width, window_size.win_height - (MARGIN + plot_height));
glVertex2f(MARGIN + plot_width, window_size.win_height - MARGIN);
glEnd();
glBegin (GL_QUADS);
glVertex2f(window_size.win_width - (MARGIN + plot_width), window_size.win_height - MARGIN);
glVertex2f(window_size.win_width - (MARGIN + plot_width), window_size.win_height - (MARGIN + plot_height));
glVertex2f(window_size.win_width - (MARGIN + plot_width) + plot_width, window_size.win_height - (MARGIN + plot_height));
glVertex2f(window_size.win_width - (MARGIN + plot_width) + plot_width, window_size.win_height - MARGIN);
glEnd();
glBegin (GL_QUADS);
glVertex2f(MARGIN, MARGIN + plot_height);
glVertex2f(MARGIN, MARGIN);
glVertex2f(MARGIN + plot_width, MARGIN);
glVertex2f(MARGIN + plot_width, MARGIN + plot_height);
glEnd();
glBegin (GL_QUADS);
glVertex2f(window_size.win_width - (MARGIN + plot_width), MARGIN + plot_height);
glVertex2f(window_size.win_width - (MARGIN + plot_width), MARGIN);
glVertex2f(window_size.win_width - (MARGIN + plot_width) + plot_width, MARGIN);
glVertex2f(window_size.win_width - (MARGIN + plot_width) + plot_width, MARGIN + plot_height);
glEnd();
// Draw the axes
glColor3f(0.0f, 0.0f, 0.0f);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f(MARGIN, window_size.win_height - MARGIN);
glVertex2f(MARGIN, window_size.win_height - (MARGIN + plot_height));
glVertex2f(MARGIN, window_size.win_height - (MARGIN + plot_height / 2));
glVertex2f(MARGIN + plot_width, window_size.win_height - (MARGIN + plot_height / 2));
glEnd();
glBegin(GL_LINES);
glVertex2f(window_size.win_width - (MARGIN + plot_width), window_size.win_height - MARGIN);
glVertex2f(window_size.win_width - (MARGIN + plot_width), window_size.win_height - (MARGIN + plot_height));
glVertex2f(window_size.win_width - (MARGIN + plot_width), window_size.win_height - (MARGIN + plot_height / 2));