This commit is contained in:
Ivan
2022-04-05 11:42:28 +03:00
commit 6dc0eb0fcf
5565 changed files with 1200500 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <iostream>
#include <string>
#include <cmath>
namespace pangolin
{
/// Units for measuring screen distances.
enum Unit {
Fraction,
Pixel,
ReversePixel
};
/// Defines absolute or relative position from parent viewport edge.
/// Constructors distinguised by whole pixels, or floating
/// fraction in interval [0,1]
struct PANGOLIN_EXPORT Attach {
/// Attach to Left/Bottom edge
Attach() : unit(Fraction), p(0) {}
/// General constructor
Attach(Unit unit, GLfloat p) : unit(unit), p(p) {}
/// Specify relative position in range [0,1].
/// 0 represents leftmost / bottom-most edge,
/// 1 represents rightmost / topmost edge
Attach(GLfloat p) : unit(Fraction), p(p) {
// Allow for numerical imprecision when checking usage.
if( p < -1E-3 || 1.001 < p ) {
std::cerr << "Pangolin API Change: Display::SetBounds must be used with Attach::Pix or Attach::ReversePix to specify pixel bounds relative to an edge. See the code samples for details." << std::endl;
throw std::exception();
}
}
/// Specify absolute position from leftmost / bottom-most edge.
static Attach Pix(int p) {
return Attach(p >=0 ? Pixel : ReversePixel, std::abs((float)p));
}
/// Specify absolute position from rightmost / topmost edge.
static Attach ReversePix(int p) {
return Attach(ReversePixel, (GLfloat)p);
}
/// Specify relative position in range [0,1].
/// 0 represents leftmost / bottom-most edge,
/// 1 represents rightmost / topmost edge
static Attach Frac(float frac) {
return Attach(frac);
}
Unit unit;
GLfloat p;
};
} // namespace pangolin

View File

@@ -0,0 +1,68 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
#include <pangolin/display/display_internal.h>
#include <pangolin/display/device/PangolinNSApplication.h>
#include <pangolin/display/device/PangolinNSGLView.h>
namespace pangolin
{
struct OsxWindow : public PangolinGl
{
OsxWindow(const std::string& title, int width, int height, bool USE_RETINA);
~OsxWindow();
void StartFullScreen();
void StopFullScreen();
void ToggleFullscreen() override;
void Move(int x, int y) override;
void Resize(unsigned int w, unsigned int h) override;
void MakeCurrent() override;
void RemoveCurrent() override;
void SwapBuffers() override;
void ProcessEvents() override;
private:
NSWindow* _window;
PangolinNSGLView *view;
};
}

View File

@@ -0,0 +1,59 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
////////////////////////////////////////////////////////////////////
// PangolinNSApplication
////////////////////////////////////////////////////////////////////
@interface PangolinNSApplication : NSObject {
}
+ (void)run_pre;
+ (void)run_step;
@end
////////////////////////////////////////////////////////////////////
// PangolinWindowDelegate
////////////////////////////////////////////////////////////////////
@interface PangolinWindowDelegate : NSObject <NSWindowDelegate>
@end
////////////////////////////////////////////////////////////////////
// PangolinAppDelegate
////////////////////////////////////////////////////////////////////
@interface PangolinAppDelegate : NSObject <NSApplicationDelegate>
@end

View File

@@ -0,0 +1,45 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#include <pangolin/display/display_internal.h>
////////////////////////////////////////////////////////////////////
// PangolinNSGLView
////////////////////////////////////////////////////////////////////
@interface PangolinNSGLView : NSOpenGLView
{
pangolin::PangolinGl* context;
float backing_scale;
}
@end

View File

@@ -0,0 +1,89 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
#include <pangolin/display/display_internal.h>
#include <string>
#include <windowsx.h>
namespace pangolin
{
struct WinWindow : public PangolinGl
{
WinWindow(
const std::string& title, int width, int height
);
~WinWindow();
void StartFullScreen();
void StopFullScreen();
void ToggleFullscreen() override;
void Move(int x, int y) override;
void Resize(unsigned int w, unsigned int h) override;
void MakeCurrent() override;
void RemoveCurrent() override;
void SwapBuffers() override;
void ProcessEvents() override;
HGLRC GetGLRenderContext()
{
return hGLRC;
}
private:
static LRESULT APIENTRY WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT HandleWinMessages(UINT message, WPARAM wParam, LPARAM lParam);
void RegisterThisClass(HMODULE hCurrentInst);
void SetupPixelFormat(HDC hdc);
void SetupPalette(HDC hDC);
// Owns the Window
HWND hWnd;
HDC hDC;
HGLRC hGLRC;
HPALETTE hPalette;
};
}

View File

@@ -0,0 +1,109 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
#include <pangolin/display/display_internal.h>
#include <stdexcept>
#include <string>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/glx.h>
namespace pangolin
{
struct X11Display
{
X11Display(const char* name = 0) {
XInitThreads();
display = XOpenDisplay(name);
if (!display) {
throw std::runtime_error("Pangolin X11: Failed to open X display");
}
}
~X11Display() {
XCloseDisplay(display);
}
// Owns the display
::Display* display;
};
struct X11GlContext : public GlContextInterface
{
X11GlContext(std::shared_ptr<X11Display> &d, ::GLXFBConfig chosenFbc, std::shared_ptr<X11GlContext> shared_context = std::shared_ptr<X11GlContext>() );
~X11GlContext();
std::shared_ptr<X11Display> display;
std::shared_ptr<X11GlContext> shared_context;
// Owns the OpenGl Context
::GLXContext glcontext;
};
struct X11Window : public PangolinGl
{
X11Window(
const std::string& title, int width, int height,
std::shared_ptr<X11Display>& display, ::GLXFBConfig chosenFbc
);
~X11Window();
void ToggleFullscreen() override;
void Move(int x, int y) override;
void Resize(unsigned int w, unsigned int h) override;
void MakeCurrent(GLXContext ctx);
void MakeCurrent() override;
void RemoveCurrent() override;
void SwapBuffers() override;
void ProcessEvents() override;
// References the X11 display and context.
std::shared_ptr<X11Display> display;
std::shared_ptr<X11GlContext> glcontext;
// Owns the X11 Window and Colourmap
::Window win;
::Colormap cmap;
Atom delete_message;
};
}

View File

@@ -0,0 +1,333 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <poll.h>
#include <pthread.h>
#include <sched.h>
#include <android/configuration.h>
#include <android/looper.h>
#include <android/native_activity.h>
#include <android/log.h>
#include <string>
#include <pangolin/utils/type_convert.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "pango", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "pango", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "pango", __VA_ARGS__))
/* For debug builds, always enable the debug traces in this library */
#undef NDEBUG
#ifndef NDEBUG
# define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "pango", __VA_ARGS__))
#else
# define LOGV(...) ((void)0)
#endif
template<typename T> inline
void Log(T v) {
const std::string sv = pangolin::Convert<std::string,T>::Do(v);
LOGI(sv.c_str());
}
template<typename T> inline
void Log(const std::string& str, T v)
{
const std::string sv = pangolin::Convert<std::string,T>::Do(v);
LOGI((str + ":" + sv).c_str());
}
namespace pangolin
{
void CreateAndroidWindowAndBind(std::string name);
void ProcessAndroidEvents();
void FinishAndroidFrame();
}
#ifdef __cplusplus
extern "C" {
#endif
struct android_app;
/**
* Data associated with an ALooper fd that will be returned as the "outData"
* when that source has data ready.
*/
struct android_poll_source {
// The identifier of this source. May be LOOPER_ID_MAIN or
// LOOPER_ID_INPUT.
int32_t id;
// The android_app this ident is associated with.
struct android_app* app;
// Function to call to perform the standard processing of data from
// this source.
void (*process)(struct android_app* app, struct android_poll_source* source);
};
/**
* This is the interface for the standard glue code of a threaded
* application. In this model, the application's code is running
* in its own thread separate from the main thread of the process.
* It is not required that this thread be associated with the Java
* VM, although it will need to be in order to make JNI calls any
* Java objects.
*/
struct android_app {
// The application can place a pointer to its own state object
// here if it likes.
void* userData;
// Fill this in with the function to process main app commands (APP_CMD_*)
void (*onAppCmd)(struct android_app* app, int32_t cmd);
// Fill this in with the function to process input events. At this point
// the event has already been pre-dispatched, and it will be finished upon
// return. Return 1 if you have handled the event, 0 for any default
// dispatching.
int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
// The ANativeActivity object instance that this app is running in.
ANativeActivity* activity;
// The current configuration the app is running in.
AConfiguration* config;
// This is the last instance's saved state, as provided at creation time.
// It is NULL if there was no state. You can use this as you need; the
// memory will remain around until you call android_app_exec_cmd() for
// APP_CMD_RESUME, at which point it will be freed and savedState set to NULL.
// These variables should only be changed when processing a APP_CMD_SAVE_STATE,
// at which point they will be initialized to NULL and you can malloc your
// state and place the information here. In that case the memory will be
// freed for you later.
void* savedState;
size_t savedStateSize;
// The ALooper associated with the app's thread.
ALooper* looper;
// When non-NULL, this is the input queue from which the app will
// receive user input events.
AInputQueue* inputQueue;
// When non-NULL, this is the window surface that the app can draw in.
ANativeWindow* window;
// Current content rectangle of the window; this is the area where the
// window's content should be placed to be seen by the user.
ARect contentRect;
// Current state of the app's activity. May be either APP_CMD_START,
// APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below.
int activityState;
// This is non-zero when the application's NativeActivity is being
// destroyed and waiting for the app thread to complete.
int destroyRequested;
// -------------------------------------------------
// Below are "private" implementation of the glue code.
pthread_mutex_t mutex;
pthread_cond_t cond;
int msgread;
int msgwrite;
pthread_t thread;
struct android_poll_source cmdPollSource;
struct android_poll_source inputPollSource;
int running;
int stateSaved;
int destroyed;
int redrawNeeded;
AInputQueue* pendingInputQueue;
ANativeWindow* pendingWindow;
ARect pendingContentRect;
const char* application_so;
};
enum {
/**
* Looper data ID of commands coming from the app's main thread, which
* is returned as an identifier from ALooper_pollOnce(). The data for this
* identifier is a pointer to an android_poll_source structure.
* These can be retrieved and processed with android_app_read_cmd()
* and android_app_exec_cmd().
*/
LOOPER_ID_MAIN = 1,
/**
* Looper data ID of events coming from the AInputQueue of the
* application's window, which is returned as an identifier from
* ALooper_pollOnce(). The data for this identifier is a pointer to an
* android_poll_source structure. These can be read via the inputQueue
* object of android_app.
*/
LOOPER_ID_INPUT = 2,
/**
* Start of user-defined ALooper identifiers.
*/
LOOPER_ID_USER = 3,
};
enum {
/**
* Command from main thread: the AInputQueue has changed. Upon processing
* this command, android_app->inputQueue will be updated to the new queue
* (or NULL).
*/
APP_CMD_INPUT_CHANGED,
/**
* Command from main thread: a new ANativeWindow is ready for use. Upon
* receiving this command, android_app->window will contain the new window
* surface.
*/
APP_CMD_INIT_WINDOW,
/**
* Command from main thread: the existing ANativeWindow needs to be
* terminated. Upon receiving this command, android_app->window still
* contains the existing window; after calling android_app_exec_cmd
* it will be set to NULL.
*/
APP_CMD_TERM_WINDOW,
/**
* Command from main thread: the current ANativeWindow has been resized.
* Please redraw with its new size.
*/
APP_CMD_WINDOW_RESIZED,
/**
* Command from main thread: the system needs that the current ANativeWindow
* be redrawn. You should redraw the window before handing this to
* android_app_exec_cmd() in order to avoid transient drawing glitches.
*/
APP_CMD_WINDOW_REDRAW_NEEDED,
/**
* Command from main thread: the content area of the window has changed,
* such as from the soft input window being shown or hidden. You can
* find the new content rect in android_app::contentRect.
*/
APP_CMD_CONTENT_RECT_CHANGED,
/**
* Command from main thread: the app's activity window has gained
* input focus.
*/
APP_CMD_GAINED_FOCUS,
/**
* Command from main thread: the app's activity window has lost
* input focus.
*/
APP_CMD_LOST_FOCUS,
/**
* Command from main thread: the current device configuration has changed.
*/
APP_CMD_CONFIG_CHANGED,
/**
* Command from main thread: the system is running low on memory.
* Try to reduce your memory use.
*/
APP_CMD_LOW_MEMORY,
/**
* Command from main thread: the app's activity has been started.
*/
APP_CMD_START,
/**
* Command from main thread: the app's activity has been resumed.
*/
APP_CMD_RESUME,
/**
* Command from main thread: the app should generate a new saved state
* for itself, to restore from later if needed. If you have saved state,
* allocate it with malloc and place it in android_app.savedState with
* the size in android_app.savedStateSize. The will be freed for you
* later.
*/
APP_CMD_SAVE_STATE,
/**
* Command from main thread: the app's activity has been paused.
*/
APP_CMD_PAUSE,
/**
* Command from main thread: the app's activity has been stopped.
*/
APP_CMD_STOP,
/**
* Command from main thread: the app's activity is being destroyed,
* and waiting for the app thread to clean up and exit before proceeding.
*/
APP_CMD_DESTROY,
};
/**
* Call when ALooper_pollAll() returns LOOPER_ID_MAIN, reading the next
* app command message.
*/
int8_t android_app_read_cmd(struct android_app* android_app);
/**
* Call with the command returned by android_app_read_cmd() to do the
* initial pre-processing of the given command. You can perform your own
* actions for the command after calling this function.
*/
void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd);
/**
* Call with the command returned by android_app_read_cmd() to do the
* final post-processing of the given command. You must have done your own
* actions for the command before calling this function.
*/
void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,219 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove, Richard Newcombe
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
#include <pangolin/gl/glinclude.h>
#include <pangolin/handler/handler_enums.h>
#include <pangolin/utils/params.h>
#include <pangolin/display/window.h>
#include <functional>
#include <string>
#include <memory>
/*! \file display.h
* This file contains a number of global methods for creating and
* querying window state as well as handling user input.
*/
namespace pangolin
{
// CreateWindowAndBind parameter key names.
// X11 Window options:
extern const char* PARAM_DISPLAYNAME; // std::string
extern const char* PARAM_DOUBLEBUFFER; // bool
extern const char* PARAM_SAMPLE_BUFFERS; // int
extern const char* PARAM_SAMPLES; // int
extern const char* PARAM_HIGHRES; // bool - Apple Retina screens only
// Forward Declarations
struct View;
struct Viewport;
class UserApp;
/// Give this OpenGL context a name or switch contexts.
/// This is required to initialise Pangolin for use with an
/// externally defined OpenGL context. You needn't call it
/// if you have used CreateWindowAndBind() to create a window
/// or launched a pangolin::UserApp
PANGOLIN_EXPORT
WindowInterface& BindToContext(std::string name);
/// Initialise OpenGL window (determined by platform) and bind context.
/// This method will choose an available windowing system if one is present.
PANGOLIN_EXPORT
WindowInterface& CreateWindowAndBind(std::string window_title, int w = 640, int h = 480, const Params& params = Params());
/// Return pointer to current Pangolin Window context, or nullptr if none bound.
PANGOLIN_EXPORT
WindowInterface* GetBoundWindow();
PANGOLIN_EXPORT
void DestroyWindow(const std::string& window_title);
/// Launch users derived UserApp, controlling OpenGL event loop.
/// This method will block until the application exits, calling app's
/// Init() method to start and Render() method subsequently to draw each frame.
/// @return exit code for use when returning from main. Currently always 0.
PANGOLIN_EXPORT
int LaunchUserApp(UserApp& app);
/// Perform any post rendering, event processing and frame swapping.
PANGOLIN_EXPORT
void FinishFrame();
/// Request that the window close.
PANGOLIN_EXPORT
void Quit();
/// Request that all windows close.
PANGOLIN_EXPORT
void QuitAll();
/// Returns true if user has requested to close OpenGL window.
PANGOLIN_EXPORT
bool ShouldQuit();
/// Returns true if user has interacted with the window since this was last called.
PANGOLIN_EXPORT
bool HadInput();
/// Returns true if user has resized the window.
PANGOLIN_EXPORT
bool HasResized();
/// Renders any views with default draw methods.
PANGOLIN_EXPORT
void RenderViews();
/// Perform any post render events, such as screen recording.
PANGOLIN_EXPORT
void PostRender();
/// Request to be notified via functor when key is pressed.
/// Functor may take one parameter which will equal the key pressed
PANGOLIN_EXPORT
void RegisterKeyPressCallback(int key, std::function<void(void)> func);
/// Save window contents to image.
PANGOLIN_EXPORT
void SaveWindowOnRender(std::string filename_prefix);
PANGOLIN_EXPORT
void SaveFramebuffer(std::string prefix, const Viewport& v);
namespace process
{
/// Tell pangolin to process input to drive display.
/// You will need to call this manually if you haven't let
/// Pangolin register callbacks from your windowing system
PANGOLIN_EXPORT
void Keyboard( unsigned char key, int x, int y);
PANGOLIN_EXPORT
void KeyboardUp(unsigned char key, int x, int y);
PANGOLIN_EXPORT
void SpecialFunc(int key, int x, int y);
PANGOLIN_EXPORT
void SpecialFuncUp(int key, int x, int y);
/// Tell pangolin base window size has changed
/// You will need to call this manually if you haven't let
/// Pangolin register callbacks from your windowing system
PANGOLIN_EXPORT
void Resize(int width, int height);
/// Event based rendering entry point. Not currently supported.
PANGOLIN_EXPORT
void Display();
PANGOLIN_EXPORT
void Mouse( int button, int state, int x, int y);
PANGOLIN_EXPORT
void MouseMotion( int x, int y);
PANGOLIN_EXPORT
void PassiveMouseMotion(int x, int y);
PANGOLIN_EXPORT
void Scroll(float x, float y);
PANGOLIN_EXPORT
void Zoom(float m);
PANGOLIN_EXPORT
void Rotate(float r);
PANGOLIN_EXPORT
void SubpixMotion(float x, float y, float pressure, float rotation, float tiltx, float tilty);
PANGOLIN_EXPORT
void SpecialInput(InputSpecial inType, float x, float y, float p1, float p2, float p3, float p4);
}
/// Retrieve 'base' display, corresponding to entire window.
PANGOLIN_EXPORT
View& DisplayBase();
/// Create or retrieve named display managed by pangolin (automatically deleted).
PANGOLIN_EXPORT
View& Display(const std::string& name);
/// Create unnamed display managed by pangolin (automatically deleted).
PANGOLIN_EXPORT
View& CreateDisplay();
/// Switch between windowed and fullscreen mode.
PANGOLIN_EXPORT
void ToggleFullscreen();
/// Switch windows/fullscreenmode = fullscreen.
PANGOLIN_EXPORT
void SetFullscreen(bool fullscreen = true);
/// Toggle display of Pangolin console
PANGOLIN_EXPORT
void ToggleConsole();
/// Convenience functor for toggling pangolin::View.
/// Use with RegisterKeyPressCallback for example
struct ToggleViewFunctor {
inline ToggleViewFunctor(View& view);
inline ToggleViewFunctor(const std::string& name);
void operator()();
View& view;
};
}

View File

@@ -0,0 +1,138 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
#include <pangolin/display/window.h>
#include <pangolin/display/view.h>
#include <pangolin/display/user_app.h>
#include <functional>
#include <memory>
#include <map>
#include <queue>
#ifdef BUILD_PANGOLIN_VIDEO
# include <pangolin/video/video_output.h>
#endif // BUILD_PANGOLIN_VIDEO
namespace pangolin
{
// Forward Declarations
#ifdef HAVE_PYTHON
class ConsoleView;
#endif // HAVE_PYTHON
class GlFont;
typedef std::map<const std::string,View*> ViewMap;
typedef std::map<int,std::function<void(void)> > KeyhookMap;
struct PANGOLIN_EXPORT PangolinGl : public WindowInterface
{
PangolinGl();
~PangolinGl();
// Base container for displays
View base;
// Named views which are managed by pangolin (i.e. created / deleted by pangolin)
ViewMap named_managed_views;
// Optional user app
UserApp* user_app;
// Global keypress hooks
KeyhookMap keypress_hooks;
// Manage fullscreen (ToggleFullscreen is quite new)
bool is_double_buffered;
bool is_fullscreen;
GLint windowed_size[2];
bool is_high_res;
// State relating to interactivity
bool quit;
int had_input;
int has_resized;
int mouse_state;
View* activeDisplay;
std::queue<std::pair<std::string,Viewport> > screen_capture;
#ifdef BUILD_PANGOLIN_VIDEO
View* record_view;
VideoOutput recorder;
#endif
#ifdef HAVE_PYTHON
ConsoleView* console_view;
#endif
std::shared_ptr<GlFont> font;
virtual void ToggleFullscreen() override {
pango_print_warn("ToggleFullscreen: Not available with non-pangolin window.\n");
}
virtual void ProcessEvents() override {
pango_print_warn("ProcessEvents: Not available with non-pangolin window.\n");
}
virtual void SwapBuffers() override {
pango_print_warn("SwapBuffers: Not available with non-pangolin window.\n");
}
virtual void MakeCurrent() override {
pango_print_warn("MakeCurrent: Not available with non-pangolin window.\n");
}
virtual void RemoveCurrent() override {
pango_print_warn("RemoveCurrent: Not available with non-pangolin window.\n");
}
virtual void Move(int /*x*/, int /*y*/) override {
pango_print_warn("Move: Not available with non-pangolin window.\n");
}
virtual void Resize(unsigned int /*w*/, unsigned int /*h*/) override {
pango_print_warn("Resize: Not available with non-pangolin window.\n");
}
};
PangolinGl* GetCurrentContext();
void RegisterNewContext(const std::string& name, std::shared_ptr<PangolinGl> newcontext);
void DeleteContext(const std::string& name);
PangolinGl *FindContext(const std::string& name);
}

View File

@@ -0,0 +1,74 @@
#pragma once
#include <pangolin/display/display.h>
#include <pangolin/gl/glpixformat.h>
#include <pangolin/gl/glformattraits.h>
#include <pangolin/gl/glsl.h>
#include <pangolin/handler/handler_image.h>
#include <pangolin/image/image_utils.h>
#include <mutex>
namespace pangolin
{
class ImageView : public pangolin::View, public pangolin::ImageViewHandler
{
public:
ImageView();
~ImageView();
void Render() override;
void Mouse(View& view, pangolin::MouseButton button, int x, int y, bool pressed, int button_state) override;
void Keyboard(View& view, unsigned char key, int x, int y, bool pressed) override;
pangolin::GlTexture& Tex();
ImageView& SetImage(void* ptr, size_t w, size_t h, size_t pitch, pangolin::GlPixFormat img_fmt, bool delayed_upload = false);
ImageView& SetImage(const pangolin::Image<unsigned char>& img, const pangolin::GlPixFormat& glfmt, bool delayed_upload = false);
template<typename T> inline
ImageView& SetImage(const pangolin::Image<T>& img, bool delayed_upload = false)
{
return SetImage(img.template UnsafeReinterpret<unsigned char>(), GlPixFormat::FromType<T>(), delayed_upload);
}
ImageView& SetImage(const pangolin::TypedImage& img, bool delayed_upload = false);
ImageView& SetImage(const pangolin::GlTexture& texture);
void LoadPending();
ImageView& Clear();
std::pair<float, float>& GetOffsetScale();
bool MouseReleased() const;
bool MousePressed() const;
void SetRenderOverlay(const bool& val);
// private:
// img_to_load contains image data that should be uploaded to the texture on
// the next render cycle. The data is owned by this object and should be
// freed after use.
pangolin::ManagedImage<unsigned char> img_to_load;
pangolin::GlPixFormat img_fmt_to_load;
std::pair<float, float> offset_scale;
pangolin::GlPixFormat fmt;
pangolin::GlTexture tex;
bool lastPressed;
bool mouseReleased;
bool mousePressed;
bool overlayRender;
std::mutex texlock;
};
}

View File

@@ -0,0 +1,446 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
#include <pangolin/utils/simple_math.h>
#include <vector>
#if defined(HAVE_EIGEN) && !defined(__CUDACC__) //prevent including Eigen in cuda files
#define USE_EIGEN
#endif
#ifdef USE_EIGEN
#include <Eigen/Core>
#include <Eigen/Geometry>
#endif
#ifdef HAVE_TOON
#include <cstring>
#include <TooN/TooN.h>
#include <TooN/se3.h>
#endif
#ifdef HAVE_OCULUS
#include <pangolin/compat/ovr.h>
#endif
namespace pangolin {
#ifdef HAVE_GLES
typedef float GLprecision;
#else
typedef double GLprecision;
#endif
/// Capture OpenGL matrix types in enum to typing.
enum OpenGlStack {
GlModelViewStack = 0x1700, // GL_MODELVIEW
GlProjectionStack = 0x1701, // GL_PROJECTION
GlTextureStack = 0x1702 // GL_TEXTURE
};
enum AxisDirection
{
AxisNone,
AxisNegX, AxisX,
AxisNegY, AxisY,
AxisNegZ, AxisZ
};
struct CameraSpec {
GLprecision forward[3];
GLprecision up[3];
GLprecision right[3];
GLprecision img_up[2];
GLprecision img_right[2];
};
const static CameraSpec CameraSpecOpenGl = {{0,0,-1},{0,1,0},{1,0,0},{0,1},{1,0}};
const static CameraSpec CameraSpecYDownZForward = {{0,0,1},{0,-1,0},{1,0,0},{0,-1},{1,0}};
/// Direction vector for each AxisDirection enum
const static GLprecision AxisDirectionVector[7][3] = {
{0,0,0},
{-1,0,0}, {1,0,0},
{0,-1,0}, {0,1,0},
{0,0,-1}, {0,0,1}
};
/// Object representing OpenGl Matrix.
struct PANGOLIN_EXPORT OpenGlMatrix {
static OpenGlMatrix Translate(GLprecision x, GLprecision y, GLprecision z);
static OpenGlMatrix Scale(GLprecision x, GLprecision y, GLprecision z);
static OpenGlMatrix RotateX(GLprecision theta_rad);
static OpenGlMatrix RotateY(GLprecision theta_rad);
static OpenGlMatrix RotateZ(GLprecision theta_rad);
template<typename P>
static OpenGlMatrix ColMajor4x4(const P* col_major_4x4);
OpenGlMatrix();
#ifdef USE_EIGEN
template<typename P>
OpenGlMatrix(const Eigen::Matrix<P,4,4>& mat);
template<typename P>
OpenGlMatrix(const Eigen::Transform<P,3,Eigen::Affine>& mat) : OpenGlMatrix(mat.matrix()) { }
template<typename P>
operator Eigen::Matrix<P,4,4>() const;
template<typename P>
operator Eigen::Transform<P,3,Eigen::Affine>() const;
#endif // USE_EIGEN
#ifdef HAVE_TOON
OpenGlMatrix(const TooN::SE3<>& T);
OpenGlMatrix(const TooN::Matrix<4,4>& M);
operator const TooN::SE3<>() const;
operator const TooN::Matrix<4,4>() const;
#endif // HAVE_TOON
#ifdef HAVE_OCULUS
OpenGlMatrix(const OVR::Matrix4f& M);
operator const OVR::Matrix4f() const;
#endif // HAVE_OCULUS
// Load matrix on to OpenGl stack
void Load() const;
void Multiply() const;
void SetIdentity();
OpenGlMatrix Transpose() const;
OpenGlMatrix Inverse() const;
GLprecision& operator()(int r, int c) {
return m[4*c +r];
}
GLprecision operator()(int r, int c) const {
return m[4 * c + r];
}
// Column major Internal buffer
GLprecision m[16];
};
PANGOLIN_EXPORT
OpenGlMatrix operator*(const OpenGlMatrix& lhs, const OpenGlMatrix& rhs);
PANGOLIN_EXPORT
std::ostream& operator<<(std::ostream& os, const OpenGlMatrix& mat);
/// Deprecated.
struct PANGOLIN_EXPORT OpenGlMatrixSpec : public OpenGlMatrix {
// Specify which stack this refers to
OpenGlStack type;
};
/// Object representing attached OpenGl Matrices / transforms.
class PANGOLIN_EXPORT OpenGlRenderState
{
public:
OpenGlRenderState();
OpenGlRenderState(const OpenGlMatrix& projection_matrix);
OpenGlRenderState(const OpenGlMatrix& projection_matrix, const OpenGlMatrix& modelview_matrix);
static void ApplyIdentity();
void Apply() const;
OpenGlRenderState& SetProjectionMatrix(OpenGlMatrix m);
OpenGlRenderState& SetModelViewMatrix(OpenGlMatrix m);
OpenGlMatrix& GetProjectionMatrix();
OpenGlMatrix GetProjectionMatrix() const;
OpenGlMatrix& GetModelViewMatrix();
OpenGlMatrix GetModelViewMatrix() const;
OpenGlMatrix GetProjectionModelViewMatrix() const;
OpenGlMatrix GetProjectiveTextureMatrix() const;
void EnableProjectiveTexturing() const;
void DisableProjectiveTexturing() const;
//! Seemlessly move OpenGl camera relative to changes in T_wc,
//! whilst still enabling interaction
void Follow(const OpenGlMatrix& T_wc, bool follow = true);
void Unfollow();
// Experimental - subject to change
OpenGlMatrix& GetProjectionMatrix(unsigned int view);
OpenGlMatrix GetProjectionMatrix(unsigned int view) const;
OpenGlMatrix& GetViewOffset(unsigned int view);
OpenGlMatrix GetViewOffset(unsigned int view) const;
OpenGlMatrix GetModelViewMatrix(int i) const;
void ApplyNView(int view) const;
PANGOLIN_DEPRECATED
OpenGlRenderState& Set(OpenGlMatrixSpec spec);
protected:
OpenGlMatrix modelview;
std::vector<OpenGlMatrix> projection;
std::vector<OpenGlMatrix> modelview_premult;
OpenGlMatrix T_cw;
bool follow;
};
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixRUB_BottomLeft(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixRUB_TopLeft(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixRDF_TopLeft(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixRDF_TopRight(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixRDF_BottomLeft(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixRDF_BottomRight(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
//! Use OpenGl's default frame RUB_BottomLeft
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrix(int w, int h, GLprecision fu, GLprecision fv, GLprecision u0, GLprecision v0, GLprecision zNear, GLprecision zFar );
PANGOLIN_EXPORT
OpenGlMatrixSpec ProjectionMatrixOrthographic(GLprecision l, GLprecision r, GLprecision b, GLprecision t, GLprecision n, GLprecision f );
//! Generate glulookat style model view matrix, looking at (lx,ly,lz)
//! X-Right, Y-Up, Z-Back
PANGOLIN_EXPORT
OpenGlMatrix ModelViewLookAtRUB(GLprecision ex, GLprecision ey, GLprecision ez, GLprecision lx, GLprecision ly, GLprecision lz, GLprecision ux, GLprecision uy, GLprecision uz);
//! Generate glulookat style model view matrix, looking at (lx,ly,lz)
//! X-Right, Y-Down, Z-Forward
PANGOLIN_EXPORT
OpenGlMatrix ModelViewLookAtRDF(GLprecision ex, GLprecision ey, GLprecision ez, GLprecision lx, GLprecision ly, GLprecision lz, GLprecision ux, GLprecision uy, GLprecision uz);
//! Generate glulookat style model view matrix, OpenGL Default camera convention (XYZ=RUB), looking at (lx,ly,lz)
PANGOLIN_EXPORT
OpenGlMatrix ModelViewLookAt(GLprecision x, GLprecision y, GLprecision z, GLprecision lx, GLprecision ly, GLprecision lz, AxisDirection up);
PANGOLIN_EXPORT
OpenGlMatrix ModelViewLookAt(GLprecision ex, GLprecision ey, GLprecision ez, GLprecision lx, GLprecision ly, GLprecision lz, GLprecision ux, GLprecision uy, GLprecision uz);
PANGOLIN_EXPORT
OpenGlMatrix IdentityMatrix();
PANGOLIN_EXPORT
OpenGlMatrixSpec IdentityMatrix(OpenGlStack type);
PANGOLIN_EXPORT
OpenGlMatrixSpec negIdentityMatrix(OpenGlStack type);
#ifdef HAVE_TOON
OpenGlMatrixSpec FromTooN(const TooN::SE3<>& T_cw);
OpenGlMatrixSpec FromTooN(OpenGlStack type, const TooN::Matrix<4,4>& M);
TooN::Matrix<4,4> ToTooN(const OpenGlMatrixSpec& ms);
TooN::SE3<> ToTooN_SE3(const OpenGlMatrixSpec& ms);
#endif
#ifdef HAVE_EIGEN
template<typename P>
Eigen::Matrix<P,4,4> ToEigen(const OpenGlMatrix& ms);
#endif
}
// Inline definitions
namespace pangolin
{
template<typename P>
inline OpenGlMatrix OpenGlMatrix::ColMajor4x4(const P* col_major_4x4)
{
OpenGlMatrix mat;
std::copy(col_major_4x4, col_major_4x4 + 16, mat.m);
return mat;
}
inline OpenGlMatrix::OpenGlMatrix() {
}
#ifdef USE_EIGEN
template<typename P> inline
OpenGlMatrix::OpenGlMatrix(const Eigen::Matrix<P,4,4>& mat)
{
for(int r=0; r<4; ++r ) {
for(int c=0; c<4; ++c ) {
m[c*4+r] = mat(r,c);
}
}
}
template<typename P>
OpenGlMatrix::operator Eigen::Matrix<P,4,4>() const
{
return ToEigen<P>(*this);
}
template<typename P>
OpenGlMatrix::operator Eigen::Transform<P,3,Eigen::Affine>() const
{
return Eigen::Transform<P,3,Eigen::Affine>(ToEigen<P>(*this));
}
template<typename P> inline
Eigen::Matrix<P,4,4> ToEigen(const OpenGlMatrix& ms)
{
Eigen::Matrix<P,4,4> mat;
for(int r=0; r<4; ++r ) {
for(int c=0; c<4; ++c ) {
mat(r,c) = (P)ms.m[c*4+r];
}
}
return mat;
}
#endif // USE_EIGEN
#ifdef HAVE_TOON
inline OpenGlMatrix::OpenGlMatrix(const TooN::SE3<>& T)
{
TooN::Matrix<4,4,GLprecision,TooN::ColMajor> M;
M.slice<0,0,3,3>() = T.get_rotation().get_matrix();
M.T()[3].slice<0,3>() = T.get_translation();
M[3] = TooN::makeVector(0,0,0,1);
std::memcpy(m, &(M[0][0]),16*sizeof(GLprecision));
}
inline OpenGlMatrix::OpenGlMatrix(const TooN::Matrix<4,4>& M)
{
// Read in remembering col-major convension for our matrices
int el = 0;
for(int c=0; c<4; ++c)
for(int r=0; r<4; ++r)
m[el++] = M[r][c];
}
inline OpenGlMatrix::operator const TooN::SE3<>() const
{
const TooN::Matrix<4,4> m = *this;
const TooN::SO3<> R(m.slice<0,0,3,3>());
const TooN::Vector<3> t = m.T()[3].slice<0,3>();
return TooN::SE3<>(R,t);
}
inline OpenGlMatrix::operator const TooN::Matrix<4,4>() const
{
TooN::Matrix<4,4> M;
int el = 0;
for( int c=0; c<4; ++c )
for( int r=0; r<4; ++r )
M(r,c) = m[el++];
return M;
}
PANGOLIN_DEPRECATED
inline OpenGlMatrixSpec FromTooN(const TooN::SE3<>& T_cw)
{
TooN::Matrix<4,4,GLprecision,TooN::ColMajor> M;
M.slice<0,0,3,3>() = T_cw.get_rotation().get_matrix();
M.T()[3].slice<0,3>() = T_cw.get_translation();
M[3] = TooN::makeVector(0,0,0,1);
OpenGlMatrixSpec P;
P.type = GlModelViewStack;
std::memcpy(P.m, &(M[0][0]),16*sizeof(GLprecision));
return P;
}
PANGOLIN_DEPRECATED
inline OpenGlMatrixSpec FromTooN(OpenGlStack type, const TooN::Matrix<4,4>& M)
{
// Read in remembering col-major convension for our matrices
OpenGlMatrixSpec P;
P.type = type;
int el = 0;
for(int c=0; c<4; ++c)
for(int r=0; r<4; ++r)
P.m[el++] = M[r][c];
return P;
}
PANGOLIN_DEPRECATED
inline TooN::Matrix<4,4> ToTooN(const OpenGlMatrix& ms)
{
TooN::Matrix<4,4> m;
int el = 0;
for( int c=0; c<4; ++c )
for( int r=0; r<4; ++r )
m(r,c) = ms.m[el++];
return m;
}
PANGOLIN_DEPRECATED
inline TooN::SE3<> ToTooN_SE3(const OpenGlMatrix& ms)
{
TooN::Matrix<4,4> m = ms;
const TooN::SO3<> R(m.slice<0,0,3,3>());
const TooN::Vector<3> t = m.T()[3].slice<0,3>();
return TooN::SE3<>(R,t);
}
#endif // HAVE_TOON
#ifdef HAVE_OCULUS
inline OpenGlMatrix::OpenGlMatrix(const OVR::Matrix4f& mat)
{
for(int r=0; r<4; ++r )
for(int c=0; c<4; ++c )
m[c*4+r] = mat.M[r][c];
}
inline OpenGlMatrix::operator const OVR::Matrix4f() const
{
OVR::Matrix4f mat;
for(int r=0; r<4; ++r )
for(int c=0; c<4; ++c )
mat.M[r][c] = m[c*4+r];
return mat;
}
#endif // HAVE_OCULUS
}

View File

@@ -0,0 +1,43 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/platform.h>
namespace pangolin
{
class PANGOLIN_EXPORT UserApp
{
public:
virtual ~UserApp() {}
virtual void Init() {}
virtual void Render() = 0;
};
}

View File

@@ -0,0 +1,235 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <functional>
#include <vector>
#include <pangolin/display/viewport.h>
#include <pangolin/display/attach.h>
namespace pangolin
{
enum Layout
{
LayoutOverlay,
LayoutVertical,
LayoutHorizontal,
LayoutEqual,
LayoutEqualVertical,
LayoutEqualHorizontal
};
enum Lock {
LockLeft = 0,
LockBottom = 0,
LockCenter = 1,
LockRight = 2,
LockTop = 2
};
// Forward declarations
struct Handler;
class OpenGlRenderState;
/// A Display manages the location and resizing of an OpenGl viewport.
struct PANGOLIN_EXPORT View
{
View(double aspect=0.0)
: aspect(aspect), top(1.0),left(0.0),right(1.0),bottom(0.0), hlock(LockCenter),vlock(LockCenter),
layout(LayoutOverlay), scroll_offset(0), show(1), zorder(0), handler(0), scroll_show(1) {}
virtual ~View() {}
//! Activate Displays viewport for drawing within this area
void Activate() const;
//! Activate Displays and set State Matrices
void Activate(const OpenGlRenderState& state ) const;
//! Activate Displays viewport and Scissor for drawing within this area
void ActivateAndScissor() const;
//! Activate Displays viewport and Scissor for drawing within this area
void ActivateScissorAndClear() const;
//! Activate Display and set State Matrices
void ActivateAndScissor(const OpenGlRenderState& state ) const;
//! Activate Display and set State Matrices
void ActivateScissorAndClear(const OpenGlRenderState& state ) const;
//! Activate Display and setup coordinate system for 2d pixel View coordinates
void ActivatePixelOrthographic() const;
//! Activate Display and reset coordinate system to OpenGL default
void ActivateIdentity() const;
//! Return closest depth buffer value within radius of window (winx,winy)
GLfloat GetClosestDepth(int winx, int winy, int radius) const;
//! Obtain camera space coordinates of scene at pixel (winx, winy, winzdepth)
//! winzdepth can be obtained from GetClosestDepth
void GetCamCoordinates(const OpenGlRenderState& cam_state, double winx, double winy, double winzdepth, GLdouble& x, GLdouble& y, GLdouble& z) const;
//! Obtain object space coordinates of scene at pixel (winx, winy, winzdepth)
//! winzdepth can be obtained from GetClosestDepth
void GetObjectCoordinates(const OpenGlRenderState& cam_state, double winx, double winy, double winzdepth, GLdouble& x, GLdouble& y, GLdouble& z) const;
//! Given the specification of Display, compute viewport
virtual void Resize(const Viewport& parent);
//! Instruct all children to resize
virtual void ResizeChildren();
//! Perform any automatic rendering for this View.
//! Default implementation simply instructs children to render themselves.
virtual void Render();
//! Instruct all children to render themselves if appropriate
virtual void RenderChildren();
//! Set this view as the active View to receive input
View& SetFocus();
//! Returns true iff this view currently has focus and will receive user input
bool HasFocus() const;
//! Set bounds for the View using mixed fractional / pixel coordinates (OpenGl view coordinates)
View& SetBounds(Attach bottom, Attach top, Attach left, Attach right);
//! Set bounds for the View using mixed fractional / pixel coordinates (OpenGl view coordinates)
View& SetBounds(Attach bottom, Attach top, Attach left, Attach right, bool keep_aspect);
//! Set bounds for the View using mixed fractional / pixel coordinates (OpenGl view coordinates)
View& SetBounds(Attach bottom, Attach top, Attach left, Attach right, double aspect);
//! Designate handler for accepting mouse / keyboard input.
View& SetHandler(Handler* handler);
//! Set drawFunc as the drawing function for this view
View& SetDrawFunction(const std::function<void(View&)>& drawFunc);
//! Force this view to have the given aspect, whilst fitting snuggly
//! within the parent. A negative value with 'over-draw', fitting the
//! smaller side of the parent.
View& SetAspect(double aspect);
//! Set how this view should be positioned relative to its parent
View& SetLock(Lock horizontal, Lock vertical );
//! Set layout policy for this view
View& SetLayout(Layout layout);
//! Add view as child
View& AddDisplay(View& view);
//! Show / hide this view
View& Show(bool show=true);
//! Toggle this views visibility
void ToggleShow();
//! Return whether this view should be shown.
//! This method should be checked if drawing manually
bool IsShown() const;
//! Returns viewport reflecting space that will actually get drawn
//! The minimum of vp and v
Viewport GetBounds() const;
//! Specify that this views region in the framebuffer should be saved to
//! a file just before the buffer is flipped.
void SaveOnRender(const std::string& filename_prefix);
//! Specify that this views region in the framebuffer should be saved to
//! a video just before the buffer is flipped
void RecordOnRender(const std::string& record_uri);
//! Uses the views default render method to draw into an FBO 'scale' times
//! the size of the view and save to a file.
void SaveRenderNow(const std::string& filename_prefix, float scale = 1);
//! Return number of child views attached to this view
size_t NumChildren() const;
//! Return (i)th child of this view
View& operator[](size_t i);
//! Return number of visible child views attached to this view.
size_t NumVisibleChildren() const;
//! Return visible child by index.
View& VisibleChild(size_t i);
//! Return visible child at window coords x,y
View* FindChild(int x, int y);
// Desired width / height aspect (0 if dynamic)
double aspect;
// Bounds to fit display within
Attach top, left, right, bottom;
Lock hlock;
Lock vlock;
Layout layout;
int scroll_offset;
// Cached client area (space allocated from parent)
Viewport vp;
// Cached absolute viewport (recomputed on resize - respects aspect)
Viewport v;
// Should this view be displayed?
bool show;
// Child views are rendered in order of low to high z-order
// Views default to 0 z-order
int zorder;
// Input event handler (if any)
Handler* handler;
// Map for sub-displays (if any)
std::vector<View*> views;
// External draw function
std::function<void(View&)> extern_draw_function;
private:
// Private copy constructor
View(View&) { /* Do Not copy - take reference instead*/ }
bool scroll_show;
};
}

View File

@@ -0,0 +1,65 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/gl/glinclude.h>
#include <pangolin/display/opengl_render_state.h>
namespace pangolin
{
/// Encapsulates OpenGl Viewport.
struct PANGOLIN_EXPORT Viewport
{
Viewport() : l(0),b(0),w(0),h(0) {}
Viewport(GLint l,GLint b,GLint w,GLint h) : l(l),b(b),w(w),h(h) {}
void Activate() const;
void ActivateIdentity() const;
void ActivatePixelOrthographic() const;
void Scissor() const;
void ActivateAndScissor() const;
bool Contains(int x, int y) const;
Viewport Inset(int i) const;
Viewport Inset(int horiz, int vert) const;
Viewport Intersect(const Viewport& vp) const;
void GetCamCoordinates(const OpenGlRenderState& cam_state, double winx, double winy, double winzdepth, GLdouble& x, GLdouble& y, GLdouble& z) const;
static void DisableScissor();
GLint r() const { return l+w;}
GLint t() const { return b+h;}
GLfloat aspect() const { return (GLfloat)w / (GLfloat)h; }
GLint l,b,w,h;
};
}

View File

@@ -0,0 +1,141 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/display/view.h>
#include <pangolin/var/var.h>
#include <pangolin/handler/handler.h>
#include <pangolin/gl/glfont.h>
#include <functional>
namespace pangolin
{
PANGOLIN_EXPORT
View& CreatePanel(const std::string& name);
struct PANGOLIN_EXPORT Panel : public View
{
Panel();
Panel(const std::string& auto_register_var_prefix);
void Render();
void ResizeChildren();
static void AddVariable(void* data, const std::string& name, VarValueGeneric& var, bool brand_new);
};
template<typename T>
struct Widget : public View, Handler, Var<T>
{
Widget(std::string title, VarValueGeneric& tv)
: Var<T>(tv), title(title)
{
handler = this;
}
std::string title;
};
struct PANGOLIN_EXPORT Button : public Widget<bool>
{
Button(std::string title, VarValueGeneric& tv);
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int mouse_state);
void Render();
//Cache params on resize
void ResizeChildren();
GlText gltext;
GLfloat raster[2];
bool down;
};
struct PANGOLIN_EXPORT FunctionButton : public Widget<std::function<void(void)> >
{
FunctionButton(std::string title, VarValueGeneric& tv);
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int mouse_state);
void Render();
//Cache params on resize
void ResizeChildren();
GlText gltext;
GLfloat raster[2];
bool down;
};
struct PANGOLIN_EXPORT Checkbox : public Widget<bool>
{
Checkbox(std::string title, VarValueGeneric& tv);
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int mouse_state);
void Render();
//Cache params on resize
void ResizeChildren();
GlText gltext;
GLfloat raster[2];
Viewport vcb;
};
struct PANGOLIN_EXPORT Slider : public Widget<double>
{
Slider(std::string title, VarValueGeneric& tv);
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int mouse_state);
void MouseMotion(View&, int x, int y, int mouse_state);
void Keyboard(View&, unsigned char key, int x, int y, bool pressed);
void Render();
//Cache params on resize
void ResizeChildren();
GlText gltext;
GLfloat raster[2];
bool lock_bounds;
bool logscale;
bool is_integral_type;
};
struct PANGOLIN_EXPORT TextInput : public Widget<std::string>
{
TextInput(std::string title, VarValueGeneric& tv);
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int mouse_state);
void MouseMotion(View&, int x, int y, int mouse_state);
void Keyboard(View&, unsigned char key, int x, int y, bool pressed);
void Render();
std::string edit;
GlText gledit;
//Cache params on resize
void ResizeChildren();
GlText gltext;
GLfloat raster[2];
bool can_edit;
bool do_edit;
int sel[2];
};
}

View File

@@ -0,0 +1,90 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2016 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <exception>
#include <pangolin/platform.h>
#include <string>
namespace pangolin
{
class GlContextInterface
{
public:
virtual ~GlContextInterface() {}
};
class WindowInterface
{
public:
virtual ~WindowInterface() {}
virtual void ToggleFullscreen() = 0;
virtual void Move(int x, int y) = 0;
virtual void Resize(unsigned int w, unsigned int h) = 0;
/**
* @brief MakeCurrent set the current context
* to be called in a thread before accessing OpenGL
*/
virtual void MakeCurrent() = 0;
/**
* @brief RemoveCurrent remove the current context
* to be called at the end of a thread
*/
virtual void RemoveCurrent() = 0;
virtual void ProcessEvents() = 0;
virtual void SwapBuffers() = 0;
};
struct PANGOLIN_EXPORT WindowException : std::exception
{
WindowException(std::string str) : desc(str) {}
WindowException(std::string str, std::string detail) {
desc = str + "\n\t" + detail;
}
~WindowException() throw() {}
const char* what() const throw() { return desc.c_str(); }
std::string desc;
};
struct PANGOLIN_EXPORT WindowExceptionNoKnownHandler : public WindowException
{
WindowExceptionNoKnownHandler(const std::string& scheme)
: WindowException("No known window handler for URI '" + scheme + "'")
{
}
};
}