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,33 @@
# All examples depend on Pangolin GUI
if(BUILD_PANGOLIN_GUI)
add_subdirectory(HelloPangolin)
add_subdirectory(HelloPangolinOffscreen)
add_subdirectory(HelloPangolinThreads)
add_subdirectory(SimpleMultiDisplay)
add_subdirectory(SimpleDisplayImage)
add_subdirectory(SimpleScene)
if(NOT HAVE_GLES OR HAVE_GLES_2)
add_subdirectory(SimplePlot)
endif()
## These samples require Pangolin Var support
if(BUILD_PANGOLIN_VARS)
add_subdirectory(SimpleDisplay)
## Video Samples require Pangolin Video support
if(BUILD_PANGOLIN_VIDEO)
add_subdirectory(SimpleVideo)
add_subdirectory(SimpleRecord)
add_subdirectory(SharedMemoryCamera)
endif()
# # This sample fails on many platforms, so exclude it for now,
# # until we can create a better cmake test for support.
# find_package(CUDA QUIET)
# if( CUDA_FOUND )
# add_subdirectory(VBODisplay)
# endif()
endif()
endif()

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(HelloPangolin main.cpp)
target_link_libraries(HelloPangolin ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,34 @@
#include <pangolin/pangolin.h>
int main( int /*argc*/, char** /*argv*/ )
{
pangolin::CreateWindowAndBind("Main",640,480);
glEnable(GL_DEPTH_TEST);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),
pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)
);
// Create Interactive View in window
pangolin::Handler3D handler(s_cam);
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)
.SetHandler(&handler);
while( !pangolin::ShouldQuit() )
{
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
// Render OpenGL Cube
pangolin::glDrawColouredCube();
// Swap frames and Process Events
pangolin::FinishFrame();
}
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.5 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(HelloPangolinOffscreen main.cpp)
target_link_libraries(HelloPangolinOffscreen ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,48 @@
#include <pangolin/pangolin.h>
int main( int /*argc*/, char** /*argv*/ )
{
static const int w = 640;
static const int h = 480;
pangolin::CreateWindowAndBind("Main",w,h,pangolin::Params({{"scheme", "headless"}}));
glEnable(GL_DEPTH_TEST);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(w,h,420,420,320,240,0.2,100),
pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)
);
// Create Interactive View in window
pangolin::Handler3D handler(s_cam);
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, 0.0, 1.0, -float(w)/float(h))
.SetHandler(&handler);
pangolin::SaveWindowOnRender("window");
// create a frame buffer object with colour and depth buffer
pangolin::GlTexture color_buffer(w,h);
pangolin::GlRenderBuffer depth_buffer(w,h);
pangolin::GlFramebuffer fbo_buffer(color_buffer, depth_buffer);
fbo_buffer.Bind();
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
// Render OpenGL Cube
pangolin::glDrawColouredCube();
// Swap frames and Process Events
pangolin::FinishFrame();
fbo_buffer.Unbind();
// download and save the colour buffer
color_buffer.Save("fbo.png", false);
pangolin::QuitAll();
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.5 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(HelloPangolinThreads main.cpp)
target_link_libraries(HelloPangolinThreads ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,64 @@
#include <pangolin/pangolin.h>
#include <thread>
static const std::string window_name = "HelloPangolinThreads";
void setup() {
// create a window and bind its context to the main thread
pangolin::CreateWindowAndBind(window_name, 640, 480);
// enable depth
glEnable(GL_DEPTH_TEST);
// unset the current context from the main thread
pangolin::GetBoundWindow()->RemoveCurrent();
}
void run() {
// fetch the context and bind it to this thread
pangolin::BindToContext(window_name);
// we manually need to restore the properties of the context
glEnable(GL_DEPTH_TEST);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),
pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)
);
// Create Interactive View in window
pangolin::Handler3D handler(s_cam);
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)
.SetHandler(&handler);
while( !pangolin::ShouldQuit() )
{
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
// Render OpenGL Cube
pangolin::glDrawColouredCube();
// Swap frames and Process Events
pangolin::FinishFrame();
}
// unset the current context from the main thread
pangolin::GetBoundWindow()->RemoveCurrent();
}
int main( int /*argc*/, char** /*argv*/ )
{
// create window and context in the main thread
setup();
// use the context in a separate rendering thread
std::thread render_loop;
render_loop = std::thread(run);
render_loop.join();
return 0;
}

View File

@@ -0,0 +1,7 @@
if(UNIX)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SharedMemoryCamera main.cpp)
target_link_libraries(SharedMemoryCamera ${Pangolin_LIBRARIES})
endif()

View File

@@ -0,0 +1,53 @@
#include <pangolin/pangolin.h>
#include <pangolin/utils/posix/condition_variable.h>
#include <pangolin/utils/posix/shared_memory_buffer.h>
#include <pangolin/utils/timer.h>
#include <cmath>
#include <memory>
// This sample acts as a soft camera. It writes a pattern of GRAY8 pixels to the
// shared memory space. It can be seen in Pangolin's SimpleVideo sample using
// the shmem:[size=640x480]//example video URI.
using namespace pangolin;
unsigned char generate_value(double t)
{
// 10s sinusoid
const double d = std::sin(t * 10.0 / M_PI) * 128.0 + 128.0;
return static_cast<unsigned char>(d);
}
int main(/*int argc, char *argv[]*/)
{
std::string shmem_name = "/example";
std::shared_ptr<SharedMemoryBufferInterface> shmem_buffer =
create_named_shared_memory_buffer(shmem_name, 640 * 480);
if (!shmem_buffer) {
perror("Unable to create shared memory buffer");
exit(1);
}
std::string cond_name = shmem_name + "_cond";
std::shared_ptr<ConditionVariableInterface> buffer_full =
create_named_condition_variable(cond_name);
// Sit in a loop and write gray values based on some timing pattern.
while (true) {
shmem_buffer->lock();
unsigned char *ptr = shmem_buffer->ptr();
unsigned char value = generate_value(std::chrono::system_clock::now().time_since_epoch().count());
for (int i = 0; i < 640*480; ++i) {
ptr[i] = value;
}
shmem_buffer->unlock();
buffer_full->signal();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}

View File

@@ -0,0 +1,7 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimpleDisplay main.cpp)
target_link_libraries(SimpleDisplay ${Pangolin_LIBRARIES} )

View File

@@ -0,0 +1,26 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pangolin Sample configuration file
% Comments start with '%' or '#'
%
% Declarations are name value pairs,
% seperated with '=' and terminated with ';'
% We can set any variable referenced in code directly
ui.A Double = 3.2;
ui.A Checkbox = false;
% We can set unreferenced variables too
a.b = 1;
a.c = 2;
z.b = 3;
z.c = 4;
start = z;
% Which we might refer to by reference
ui.An Int = ${${start}.c};
% Declarations can span multiple lines
M =
[1, 0, 0
0, 1, 0
0, 0, 1];

View File

@@ -0,0 +1,129 @@
#include <iostream>
#include <pangolin/pangolin.h>
struct CustomType
{
CustomType()
: x(0), y(0.0f) {}
CustomType(int x, float y, std::string z)
: x(x), y(y), z(z) {}
int x;
float y;
std::string z;
};
std::ostream& operator<< (std::ostream& os, const CustomType& o){
os << o.x << " " << o.y << " " << o.z;
return os;
}
std::istream& operator>> (std::istream& is, CustomType& o){
is >> o.x;
is >> o.y;
is >> o.z;
return is;
}
void SampleMethod()
{
std::cout << "You typed ctrl-r or pushed reset" << std::endl;
}
int main(/*int argc, char* argv[]*/)
{
// Load configuration data
pangolin::ParseVarsFile("app.cfg");
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Main",640,480);
// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);
// Define Camera Render Object (for view / scene browsing)
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-0,0.5,-3, 0,0,0, pangolin::AxisY)
);
const int UI_WIDTH = 180;
// Add named OpenGL viewport to window and provide 3D Handler
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
// Add named Panel and bind to variables beginning 'ui'
// A Panel is just a View with a default layout and input handling
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
// Safe and efficient binding of named variables.
// Specialisations mean no conversions take place for exact types
// and conversions between scalar types are cheap.
pangolin::Var<bool> a_button("ui.A_Button",false,false);
pangolin::Var<double> a_double("ui.A_Double",3,0,5);
pangolin::Var<int> an_int("ui.An_Int",2,0,5);
pangolin::Var<double> a_double_log("ui.Log_scale var",3,1,1E4, true);
pangolin::Var<bool> a_checkbox("ui.A_Checkbox",false,true);
pangolin::Var<int> an_int_no_input("ui.An_Int_No_Input",2);
pangolin::Var<CustomType> any_type("ui.Some_Type", CustomType(0,1.2f,"Hello") );
pangolin::Var<bool> save_window("ui.Save_Window",false,false);
pangolin::Var<bool> save_cube("ui.Save_Cube",false,false);
pangolin::Var<bool> record_cube("ui.Record_Cube",false,false);
// std::function objects can be used for Var's too. These work great with C++11 closures.
pangolin::Var<std::function<void(void)> > reset("ui.Reset", SampleMethod);
// Demonstration of how we can register a keyboard hook to alter a Var
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'b', pangolin::SetVarFunctor<double>("ui.A_Double", 3.5));
// Demonstration of how we can register a keyboard hook to trigger a method
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
// Default hooks for exiting (Esc) and fullscreen (tab).
while( !pangolin::ShouldQuit() )
{
// Clear entire screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if( pangolin::Pushed(a_button) )
std::cout << "You Pushed a button!" << std::endl;
// Overloading of Var<T> operators allows us to treat them like
// their wrapped types, eg:
if( a_checkbox )
an_int = (int)a_double;
if( !any_type->z.compare("robot"))
any_type = CustomType(1,2.3f,"Boogie");
an_int_no_input = an_int;
if( pangolin::Pushed(save_window) )
pangolin::SaveWindowOnRender("window");
if( pangolin::Pushed(save_cube) )
d_cam.SaveOnRender("cube");
if( pangolin::Pushed(record_cube) )
pangolin::DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");
// Activate efficiently by object
d_cam.Activate(s_cam);
// Render some stuff
glColor3f(1.0,1.0,1.0);
pangolin::glDrawColouredCube();
// Swap frames and Process Events
pangolin::FinishFrame();
}
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimpleDisplayImage main.cpp)
target_link_libraries(SimpleDisplayImage ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,72 @@
#include <limits>
#include <iostream>
#include <pangolin/pangolin.h>
void setImageData(unsigned char * imageArray, int size){
for(int i = 0 ; i < size;i++) {
imageArray[i] = (unsigned char)(rand()/(RAND_MAX/255.0));
}
}
int main(/*int argc, char* argv[]*/)
{
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Main",640,480);
// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-1,1,-1, 0,0,0, pangolin::AxisY)
);
// Aspect ratio allows us to constrain width and height whilst fitting within specified
// bounds. A positive aspect ratio makes a view 'shrink to fit' (introducing empty bars),
// whilst a negative ratio makes the view 'grow to fit' (cropping the view).
pangolin::View& d_cam = pangolin::Display("cam")
.SetBounds(0,1.0f,0,1.0f,-640/480.0)
.SetHandler(new pangolin::Handler3D(s_cam));
// This view will take up no more than a third of the windows width or height, and it
// will have a fixed aspect ratio to match the image that it will display. When fitting
// within the specified bounds, push to the top-left (as specified by SetLock).
pangolin::View& d_image = pangolin::Display("image")
.SetBounds(2/3.0f,1.0f,0,1/3.0f,640.0/480)
.SetLock(pangolin::LockLeft, pangolin::LockTop);
std::cout << "Resize the window to experiment with SetBounds, SetLock and SetAspect." << std::endl;
std::cout << "Notice that the cubes aspect is maintained even though it covers the whole screen." << std::endl;
const int width = 64;
const int height = 48;
unsigned char* imageArray = new unsigned char[3*width*height];
pangolin::GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
// Default hooks for exiting (Esc) and fullscreen (tab).
while(!pangolin::ShouldQuit())
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
glColor3f(1.0,1.0,1.0);
pangolin::glDrawColouredCube();
//Set some random image data and upload to GPU
setImageData(imageArray,3*width*height);
imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE);
//display the image
d_image.Activate();
glColor3f(1.0,1.0,1.0);
imageTexture.RenderToViewport();
pangolin::FinishFrame();
}
delete[] imageArray;
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimpleMultiDisplay main.cpp)
target_link_libraries(SimpleMultiDisplay ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,28 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pangolin Sample configuration file
% Comments start with '%' or '#'
%
% Declarations are name value pairs,
% seperated with '=' and terminated with ';'
% We can set any variable referenced in code directly
ui.A Double = 3.2;
% We can set unreferenced variables too
a.b = 1;
a.c = 2;
z.b = 3;
z.c = 4;
start = z;
% Which we might refer to by reference
ui.An Int = ${${start}.c};
% Declarations can span multiple lines
M =
[1, 0, 0
0, 1, 0
0, 0, 1];
ui.Aliased Double = @ui.A Double;
ui.Aliased Double = 2.0;

View File

@@ -0,0 +1,106 @@
#include <iostream>
#include <pangolin/pangolin.h>
void setImageData(unsigned char * imageArray, int size){
for(int i = 0 ; i < size;i++) {
imageArray[i] = (unsigned char)(rand()/(RAND_MAX/255.0));
}
}
int main(/*int argc, char* argv[]*/)
{
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Main",640,480);
// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);
// Issue specific OpenGl we might need
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Define Camera Render Object (for view / scene browsing)
pangolin::OpenGlMatrix proj = pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000);
pangolin::OpenGlRenderState s_cam(proj, pangolin::ModelViewLookAt(1,0.5,-2,0,0,0, pangolin::AxisY) );
pangolin::OpenGlRenderState s_cam2(proj, pangolin::ModelViewLookAt(0,0,-2,0,0,0, pangolin::AxisY) );
// Add named OpenGL viewport to window and provide 3D Handler
pangolin::View& d_cam1 = pangolin::Display("cam1")
.SetAspect(640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
pangolin::View& d_cam2 = pangolin::Display("cam2")
.SetAspect(640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam2));
pangolin::View& d_cam3 = pangolin::Display("cam3")
.SetAspect(640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
pangolin::View& d_cam4 = pangolin::Display("cam4")
.SetAspect(640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam2));
pangolin::View& d_img1 = pangolin::Display("img1")
.SetAspect(640.0f/480.0f);
pangolin::View& d_img2 = pangolin::Display("img2")
.SetAspect(640.0f/480.0f);
// LayoutEqual is an EXPERIMENTAL feature - it requires that all sub-displays
// share the same aspect ratio, placing them in a raster fasion in the
// viewport so as to maximise display size.
pangolin::Display("multi")
.SetBounds(0.0, 1.0, 0.0, 1.0)
.SetLayout(pangolin::LayoutEqual)
.AddDisplay(d_cam1)
.AddDisplay(d_img1)
.AddDisplay(d_cam2)
.AddDisplay(d_img2)
.AddDisplay(d_cam3)
.AddDisplay(d_cam4);
const int width = 64;
const int height = 48;
unsigned char* imageArray = new unsigned char[3*width*height];
pangolin::GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
// Default hooks for exiting (Esc) and fullscreen (tab).
while( !pangolin::ShouldQuit() )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Generate random image and place in texture memory for display
setImageData(imageArray,3*width*height);
imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE);
glColor3f(1.0,1.0,1.0);
d_cam1.Activate(s_cam);
pangolin::glDrawColouredCube();
d_cam2.Activate(s_cam2);
pangolin::glDrawColouredCube();
d_cam3.Activate(s_cam);
pangolin::glDrawColouredCube();
d_cam4.Activate(s_cam2);
pangolin::glDrawColouredCube();
d_img1.Activate();
glColor4f(1.0f,1.0f,1.0f,1.0f);
imageTexture.RenderToViewport();
d_img2.Activate();
glColor4f(1.0f,1.0f,1.0f,1.0f);
imageTexture.RenderToViewport();
// Swap frames and Process Events
pangolin::FinishFrame();
}
delete[] imageArray;
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimplePlot main.cpp)
target_link_libraries(SimplePlot ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,49 @@
#include <iostream>
#include <pangolin/pangolin.h>
int main(/*int argc, char* argv[]*/)
{
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Main",640,480);
// Data logger object
pangolin::DataLog log;
// Optionally add named labels
std::vector<std::string> labels;
labels.push_back(std::string("sin(t)"));
labels.push_back(std::string("cos(t)"));
labels.push_back(std::string("sin(t)+cos(t)"));
log.SetLabels(labels);
const float tinc = 0.01f;
// OpenGL 'view' of data. We might have many views of the same data.
pangolin::Plotter plotter(&log,0.0f,4.0f*(float)M_PI/tinc,-2.0f,2.0f,(float)M_PI/(4.0f*tinc),0.5f);
plotter.SetBounds(0.0, 1.0, 0.0, 1.0);
plotter.Track("$i");
// Add some sample annotations to the plot
plotter.AddMarker(pangolin::Marker::Vertical, -1000, pangolin::Marker::LessThan, pangolin::Colour::Blue().WithAlpha(0.2f) );
plotter.AddMarker(pangolin::Marker::Horizontal, 100, pangolin::Marker::GreaterThan, pangolin::Colour::Red().WithAlpha(0.2f) );
plotter.AddMarker(pangolin::Marker::Horizontal, 10, pangolin::Marker::Equal, pangolin::Colour::Green().WithAlpha(0.2f) );
pangolin::DisplayBase().AddDisplay(plotter);
float t = 0;
// Default hooks for exiting (Esc) and fullscreen (tab).
while( !pangolin::ShouldQuit() )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
log.Log(sin(t),cos(t),sin(t)+cos(t));
t += tinc;
// Render graph, Swap frames and Process Events
pangolin::FinishFrame();
}
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimpleRecord main.cpp)
target_link_libraries(SimpleRecord ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,94 @@
#include <pangolin/pangolin.h>
void RecordSample(const std::string input_uri, const std::string record_uri)
{
// Setup Video Source
pangolin::VideoInput video(input_uri);
const pangolin::PixelFormat vid_fmt = video.PixFormat();
const unsigned w = video.Width();
const unsigned h = video.Height();
pangolin::VideoOutput recorder( record_uri );
recorder.SetStreams(video.Streams());
// Create OpenGL window
pangolin::CreateWindowAndBind("Main",w,h);
// Create viewport for video with fixed aspect
pangolin::View vVideo((float)w/h);
// OpenGl Texture for video frame
pangolin::GlTexture texVideo(w,h,GL_RGBA);
// Allocate image buffer. The +1 is to give ffmpeg some alignment slack
// swscale seems to have a bug which goes over the array by 1...
unsigned char* img = new unsigned char[video.SizeBytes() + 1];
while( !pangolin::ShouldQuit() )
{
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if( video.GrabNext(img,true) )
{
// Upload to GPU as texture for display
texVideo.Upload(img, vid_fmt.channels==1 ? GL_LUMINANCE:GL_RGB, GL_UNSIGNED_BYTE);
// Record video frame
recorder.WriteStreams(img);
}
// Activate video viewport and render texture
vVideo.Activate();
texVideo.RenderToViewportFlipY();
// Swap back buffer with front and process window events
pangolin::FinishFrame();
}
delete[] img;
}
int main( int argc, char* argv[] )
{
std::string record_uri = "ffmpeg:[fps=30,bps=8388608]//video.avi";
std::string input_uris[] = {
"dc1394:[fps=30,dma=10,size=640x480,iso=400]//0",
"convert:[fmt=RGB24]//v4l:///dev/video0",
"convert:[fmt=RGB24]//v4l:///dev/video1",
""
};
if( argc >= 2 ) {
const std::string uri = std::string(argv[1]);
if( argc == 3 ) {
record_uri = std::string(argv[2]);
}
RecordSample(uri, record_uri);
}else{
std::cout << "Usage : SimpleRecord [video-uri] [output-uri]" << std::endl << std::endl;
std::cout << "Where video-uri describes a stream or file resource, e.g." << std::endl;
std::cout << "\tfile:[realtime=1]///home/user/video/movie.pvn" << std::endl;
std::cout << "\tfile:///home/user/video/movie.avi" << std::endl;
std::cout << "\tfiles:///home/user/seqiemce/foo%03d.jpeg" << std::endl;
std::cout << "\tdc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0" << std::endl;
std::cout << "\tdc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0" << std::endl;
std::cout << "\tv4l:///dev/video0" << std::endl;
std::cout << "\tconvert:[fmt=RGB24]//v4l:///dev/video0" << std::endl;
std::cout << "\tmjpeg://http://127.0.0.1/?action=stream" << std::endl;
std::cout << std::endl;
// Try to open some video device
for(int i=0; !input_uris[i].empty(); ++i )
{
try{
std::cout << "Trying: " << input_uris[i] << std::endl;
RecordSample(input_uris[i], record_uri);
return 0;
}catch(const pangolin::VideoException&) {}
}
}
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimpleScene main.cpp)
target_link_libraries(SimpleScene ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,40 @@
#include <pangolin/pangolin.h>
#include <pangolin/scene/axis.h>
#include <pangolin/scene/scenehandler.h>
int main( int /*argc*/, char** /*argv*/ )
{
pangolin::CreateWindowAndBind("Main",640,480);
glEnable(GL_DEPTH_TEST);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),
pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)
);
pangolin::Renderable tree;
tree.Add( std::make_shared<pangolin::Axis>() );
// Create Interactive View in window
pangolin::SceneHandler handler(tree, s_cam);
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)
.SetHandler(&handler);
d_cam.SetDrawFunction([&](pangolin::View& view){
view.Activate(s_cam);
tree.Render();
});
while( !pangolin::ShouldQuit() )
{
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Swap frames and Process Events
pangolin::FinishFrame();
}
return 0;
}

View File

@@ -0,0 +1,6 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(SimpleVideo main.cpp)
target_link_libraries(SimpleVideo ${Pangolin_LIBRARIES})

View File

@@ -0,0 +1,111 @@
/**
* @author Steven Lovegrove
* Copyright (C) 2010 Steven Lovegrove
* Imperial College London
**/
#include <pangolin/pangolin.h>
void SetGlFormat(GLint& glformat, GLenum& gltype, const pangolin::PixelFormat& fmt)
{
switch( fmt.channels) {
case 1: glformat = GL_LUMINANCE; break;
case 3: glformat = GL_RGB; break;
case 4: glformat = GL_RGBA; break;
default: throw std::runtime_error("Unable to display video format");
}
switch (fmt.channel_bits[0]) {
case 8: gltype = GL_UNSIGNED_BYTE; break;
case 16: gltype = GL_UNSIGNED_SHORT; break;
case 32: gltype = GL_FLOAT; break;
default: throw std::runtime_error("Unknown channel format");
}
}
void VideoSample(const std::string uri)
{
// Setup Video Source
pangolin::VideoInput video(uri);
const pangolin::PixelFormat vid_fmt = video.PixFormat();
const unsigned w = video.Width();
const unsigned h = video.Height();
// Work out appropriate GL channel and format options
GLint glformat;
GLenum gltype;
SetGlFormat(glformat, gltype, vid_fmt);
// Create OpenGL window
pangolin::CreateWindowAndBind("Main",w,h);
// Create viewport for video with fixed aspect
pangolin::View& vVideo = pangolin::Display("Video").SetAspect((float)w/h);
// OpenGl Texture for video frame.
pangolin::GlTexture texVideo(w,h,glformat,false,0,glformat,gltype);
unsigned char* img = new unsigned char[video.SizeBytes()];
for(int frame=0; !pangolin::ShouldQuit(); ++frame)
{
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if( video.GrabNext(img,true) ) {
texVideo.Upload( img, glformat, gltype );
}
// Activate video viewport and render texture
vVideo.Activate();
texVideo.RenderToViewportFlipY();
// Swap back buffer with front and process window events
pangolin::FinishFrame();
}
delete[] img;
}
int main( int argc, char* argv[] )
{
std::string uris[] = {
"dc1394:[fps=30,dma=10,size=640x480,iso=400]//0",
"convert:[fmt=RGB24]//v4l:///dev/video0",
"convert:[fmt=RGB24]//v4l:///dev/video1",
"openni:[img1=rgb]//",
"pleora:[sn=00000215,size=640x480,pos=64x64]//",
"test:[size=160x120,n=1,fmt=RGB24]//"
""
};
if( argc > 1 ) {
const std::string uri = std::string(argv[1]);
VideoSample(uri);
}else{
std::cout << "Usage : SimpleRecord [video-uri]" << std::endl << std::endl;
std::cout << "Where video-uri describes a stream or file resource, e.g." << std::endl;
std::cout << "\tfile:[realtime=1]///home/user/video/movie.pvn" << std::endl;
std::cout << "\tfile:///home/user/video/movie.avi" << std::endl;
std::cout << "\tfiles:///home/user/seqiemce/foo%03d.jpeg" << std::endl;
std::cout << "\tdc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0" << std::endl;
std::cout << "\tdc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0" << std::endl;
std::cout << "\tv4l:///dev/video0" << std::endl;
std::cout << "\tconvert:[fmt=RGB24]//v4l:///dev/video0" << std::endl;
std::cout << "\tmjpeg://http://127.0.0.1/?action=stream" << std::endl;
std::cout << "\topenni:[img1=rgb]//" << std::endl;
std::cout << std::endl;
// Try to open some video device
for(int i=0; !uris[i].empty(); ++i )
{
try{
std::cout << "Trying: " << uris[i] << std::endl;
VideoSample(uris[i]);
return 0;
}catch(const pangolin::VideoException&) { }
}
}
return 0;
}

View File

@@ -0,0 +1,19 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
link_directories(${Pangolin_LIBRARY_DIRS})
link_libraries(${Pangolin_LIBRARIES})
find_package(CUDA QUIET)
# This example could be made to work with C++11, but the kernel code must be
# compiled without it.
if(CUDA_FOUND)
cuda_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
cuda_add_executable(
VBODisplay
main.cpp kernal.cu
)
endif()

View File

@@ -0,0 +1,30 @@
// Colour Sine wave Kernal
// Based on kernal_colour in kernelVBO.cpp by Rob Farber
__global__ void kernel(float4* dVertexArray, uchar4 *dColorArray,
unsigned int width, unsigned int height, float time)
{
unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
// Each thread is unique point (u,v) in interval [-1,1],[-1,1]
const float u = 2.0f* (x/(float)width) - 1.0f;
const float v = 2.0f* (y/(float)height) - 1.0f;
const float w = 0.5f * sinf(4.0f*u + time) * cosf(4.0f*v + time);
// Update vertex array for point
dVertexArray[y*width+x] = make_float4(u, w, v, 1.0f);
// Update colour array for point
dColorArray[y*width+x].w = 0.0f;
dColorArray[y*width+x].x = 255.0f *0.5f*(1.f+sinf(w+x));
dColorArray[y*width+x].y = 255.0f *0.5f*(1.f+sinf(x)*cosf(y));
dColorArray[y*width+x].z = 255.0f *0.5f*(1.f+sinf(w+time/10.0f));
}
extern "C" void launch_kernel(float4* dVertexArray, uchar4* dColourArray,
unsigned int width, unsigned int height, float time)
{
dim3 block(8, 8, 1);
dim3 grid(width / block.x, height / block.y, 1);
kernel<<< grid, block>>>(dVertexArray, dColourArray, width, height, time);
}

View File

@@ -0,0 +1,84 @@
#include <iostream>
#include <GL/glew.h>
#include <pangolin/pangolin.h>
#include <pangolin/gl/glcuda.h>
#include <pangolin/gl/glvbo.h>
#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#include <vector_types.h>
using namespace pangolin;
using namespace std;
// Mesh size
const int mesh_width=256;
const int mesh_height=256;
extern "C" void launch_kernel(float4* dVertexArray, uchar4* dColourArray, unsigned int width, unsigned int height, float time);
int main( int /*argc*/, char* argv[] )
{
// cudaGLSetGLDevice(0);
pangolin::CreateWindowAndBind("Main",640,480);
glewInit();
// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);
// Create vertex and colour buffer objects and register them with CUDA
GlBufferCudaPtr vertex_array(
GlArrayBuffer, mesh_width*mesh_height, GL_FLOAT, 4,
cudaGraphicsMapFlagsWriteDiscard, GL_STREAM_DRAW
);
GlBufferCudaPtr colour_array(
GlArrayBuffer, mesh_width*mesh_height, GL_UNSIGNED_BYTE, 4,
cudaGraphicsMapFlagsWriteDiscard, GL_STREAM_DRAW
);
// Define Camera Render Object (for view / scene browsing)
pangolin::OpenGlRenderState s_cam(
ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
ModelViewLookAt(-0,2,-2, 0,0,0, AxisY)
);
const int UI_WIDTH = 180;
// Add named OpenGL viewport to window and provide 3D Handler
View& d_cam = pangolin::Display("cam")
.SetBounds(0.0, 1.0, Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new Handler3D(s_cam));
// Add named Panel and bind to variables beginning 'ui'
// A Panel is just a View with a default layout and input handling
View& d_panel = pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, Attach::Pix(UI_WIDTH));
// Default hooks for exiting (Esc) and fullscreen (tab).
for(int frame=0; !pangolin::ShouldQuit(); ++frame)
{
static double time = 0;
static Var<double> delta("ui.time delta", 0.001, 0, 0.005);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
glColor3f(1.0,1.0,1.0);
{
CudaScopedMappedPtr var(vertex_array);
CudaScopedMappedPtr car(colour_array);
launch_kernel((float4*)*var,(uchar4*)*car,mesh_width,mesh_height,time);
time += delta;
}
pangolin::RenderVboCbo(vertex_array, colour_array);
// Swap frames and Process Events
pangolin::FinishFrame();
}
return 0;
}