-
Notifications
You must be signed in to change notification settings - Fork 61
[ogre1.x] Add support for wide angle camera #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
2d10ca2
WIP add ogre 1.x wide angle camera
iche033 94f6983
add create wide angle camera functions to scene, add example, debuggi…
iche033 c1d001a
connect to image event
iche033 b115577
Merge branch 'ign-rendering6' into wide_angle_camera_ogre
iche033 a2ec20c
update api, fix example display
iche033 45bd4d1
callback api tweak
iche033 790513a
merge from main
iche033 26ddf35
dep bump
iche033 9ca30a8
add integration test
iche033 5850f6f
remove commented out line
iche033 3bd1ce8
cleanup
iche033 a746ace
Merge branch 'main' into wide_angle_camera_ogre
iche033 acbfc09
fix merge, update demo
iche033 230684e
more cleanup
iche033 2db301b
fix null vp
iche033 a4bde04
codecheck
iche033 2b0fcd8
fixing windows
iche033 11d3ba4
fix doxy
iche033 3399e6d
feedback changes
iche033 a826e9e
windows changes
iche033 bc70c8e
fix homebrew warnings
iche033 f373671
Merge branch 'main' into wide_angle_camera_ogre
iche033 21d9f79
use utils impl
iche033 0369511
fixing warning
iche033 9d4b6ea
fixing warning
iche033 1135fe7
port fix from gazebo11 3135
iche033 d8d4a69
Merge branch 'main' into wide_angle_camera_ogre
iche033 e6d2374
style
iche033 d145a6c
Merge branch 'wide_angle_camera_ogre' of github.com:ignitionrobotics/…
iche033 cdf6cd7
Merge branch 'main' into wide_angle_camera_ogre
iche033 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) | ||
project(ignition-rendering-wide-angle-camera) | ||
find_package(ignition-rendering7 REQUIRED) | ||
|
||
include_directories(SYSTEM | ||
${PROJECT_BINARY_DIR} | ||
) | ||
|
||
find_package(GLUT REQUIRED) | ||
include_directories(SYSTEM ${GLUT_INCLUDE_DIRS}) | ||
link_directories(${GLUT_LIBRARY_DIRS}) | ||
|
||
find_package(OpenGL REQUIRED) | ||
include_directories(SYSTEM ${OpenGL_INCLUDE_DIRS}) | ||
link_directories(${OpenGL_LIBRARY_DIRS}) | ||
|
||
if (NOT APPLE) | ||
find_package(GLEW REQUIRED) | ||
include_directories(SYSTEM ${GLEW_INCLUDE_DIRS}) | ||
link_directories(${GLEW_LIBRARY_DIRS}) | ||
endif() | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") | ||
|
||
add_executable(wide_angle_camera Main.cc GlutWindow.cc) | ||
|
||
target_link_libraries(wide_angle_camera | ||
${GLUT_LIBRARIES} | ||
${OPENGL_LIBRARIES} | ||
${GLEW_LIBRARIES} | ||
${IGNITION-RENDERING_LIBRARIES} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#if __APPLE__ | ||
#include <OpenGL/gl.h> | ||
#include <OpenGL/OpenGL.h> | ||
#include <GLUT/glut.h> | ||
#else | ||
#include <GL/glew.h> | ||
#include <GL/gl.h> | ||
#include <GL/glut.h> | ||
#endif | ||
|
||
#if !defined(__APPLE__) && !defined(_WIN32) | ||
#include <GL/glx.h> | ||
#endif | ||
|
||
#include <mutex> | ||
|
||
#include <ignition/common/Console.hh> | ||
#include <ignition/rendering/Image.hh> | ||
#include <ignition/rendering/Scene.hh> | ||
#include <ignition/rendering/WideAngleCamera.hh> | ||
|
||
#include "GlutWindow.hh" | ||
|
||
#define KEY_ESC 27 | ||
#define KEY_TAB 9 | ||
|
||
////////////////////////////////////////////////// | ||
unsigned int imgw = 0; | ||
unsigned int imgh = 0; | ||
|
||
std::vector<ir::CameraPtr> g_cameras; | ||
ir::CameraPtr g_camera; | ||
ir::CameraPtr g_currCamera; | ||
unsigned int g_cameraIndex = 0; | ||
ir::ImagePtr g_image; | ||
ignition::common::ConnectionPtr g_connection; | ||
|
||
bool g_initContext = false; | ||
|
||
#if __APPLE__ | ||
CGLContextObj g_context; | ||
CGLContextObj g_glutContext; | ||
#elif _WIN32 | ||
#else | ||
GLXContext g_context; | ||
Display *g_display; | ||
GLXDrawable g_drawable; | ||
GLXContext g_glutContext; | ||
Display *g_glutDisplay; | ||
GLXDrawable g_glutDrawable; | ||
#endif | ||
|
||
double g_offset = 0.0; | ||
|
||
////////////////////////////////////////////////// | ||
void displayCB() | ||
{ | ||
#if __APPLE__ | ||
CGLSetCurrentContext(g_context); | ||
#elif _WIN32 | ||
#else | ||
if (g_display) | ||
{ | ||
glXMakeCurrent(g_display, g_drawable, g_context); | ||
} | ||
#endif | ||
|
||
g_cameras[g_cameraIndex]->Update(); | ||
|
||
#if __APPLE__ | ||
CGLSetCurrentContext(g_glutContext); | ||
#elif _WIN32 | ||
#else | ||
glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext); | ||
#endif | ||
|
||
unsigned char *data = g_image->Data<unsigned char>(); | ||
|
||
glClearColor(0.5, 0.5, 0.5, 1); | ||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
glPixelZoom(1, -1); | ||
glRasterPos2f(-1, 1); | ||
glDrawPixels(imgw, imgh, GL_RGB, GL_UNSIGNED_BYTE, data); | ||
|
||
glutSwapBuffers(); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void idleCB() | ||
{ | ||
glutPostRedisplay(); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void keyboardCB(unsigned char _key, int, int) | ||
{ | ||
if (_key == KEY_ESC || _key == 'q' || _key == 'Q') | ||
{ | ||
exit(0); | ||
} | ||
else if (_key == KEY_TAB) | ||
{ | ||
g_cameraIndex = (g_cameraIndex + 1) % g_cameras.size(); | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void OnNewWideAngleFrame(const void *_data, | ||
unsigned int _width, unsigned int _height, | ||
unsigned int _channels, | ||
const std::string &/*_format*/) | ||
{ | ||
unsigned char *data = g_image->Data<unsigned char>(); | ||
memcpy(data, _data,_width * _height * _channels); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void initCamera(ir::CameraPtr _camera) | ||
{ | ||
g_camera = _camera; | ||
imgw = g_camera->ImageWidth(); | ||
imgh = g_camera->ImageHeight(); | ||
ir::Image image = g_camera->CreateImage(); | ||
g_image = std::make_shared<ir::Image>(image); | ||
|
||
ir::WideAngleCameraPtr wideAngleCamera = | ||
std::dynamic_pointer_cast<ir::WideAngleCamera>( | ||
g_camera); | ||
|
||
// connect to new image event | ||
g_connection = wideAngleCamera->ConnectNewWideAngleFrame( | ||
std::bind(OnNewWideAngleFrame, | ||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, | ||
std::placeholders::_4, std::placeholders::_5)); | ||
|
||
// update the camera once | ||
g_camera->Update(); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void initContext() | ||
{ | ||
glutInitDisplayMode(GLUT_DOUBLE); | ||
glutInitWindowPosition(0, 0); | ||
glutInitWindowSize(imgw, imgh); | ||
glutCreateWindow("Wide Angle Camera"); | ||
glutDisplayFunc(displayCB); | ||
glutIdleFunc(idleCB); | ||
glutKeyboardFunc(keyboardCB); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void printUsage() | ||
{ | ||
std::cout << "===============================" << std::endl; | ||
std::cout << " TAB - Switch render engines " << std::endl; | ||
std::cout << " ESC - Exit " << std::endl; | ||
std::cout << "===============================" << std::endl; | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void run(std::vector<ir::CameraPtr> _cameras) | ||
{ | ||
if (_cameras.empty()) | ||
{ | ||
ignerr << "No cameras found. Scene will not be rendered" << std::endl; | ||
return; | ||
} | ||
|
||
#if __APPLE__ | ||
g_context = CGLGetCurrentContext(); | ||
#elif _WIN32 | ||
#else | ||
g_context = glXGetCurrentContext(); | ||
g_display = glXGetCurrentDisplay(); | ||
g_drawable = glXGetCurrentDrawable(); | ||
#endif | ||
|
||
g_cameras = _cameras; | ||
initCamera(_cameras[0]); | ||
initContext(); | ||
printUsage(); | ||
|
||
#if __APPLE__ | ||
g_glutContext = CGLGetCurrentContext(); | ||
#elif _WIN32 | ||
#else | ||
g_glutDisplay = glXGetCurrentDisplay(); | ||
g_glutDrawable = glXGetCurrentDrawable(); | ||
g_glutContext = glXGetCurrentContext(); | ||
#endif | ||
|
||
glutMainLoop(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
#ifndef IGNITION_RENDERING_EXAMPLES_WIDE_ANGLE_CAMERA_GLUTWINDOW_HH_ | ||
#define IGNITION_RENDERING_EXAMPLES_WIDE_ANGLE_CAMERA_GLUTWINDOW_HH_ | ||
|
||
#include <vector> | ||
#include "ignition/rendering/RenderTypes.hh" | ||
|
||
namespace ir = ignition::rendering; | ||
|
||
/// \brief Run the demo and render the scene from the cameras | ||
/// \param[in] _cameras Cameras in the scene | ||
void run(std::vector<ir::CameraPtr> _cameras); | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.