diff --git a/LivePlotter.cs b/LivePlotter.cs new file mode 100644 index 0000000..8fd1860 --- /dev/null +++ b/LivePlotter.cs @@ -0,0 +1,68 @@ +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using Common.Data; +using pointid = System.UInt64; + +namespace TysonPalletScanner +{ + public class LivePlotter + { + [DllImport("LivePlotter.dll")] + public static extern bool start(int win_w, int win_h); + + [DllImport("LivePlotter.dll")] + public static extern bool stop(); + + [DllImport("LivePlotter.dll")] + public static extern pointid create_point(float x, float y, float z); + + [DllImport("LivePlotter.dll")] + public static extern void set_color(pointid id, float r, float g, float b); + + [DllImport("LivePlotter.dll")] + public static extern void set_scale(pointid id, float scale); + + [DllImport("LivePlotter.dll")] + public static extern void update_point(pointid id, float x, float y, float z); + + [DllImport("LivePlotter.dll")] + public static extern void set_lifetime(pointid id, float new_lifetime_s); + + [DllImport("LivePlotter.dll")] + public static extern void clear_point(pointid id); + + public static void PlotCameraPoses() + { + string[] lines = File.ReadAllLines("poses.csv"); + for (int camera_i = 1; camera_i < lines.Length; camera_i++) + { + string[] words = lines[camera_i].Split(','); + float x = float.Parse(words[0]); + float y = float.Parse(words[1]); + float z = float.Parse(words[2]); + float w = float.Parse(words[3]); + float i = float.Parse(words[4]); + float j = float.Parse(words[5]); + float k = float.Parse(words[6]); + + Pose pose = new(new Quaternion(i, j, k, w), new Vector3(x, y, z)); + for (int m = 0; m < 3; m++) + { + for (int n = 0; n < 25; n++) + { + Vector3 local = new(0); + local[m] = n * 10.0f; + Vector3 global = pose * local; + pointid id = create_point(global.X, global.Y, global.Z); + + Vector3 color = new(0); + color[m] = 1.0f; + set_color(id, color.X, color.Y, color.Z); + set_scale(id, 15); + } + } + } + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7edf7ca --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Overview + +LivePlotter is an opengl-based, 3d point plotting DLL. It is designed to be integrated into any project that needs to see 3d points plotted and updated in real time. It supposts simple camera control: rotate, pan, and zoom. Points can be given a "lifetime" during which their opacity will fade. The opacity of these points can be restored by updating their position. This allows an intuite representation of sensor readings (where the opacity of the point represents the age of the reading). + +This DLL is designed to integrate easily into a C# application. A class that acomplishes this included. See [LivePlotter.cs](./LivePlotter.cs). + +![til](./demo.gif) + +*Please note that this project is still considered a work in progress. I will avoid making api-breaking changes. Functionality may be added and code refactoring may occur in the future since I plan to use this for several projects* + +# Acquiring the DLL + +There are two main ways to get the DLL... + +## Download from Releases (recommended) + +Download the DLL from the latest release on the [releases page](https://git.the-embedded-lab.com/shamilton/LivePlotter/releases). + +## Build from source (not recommended) + +Building is a tad messy atm. I despise Visual Studio and like to manage my own build process. I prefer something simple like a script to build and that's currently what I have. I hope to fix this mess in the future. + +1. You'll need git bash and an installation of MSVC (likely via downloading/installing Visual Studio and then installing the C++ build tools). +2. Find `vcvars64.bat` in your installation and modify the path in [run_before_build.bat](.run_before_build.bat) to point to it. +3. Open git bash to the root directory of the project. +4. Run `./run_before_build.bat` then `build.sh` +5. A folder bin/ should exist with `LivePlotter.dll` inside.