raw
This commit is contained in:
55
.gitignore
vendored
Normal file
55
.gitignore
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
CMakeLists.txt.user
|
||||
CMakeLists_modified.txt
|
||||
|
||||
Examples/
|
||||
evaluation/
|
||||
|
||||
Examples/RGB-D/rgbd_tum
|
||||
|
||||
Examples/Monocular/mono_euroc
|
||||
Examples/Monocular/mono_kitti
|
||||
Examples/Monocular/mono_tum
|
||||
Examples/Monocular/mono_tum_vi
|
||||
|
||||
Examples/Stereo/stereo_euroc
|
||||
Examples/Stereo/stereo_kitti
|
||||
Examples/Stereo/stereo_tum_vi
|
||||
|
||||
Examples/Monocular-Inertial/mono_inertial_euroc
|
||||
Examples/Monocular-Inertial/mono_inertial_tum_vi
|
||||
|
||||
Examples/Stereo-Inertial/stereo_inertial_euroc
|
||||
Examples/Stereo-Inertial/stereo_inertial_tum_vi
|
||||
|
||||
Examples/ROS/ORB_SLAM3/Mono
|
||||
Examples/ROS/ORB_SLAM3/Mono_Inertial
|
||||
Examples/ROS/ORB_SLAM3/MonoAR
|
||||
Examples/ROS/ORB_SLAM3/RGBD
|
||||
Examples/ROS/ORB_SLAM3/Stereo
|
||||
Examples/ROS/ORB_SLAM3/Stereo_Inertial
|
||||
|
||||
Examples/ROS/ORB_SLAM3/CMakeLists.txt.user
|
||||
Examples/ROS/ORB_SLAM3/build/
|
||||
|
||||
KeyFrameTrajectory.txt
|
||||
CameraTrajectory.txt
|
||||
kf_*.txt
|
||||
f_*.txt
|
||||
Thirdparty/DBoW2/build/
|
||||
Thirdparty/DBoW2/lib/
|
||||
Thirdparty/g2o/build/
|
||||
Thirdparty/g2o/config.h
|
||||
Thirdparty/g2o/lib/
|
||||
|
||||
Thirdparty/Pangolin/build/
|
||||
Thirdparty/Pangolin/vcpkg/
|
||||
Thirdparty/Pangolin/CMakeModules/
|
||||
|
||||
Vocabulary/ORBvoc.txt.tar.gz
|
||||
build/
|
||||
|
||||
cmake_modules/
|
||||
cmake-build-debug/
|
||||
|
||||
*.pyc
|
||||
*.osa
|
||||
210
CMakeLists.txt
Normal file
210
CMakeLists.txt
Normal file
@@ -0,0 +1,210 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(ORB_SLAM3)
|
||||
|
||||
IF(NOT CMAKE_BUILD_TYPE)
|
||||
SET(CMAKE_BUILD_TYPE Release)
|
||||
ENDIF()
|
||||
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
|
||||
|
||||
MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
|
||||
|
||||
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-deprecated -O3 -march=native ")
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-deprecated -O3 -march=native")
|
||||
|
||||
# Check C++11 or C++0x support
|
||||
if(MSVC)
|
||||
message(MSVC_VERSION "Using MSVC, Skipping std=c++11 support...")
|
||||
else()
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
add_definitions(-DCOMPILEDWITHC11)
|
||||
message(STATUS "Using flag -std=c++11.")
|
||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
add_definitions(-DCOMPILEDWITHC0X)
|
||||
message(STATUS "Using flag -std=c++0x.")
|
||||
else()
|
||||
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
|
||||
|
||||
set(OpenCV_DIR C:/OpenCV3/build)
|
||||
set(Boost_INCLUDE_DIR C:/Users/ivan/Source/Repos/ORB-SLAM3forWindows/Thirdparty/boost_1_77_0/)
|
||||
# set(Boost_LIB_DIR C:/Users/ivan/Source/Repos/ORB-SLAM3forWindows/Thirdparty/boost_1_77_0/stage/lib)
|
||||
|
||||
|
||||
find_package(OpenCV 3.4.16)
|
||||
if(NOT OpenCV_FOUND)
|
||||
find_package(OpenCV 3.0 REQUIRED C:/OpenCV3/build/x64/vc15/lib)
|
||||
if(NOT OpenCV_FOUND)
|
||||
message(FATAL_ERROR "OpenCV > 3.0 not found.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
MESSAGE("OPENCV VERSION:")
|
||||
MESSAGE(${OpenCV_VERSION})
|
||||
|
||||
find_package(Eigen3 3.1.0 REQUIRED)
|
||||
find_package(Pangolin REQUIRED)
|
||||
find_package(Boost)
|
||||
find_package(realsense2)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/include/CameraModels
|
||||
${EIGEN3_INCLUDE_DIR}
|
||||
${Pangolin_INCLUDE_DIRS}
|
||||
${Boost_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
src/System.cc
|
||||
src/Tracking.cc
|
||||
src/LocalMapping.cc
|
||||
src/LoopClosing.cc
|
||||
src/ORBextractor.cc
|
||||
src/ORBmatcher.cc
|
||||
src/FrameDrawer.cc
|
||||
src/Converter.cc
|
||||
src/MapPoint.cc
|
||||
src/KeyFrame.cc
|
||||
src/Atlas.cc
|
||||
src/Map.cc
|
||||
src/MapDrawer.cc
|
||||
src/Optimizer.cc
|
||||
src/Frame.cc
|
||||
src/KeyFrameDatabase.cc
|
||||
src/Sim3Solver.cc
|
||||
src/Initializer.cc
|
||||
src/Viewer.cc
|
||||
src/ImuTypes.cc
|
||||
src/G2oTypes.cc
|
||||
src/CameraModels/Pinhole.cpp
|
||||
src/CameraModels/KannalaBrandt8.cpp
|
||||
src/OptimizableTypes.cpp
|
||||
src/MLPnPsolver.cpp
|
||||
src/TwoViewReconstruction.cc
|
||||
include/System.h
|
||||
include/Tracking.h
|
||||
include/LocalMapping.h
|
||||
include/LoopClosing.h
|
||||
include/ORBextractor.h
|
||||
include/ORBmatcher.h
|
||||
include/FrameDrawer.h
|
||||
include/Converter.h
|
||||
include/MapPoint.h
|
||||
include/KeyFrame.h
|
||||
include/Atlas.h
|
||||
include/Map.h
|
||||
include/MapDrawer.h
|
||||
include/Optimizer.h
|
||||
include/Frame.h
|
||||
include/KeyFrameDatabase.h
|
||||
include/Sim3Solver.h
|
||||
include/Initializer.h
|
||||
include/Viewer.h
|
||||
include/ImuTypes.h
|
||||
include/G2oTypes.h
|
||||
include/CameraModels/GeometricCamera.h
|
||||
include/CameraModels/Pinhole.h
|
||||
include/CameraModels/KannalaBrandt8.h
|
||||
include/OptimizableTypes.h
|
||||
include/MLPnPsolver.h
|
||||
include/TwoViewReconstruction.h
|
||||
include/Config.h
|
||||
)
|
||||
|
||||
add_subdirectory(Thirdparty/g2o)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${OpenCV_LIBS}
|
||||
${EIGEN3_LIBS}
|
||||
${Pangolin_LIBRARIES}
|
||||
${Boost_LIBS}
|
||||
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
|
||||
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
|
||||
-lboost_serialization
|
||||
-lcrypto
|
||||
)
|
||||
|
||||
|
||||
### Build examples
|
||||
|
||||
# RGB-D examples
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D)
|
||||
|
||||
add_executable(rgbd_tum
|
||||
Examples/RGB-D/rgbd_tum.cc)
|
||||
target_link_libraries(rgbd_tum ${PROJECT_NAME})
|
||||
|
||||
|
||||
# Stereo examples
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo)
|
||||
|
||||
add_executable(stereo_kitti
|
||||
Examples/Stereo/stereo_kitti.cc)
|
||||
target_link_libraries(stereo_kitti ${PROJECT_NAME})
|
||||
|
||||
add_executable(stereo_euroc
|
||||
Examples/Stereo/stereo_euroc.cc)
|
||||
target_link_libraries(stereo_euroc ${PROJECT_NAME})
|
||||
|
||||
add_executable(stereo_tum_vi
|
||||
Examples/Stereo/stereo_tum_vi.cc)
|
||||
target_link_libraries(stereo_tum_vi ${PROJECT_NAME})
|
||||
|
||||
# Monocular examples
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)
|
||||
|
||||
add_executable(mono_tum
|
||||
Examples/Monocular/mono_tum.cc)
|
||||
target_link_libraries(mono_tum ${PROJECT_NAME})
|
||||
|
||||
add_executable(mono_kitti
|
||||
Examples/Monocular/mono_kitti.cc)
|
||||
target_link_libraries(mono_kitti ${PROJECT_NAME})
|
||||
|
||||
add_executable(mono_euroc
|
||||
Examples/Monocular/mono_euroc.cc)
|
||||
target_link_libraries(mono_euroc ${PROJECT_NAME})
|
||||
|
||||
add_executable(mono_tum_vi
|
||||
Examples/Monocular/mono_tum_vi.cc)
|
||||
target_link_libraries(mono_tum_vi ${PROJECT_NAME})
|
||||
|
||||
# Monocular-Inertial examples
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular-Inertial)
|
||||
|
||||
add_executable(mono_inertial_euroc
|
||||
Examples/Monocular-Inertial/mono_inertial_euroc.cc)
|
||||
target_link_libraries(mono_inertial_euroc ${PROJECT_NAME})
|
||||
|
||||
add_executable(mono_inertial_tum_vi
|
||||
Examples/Monocular-Inertial/mono_inertial_tum_vi.cc)
|
||||
target_link_libraries(mono_inertial_tum_vi ${PROJECT_NAME})
|
||||
|
||||
# Stereo-Inertial examples
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo-Inertial)
|
||||
|
||||
add_executable(stereo_inertial_euroc
|
||||
Examples/Stereo-Inertial/stereo_inertial_euroc.cc)
|
||||
target_link_libraries(stereo_inertial_euroc ${PROJECT_NAME})
|
||||
|
||||
add_executable(stereo_inertial_tum_vi
|
||||
Examples/Stereo-Inertial/stereo_inertial_tum_vi.cc)
|
||||
target_link_libraries(stereo_inertial_tum_vi ${PROJECT_NAME})
|
||||
|
||||
37
Changelog.md
Normal file
37
Changelog.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# ORB-SLAM3
|
||||
Details of changes between the different versions.
|
||||
|
||||
### V0.4: Beta version, 21 April 2021
|
||||
|
||||
- Changed OpenCV dynamic matrices to static matrices to speed up the code.
|
||||
|
||||
- Capability to measure running time of the system threads.
|
||||
|
||||
- Compatibility with OpenCV 4.0 (Requires at least OpenCV 3.0)
|
||||
|
||||
- Fixed minor bugs.
|
||||
|
||||
|
||||
### V0.3: Beta version, 4 Sep 2020
|
||||
|
||||
- RGB-D compatibility, the RGB-D examples have been adapted to the new version.
|
||||
|
||||
- Kitti and TUM dataset compatibility, these examples have been adapted to the new version.
|
||||
|
||||
- ROS compatibility, updated the old references in the code to work with this version.
|
||||
|
||||
- Config file parser, the YAML file contains the session configuration, a wrong parametrization may break the execution without any information to solve it. This version parses the file to read all the fields and give a proper answer if one of the fields have been wrongly deffined or does not exist.
|
||||
|
||||
- Fixed minor bugs.
|
||||
|
||||
|
||||
### V0.2: Beta version, 7 Aug 2020
|
||||
Initial release. It has these capabilities:
|
||||
|
||||
- Multiple-Maps capabilities, it is able to handle multiple maps in the same session and merge them when a common area is detected with a seamless fussion.
|
||||
|
||||
- Inertial sensor, the IMU initialization takes 2 seconds to achieve a scale error less than 5\% and it is reffined in the next 10 seconds until it is around 1\%. Inertial measures are integrated at frame rate to estimate the scale, gravity and velocity in order to improve the visual features detection and make the system robust to temporal occlusions.
|
||||
|
||||
- Fisheye sensor, the fisheye sensors are now fully supported in monocular and stereo.
|
||||
|
||||
|
||||
48
Dependencies.md
Normal file
48
Dependencies.md
Normal file
@@ -0,0 +1,48 @@
|
||||
##List of Known Dependencies
|
||||
###ORB-SLAM3 version 0.3
|
||||
|
||||
In this document we list all the pieces of code included by ORB-SLAM3 and linked libraries which are not property of the authors of ORB-SLAM3.
|
||||
|
||||
|
||||
#####Code in **src** and **include** folders
|
||||
|
||||
* *ORBextractor.cc*.
|
||||
This is a modified version of orb.cpp of OpenCV library. The original code is BSD licensed.
|
||||
|
||||
* *PnPsolver.h, PnPsolver.cc*.
|
||||
This is a modified version of the epnp.h and epnp.cc of Vincent Lepetit.
|
||||
This code can be found in popular BSD licensed computer vision libraries as [OpenCV](https://github.com/Itseez/opencv/blob/master/modules/calib3d/src/epnp.cpp) and [OpenGV](https://github.com/laurentkneip/opengv/blob/master/src/absolute_pose/modules/Epnp.cpp). The original code is FreeBSD.
|
||||
|
||||
* *MLPnPsolver.h, MLPnPsolver.cc*.
|
||||
This is a modified version of the MLPnP of Steffen Urban from [here](https://github.com/urbste/opengv).
|
||||
The original code is BSD licensed.
|
||||
|
||||
* Function *ORBmatcher::DescriptorDistance* in *ORBmatcher.cc*.
|
||||
The code is from: http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel.
|
||||
The code is in the public domain.
|
||||
|
||||
#####Code in Thirdparty folder
|
||||
|
||||
* All code in **DBoW2** folder.
|
||||
This is a modified version of [DBoW2](https://github.com/dorian3d/DBoW2) and [DLib](https://github.com/dorian3d/DLib) library. All files included are BSD licensed.
|
||||
|
||||
* All code in **g2o** folder.
|
||||
This is a modified version of [g2o](https://github.com/RainerKuemmerle/g2o). All files included are BSD licensed.
|
||||
|
||||
#####Library dependencies
|
||||
|
||||
* **Pangolin (visualization and user interface)**.
|
||||
[MIT license](https://en.wikipedia.org/wiki/MIT_License).
|
||||
|
||||
* **OpenCV**.
|
||||
BSD license.
|
||||
|
||||
* **Eigen3**.
|
||||
For versions greater than 3.1.1 is MPL2, earlier versions are LGPLv3.
|
||||
|
||||
* **ROS (Optional, only if you build Examples/ROS)**.
|
||||
BSD license. In the manifest.xml the only declared package dependencies are roscpp, tf, sensor_msgs, image_transport, cv_bridge, which are all BSD licensed.
|
||||
|
||||
|
||||
|
||||
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
214
README.md
Normal file
214
README.md
Normal file
@@ -0,0 +1,214 @@
|
||||
# ORB-SLAM3
|
||||
|
||||
### V0.4: Beta version, 21 April 2021
|
||||
**Authors:** Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, [José M. M. Montiel](http://webdiis.unizar.es/~josemari/), [Juan D. Tardos](http://webdiis.unizar.es/~jdtardos/).
|
||||
|
||||
The [Changelog](https://github.com/UZ-SLAMLab/ORB_SLAM3/blob/master/Changelog.md) describes the features of each version.
|
||||
|
||||
ORB-SLAM3 is the first real-time SLAM library able to perform **Visual, Visual-Inertial and Multi-Map SLAM** with **monocular, stereo and RGB-D** cameras, using **pin-hole and fisheye** lens models. In all sensor configurations, ORB-SLAM3 is as robust as the best systems available in the literature, and significantly more accurate.
|
||||
|
||||
We provide examples to run ORB-SLAM3 in the [EuRoC dataset](http://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets) using stereo or monocular, with or without IMU, and in the [TUM-VI dataset](https://vision.in.tum.de/data/datasets/visual-inertial-dataset) using fisheye stereo or monocular, with or without IMU. Videos of some example executions can be found at [ORB-SLAM3 channel](https://www.youtube.com/channel/UCXVt-kXG6T95Z4tVaYlU80Q).
|
||||
|
||||
This software is based on [ORB-SLAM2](https://github.com/raulmur/ORB_SLAM2) developed by [Raul Mur-Artal](http://webdiis.unizar.es/~raulmur/), [Juan D. Tardos](http://webdiis.unizar.es/~jdtardos/), [J. M. M. Montiel](http://webdiis.unizar.es/~josemari/) and [Dorian Galvez-Lopez](http://doriangalvez.com/) ([DBoW2](https://github.com/dorian3d/DBoW2)).
|
||||
|
||||
<a href="https://youtu.be/HyLNq-98LRo" target="_blank"><img src="https://img.youtube.com/vi/HyLNq-98LRo/0.jpg"
|
||||
alt="ORB-SLAM3" width="240" height="180" border="10" /></a>
|
||||
|
||||
### Related Publications:
|
||||
|
||||
[ORB-SLAM3] Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M. M. Montiel and Juan D. Tardós, **ORB-SLAM3: An Accurate Open-Source Library for Visual, Visual-Inertial and Multi-Map SLAM**, *IEEE Transactions on Robotics, 2021* **[PDF](https://arxiv.org/abs/2007.11898)**.
|
||||
|
||||
[IMU-Initialization] Carlos Campos, J. M. M. Montiel and Juan D. Tardós, **Inertial-Only Optimization for Visual-Inertial Initialization**, *ICRA 2020*. **[PDF](https://arxiv.org/pdf/2003.05766.pdf)**
|
||||
|
||||
[ORBSLAM-Atlas] Richard Elvira, J. M. M. Montiel and Juan D. Tardós, **ORBSLAM-Atlas: a robust and accurate multi-map system**, *IROS 2019*. **[PDF](https://arxiv.org/pdf/1908.11585.pdf)**.
|
||||
|
||||
[ORBSLAM-VI] Raúl Mur-Artal, and Juan D. Tardós, **Visual-inertial monocular SLAM with map reuse**, IEEE Robotics and Automation Letters, vol. 2 no. 2, pp. 796-803, 2017. **[PDF](https://arxiv.org/pdf/1610.05949.pdf)**.
|
||||
|
||||
[Stereo and RGB-D] Raúl Mur-Artal and Juan D. Tardós. **ORB-SLAM2: an Open-Source SLAM System for Monocular, Stereo and RGB-D Cameras**. *IEEE Transactions on Robotics,* vol. 33, no. 5, pp. 1255-1262, 2017. **[PDF](https://arxiv.org/pdf/1610.06475.pdf)**.
|
||||
|
||||
[Monocular] Raúl Mur-Artal, José M. M. Montiel and Juan D. Tardós. **ORB-SLAM: A Versatile and Accurate Monocular SLAM System**. *IEEE Transactions on Robotics,* vol. 31, no. 5, pp. 1147-1163, 2015. (**2015 IEEE Transactions on Robotics Best Paper Award**). **[PDF](https://arxiv.org/pdf/1502.00956.pdf)**.
|
||||
|
||||
[DBoW2 Place Recognition] Dorian Gálvez-López and Juan D. Tardós. **Bags of Binary Words for Fast Place Recognition in Image Sequences**. *IEEE Transactions on Robotics,* vol. 28, no. 5, pp. 1188-1197, 2012. **[PDF](http://doriangalvez.com/php/dl.php?dlp=GalvezTRO12.pdf)**
|
||||
|
||||
# 1. License
|
||||
|
||||
ORB-SLAM3 is released under [GPLv3 license](https://github.com/UZ-SLAMLab/ORB_SLAM3/LICENSE). For a list of all code/library dependencies (and associated licenses), please see [Dependencies.md](https://github.com/UZ-SLAMLab/ORB_SLAM3/blob/master/Dependencies.md).
|
||||
|
||||
For a closed-source version of ORB-SLAM3 for commercial purposes, please contact the authors: orbslam (at) unizar (dot) es.
|
||||
|
||||
If you use ORB-SLAM3 in an academic work, please cite:
|
||||
|
||||
@article{ORBSLAM3_2020,
|
||||
title={{ORB-SLAM3}: An Accurate Open-Source Library for Visual, Visual-Inertial
|
||||
and Multi-Map {SLAM}},
|
||||
author={Campos, Carlos AND Elvira, Richard AND G\´omez, Juan J. AND Montiel,
|
||||
Jos\'e M. M. AND Tard\'os, Juan D.},
|
||||
journal={arXiv preprint arXiv:2007.11898},
|
||||
year={2020}
|
||||
}
|
||||
|
||||
# 2. Prerequisites
|
||||
We have tested the library in **Ubuntu 16.04** and **18.04**, but it should be easy to compile in other platforms. A powerful computer (e.g. i7) will ensure real-time performance and provide more stable and accurate results.
|
||||
|
||||
## C++11 or C++0x Compiler
|
||||
We use the new thread and chrono functionalities of C++11.
|
||||
|
||||
## Pangolin
|
||||
We use [Pangolin](https://github.com/stevenlovegrove/Pangolin) for visualization and user interface. Dowload and install instructions can be found at: https://github.com/stevenlovegrove/Pangolin.
|
||||
|
||||
## OpenCV
|
||||
We use [OpenCV](http://opencv.org) to manipulate images and features. Dowload and install instructions can be found at: http://opencv.org. **Required at leat 3.0. Tested with OpenCV 3.2.0 and 4.4.0**.
|
||||
|
||||
## Eigen3
|
||||
Required by g2o (see below). Download and install instructions can be found at: http://eigen.tuxfamily.org. **Required at least 3.1.0**.
|
||||
|
||||
## DBoW2 and g2o (Included in Thirdparty folder)
|
||||
We use modified versions of the [DBoW2](https://github.com/dorian3d/DBoW2) library to perform place recognition and [g2o](https://github.com/RainerKuemmerle/g2o) library to perform non-linear optimizations. Both modified libraries (which are BSD) are included in the *Thirdparty* folder.
|
||||
|
||||
## Python
|
||||
Required to calculate the alignment of the trajectory with the ground truth. **Required Numpy module**.
|
||||
|
||||
* (win) http://www.python.org/downloads/windows
|
||||
* (deb) `sudo apt install libpython2.7-dev`
|
||||
* (mac) preinstalled with osx
|
||||
|
||||
## ROS (optional)
|
||||
|
||||
We provide some examples to process input of a monocular, monocular-inertial, stereo, stereo-inertial or RGB-D camera using ROS. Building these examples is optional. These have been tested with ROS Melodic under Ubuntu 18.04.
|
||||
|
||||
# 3. Building ORB-SLAM3 library and examples
|
||||
|
||||
Clone the repository:
|
||||
```
|
||||
git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git ORB_SLAM3
|
||||
```
|
||||
|
||||
We provide a script `build.sh` to build the *Thirdparty* libraries and *ORB-SLAM3*. Please make sure you have installed all required dependencies (see section 2). Execute:
|
||||
```
|
||||
cd ORB_SLAM3
|
||||
chmod +x build.sh
|
||||
./build.sh
|
||||
```
|
||||
|
||||
This will create **libORB_SLAM3.so** at *lib* folder and the executables in *Examples* folder.
|
||||
|
||||
# 4. EuRoC Examples
|
||||
[EuRoC dataset](http://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets) was recorded with two pinhole cameras and an inertial sensor. We provide an example script to launch EuRoC sequences in all the sensor configurations.
|
||||
|
||||
1. Download a sequence (ASL format) from http://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets
|
||||
|
||||
2. Open the script "euroc_examples.sh" in the root of the project. Change **pathDatasetEuroc** variable to point to the directory where the dataset has been uncompressed.
|
||||
|
||||
3. Execute the following script to process all the sequences with all sensor configurations:
|
||||
```
|
||||
./euroc_examples
|
||||
```
|
||||
|
||||
## Evaluation
|
||||
EuRoC provides ground truth for each sequence in the IMU body reference. As pure visual executions report trajectories centered in the left camera, we provide in the "evaluation" folder the transformation of the ground truth to the left camera reference. Visual-inertial trajectories use the ground truth from the dataset.
|
||||
|
||||
Execute the following script to process sequences and compute the RMS ATE:
|
||||
```
|
||||
./euroc_eval_examples
|
||||
```
|
||||
|
||||
# 5. TUM-VI Examples
|
||||
[TUM-VI dataset](https://vision.in.tum.de/data/datasets/visual-inertial-dataset) was recorded with two fisheye cameras and an inertial sensor.
|
||||
|
||||
1. Download a sequence from https://vision.in.tum.de/data/datasets/visual-inertial-dataset and uncompress it.
|
||||
|
||||
2. Open the script "tum_vi_examples.sh" in the root of the project. Change **pathDatasetTUM_VI** variable to point to the directory where the dataset has been uncompressed.
|
||||
|
||||
3. Execute the following script to process all the sequences with all sensor configurations:
|
||||
```
|
||||
./tum_vi_examples
|
||||
```
|
||||
|
||||
## Evaluation
|
||||
In TUM-VI ground truth is only available in the room where all sequences start and end. As a result the error measures the drift at the end of the sequence.
|
||||
|
||||
Execute the following script to process sequences and compute the RMS ATE:
|
||||
```
|
||||
./tum_vi_eval_examples
|
||||
```
|
||||
|
||||
# 6. ROS Examples
|
||||
|
||||
### Building the nodes for mono, mono-inertial, stereo, stereo-inertial and RGB-D
|
||||
Tested with ROS Melodic and ubuntu 18.04.
|
||||
|
||||
1. Add the path including *Examples/ROS/ORB_SLAM3* to the ROS_PACKAGE_PATH environment variable. Open .bashrc file:
|
||||
```
|
||||
gedit ~/.bashrc
|
||||
```
|
||||
and add at the end the following line. Replace PATH by the folder where you cloned ORB_SLAM3:
|
||||
|
||||
```
|
||||
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM3/Examples/ROS
|
||||
```
|
||||
|
||||
2. Execute `build_ros.sh` script:
|
||||
|
||||
```
|
||||
chmod +x build_ros.sh
|
||||
./build_ros.sh
|
||||
```
|
||||
|
||||
### Running Monocular Node
|
||||
For a monocular input from topic `/camera/image_raw` run node ORB_SLAM3/Mono. You will need to provide the vocabulary file and a settings file. See the monocular examples above.
|
||||
|
||||
```
|
||||
rosrun ORB_SLAM3 Mono PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE
|
||||
```
|
||||
|
||||
### Running Monocular-Inertial Node
|
||||
For a monocular input from topic `/camera/image_raw` and an inertial input from topic `/imu`, run node ORB_SLAM3/Mono_Inertial. Setting the optional third argument to true will apply CLAHE equalization to images (Mainly for TUM-VI dataset).
|
||||
|
||||
```
|
||||
rosrun ORB_SLAM3 Mono PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE [EQUALIZATION]
|
||||
```
|
||||
|
||||
### Running Stereo Node
|
||||
For a stereo input from topic `/camera/left/image_raw` and `/camera/right/image_raw` run node ORB_SLAM3/Stereo. You will need to provide the vocabulary file and a settings file. For Pinhole camera model, if you **provide rectification matrices** (see Examples/Stereo/EuRoC.yaml example), the node will recitify the images online, **otherwise images must be pre-rectified**. For FishEye camera model, rectification is not required since system works with original images:
|
||||
|
||||
```
|
||||
rosrun ORB_SLAM3 Stereo PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE ONLINE_RECTIFICATION
|
||||
```
|
||||
|
||||
### Running Stereo-Inertial Node
|
||||
For a stereo input from topics `/camera/left/image_raw` and `/camera/right/image_raw`, and an inertial input from topic `/imu`, run node ORB_SLAM3/Stereo_Inertial. You will need to provide the vocabulary file and a settings file, including rectification matrices if required in a similar way to Stereo case:
|
||||
|
||||
```
|
||||
rosrun ORB_SLAM3 Stereo_Inertial PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE ONLINE_RECTIFICATION [EQUALIZATION]
|
||||
```
|
||||
|
||||
### Running RGB_D Node
|
||||
For an RGB-D input from topics `/camera/rgb/image_raw` and `/camera/depth_registered/image_raw`, run node ORB_SLAM3/RGBD. You will need to provide the vocabulary file and a settings file. See the RGB-D example above.
|
||||
|
||||
```
|
||||
rosrun ORB_SLAM3 RGBD PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE
|
||||
```
|
||||
|
||||
**Running ROS example:** Download a rosbag (e.g. V1_02_medium.bag) from the EuRoC dataset (http://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets). Open 3 tabs on the terminal and run the following command at each tab for a Stereo-Inertial configuration:
|
||||
```
|
||||
roscore
|
||||
```
|
||||
|
||||
```
|
||||
rosrun ORB_SLAM3 Stereo_Inertial Vocabulary/ORBvoc.txt Examples/Stereo-Inertial/EuRoC.yaml true
|
||||
```
|
||||
|
||||
```
|
||||
rosbag play --pause V1_02_medium.bag /cam0/image_raw:=/camera/left/image_raw /cam1/image_raw:=/camera/right/image_raw /imu0:=/imu
|
||||
```
|
||||
|
||||
Once ORB-SLAM3 has loaded the vocabulary, press space in the rosbag tab.
|
||||
|
||||
**Remark:** For rosbags from TUM-VI dataset, some play issue may appear due to chunk size. One possible solution is to rebag them with the default chunk size, for example:
|
||||
```
|
||||
rosrun rosbag fastrebag.py dataset-room1_512_16.bag dataset-room1_512_16_small_chunks.bag
|
||||
```
|
||||
|
||||
# 7. Running time analysis
|
||||
A flag in `include\Config.h` activates time measurements. It is necessary to uncomment the line `#define REGISTER_TIMES` to obtain the time stats of one execution which is shown at the terminal and stored in a text file(`ExecTimeMean.txt`).
|
||||
|
||||
40
Thirdparty/DBoW2/CMakeLists.txt
vendored
Normal file
40
Thirdparty/DBoW2/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(DBoW2)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")
|
||||
|
||||
set(HDRS_DBOW2
|
||||
DBoW2/BowVector.h
|
||||
DBoW2/FORB.h
|
||||
DBoW2/FClass.h
|
||||
DBoW2/FeatureVector.h
|
||||
DBoW2/ScoringObject.h
|
||||
DBoW2/TemplatedVocabulary.h)
|
||||
set(SRCS_DBOW2
|
||||
DBoW2/BowVector.cpp
|
||||
DBoW2/FORB.cpp
|
||||
DBoW2/FeatureVector.cpp
|
||||
DBoW2/ScoringObject.cpp)
|
||||
|
||||
set(HDRS_DUTILS
|
||||
DUtils/Random.h
|
||||
DUtils/Timestamp.h)
|
||||
set(SRCS_DUTILS
|
||||
DUtils/Random.cpp
|
||||
DUtils/Timestamp.cpp)
|
||||
|
||||
find_package(OpenCV 4.0 QUIET)
|
||||
if(NOT OpenCV_FOUND)
|
||||
find_package(OpenCV 3.0 QUIET)
|
||||
if(NOT OpenCV_FOUND)
|
||||
message(FATAL_ERROR "OpenCV > 3.0 not found.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
||||
|
||||
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||
add_library(DBoW2 SHARED ${SRCS_DBOW2} ${SRCS_DUTILS})
|
||||
target_link_libraries(DBoW2 ${OpenCV_LIBS})
|
||||
|
||||
130
Thirdparty/DBoW2/DBoW2/BowVector.cpp
vendored
Normal file
130
Thirdparty/DBoW2/DBoW2/BowVector.cpp
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* File: BowVector.cpp
|
||||
* Date: March 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: bag of words vector
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "BowVector.h"
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
BowVector::BowVector(void)
|
||||
{
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
BowVector::~BowVector(void)
|
||||
{
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void BowVector::addWeight(WordId id, WordValue v)
|
||||
{
|
||||
BowVector::iterator vit = this->lower_bound(id);
|
||||
|
||||
if(vit != this->end() && !(this->key_comp()(id, vit->first)))
|
||||
{
|
||||
vit->second += v;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->insert(vit, BowVector::value_type(id, v));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void BowVector::addIfNotExist(WordId id, WordValue v)
|
||||
{
|
||||
BowVector::iterator vit = this->lower_bound(id);
|
||||
|
||||
if(vit == this->end() || (this->key_comp()(id, vit->first)))
|
||||
{
|
||||
this->insert(vit, BowVector::value_type(id, v));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void BowVector::normalize(LNorm norm_type)
|
||||
{
|
||||
double norm = 0.0;
|
||||
BowVector::iterator it;
|
||||
|
||||
if(norm_type == DBoW2::L1)
|
||||
{
|
||||
for(it = begin(); it != end(); ++it)
|
||||
norm += fabs(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(it = begin(); it != end(); ++it)
|
||||
norm += it->second * it->second;
|
||||
norm = sqrt(norm);
|
||||
}
|
||||
|
||||
if(norm > 0.0)
|
||||
{
|
||||
for(it = begin(); it != end(); ++it)
|
||||
it->second /= norm;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
std::ostream& operator<< (std::ostream &out, const BowVector &v)
|
||||
{
|
||||
BowVector::const_iterator vit;
|
||||
std::vector<unsigned int>::const_iterator iit;
|
||||
unsigned int i = 0;
|
||||
const unsigned int N = v.size();
|
||||
for(vit = v.begin(); vit != v.end(); ++vit, ++i)
|
||||
{
|
||||
out << "<" << vit->first << ", " << vit->second << ">";
|
||||
|
||||
if(i < N-1) out << ", ";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void BowVector::saveM(const std::string &filename, size_t W) const
|
||||
{
|
||||
std::fstream f(filename.c_str(), std::ios::out);
|
||||
|
||||
WordId last = 0;
|
||||
BowVector::const_iterator bit;
|
||||
for(bit = this->begin(); bit != this->end(); ++bit)
|
||||
{
|
||||
for(; last < bit->first; ++last)
|
||||
{
|
||||
f << "0 ";
|
||||
}
|
||||
f << bit->second << " ";
|
||||
|
||||
last = bit->first + 1;
|
||||
}
|
||||
for(; last < (WordId)W; ++last)
|
||||
f << "0 ";
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
119
Thirdparty/DBoW2/DBoW2/BowVector.h
vendored
Normal file
119
Thirdparty/DBoW2/DBoW2/BowVector.h
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* File: BowVector.h
|
||||
* Date: March 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: bag of words vector
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __D_T_BOW_VECTOR__
|
||||
#define __D_T_BOW_VECTOR__
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
/// Id of words
|
||||
typedef unsigned int WordId;
|
||||
|
||||
/// Value of a word
|
||||
typedef double WordValue;
|
||||
|
||||
/// Id of nodes in the vocabulary treee
|
||||
typedef unsigned int NodeId;
|
||||
|
||||
/// L-norms for normalization
|
||||
enum LNorm
|
||||
{
|
||||
L1,
|
||||
L2
|
||||
};
|
||||
|
||||
/// Weighting type
|
||||
enum WeightingType
|
||||
{
|
||||
TF_IDF,
|
||||
TF,
|
||||
IDF,
|
||||
BINARY
|
||||
};
|
||||
|
||||
/// Scoring type
|
||||
enum ScoringType
|
||||
{
|
||||
L1_NORM,
|
||||
L2_NORM,
|
||||
CHI_SQUARE,
|
||||
KL,
|
||||
BHATTACHARYYA,
|
||||
DOT_PRODUCT,
|
||||
};
|
||||
|
||||
/// Vector of words to represent images
|
||||
class BowVector:
|
||||
public std::map<WordId, WordValue>
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar, const int version)
|
||||
{
|
||||
ar & boost::serialization::base_object<std::map<WordId, WordValue> >(*this);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
BowVector(void);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~BowVector(void);
|
||||
|
||||
/**
|
||||
* Adds a value to a word value existing in the vector, or creates a new
|
||||
* word with the given value
|
||||
* @param id word id to look for
|
||||
* @param v value to create the word with, or to add to existing word
|
||||
*/
|
||||
void addWeight(WordId id, WordValue v);
|
||||
|
||||
/**
|
||||
* Adds a word with a value to the vector only if this does not exist yet
|
||||
* @param id word id to look for
|
||||
* @param v value to give to the word if this does not exist
|
||||
*/
|
||||
void addIfNotExist(WordId id, WordValue v);
|
||||
|
||||
/**
|
||||
* L1-Normalizes the values in the vector
|
||||
* @param norm_type norm used
|
||||
*/
|
||||
void normalize(LNorm norm_type);
|
||||
|
||||
/**
|
||||
* Prints the content of the bow vector
|
||||
* @param out stream
|
||||
* @param v
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream &out, const BowVector &v);
|
||||
|
||||
/**
|
||||
* Saves the bow vector as a vector in a matlab file
|
||||
* @param filename
|
||||
* @param W number of words in the vocabulary
|
||||
*/
|
||||
void saveM(const std::string &filename, size_t W) const;
|
||||
};
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
#endif
|
||||
71
Thirdparty/DBoW2/DBoW2/FClass.h
vendored
Normal file
71
Thirdparty/DBoW2/DBoW2/FClass.h
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* File: FClass.h
|
||||
* Date: November 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: generic FClass to instantiate templated classes
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __D_T_FCLASS__
|
||||
#define __D_T_FCLASS__
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
/// Generic class to encapsulate functions to manage descriptors.
|
||||
/**
|
||||
* This class must be inherited. Derived classes can be used as the
|
||||
* parameter F when creating Templated structures
|
||||
* (TemplatedVocabulary, TemplatedDatabase, ...)
|
||||
*/
|
||||
class FClass
|
||||
{
|
||||
class TDescriptor;
|
||||
typedef const TDescriptor *pDescriptor;
|
||||
|
||||
/**
|
||||
* Calculates the mean value of a set of descriptors
|
||||
* @param descriptors
|
||||
* @param mean mean descriptor
|
||||
*/
|
||||
virtual void meanValue(const std::vector<pDescriptor> &descriptors,
|
||||
TDescriptor &mean) = 0;
|
||||
|
||||
/**
|
||||
* Calculates the distance between two descriptors
|
||||
* @param a
|
||||
* @param b
|
||||
* @return distance
|
||||
*/
|
||||
static double distance(const TDescriptor &a, const TDescriptor &b);
|
||||
|
||||
/**
|
||||
* Returns a string version of the descriptor
|
||||
* @param a descriptor
|
||||
* @return string version
|
||||
*/
|
||||
static std::string toString(const TDescriptor &a);
|
||||
|
||||
/**
|
||||
* Returns a descriptor from a string
|
||||
* @param a descriptor
|
||||
* @param s string version
|
||||
*/
|
||||
static void fromString(TDescriptor &a, const std::string &s);
|
||||
|
||||
/**
|
||||
* Returns a mat with the descriptors in float format
|
||||
* @param descriptors
|
||||
* @param mat (out) NxL 32F matrix
|
||||
*/
|
||||
static void toMat32F(const std::vector<TDescriptor> &descriptors,
|
||||
cv::Mat &mat);
|
||||
};
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
#endif
|
||||
193
Thirdparty/DBoW2/DBoW2/FORB.cpp
vendored
Normal file
193
Thirdparty/DBoW2/DBoW2/FORB.cpp
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* File: FORB.cpp
|
||||
* Date: June 2012
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: functions for ORB descriptors
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
* Distance function has been modified
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FORB.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
const int FORB::L=32;
|
||||
|
||||
void FORB::meanValue(const std::vector<FORB::pDescriptor> &descriptors,
|
||||
FORB::TDescriptor &mean)
|
||||
{
|
||||
if(descriptors.empty())
|
||||
{
|
||||
mean.release();
|
||||
return;
|
||||
}
|
||||
else if(descriptors.size() == 1)
|
||||
{
|
||||
mean = descriptors[0]->clone();
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<int> sum(FORB::L * 8, 0);
|
||||
|
||||
for(size_t i = 0; i < descriptors.size(); ++i)
|
||||
{
|
||||
const cv::Mat &d = *descriptors[i];
|
||||
const unsigned char *p = d.ptr<unsigned char>();
|
||||
|
||||
for(int j = 0; j < d.cols; ++j, ++p)
|
||||
{
|
||||
if(*p & (1 << 7)) ++sum[ j*8 ];
|
||||
if(*p & (1 << 6)) ++sum[ j*8 + 1 ];
|
||||
if(*p & (1 << 5)) ++sum[ j*8 + 2 ];
|
||||
if(*p & (1 << 4)) ++sum[ j*8 + 3 ];
|
||||
if(*p & (1 << 3)) ++sum[ j*8 + 4 ];
|
||||
if(*p & (1 << 2)) ++sum[ j*8 + 5 ];
|
||||
if(*p & (1 << 1)) ++sum[ j*8 + 6 ];
|
||||
if(*p & (1)) ++sum[ j*8 + 7 ];
|
||||
}
|
||||
}
|
||||
|
||||
mean = cv::Mat::zeros(1, FORB::L, CV_8U);
|
||||
unsigned char *p = mean.ptr<unsigned char>();
|
||||
|
||||
const int N2 = (int)descriptors.size() / 2 + descriptors.size() % 2;
|
||||
for(size_t i = 0; i < sum.size(); ++i)
|
||||
{
|
||||
if(sum[i] >= N2)
|
||||
{
|
||||
// set bit
|
||||
*p |= 1 << (7 - (i % 8));
|
||||
}
|
||||
|
||||
if(i % 8 == 7) ++p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
int FORB::distance(const FORB::TDescriptor &a,
|
||||
const FORB::TDescriptor &b)
|
||||
{
|
||||
// Bit set count operation from
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||
|
||||
const int *pa = a.ptr<int32_t>();
|
||||
const int *pb = b.ptr<int32_t>();
|
||||
|
||||
int dist=0;
|
||||
|
||||
for(int i=0; i<8; i++, pa++, pb++)
|
||||
{
|
||||
unsigned int v = *pa ^ *pb;
|
||||
v = v - ((v >> 1) & 0x55555555);
|
||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
||||
dist += (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
|
||||
}
|
||||
|
||||
return dist;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
std::string FORB::toString(const FORB::TDescriptor &a)
|
||||
{
|
||||
stringstream ss;
|
||||
const unsigned char *p = a.ptr<unsigned char>();
|
||||
|
||||
for(int i = 0; i < a.cols; ++i, ++p)
|
||||
{
|
||||
ss << (int)*p << " ";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void FORB::fromString(FORB::TDescriptor &a, const std::string &s)
|
||||
{
|
||||
a.create(1, FORB::L, CV_8U);
|
||||
unsigned char *p = a.ptr<unsigned char>();
|
||||
|
||||
stringstream ss(s);
|
||||
for(int i = 0; i < FORB::L; ++i, ++p)
|
||||
{
|
||||
int n;
|
||||
ss >> n;
|
||||
|
||||
if(!ss.fail())
|
||||
*p = (unsigned char)n;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void FORB::toMat32F(const std::vector<TDescriptor> &descriptors,
|
||||
cv::Mat &mat)
|
||||
{
|
||||
if(descriptors.empty())
|
||||
{
|
||||
mat.release();
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t N = descriptors.size();
|
||||
|
||||
mat.create(N, FORB::L*8, CV_32F);
|
||||
float *p = mat.ptr<float>();
|
||||
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
{
|
||||
const int C = descriptors[i].cols;
|
||||
const unsigned char *desc = descriptors[i].ptr<unsigned char>();
|
||||
|
||||
for(int j = 0; j < C; ++j, p += 8)
|
||||
{
|
||||
p[0] = (desc[j] & (1 << 7) ? 1 : 0);
|
||||
p[1] = (desc[j] & (1 << 6) ? 1 : 0);
|
||||
p[2] = (desc[j] & (1 << 5) ? 1 : 0);
|
||||
p[3] = (desc[j] & (1 << 4) ? 1 : 0);
|
||||
p[4] = (desc[j] & (1 << 3) ? 1 : 0);
|
||||
p[5] = (desc[j] & (1 << 2) ? 1 : 0);
|
||||
p[6] = (desc[j] & (1 << 1) ? 1 : 0);
|
||||
p[7] = desc[j] & (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void FORB::toMat8U(const std::vector<TDescriptor> &descriptors,
|
||||
cv::Mat &mat)
|
||||
{
|
||||
mat.create(descriptors.size(), 32, CV_8U);
|
||||
|
||||
unsigned char *p = mat.ptr<unsigned char>();
|
||||
|
||||
for(size_t i = 0; i < descriptors.size(); ++i, p += 32)
|
||||
{
|
||||
const unsigned char *d = descriptors[i].ptr<unsigned char>();
|
||||
std::copy(d, d+32, p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
|
||||
79
Thirdparty/DBoW2/DBoW2/FORB.h
vendored
Normal file
79
Thirdparty/DBoW2/DBoW2/FORB.h
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* File: FORB.h
|
||||
* Date: June 2012
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: functions for ORB descriptors
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __D_T_F_ORB__
|
||||
#define __D_T_F_ORB__
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "FClass.h"
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
/// Functions to manipulate ORB descriptors
|
||||
class FORB: protected FClass
|
||||
{
|
||||
public:
|
||||
|
||||
/// Descriptor type
|
||||
typedef cv::Mat TDescriptor; // CV_8U
|
||||
/// Pointer to a single descriptor
|
||||
typedef const TDescriptor *pDescriptor;
|
||||
/// Descriptor length (in bytes)
|
||||
static const int L;
|
||||
|
||||
/**
|
||||
* Calculates the mean value of a set of descriptors
|
||||
* @param descriptors
|
||||
* @param mean mean descriptor
|
||||
*/
|
||||
static void meanValue(const std::vector<pDescriptor> &descriptors,
|
||||
TDescriptor &mean);
|
||||
|
||||
/**
|
||||
* Calculates the distance between two descriptors
|
||||
* @param a
|
||||
* @param b
|
||||
* @return distance
|
||||
*/
|
||||
static int distance(const TDescriptor &a, const TDescriptor &b);
|
||||
|
||||
/**
|
||||
* Returns a string version of the descriptor
|
||||
* @param a descriptor
|
||||
* @return string version
|
||||
*/
|
||||
static std::string toString(const TDescriptor &a);
|
||||
|
||||
/**
|
||||
* Returns a descriptor from a string
|
||||
* @param a descriptor
|
||||
* @param s string version
|
||||
*/
|
||||
static void fromString(TDescriptor &a, const std::string &s);
|
||||
|
||||
/**
|
||||
* Returns a mat with the descriptors in float format
|
||||
* @param descriptors
|
||||
* @param mat (out) NxL 32F matrix
|
||||
*/
|
||||
static void toMat32F(const std::vector<TDescriptor> &descriptors,
|
||||
cv::Mat &mat);
|
||||
|
||||
static void toMat8U(const std::vector<TDescriptor> &descriptors,
|
||||
cv::Mat &mat);
|
||||
|
||||
};
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
#endif
|
||||
|
||||
85
Thirdparty/DBoW2/DBoW2/FeatureVector.cpp
vendored
Normal file
85
Thirdparty/DBoW2/DBoW2/FeatureVector.cpp
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* File: FeatureVector.cpp
|
||||
* Date: November 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: feature vector
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#include "FeatureVector.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
FeatureVector::FeatureVector(void)
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
FeatureVector::~FeatureVector(void)
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void FeatureVector::addFeature(NodeId id, unsigned int i_feature)
|
||||
{
|
||||
FeatureVector::iterator vit = this->lower_bound(id);
|
||||
|
||||
if(vit != this->end() && vit->first == id)
|
||||
{
|
||||
vit->second.push_back(i_feature);
|
||||
}
|
||||
else
|
||||
{
|
||||
vit = this->insert(vit, FeatureVector::value_type(id,
|
||||
std::vector<unsigned int>() ));
|
||||
vit->second.push_back(i_feature);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
std::ostream& operator<<(std::ostream &out,
|
||||
const FeatureVector &v)
|
||||
{
|
||||
if(!v.empty())
|
||||
{
|
||||
FeatureVector::const_iterator vit = v.begin();
|
||||
|
||||
const std::vector<unsigned int>* f = &vit->second;
|
||||
|
||||
out << "<" << vit->first << ": [";
|
||||
if(!f->empty()) out << (*f)[0];
|
||||
for(unsigned int i = 1; i < f->size(); ++i)
|
||||
{
|
||||
out << ", " << (*f)[i];
|
||||
}
|
||||
out << "]>";
|
||||
|
||||
for(++vit; vit != v.end(); ++vit)
|
||||
{
|
||||
f = &vit->second;
|
||||
|
||||
out << ", <" << vit->first << ": [";
|
||||
if(!f->empty()) out << (*f)[0];
|
||||
for(unsigned int i = 1; i < f->size(); ++i)
|
||||
{
|
||||
out << ", " << (*f)[i];
|
||||
}
|
||||
out << "]>";
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
} // namespace DBoW2
|
||||
66
Thirdparty/DBoW2/DBoW2/FeatureVector.h
vendored
Normal file
66
Thirdparty/DBoW2/DBoW2/FeatureVector.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* File: FeatureVector.h
|
||||
* Date: November 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: feature vector
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __D_T_FEATURE_VECTOR__
|
||||
#define __D_T_FEATURE_VECTOR__
|
||||
|
||||
#include "BowVector.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
/// Vector of nodes with indexes of local features
|
||||
class FeatureVector:
|
||||
public std::map<NodeId, std::vector<unsigned int> >
|
||||
{
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar, const int version)
|
||||
{
|
||||
ar & boost::serialization::base_object<std::map<NodeId, std::vector<unsigned int> > >(*this);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
FeatureVector(void);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~FeatureVector(void);
|
||||
|
||||
/**
|
||||
* Adds a feature to an existing node, or adds a new node with an initial
|
||||
* feature
|
||||
* @param id node id to add or to modify
|
||||
* @param i_feature index of feature to add to the given node
|
||||
*/
|
||||
void addFeature(NodeId id, unsigned int i_feature);
|
||||
|
||||
/**
|
||||
* Sends a string versions of the feature vector through the stream
|
||||
* @param out stream
|
||||
* @param v feature vector
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream &out, const FeatureVector &v);
|
||||
|
||||
};
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
#endif
|
||||
|
||||
315
Thirdparty/DBoW2/DBoW2/ScoringObject.cpp
vendored
Normal file
315
Thirdparty/DBoW2/DBoW2/ScoringObject.cpp
vendored
Normal file
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* File: ScoringObject.cpp
|
||||
* Date: November 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: functions to compute bow scores
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cfloat>
|
||||
#include "TemplatedVocabulary.h"
|
||||
#include "BowVector.h"
|
||||
|
||||
using namespace DBoW2;
|
||||
|
||||
// If you change the type of WordValue, make sure you change also the
|
||||
// epsilon value (this is needed by the KL method)
|
||||
const double GeneralScoring::LOG_EPS = log(DBL_EPSILON); // FLT_EPSILON
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
double L1Scoring::score(const BowVector &v1, const BowVector &v2) const
|
||||
{
|
||||
BowVector::const_iterator v1_it, v2_it;
|
||||
const BowVector::const_iterator v1_end = v1.end();
|
||||
const BowVector::const_iterator v2_end = v2.end();
|
||||
|
||||
v1_it = v1.begin();
|
||||
v2_it = v2.begin();
|
||||
|
||||
double score = 0;
|
||||
|
||||
while(v1_it != v1_end && v2_it != v2_end)
|
||||
{
|
||||
const WordValue& vi = v1_it->second;
|
||||
const WordValue& wi = v2_it->second;
|
||||
|
||||
if(v1_it->first == v2_it->first)
|
||||
{
|
||||
score += fabs(vi - wi) - fabs(vi) - fabs(wi);
|
||||
|
||||
// move v1 and v2 forward
|
||||
++v1_it;
|
||||
++v2_it;
|
||||
}
|
||||
else if(v1_it->first < v2_it->first)
|
||||
{
|
||||
// move v1 forward
|
||||
v1_it = v1.lower_bound(v2_it->first);
|
||||
// v1_it = (first element >= v2_it.id)
|
||||
}
|
||||
else
|
||||
{
|
||||
// move v2 forward
|
||||
v2_it = v2.lower_bound(v1_it->first);
|
||||
// v2_it = (first element >= v1_it.id)
|
||||
}
|
||||
}
|
||||
|
||||
// ||v - w||_{L1} = 2 + Sum(|v_i - w_i| - |v_i| - |w_i|)
|
||||
// for all i | v_i != 0 and w_i != 0
|
||||
// (Nister, 2006)
|
||||
// scaled_||v - w||_{L1} = 1 - 0.5 * ||v - w||_{L1}
|
||||
score = -score/2.0;
|
||||
|
||||
return score; // [0..1]
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
double L2Scoring::score(const BowVector &v1, const BowVector &v2) const
|
||||
{
|
||||
BowVector::const_iterator v1_it, v2_it;
|
||||
const BowVector::const_iterator v1_end = v1.end();
|
||||
const BowVector::const_iterator v2_end = v2.end();
|
||||
|
||||
v1_it = v1.begin();
|
||||
v2_it = v2.begin();
|
||||
|
||||
double score = 0;
|
||||
|
||||
while(v1_it != v1_end && v2_it != v2_end)
|
||||
{
|
||||
const WordValue& vi = v1_it->second;
|
||||
const WordValue& wi = v2_it->second;
|
||||
|
||||
if(v1_it->first == v2_it->first)
|
||||
{
|
||||
score += vi * wi;
|
||||
|
||||
// move v1 and v2 forward
|
||||
++v1_it;
|
||||
++v2_it;
|
||||
}
|
||||
else if(v1_it->first < v2_it->first)
|
||||
{
|
||||
// move v1 forward
|
||||
v1_it = v1.lower_bound(v2_it->first);
|
||||
// v1_it = (first element >= v2_it.id)
|
||||
}
|
||||
else
|
||||
{
|
||||
// move v2 forward
|
||||
v2_it = v2.lower_bound(v1_it->first);
|
||||
// v2_it = (first element >= v1_it.id)
|
||||
}
|
||||
}
|
||||
|
||||
// ||v - w||_{L2} = sqrt( 2 - 2 * Sum(v_i * w_i) )
|
||||
// for all i | v_i != 0 and w_i != 0 )
|
||||
// (Nister, 2006)
|
||||
if(score >= 1) // rounding errors
|
||||
score = 1.0;
|
||||
else
|
||||
score = 1.0 - sqrt(1.0 - score); // [0..1]
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
double ChiSquareScoring::score(const BowVector &v1, const BowVector &v2)
|
||||
const
|
||||
{
|
||||
BowVector::const_iterator v1_it, v2_it;
|
||||
const BowVector::const_iterator v1_end = v1.end();
|
||||
const BowVector::const_iterator v2_end = v2.end();
|
||||
|
||||
v1_it = v1.begin();
|
||||
v2_it = v2.begin();
|
||||
|
||||
double score = 0;
|
||||
|
||||
// all the items are taken into account
|
||||
|
||||
while(v1_it != v1_end && v2_it != v2_end)
|
||||
{
|
||||
const WordValue& vi = v1_it->second;
|
||||
const WordValue& wi = v2_it->second;
|
||||
|
||||
if(v1_it->first == v2_it->first)
|
||||
{
|
||||
// (v-w)^2/(v+w) - v - w = -4 vw/(v+w)
|
||||
// we move the -4 out
|
||||
if(vi + wi != 0.0) score += vi * wi / (vi + wi);
|
||||
|
||||
// move v1 and v2 forward
|
||||
++v1_it;
|
||||
++v2_it;
|
||||
}
|
||||
else if(v1_it->first < v2_it->first)
|
||||
{
|
||||
// move v1 forward
|
||||
v1_it = v1.lower_bound(v2_it->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
// move v2 forward
|
||||
v2_it = v2.lower_bound(v1_it->first);
|
||||
}
|
||||
}
|
||||
|
||||
// this takes the -4 into account
|
||||
score = 2. * score; // [0..1]
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
double KLScoring::score(const BowVector &v1, const BowVector &v2) const
|
||||
{
|
||||
BowVector::const_iterator v1_it, v2_it;
|
||||
const BowVector::const_iterator v1_end = v1.end();
|
||||
const BowVector::const_iterator v2_end = v2.end();
|
||||
|
||||
v1_it = v1.begin();
|
||||
v2_it = v2.begin();
|
||||
|
||||
double score = 0;
|
||||
|
||||
// all the items or v are taken into account
|
||||
|
||||
while(v1_it != v1_end && v2_it != v2_end)
|
||||
{
|
||||
const WordValue& vi = v1_it->second;
|
||||
const WordValue& wi = v2_it->second;
|
||||
|
||||
if(v1_it->first == v2_it->first)
|
||||
{
|
||||
if(vi != 0 && wi != 0) score += vi * log(vi/wi);
|
||||
|
||||
// move v1 and v2 forward
|
||||
++v1_it;
|
||||
++v2_it;
|
||||
}
|
||||
else if(v1_it->first < v2_it->first)
|
||||
{
|
||||
// move v1 forward
|
||||
score += vi * (log(vi) - LOG_EPS);
|
||||
++v1_it;
|
||||
}
|
||||
else
|
||||
{
|
||||
// move v2_it forward, do not add any score
|
||||
v2_it = v2.lower_bound(v1_it->first);
|
||||
// v2_it = (first element >= v1_it.id)
|
||||
}
|
||||
}
|
||||
|
||||
// sum rest of items of v
|
||||
for(; v1_it != v1_end; ++v1_it)
|
||||
if(v1_it->second != 0)
|
||||
score += v1_it->second * (log(v1_it->second) - LOG_EPS);
|
||||
|
||||
return score; // cannot be scaled
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
double BhattacharyyaScoring::score(const BowVector &v1,
|
||||
const BowVector &v2) const
|
||||
{
|
||||
BowVector::const_iterator v1_it, v2_it;
|
||||
const BowVector::const_iterator v1_end = v1.end();
|
||||
const BowVector::const_iterator v2_end = v2.end();
|
||||
|
||||
v1_it = v1.begin();
|
||||
v2_it = v2.begin();
|
||||
|
||||
double score = 0;
|
||||
|
||||
while(v1_it != v1_end && v2_it != v2_end)
|
||||
{
|
||||
const WordValue& vi = v1_it->second;
|
||||
const WordValue& wi = v2_it->second;
|
||||
|
||||
if(v1_it->first == v2_it->first)
|
||||
{
|
||||
score += sqrt(vi * wi);
|
||||
|
||||
// move v1 and v2 forward
|
||||
++v1_it;
|
||||
++v2_it;
|
||||
}
|
||||
else if(v1_it->first < v2_it->first)
|
||||
{
|
||||
// move v1 forward
|
||||
v1_it = v1.lower_bound(v2_it->first);
|
||||
// v1_it = (first element >= v2_it.id)
|
||||
}
|
||||
else
|
||||
{
|
||||
// move v2 forward
|
||||
v2_it = v2.lower_bound(v1_it->first);
|
||||
// v2_it = (first element >= v1_it.id)
|
||||
}
|
||||
}
|
||||
|
||||
return score; // already scaled
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
double DotProductScoring::score(const BowVector &v1,
|
||||
const BowVector &v2) const
|
||||
{
|
||||
BowVector::const_iterator v1_it, v2_it;
|
||||
const BowVector::const_iterator v1_end = v1.end();
|
||||
const BowVector::const_iterator v2_end = v2.end();
|
||||
|
||||
v1_it = v1.begin();
|
||||
v2_it = v2.begin();
|
||||
|
||||
double score = 0;
|
||||
|
||||
while(v1_it != v1_end && v2_it != v2_end)
|
||||
{
|
||||
const WordValue& vi = v1_it->second;
|
||||
const WordValue& wi = v2_it->second;
|
||||
|
||||
if(v1_it->first == v2_it->first)
|
||||
{
|
||||
score += vi * wi;
|
||||
|
||||
// move v1 and v2 forward
|
||||
++v1_it;
|
||||
++v2_it;
|
||||
}
|
||||
else if(v1_it->first < v2_it->first)
|
||||
{
|
||||
// move v1 forward
|
||||
v1_it = v1.lower_bound(v2_it->first);
|
||||
// v1_it = (first element >= v2_it.id)
|
||||
}
|
||||
else
|
||||
{
|
||||
// move v2 forward
|
||||
v2_it = v2.lower_bound(v1_it->first);
|
||||
// v2_it = (first element >= v1_it.id)
|
||||
}
|
||||
}
|
||||
|
||||
return score; // cannot scale
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
96
Thirdparty/DBoW2/DBoW2/ScoringObject.h
vendored
Normal file
96
Thirdparty/DBoW2/DBoW2/ScoringObject.h
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* File: ScoringObject.h
|
||||
* Date: November 2011
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Description: functions to compute bow scores
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __D_T_SCORING_OBJECT__
|
||||
#define __D_T_SCORING_OBJECT__
|
||||
|
||||
#include "BowVector.h"
|
||||
|
||||
namespace DBoW2 {
|
||||
|
||||
/// Base class of scoring functions
|
||||
class GeneralScoring
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Computes the score between two vectors. Vectors must be sorted and
|
||||
* normalized if necessary
|
||||
* @param v (in/out)
|
||||
* @param w (in/out)
|
||||
* @return score
|
||||
*/
|
||||
virtual double score(const BowVector &v, const BowVector &w) const = 0;
|
||||
|
||||
/**
|
||||
* Returns whether a vector must be normalized before scoring according
|
||||
* to the scoring scheme
|
||||
* @param norm norm to use
|
||||
* @return true iff must normalize
|
||||
*/
|
||||
virtual bool mustNormalize(LNorm &norm) const = 0;
|
||||
|
||||
/// Log of epsilon
|
||||
static const double LOG_EPS;
|
||||
// If you change the type of WordValue, make sure you change also the
|
||||
// epsilon value (this is needed by the KL method)
|
||||
|
||||
virtual ~GeneralScoring() {} //!< Required for virtual base classes
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Macro for defining Scoring classes
|
||||
* @param NAME name of class
|
||||
* @param MUSTNORMALIZE if vectors must be normalized to compute the score
|
||||
* @param NORM type of norm to use when MUSTNORMALIZE
|
||||
*/
|
||||
#define __SCORING_CLASS(NAME, MUSTNORMALIZE, NORM) \
|
||||
NAME: public GeneralScoring \
|
||||
{ public: \
|
||||
/** \
|
||||
* Computes score between two vectors \
|
||||
* @param v \
|
||||
* @param w \
|
||||
* @return score between v and w \
|
||||
*/ \
|
||||
virtual double score(const BowVector &v, const BowVector &w) const; \
|
||||
\
|
||||
/** \
|
||||
* Says if a vector must be normalized according to the scoring function \
|
||||
* @param norm (out) if true, norm to use
|
||||
* @return true iff vectors must be normalized \
|
||||
*/ \
|
||||
virtual inline bool mustNormalize(LNorm &norm) const \
|
||||
{ norm = NORM; return MUSTNORMALIZE; } \
|
||||
}
|
||||
|
||||
/// L1 Scoring object
|
||||
class __SCORING_CLASS(L1Scoring, true, L1);
|
||||
|
||||
/// L2 Scoring object
|
||||
class __SCORING_CLASS(L2Scoring, true, L2);
|
||||
|
||||
/// Chi square Scoring object
|
||||
class __SCORING_CLASS(ChiSquareScoring, true, L1);
|
||||
|
||||
/// KL divergence Scoring object
|
||||
class __SCORING_CLASS(KLScoring, true, L1);
|
||||
|
||||
/// Bhattacharyya Scoring object
|
||||
class __SCORING_CLASS(BhattacharyyaScoring, true, L1);
|
||||
|
||||
/// Dot product Scoring object
|
||||
class __SCORING_CLASS(DotProductScoring, false, L1);
|
||||
|
||||
#undef __SCORING_CLASS
|
||||
|
||||
} // namespace DBoW2
|
||||
|
||||
#endif
|
||||
|
||||
1665
Thirdparty/DBoW2/DBoW2/TemplatedVocabulary.h
vendored
Normal file
1665
Thirdparty/DBoW2/DBoW2/TemplatedVocabulary.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
129
Thirdparty/DBoW2/DUtils/Random.cpp
vendored
Normal file
129
Thirdparty/DBoW2/DUtils/Random.cpp
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* File: Random.cpp
|
||||
* Project: DUtils library
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Date: April 2010
|
||||
* Description: manages pseudo-random numbers
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Random.h"
|
||||
#include "Timestamp.h"
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
|
||||
bool DUtils::Random::m_already_seeded = false;
|
||||
|
||||
void DUtils::Random::SeedRand(){
|
||||
Timestamp time;
|
||||
time.setToCurrentTime();
|
||||
srand((unsigned)time.getFloatTime());
|
||||
}
|
||||
|
||||
void DUtils::Random::SeedRandOnce()
|
||||
{
|
||||
if(!m_already_seeded)
|
||||
{
|
||||
DUtils::Random::SeedRand();
|
||||
m_already_seeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DUtils::Random::SeedRand(int seed)
|
||||
{
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
void DUtils::Random::SeedRandOnce(int seed)
|
||||
{
|
||||
if(!m_already_seeded)
|
||||
{
|
||||
DUtils::Random::SeedRand(seed);
|
||||
m_already_seeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
int DUtils::Random::RandomInt(int min, int max){
|
||||
int d = max - min + 1;
|
||||
return int(((double)rand()/((double)RAND_MAX + 1.0)) * d) + min;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
DUtils::Random::UnrepeatedRandomizer::UnrepeatedRandomizer(int min, int max)
|
||||
{
|
||||
if(min <= max)
|
||||
{
|
||||
m_min = min;
|
||||
m_max = max;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_min = max;
|
||||
m_max = min;
|
||||
}
|
||||
|
||||
createValues();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
DUtils::Random::UnrepeatedRandomizer::UnrepeatedRandomizer
|
||||
(const DUtils::Random::UnrepeatedRandomizer& rnd)
|
||||
{
|
||||
*this = rnd;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int DUtils::Random::UnrepeatedRandomizer::get()
|
||||
{
|
||||
if(empty()) createValues();
|
||||
|
||||
DUtils::Random::SeedRandOnce();
|
||||
|
||||
int k = DUtils::Random::RandomInt(0, m_values.size()-1);
|
||||
int ret = m_values[k];
|
||||
m_values[k] = m_values.back();
|
||||
m_values.pop_back();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void DUtils::Random::UnrepeatedRandomizer::createValues()
|
||||
{
|
||||
int n = m_max - m_min + 1;
|
||||
|
||||
m_values.resize(n);
|
||||
for(int i = 0; i < n; ++i) m_values[i] = m_min + i;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void DUtils::Random::UnrepeatedRandomizer::reset()
|
||||
{
|
||||
if((int)m_values.size() != m_max - m_min + 1) createValues();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
DUtils::Random::UnrepeatedRandomizer&
|
||||
DUtils::Random::UnrepeatedRandomizer::operator=
|
||||
(const DUtils::Random::UnrepeatedRandomizer& rnd)
|
||||
{
|
||||
if(this != &rnd)
|
||||
{
|
||||
this->m_min = rnd.m_min;
|
||||
this->m_max = rnd.m_max;
|
||||
this->m_values = rnd.m_values;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
184
Thirdparty/DBoW2/DUtils/Random.h
vendored
Normal file
184
Thirdparty/DBoW2/DUtils/Random.h
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* File: Random.h
|
||||
* Project: DUtils library
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Date: April 2010, November 2011
|
||||
* Description: manages pseudo-random numbers
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __D_RANDOM__
|
||||
#define __D_RANDOM__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
namespace DUtils {
|
||||
|
||||
/// Functions to generate pseudo-random numbers
|
||||
class Random
|
||||
{
|
||||
public:
|
||||
class UnrepeatedRandomizer;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Sets the random number seed to the current time
|
||||
*/
|
||||
static void SeedRand();
|
||||
|
||||
/**
|
||||
* Sets the random number seed to the current time only the first
|
||||
* time this function is called
|
||||
*/
|
||||
static void SeedRandOnce();
|
||||
|
||||
/**
|
||||
* Sets the given random number seed
|
||||
* @param seed
|
||||
*/
|
||||
static void SeedRand(int seed);
|
||||
|
||||
/**
|
||||
* Sets the given random number seed only the first time this function
|
||||
* is called
|
||||
* @param seed
|
||||
*/
|
||||
static void SeedRandOnce(int seed);
|
||||
|
||||
/**
|
||||
* Returns a random number in the range [0..1]
|
||||
* @return random T number in [0..1]
|
||||
*/
|
||||
template <class T>
|
||||
static T RandomValue(){
|
||||
return (T)rand()/(T)RAND_MAX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random number in the range [min..max]
|
||||
* @param min
|
||||
* @param max
|
||||
* @return random T number in [min..max]
|
||||
*/
|
||||
template <class T>
|
||||
static T RandomValue(T min, T max){
|
||||
return Random::RandomValue<T>() * (max - min) + min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random int in the range [min..max]
|
||||
* @param min
|
||||
* @param max
|
||||
* @return random int in [min..max]
|
||||
*/
|
||||
static int RandomInt(int min, int max);
|
||||
|
||||
/**
|
||||
* Returns a random number from a gaussian distribution
|
||||
* @param mean
|
||||
* @param sigma standard deviation
|
||||
*/
|
||||
template <class T>
|
||||
static T RandomGaussianValue(T mean, T sigma)
|
||||
{
|
||||
// Box-Muller transformation
|
||||
T x1, x2, w, y1;
|
||||
|
||||
do {
|
||||
x1 = (T)2. * RandomValue<T>() - (T)1.;
|
||||
x2 = (T)2. * RandomValue<T>() - (T)1.;
|
||||
w = x1 * x1 + x2 * x2;
|
||||
} while ( w >= (T)1. || w == (T)0. );
|
||||
|
||||
w = sqrt( ((T)-2.0 * log( w ) ) / w );
|
||||
y1 = x1 * w;
|
||||
|
||||
return( mean + y1 * sigma );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// If SeedRandOnce() or SeedRandOnce(int) have already been called
|
||||
static bool m_already_seeded;
|
||||
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Provides pseudo-random numbers with no repetitions
|
||||
class Random::UnrepeatedRandomizer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a randomizer that returns numbers in the range [min, max]
|
||||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
UnrepeatedRandomizer(int min, int max);
|
||||
~UnrepeatedRandomizer(){}
|
||||
|
||||
/**
|
||||
* Copies a randomizer
|
||||
* @param rnd
|
||||
*/
|
||||
UnrepeatedRandomizer(const UnrepeatedRandomizer& rnd);
|
||||
|
||||
/**
|
||||
* Copies a randomizer
|
||||
* @param rnd
|
||||
*/
|
||||
UnrepeatedRandomizer& operator=(const UnrepeatedRandomizer& rnd);
|
||||
|
||||
/**
|
||||
* Returns a random number not given before. If all the possible values
|
||||
* were already given, the process starts again
|
||||
* @return unrepeated random number
|
||||
*/
|
||||
int get();
|
||||
|
||||
/**
|
||||
* Returns whether all the possible values between min and max were
|
||||
* already given. If get() is called when empty() is true, the behaviour
|
||||
* is the same than after creating the randomizer
|
||||
* @return true iff all the values were returned
|
||||
*/
|
||||
inline bool empty() const { return m_values.empty(); }
|
||||
|
||||
/**
|
||||
* Returns the number of values still to be returned
|
||||
* @return amount of values to return
|
||||
*/
|
||||
inline unsigned int left() const { return m_values.size(); }
|
||||
|
||||
/**
|
||||
* Resets the randomizer as it were just created
|
||||
*/
|
||||
void reset();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Creates the vector with available values
|
||||
*/
|
||||
void createValues();
|
||||
|
||||
protected:
|
||||
|
||||
/// Min of range of values
|
||||
int m_min;
|
||||
/// Max of range of values
|
||||
int m_max;
|
||||
|
||||
/// Available values
|
||||
std::vector<int> m_values;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
246
Thirdparty/DBoW2/DUtils/Timestamp.cpp
vendored
Normal file
246
Thirdparty/DBoW2/DUtils/Timestamp.cpp
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* File: Timestamp.cpp
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Date: March 2009
|
||||
* Description: timestamping functions
|
||||
*
|
||||
* Note: in windows, this class has a 1ms resolution
|
||||
*
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32
|
||||
#define WIN32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <sys/timeb.h>
|
||||
#define sprintf sprintf_s
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "Timestamp.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace DUtils;
|
||||
|
||||
Timestamp::Timestamp(Timestamp::tOptions option)
|
||||
{
|
||||
if(option & CURRENT_TIME)
|
||||
setToCurrentTime();
|
||||
else if(option & ZERO)
|
||||
setTime(0.);
|
||||
}
|
||||
|
||||
Timestamp::~Timestamp(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool Timestamp::empty() const
|
||||
{
|
||||
return m_secs == 0 && m_usecs == 0;
|
||||
}
|
||||
|
||||
void Timestamp::setToCurrentTime(){
|
||||
|
||||
#ifdef WIN32
|
||||
struct __timeb32 timebuffer;
|
||||
_ftime32_s( &timebuffer ); // C4996
|
||||
// Note: _ftime is deprecated; consider using _ftime_s instead
|
||||
m_secs = timebuffer.time;
|
||||
m_usecs = timebuffer.millitm * 1000;
|
||||
#else
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
m_secs = now.tv_sec;
|
||||
m_usecs = now.tv_usec;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void Timestamp::setTime(const string &stime){
|
||||
string::size_type p = stime.find('.');
|
||||
if(p == string::npos){
|
||||
m_secs = atol(stime.c_str());
|
||||
m_usecs = 0;
|
||||
}else{
|
||||
m_secs = atol(stime.substr(0, p).c_str());
|
||||
|
||||
string s_usecs = stime.substr(p+1, 6);
|
||||
m_usecs = atol(stime.substr(p+1).c_str());
|
||||
m_usecs *= (unsigned long)pow(10.0, double(6 - s_usecs.length()));
|
||||
}
|
||||
}
|
||||
|
||||
void Timestamp::setTime(double s)
|
||||
{
|
||||
m_secs = (unsigned long)s;
|
||||
m_usecs = (s - (double)m_secs) * 1e6;
|
||||
}
|
||||
|
||||
double Timestamp::getFloatTime() const {
|
||||
return double(m_secs) + double(m_usecs)/1000000.0;
|
||||
}
|
||||
|
||||
string Timestamp::getStringTime() const {
|
||||
char buf[32];
|
||||
sprintf(buf, "%.6lf", this->getFloatTime());
|
||||
return string(buf);
|
||||
}
|
||||
|
||||
double Timestamp::operator- (const Timestamp &t) const {
|
||||
return this->getFloatTime() - t.getFloatTime();
|
||||
}
|
||||
|
||||
Timestamp& Timestamp::operator+= (double s)
|
||||
{
|
||||
*this = *this + s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& Timestamp::operator-= (double s)
|
||||
{
|
||||
*this = *this - s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp Timestamp::operator+ (double s) const
|
||||
{
|
||||
unsigned long secs = (long)floor(s);
|
||||
unsigned long usecs = (long)((s - (double)secs) * 1e6);
|
||||
|
||||
return this->plus(secs, usecs);
|
||||
}
|
||||
|
||||
Timestamp Timestamp::plus(unsigned long secs, unsigned long usecs) const
|
||||
{
|
||||
Timestamp t;
|
||||
|
||||
const unsigned long max = 1000000ul;
|
||||
|
||||
if(m_usecs + usecs >= max)
|
||||
t.setTime(m_secs + secs + 1, m_usecs + usecs - max);
|
||||
else
|
||||
t.setTime(m_secs + secs, m_usecs + usecs);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
Timestamp Timestamp::operator- (double s) const
|
||||
{
|
||||
unsigned long secs = (long)floor(s);
|
||||
unsigned long usecs = (long)((s - (double)secs) * 1e6);
|
||||
|
||||
return this->minus(secs, usecs);
|
||||
}
|
||||
|
||||
Timestamp Timestamp::minus(unsigned long secs, unsigned long usecs) const
|
||||
{
|
||||
Timestamp t;
|
||||
|
||||
const unsigned long max = 1000000ul;
|
||||
|
||||
if(m_usecs < usecs)
|
||||
t.setTime(m_secs - secs - 1, max - (usecs - m_usecs));
|
||||
else
|
||||
t.setTime(m_secs - secs, m_usecs - usecs);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
bool Timestamp::operator> (const Timestamp &t) const
|
||||
{
|
||||
if(m_secs > t.m_secs) return true;
|
||||
else if(m_secs == t.m_secs) return m_usecs > t.m_usecs;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Timestamp::operator>= (const Timestamp &t) const
|
||||
{
|
||||
if(m_secs > t.m_secs) return true;
|
||||
else if(m_secs == t.m_secs) return m_usecs >= t.m_usecs;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Timestamp::operator< (const Timestamp &t) const
|
||||
{
|
||||
if(m_secs < t.m_secs) return true;
|
||||
else if(m_secs == t.m_secs) return m_usecs < t.m_usecs;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Timestamp::operator<= (const Timestamp &t) const
|
||||
{
|
||||
if(m_secs < t.m_secs) return true;
|
||||
else if(m_secs == t.m_secs) return m_usecs <= t.m_usecs;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Timestamp::operator== (const Timestamp &t) const
|
||||
{
|
||||
return(m_secs == t.m_secs && m_usecs == t.m_usecs);
|
||||
}
|
||||
|
||||
|
||||
string Timestamp::Format(bool machine_friendly) const
|
||||
{
|
||||
struct tm tm_time;
|
||||
|
||||
time_t t = (time_t)getFloatTime();
|
||||
|
||||
#ifdef WIN32
|
||||
localtime_s(&tm_time, &t);
|
||||
#else
|
||||
localtime_r(&t, &tm_time);
|
||||
#endif
|
||||
|
||||
char buffer[128];
|
||||
|
||||
if(machine_friendly)
|
||||
{
|
||||
strftime(buffer, 128, "%Y%m%d_%H%M%S", &tm_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
strftime(buffer, 128, "%c", &tm_time); // Thu Aug 23 14:55:02 2001
|
||||
}
|
||||
|
||||
return string(buffer);
|
||||
}
|
||||
|
||||
string Timestamp::Format(double s) {
|
||||
int days = int(s / (24. * 3600.0));
|
||||
s -= days * (24. * 3600.0);
|
||||
int hours = int(s / 3600.0);
|
||||
s -= hours * 3600;
|
||||
int minutes = int(s / 60.0);
|
||||
s -= minutes * 60;
|
||||
int seconds = int(s);
|
||||
int ms = int((s - seconds)*1e6);
|
||||
|
||||
stringstream ss;
|
||||
ss.fill('0');
|
||||
bool b;
|
||||
if((b = (days > 0))) ss << days << "d ";
|
||||
if((b = (b || hours > 0))) ss << setw(2) << hours << ":";
|
||||
if((b = (b || minutes > 0))) ss << setw(2) << minutes << ":";
|
||||
if(b) ss << setw(2);
|
||||
ss << seconds;
|
||||
if(!b) ss << "." << setw(6) << ms;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
204
Thirdparty/DBoW2/DUtils/Timestamp.h
vendored
Normal file
204
Thirdparty/DBoW2/DUtils/Timestamp.h
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* File: Timestamp.h
|
||||
* Author: Dorian Galvez-Lopez
|
||||
* Date: March 2009
|
||||
* Description: timestamping functions
|
||||
* License: see the LICENSE.txt file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __D_TIMESTAMP__
|
||||
#define __D_TIMESTAMP__
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace DUtils {
|
||||
|
||||
/// Timestamp
|
||||
class Timestamp
|
||||
{
|
||||
public:
|
||||
|
||||
/// Options to initiate a timestamp
|
||||
enum tOptions
|
||||
{
|
||||
NONE = 0,
|
||||
CURRENT_TIME = 0x1,
|
||||
ZERO = 0x2
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a timestamp
|
||||
* @param option option to set the initial time stamp
|
||||
*/
|
||||
Timestamp(Timestamp::tOptions option = NONE);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~Timestamp(void);
|
||||
|
||||
/**
|
||||
* Says if the timestamp is "empty": seconds and usecs are both 0, as
|
||||
* when initiated with the ZERO flag
|
||||
* @return true iif secs == usecs == 0
|
||||
*/
|
||||
bool empty() const;
|
||||
|
||||
/**
|
||||
* Sets this instance to the current time
|
||||
*/
|
||||
void setToCurrentTime();
|
||||
|
||||
/**
|
||||
* Sets the timestamp from seconds and microseconds
|
||||
* @param secs: seconds
|
||||
* @param usecs: microseconds
|
||||
*/
|
||||
inline void setTime(unsigned long secs, unsigned long usecs){
|
||||
m_secs = secs;
|
||||
m_usecs = usecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp in seconds and microseconds
|
||||
* @param secs seconds
|
||||
* @param usecs microseconds
|
||||
*/
|
||||
inline void getTime(unsigned long &secs, unsigned long &usecs) const
|
||||
{
|
||||
secs = m_secs;
|
||||
usecs = m_usecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timestamp from a string with the time in seconds
|
||||
* @param stime: string such as "1235603336.036609"
|
||||
*/
|
||||
void setTime(const string &stime);
|
||||
|
||||
/**
|
||||
* Sets the timestamp from a number of seconds from the epoch
|
||||
* @param s seconds from the epoch
|
||||
*/
|
||||
void setTime(double s);
|
||||
|
||||
/**
|
||||
* Returns this timestamp as the number of seconds in (long) float format
|
||||
*/
|
||||
double getFloatTime() const;
|
||||
|
||||
/**
|
||||
* Returns this timestamp as the number of seconds in fixed length string format
|
||||
*/
|
||||
string getStringTime() const;
|
||||
|
||||
/**
|
||||
* Returns the difference in seconds between this timestamp (greater) and t (smaller)
|
||||
* If the order is swapped, a negative number is returned
|
||||
* @param t: timestamp to subtract from this timestamp
|
||||
* @return difference in seconds
|
||||
*/
|
||||
double operator- (const Timestamp &t) const;
|
||||
|
||||
/**
|
||||
* Returns a copy of this timestamp + s seconds + us microseconds
|
||||
* @param s seconds
|
||||
* @param us microseconds
|
||||
*/
|
||||
Timestamp plus(unsigned long s, unsigned long us) const;
|
||||
|
||||
/**
|
||||
* Returns a copy of this timestamp - s seconds - us microseconds
|
||||
* @param s seconds
|
||||
* @param us microseconds
|
||||
*/
|
||||
Timestamp minus(unsigned long s, unsigned long us) const;
|
||||
|
||||
/**
|
||||
* Adds s seconds to this timestamp and returns a reference to itself
|
||||
* @param s seconds
|
||||
* @return reference to this timestamp
|
||||
*/
|
||||
Timestamp& operator+= (double s);
|
||||
|
||||
/**
|
||||
* Substracts s seconds to this timestamp and returns a reference to itself
|
||||
* @param s seconds
|
||||
* @return reference to this timestamp
|
||||
*/
|
||||
Timestamp& operator-= (double s);
|
||||
|
||||
/**
|
||||
* Returns a copy of this timestamp + s seconds
|
||||
* @param s: seconds
|
||||
*/
|
||||
Timestamp operator+ (double s) const;
|
||||
|
||||
/**
|
||||
* Returns a copy of this timestamp - s seconds
|
||||
* @param s: seconds
|
||||
*/
|
||||
Timestamp operator- (double s) const;
|
||||
|
||||
/**
|
||||
* Returns whether this timestamp is at the future of t
|
||||
* @param t
|
||||
*/
|
||||
bool operator> (const Timestamp &t) const;
|
||||
|
||||
/**
|
||||
* Returns whether this timestamp is at the future of (or is the same as) t
|
||||
* @param t
|
||||
*/
|
||||
bool operator>= (const Timestamp &t) const;
|
||||
|
||||
/**
|
||||
* Returns whether this timestamp and t represent the same instant
|
||||
* @param t
|
||||
*/
|
||||
bool operator== (const Timestamp &t) const;
|
||||
|
||||
/**
|
||||
* Returns whether this timestamp is at the past of t
|
||||
* @param t
|
||||
*/
|
||||
bool operator< (const Timestamp &t) const;
|
||||
|
||||
/**
|
||||
* Returns whether this timestamp is at the past of (or is the same as) t
|
||||
* @param t
|
||||
*/
|
||||
bool operator<= (const Timestamp &t) const;
|
||||
|
||||
/**
|
||||
* Returns the timestamp in a human-readable string
|
||||
* @param machine_friendly if true, the returned string is formatted
|
||||
* to yyyymmdd_hhmmss, without weekday or spaces
|
||||
* @note This has not been tested under Windows
|
||||
* @note The timestamp is truncated to seconds
|
||||
*/
|
||||
string Format(bool machine_friendly = false) const;
|
||||
|
||||
/**
|
||||
* Returns a string version of the elapsed time in seconds, with the format
|
||||
* xd hh:mm:ss, hh:mm:ss, mm:ss or s.us
|
||||
* @param s: elapsed seconds (given by getFloatTime) to format
|
||||
*/
|
||||
static string Format(double s);
|
||||
|
||||
|
||||
protected:
|
||||
/// Seconds
|
||||
unsigned long m_secs; // seconds
|
||||
/// Microseconds
|
||||
unsigned long m_usecs; // microseconds
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
7
Thirdparty/DBoW2/README.txt
vendored
Normal file
7
Thirdparty/DBoW2/README.txt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
You should have received this DBoW2 version along with ORB-SLAM2 (https://github.com/raulmur/ORB_SLAM2).
|
||||
See the original DBoW2 library at: https://github.com/dorian3d/DBoW2
|
||||
All files included in this version are BSD, see LICENSE.txt
|
||||
|
||||
We also use Random.h, Random.cpp, Timestamp.pp and Timestamp.h from DLib/DUtils.
|
||||
See the original DLib library at: https://github.com/dorian3d/DLib
|
||||
All files included in this version are BSD, see LICENSE.txt
|
||||
2
Thirdparty/Pangolin/.clang-format
vendored
Normal file
2
Thirdparty/Pangolin/.clang-format
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
DisableFormat: true
|
||||
SortIncludes: false
|
||||
3
Thirdparty/Pangolin/.gitignore
vendored
Normal file
3
Thirdparty/Pangolin/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.DS_Store
|
||||
CMakeLists.txt.user
|
||||
build*
|
||||
3
Thirdparty/Pangolin/.gitmodules
vendored
Normal file
3
Thirdparty/Pangolin/.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "external/pybind11"]
|
||||
path = external/pybind11
|
||||
url = https://github.com/pybind/pybind11.git
|
||||
30
Thirdparty/Pangolin/.travis.yml
vendored
Normal file
30
Thirdparty/Pangolin/.travis.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
sudo: required
|
||||
dist: xenial
|
||||
|
||||
before_install:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt -qq update ; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt install -qq --no-install-suggests --no-install-recommends libeigen3-dev libglew-dev libc++-dev libwayland-dev libxkbcommon-dev wayland-protocols libegl1-mesa-dev; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pyenv versions && pyenv global system 3.7; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install eigen glew ; fi
|
||||
|
||||
language: cpp
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: PARALLEL_BUILD="-- -j 8"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: PARALLEL_BUILD="-- -j 8"
|
||||
- os: osx
|
||||
env: PARALLEL_BUILD="-- -j 8"
|
||||
- os: windows
|
||||
env: PARALLEL_BUILD="--parallel 8"
|
||||
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake -D CMAKE_BUILD_TYPE=Release ..
|
||||
- cmake --build . $PARALLEL_BUILD
|
||||
109
Thirdparty/Pangolin/CMakeLists.txt
vendored
Normal file
109
Thirdparty/Pangolin/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project("Pangolin")
|
||||
set(PANGOLIN_VERSION_MAJOR 0)
|
||||
set(PANGOLIN_VERSION_MINOR 6)
|
||||
set(PANGOLIN_VERSION ${PANGOLIN_VERSION_MAJOR}.${PANGOLIN_VERSION_MINOR})
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
|
||||
|
||||
# Platform configuration vars
|
||||
include(SetPlatformVars)
|
||||
|
||||
SET(CPACK_GENERATOR "DEB")
|
||||
|
||||
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Steven Lovegrove")
|
||||
SET(CPACK_PACKAGE_VERSION_MAJOR ${PANGOLIN_VERSION_MAJOR})
|
||||
SET(CPACK_PACKAGE_VERSION_MINOR ${PANGOLIN_VERSION_MINOR})
|
||||
SET(CPACK_PACKAGE_VERSION_PATCH "0")
|
||||
include(CPack)
|
||||
|
||||
option( BUILD_TESTS "Build Tests" ON )
|
||||
option( BUILD_TOOLS "Build Examples" ON )
|
||||
option( BUILD_EXAMPLES "Build Tools" ON )
|
||||
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
if(_WIN_)
|
||||
option( BUILD_SHARED_LIBS "Build Shared Library" OFF)
|
||||
option( BUILD_EXTERN_GLEW "Automatically download, build and compile GLEW" ON)
|
||||
option( BUILD_EXTERN_LIBPNG "Automatically download, build and compile libpng" ON)
|
||||
option( BUILD_EXTERN_LIBJPEG "Automatically download, build and compile libjpeg" ON)
|
||||
option( MSVC_USE_STATIC_CRT "Use static C Runtime with MSVC, /MT instead of /MD" ON)
|
||||
|
||||
# Make sure there are no erroneous C Runtime flags
|
||||
list(APPEND FLAG_VARS
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
||||
)
|
||||
if(MSVC_USE_STATIC_CRT)
|
||||
foreach(FLAG_VAR ${FLAG_VARS})
|
||||
string(REGEX REPLACE "/MD" "/MT" NEW_FLAGS "${${FLAG_VAR}}")
|
||||
set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE)
|
||||
endforeach()
|
||||
else()
|
||||
foreach(FLAG_VAR ${FLAG_VARS})
|
||||
string(REGEX REPLACE "/MT" "/MD" NEW_FLAGS "${${FLAG_VAR}}")
|
||||
set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE)
|
||||
endforeach()
|
||||
endif()
|
||||
else()
|
||||
option( BUILD_SHARED_LIBS "Build Shared Library" ON)
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
set( CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}" )
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
set(ANDROID_PACKAGE_NAME "com.github.stevenlovegrove.pangolin")
|
||||
include(AndroidUtils)
|
||||
endif()
|
||||
|
||||
if(ANDROID OR IOS)
|
||||
set(HAVE_GLES 1)
|
||||
option(BUILD_FOR_GLES_2 "Build for OpenGL ES 2 instead of ES 1" ON )
|
||||
if(BUILD_FOR_GLES_2)
|
||||
set(HAVE_GLES_2 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_OSX_)
|
||||
set(CMAKE_MACOSX_RPATH ON)
|
||||
endif()
|
||||
|
||||
# Overide with cmake -DCMAKE_BUILD_TYPE=Debug {dir}
|
||||
if( NOT CMAKE_BUILD_TYPE AND NOT _WIN_ )
|
||||
message("Build type not set (defaults to release)")
|
||||
message("-DCMAKE_BUILD_TYPE=Debug for debug")
|
||||
set( CMAKE_BUILD_TYPE Release )
|
||||
endif()
|
||||
|
||||
string(TOLOWER ${PROJECT_NAME} LIBRARY_NAME)
|
||||
|
||||
# make an uninstall target
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
||||
IMMEDIATE @ONLY
|
||||
)
|
||||
|
||||
add_custom_target(pangolin_uninstall
|
||||
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
||||
|
||||
add_subdirectory("external")
|
||||
add_subdirectory("src")
|
||||
|
||||
if(BUILD_TESTS)
|
||||
set(Pangolin_DIR ${Pangolin_BINARY_DIR}/src)
|
||||
add_subdirectory("test")
|
||||
endif()
|
||||
|
||||
if(BUILD_TOOLS)
|
||||
set(Pangolin_DIR ${Pangolin_BINARY_DIR}/src)
|
||||
add_subdirectory(tools)
|
||||
endif()
|
||||
|
||||
if(BUILD_EXAMPLES)
|
||||
set(Pangolin_DIR ${Pangolin_BINARY_DIR}/src)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
22
Thirdparty/Pangolin/LICENCE
vendored
Normal file
22
Thirdparty/Pangolin/LICENCE
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2011 Steven Lovegrove and 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.
|
||||
176
Thirdparty/Pangolin/README.md
vendored
Normal file
176
Thirdparty/Pangolin/README.md
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
What is Pangolin
|
||||
====================================
|
||||
|
||||
Pangolin is a lightweight portable rapid development library for managing OpenGL
|
||||
display / interaction and abstracting video input. At its heart is a simple
|
||||
OpenGl viewport manager which can help to modularise 3D visualisation without
|
||||
adding to its complexity, and offers an advanced but intuitive 3D navigation
|
||||
handler. Pangolin also provides a mechanism for manipulating program variables
|
||||
through config files and ui integration, and has a flexible real-time plotter
|
||||
for visualising graphical data.
|
||||
|
||||
The ethos of Pangolin is to reduce the boilerplate code that normally
|
||||
gets written to visualise and interact with (typically image and 3D
|
||||
based) systems, without compromising performance. It also enables write-once
|
||||
code for a number of platforms, currently including Windows, Linux, OSX, Android
|
||||
and IOS.
|
||||
|
||||
## Code ##
|
||||
|
||||
Find the latest version on [Github](http://github.com/stevenlovegrove/Pangolin):
|
||||
|
||||
```
|
||||
git clone https://github.com/stevenlovegrove/Pangolin.git
|
||||
```
|
||||
|
||||
## Dependencies ##
|
||||
|
||||
Optional dependencies are enabled when found, otherwise they are silently disabled.
|
||||
Check the CMake configure output for details.
|
||||
|
||||
### Required Dependencies ###
|
||||
|
||||
* C++11
|
||||
|
||||
* OpenGL (Desktop / ES / ES2)
|
||||
* (lin) `sudo apt install libgl1-mesa-dev`
|
||||
|
||||
* Glew
|
||||
* (win) built automatically (assuming git is on your path)
|
||||
* (deb) `sudo apt install libglew-dev`
|
||||
* (mac) `sudo port install glew`
|
||||
|
||||
* CMake (for build environment)
|
||||
* (win) http://www.cmake.org/cmake/resources/software.html
|
||||
* (deb) `sudo apt install cmake`
|
||||
* (mac) `sudo port install cmake`
|
||||
|
||||
### Recommended Dependencies ###
|
||||
|
||||
* Python2 / Python3, for drop-down interactive console
|
||||
* (win) http://www.python.org/downloads/windows
|
||||
* (deb) `sudo apt install libpython2.7-dev`
|
||||
* (mac) preinstalled with osx
|
||||
* (for pybind11) `git submodule init && git submodule update`
|
||||
* (useful modules) `sudo python -mpip install numpy pyopengl Pillow pybind11`
|
||||
|
||||
* Wayland
|
||||
* pkg-config: `sudo apt install pkg-config`
|
||||
* Wayland and EGL:`sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols`
|
||||
|
||||
### Optional Dependencies for video input ###
|
||||
|
||||
* FFMPEG (For video decoding and image rescaling)
|
||||
* (deb) `sudo apt install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev`
|
||||
|
||||
* DC1394 (For firewire input)
|
||||
* (deb) `sudo apt install libdc1394-22-dev libraw1394-dev`
|
||||
|
||||
* libuvc (For cross-platform webcam video input via libusb)
|
||||
* git://github.com/ktossell/libuvc.git
|
||||
|
||||
* libjpeg, libpng, libtiff, libopenexr (For reading still-image sequences)
|
||||
* (deb) `sudo apt install libjpeg-dev libpng12-dev libtiff5-dev libopenexr-dev`
|
||||
|
||||
* OpenNI / OpenNI2 (For Kinect / Xtrion / Primesense capture)
|
||||
|
||||
* DepthSense SDK
|
||||
|
||||
### Very Optional Dependencies ###
|
||||
|
||||
* Eigen / TooN (These matrix types supported in the Pangolin API.)
|
||||
|
||||
* CUDA Toolkit >= 3.2 (Some CUDA header-only interop utilities included)
|
||||
* http://developer.nvidia.com/cuda-downloads
|
||||
|
||||
* Doxygen for generating html / pdf documentation.
|
||||
|
||||
## Building ##
|
||||
|
||||
Pangolin uses the CMake portable pre-build tool. To checkout and build pangolin in the
|
||||
directory 'build', execute the following at a shell (or the equivelent using a GUI):
|
||||
|
||||
```
|
||||
git clone https://github.com/stevenlovegrove/Pangolin.git
|
||||
cd Pangolin
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
If you would like to build the documentation and you have Doxygen installed, you
|
||||
can execute:
|
||||
|
||||
```
|
||||
cmake --build . --target pangolin_doc
|
||||
```
|
||||
|
||||
**On Windows**, Pangolin will attempt to download and build *glew*, *libjpeg*, *libpng* and *zlib* automatically. It does so assuming that git is available on the path - this assumption may be wrong for windows users who have downloaded Pangolin via a zip file on github. You will instead need to download and compile the dependencies manually, and set the BUILD_EXTERN_(lib) options to false for these libraries. The alternate and recommended approach is to install [gitbash](https://git-scm.com/downloads) and work from within their provided console.
|
||||
|
||||
## Issues ##
|
||||
|
||||
Please visit [Github Issues](https://github.com/stevenlovegrove/Pangolin/issues) to view and report problems with Pangolin. Issues and pull requests should be raised against the master branch which contains the current development version.
|
||||
|
||||
Please note; most Pangolin dependencies are optional - to disable a dependency which may be causing trouble on your machine, set the BUILD_PANGOLIN_(option) variable to false with a cmake configuration tool (e.g. ccmake or cmake-gui).
|
||||
|
||||
## Contributions and Continuous Integration ##
|
||||
|
||||
For CI, Pangolin uses [travis-ci.org](https://travis-ci.org/stevenlovegrove/Pangolin) for Ubuntu, OSX and [ci.appveyor.com](https://ci.appveyor.com/project/stevenlovegrove/pangolin) for Windows.
|
||||
|
||||
To contribute to Pangolin, I would appreciate pull requests against the master branch. This will trigger CI builds for your changes automatically, and help me to merge with confidence.
|
||||
|
||||
## Binaries ##
|
||||
|
||||
Binaries are available for Windows x64, as output by the Windows CI server: [Appveyor Artifacts](https://ci.appveyor.com/project/stevenlovegrove/pangolin/build/artifacts).
|
||||
|
||||
## Bindings ##
|
||||
|
||||
### Python ###
|
||||
|
||||
Pangolin python bindings are enabled via [pybind11](www.pybind11.com). These bindings can be used both standalone and from within Pangolin's drop-down console (press the back-tick key, `).
|
||||
|
||||
To enable the bindings, you must checkout the pybind submodule. To use pangolin in python, it's recommend to install a few other python packages too:
|
||||
|
||||
```
|
||||
sudo python -mpip install numpy pyopengl Pillow pybind11
|
||||
git submodule init && git submodule update
|
||||
```
|
||||
|
||||
The python module pypangolin must be on your python path, either through installation, or by setting it explicitly:
|
||||
|
||||
```
|
||||
import sys
|
||||
sys.path.append('path/of/pypangolin.so')
|
||||
```
|
||||
|
||||
## Scheme syntax for windowing and video
|
||||
|
||||
Pangolin uses 'URI' syntax for modularising video drivers and windowing backends. The syntax follows along the lines of `module_name:[option1=value1,option2=value2,...]//module_resource_to_open`. Some examples for using this URI syntax with the VideoViewer tool is as follows:
|
||||
|
||||
```
|
||||
VideoViewer test://
|
||||
VideoViewer uvc:[size=640x480]///dev/video0
|
||||
VideoViewer flip://debayer:[tile=rggb,method=downsample]//file://~/somefile.pango
|
||||
```
|
||||
|
||||
Notice that for video, some modules support chaining to construct a simple filter graph. See include/pangolin/video/video.h for more examples.
|
||||
|
||||
For windowing, you can also customize default arguments for Pangolin applications by setting the `PANGOLIN_WINDOW_URI` environment variable. For instance, on high-DPI screens (in this example on OSX), you could set:
|
||||
|
||||
|
||||
```
|
||||
setenv PANGOLIN_WINDOW_URI "cocoa:[HIGHRES=true]//"
|
||||
```
|
||||
|
||||
Some window parameters that may be interesting to override are `DISPLAYNAME`, `DOUBLEBUFFER`, `SAMPLE_BUFFERS`, `SAMPLES`, `HIGHRES`. Window modules currently include `x11`, `winapi`, `cocoa`.
|
||||
|
||||
## Acknowledgements ##
|
||||
|
||||
I'd like to thank the growing number of kind contributors to Pangolin for helping to make it more stable and feature rich. Many features of Pangolin have been influenced by other projects such as GFlags, GLConsole, and libcvd in particular. I'd also like to thank the FOSS projects on which Pangolin depends.
|
||||
|
||||
For a summary of those who have made code contributions, execute:
|
||||
|
||||
```
|
||||
git shortlog -sne
|
||||
```
|
||||
25
Thirdparty/Pangolin/appveyor.yml
vendored
Normal file
25
Thirdparty/Pangolin/appveyor.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
os: Visual Studio 2015
|
||||
|
||||
clone_folder: c:/projects/Pangolin
|
||||
|
||||
platform: x64
|
||||
configuration: Release
|
||||
|
||||
build:
|
||||
verbosity: minimal
|
||||
project: c:/projects/Pangolin/build/Pangolin.sln
|
||||
|
||||
install:
|
||||
- ps: wget http://bitbucket.org/eigen/eigen/get/3.2.10.zip -outfile eigen3.zip
|
||||
- cmd: 7z x eigen3.zip -o"C:/projects" -y > nul
|
||||
|
||||
before_build:
|
||||
- cd c:/projects/Pangolin
|
||||
- mkdir bin
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake -G "Visual Studio 14 2015 Win64" -D EIGEN3_INCLUDE_DIR=C:/projects/eigen-eigen-b9cd8366d4e8 -D CMAKE_INSTALL_PREFIX=../bin ..
|
||||
|
||||
on_success:
|
||||
- 7z a pangolin_build.zip "c:/projects/Pangolin/build/src/include" "c:/projects/Pangolin/build/src/Release/pangolin.lib" "c:/projects/Pangolin/build/tools/*/Release/*.exe" "c:/projects/Pangolin/build/examples/*/Release/*.exe"
|
||||
- appveyor PushArtifact pangolin_build.zip
|
||||
25
Thirdparty/Pangolin/cmake_uninstall.cmake.in
vendored
Normal file
25
Thirdparty/Pangolin/cmake_uninstall.cmake.in
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# -----------------------------------------------
|
||||
# File that provides "make uninstall" target
|
||||
# We use the file 'install_manifest.txt'
|
||||
# -----------------------------------------------
|
||||
IF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
|
||||
MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"")
|
||||
ENDIF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
|
||||
|
||||
FILE(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
|
||||
STRING(REGEX REPLACE "\n" ";" files "${files}")
|
||||
FOREACH(file ${files})
|
||||
MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
|
||||
IF(EXISTS "$ENV{DESTDIR}${file}")
|
||||
EXEC_PROGRAM(
|
||||
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||
OUTPUT_VARIABLE rm_out
|
||||
RETURN_VALUE rm_retval
|
||||
)
|
||||
IF(NOT "${rm_retval}" STREQUAL 0)
|
||||
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
|
||||
ENDIF(NOT "${rm_retval}" STREQUAL 0)
|
||||
ELSE(EXISTS "$ENV{DESTDIR}${file}")
|
||||
MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
|
||||
ENDIF(EXISTS "$ENV{DESTDIR}${file}")
|
||||
ENDFOREACH(file)
|
||||
153
Thirdparty/Pangolin/external/CMakeLists.txt
vendored
Normal file
153
Thirdparty/Pangolin/external/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
include(ExternalProject)
|
||||
|
||||
set(ExternConfig "")
|
||||
|
||||
if( BUILD_EXTERN_GLEW )
|
||||
|
||||
#########################################################
|
||||
# GLEW
|
||||
#########################################################
|
||||
ExternalProject_Add( __glew
|
||||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/glew"
|
||||
GIT_REPOSITORY https://github.com/Perlmint/glew-cmake.git
|
||||
GIT_TAG 7574ab4d00b683e56adbfdec7da636529dfe65d8
|
||||
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
|
||||
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
|
||||
-DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
|
||||
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
||||
)
|
||||
|
||||
add_library(_glew STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(_glew __glew)
|
||||
set_target_properties(_glew PROPERTIES
|
||||
IMPORTED_LOCATION_RELWITHDEBINFO ${CMAKE_INSTALL_PREFIX}/lib/glew.lib
|
||||
IMPORTED_LOCATION_RELEASE ${CMAKE_INSTALL_PREFIX}/lib/glew.lib
|
||||
IMPORTED_LOCATION_DEBUG ${CMAKE_INSTALL_PREFIX}/lib/glewd.lib
|
||||
)
|
||||
|
||||
set(GLEW_FOUND true PARENT_SCOPE)
|
||||
set(GLEW_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" PARENT_SCOPE)
|
||||
set(GLEW_LIBRARY _glew PARENT_SCOPE)
|
||||
set(GLEW_STATIC 1 PARENT_SCOPE)
|
||||
set(ExternConfig "${ExternConfig}
|
||||
add_library(_glew STATIC IMPORTED)
|
||||
set_target_properties(_glew PROPERTIES
|
||||
IMPORTED_LOCATION_RELWITHDEBINFO \"${CMAKE_INSTALL_PREFIX}/lib/glew.lib\"
|
||||
IMPORTED_LOCATION_RELEASE \"${CMAKE_INSTALL_PREFIX}/lib/glew.lib\"
|
||||
IMPORTED_LOCATION_DEBUG \"${CMAKE_INSTALL_PREFIX}/lib/glewd.lib\"
|
||||
)")
|
||||
endif()
|
||||
|
||||
if( BUILD_EXTERN_LIBPNG )
|
||||
|
||||
#########################################################
|
||||
# zlib
|
||||
#########################################################
|
||||
|
||||
ExternalProject_Add( __zlib
|
||||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/zlib"
|
||||
GIT_REPOSITORY https://github.com/madler/zlib.git
|
||||
GIT_TAG v1.2.8
|
||||
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
|
||||
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
|
||||
-DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
|
||||
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
||||
)
|
||||
add_library(_zlib STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(_zlib __zlib)
|
||||
set_target_properties(_zlib PROPERTIES
|
||||
IMPORTED_LOCATION_RELEASE ${CMAKE_INSTALL_PREFIX}/lib/zlibstatic.lib
|
||||
IMPORTED_LOCATION_RELWITHDEBINFO ${CMAKE_INSTALL_PREFIX}/lib/zlibstatic.lib
|
||||
IMPORTED_LOCATION_DEBUG ${CMAKE_INSTALL_PREFIX}/lib/zlibstaticd.lib
|
||||
)
|
||||
|
||||
#########################################################
|
||||
# libpng
|
||||
#########################################################
|
||||
|
||||
ExternalProject_Add( __libpng
|
||||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libpng"
|
||||
GIT_REPOSITORY https://github.com/glennrp/libpng.git
|
||||
GIT_TAG v1.6.18
|
||||
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
-DZLIB_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include
|
||||
-DZLIB_LIBRARY=${CMAKE_INSTALL_PREFIX}/lib/zlibstatic*.lib
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
|
||||
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
|
||||
-DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
|
||||
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
||||
DEPENDS __zlib
|
||||
)
|
||||
|
||||
add_library(_libpng STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(_libpng __libpng)
|
||||
set_target_properties(_libpng PROPERTIES
|
||||
IMPORTED_LOCATION_RELWITHDEBINFO ${CMAKE_INSTALL_PREFIX}/lib/libpng16_static.lib
|
||||
IMPORTED_LOCATION_RELEASE ${CMAKE_INSTALL_PREFIX}/lib/libpng16_static.lib
|
||||
IMPORTED_LOCATION_DEBUG ${CMAKE_INSTALL_PREFIX}/lib/libpng16_staticd.lib
|
||||
)
|
||||
|
||||
set(PNG_FOUND true PARENT_SCOPE)
|
||||
set(PNG_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" PARENT_SCOPE)
|
||||
set(PNG_LIBRARY _libpng PARENT_SCOPE)
|
||||
set(ZLIB_LIBRARY _zlib PARENT_SCOPE)
|
||||
set(ExternConfig "${ExternConfig}
|
||||
add_library(_zlib STATIC IMPORTED)
|
||||
set_target_properties(_zlib PROPERTIES
|
||||
IMPORTED_LOCATION_RELEASE \"${CMAKE_INSTALL_PREFIX}/lib/zlibstatic.lib\"
|
||||
IMPORTED_LOCATION_RELWITHDEBINFO \"${CMAKE_INSTALL_PREFIX}/lib/zlibstatic.lib\"
|
||||
IMPORTED_LOCATION_DEBUG \"${CMAKE_INSTALL_PREFIX}/lib/zlibstaticd.lib\"
|
||||
)
|
||||
add_library(_libpng STATIC IMPORTED)
|
||||
set_target_properties(_libpng PROPERTIES
|
||||
IMPORTED_LOCATION_RELEASE \"${CMAKE_INSTALL_PREFIX}/lib/libpng16_static.lib\"
|
||||
IMPORTED_LOCATION_RELWITHDEBINFO \"${CMAKE_INSTALL_PREFIX}/lib/libpng16_static.lib\"
|
||||
IMPORTED_LOCATION_DEBUG \"${CMAKE_INSTALL_PREFIX}/lib/libpng16_staticd.lib\"
|
||||
)")
|
||||
endif()
|
||||
|
||||
if( BUILD_EXTERN_LIBJPEG )
|
||||
|
||||
#########################################################
|
||||
# libjpg
|
||||
#########################################################
|
||||
|
||||
ExternalProject_Add( __libjpeg
|
||||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libjpeg"
|
||||
GIT_REPOSITORY https://github.com/LuaDist/libjpeg.git
|
||||
GIT_TAG bc8f8be222287fec977ec3f47a5cb065cceb2ee9
|
||||
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
-DBUILD_SHARED_LIBS=false
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
|
||||
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
|
||||
-DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
|
||||
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
||||
)
|
||||
|
||||
add_library(_libjpeg STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(_libjpeg __libjpeg)
|
||||
set_target_properties(_libjpeg PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_INSTALL_PREFIX}/lib/jpeg.lib
|
||||
)
|
||||
|
||||
set(JPEG_FOUND true PARENT_SCOPE)
|
||||
set(JPEG_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" PARENT_SCOPE)
|
||||
set(JPEG_LIBRARY _libjpeg PARENT_SCOPE)
|
||||
set(ExternConfig "${ExternConfig}
|
||||
add_library(_libjpeg STATIC IMPORTED)
|
||||
set_target_properties(_libjpeg PROPERTIES
|
||||
IMPORTED_LOCATION \"${CMAKE_INSTALL_PREFIX}/lib/jpeg.lib\"
|
||||
)")
|
||||
endif()
|
||||
|
||||
set(ExternConfig "${ExternConfig}" PARENT_SCOPE)
|
||||
1067
Thirdparty/Pangolin/include/experimental/optional.hpp
vendored
Normal file
1067
Thirdparty/Pangolin/include/experimental/optional.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2468
Thirdparty/Pangolin/include/mpark/variant.hpp
vendored
Normal file
2468
Thirdparty/Pangolin/include/mpark/variant.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
92
Thirdparty/Pangolin/include/pangolin/compat/glutbitmap.h
vendored
Normal file
92
Thirdparty/Pangolin/include/pangolin/compat/glutbitmap.h
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 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 <pangolin/gl/glplatform.h>
|
||||
#include <pangolin/gl/glfont.h>
|
||||
|
||||
#ifdef HAVE_GLES
|
||||
GLfloat g_raster_pos[4];
|
||||
|
||||
inline void glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
// find object point (x,y,z)' in pixel coords
|
||||
GLdouble projection[16];
|
||||
GLdouble modelview[16];
|
||||
GLint view[4];
|
||||
|
||||
#ifdef HAVE_GLES_2
|
||||
std::copy(pangolin::glEngine().projection.top().m, pangolin::glEngine().projection.top().m+16, projection);
|
||||
std::copy(pangolin::glEngine().modelview.top().m, pangolin::glEngine().modelview.top().m+16, modelview);
|
||||
#else
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projection );
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, modelview );
|
||||
#endif
|
||||
glGetIntegerv(GL_VIEWPORT, view );
|
||||
|
||||
pangolin::glProject(x, y, z, modelview, projection, view,
|
||||
g_raster_pos, g_raster_pos + 1, g_raster_pos + 2);
|
||||
}
|
||||
|
||||
inline void glRasterPos2f(GLfloat x, GLfloat y)
|
||||
{
|
||||
glRasterPos3f(x,y,1.0f);
|
||||
}
|
||||
|
||||
inline void glRasterPos2i(GLint x, GLint y)
|
||||
{
|
||||
glRasterPos3f((GLfloat)x, (GLfloat)y, 1.0f );
|
||||
}
|
||||
|
||||
inline void glRasterPos3fv(const GLfloat *v){
|
||||
glRasterPos3f(v[0],v[1],v[2]);
|
||||
}
|
||||
|
||||
inline void glRasterPos2fv(const GLfloat *v){
|
||||
glRasterPos3f(v[0],v[1],1.0f);
|
||||
}
|
||||
#endif // HAVE_GLES
|
||||
|
||||
inline void glutBitmapString(void * /*font*/, const unsigned char *str)
|
||||
{
|
||||
#ifndef HAVE_GLES
|
||||
float g_raster_pos[4];
|
||||
glGetFloatv(GL_CURRENT_RASTER_POSITION, g_raster_pos);
|
||||
#endif
|
||||
|
||||
pangolin::GlFont::I().Text( (const char *)str ).DrawWindow(
|
||||
g_raster_pos[0], g_raster_pos[1], g_raster_pos[2]
|
||||
);
|
||||
}
|
||||
|
||||
inline int glutBitmapLength(void * /*font*/, const unsigned char *str)
|
||||
{
|
||||
return (int)(pangolin::GlFont::I().Text((const char *)str).Width());
|
||||
}
|
||||
|
||||
#define GLUT_BITMAP_HELVETICA_12 0;
|
||||
20
Thirdparty/Pangolin/include/pangolin/compat/optional.h
vendored
Normal file
20
Thirdparty/Pangolin/include/pangolin/compat/optional.h
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
// Use either C++17 optional, or the standalone backwards compatible version
|
||||
#if (__cplusplus >= 201703L)
|
||||
# include <optional>
|
||||
#else
|
||||
# include <experimental/optional.hpp>
|
||||
#endif
|
||||
|
||||
namespace pangolin {
|
||||
#if (__cplusplus >= 201703L)
|
||||
template <typename T>
|
||||
using optional = std::optional<T>;
|
||||
#else
|
||||
template <typename T>
|
||||
using optional = std::experimental::optional<T>;
|
||||
#endif
|
||||
}
|
||||
49
Thirdparty/Pangolin/include/pangolin/compat/type_traits.h
vendored
Normal file
49
Thirdparty/Pangolin/include/pangolin/compat/type_traits.h
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/* 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 <pangolin/platform.h>
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
// enable_if From Boost
|
||||
namespace pangolin
|
||||
{
|
||||
template <bool B, class T = void>
|
||||
struct enable_if_c {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct enable_if_c<false, T> {};
|
||||
|
||||
template <class Cond, class T = void>
|
||||
struct enable_if : public enable_if_c<Cond::value, T> {};
|
||||
}
|
||||
25
Thirdparty/Pangolin/include/pangolin/compat/variant.h
vendored
Normal file
25
Thirdparty/Pangolin/include/pangolin/compat/variant.h
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
// Use either C++17 variant, or the standalone backwards compatible version
|
||||
// of M. Park.
|
||||
#if (__cplusplus >= 201703L)
|
||||
# include <variant>
|
||||
#else
|
||||
# include <mpark/variant.hpp>
|
||||
#endif
|
||||
|
||||
namespace pangolin {
|
||||
#if (__cplusplus >= 201703L)
|
||||
using std::variant;
|
||||
using std::get;
|
||||
using std::get_if;
|
||||
using std::visit;
|
||||
#else
|
||||
using mpark::variant;
|
||||
using mpark::get;
|
||||
using mpark::get_if;
|
||||
using mpark::visit;
|
||||
#endif
|
||||
}
|
||||
80
Thirdparty/Pangolin/include/pangolin/console/ConsoleInterpreter.h
vendored
Normal file
80
Thirdparty/Pangolin/include/pangolin/console/ConsoleInterpreter.h
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/* 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 <vector>
|
||||
#include <string>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
enum ConsoleLineType
|
||||
{
|
||||
ConsoleLineTypeCmd,
|
||||
ConsoleLineTypeCmdOptions,
|
||||
ConsoleLineTypeStdout,
|
||||
ConsoleLineTypeStderr,
|
||||
ConsoleLineTypeOutput,
|
||||
ConsoleLineTypeHelp,
|
||||
};
|
||||
|
||||
class ConsoleLine
|
||||
{
|
||||
public:
|
||||
inline ConsoleLine()
|
||||
: linetype(ConsoleLineTypeCmd)
|
||||
{
|
||||
}
|
||||
|
||||
inline ConsoleLine(std::string text, ConsoleLineType linetype = ConsoleLineTypeOutput)
|
||||
: text(text), linetype(linetype)
|
||||
{
|
||||
}
|
||||
|
||||
std::string text;
|
||||
ConsoleLineType linetype;
|
||||
};
|
||||
|
||||
class ConsoleInterpreter
|
||||
{
|
||||
public:
|
||||
inline virtual ~ConsoleInterpreter()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PushCommand(const std::string& cmd) = 0;
|
||||
|
||||
virtual bool PullLine(ConsoleLine& line) = 0;
|
||||
|
||||
virtual std::vector<std::string> Complete(
|
||||
const std::string& cmd, int max_options = 20
|
||||
) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
109
Thirdparty/Pangolin/include/pangolin/console/ConsoleView.h
vendored
Normal file
109
Thirdparty/Pangolin/include/pangolin/console/ConsoleView.h
vendored
Normal 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 <deque>
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
#include <pangolin/gl/glfont.h>
|
||||
#include <pangolin/var/var.h>
|
||||
#include <pangolin/display/view.h>
|
||||
#include <pangolin/handler/handler.h>
|
||||
#include <pangolin/gl/colour.h>
|
||||
|
||||
#include <pangolin/console/ConsoleInterpreter.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
class ConsoleView : public pangolin::View, pangolin::Handler
|
||||
{
|
||||
public:
|
||||
struct Line
|
||||
{
|
||||
Line()
|
||||
: linetype(ConsoleLineTypeCmd)
|
||||
{
|
||||
}
|
||||
|
||||
Line(const GlText& text, ConsoleLineType linetype = ConsoleLineTypeCmd )
|
||||
: text(text), linetype(linetype)
|
||||
{
|
||||
}
|
||||
|
||||
GlText text;
|
||||
ConsoleLineType linetype;
|
||||
};
|
||||
|
||||
|
||||
// Construct with interpreter (and take ownership)
|
||||
ConsoleView(ConsoleInterpreter* interpreter);
|
||||
|
||||
~ConsoleView();
|
||||
|
||||
View& ShowWithoutAnimation(bool show=true);
|
||||
|
||||
// Replace implementation in View to account for hiding animation
|
||||
View& Show(bool show=true);
|
||||
|
||||
// Replace implementation in View to account for hiding animation
|
||||
void ToggleShow();
|
||||
|
||||
// Replace implementation in View to account for hiding animation
|
||||
bool IsShown() const;
|
||||
|
||||
void Render() override;
|
||||
|
||||
void Keyboard(View&, unsigned char key, int x, int y, bool pressed) override;
|
||||
|
||||
private:
|
||||
void DrawLine(const ConsoleView::Line& l, int carat);
|
||||
|
||||
void ProcessOutputLines();
|
||||
|
||||
void AddLine(const std::string& text, ConsoleLineType linetype = ConsoleLineTypeCmd);
|
||||
|
||||
Line* GetLine(int id, ConsoleLineType line_type, const std::string& prefix = "");
|
||||
|
||||
ConsoleInterpreter* interpreter;
|
||||
|
||||
GlFont& font;
|
||||
|
||||
int carat;
|
||||
Line current_line;
|
||||
std::deque<Line> line_buffer;
|
||||
|
||||
bool hiding;
|
||||
GLfloat bottom;
|
||||
|
||||
Colour background_colour;
|
||||
std::map<ConsoleLineType,pangolin::Colour> line_colours;
|
||||
float animation_speed;
|
||||
};
|
||||
|
||||
}
|
||||
86
Thirdparty/Pangolin/include/pangolin/display/attach.h
vendored
Normal file
86
Thirdparty/Pangolin/include/pangolin/display/attach.h
vendored
Normal 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
|
||||
68
Thirdparty/Pangolin/include/pangolin/display/device/OsxWindow.h
vendored
Normal file
68
Thirdparty/Pangolin/include/pangolin/display/device/OsxWindow.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
59
Thirdparty/Pangolin/include/pangolin/display/device/PangolinNSApplication.h
vendored
Normal file
59
Thirdparty/Pangolin/include/pangolin/display/device/PangolinNSApplication.h
vendored
Normal 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
|
||||
45
Thirdparty/Pangolin/include/pangolin/display/device/PangolinNSGLView.h
vendored
Normal file
45
Thirdparty/Pangolin/include/pangolin/display/device/PangolinNSGLView.h
vendored
Normal 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
|
||||
|
||||
89
Thirdparty/Pangolin/include/pangolin/display/device/WinWindow.h
vendored
Normal file
89
Thirdparty/Pangolin/include/pangolin/display/device/WinWindow.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
0
Thirdparty/Pangolin/include/pangolin/display/device/X11GlContext.h
vendored
Normal file
0
Thirdparty/Pangolin/include/pangolin/display/device/X11GlContext.h
vendored
Normal file
109
Thirdparty/Pangolin/include/pangolin/display/device/X11Window.h
vendored
Normal file
109
Thirdparty/Pangolin/include/pangolin/display/device/X11Window.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
333
Thirdparty/Pangolin/include/pangolin/display/device/display_android.h
vendored
Normal file
333
Thirdparty/Pangolin/include/pangolin/display/device/display_android.h
vendored
Normal 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
|
||||
219
Thirdparty/Pangolin/include/pangolin/display/display.h
vendored
Normal file
219
Thirdparty/Pangolin/include/pangolin/display/display.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
138
Thirdparty/Pangolin/include/pangolin/display/display_internal.h
vendored
Normal file
138
Thirdparty/Pangolin/include/pangolin/display/display_internal.h
vendored
Normal 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);
|
||||
|
||||
}
|
||||
|
||||
74
Thirdparty/Pangolin/include/pangolin/display/image_view.h
vendored
Normal file
74
Thirdparty/Pangolin/include/pangolin/display/image_view.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
446
Thirdparty/Pangolin/include/pangolin/display/opengl_render_state.h
vendored
Normal file
446
Thirdparty/Pangolin/include/pangolin/display/opengl_render_state.h
vendored
Normal 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
|
||||
|
||||
|
||||
}
|
||||
43
Thirdparty/Pangolin/include/pangolin/display/user_app.h
vendored
Normal file
43
Thirdparty/Pangolin/include/pangolin/display/user_app.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
235
Thirdparty/Pangolin/include/pangolin/display/view.h
vendored
Normal file
235
Thirdparty/Pangolin/include/pangolin/display/view.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
65
Thirdparty/Pangolin/include/pangolin/display/viewport.h
vendored
Normal file
65
Thirdparty/Pangolin/include/pangolin/display/viewport.h
vendored
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
141
Thirdparty/Pangolin/include/pangolin/display/widgets/widgets.h
vendored
Normal file
141
Thirdparty/Pangolin/include/pangolin/display/widgets/widgets.h
vendored
Normal 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];
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
90
Thirdparty/Pangolin/include/pangolin/display/window.h
vendored
Normal file
90
Thirdparty/Pangolin/include/pangolin/display/window.h
vendored
Normal 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 + "'")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
114
Thirdparty/Pangolin/include/pangolin/factory/factory_registry.h
vendored
Normal file
114
Thirdparty/Pangolin/include/pangolin/factory/factory_registry.h
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011-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 <memory>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <pangolin/utils/uri.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct FactoryInterface
|
||||
{
|
||||
typedef T FactoryItem;
|
||||
|
||||
virtual ~FactoryInterface() = default;
|
||||
virtual std::unique_ptr<T> Open(const Uri& uri) = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class FactoryRegistry
|
||||
{
|
||||
public:
|
||||
// IMPORTANT: Implement for each templated instantiation within a seperate compilation unit.
|
||||
static FactoryRegistry<T>& I();
|
||||
|
||||
~FactoryRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
void RegisterFactory(std::shared_ptr<FactoryInterface<T>> factory, uint32_t precedence, const std::string& scheme_name )
|
||||
{
|
||||
FactoryItem item = {precedence, scheme_name, factory};
|
||||
factories.push_back( item );
|
||||
std::sort(factories.begin(), factories.end());
|
||||
}
|
||||
|
||||
void UnregisterFactory(FactoryInterface<T>* factory)
|
||||
{
|
||||
for( auto i = factories.end()-1; i != factories.begin(); --i)
|
||||
{
|
||||
if( i->factory.get() == factory ) {
|
||||
factories.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnregisterAllFactories()
|
||||
{
|
||||
factories.clear();
|
||||
}
|
||||
|
||||
std::unique_ptr<T> Open(const Uri& uri)
|
||||
{
|
||||
// Iterate over all registered factories in order of precedence.
|
||||
for(auto& item : factories) {
|
||||
if( item.scheme == uri.scheme) {
|
||||
std::unique_ptr<T> video = item.factory->Open(uri);
|
||||
if(video) {
|
||||
return video;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::unique_ptr<T>();
|
||||
}
|
||||
|
||||
private:
|
||||
struct FactoryItem
|
||||
{
|
||||
uint32_t precedence;
|
||||
std::string scheme;
|
||||
std::shared_ptr<FactoryInterface<T>> factory;
|
||||
|
||||
bool operator<(const FactoryItem& rhs) const {
|
||||
return precedence < rhs.precedence;
|
||||
}
|
||||
};
|
||||
|
||||
// Priority, Factory tuple
|
||||
std::vector<FactoryItem> factories;
|
||||
};
|
||||
|
||||
#define PANGOLIN_REGISTER_FACTORY(x) void Register ## x ## Factory()
|
||||
|
||||
}
|
||||
95
Thirdparty/Pangolin/include/pangolin/geometry/geometry.h
vendored
Normal file
95
Thirdparty/Pangolin/include/pangolin/geometry/geometry.h
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef PANGOLIN_GEOMETRY_H
|
||||
#define PANGOLIN_GEOMETRY_H
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <pangolin/image/typed_image.h>
|
||||
#include <pangolin/compat/variant.h>
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
#include <Eigen/Geometry>
|
||||
#endif
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
struct Geometry
|
||||
{
|
||||
struct Element : public ManagedImage<uint8_t> {
|
||||
Element() = default;
|
||||
Element(Element&&) = default;
|
||||
Element& operator=(Element&&) = default;
|
||||
|
||||
Element(size_t stride_bytes, size_t num_elements)
|
||||
: ManagedImage<uint8_t>(stride_bytes, num_elements)
|
||||
{}
|
||||
|
||||
using Attribute = variant<Image<float>,Image<uint32_t>,Image<uint16_t>,Image<uint8_t>>;
|
||||
// "vertex", "rgb", "normal", "uv", "tris", "quads", ...
|
||||
std::map<std::string, Attribute> attributes;
|
||||
};
|
||||
|
||||
// Store vertices and attributes
|
||||
std::map<std::string, Element> buffers;
|
||||
// Stores index buffers for each sub-object
|
||||
std::multimap<std::string, Element> objects;
|
||||
// Stores pixmaps
|
||||
std::map<std::string, TypedImage> textures;
|
||||
};
|
||||
|
||||
pangolin::Geometry::Element::Attribute MakeAttribute(uint32_t gldatatype, size_t num_items, size_t count_per_item, void* ptr, size_t pitch_bytes);
|
||||
|
||||
pangolin::Geometry LoadGeometry(const std::string& filename);
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
inline Eigen::AlignedBox3f GetAxisAlignedBox(const Geometry& geom)
|
||||
{
|
||||
Eigen::AlignedBox3f box;
|
||||
box.setEmpty();
|
||||
|
||||
for(const auto& b : geom.buffers) {
|
||||
const auto& it_vert = b.second.attributes.find("vertex");
|
||||
if(it_vert != b.second.attributes.end()) {
|
||||
const Image<float>& vs = get<Image<float>>(it_vert->second);
|
||||
for(size_t i=0; i < vs.h; ++i) {
|
||||
const Eigen::Map<const Eigen::Vector3f> v(vs.RowPtr(i));
|
||||
box.extend(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return box;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif // PANGOLIN_GEOMETRY_H
|
||||
34
Thirdparty/Pangolin/include/pangolin/geometry/geometry_obj.h
vendored
Normal file
34
Thirdparty/Pangolin/include/pangolin/geometry/geometry_obj.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include <pangolin/geometry/geometry.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
pangolin::Geometry LoadGeometryObj(const std::string& filename);
|
||||
|
||||
}
|
||||
165
Thirdparty/Pangolin/include/pangolin/geometry/geometry_ply.h
vendored
Normal file
165
Thirdparty/Pangolin/include/pangolin/geometry/geometry_ply.h
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
#include <pangolin/compat/variant.h>
|
||||
#include <pangolin/geometry/geometry.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
#define PLY_GROUP_LIST(m) m(PlyHeader) m(PlyFormat) m(PlyType)
|
||||
#define PLY_HEADER_LIST(m) m(ply) m(format) m(comment) m(property) m(element) m(end_header)
|
||||
#define PLY_FORMAT_LIST(m) m(ascii) m(binary_big_endian) m(binary_little_endian)
|
||||
#define PLY_TYPE_LIST(m) m(char) m(int8) m(uchar) m(uint8) m(short) m(int16) m(ushort) m(uint16) m(int) m(int32) m(uint) m(uint32) m(float) m(float32) m(double) m(float64) m(list)
|
||||
|
||||
// Define Enums / strings
|
||||
enum PlyHeader {
|
||||
#define FORMAT_ENUM(x) PlyHeader_##x,
|
||||
PLY_HEADER_LIST(FORMAT_ENUM)
|
||||
PlyHeaderSize
|
||||
#undef FORMAT_ENUM
|
||||
};
|
||||
|
||||
enum PlyFormat {
|
||||
#define FORMAT_ENUM(x) PlyFormat_##x,
|
||||
PLY_FORMAT_LIST(FORMAT_ENUM)
|
||||
PlyFormatSize
|
||||
#undef FORMAT_ENUM
|
||||
};
|
||||
|
||||
enum PlyType {
|
||||
#define FORMAT_ENUM(x) PlyType_##x,
|
||||
PLY_TYPE_LIST(FORMAT_ENUM)
|
||||
PlyTypeSize
|
||||
#undef FORMAT_ENUM
|
||||
};
|
||||
const size_t PlyTypeGl[] = {
|
||||
// char, int8 -> GL_BYTE
|
||||
0x1400, 0x1400,
|
||||
// uchar, uint8 -> GL_UNSIGNED_BYTE
|
||||
0x1401, 0x1401,
|
||||
// short, int16 -> GL_SHORT
|
||||
0x1402, 0x1402,
|
||||
// ushort, uint16 -> GL_UNSIGNED_SHORT
|
||||
0x1403, 0x1403,
|
||||
// int, int32 -> GL_INT
|
||||
0x1404, 0x1404,
|
||||
// uint, uint32 -> GL_UNSIGNED_INT
|
||||
0x1405, 0x1405,
|
||||
// float, float32 -> GL_FLOAT
|
||||
0x1406, 0x1406,
|
||||
// double, float64 -> GL_DOUBLE
|
||||
0x140A, 0x140A,
|
||||
// list -> GL_NONE
|
||||
0
|
||||
};
|
||||
|
||||
#undef FORMAT_ENUM
|
||||
|
||||
struct PlyPropertyDetails
|
||||
{
|
||||
std::string name;
|
||||
|
||||
// Type of property (GLenum)
|
||||
size_t type;
|
||||
|
||||
// Type of list index if a list, or 0 otherwise. (GLenum)
|
||||
size_t list_index_type;
|
||||
|
||||
// Offset from element start
|
||||
size_t offset_bytes;
|
||||
|
||||
// Number of items in the list. 1 if not a list. -1 if unknown.
|
||||
int num_items;
|
||||
|
||||
bool isList() const {
|
||||
return list_index_type > 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct PlyElementDetails
|
||||
{
|
||||
std::string name;
|
||||
int num_items;
|
||||
int stride_bytes;
|
||||
std::vector<PlyPropertyDetails> properties;
|
||||
|
||||
inline std::vector<PlyPropertyDetails>::iterator FindProperty(const std::string& name)
|
||||
{
|
||||
return std::find_if(properties.begin(), properties.end(),
|
||||
[&name](const PlyPropertyDetails& p){ return p.name == name;}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
struct PlyHeaderDetails
|
||||
{
|
||||
PlyFormat format;
|
||||
std::string version;
|
||||
std::vector<PlyElementDetails> elements;
|
||||
|
||||
inline std::vector<PlyElementDetails>::iterator FindElement(const std::string& name)
|
||||
{
|
||||
return std::find_if(elements.begin(), elements.end(),
|
||||
[&name](const PlyElementDetails& el){ return el.name == name;}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
void ParsePlyHeader(PlyHeaderDetails& ply, std::istream& is);
|
||||
|
||||
struct PlyBuffer
|
||||
{
|
||||
size_t index_size_bytes;
|
||||
size_t element_item_size_bytes;
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
void ParsePlyAscii(pangolin::Geometry& /*geom*/, const PlyHeaderDetails& /*ply*/, std::istream& /*is*/);
|
||||
|
||||
// Convert Seperate "x","y","z" attributes into a single "vertex" attribute
|
||||
void StandardizeXyzToVertex(pangolin::Geometry& geom);
|
||||
|
||||
// The Artec scanner saves with these attributes, for example
|
||||
void StandardizeMultiTextureFaceToXyzuv(pangolin::Geometry& geom);
|
||||
|
||||
void Standardize(pangolin::Geometry& geom);
|
||||
|
||||
void ParsePlyLE(pangolin::Geometry& geom, PlyHeaderDetails& ply, std::istream& is);
|
||||
|
||||
void ParsePlyBE(pangolin::Geometry& /*geom*/, const PlyHeaderDetails& /*ply*/, std::istream& /*is*/);
|
||||
|
||||
void AttachAssociatedTexturesPly(pangolin::Geometry& geom, const std::string& filename);
|
||||
|
||||
pangolin::Geometry LoadGeometryPly(const std::string& filename);
|
||||
|
||||
}
|
||||
87
Thirdparty/Pangolin/include/pangolin/geometry/glgeometry.h
vendored
Normal file
87
Thirdparty/Pangolin/include/pangolin/geometry/glgeometry.h
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/* 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/geometry/geometry.h>
|
||||
#include <pangolin/gl/gl.h>
|
||||
#include <pangolin/gl/glsl.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
struct GlGeometry
|
||||
{
|
||||
GlGeometry() = default;
|
||||
GlGeometry(GlGeometry&&) = default;
|
||||
GlGeometry& operator=(GlGeometry&&) = default;
|
||||
|
||||
struct Element : public GlBufferData
|
||||
{
|
||||
Element() = default;
|
||||
Element(Element&&) = default;
|
||||
Element& operator=(Element&&) = default;
|
||||
|
||||
Element(GlBufferType buffer_type, size_t size_bytes, GLenum gluse, uint8_t* data)
|
||||
: GlBufferData(buffer_type, size_bytes, gluse, data)
|
||||
{}
|
||||
|
||||
inline bool HasAttribute(const std::string& name) const {
|
||||
return attributes.find(name) != attributes.end();
|
||||
}
|
||||
|
||||
struct Attribute {
|
||||
// Stuff needed by glVertexAttribPointer
|
||||
GLenum gltype;
|
||||
size_t count_per_element;
|
||||
size_t num_elements;
|
||||
size_t offset;
|
||||
size_t stride_bytes;
|
||||
};
|
||||
std::map<std::string, Attribute> attributes;
|
||||
};
|
||||
|
||||
inline bool HasAttribute(const std::string& name) const
|
||||
{
|
||||
for(const auto& b : buffers) if(b.second.HasAttribute(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store vertices and attributes
|
||||
std::map<std::string, Element> buffers;
|
||||
// Stores index buffers for each sub-object
|
||||
std::multimap<std::string, Element> objects;
|
||||
// Stores pixmaps
|
||||
std::map<std::string, GlTexture> textures;
|
||||
};
|
||||
|
||||
GlGeometry::Element ToGlGeometry(const Geometry::Element& el, GlBufferType buffertype);
|
||||
|
||||
GlGeometry ToGlGeometry(const Geometry& geom);
|
||||
|
||||
void GlDraw(GlSlProgram& prog, const GlGeometry& geom, const GlTexture *matcap);
|
||||
|
||||
}
|
||||
283
Thirdparty/Pangolin/include/pangolin/gl/cg.h
vendored
Normal file
283
Thirdparty/Pangolin/include/pangolin/gl/cg.h
vendored
Normal file
@@ -0,0 +1,283 @@
|
||||
/* 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 <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
// Cg includes
|
||||
#include <Cg/cg.h>
|
||||
#include <Cg/cgGL.h>
|
||||
|
||||
#include "gl.h"
|
||||
|
||||
#ifdef HAVE_TOON
|
||||
#include <TooN/TooN.h>
|
||||
#endif // HAVE_TOON
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Interface
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/// Lightweight object wrapper for NVidia Cg Shader program objects.
|
||||
class CgProgram
|
||||
{
|
||||
friend class CgLoader;
|
||||
public:
|
||||
void SetUniform(const std::string& name, GlTexture& tex);
|
||||
void SetUniform(const std::string& name, float f);
|
||||
void SetUniform(const std::string& name, float v0, float v1);
|
||||
void SetUniform(const std::string& name, float v0, float v1, float v2, float v3);
|
||||
|
||||
#ifdef HAVE_TOON
|
||||
void SetUniform(const std::string& name, const TooN::Vector<2>& v );
|
||||
void SetUniform(const std::string& name, const TooN::Vector<3>& v );
|
||||
|
||||
template <int R, int C>
|
||||
void SetUniform(const std::string& name, const TooN::Matrix<R,C>& M );
|
||||
#endif
|
||||
|
||||
void UpdateParams();
|
||||
|
||||
protected:
|
||||
CGprogram mProg;
|
||||
CGcontext mContext;
|
||||
CGprofile mProfile;
|
||||
};
|
||||
|
||||
class CgLoader
|
||||
{
|
||||
public:
|
||||
CgLoader();
|
||||
~CgLoader();
|
||||
|
||||
// Call AFTER glewInit (or similar)
|
||||
void Initialise();
|
||||
|
||||
CgProgram LoadProgramFromFile(const std::string& file, const std::string& function, bool isVertexShader );
|
||||
|
||||
void EnableProgram(CgProgram program);
|
||||
void DisablePrograms();
|
||||
|
||||
void RenderDummyQuad();
|
||||
void RenderDummyQuadWithTexCoords(int w, int h);
|
||||
|
||||
protected:
|
||||
CGcontext mContext;
|
||||
CGprofile mFragmentProfile;
|
||||
CGprofile mVertexProfile;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Implementation
|
||||
////////////////////////////////////////////////
|
||||
|
||||
inline bool cgOkay()
|
||||
{
|
||||
CGerror error;
|
||||
const char *string = cgGetLastErrorString(&error);
|
||||
|
||||
if (error != CG_NO_ERROR) {
|
||||
std::cout << "CG Error: " << string << std::endl;
|
||||
// assert(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline CgLoader::CgLoader()
|
||||
:mContext(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline CgLoader::~CgLoader()
|
||||
{
|
||||
if(mContext)
|
||||
{
|
||||
// Destroying context destroys all programs associated with it
|
||||
cgDestroyContext(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void CgLoader::Initialise()
|
||||
{
|
||||
mContext = cgCreateContext();
|
||||
cgSetParameterSettingMode(mContext, CG_DEFERRED_PARAMETER_SETTING);
|
||||
cgOkay();
|
||||
|
||||
mFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
||||
cgGLSetOptimalOptions(mFragmentProfile);
|
||||
cgOkay();
|
||||
|
||||
mVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
|
||||
cgGLSetOptimalOptions(mVertexProfile);
|
||||
cgOkay();
|
||||
}
|
||||
|
||||
inline CgProgram CgLoader::LoadProgramFromFile(const std::string& file, const std::string& function, bool isVertexShader )
|
||||
{
|
||||
if( !mContext ) {
|
||||
Initialise();
|
||||
}
|
||||
|
||||
CgProgram prog;
|
||||
|
||||
prog.mContext = mContext;
|
||||
prog.mProfile = isVertexShader ? mVertexProfile : mFragmentProfile;
|
||||
prog.mProg = cgCreateProgramFromFile( prog.mContext, CG_SOURCE, file.c_str(), prog.mProfile, function.c_str(), NULL);
|
||||
|
||||
if( !cgOkay() )
|
||||
{
|
||||
std::cout << cgGetLastListing(mContext) << std::endl;
|
||||
assert(0);
|
||||
}
|
||||
|
||||
cgGLLoadProgram(prog.mProg);
|
||||
if( !cgOkay() )
|
||||
{
|
||||
const char* err = cgGetProgramString( prog.mProg, CG_COMPILED_PROGRAM );
|
||||
int pos;
|
||||
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
|
||||
std::cout << err << std::endl;
|
||||
std::cout << "@ " << pos << std::endl;
|
||||
assert(0);
|
||||
}
|
||||
return prog;
|
||||
}
|
||||
|
||||
inline void CgLoader::EnableProgram(CgProgram program)
|
||||
{
|
||||
cgGLBindProgram(program.mProg);
|
||||
cgGLEnableProfile(program.mProfile);
|
||||
cgOkay();
|
||||
}
|
||||
|
||||
inline void CgLoader::DisablePrograms()
|
||||
{
|
||||
cgGLDisableProfile(mFragmentProfile);
|
||||
cgGLDisableProfile(mVertexProfile);
|
||||
}
|
||||
|
||||
inline void CgLoader::RenderDummyQuad()
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2d(-1,1);
|
||||
glVertex2d(1,1);
|
||||
glVertex2d(1,-1);
|
||||
glVertex2d(-1,-1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
inline void CgLoader::RenderDummyQuadWithTexCoords(int w, int h)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2d(-1,-1);
|
||||
glTexCoord2f(w, 0);
|
||||
glVertex2d(1,-1);
|
||||
glTexCoord2f(w, h);
|
||||
glVertex2d(1,1);
|
||||
glTexCoord2f(0, h);
|
||||
glVertex2d(-1,1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CgProgram::SetUniform(const std::string& name, float f)
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
cgSetParameter1f( p, f );
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
void CgProgram::SetUniform(const std::string& name, GlTexture& tex)
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
cgGLSetTextureParameter(p, tex.tid );
|
||||
cgGLEnableTextureParameter(p);
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
void CgProgram::SetUniform(const std::string& name, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
cgGLSetParameter4f(p, v0,v1,v2,v3);
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
void CgProgram::SetUniform(const std::string& name, float v0, float v1)
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
cgGLSetParameter2f(p, v0,v1);
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
#ifdef HAVE_TOON
|
||||
void CgProgram::SetUniform(const std::string& name, const TooN::Vector<2>& v )
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
cgGLSetParameter2f(p, v[0],v[1] );
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
void CgProgram::SetUniform(const std::string& name, const TooN::Vector<3>& v )
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
cgGLSetParameter3f(p, v[0],v[1],v[2] );
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
template <int R, int C>
|
||||
void CgProgram::SetUniform(const std::string& name, const TooN::Matrix<R,C>& M )
|
||||
{
|
||||
CGparameter p = cgGetNamedParameter( mProg, name.c_str());
|
||||
float Mdata[R*C];
|
||||
|
||||
int i=0;
|
||||
for( int r=0; r<R; ++r )
|
||||
for( int c=0; c<C; ++c )
|
||||
Mdata[i++] = (float)(M[r][c]);
|
||||
|
||||
cgGLSetMatrixParameterfr(p, Mdata );
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CgProgram::UpdateParams()
|
||||
{
|
||||
cgUpdateProgramParameters(mProg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
178
Thirdparty/Pangolin/include/pangolin/gl/colour.h
vendored
Normal file
178
Thirdparty/Pangolin/include/pangolin/gl/colour.h
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
/* 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 <cmath>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
/// Represent OpenGL floating point colour: Red, Green and Blue with alpha.
|
||||
struct Colour
|
||||
{
|
||||
inline static Colour White() {
|
||||
return Colour(1.0f,1.0f,1.0f,1.0f);
|
||||
}
|
||||
inline static Colour Black() {
|
||||
return Colour(0.0f,0.0f,0.0f,1.0f);
|
||||
}
|
||||
inline static Colour Red() {
|
||||
return Colour(1.0f,0.0f,0.0f,1.0f);
|
||||
}
|
||||
inline static Colour Green() {
|
||||
return Colour(0.0f,1.0f,0.0f,1.0f);
|
||||
}
|
||||
inline static Colour Blue() {
|
||||
return Colour(0.0f,0.0f,1.0f,1.0f);
|
||||
}
|
||||
inline static Colour Unspecified() {
|
||||
return Colour(
|
||||
std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN(),
|
||||
std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::quiet_NaN()
|
||||
);
|
||||
}
|
||||
|
||||
/// Default constructs white.
|
||||
inline Colour()
|
||||
: red(1.0f), green(1.0f), blue(1.0f), alpha(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct from component values
|
||||
inline Colour(const float red, const float green, const float blue, const float alpha = 1.0f)
|
||||
: red(red), green(green), blue(blue), alpha(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct from rgba array.
|
||||
inline Colour(const float rgba[4])
|
||||
{
|
||||
r = rgba[0];
|
||||
g = rgba[1];
|
||||
b = rgba[2];
|
||||
a = rgba[3];
|
||||
}
|
||||
|
||||
/// Return pointer to OpenGL compatible RGBA array.
|
||||
inline float* Get()
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
/// Return this colour with alpha adjusted.
|
||||
inline Colour WithAlpha(const float alpha)
|
||||
{
|
||||
return Colour(r,g,b,alpha);
|
||||
}
|
||||
|
||||
/// Construct from HSV Colour
|
||||
/// @param hue Colour hue in range [0,1]
|
||||
/// @param sat Saturation in range [0,1]
|
||||
/// @param val Value / Brightness in range [0,1].
|
||||
static inline Colour Hsv(const float hue, const float sat = 1.0f, const float val = 1.0f, const float alpha = 1.0f)
|
||||
{
|
||||
const float h = 6.0f * hue;
|
||||
const int i = (int)floor(h);
|
||||
const float f = (i%2 == 0) ? 1-(h-i) : h-i;
|
||||
const float m = val * (1-sat);
|
||||
const float n = val * (1-sat*f);
|
||||
|
||||
switch(i)
|
||||
{
|
||||
case 0: return Colour(val,n,m,alpha);
|
||||
case 1: return Colour(n,val,m,alpha);
|
||||
case 2: return Colour(m,val,n,alpha);
|
||||
case 3: return Colour(m,n,val,alpha);
|
||||
case 4: return Colour(n,m,val,alpha);
|
||||
case 5: return Colour(val,m,n,alpha);
|
||||
default:
|
||||
throw std::runtime_error("Found extra colour in rainbow.");
|
||||
}
|
||||
}
|
||||
|
||||
union {
|
||||
struct {
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float alpha;
|
||||
};
|
||||
struct {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
float c[4];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/// A ColourWheel is like a continuous colour palate that can be sampled.
|
||||
/// In the future, different ColourWheels will be supported, but this one
|
||||
/// is based on sampling hues in HSV colourspace. An indefinite number of
|
||||
/// unique colours are sampled using the golden angle.
|
||||
class ColourWheel
|
||||
{
|
||||
public:
|
||||
/// Construct ColourWheel with Saturation, Value and Alpha constant.
|
||||
inline ColourWheel(float saturation = 0.5f, float value = 1.0f, float alpha = 1.0f)
|
||||
: unique_colours(0), sat(saturation), val(value), alpha(alpha)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// Use Golden ratio (/angle) to pick well spaced colours.
|
||||
inline Colour GetColourBin(int i) const
|
||||
{
|
||||
float hue = i * 0.5f * (3.0f - sqrt(5.0f));
|
||||
hue -= (int)hue;
|
||||
return Colour::Hsv(hue,sat,val,alpha);
|
||||
}
|
||||
|
||||
/// Return next unique colour from ColourWheel.
|
||||
inline Colour GetUniqueColour()
|
||||
{
|
||||
return GetColourBin(unique_colours++);
|
||||
}
|
||||
|
||||
/// Reset colour wheel counter to initial state
|
||||
inline void Reset() {
|
||||
unique_colours = 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
int unique_colours;
|
||||
float sat;
|
||||
float val;
|
||||
float alpha;
|
||||
};
|
||||
|
||||
}
|
||||
320
Thirdparty/Pangolin/include/pangolin/gl/compat/gl2engine.h
vendored
Normal file
320
Thirdparty/Pangolin/include/pangolin/gl/compat/gl2engine.h
vendored
Normal file
@@ -0,0 +1,320 @@
|
||||
/* 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 <stack>
|
||||
|
||||
#include <pangolin/opengl_render_state.h>
|
||||
#include <pangolin/glsl.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
class GlEngine
|
||||
{
|
||||
public:
|
||||
const char* vert =
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec4 a_color;\n"
|
||||
"attribute vec3 a_normal;\n"
|
||||
"attribute vec2 a_texcoord;\n"
|
||||
"uniform vec4 u_color;\n"
|
||||
"uniform mat4 u_modelViewMatrix;\n"
|
||||
"uniform mat4 u_modelViewProjectionMatrix;\n"
|
||||
"varying vec4 v_frontColor;\n"
|
||||
"varying vec2 v_texcoord;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_modelViewProjectionMatrix * a_position;\n"
|
||||
" v_frontColor = u_color;\n"
|
||||
" v_texcoord = a_texcoord;\n"
|
||||
"}\n";
|
||||
|
||||
const char* frag =
|
||||
#ifdef HAVE_GLES_2
|
||||
"precision mediump float;\n"
|
||||
#endif // HAVE_GLES_2
|
||||
"varying vec4 v_frontColor;\n"
|
||||
"varying vec2 v_texcoord;\n"
|
||||
"uniform sampler2D u_texture;\n"
|
||||
"uniform bool u_textureEnable;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = v_frontColor;\n"
|
||||
" if(u_textureEnable) {\n"
|
||||
" gl_FragColor *= texture2D(u_texture, v_texcoord);\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
GlEngine()
|
||||
{
|
||||
// Initialise default state
|
||||
projection.push(IdentityMatrix());
|
||||
modelview.push(IdentityMatrix());
|
||||
currentmatrix = &modelview;
|
||||
|
||||
// Set GL_TEXTURE0 as default active texture
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// Compile and link shaders
|
||||
prog_fixed.AddShader(GlSlVertexShader, vert);
|
||||
prog_fixed.AddShader(GlSlFragmentShader, frag);
|
||||
prog_fixed.BindPangolinDefaultAttribLocationsAndLink();
|
||||
|
||||
// Save locations of uniforms
|
||||
u_color = prog_fixed.GetUniformHandle("u_color");
|
||||
u_modelViewMatrix = prog_fixed.GetUniformHandle("u_modelViewMatrix");
|
||||
u_modelViewProjectionMatrix = prog_fixed.GetUniformHandle("u_modelViewProjectionMatrix");
|
||||
u_texture = prog_fixed.GetUniformHandle("u_texture");
|
||||
u_textureEnable = prog_fixed.GetUniformHandle("u_textureEnable");
|
||||
|
||||
// Initialise default uniform values
|
||||
UpdateMatrices();
|
||||
SetColor(1.0,1.0,1.0,1.0);
|
||||
}
|
||||
|
||||
void UpdateMatrices()
|
||||
{
|
||||
OpenGlMatrix pmv = projection.top() * modelview.top();
|
||||
prog_fixed.SaveBind();
|
||||
glUniformMatrix4fv( u_modelViewMatrix, 1, false, modelview.top().m );
|
||||
glUniformMatrix4fv( u_modelViewProjectionMatrix, 1, false, pmv.m );
|
||||
prog_fixed.Unbind();
|
||||
}
|
||||
|
||||
void SetColor(float r, float g, float b, float a)
|
||||
{
|
||||
prog_fixed.SaveBind();
|
||||
glUniform4f( u_color, r, g, b, a);
|
||||
prog_fixed.Unbind();
|
||||
}
|
||||
|
||||
void EnableTexturing(GLboolean v)
|
||||
{
|
||||
prog_fixed.SaveBind();
|
||||
glUniform1i( u_textureEnable, v);
|
||||
prog_fixed.Unbind();
|
||||
}
|
||||
|
||||
//protected:
|
||||
std::stack<OpenGlMatrix> projection;
|
||||
std::stack<OpenGlMatrix> modelview;
|
||||
std::stack<OpenGlMatrix>* currentmatrix;
|
||||
|
||||
GLenum matrixmode;
|
||||
|
||||
float color[4];
|
||||
|
||||
GlSlProgram prog_fixed;
|
||||
|
||||
GLint u_color;
|
||||
GLint u_modelViewMatrix;
|
||||
GLint u_modelViewProjectionMatrix;
|
||||
GLint u_texture;
|
||||
GLint u_textureEnable;
|
||||
};
|
||||
|
||||
GlEngine& glEngine();
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL 1.0 compatibility - Emulate fixed pipeline
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Missing defines that we'll be using
|
||||
#define GL_MODELVIEW 0x1700
|
||||
#define GL_PROJECTION 0x1701
|
||||
#define GL_SHADE_MODEL 0x0B54
|
||||
#define GL_POINT_SIZE 0x0B11
|
||||
|
||||
#define GL_MULTISAMPLE 0x809D
|
||||
|
||||
#define GL_LIGHTING 0x0B50
|
||||
#define GL_POINT_SMOOTH 0x0B10
|
||||
#define GL_LINE_SMOOTH 0x0B20
|
||||
#define GL_SCISSOR_TEST 0x0C11
|
||||
#define GL_COLOR_MATERIAL 0x0B57
|
||||
|
||||
#define GL_FLAT 0x1D00
|
||||
#define GL_SMOOTH 0x1D01
|
||||
|
||||
#define GL_MODULATE 0x2100
|
||||
#define GL_DECAL 0x2101
|
||||
#define GL_ADD 0x0104
|
||||
#define GL_TEXTURE_ENV_MODE 0x2200
|
||||
#define GL_TEXTURE_ENV_COLOR 0x2201
|
||||
#define GL_TEXTURE_ENV 0x2300
|
||||
|
||||
#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
|
||||
#define GL_POINT_SMOOTH_HINT 0x0C51
|
||||
#define GL_LINE_SMOOTH_HINT 0x0C52
|
||||
|
||||
#define GL_VERTEX_ARRAY 0x8074
|
||||
#define GL_NORMAL_ARRAY 0x8075
|
||||
#define GL_COLOR_ARRAY 0x8076
|
||||
#define GL_TEXTURE_COORD_ARRAY 0x8078
|
||||
|
||||
inline void glEnableClientState(GLenum cap)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
if(cap == GL_VERTEX_ARRAY) {
|
||||
glEnableVertexAttribArray(pangolin::DEFAULT_LOCATION_POSITION);
|
||||
}else if(cap == GL_COLOR_ARRAY) {
|
||||
glEnableVertexAttribArray(pangolin::DEFAULT_LOCATION_COLOUR);
|
||||
}else if(cap == GL_NORMAL_ARRAY) {
|
||||
glEnableVertexAttribArray(pangolin::DEFAULT_LOCATION_NORMAL);
|
||||
}else if(cap == GL_TEXTURE_COORD_ARRAY) {
|
||||
glEnableVertexAttribArray(pangolin::DEFAULT_LOCATION_TEXCOORD);
|
||||
gl.EnableTexturing(true);
|
||||
}else{
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glDisableClientState(GLenum cap)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
if(cap == GL_VERTEX_ARRAY) {
|
||||
glDisableVertexAttribArray(pangolin::DEFAULT_LOCATION_POSITION);
|
||||
}else if(cap == GL_COLOR_ARRAY) {
|
||||
glDisableVertexAttribArray(pangolin::DEFAULT_LOCATION_COLOUR);
|
||||
}else if(cap == GL_NORMAL_ARRAY) {
|
||||
glDisableVertexAttribArray(pangolin::DEFAULT_LOCATION_NORMAL);
|
||||
}else if(cap == GL_TEXTURE_COORD_ARRAY) {
|
||||
glDisableVertexAttribArray(pangolin::DEFAULT_LOCATION_TEXCOORD);
|
||||
gl.EnableTexturing(false);
|
||||
}else{
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid * pointer)
|
||||
{
|
||||
glVertexAttribPointer(pangolin::DEFAULT_LOCATION_POSITION, size, type, GL_FALSE, stride, pointer);
|
||||
}
|
||||
|
||||
inline void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid * pointer)
|
||||
{
|
||||
glVertexAttribPointer(pangolin::DEFAULT_LOCATION_TEXCOORD, size, type, GL_FALSE, stride, pointer);
|
||||
}
|
||||
|
||||
inline void glMatrixMode(GLenum mode)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
gl.currentmatrix = (mode == pangolin::GlProjectionStack) ? &gl.projection : &gl.modelview;
|
||||
}
|
||||
|
||||
inline void glLoadIdentity()
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
gl.currentmatrix->top() = pangolin::IdentityMatrix();
|
||||
gl.UpdateMatrices();
|
||||
}
|
||||
|
||||
inline void glLoadMatrixf(const GLfloat* m)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
pangolin::GLprecision* cm = gl.currentmatrix->top().m;
|
||||
for(int i=0; i<16; ++i) cm[i] = (pangolin::GLprecision)m[i];
|
||||
gl.UpdateMatrices();
|
||||
}
|
||||
|
||||
inline void glLoadMatrixd(const GLdouble* m)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
pangolin::GLprecision* cm = gl.currentmatrix->top().m;
|
||||
for(int i=0; i<16; ++i) cm[i] = (pangolin::GLprecision)m[i];
|
||||
gl.UpdateMatrices();
|
||||
}
|
||||
|
||||
inline void glMultMatrixf(const GLfloat* m)
|
||||
{
|
||||
// pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
// float res[16];
|
||||
// pangolin::MatMul<4,4,4,float>(res, m, gl.currentmatrix->m );
|
||||
// std::memcpy(gl.currentmatrix->m, res, sizeof(float) * 16 );
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
inline void glMultMatrixd(const GLdouble* m)
|
||||
{
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
inline void glPushMatrix(void)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
gl.currentmatrix->push(gl.currentmatrix->top());
|
||||
}
|
||||
|
||||
inline void glPopMatrix(void)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
gl.currentmatrix->pop();
|
||||
gl.UpdateMatrices();
|
||||
}
|
||||
|
||||
inline void glTranslatef(GLfloat x, GLfloat y, GLfloat z )
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
pangolin::GLprecision* cm = gl.currentmatrix->top().m;
|
||||
cm[12] += x;
|
||||
cm[13] += y;
|
||||
cm[14] += z;
|
||||
gl.UpdateMatrices();
|
||||
}
|
||||
|
||||
inline void glOrtho(
|
||||
GLdouble l, GLdouble r,
|
||||
GLdouble b, GLdouble t,
|
||||
GLdouble n, GLdouble f)
|
||||
{
|
||||
pangolin::GlEngine& gl = pangolin::glEngine();
|
||||
gl.currentmatrix->top() = pangolin::ProjectionMatrixOrthographic(l,r,b,t,n,f);
|
||||
gl.UpdateMatrices();
|
||||
}
|
||||
|
||||
inline void glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
|
||||
{
|
||||
pangolin::glEngine().SetColor(red,green,blue,alpha);
|
||||
}
|
||||
|
||||
inline void glShadeModel( GLenum mode)
|
||||
{
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
inline void glPointSize(GLfloat size)
|
||||
{
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
inline void glTexEnvf( GLenum target,
|
||||
GLenum pname,
|
||||
GLfloat param)
|
||||
{
|
||||
pango_print_error("Not Implemented: %s, %s, %d", __FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
60
Thirdparty/Pangolin/include/pangolin/gl/compat/gl_es_compat.h
vendored
Normal file
60
Thirdparty/Pangolin/include/pangolin/gl/compat/gl_es_compat.h
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
#define GLdouble GLfloat
|
||||
#define glClearDepth glClearDepthf
|
||||
#define glFrustum glFrustumf
|
||||
|
||||
#define glColor4fv(a) glColor4f(a[0], a[1], a[2], a[3])
|
||||
#define glColor3fv(a) glColor4f(a[0], a[1], a[2], 1.0f)
|
||||
#define glColor3f(a,b,c) glColor4f(a, b, c, 1.0f)
|
||||
|
||||
#define GL_CLAMP GL_CLAMP_TO_EDGE
|
||||
|
||||
#ifdef HAVE_GLES_2
|
||||
#define glGenFramebuffersEXT glGenFramebuffers
|
||||
#define glDeleteFramebuffersEXT glDeleteFramebuffers
|
||||
#define glBindFramebufferEXT glBindFramebuffer
|
||||
#define glDrawBuffers glDrawBuffers
|
||||
#define glFramebufferTexture2DEXT glFramebufferTexture2D
|
||||
#define GL_FRAMEBUFFER_EXT GL_FRAMEBUFFER
|
||||
#define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT16 // <----
|
||||
#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0
|
||||
#define GL_DEPTH_ATTACHMENT_EXT GL_DEPTH_ATTACHMENT
|
||||
#else
|
||||
#define glOrtho glOrthof
|
||||
#define glGenFramebuffersEXT glGenFramebuffersOES
|
||||
#define glDeleteFramebuffersEXT glDeleteFramebuffersOES
|
||||
#define glBindFramebufferEXT glBindFramebufferOES
|
||||
#define glDrawBuffers glDrawBuffersOES
|
||||
#define glFramebufferTexture2DEXT glFramebufferTexture2DOES
|
||||
#define GL_FRAMEBUFFER_EXT GL_FRAMEBUFFER_OES
|
||||
#define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
|
||||
#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0_OES
|
||||
#endif
|
||||
|
||||
#define glGetDoublev glGetFloatv
|
||||
|
||||
#ifdef HAVE_GLES_2
|
||||
#include <pangolin/gl2engine.h>
|
||||
#endif
|
||||
|
||||
inline void glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
|
||||
{
|
||||
GLfloat verts[] = { x1,y1, x2,y1, x2,y2, x1,y2 };
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
inline void glRecti(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
GLfloat verts[] = { (float)x1,(float)y1, (float)x2,(float)y1,
|
||||
(float)x2,(float)y2, (float)x1,(float)y2 };
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
273
Thirdparty/Pangolin/include/pangolin/gl/gl.h
vendored
Normal file
273
Thirdparty/Pangolin/include/pangolin/gl/gl.h
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
/* 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/viewport.h>
|
||||
#include <pangolin/gl/glinclude.h>
|
||||
#include <pangolin/image/image_io.h>
|
||||
|
||||
#if defined(HAVE_EIGEN) && !defined(__CUDACC__) //prevent including Eigen in cuda files
|
||||
#define USE_EIGEN
|
||||
#endif
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
#include <Eigen/Core>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Interface
|
||||
////////////////////////////////////////////////
|
||||
|
||||
class PANGOLIN_EXPORT GlTexture
|
||||
{
|
||||
public:
|
||||
//! internal_format normally one of GL_RGBA8, GL_LUMINANCE8, GL_INTENSITY16
|
||||
GlTexture(GLint width, GLint height, GLint internal_format = GL_RGBA8, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL );
|
||||
|
||||
// Construct this texture from a CPU image
|
||||
GlTexture(const TypedImage& img, bool sampling_linear=true);
|
||||
|
||||
//! Move Constructor / asignment
|
||||
GlTexture(GlTexture&& tex);
|
||||
GlTexture& operator=(GlTexture&& tex);
|
||||
|
||||
//! Default constructor represents 'no texture'
|
||||
GlTexture();
|
||||
virtual ~GlTexture();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
//! Delete OpenGL resources and fall back to representing 'no texture'
|
||||
void Delete();
|
||||
|
||||
//! Reinitialise teture width / height / format
|
||||
virtual void Reinitialise(GLsizei width, GLsizei height, GLint internal_format = GL_RGBA8, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL );
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
|
||||
//! data_layout normally one of GL_LUMINANCE, GL_RGB, ...
|
||||
//! data_type normally one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT
|
||||
void Upload(const void* image, GLenum data_format = GL_LUMINANCE, GLenum data_type = GL_FLOAT);
|
||||
|
||||
//! Upload data to texture, overwriting a sub-region of it.
|
||||
//! data ptr contains packed data_w x data_h of pixel data.
|
||||
void Upload(const void* data,
|
||||
GLsizei tex_x_offset, GLsizei tex_y_offset,
|
||||
GLsizei data_w, GLsizei data_h,
|
||||
GLenum data_format, GLenum data_type
|
||||
);
|
||||
|
||||
void Load(const TypedImage& image, bool sampling_linear = true);
|
||||
|
||||
void LoadFromFile(const std::string& filename, bool sampling_linear = true);
|
||||
|
||||
void Download(void* image, GLenum data_layout = GL_LUMINANCE, GLenum data_type = GL_FLOAT) const;
|
||||
|
||||
void Download(TypedImage& image) const;
|
||||
|
||||
void CopyFrom(const GlTexture& tex);
|
||||
|
||||
void Save(const std::string& filename, bool top_line_first = true);
|
||||
|
||||
void SetLinear();
|
||||
void SetNearestNeighbour();
|
||||
|
||||
void RenderToViewport(const bool flip) const;
|
||||
void RenderToViewport() const;
|
||||
void RenderToViewport(Viewport tex_vp, bool flipx=false, bool flipy=false) const;
|
||||
void RenderToViewportFlipY() const;
|
||||
void RenderToViewportFlipXFlipY() const;
|
||||
|
||||
GLint internal_format;
|
||||
GLuint tid;
|
||||
GLint width;
|
||||
GLint height;
|
||||
|
||||
private:
|
||||
// Private copy constructor
|
||||
GlTexture(const GlTexture&) {}
|
||||
};
|
||||
|
||||
struct PANGOLIN_EXPORT GlRenderBuffer
|
||||
{
|
||||
GlRenderBuffer();
|
||||
GlRenderBuffer(GLint width, GLint height, GLint internal_format = GL_DEPTH_COMPONENT24);
|
||||
|
||||
void Reinitialise(GLint width, GLint height, GLint internal_format = GL_DEPTH_COMPONENT24);
|
||||
|
||||
//! Move Constructor
|
||||
GlRenderBuffer(GlRenderBuffer&& tex);
|
||||
|
||||
~GlRenderBuffer();
|
||||
|
||||
GLint width;
|
||||
GLint height;
|
||||
GLuint rbid;
|
||||
|
||||
private:
|
||||
// Private copy constructor
|
||||
GlRenderBuffer(const GlRenderBuffer&) {}
|
||||
};
|
||||
|
||||
struct PANGOLIN_EXPORT GlFramebuffer
|
||||
{
|
||||
GlFramebuffer();
|
||||
~GlFramebuffer();
|
||||
|
||||
GlFramebuffer(GlTexture& colour, GlRenderBuffer& depth);
|
||||
GlFramebuffer(GlTexture& colour0, GlTexture& colour1, GlRenderBuffer& depth);
|
||||
GlFramebuffer(GlTexture& colour0, GlTexture& colour1, GlTexture& colour2, GlRenderBuffer& depth);
|
||||
GlFramebuffer(GlTexture& colour0, GlTexture& colour1, GlTexture& colour2, GlTexture& colour3, GlRenderBuffer& depth);
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
|
||||
void Reinitialise();
|
||||
|
||||
// Attach Colour texture to frame buffer
|
||||
// Return attachment texture is bound to (e.g. GL_COLOR_ATTACHMENT0_EXT)
|
||||
GLenum AttachColour(GlTexture& tex);
|
||||
|
||||
// Attach Depth render buffer to frame buffer
|
||||
void AttachDepth(GlRenderBuffer& rb);
|
||||
|
||||
GLuint fbid;
|
||||
unsigned attachments;
|
||||
};
|
||||
|
||||
enum GlBufferType
|
||||
{
|
||||
GlUndefined = 0,
|
||||
GlArrayBuffer = GL_ARRAY_BUFFER, // VBO's, CBO's, NBO's
|
||||
GlElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER, // IBO's
|
||||
#ifndef HAVE_GLES
|
||||
GlPixelPackBuffer = GL_PIXEL_PACK_BUFFER, // PBO's
|
||||
GlPixelUnpackBuffer = GL_PIXEL_UNPACK_BUFFER,
|
||||
GlShaderStorageBuffer = GL_SHADER_STORAGE_BUFFER
|
||||
#endif
|
||||
};
|
||||
|
||||
// This encapsulates a GL Buffer object.
|
||||
struct PANGOLIN_EXPORT GlBufferData
|
||||
{
|
||||
//! Default constructor represents 'no buffer'
|
||||
GlBufferData();
|
||||
GlBufferData(GlBufferType buffer_type, GLuint size_bytes, GLenum gluse = GL_DYNAMIC_DRAW, const unsigned char* data = 0 );
|
||||
virtual ~GlBufferData();
|
||||
void Free();
|
||||
|
||||
//! Move Constructor
|
||||
GlBufferData(GlBufferData&& tex);
|
||||
GlBufferData& operator=(GlBufferData&& tex);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
size_t SizeBytes() const;
|
||||
|
||||
void Reinitialise(GlBufferType buffer_type, GLuint size_bytes, GLenum gluse = GL_DYNAMIC_DRAW, const unsigned char* data = 0 );
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
void Upload(const GLvoid* data, GLsizeiptr size_bytes, GLintptr offset = 0);
|
||||
void Download(GLvoid* ptr, GLsizeiptr size_bytes, GLintptr offset = 0) const;
|
||||
|
||||
GLuint bo;
|
||||
GlBufferType buffer_type;
|
||||
GLenum gluse;
|
||||
GLuint size_bytes;
|
||||
|
||||
private:
|
||||
GlBufferData(const GlBufferData&) {}
|
||||
};
|
||||
|
||||
// This encapsulates a GL Buffer object, also storing information about its contents.
|
||||
// You should try to use GlBufferData instead.
|
||||
struct PANGOLIN_EXPORT GlBuffer : public GlBufferData
|
||||
{
|
||||
//! Default constructor represents 'no buffer'
|
||||
GlBuffer();
|
||||
GlBuffer(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse = GL_DYNAMIC_DRAW );
|
||||
GlBuffer(const GlBuffer&) = delete;
|
||||
|
||||
//! Move Constructor
|
||||
GlBuffer(GlBuffer&& tex);
|
||||
GlBuffer& operator=(GlBuffer&& tex);
|
||||
|
||||
void Reinitialise(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse, const unsigned char* data = nullptr );
|
||||
void Reinitialise(GlBuffer const& other );
|
||||
void Resize(GLuint num_elements);
|
||||
|
||||
GLenum datatype;
|
||||
GLuint num_elements;
|
||||
GLuint count_per_element;
|
||||
};
|
||||
|
||||
class PANGOLIN_EXPORT GlSizeableBuffer
|
||||
: public pangolin::GlBuffer
|
||||
{
|
||||
public:
|
||||
GlSizeableBuffer(pangolin::GlBufferType buffer_type, GLuint initial_num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse = GL_DYNAMIC_DRAW );
|
||||
|
||||
void Clear();
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
template<typename Derived>
|
||||
void Add(const Eigen::DenseBase<Derived>& vec);
|
||||
|
||||
template<typename Derived>
|
||||
void Update(const Eigen::DenseBase<Derived>& vec, size_t position = 0);
|
||||
#endif
|
||||
|
||||
size_t start() const;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
protected:
|
||||
void CheckResize(size_t num_verts);
|
||||
|
||||
size_t NextSize(size_t min_size) const;
|
||||
|
||||
size_t m_num_verts;
|
||||
};
|
||||
|
||||
size_t GlFormatChannels(GLenum data_layout);
|
||||
|
||||
size_t GlDataTypeBytes(GLenum type);
|
||||
|
||||
}
|
||||
|
||||
// Include implementation
|
||||
#include <pangolin/gl/gl.hpp>
|
||||
866
Thirdparty/Pangolin/include/pangolin/gl/gl.hpp
vendored
Normal file
866
Thirdparty/Pangolin/include/pangolin/gl/gl.hpp
vendored
Normal file
@@ -0,0 +1,866 @@
|
||||
/* 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/gl.h>
|
||||
#include <pangolin/gl/glpixformat.h>
|
||||
#include <pangolin/display/display.h>
|
||||
#include <pangolin/image/image_io.h>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Implementation of gl.h
|
||||
////////////////////////////////////////////////
|
||||
|
||||
#ifndef HAVE_GLES
|
||||
const int MAX_ATTACHMENTS = 8;
|
||||
const static GLuint attachment_buffers[] = {
|
||||
GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_COLOR_ATTACHMENT1_EXT,
|
||||
GL_COLOR_ATTACHMENT2_EXT,
|
||||
GL_COLOR_ATTACHMENT3_EXT,
|
||||
GL_COLOR_ATTACHMENT4_EXT,
|
||||
GL_COLOR_ATTACHMENT5_EXT,
|
||||
GL_COLOR_ATTACHMENT6_EXT,
|
||||
GL_COLOR_ATTACHMENT7_EXT
|
||||
};
|
||||
#else // HAVE_GLES
|
||||
const int MAX_ATTACHMENTS = 1;
|
||||
const static GLuint attachment_buffers[] = {
|
||||
GL_COLOR_ATTACHMENT0_EXT
|
||||
};
|
||||
#endif // HAVE_GLES
|
||||
|
||||
const static size_t datatype_bytes[] = {
|
||||
1, // #define GL_BYTE 0x1400
|
||||
1, // #define GL_UNSIGNED_BYTE 0x1401
|
||||
2, // #define GL_SHORT 0x1402
|
||||
2, // #define GL_UNSIGNED_SHORT 0x1403
|
||||
4, // #define GL_INT 0x1404
|
||||
4, // #define GL_UNSIGNED_INT 0x1405
|
||||
4, // #define GL_FLOAT 0x1406
|
||||
2, // #define GL_2_BYTES 0x1407
|
||||
3, // #define GL_3_BYTES 0x1408
|
||||
4, // #define GL_4_BYTES 0x1409
|
||||
8 // #define GL_DOUBLE 0x140A
|
||||
};
|
||||
|
||||
const static size_t format_channels[] = {
|
||||
1, // #define GL_RED 0x1903
|
||||
1, // #define GL_GREEN 0x1904
|
||||
1, // #define GL_BLUE 0x1905
|
||||
1, // #define GL_ALPHA 0x1906
|
||||
3, // #define GL_RGB 0x1907
|
||||
4, // #define GL_RGBA 0x1908
|
||||
1, // #define GL_LUMINANCE 0x1909
|
||||
2 // #define GL_LUMINANCE_ALPHA 0x190A
|
||||
};
|
||||
|
||||
inline size_t GlDataTypeBytes(GLenum type)
|
||||
{
|
||||
return datatype_bytes[type - GL_BYTE];
|
||||
}
|
||||
|
||||
inline size_t GlFormatChannels(GLenum data_layout)
|
||||
{
|
||||
if (data_layout == GL_BGR) return 3;
|
||||
if (data_layout == GL_BGRA) return 4;
|
||||
return format_channels[data_layout - GL_RED];
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//struct GlDataTypeTrait {};
|
||||
//template<> struct GlDataTypeTrait<float>{ static const GLenum type = GL_FLOAT; };
|
||||
//template<> struct GlDataTypeTrait<int>{ static const GLenum type = GL_INT; };
|
||||
//template<> struct GlDataTypeTrait<unsigned char>{ static const GLenum type = GL_UNSIGNED_BYTE; };
|
||||
|
||||
inline GlTexture::GlTexture()
|
||||
: internal_format(0), tid(0), width(0), height(0)
|
||||
{
|
||||
// Not a texture constructor
|
||||
}
|
||||
|
||||
inline GlTexture::GlTexture(GLint width, GLint height, GLint internal_format, bool sampling_linear, int border, GLenum glformat, GLenum gltype, GLvoid* data )
|
||||
: internal_format(0), tid(0)
|
||||
{
|
||||
Reinitialise(width,height,internal_format,sampling_linear,border,glformat,gltype,data);
|
||||
}
|
||||
|
||||
inline GlTexture::GlTexture(const TypedImage& img, bool sampling_linear)
|
||||
{
|
||||
this->Load(img, sampling_linear);
|
||||
}
|
||||
|
||||
inline GlTexture::GlTexture(GlTexture&& tex)
|
||||
{
|
||||
*this = std::move(tex);
|
||||
}
|
||||
|
||||
inline GlTexture& GlTexture::operator=(GlTexture&& tex)
|
||||
{
|
||||
if (&tex != this) {
|
||||
internal_format = tex.internal_format;
|
||||
tid = tex.tid;
|
||||
width = tex.width;
|
||||
height = tex.height;
|
||||
|
||||
tex.internal_format = 0;
|
||||
tex.tid = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool GlTexture::IsValid() const
|
||||
{
|
||||
return tid != 0;
|
||||
}
|
||||
|
||||
inline void GlTexture::Delete()
|
||||
{
|
||||
// We have no GL context whilst exiting.
|
||||
if(internal_format!=0 && !pangolin::ShouldQuit() ) {
|
||||
glDeleteTextures(1,&tid);
|
||||
internal_format = 0;
|
||||
tid = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline GlTexture::~GlTexture()
|
||||
{
|
||||
// We have no GL context whilst exiting.
|
||||
if(internal_format!=0 && !pangolin::ShouldQuit() ) {
|
||||
glDeleteTextures(1,&tid);
|
||||
}
|
||||
}
|
||||
|
||||
inline void GlTexture::Bind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, tid);
|
||||
}
|
||||
|
||||
inline void GlTexture::Unbind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
inline void GlTexture::Reinitialise(GLsizei w, GLsizei h, GLint int_format, bool sampling_linear, int border, GLenum glformat, GLenum gltype, GLvoid* data )
|
||||
{
|
||||
if(tid!=0) {
|
||||
glDeleteTextures(1,&tid);
|
||||
}
|
||||
|
||||
internal_format = int_format;
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
glGenTextures(1,&tid);
|
||||
Bind();
|
||||
|
||||
// GL_LUMINANCE and GL_FLOAT don't seem to actually affect buffer, but some values are required
|
||||
// for call to succeed.
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, border, glformat, gltype, data);
|
||||
|
||||
if(sampling_linear) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}else{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline void GlTexture::Upload(
|
||||
const void* data,
|
||||
GLenum data_format, GLenum data_type
|
||||
) {
|
||||
Bind();
|
||||
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,data_format,data_type,data);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline void GlTexture::Upload(
|
||||
const void* data,
|
||||
GLsizei tex_x_offset, GLsizei tex_y_offset,
|
||||
GLsizei data_w, GLsizei data_h,
|
||||
GLenum data_format, GLenum data_type )
|
||||
{
|
||||
Bind();
|
||||
glTexSubImage2D(GL_TEXTURE_2D,0,tex_x_offset,tex_y_offset,data_w,data_h,data_format,data_type,data);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline void GlTexture::Load(const TypedImage& image, bool sampling_linear)
|
||||
{
|
||||
GlPixFormat fmt(image.fmt);
|
||||
Reinitialise((GLint)image.w, (GLint)image.h, GL_RGBA32F, sampling_linear, 0, fmt.glformat, fmt.gltype, image.ptr );
|
||||
}
|
||||
|
||||
inline void GlTexture::LoadFromFile(const std::string& filename, bool sampling_linear)
|
||||
{
|
||||
TypedImage image = LoadImage(filename);
|
||||
Load(image, sampling_linear);
|
||||
}
|
||||
|
||||
#ifndef HAVE_GLES
|
||||
inline void GlTexture::Download(void* image, GLenum data_layout, GLenum data_type) const
|
||||
{
|
||||
Bind();
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, data_layout, data_type, image);
|
||||
Unbind();
|
||||
}
|
||||
|
||||
inline void GlTexture::Download(TypedImage& image) const
|
||||
{
|
||||
switch (internal_format)
|
||||
{
|
||||
case GL_LUMINANCE8:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("GRAY8") );
|
||||
Download(image.ptr, GL_LUMINANCE, GL_UNSIGNED_BYTE);
|
||||
break;
|
||||
case GL_LUMINANCE16:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("GRAY16LE") );
|
||||
Download(image.ptr, GL_LUMINANCE, GL_UNSIGNED_SHORT);
|
||||
break;
|
||||
case GL_RGB8:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("RGB24"));
|
||||
Download(image.ptr, GL_RGB, GL_UNSIGNED_BYTE);
|
||||
break;
|
||||
case GL_RGBA8:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("RGBA32"));
|
||||
Download(image.ptr, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||
break;
|
||||
case GL_RGB16:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("RGB48"));
|
||||
Download(image.ptr, GL_RGB, GL_UNSIGNED_SHORT);
|
||||
break;
|
||||
case GL_RGBA16:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("RGBA64"));
|
||||
Download(image.ptr, GL_RGBA, GL_UNSIGNED_SHORT);
|
||||
break;
|
||||
case GL_LUMINANCE:
|
||||
case GL_LUMINANCE32F_ARB:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("GRAY32F"));
|
||||
Download(image.ptr, GL_LUMINANCE, GL_FLOAT);
|
||||
break;
|
||||
case GL_RGB:
|
||||
case GL_RGB32F:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("RGB96F"));
|
||||
Download(image.ptr, GL_RGB, GL_FLOAT);
|
||||
break;
|
||||
case GL_RGBA:
|
||||
case GL_RGBA32F:
|
||||
image.Reinitialise(width, height, PixelFormatFromString("RGBA128F"));
|
||||
Download(image.ptr, GL_RGBA, GL_FLOAT);
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
"GlTexture::Download - Unknown internal format (" +
|
||||
pangolin::Convert<std::string,GLint>::Do(internal_format) +
|
||||
")"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void GlTexture::CopyFrom(const GlTexture& tex)
|
||||
{
|
||||
if(!tid || width != tex.width || height != tex.height ||
|
||||
internal_format != tex.internal_format)
|
||||
{
|
||||
Reinitialise(tex.width, tex.height, tex.internal_format, true);
|
||||
}
|
||||
|
||||
glCopyImageSubData(tex.tid, GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
tid, GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
width, height, 1);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline void GlTexture::Save(const std::string& filename, bool top_line_first)
|
||||
{
|
||||
TypedImage image;
|
||||
Download(image);
|
||||
pangolin::SaveImage(image, filename, top_line_first);
|
||||
}
|
||||
#endif // HAVE_GLES
|
||||
|
||||
inline void GlTexture::SetLinear()
|
||||
{
|
||||
Bind();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
Unbind();
|
||||
}
|
||||
|
||||
inline void GlTexture::SetNearestNeighbour()
|
||||
{
|
||||
Bind();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
Unbind();
|
||||
}
|
||||
|
||||
inline void GlTexture::RenderToViewport(const bool flip) const
|
||||
{
|
||||
if(flip) {
|
||||
RenderToViewportFlipY();
|
||||
}else{
|
||||
RenderToViewport();
|
||||
}
|
||||
}
|
||||
|
||||
inline void GlTexture::RenderToViewport() const
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
GLfloat sq_vert[] = { -1,-1, 1,-1, 1, 1, -1, 1 };
|
||||
glVertexPointer(2, GL_FLOAT, 0, sq_vert);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
GLfloat sq_tex[] = { 0,0, 1,0, 1,1, 0,1 };
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, sq_tex);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
Bind();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
inline void GlTexture::RenderToViewport(Viewport tex_vp, bool flipx, bool flipy) const
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
GLfloat sq_vert[] = { -1,-1, 1,-1, 1, 1, -1, 1 };
|
||||
glVertexPointer(2, GL_FLOAT, 0, sq_vert);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
GLfloat l = tex_vp.l / (float)(width);
|
||||
GLfloat b = tex_vp.b / (float)(height);
|
||||
GLfloat r = (tex_vp.l+tex_vp.w) / (float)(width);
|
||||
GLfloat t = (tex_vp.b+tex_vp.h) / (float)(height);
|
||||
|
||||
if(flipx) std::swap(l,r);
|
||||
if(flipy) std::swap(b,t);
|
||||
|
||||
GLfloat sq_tex[] = { l,b, r,b, r,t, l,t };
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, sq_tex);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
Bind();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
inline void GlTexture::RenderToViewportFlipY() const
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
GLfloat sq_vert[] = { -1,-1, 1,-1, 1, 1, -1, 1 };
|
||||
glVertexPointer(2, GL_FLOAT, 0, sq_vert);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
GLfloat sq_tex[] = { 0,1, 1,1, 1,0, 0,0 };
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, sq_tex);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
Bind();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
inline void GlTexture::RenderToViewportFlipXFlipY() const
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
GLfloat sq_vert[] = { 1,1, -1,1, -1,-1, 1,-1 };
|
||||
glVertexPointer(2, GL_FLOAT, 0, sq_vert);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
GLfloat sq_tex[] = { 0,0, 1,0, 1,1, 0,1 };
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, sq_tex);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
Bind();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline GlRenderBuffer::GlRenderBuffer()
|
||||
: width(0), height(0), rbid(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline GlRenderBuffer::GlRenderBuffer(GLint width, GLint height, GLint internal_format )
|
||||
: width(0), height(0), rbid(0)
|
||||
{
|
||||
Reinitialise(width,height,internal_format);
|
||||
}
|
||||
|
||||
#ifndef HAVE_GLES
|
||||
inline void GlRenderBuffer::Reinitialise(GLint width, GLint height, GLint internal_format)
|
||||
{
|
||||
if( this->width != 0 ) {
|
||||
glDeleteRenderbuffersEXT(1, &rbid);
|
||||
}
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
glGenRenderbuffersEXT(1, &rbid);
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbid);
|
||||
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internal_format, width, height);
|
||||
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
|
||||
}
|
||||
|
||||
inline GlRenderBuffer::~GlRenderBuffer()
|
||||
{
|
||||
// We have no GL context whilst exiting.
|
||||
if( width!=0 && !pangolin::ShouldQuit() ) {
|
||||
glDeleteRenderbuffersEXT(1, &rbid);
|
||||
}
|
||||
}
|
||||
#else
|
||||
inline void GlRenderBuffer::Reinitialise(GLint width, GLint height, GLint internal_format)
|
||||
{
|
||||
if( width!=0 ) {
|
||||
glDeleteTextures(1, &rbid);
|
||||
}
|
||||
|
||||
// Use a texture instead...
|
||||
glGenTextures(1, &rbid);
|
||||
glBindTexture(GL_TEXTURE_2D, rbid);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internal_format,
|
||||
width, height,
|
||||
0, internal_format, GL_UNSIGNED_SHORT, NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
inline GlRenderBuffer::~GlRenderBuffer()
|
||||
{
|
||||
// We have no GL context whilst exiting.
|
||||
if( width!=0 && !pangolin::ShouldQuit() ) {
|
||||
glDeleteTextures(1, &rbid);
|
||||
}
|
||||
}
|
||||
#endif // HAVE_GLES
|
||||
|
||||
inline GlRenderBuffer::GlRenderBuffer(GlRenderBuffer&& tex)
|
||||
: width(tex.width), height(tex.height), rbid(tex.rbid)
|
||||
{
|
||||
tex.rbid = tex.width = tex.height = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline GlFramebuffer::GlFramebuffer()
|
||||
: fbid(0), attachments(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline GlFramebuffer::~GlFramebuffer()
|
||||
{
|
||||
if(fbid) {
|
||||
glDeleteFramebuffersEXT(1, &fbid);
|
||||
}
|
||||
}
|
||||
|
||||
inline GlFramebuffer::GlFramebuffer(GlTexture& colour, GlRenderBuffer& depth)
|
||||
: attachments(0)
|
||||
{
|
||||
glGenFramebuffersEXT(1, &fbid);
|
||||
AttachColour(colour);
|
||||
AttachDepth(depth);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline GlFramebuffer::GlFramebuffer(GlTexture& colour0, GlTexture& colour1, GlRenderBuffer& depth)
|
||||
: attachments(0)
|
||||
{
|
||||
glGenFramebuffersEXT(1, &fbid);
|
||||
AttachColour(colour0);
|
||||
AttachColour(colour1);
|
||||
AttachDepth(depth);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline GlFramebuffer::GlFramebuffer(GlTexture& colour0, GlTexture& colour1, GlTexture& colour2, GlRenderBuffer& depth)
|
||||
: attachments(0)
|
||||
{
|
||||
glGenFramebuffersEXT(1, &fbid);
|
||||
AttachColour(colour0);
|
||||
AttachColour(colour1);
|
||||
AttachColour(colour2);
|
||||
AttachDepth(depth);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline GlFramebuffer::GlFramebuffer(GlTexture& colour0, GlTexture& colour1, GlTexture& colour2, GlTexture& colour3, GlRenderBuffer& depth)
|
||||
: attachments(0)
|
||||
{
|
||||
glGenFramebuffersEXT(1, &fbid);
|
||||
AttachColour(colour0);
|
||||
AttachColour(colour1);
|
||||
AttachColour(colour2);
|
||||
AttachColour(colour3);
|
||||
AttachDepth(depth);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
inline void GlFramebuffer::Bind() const
|
||||
{
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbid);
|
||||
#ifndef HAVE_GLES
|
||||
glDrawBuffers( attachments, attachment_buffers );
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void GlFramebuffer::Reinitialise()
|
||||
{
|
||||
if(fbid) {
|
||||
glDeleteFramebuffersEXT(1, &fbid);
|
||||
}
|
||||
glGenFramebuffersEXT(1, &fbid);
|
||||
}
|
||||
|
||||
inline void GlFramebuffer::Unbind() const
|
||||
{
|
||||
#ifndef HAVE_GLES
|
||||
glDrawBuffers( 1, attachment_buffers );
|
||||
#endif
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
}
|
||||
|
||||
inline GLenum GlFramebuffer::AttachColour(GlTexture& tex )
|
||||
{
|
||||
if(!fbid) Reinitialise();
|
||||
|
||||
const GLenum color_attachment = GL_COLOR_ATTACHMENT0_EXT + attachments;
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbid);
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, color_attachment, GL_TEXTURE_2D, tex.tid, 0);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
attachments++;
|
||||
CheckGlDieOnError();
|
||||
return color_attachment;
|
||||
}
|
||||
|
||||
inline void GlFramebuffer::AttachDepth(GlRenderBuffer& rb )
|
||||
{
|
||||
if(!fbid) Reinitialise();
|
||||
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbid);
|
||||
#if !defined(HAVE_GLES)
|
||||
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb.rbid);
|
||||
#elif defined(HAVE_GLES_2)
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, rb.rbid, 0);
|
||||
#else
|
||||
throw std::exception();
|
||||
#endif
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
CheckGlDieOnError();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline GlBufferData::GlBufferData()
|
||||
: bo(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline GlBufferData::GlBufferData(GlBufferType buffer_type, GLuint size_bytes, GLenum gluse, const unsigned char* data )
|
||||
: bo(0)
|
||||
{
|
||||
Reinitialise(buffer_type, size_bytes, gluse, data );
|
||||
}
|
||||
|
||||
//! Move Constructor
|
||||
inline GlBufferData::GlBufferData(GlBufferData&& tex)
|
||||
: bo(0)
|
||||
{
|
||||
*this = std::move(tex);
|
||||
}
|
||||
inline GlBufferData& GlBufferData::operator=(GlBufferData&& tex)
|
||||
{
|
||||
Free();
|
||||
this->bo = tex.bo;
|
||||
this->buffer_type = tex.buffer_type;
|
||||
this->gluse = tex.gluse;
|
||||
this->size_bytes = tex.size_bytes;
|
||||
tex.bo = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline GlBufferData::~GlBufferData()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline void GlBufferData::Free()
|
||||
{
|
||||
if(bo!=0) {
|
||||
glDeleteBuffers(1, &bo);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool GlBufferData::IsValid() const
|
||||
{
|
||||
return bo != 0;
|
||||
}
|
||||
|
||||
inline size_t GlBufferData::SizeBytes() const
|
||||
{
|
||||
return size_bytes;
|
||||
}
|
||||
|
||||
inline void GlBufferData::Reinitialise(GlBufferType buffer_type, GLuint size_bytes, GLenum gluse, const unsigned char* data )
|
||||
{
|
||||
if(!bo) {
|
||||
glGenBuffers(1, &bo);
|
||||
}
|
||||
|
||||
this->buffer_type = buffer_type;
|
||||
this->gluse = gluse;
|
||||
this->size_bytes = size_bytes;
|
||||
|
||||
Bind();
|
||||
glBufferData(buffer_type, size_bytes, data, gluse);
|
||||
Unbind();
|
||||
}
|
||||
|
||||
inline void GlBufferData::Bind() const
|
||||
{
|
||||
glBindBuffer(buffer_type, bo);
|
||||
}
|
||||
|
||||
inline void GlBufferData::Unbind() const
|
||||
{
|
||||
glBindBuffer(buffer_type, 0);
|
||||
}
|
||||
|
||||
inline void GlBufferData::Upload(const GLvoid* data, GLsizeiptr size_bytes, GLintptr offset)
|
||||
{
|
||||
if(offset + size_bytes > this->size_bytes) {
|
||||
throw std::runtime_error("GlBufferData: Trying to upload past capacity.");
|
||||
}
|
||||
|
||||
Bind();
|
||||
glBufferSubData(buffer_type,offset,size_bytes,data);
|
||||
Unbind();
|
||||
}
|
||||
|
||||
inline void GlBufferData::Download(GLvoid* data, GLsizeiptr size_bytes, GLintptr offset) const
|
||||
{
|
||||
Bind();
|
||||
glGetBufferSubData(buffer_type, offset, size_bytes, data);
|
||||
Unbind();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline GlBuffer::GlBuffer()
|
||||
: GlBufferData(), num_elements(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline GlBuffer::GlBuffer(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse )
|
||||
: GlBufferData(buffer_type, num_elements * count_per_element * GlDataTypeBytes(datatype), gluse),
|
||||
datatype(datatype), num_elements(num_elements), count_per_element(count_per_element)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline GlBuffer::GlBuffer(GlBuffer&& o)
|
||||
: GlBufferData()
|
||||
{
|
||||
*this = std::move(o);
|
||||
}
|
||||
|
||||
inline GlBuffer& GlBuffer::operator=(GlBuffer&& o)
|
||||
{
|
||||
datatype = o.datatype;
|
||||
num_elements = o.num_elements;
|
||||
count_per_element = o.count_per_element;
|
||||
GlBufferData::operator =(std::move(o));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void GlBuffer::Reinitialise(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse, const unsigned char* data )
|
||||
{
|
||||
this->datatype = datatype;
|
||||
this->num_elements = num_elements;
|
||||
this->count_per_element = count_per_element;
|
||||
const GLuint size_bytes = num_elements * count_per_element * GlDataTypeBytes(datatype);
|
||||
GlBufferData::Reinitialise(buffer_type, size_bytes, gluse, data);
|
||||
}
|
||||
|
||||
inline void GlBuffer::Reinitialise(GlBuffer const& other )
|
||||
{
|
||||
Reinitialise(other.buffer_type, other.num_elements, other.datatype, other.count_per_element, other.gluse);
|
||||
}
|
||||
|
||||
inline void GlBuffer::Resize(GLuint new_num_elements)
|
||||
{
|
||||
if(bo!=0) {
|
||||
#ifndef HAVE_GLES
|
||||
// Backup current data, reinit memory, restore old data
|
||||
const size_t backup_elements = std::min(new_num_elements,num_elements);
|
||||
const size_t backup_size_bytes = backup_elements*GlDataTypeBytes(datatype)*count_per_element;
|
||||
unsigned char* backup = new unsigned char[backup_size_bytes];
|
||||
Bind();
|
||||
glGetBufferSubData(buffer_type, 0, backup_size_bytes, backup);
|
||||
glBufferData(buffer_type, new_num_elements*GlDataTypeBytes(datatype)*count_per_element, 0, gluse);
|
||||
glBufferSubData(buffer_type, 0, backup_size_bytes, backup);
|
||||
Unbind();
|
||||
delete[] backup;
|
||||
#else
|
||||
throw std::exception();
|
||||
#endif
|
||||
}else{
|
||||
Reinitialise(buffer_type, new_num_elements, datatype, count_per_element, gluse);
|
||||
}
|
||||
num_elements = new_num_elements;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline GlSizeableBuffer::GlSizeableBuffer(GlBufferType buffer_type, GLuint initial_num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse )
|
||||
: GlBuffer(buffer_type, initial_num_elements, datatype, count_per_element, gluse), m_num_verts(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
inline void GlSizeableBuffer::Clear()
|
||||
{
|
||||
m_num_verts = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
template<typename Derived> inline
|
||||
void GlSizeableBuffer::Add(const Eigen::DenseBase<Derived>& vec)
|
||||
{
|
||||
typedef typename Eigen::DenseBase<Derived>::Scalar Scalar;
|
||||
assert(vec.rows()==GlBuffer::count_per_element);
|
||||
CheckResize(m_num_verts + 1);
|
||||
// TODO: taking address of first element is really dodgey. Need to work out
|
||||
// when this is okay!
|
||||
Upload(&vec(0,0), sizeof(Scalar)*vec.rows()*vec.cols(), sizeof(Scalar)*vec.rows()*m_num_verts);
|
||||
m_num_verts += vec.cols();
|
||||
}
|
||||
|
||||
template<typename Derived> inline
|
||||
void GlSizeableBuffer::Update(const Eigen::DenseBase<Derived>& vec, size_t position )
|
||||
{
|
||||
typedef typename Eigen::DenseBase<Derived>::Scalar Scalar;
|
||||
assert(vec.rows()==GlBuffer::count_per_element);
|
||||
CheckResize(position + vec.cols() );
|
||||
// TODO: taking address of first element is really dodgey. Need to work out
|
||||
// when this is okay!
|
||||
Upload(&vec(0,0), sizeof(Scalar)*vec.rows()*vec.cols(), sizeof(Scalar)*vec.rows()*position );
|
||||
m_num_verts = std::max(position+vec.cols(), m_num_verts);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline size_t GlSizeableBuffer::start() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline size_t GlSizeableBuffer::size() const {
|
||||
return m_num_verts;
|
||||
}
|
||||
|
||||
inline void GlSizeableBuffer::CheckResize(size_t num_verts)
|
||||
{
|
||||
if( num_verts > GlBuffer::num_elements) {
|
||||
const size_t new_size = NextSize(num_verts);
|
||||
GlBuffer::Resize((GLuint)new_size);
|
||||
}
|
||||
}
|
||||
|
||||
inline size_t GlSizeableBuffer::NextSize(size_t min_size) const
|
||||
{
|
||||
size_t new_size = std::max(GlBuffer::num_elements, 1u);
|
||||
while(new_size < min_size) {
|
||||
new_size *= 2;
|
||||
}
|
||||
return new_size;
|
||||
}
|
||||
|
||||
}
|
||||
78
Thirdparty/Pangolin/include/pangolin/gl/glchar.h
vendored
Normal file
78
Thirdparty/Pangolin/include/pangolin/gl/glchar.h
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/* 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 <pangolin/gl/glplatform.h>
|
||||
#include <map>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
struct PANGOLIN_EXPORT XYUV
|
||||
{
|
||||
XYUV() {}
|
||||
XYUV(GLfloat x, GLfloat y, GLfloat tu, GLfloat tv)
|
||||
: x(x), y(y), tu(tu), tv(tv) {}
|
||||
|
||||
XYUV operator+(float dx) const {
|
||||
return XYUV(x+dx,y,tu,tv);
|
||||
}
|
||||
|
||||
GLfloat x, y, tu, tv;
|
||||
};
|
||||
|
||||
class PANGOLIN_EXPORT GlChar
|
||||
{
|
||||
public:
|
||||
GlChar();
|
||||
GlChar(int tw, int th, int x, int y, int w, int h, GLfloat x_step, GLfloat ox, GLfloat oy);
|
||||
|
||||
inline const XYUV& GetVert(size_t i) const {
|
||||
return vs[i];
|
||||
}
|
||||
|
||||
inline GLfloat StepX() const {
|
||||
return x_step;
|
||||
}
|
||||
|
||||
inline GLfloat YMin() const {
|
||||
return y_min;
|
||||
}
|
||||
|
||||
inline GLfloat YMax() const {
|
||||
return y_max;
|
||||
}
|
||||
|
||||
void Draw() const;
|
||||
|
||||
protected:
|
||||
XYUV vs[4];
|
||||
GLfloat x_step;
|
||||
GLfloat y_min, y_max;
|
||||
};
|
||||
|
||||
}
|
||||
258
Thirdparty/Pangolin/include/pangolin/gl/glcuda.h
vendored
Normal file
258
Thirdparty/Pangolin/include/pangolin/gl/glcuda.h
vendored
Normal file
@@ -0,0 +1,258 @@
|
||||
/* 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 <algorithm>
|
||||
#include <cuda_runtime.h>
|
||||
#include <cuda_gl_interop.h>
|
||||
|
||||
#include "gl.h"
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Interface
|
||||
////////////////////////////////////////////////
|
||||
|
||||
struct GlBufferCudaPtr : public GlBuffer
|
||||
{
|
||||
//! Default constructor represents 'no buffer'
|
||||
GlBufferCudaPtr();
|
||||
|
||||
GlBufferCudaPtr(GlBufferType buffer_type, GLuint size_bytes, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ );
|
||||
GlBufferCudaPtr(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ );
|
||||
|
||||
PANGOLIN_DEPRECATED
|
||||
GlBufferCudaPtr(GlBufferType buffer_type, GLuint width, GLuint height, GLenum datatype, GLuint count_per_element, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ );
|
||||
|
||||
~GlBufferCudaPtr();
|
||||
|
||||
void Reinitialise(GlBufferType buffer_type, GLuint size_bytes, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ );
|
||||
void Reinitialise(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ );
|
||||
|
||||
/**
|
||||
* Use parameters from another @c GlBufferCudaPtr to initialize this buffer.
|
||||
*/
|
||||
void Reinitialise(const GlBufferCudaPtr& other);
|
||||
|
||||
unsigned int cuda_use;
|
||||
cudaGraphicsResource* cuda_res;
|
||||
};
|
||||
|
||||
struct GlTextureCudaArray : GlTexture
|
||||
{
|
||||
GlTextureCudaArray();
|
||||
// Some internal_formats aren't accepted. I have trouble with GL_RGB8
|
||||
GlTextureCudaArray(int width, int height, GLint internal_format, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL);
|
||||
~GlTextureCudaArray();
|
||||
|
||||
void Reinitialise(int width, int height, GLint internal_format, bool sampling_linear = true, int border = 0, GLenum glformat = GL_RGBA, GLenum gltype = GL_UNSIGNED_BYTE, GLvoid* data = NULL) override;
|
||||
cudaGraphicsResource* cuda_res;
|
||||
};
|
||||
|
||||
struct CudaScopedMappedPtr
|
||||
{
|
||||
CudaScopedMappedPtr(const GlBufferCudaPtr& buffer);
|
||||
~CudaScopedMappedPtr();
|
||||
void* operator*();
|
||||
cudaGraphicsResource* res;
|
||||
|
||||
private:
|
||||
CudaScopedMappedPtr(const CudaScopedMappedPtr&) {}
|
||||
};
|
||||
|
||||
struct CudaScopedMappedArray
|
||||
{
|
||||
CudaScopedMappedArray(const GlTextureCudaArray& tex);
|
||||
~CudaScopedMappedArray();
|
||||
cudaArray* operator*();
|
||||
cudaGraphicsResource* res;
|
||||
|
||||
private:
|
||||
CudaScopedMappedArray(const CudaScopedMappedArray&) {}
|
||||
};
|
||||
|
||||
void CopyPboToTex(GlBufferCudaPtr& buffer, GlTexture& tex);
|
||||
|
||||
void swap(GlBufferCudaPtr& a, GlBufferCudaPtr& b);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Implementation
|
||||
////////////////////////////////////////////////
|
||||
|
||||
inline GlBufferCudaPtr::GlBufferCudaPtr()
|
||||
: cuda_res(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline GlBufferCudaPtr::GlBufferCudaPtr(GlBufferType buffer_type, GLuint size_bytes, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ )
|
||||
: cuda_res(0)
|
||||
{
|
||||
Reinitialise(buffer_type, size_bytes, cudause, gluse);
|
||||
}
|
||||
|
||||
inline GlBufferCudaPtr::GlBufferCudaPtr(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, unsigned int cudause, GLenum gluse )
|
||||
: cuda_res(0)
|
||||
{
|
||||
Reinitialise(buffer_type, num_elements, datatype, count_per_element, cudause, gluse);
|
||||
}
|
||||
|
||||
inline GlBufferCudaPtr::GlBufferCudaPtr(GlBufferType buffer_type, GLuint width, GLuint height, GLenum datatype, GLuint count_per_element, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ )
|
||||
: cuda_res(0)
|
||||
{
|
||||
Reinitialise(buffer_type, width*height, datatype, count_per_element, cudause, gluse);
|
||||
}
|
||||
|
||||
inline GlBufferCudaPtr::~GlBufferCudaPtr()
|
||||
{
|
||||
if(cuda_res) {
|
||||
cudaGraphicsUnregisterResource(cuda_res);
|
||||
}
|
||||
}
|
||||
|
||||
inline void GlBufferCudaPtr::Reinitialise(GlBufferType buffer_type, GLuint size_bytes, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ )
|
||||
{
|
||||
GlBufferCudaPtr::Reinitialise(buffer_type, size_bytes, GL_BYTE, 1, cudause, gluse);
|
||||
}
|
||||
|
||||
inline void GlBufferCudaPtr::Reinitialise(GlBufferType buffer_type, GLuint num_elements, GLenum datatype, GLuint count_per_element, unsigned int cudause /*= cudaGraphicsMapFlagsNone*/, GLenum gluse /*= GL_DYNAMIC_DRAW*/ )
|
||||
{
|
||||
if(cuda_res) {
|
||||
cudaGraphicsUnregisterResource(cuda_res);
|
||||
}
|
||||
GlBuffer::Reinitialise(buffer_type, num_elements, datatype, count_per_element, gluse);
|
||||
|
||||
cuda_use = cudause;
|
||||
cudaGraphicsGLRegisterBuffer( &cuda_res, bo, cudause );
|
||||
}
|
||||
|
||||
inline void GlBufferCudaPtr::Reinitialise(const GlBufferCudaPtr& other)
|
||||
{
|
||||
Reinitialise(other.buffer_type, other.num_elements, other.datatype, other.count_per_element, other.cuda_use, other.gluse);
|
||||
}
|
||||
|
||||
inline GlTextureCudaArray::GlTextureCudaArray()
|
||||
: GlTexture(), cuda_res(0)
|
||||
{
|
||||
// Not a texture
|
||||
}
|
||||
|
||||
inline GlTextureCudaArray::GlTextureCudaArray(int width, int height, GLint internal_format, bool sampling_linear, int border, GLenum glformat, GLenum gltype, GLvoid *data)
|
||||
:GlTexture(width,height,internal_format, sampling_linear, border, glformat, gltype, data)
|
||||
{
|
||||
// TODO: specify flags too
|
||||
const cudaError_t err = cudaGraphicsGLRegisterImage(&cuda_res, tid, GL_TEXTURE_2D, cudaGraphicsMapFlagsNone);
|
||||
if( err != cudaSuccess ) {
|
||||
std::cout << "cudaGraphicsGLRegisterImage failed: " << err << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
inline GlTextureCudaArray::~GlTextureCudaArray()
|
||||
{
|
||||
if(cuda_res) {
|
||||
cudaGraphicsUnregisterResource(cuda_res);
|
||||
}
|
||||
}
|
||||
|
||||
inline void GlTextureCudaArray::Reinitialise(int width, int height, GLint internal_format, bool sampling_linear, int border, GLenum glformat, GLenum gltype, GLvoid* data)
|
||||
{
|
||||
if(cuda_res) {
|
||||
cudaGraphicsUnregisterResource(cuda_res);
|
||||
}
|
||||
|
||||
GlTexture::Reinitialise(width, height, internal_format, sampling_linear, border, glformat, gltype, data);
|
||||
|
||||
const cudaError_t err = cudaGraphicsGLRegisterImage(&cuda_res, tid, GL_TEXTURE_2D, cudaGraphicsMapFlagsNone);
|
||||
if( err != cudaSuccess ) {
|
||||
std::cout << "cudaGraphicsGLRegisterImage failed: " << err << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
inline CudaScopedMappedPtr::CudaScopedMappedPtr(const GlBufferCudaPtr& buffer)
|
||||
: res(buffer.cuda_res)
|
||||
{
|
||||
cudaGraphicsMapResources(1, &res, 0);
|
||||
}
|
||||
|
||||
inline CudaScopedMappedPtr::~CudaScopedMappedPtr()
|
||||
{
|
||||
cudaGraphicsUnmapResources(1, &res, 0);
|
||||
}
|
||||
|
||||
inline void* CudaScopedMappedPtr::operator*()
|
||||
{
|
||||
size_t num_bytes;
|
||||
void* d_ptr;
|
||||
cudaGraphicsResourceGetMappedPointer(&d_ptr,&num_bytes,res);
|
||||
return d_ptr;
|
||||
}
|
||||
|
||||
inline CudaScopedMappedArray::CudaScopedMappedArray(const GlTextureCudaArray& tex)
|
||||
: res(tex.cuda_res)
|
||||
{
|
||||
cudaGraphicsMapResources(1, &res);
|
||||
}
|
||||
|
||||
inline CudaScopedMappedArray::~CudaScopedMappedArray()
|
||||
{
|
||||
cudaGraphicsUnmapResources(1, &res);
|
||||
}
|
||||
|
||||
inline cudaArray* CudaScopedMappedArray::operator*()
|
||||
{
|
||||
cudaArray* array;
|
||||
cudaGraphicsSubResourceGetMappedArray(&array, res, 0, 0);
|
||||
return array;
|
||||
}
|
||||
|
||||
inline void CopyPboToTex(const GlBufferCudaPtr& buffer, GlTexture& tex, GLenum buffer_layout, GLenum buffer_data_type )
|
||||
{
|
||||
buffer.Bind();
|
||||
tex.Bind();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, tex.internal_format, tex.width, tex.height, 0, buffer_layout, buffer_data_type, 0);
|
||||
buffer.Unbind();
|
||||
tex.Unbind();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void CopyDevMemtoTex(T* d_img, size_t pitch, GlTextureCudaArray& tex )
|
||||
{
|
||||
CudaScopedMappedArray arr_tex(tex);
|
||||
cudaMemcpy2DToArray(*arr_tex, 0, 0, d_img, pitch, tex.width*sizeof(T), tex.height, cudaMemcpyDeviceToDevice );
|
||||
}
|
||||
|
||||
inline void swap(GlBufferCudaPtr& a, GlBufferCudaPtr& b)
|
||||
{
|
||||
std::swap(a.bo, b.bo);
|
||||
std::swap(a.cuda_res, b.cuda_res);
|
||||
std::swap(a.buffer_type, b.buffer_type);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
518
Thirdparty/Pangolin/include/pangolin/gl/gldraw.h
vendored
Normal file
518
Thirdparty/Pangolin/include/pangolin/gl/gldraw.h
vendored
Normal file
@@ -0,0 +1,518 @@
|
||||
/* 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/gl/glformattraits.h>
|
||||
#include <pangolin/display/opengl_render_state.h>
|
||||
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
|
||||
#if defined(HAVE_EIGEN) && !defined(__CUDACC__) //prevent including Eigen in cuda files
|
||||
#define USE_EIGEN
|
||||
#endif
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/src/Geometry/AlignedBox.h>
|
||||
#endif // USE_EIGEN
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
// h [0,360)
|
||||
// s [0,1]
|
||||
// v [0,1]
|
||||
inline void glColorHSV( GLfloat hue, GLfloat s=1.0f, GLfloat v=1.0f )
|
||||
{
|
||||
const GLfloat h = hue / 60.0f;
|
||||
const int i = (int)floor(h);
|
||||
const GLfloat f = (i%2 == 0) ? 1-(h-i) : h-i;
|
||||
const GLfloat m = v * (1-s);
|
||||
const GLfloat n = v * (1-s*f);
|
||||
switch(i)
|
||||
{
|
||||
case 0: glColor4f(v,n,m,1); break;
|
||||
case 1: glColor4f(n,v,m,1); break;
|
||||
case 2: glColor4f(m,v,n,1); break;
|
||||
case 3: glColor4f(m,n,v,1); break;
|
||||
case 4: glColor4f(n,m,v,1); break;
|
||||
case 5: glColor4f(v,m,n,1); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void glColorBin( int bin, int max_bins, GLfloat sat=1.0f, GLfloat val=1.0f )
|
||||
{
|
||||
if( bin >= 0 ) {
|
||||
const GLfloat hue = (GLfloat)(bin%max_bins) * 360.0f / (GLfloat)max_bins;
|
||||
glColorHSV(hue,sat,val);
|
||||
}else{
|
||||
glColor4f(1,1,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void glDrawVertices(
|
||||
size_t num_vertices, const T* const vertex_ptr, GLenum mode,
|
||||
size_t elements_per_vertex = GlFormatTraits<T>::components,
|
||||
size_t vertex_stride_bytes = 0 )
|
||||
{
|
||||
if(num_vertices > 0)
|
||||
{
|
||||
PANGO_ENSURE(vertex_ptr != nullptr);
|
||||
PANGO_ENSURE(mode != GL_LINES || num_vertices % 2 == 0, "number of vertices (%) must be even in GL_LINES mode", num_vertices );
|
||||
|
||||
glVertexPointer(elements_per_vertex, GlFormatTraits<T>::gltype, vertex_stride_bytes, vertex_ptr);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glDrawArrays(mode, 0, num_vertices);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TV, typename TC>
|
||||
inline void glDrawColoredVertices(
|
||||
size_t num_vertices, const TV* const vertex_ptr, const TC* const color_ptr, GLenum mode,
|
||||
size_t elements_per_vertex = GlFormatTraits<TV>::components,
|
||||
size_t elements_per_color = GlFormatTraits<TC>::components,
|
||||
size_t vertex_stride_bytes = 0,
|
||||
size_t color_stride_bytes = 0
|
||||
) {
|
||||
if(color_ptr) {
|
||||
glColorPointer(elements_per_color, GlFormatTraits<TC>::gltype, color_stride_bytes, color_ptr);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glDrawVertices<TV>(num_vertices, vertex_ptr, mode, elements_per_vertex, vertex_stride_bytes);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
}else{
|
||||
glDrawVertices<TV>(num_vertices, vertex_ptr, mode, elements_per_vertex, vertex_stride_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glDrawLine( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
|
||||
{
|
||||
const GLfloat verts[] = { x1,y1, x2,y2 };
|
||||
glDrawVertices<float>(2, verts, GL_LINES, 2);
|
||||
}
|
||||
|
||||
inline void glDrawLine( GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2)
|
||||
{
|
||||
const GLfloat verts[] = { x1,y1,z1, x2,y2,z2 };
|
||||
glDrawVertices<float>(2, verts, GL_LINES, 3);
|
||||
}
|
||||
|
||||
inline void glDrawCross( GLfloat x, GLfloat y, GLfloat rad )
|
||||
{
|
||||
const GLfloat verts[] = { x-rad,y, x+rad, y, x,y-rad, x, y+rad};
|
||||
glDrawVertices<float>(4, verts, GL_LINES, 2);
|
||||
}
|
||||
|
||||
inline void glDrawCross( GLfloat x, GLfloat y, GLfloat z, GLfloat rad )
|
||||
{
|
||||
const GLfloat verts[] = { x-rad,y,z, x+rad,y,z, x,y-rad,z, x,y+rad,z, x,y,z-rad, x,y,z+rad };
|
||||
glDrawVertices<float>(6, verts, GL_LINES, 3);
|
||||
}
|
||||
|
||||
inline void glDrawAxis(float s)
|
||||
{
|
||||
const GLfloat cols[] = { 1,0,0, 1,0,0, 0,1,0, 0,1,0, 0,0,1, 0,0,1 };
|
||||
const GLfloat verts[] = { 0,0,0, s,0,0, 0,0,0, 0,s,0, 0,0,0, 0,0,s };
|
||||
glDrawColoredVertices<float,float>(6, verts, cols, GL_LINES, 3, 3);
|
||||
}
|
||||
|
||||
inline void glDrawRect( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLenum mode = GL_TRIANGLE_FAN )
|
||||
{
|
||||
const GLfloat verts[] = { x1,y1, x2,y1, x2,y2, x1,y2 };
|
||||
glDrawVertices<float>(4, verts, mode, 2);
|
||||
}
|
||||
|
||||
inline void glDrawRectPerimeter( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
|
||||
{
|
||||
glDrawRect(x1,y1, x2,y2, GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
inline void glDrawCirclePerimeter( float x, float y, float rad )
|
||||
{
|
||||
const int N = 50;
|
||||
GLfloat verts[N*2];
|
||||
|
||||
const float TAU_DIV_N = 2*(float)M_PI/N;
|
||||
for(int i = 0; i < N*2; i+=2) {
|
||||
verts[i] = x + rad * cos(i*TAU_DIV_N);
|
||||
verts[i+1] = y + rad * sin(i*TAU_DIV_N);
|
||||
}
|
||||
|
||||
glDrawVertices<float>(N, verts, GL_LINES, 2);
|
||||
}
|
||||
|
||||
inline void glDrawCircle( GLfloat x, GLfloat y, GLfloat rad )
|
||||
{
|
||||
const int N = 50;
|
||||
GLfloat verts[N*2];
|
||||
|
||||
// Draw vertices anticlockwise for front face
|
||||
const float TAU_DIV_N = 2*(float)M_PI/N;
|
||||
for(int i = 0; i < N*2; i+=2) {
|
||||
verts[i] = x + rad * cos(-i*TAU_DIV_N);
|
||||
verts[i+1] = y + rad * sin(-i*TAU_DIV_N);
|
||||
}
|
||||
|
||||
// Render filled shape and outline (to make it look smooth)
|
||||
glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, N);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, N);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
inline void glDrawColouredCube(GLfloat axis_min=-0.5f, GLfloat axis_max = +0.5f)
|
||||
{
|
||||
const GLfloat l = axis_min;
|
||||
const GLfloat h = axis_max;
|
||||
|
||||
const GLfloat verts[] = {
|
||||
l,l,h, h,l,h, l,h,h, h,h,h, // FRONT
|
||||
l,l,l, l,h,l, h,l,l, h,h,l, // BACK
|
||||
l,l,h, l,h,h, l,l,l, l,h,l, // LEFT
|
||||
h,l,l, h,h,l, h,l,h, h,h,h, // RIGHT
|
||||
l,h,h, h,h,h, l,h,l, h,h,l, // TOP
|
||||
l,l,h, l,l,l, h,l,h, h,l,l // BOTTOM
|
||||
};
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, 0, verts);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
|
||||
|
||||
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
|
||||
|
||||
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
inline void glDraw_x0(GLfloat scale, int grid)
|
||||
{
|
||||
const GLfloat maxord = grid*scale;
|
||||
for (int i = -grid; i <= grid; ++i) {
|
||||
glDrawLine(0.0, i*scale, -maxord, 0.0, i*scale, +maxord);
|
||||
glDrawLine(0.0, -maxord, i*scale, 0.0, +maxord, i*scale);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glDraw_y0(GLfloat scale, int grid)
|
||||
{
|
||||
const GLfloat maxord = grid*scale;
|
||||
for (int i = -grid; i <= grid; ++i) {
|
||||
glDrawLine(i*scale, 0.0, -maxord, i*scale, 0.0, +maxord);
|
||||
glDrawLine(-maxord, 0.0, i*scale, +maxord, 0.0, i*scale);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glDraw_z0(GLfloat scale, int grid)
|
||||
{
|
||||
const GLfloat maxord = grid*scale;
|
||||
for(int i=-grid; i<=grid; ++i ) {
|
||||
glDrawLine(i*scale,-maxord, i*scale,+maxord);
|
||||
glDrawLine(-maxord, i*scale, +maxord, i*scale);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glDrawFrustum( GLfloat u0, GLfloat v0, GLfloat fu, GLfloat fv, int w, int h, GLfloat scale )
|
||||
{
|
||||
const GLfloat xl = scale * u0;
|
||||
const GLfloat xh = scale * (w*fu + u0);
|
||||
const GLfloat yl = scale * v0;
|
||||
const GLfloat yh = scale * (h*fv + v0);
|
||||
|
||||
const GLfloat verts[] = {
|
||||
xl,yl,scale, xh,yl,scale,
|
||||
xh,yh,scale, xl,yh,scale,
|
||||
xl,yl,scale, 0,0,0,
|
||||
xh,yl,scale, 0,0,0,
|
||||
xl,yh,scale, 0,0,0,
|
||||
xh,yh,scale
|
||||
};
|
||||
|
||||
glDrawVertices(11, verts, GL_LINE_STRIP, 3);
|
||||
}
|
||||
|
||||
inline void glDrawTexture(GLenum target, GLuint texid)
|
||||
{
|
||||
glBindTexture(target, texid);
|
||||
glEnable(target);
|
||||
|
||||
const GLfloat sq_vert[] = { -1,-1, 1,-1, 1, 1, -1, 1 };
|
||||
glVertexPointer(2, GL_FLOAT, 0, sq_vert);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
const GLfloat sq_tex[] = { 0,0, 1,0, 1,1, 0,1 };
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, sq_tex);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glColor4f(1,1,1,1);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(target);
|
||||
}
|
||||
|
||||
inline void glDrawTextureFlipY(GLenum target, GLuint texid)
|
||||
{
|
||||
glBindTexture(target, texid);
|
||||
glEnable(target);
|
||||
|
||||
const GLfloat sq_vert[] = { -1,-1, 1,-1, 1, 1, -1, 1 };
|
||||
glVertexPointer(2, GL_FLOAT, 0, sq_vert);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
const GLfloat sq_tex[] = { 0,1, 1,1, 1,0, 0,0 };
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, sq_tex);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glColor4f(1,1,1,1);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(target);
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
|
||||
#ifndef HAVE_GLES
|
||||
inline void glVertex( const Eigen::Vector3d& p )
|
||||
{
|
||||
glVertex3dv(p.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void glDrawLine( const Eigen::Vector2d& p1, const Eigen::Vector2d& p2 )
|
||||
{
|
||||
glDrawLine((GLfloat)p1(0), (GLfloat)p1(1), (GLfloat)p2(0), (GLfloat)p2(1));
|
||||
}
|
||||
|
||||
// Draws a vector of 2d or 3d vertices using provided ``mode``.
|
||||
//
|
||||
// Preconditions:
|
||||
// - ``mode`` must be GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, etc
|
||||
// - If ``mode == GL_LINES``, then ``vertices.size()`` must be a multiple of 2.
|
||||
//
|
||||
template<typename P, int N, class Allocator>
|
||||
void glDrawVertices(const std::vector<Eigen::Matrix<P, N, 1>, Allocator>& vertices, GLenum mode)
|
||||
{
|
||||
glDrawVertices(vertices.size(), vertices.data(), mode);
|
||||
}
|
||||
|
||||
// Draws a vector of 2d or 3d points.
|
||||
//
|
||||
template<typename P, int N, class Allocator>
|
||||
void glDrawPoints(const std::vector<Eigen::Matrix<P, N, 1>, Allocator>& vertices)
|
||||
{
|
||||
glDrawVertices(vertices, GL_POINTS);
|
||||
}
|
||||
|
||||
// Draws a vector of 2d or 3d lines.
|
||||
//
|
||||
// Precondition: ``vertices.size()`` must be a multiple of 2.
|
||||
//
|
||||
template<typename P, int N, class Allocator>
|
||||
void glDrawLines(const std::vector<Eigen::Matrix<P, N, 1>, Allocator>& vertices)
|
||||
{
|
||||
glDrawVertices(vertices, GL_LINES);
|
||||
}
|
||||
|
||||
// Draws a 2d or 3d line strip.
|
||||
//
|
||||
template<typename P, int N, class Allocator>
|
||||
void glDrawLineStrip(const std::vector<Eigen::Matrix<P, N, 1>, Allocator>& vertices)
|
||||
{
|
||||
glDrawVertices(vertices, GL_LINE_STRIP);
|
||||
}
|
||||
|
||||
// Draws a 2d or 3d line loop.
|
||||
//
|
||||
template<typename P, int N, class Allocator>
|
||||
void glDrawLineLoop(const std::vector<Eigen::Matrix<P, N, 1>, Allocator>& vertices)
|
||||
{
|
||||
glDrawVertices(vertices, GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
inline void glDrawCross( const Eigen::Vector2d& p, double r = 5.0 )
|
||||
{
|
||||
glDrawCross((GLfloat)p(0), (GLfloat)p(1), (GLfloat)r);
|
||||
}
|
||||
|
||||
inline void glDrawCross( const Eigen::Vector3d& p, double r = 5.0 )
|
||||
{
|
||||
glDrawCross((GLfloat)p(0), (GLfloat)p(1), (GLfloat)p(2), (GLfloat)r);
|
||||
}
|
||||
|
||||
inline void glDrawCircle( const Eigen::Vector2d& p, double radius = 5.0 )
|
||||
{
|
||||
glDrawCircle((GLfloat)p(0), (GLfloat)p(1), (GLfloat)radius);
|
||||
}
|
||||
|
||||
inline void glDrawCirclePerimeter( const Eigen::Vector2d& p, double radius = 5.0 )
|
||||
{
|
||||
glDrawCirclePerimeter((GLfloat)p(0), (GLfloat)p(1), (GLfloat)radius);
|
||||
}
|
||||
|
||||
inline void glSetFrameOfReference( const Eigen::Matrix4f& T_wf )
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glMultMatrixf( T_wf.data() );
|
||||
}
|
||||
|
||||
inline void glSetFrameOfReference( const Eigen::Matrix4d& T_wf )
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
#ifndef HAVE_GLES
|
||||
glMultMatrixd( T_wf.data() );
|
||||
#else
|
||||
const Eigen::Matrix4f fT_wf = T_wf.cast<GLfloat>();
|
||||
glMultMatrixf( fT_wf.data() );
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void glSetFrameOfReference( const pangolin::OpenGlMatrix& T_wf )
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glMultMatrixd( T_wf.m );
|
||||
}
|
||||
|
||||
inline void glUnsetFrameOfReference()
|
||||
{
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
template<typename T, typename S>
|
||||
inline void glDrawAxis( const T& T_wf, S scale )
|
||||
{
|
||||
glSetFrameOfReference(T_wf);
|
||||
glDrawAxis(scale);
|
||||
glUnsetFrameOfReference();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void glDrawFrustum( const Eigen::Matrix<T,3,3>& Kinv, int w, int h, GLfloat scale )
|
||||
{
|
||||
glDrawFrustum((GLfloat)Kinv(0,2), (GLfloat)Kinv(1,2), (GLfloat)Kinv(0,0), (GLfloat)Kinv(1,1), w, h, scale);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void glDrawFrustum( const Eigen::Matrix<T,3,3>& Kinv, int w, int h, const Eigen::Matrix<T,4,4>& T_wf, T scale )
|
||||
{
|
||||
glSetFrameOfReference(T_wf);
|
||||
glDrawFrustum(Kinv,w,h,scale);
|
||||
glUnsetFrameOfReference();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void glDrawAlignedBox( const Eigen::AlignedBox<T,2>& box, GLenum mode = GL_TRIANGLE_FAN )
|
||||
{
|
||||
const Eigen::Matrix<float,2,1> l = box.min().template cast<float>();
|
||||
const Eigen::Matrix<float,2,1> h = box.max().template cast<float>();
|
||||
|
||||
GLfloat verts[] = {
|
||||
l[0], l[1],
|
||||
h[0], l[1],
|
||||
h[0], h[1],
|
||||
l[0], h[1]
|
||||
};
|
||||
|
||||
glDrawVertices(4, verts, mode, 2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void glDrawAlignedBoxPerimeter( const Eigen::AlignedBox<T,2>& box)
|
||||
{
|
||||
glDrawAlignedBox<T>(box, GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void glDrawAlignedBox( const Eigen::AlignedBox<T,3>& box)
|
||||
{
|
||||
const Eigen::Matrix<float,3,1> l = box.min().template cast<float>();
|
||||
const Eigen::Matrix<float,3,1> h = box.max().template cast<float>();
|
||||
|
||||
GLfloat verts[] = {
|
||||
l[0], l[1], l[2],
|
||||
l[0], l[1], h[2],
|
||||
h[0], l[1], h[2],
|
||||
h[0], l[1], l[2],
|
||||
l[0], l[1], l[2],
|
||||
l[0], h[1], l[2],
|
||||
h[0], h[1], l[2],
|
||||
h[0], l[1], l[2],
|
||||
h[0], h[1], l[2],
|
||||
h[0], h[1], h[2],
|
||||
l[0], h[1], h[2],
|
||||
l[0], h[1], l[2],
|
||||
l[0], h[1], h[2],
|
||||
l[0], l[1], h[2],
|
||||
h[0], l[1], h[2],
|
||||
h[0], h[1], h[2]
|
||||
};
|
||||
|
||||
glDrawVertices(16, verts, GL_LINE_STRIP, 3);
|
||||
}
|
||||
|
||||
#endif // USE_EIGEN
|
||||
|
||||
#ifndef HAVE_GLES
|
||||
inline void glPixelTransferScale( float r, float g, float b )
|
||||
{
|
||||
glPixelTransferf(GL_RED_SCALE,r);
|
||||
glPixelTransferf(GL_GREEN_SCALE,g);
|
||||
glPixelTransferf(GL_BLUE_SCALE,b);
|
||||
}
|
||||
|
||||
inline void glPixelTransferScale( float scale )
|
||||
{
|
||||
glPixelTransferScale(scale,scale,scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
void glRecordGraphic(float x, float y, float radius);
|
||||
|
||||
}
|
||||
78
Thirdparty/Pangolin/include/pangolin/gl/glfont.h
vendored
Normal file
78
Thirdparty/Pangolin/include/pangolin/gl/glfont.h
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2015 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/gltext.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
class PANGOLIN_EXPORT GlFont
|
||||
{
|
||||
public:
|
||||
// Singleton instance if requested.
|
||||
static GlFont& I();
|
||||
|
||||
// Load GL Font data. Delay uploading as texture until first use.
|
||||
GlFont(const unsigned char* ttf_buffer, float pixel_height, int tex_w=512, int tex_h=512);
|
||||
GlFont(const std::string& filename, float pixel_height, int tex_w=512, int tex_h=512);
|
||||
|
||||
virtual ~GlFont();
|
||||
|
||||
// Generate renderable GlText object from this font.
|
||||
GlText Text( const char* fmt, ... );
|
||||
|
||||
GlText Text( const std::string& str );
|
||||
|
||||
inline float Height() const {
|
||||
return font_height_px;
|
||||
}
|
||||
|
||||
protected:
|
||||
void InitialiseFont(const unsigned char* ttf_buffer, float pixel_height, int tex_w, int tex_h);
|
||||
|
||||
// This can only be called once GL context is initialised
|
||||
void InitialiseGlTexture();
|
||||
|
||||
const static int FIRST_CHAR = 32;
|
||||
const static int NUM_CHARS = 96;
|
||||
|
||||
float font_height_px;
|
||||
|
||||
int tex_w;
|
||||
int tex_h;
|
||||
unsigned char* font_bitmap;
|
||||
GlTexture mTex;
|
||||
|
||||
GlChar chardata[NUM_CHARS];
|
||||
GLfloat kern_table[NUM_CHARS*NUM_CHARS];
|
||||
};
|
||||
|
||||
}
|
||||
214
Thirdparty/Pangolin/include/pangolin/gl/glformattraits.h
vendored
Normal file
214
Thirdparty/Pangolin/include/pangolin/gl/glformattraits.h
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
/* 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/gl/glplatform.h>
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
# include <Eigen/Core>
|
||||
#endif
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct GlFormatTraits;
|
||||
//{
|
||||
// static const GLint glinternalformat = 0;
|
||||
// static const GLenum glformat = 0;
|
||||
// static const GLenum gltype = 0;
|
||||
// static const T glmin = 0;
|
||||
// static const T glmax = 0;
|
||||
//};
|
||||
|
||||
template<>
|
||||
struct GlFormatTraits<unsigned char>
|
||||
{
|
||||
static const GLint glinternalformat = GL_LUMINANCE8;
|
||||
static const GLenum glformat = GL_LUMINANCE;
|
||||
static const GLenum gltype = GL_UNSIGNED_BYTE;
|
||||
static const size_t components = 1;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct GlFormatTraits<unsigned short>
|
||||
{
|
||||
static const GLint glinternalformat = GL_LUMINANCE16;
|
||||
static const GLenum glformat = GL_LUMINANCE;
|
||||
static const GLenum gltype = GL_UNSIGNED_SHORT;
|
||||
static const size_t components = 1;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct GlFormatTraits<unsigned int>
|
||||
{
|
||||
static const GLint glinternalformat = GL_LUMINANCE32I_EXT;
|
||||
static const GLenum glformat = GL_LUMINANCE;
|
||||
static const GLenum gltype = GL_UNSIGNED_INT;
|
||||
static const size_t components = 1;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct GlFormatTraits<int>
|
||||
{
|
||||
static const GLint glinternalformat = GL_LUMINANCE32I_EXT;
|
||||
static const GLenum glformat = GL_LUMINANCE;
|
||||
static const GLenum gltype = GL_INT;
|
||||
static const size_t components = 1;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct GlFormatTraits<float>
|
||||
{
|
||||
static const GLint glinternalformat = GL_LUMINANCE32F_ARB;
|
||||
static const GLenum glformat = GL_LUMINANCE;
|
||||
static const GLenum gltype = GL_FLOAT;
|
||||
static const size_t components = 1;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct GlFormatTraits<double>
|
||||
{
|
||||
static const GLint glinternalformat = GL_LUMINANCE32F_ARB;
|
||||
static const GLenum glformat = GL_LUMINANCE;
|
||||
static const GLenum gltype = GL_DOUBLE;
|
||||
static const size_t components = 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector2i>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RG32I;
|
||||
static const GLenum glformat = GL_RG;
|
||||
static const GLenum gltype = GL_INT;
|
||||
static const size_t components = 2;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector2f>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RG32F;
|
||||
static const GLenum glformat = GL_RG;
|
||||
static const GLenum gltype = GL_FLOAT;
|
||||
static const size_t components = 2;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector2d>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RG32F;
|
||||
static const GLenum glformat = GL_RG;
|
||||
static const GLenum gltype = GL_DOUBLE;
|
||||
static const size_t components = 2;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Matrix<unsigned char,3,1>>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGB8;
|
||||
static const GLenum glformat = GL_RGB;
|
||||
static const GLenum gltype = GL_UNSIGNED_BYTE;
|
||||
static const size_t components = 3;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Matrix<unsigned short,3,1>>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGBA16;
|
||||
static const GLenum glformat = GL_RGB;
|
||||
static const GLenum gltype = GL_UNSIGNED_SHORT;
|
||||
static const size_t components = 3;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector3f>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGB32F;
|
||||
static const GLenum glformat = GL_RGB;
|
||||
static const GLenum gltype = GL_FLOAT;
|
||||
static const size_t components = 3;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector3d>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGB32F;
|
||||
static const GLenum glformat = GL_RGB;
|
||||
static const GLenum gltype = GL_DOUBLE;
|
||||
static const size_t components = 3;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Matrix<unsigned char,4,1>>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGBA8;
|
||||
static const GLenum glformat = GL_RGBA;
|
||||
static const GLenum gltype = GL_UNSIGNED_BYTE;
|
||||
static const size_t components = 4;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Matrix<unsigned short,4,1>>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGBA16;
|
||||
static const GLenum glformat = GL_RGBA;
|
||||
static const GLenum gltype = GL_UNSIGNED_SHORT;
|
||||
static const size_t components = 4;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector4f>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGBA32F;
|
||||
static const GLenum glformat = GL_RGBA;
|
||||
static const GLenum gltype = GL_FLOAT;
|
||||
static const size_t components = 4;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GlFormatTraits<Eigen::Vector4d>
|
||||
{
|
||||
static const GLint glinternalformat = GL_RGBA32F;
|
||||
static const GLenum glformat = GL_RGBA;
|
||||
static const GLenum gltype = GL_DOUBLE;
|
||||
static const size_t components = 4;
|
||||
};
|
||||
|
||||
#endif // HAVE_EIGEN
|
||||
|
||||
}
|
||||
46
Thirdparty/Pangolin/include/pangolin/gl/glinclude.h
vendored
Normal file
46
Thirdparty/Pangolin/include/pangolin/gl/glinclude.h
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/* 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/gl/glplatform.h>
|
||||
|
||||
#ifdef HAVE_GLES
|
||||
#include <pangolin/gl/compat/gl_es_compat.h>
|
||||
#endif
|
||||
|
||||
#define CheckGlDieOnError() pangolin::_CheckGlDieOnError( __FILE__, __LINE__ );
|
||||
namespace pangolin {
|
||||
inline void _CheckGlDieOnError( const char *sFile, const int nLine )
|
||||
{
|
||||
const GLenum glError = glGetError();
|
||||
if( glError != GL_NO_ERROR ) {
|
||||
pango_print_error("OpenGL Error %x: %s\n", glError, glErrorString(glError));
|
||||
pango_print_error("In: %s, line %d\n", sFile, nLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
79
Thirdparty/Pangolin/include/pangolin/gl/glpangoglu.h
vendored
Normal file
79
Thirdparty/Pangolin/include/pangolin/gl/glpangoglu.h
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/* 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/gl/glplatform.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
const char* glErrorString(GLenum error);
|
||||
|
||||
/// Clone of gluProject
|
||||
PANGOLIN_EXPORT
|
||||
GLint glProject(
|
||||
float objx, float objy, float objz,
|
||||
const float modelMatrix[16],
|
||||
const float projMatrix[16],
|
||||
const GLint viewport[4],
|
||||
float* winx, float* winy, float* winz
|
||||
);
|
||||
|
||||
|
||||
/// Clone of gluUnProject
|
||||
PANGOLIN_EXPORT
|
||||
GLint glUnProject(
|
||||
float winx, float winy, float winz,
|
||||
const float modelMatrix[16],
|
||||
const float projMatrix[16],
|
||||
const GLint viewport[4],
|
||||
float* objx, float* objy, float* objz
|
||||
);
|
||||
|
||||
/// Clone of gluProject
|
||||
PANGOLIN_EXPORT
|
||||
GLint glProject(
|
||||
double objx, double objy, double objz,
|
||||
const double modelMatrix[16],
|
||||
const double projMatrix[16],
|
||||
const GLint viewport[4],
|
||||
double* winx, double* winy, double* winz
|
||||
);
|
||||
|
||||
|
||||
/// Clone of gluUnProject
|
||||
PANGOLIN_EXPORT
|
||||
GLint glUnProject(
|
||||
double winx, double winy, double winz,
|
||||
const double modelMatrix[16],
|
||||
const double projMatrix[16],
|
||||
const GLint viewport[4],
|
||||
double* objx, double* objy, double* objz
|
||||
);
|
||||
|
||||
}
|
||||
95
Thirdparty/Pangolin/include/pangolin/gl/glpixformat.h
vendored
Normal file
95
Thirdparty/Pangolin/include/pangolin/gl/glpixformat.h
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/* 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/gl/glplatform.h>
|
||||
#include <pangolin/gl/glformattraits.h>
|
||||
#include <pangolin/image/pixel_format.h>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
// This class may dissapear in the future
|
||||
struct GlPixFormat
|
||||
{
|
||||
GlPixFormat() {}
|
||||
|
||||
GlPixFormat(const PixelFormat& fmt)
|
||||
{
|
||||
switch( fmt.channels) {
|
||||
case 1: glformat = GL_LUMINANCE; break;
|
||||
case 3: glformat = (fmt.format == "BGR24" || fmt.format == "BGR48") ? GL_BGR : GL_RGB; break;
|
||||
case 4: glformat = (fmt.format == "BGRA24" || fmt.format == "BGRA32" || fmt.format == "BGRA48") ? GL_BGRA : GL_RGBA; break;
|
||||
default: throw std::runtime_error("Unable to form OpenGL format from video format: '" + fmt.format + "'.");
|
||||
}
|
||||
|
||||
const bool is_integral = fmt.format.find('F') == std::string::npos;
|
||||
|
||||
switch (fmt.channel_bits[0]) {
|
||||
case 8: gltype = GL_UNSIGNED_BYTE; break;
|
||||
case 16: gltype = GL_UNSIGNED_SHORT; break;
|
||||
case 32: gltype = (is_integral ? GL_UNSIGNED_INT : GL_FLOAT); break;
|
||||
case 64: gltype = (is_integral ? GL_UNSIGNED_INT64_NV : GL_DOUBLE); break;
|
||||
default: throw std::runtime_error("Unknown OpenGL data type for video format: '" + fmt.format + "'.");
|
||||
}
|
||||
|
||||
if(glformat == GL_LUMINANCE) {
|
||||
if(gltype == GL_UNSIGNED_BYTE) {
|
||||
scalable_internal_format = GL_LUMINANCE8;
|
||||
}else if(gltype == GL_UNSIGNED_SHORT){
|
||||
scalable_internal_format = GL_LUMINANCE16;
|
||||
}else{
|
||||
scalable_internal_format = GL_LUMINANCE32F_ARB;
|
||||
}
|
||||
}else{
|
||||
if(gltype == GL_UNSIGNED_BYTE) {
|
||||
scalable_internal_format = GL_RGBA8;
|
||||
}else if(gltype == GL_UNSIGNED_SHORT) {
|
||||
scalable_internal_format = GL_RGBA16;
|
||||
}else{
|
||||
scalable_internal_format = GL_RGBA32F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static GlPixFormat FromType()
|
||||
{
|
||||
GlPixFormat fmt;
|
||||
fmt.glformat = GlFormatTraits<T>::glformat;
|
||||
fmt.gltype = GlFormatTraits<T>::gltype;
|
||||
fmt.scalable_internal_format = GlFormatTraits<T>::glinternalformat;
|
||||
return fmt;
|
||||
}
|
||||
|
||||
GLint glformat;
|
||||
GLenum gltype;
|
||||
GLint scalable_internal_format;
|
||||
};
|
||||
|
||||
}
|
||||
83
Thirdparty/Pangolin/include/pangolin/gl/glplatform.h
vendored
Normal file
83
Thirdparty/Pangolin/include/pangolin/gl/glplatform.h
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/* 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
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// Attempt to portably include Necessary OpenGL headers
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
#ifdef _WIN_
|
||||
// Define maths quantities when using <cmath> to match posix systems
|
||||
#ifndef _USE_MATH_DEFINES
|
||||
# define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
// Don't define min / max macros in windows.h or other unnecessary macros
|
||||
#ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
#endif
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
|
||||
// Undef nuisance Windows.h macros which interfere with our methods
|
||||
#undef LoadImage
|
||||
#undef near
|
||||
#undef far
|
||||
#undef ERROR
|
||||
#endif
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#ifdef HAVE_GLES
|
||||
#if defined(_ANDROID_)
|
||||
#include <EGL/egl.h>
|
||||
#ifdef HAVE_GLES_2
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#else
|
||||
#include <GLES/gl.h>
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GLES/glext.h>
|
||||
#endif
|
||||
#elif defined(_APPLE_IOS_)
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
#endif
|
||||
#else
|
||||
#ifdef _OSX_
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#endif // HAVE_GLES
|
||||
|
||||
#include <pangolin/gl/glpangoglu.h>
|
||||
738
Thirdparty/Pangolin/include/pangolin/gl/glsl.h
vendored
Normal file
738
Thirdparty/Pangolin/include/pangolin/gl/glsl.h
vendored
Normal file
@@ -0,0 +1,738 @@
|
||||
/* 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 <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cctype>
|
||||
|
||||
#include <pangolin/gl/glplatform.h>
|
||||
#include <pangolin/gl/colour.h>
|
||||
#include <pangolin/utils/file_utils.h>
|
||||
#include <pangolin/display/opengl_render_state.h>
|
||||
|
||||
#ifdef HAVE_GLES
|
||||
#define GLhandleARB GLuint
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_EIGEN) && !defined(__CUDACC__) //prevent including Eigen in cuda files
|
||||
#define USE_EIGEN
|
||||
#endif
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
#include <Eigen/Core>
|
||||
#endif // USE_EIGEN
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Standard attribute locations
|
||||
////////////////////////////////////////////////
|
||||
|
||||
const GLuint DEFAULT_LOCATION_POSITION = 0;
|
||||
const GLuint DEFAULT_LOCATION_COLOUR = 1;
|
||||
const GLuint DEFAULT_LOCATION_NORMAL = 2;
|
||||
const GLuint DEFAULT_LOCATION_TEXCOORD = 3;
|
||||
|
||||
const char DEFAULT_NAME_POSITION[] = "a_position";
|
||||
const char DEFAULT_NAME_COLOUR[] = "a_color";
|
||||
const char DEFAULT_NAME_NORMAL[] = "a_normal";
|
||||
const char DEFAULT_NAME_TEXCOORD[] = "a_texcoord";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Interface
|
||||
////////////////////////////////////////////////
|
||||
|
||||
enum GlSlShaderType
|
||||
{
|
||||
GlSlAnnotatedShader = 0,
|
||||
GlSlFragmentShader = GL_FRAGMENT_SHADER,
|
||||
GlSlVertexShader = GL_VERTEX_SHADER,
|
||||
GlSlGeometryShader = 0x8DD9 /*GL_GEOMETRY_SHADER*/,
|
||||
GlSlComputeShader = 0x91B9 /*GL_COMPUTE_SHADER*/
|
||||
};
|
||||
|
||||
class GlSlProgram
|
||||
{
|
||||
public:
|
||||
GlSlProgram();
|
||||
|
||||
//! Move Constructor
|
||||
GlSlProgram(GlSlProgram&& tex);
|
||||
|
||||
~GlSlProgram();
|
||||
|
||||
bool AddShader(
|
||||
GlSlShaderType shader_type,
|
||||
const std::string& source_code,
|
||||
const std::map<std::string,std::string>& program_defines = std::map<std::string,std::string>(),
|
||||
const std::vector<std::string>& search_path = std::vector<std::string>()
|
||||
);
|
||||
|
||||
bool AddShaderFromFile(
|
||||
GlSlShaderType shader_type,
|
||||
const std::string& filename,
|
||||
const std::map<std::string,std::string>& program_defines = std::map<std::string,std::string>(),
|
||||
const std::vector<std::string>& search_path = std::vector<std::string>()
|
||||
);
|
||||
|
||||
bool Link();
|
||||
|
||||
// Remove all shaders from this program, and reload from files.
|
||||
bool ReloadShaderFiles();
|
||||
|
||||
GLint GetAttributeHandle(const std::string& name);
|
||||
GLint GetUniformHandle(const std::string& name);
|
||||
|
||||
// Before setting uniforms, be sure to Bind() the GlSl program first.
|
||||
void SetUniform(const std::string& name, int x);
|
||||
void SetUniform(const std::string& name, int x1, int x2);
|
||||
void SetUniform(const std::string& name, int x1, int x2, int x3);
|
||||
void SetUniform(const std::string& name, int x1, int x2, int x3, int x4);
|
||||
|
||||
void SetUniform(const std::string& name, float f);
|
||||
void SetUniform(const std::string& name, float f1, float f2);
|
||||
void SetUniform(const std::string& name, float f1, float f2, float f3);
|
||||
void SetUniform(const std::string& name, float f1, float f2, float f3, float f4);
|
||||
|
||||
void SetUniform(const std::string& name, Colour c);
|
||||
|
||||
void SetUniform(const std::string& name, const OpenGlMatrix& m);
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
void SetUniform(const std::string& name, const Eigen::Matrix3f& m);
|
||||
void SetUniform(const std::string& name, const Eigen::Matrix4f& m);
|
||||
void SetUniform(const std::string& name, const Eigen::Matrix3d& m);
|
||||
void SetUniform(const std::string& name, const Eigen::Matrix4d& m);
|
||||
#endif
|
||||
|
||||
#if GL_VERSION_4_3
|
||||
GLint GetProgramResourceIndex(const std::string& name);
|
||||
void SetShaderStorageBlock(const std::string& name, const int& bindingIndex);
|
||||
#endif
|
||||
|
||||
void Bind();
|
||||
void SaveBind();
|
||||
void Unbind();
|
||||
|
||||
|
||||
void BindPangolinDefaultAttribLocationsAndLink();
|
||||
|
||||
// Unlink all shaders from program
|
||||
void ClearShaders();
|
||||
|
||||
GLint ProgramId() const {
|
||||
return prog;
|
||||
}
|
||||
|
||||
bool Valid() const {
|
||||
return ProgramId() != 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
struct ShaderFileOrCode
|
||||
{
|
||||
GlSlShaderType shader_type;
|
||||
std::string filename;
|
||||
std::string code;
|
||||
std::map<std::string,std::string> program_defines;
|
||||
std::vector<std::string> search_path;
|
||||
};
|
||||
|
||||
|
||||
// Convenience method to load shader description
|
||||
bool AddShaderFile(const ShaderFileOrCode &shader_file);
|
||||
|
||||
std::string ParseIncludeFilename(
|
||||
const std::string& location
|
||||
);
|
||||
|
||||
std::string SearchIncludePath(
|
||||
const std::string& filename,
|
||||
const std::vector<std::string>& search_path,
|
||||
const std::string& current_path
|
||||
);
|
||||
|
||||
bool AddPreprocessedShader(
|
||||
GlSlShaderType shader_type,
|
||||
const std::string& source_code,
|
||||
const std::string& name_for_errors
|
||||
);
|
||||
|
||||
void PreprocessGLSL(
|
||||
std::istream& input,
|
||||
std::ostream& output,
|
||||
const std::map<std::string,std::string>& program_defines,
|
||||
const std::vector<std::string>& search_path,
|
||||
const std::string& current_path
|
||||
);
|
||||
|
||||
// Split 'code' into several code blocks per shader type
|
||||
// shader blocks in 'code' must be annotated with:
|
||||
// @start vertex, @start fragment, @start geometry or @start compute
|
||||
static std::map<GlSlShaderType,std::string>
|
||||
SplitAnnotatedShaders(const std::string& code);
|
||||
|
||||
bool linked;
|
||||
std::vector<GLhandleARB> shaders;
|
||||
GLenum prog;
|
||||
GLint prev_prog;
|
||||
std::vector<ShaderFileOrCode> shader_files;
|
||||
};
|
||||
|
||||
class GlSlUtilities
|
||||
{
|
||||
public:
|
||||
inline static GlSlProgram& OffsetAndScale(float offset, float scale) {
|
||||
GlSlProgram& prog = Instance().prog_offsetscale;
|
||||
prog.Bind();
|
||||
prog.SetUniform("offset", offset);
|
||||
prog.SetUniform("scale", scale);
|
||||
return prog;
|
||||
}
|
||||
|
||||
inline static GlSlProgram& Scale(float scale, float bias = 0.0f) {
|
||||
GlSlProgram& prog = Instance().prog_scale;
|
||||
prog.Bind();
|
||||
prog.SetUniform("scale", scale);
|
||||
prog.SetUniform("bias", bias);
|
||||
return prog;
|
||||
}
|
||||
|
||||
inline static void UseNone()
|
||||
{
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
static GlSlUtilities& Instance() {
|
||||
// TODO: BUG: The GlSLUtilities instance needs to be tied
|
||||
// to the OpenGL context, not the thread, or globally.
|
||||
#ifndef PANGO_NO_THREADLOCAL
|
||||
thread_local
|
||||
#else
|
||||
static
|
||||
#endif
|
||||
GlSlUtilities instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// protected constructor
|
||||
GlSlUtilities() {
|
||||
const char* source_scale =
|
||||
"uniform float scale;"
|
||||
"uniform float bias;"
|
||||
"uniform sampler2D tex;"
|
||||
"void main() {"
|
||||
" vec2 uv = gl_TexCoord[0].st;"
|
||||
" if(0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0) {"
|
||||
" gl_FragColor = texture2D(tex,uv);"
|
||||
" gl_FragColor.xyz *= scale;"
|
||||
" gl_FragColor.xyz += vec3(bias,bias,bias);"
|
||||
" }else{"
|
||||
" float v = 0.1;"
|
||||
" gl_FragColor.xyz = vec3(v,v,v);"
|
||||
" }"
|
||||
"}";
|
||||
prog_scale.AddShader(GlSlFragmentShader, source_scale);
|
||||
prog_scale.Link();
|
||||
|
||||
const char* source_offsetscale =
|
||||
"uniform float offset;"
|
||||
"uniform float scale;"
|
||||
"uniform sampler2D tex;"
|
||||
"void main() {"
|
||||
" vec2 uv = gl_TexCoord[0].st;"
|
||||
" if(0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0) {"
|
||||
" gl_FragColor = texture2D(tex,gl_TexCoord[0].st);"
|
||||
" gl_FragColor.xyz += vec3(offset,offset,offset);"
|
||||
" gl_FragColor.xyz *= scale;"
|
||||
" }else{"
|
||||
" float v = 0.1;"
|
||||
" gl_FragColor.xyz = vec3(v,v,v);"
|
||||
" }"
|
||||
"}";
|
||||
prog_offsetscale.AddShader(GlSlFragmentShader, source_offsetscale);
|
||||
prog_offsetscale.Link();
|
||||
}
|
||||
|
||||
GlSlProgram prog_scale;
|
||||
GlSlProgram prog_offsetscale;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Implementation
|
||||
////////////////////////////////////////////////
|
||||
|
||||
inline bool IsLinkSuccessPrintLog(GLhandleARB prog)
|
||||
{
|
||||
GLint status;
|
||||
glGetProgramiv(prog, GL_LINK_STATUS, &status);
|
||||
if(status != GL_TRUE) {
|
||||
pango_print_error("GLSL Program link failed: ");
|
||||
const int PROGRAM_LOG_MAX_LEN = 10240;
|
||||
char infolog[PROGRAM_LOG_MAX_LEN];
|
||||
GLsizei len;
|
||||
glGetProgramInfoLog(prog, PROGRAM_LOG_MAX_LEN, &len, infolog);
|
||||
if(len) {
|
||||
pango_print_error("%s\n",infolog);
|
||||
}else{
|
||||
pango_print_error("No details provided.\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool IsCompileSuccessPrintLog(GLhandleARB shader, const std::string& name_for_errors)
|
||||
{
|
||||
GLint status;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
||||
if(status != GL_TRUE) {
|
||||
pango_print_error("GLSL Shader compilation failed: ");
|
||||
const int SHADER_LOG_MAX_LEN = 10240;
|
||||
char infolog[SHADER_LOG_MAX_LEN];
|
||||
GLsizei len;
|
||||
glGetShaderInfoLog(shader, SHADER_LOG_MAX_LEN, &len, infolog);
|
||||
if(len) {
|
||||
pango_print_error("%s:\n%s\n",name_for_errors.c_str(), infolog);
|
||||
}else{
|
||||
pango_print_error("%s:\nNo details provided.\n",name_for_errors.c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline GlSlProgram::GlSlProgram()
|
||||
: linked(false), prog(0), prev_prog(0)
|
||||
{
|
||||
}
|
||||
|
||||
//! Move Constructor
|
||||
inline GlSlProgram::GlSlProgram(GlSlProgram&& o)
|
||||
: linked(o.linked), shaders(o.shaders), prog(o.prog), prev_prog(o.prev_prog)
|
||||
{
|
||||
o.prog = 0;
|
||||
}
|
||||
|
||||
inline GlSlProgram::~GlSlProgram()
|
||||
{
|
||||
if(prog) {
|
||||
ClearShaders();
|
||||
glDeleteProgram(prog);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PrintSourceCode(const std::string& src)
|
||||
{
|
||||
std::stringstream ss(src);
|
||||
std::string line;
|
||||
|
||||
for(int linenum=1; std::getline(ss,line,'\n'); ++linenum) {
|
||||
std::cout << linenum << ":\t" << line << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool GlSlProgram::AddPreprocessedShader(
|
||||
GlSlShaderType shader_type,
|
||||
const std::string& source_code,
|
||||
const std::string& name_for_errors
|
||||
) {
|
||||
if(!prog) {
|
||||
prog = glCreateProgram();
|
||||
}
|
||||
|
||||
// PrintSourceCode(source_code);
|
||||
|
||||
GLhandleARB shader = glCreateShader(shader_type);
|
||||
const char* source = source_code.c_str();
|
||||
glShaderSource(shader, 1, &source, NULL);
|
||||
glCompileShader(shader);
|
||||
bool success = IsCompileSuccessPrintLog(shader, name_for_errors);
|
||||
if(success) {
|
||||
glAttachShader(prog, shader);
|
||||
shaders.push_back(shader);
|
||||
linked = false;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
inline std::string GlSlProgram::ParseIncludeFilename(const std::string& location)
|
||||
{
|
||||
size_t start = location.find_first_of("\"<");
|
||||
if(start != std::string::npos) {
|
||||
size_t end = location.find_first_of("\">", start+1);
|
||||
if(end != std::string::npos) {
|
||||
return location.substr(start+1, end - start - 1);
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("GLSL Parser: Unable to parse include location " + location );
|
||||
}
|
||||
|
||||
inline std::string GlSlProgram::SearchIncludePath(
|
||||
const std::string& filename,
|
||||
const std::vector<std::string>& search_path,
|
||||
const std::string& current_path
|
||||
) {
|
||||
if(FileExists(current_path + "/" + filename)) {
|
||||
return current_path + "/" + filename;
|
||||
}else{
|
||||
for(size_t i=0; i < search_path.size(); ++i) {
|
||||
const std::string hypoth = search_path[i] + "/" + filename;
|
||||
if( FileExists(hypoth) ) {
|
||||
return hypoth;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
inline void GlSlProgram::PreprocessGLSL(
|
||||
std::istream& input, std::ostream& output,
|
||||
const std::map<std::string,std::string>& program_defines,
|
||||
const std::vector<std::string> &search_path,
|
||||
const std::string ¤t_path
|
||||
) {
|
||||
const size_t MAXLINESIZE = 10240;
|
||||
char line[MAXLINESIZE] = "";
|
||||
|
||||
while(!input.eof()) {
|
||||
// Take like from source
|
||||
input.getline(line,MAXLINESIZE);
|
||||
|
||||
// Transform
|
||||
if( !strncmp(line, "#include", 8 ) ) {
|
||||
// C++ / G3D style include directive
|
||||
const std::string import_file = ParseIncludeFilename(line+8);
|
||||
const std::string resolved_file = SearchIncludePath(import_file, search_path, current_path);
|
||||
|
||||
std::ifstream ifs(resolved_file.c_str());
|
||||
if(ifs.good()) {
|
||||
const std::string file_path = pangolin::PathParent(resolved_file);
|
||||
PreprocessGLSL(ifs, output, program_defines, search_path, file_path);
|
||||
}else{
|
||||
throw std::runtime_error("GLSL Parser: Unable to open " + import_file );
|
||||
}
|
||||
}else if( !strncmp(line, "#expect", 7) ) {
|
||||
// G3D style 'expect' directive, annotating expected preprocessor
|
||||
// definition with document string
|
||||
|
||||
// Consume whitespace before token
|
||||
size_t token_start = 7;
|
||||
while( std::isspace(line[token_start]) ) ++token_start;
|
||||
|
||||
// Iterate over contigous charecters until \0 or whitespace
|
||||
size_t token_end = token_start;
|
||||
while( line[token_end] && !std::isspace(line[token_end]) ) ++token_end;
|
||||
|
||||
std::string token(line+token_start, line+token_end);
|
||||
std::map<std::string,std::string>::const_iterator it = program_defines.find(token);
|
||||
if( it == program_defines.end() ) {
|
||||
pango_print_warn("Expected define missing (defaulting to 0): '%s'\n%s\n", token.c_str(), line + token_end );
|
||||
output << "#define " << token << " 0" << std::endl;
|
||||
}else{
|
||||
output << "#define " << token << " " << it->second << std::endl;
|
||||
}
|
||||
}else{
|
||||
// Output directly
|
||||
output << line << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void GlSlProgram::ClearShaders()
|
||||
{
|
||||
// Remove and delete each shader
|
||||
for(size_t i=0; i<shaders.size(); ++i ) {
|
||||
glDetachShader(prog, shaders[i]);
|
||||
glDeleteShader(shaders[i]);
|
||||
}
|
||||
shaders.clear();
|
||||
}
|
||||
|
||||
inline bool GlSlProgram::AddShaderFile(const ShaderFileOrCode& shader_file)
|
||||
{
|
||||
std::stringstream buffer;
|
||||
|
||||
if(shader_file.code.empty()) {
|
||||
std::ifstream ifs(shader_file.filename.c_str());
|
||||
if(ifs.is_open()) {
|
||||
PreprocessGLSL(ifs, buffer, shader_file.program_defines, shader_file.search_path, ".");
|
||||
}else{
|
||||
throw std::runtime_error(FormatString("Unable to open shader file '%'", shader_file.filename));
|
||||
}
|
||||
}else{
|
||||
std::istringstream iss(shader_file.code);
|
||||
PreprocessGLSL(iss, buffer, shader_file.program_defines, shader_file.search_path, ".");
|
||||
}
|
||||
|
||||
const std::string code = buffer.str();
|
||||
const std::string input_name = !shader_file.filename.empty() ? shader_file.filename : "<string>";
|
||||
|
||||
if(shader_file.shader_type == GlSlAnnotatedShader) {
|
||||
const std::map<GlSlShaderType,std::string> split_progs = SplitAnnotatedShaders(code);
|
||||
for(const auto& type_code : split_progs) {
|
||||
if(!AddPreprocessedShader(type_code.first, type_code.second, input_name )) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return AddPreprocessedShader(shader_file.shader_type, code, input_name);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool GlSlProgram::AddShaderFromFile(
|
||||
GlSlShaderType shader_type,
|
||||
const std::string& filename,
|
||||
const std::map<std::string,std::string>& program_defines,
|
||||
const std::vector<std::string>& search_path
|
||||
) {
|
||||
ShaderFileOrCode shader_file = {
|
||||
shader_type,
|
||||
pangolin::PathExpand(filename),
|
||||
std::string(),
|
||||
program_defines,
|
||||
search_path
|
||||
};
|
||||
shader_files.push_back(shader_file);
|
||||
return AddShaderFile(shader_file);
|
||||
}
|
||||
|
||||
inline bool GlSlProgram::AddShader(
|
||||
GlSlShaderType shader_type,
|
||||
const std::string& source_code,
|
||||
const std::map<std::string,std::string>& program_defines,
|
||||
const std::vector<std::string>& search_path
|
||||
) {
|
||||
ShaderFileOrCode shader_file = {
|
||||
shader_type,
|
||||
std::string(),
|
||||
source_code,
|
||||
program_defines,
|
||||
search_path
|
||||
};
|
||||
shader_files.push_back(shader_file);
|
||||
return AddShaderFile(shader_file);
|
||||
}
|
||||
|
||||
inline bool GlSlProgram::ReloadShaderFiles()
|
||||
{
|
||||
ClearShaders();
|
||||
|
||||
for(const auto& sf : shader_files) {
|
||||
if(!AddShaderFile(sf)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Link();
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::map<GlSlShaderType,std::string>
|
||||
GlSlProgram::SplitAnnotatedShaders(const std::string& code)
|
||||
{
|
||||
std::map<GlSlShaderType,std::string> ret;
|
||||
|
||||
std::stringstream input(code);
|
||||
std::stringstream output;
|
||||
|
||||
const size_t MAXLINESIZE = 10240;
|
||||
char line[MAXLINESIZE];
|
||||
|
||||
GlSlShaderType current_type = GlSlAnnotatedShader;
|
||||
auto finish_block = [&](GlSlShaderType type){
|
||||
if(current_type != GlSlAnnotatedShader) {
|
||||
ret[current_type] = output.str();
|
||||
}
|
||||
output.str(std::string());
|
||||
current_type = type;
|
||||
};
|
||||
|
||||
while(!input.eof()) {
|
||||
// Take like from source
|
||||
input.getline(line,MAXLINESIZE);
|
||||
|
||||
// Transform
|
||||
if( !strncmp(line, "@start", 6 ) ) {
|
||||
const std::string str_shader_type = pangolin::Trim(std::string(line).substr(6));
|
||||
if(str_shader_type == "vertex") {
|
||||
finish_block(GlSlVertexShader);
|
||||
}else if(str_shader_type == "fragment") {
|
||||
finish_block(GlSlFragmentShader);
|
||||
}else if(str_shader_type == "geometry") {
|
||||
finish_block(GlSlGeometryShader);
|
||||
}else if(str_shader_type == "compute") {
|
||||
finish_block(GlSlComputeShader);
|
||||
}
|
||||
}else{
|
||||
output << line << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
finish_block(GlSlAnnotatedShader);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline bool GlSlProgram::Link()
|
||||
{
|
||||
glLinkProgram(prog);
|
||||
return IsLinkSuccessPrintLog(prog);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::Bind()
|
||||
{
|
||||
prev_prog = 0;
|
||||
glUseProgram(prog);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SaveBind()
|
||||
{
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, &prev_prog);
|
||||
glUseProgram(prog);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::Unbind()
|
||||
{
|
||||
glUseProgram(prev_prog);
|
||||
}
|
||||
|
||||
inline GLint GlSlProgram::GetAttributeHandle(const std::string& name)
|
||||
{
|
||||
return glGetAttribLocation(prog, name.c_str());
|
||||
}
|
||||
|
||||
inline GLint GlSlProgram::GetUniformHandle(const std::string& name)
|
||||
{
|
||||
return glGetUniformLocation(prog, name.c_str());
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, int x)
|
||||
{
|
||||
glUniform1i( GetUniformHandle(name), x);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, int x1, int x2)
|
||||
{
|
||||
glUniform2i( GetUniformHandle(name), x1, x2);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, int x1, int x2, int x3)
|
||||
{
|
||||
glUniform3i( GetUniformHandle(name), x1, x2, x3);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, int x1, int x2, int x3, int x4)
|
||||
{
|
||||
glUniform4i( GetUniformHandle(name), x1, x2, x3, x4);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, float f)
|
||||
{
|
||||
glUniform1f( GetUniformHandle(name), f);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, float f1, float f2)
|
||||
{
|
||||
glUniform2f( GetUniformHandle(name), f1,f2);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, float f1, float f2, float f3)
|
||||
{
|
||||
glUniform3f( GetUniformHandle(name), f1,f2,f3);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, float f1, float f2, float f3, float f4)
|
||||
{
|
||||
glUniform4f( GetUniformHandle(name), f1,f2,f3,f4);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, Colour c)
|
||||
{
|
||||
glUniform4f( GetUniformHandle(name), c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, const OpenGlMatrix& mat)
|
||||
{
|
||||
// glUniformMatrix4dv seems to be crashing...
|
||||
float m[16];
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
m[i] = (float)mat.m[i];
|
||||
}
|
||||
glUniformMatrix4fv( GetUniformHandle(name), 1, GL_FALSE, m);
|
||||
}
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, const Eigen::Matrix3f& m)
|
||||
{
|
||||
glUniformMatrix3fv( GetUniformHandle(name), 1, GL_FALSE, m.data());
|
||||
}
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, const Eigen::Matrix4f& m)
|
||||
{
|
||||
glUniformMatrix4fv( GetUniformHandle(name), 1, GL_FALSE, m.data());
|
||||
}
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, const Eigen::Matrix3d& m)
|
||||
{
|
||||
glUniformMatrix3dv( GetUniformHandle(name), 1, GL_FALSE, m.data());
|
||||
}
|
||||
inline void GlSlProgram::SetUniform(const std::string& name, const Eigen::Matrix4d& m)
|
||||
{
|
||||
glUniformMatrix4dv( GetUniformHandle(name), 1, GL_FALSE, m.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void GlSlProgram::BindPangolinDefaultAttribLocationsAndLink()
|
||||
{
|
||||
glBindAttribLocation(prog, DEFAULT_LOCATION_POSITION, DEFAULT_NAME_POSITION);
|
||||
glBindAttribLocation(prog, DEFAULT_LOCATION_COLOUR, DEFAULT_NAME_COLOUR);
|
||||
glBindAttribLocation(prog, DEFAULT_LOCATION_NORMAL, DEFAULT_NAME_NORMAL);
|
||||
glBindAttribLocation(prog, DEFAULT_LOCATION_TEXCOORD, DEFAULT_NAME_TEXCOORD);
|
||||
Link();
|
||||
}
|
||||
|
||||
#if GL_VERSION_4_3
|
||||
inline GLint GlSlProgram::GetProgramResourceIndex(const std::string& name)
|
||||
{
|
||||
return glGetProgramResourceIndex(prog, GL_SHADER_STORAGE_BLOCK, name.c_str());
|
||||
}
|
||||
|
||||
inline void GlSlProgram::SetShaderStorageBlock(const std::string& name, const int& bindingIndex)
|
||||
{
|
||||
glShaderStorageBlockBinding(prog, GetProgramResourceIndex(name), bindingIndex);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
220
Thirdparty/Pangolin/include/pangolin/gl/glstate.h
vendored
Normal file
220
Thirdparty/Pangolin/include/pangolin/gl/glstate.h
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2013 Vincent Mamo, 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 <stack>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
class GlState {
|
||||
|
||||
class CapabilityState {
|
||||
public:
|
||||
|
||||
CapabilityState(GLenum cap, GLboolean enable)
|
||||
: m_cap(cap), m_enable(enable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Apply() {
|
||||
if(m_enable) {
|
||||
::glEnable(m_cap);
|
||||
}else{
|
||||
::glDisable(m_cap);
|
||||
}
|
||||
}
|
||||
|
||||
void UnApply() {
|
||||
if(m_enable) {
|
||||
::glDisable(m_cap);
|
||||
}else{
|
||||
::glEnable(m_cap);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
GLenum m_cap;
|
||||
GLboolean m_enable;
|
||||
};
|
||||
|
||||
public:
|
||||
GlState()
|
||||
: m_DepthMaskCalled(false),
|
||||
m_ShadeModelCalled(false),
|
||||
m_CullFaceCalled(false),
|
||||
m_PointSizeCalled(false),
|
||||
m_LineWidthCalled(false),
|
||||
m_ColorMaskCalled(false),
|
||||
m_ViewportCalled(false)
|
||||
{
|
||||
}
|
||||
|
||||
~GlState() {
|
||||
// Restore original state
|
||||
while (!m_history.empty()) {
|
||||
m_history.top().UnApply();
|
||||
m_history.pop();
|
||||
}
|
||||
|
||||
if (m_DepthMaskCalled) {
|
||||
::glDepthMask(m_OriginalDepthMask);
|
||||
}
|
||||
|
||||
if (m_ShadeModelCalled) {
|
||||
::glShadeModel(m_OriginalShadeModel);
|
||||
}
|
||||
|
||||
if (m_CullFaceCalled) {
|
||||
::glCullFace(m_OriginalCullFace);
|
||||
}
|
||||
|
||||
if(m_PointSizeCalled) {
|
||||
::glPointSize(m_OriginalPointSize);
|
||||
}
|
||||
|
||||
if(m_LineWidthCalled) {
|
||||
::glLineWidth(m_OriginalLineWidth);
|
||||
}
|
||||
|
||||
if (m_ColorMaskCalled) {
|
||||
::glColorMask(m_OriginalColorMask[0], m_OriginalColorMask[1], m_OriginalColorMask[2], m_OriginalColorMask[3]);
|
||||
}
|
||||
|
||||
if (m_ViewportCalled) {
|
||||
::glViewport(m_OriginalViewport[0], m_OriginalViewport[1], m_OriginalViewport[2], m_OriginalViewport[3]);
|
||||
}
|
||||
}
|
||||
|
||||
static inline GLboolean IsEnabled(GLenum cap)
|
||||
{
|
||||
GLboolean curVal;
|
||||
glGetBooleanv(cap, &curVal);
|
||||
return curVal;
|
||||
}
|
||||
|
||||
inline void glEnable(GLenum cap)
|
||||
{
|
||||
if(!IsEnabled(cap)) {
|
||||
m_history.push(CapabilityState(cap,true));
|
||||
::glEnable(cap);
|
||||
}
|
||||
}
|
||||
|
||||
inline void glDisable(GLenum cap)
|
||||
{
|
||||
if(IsEnabled(cap)) {
|
||||
m_history.push(CapabilityState(cap,false));
|
||||
::glDisable(cap);
|
||||
}
|
||||
}
|
||||
|
||||
bool m_DepthMaskCalled;
|
||||
GLboolean m_OriginalDepthMask;
|
||||
inline void glDepthMask(GLboolean flag)
|
||||
{
|
||||
if(!m_DepthMaskCalled) {
|
||||
m_DepthMaskCalled = true;
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, &m_OriginalDepthMask);
|
||||
}
|
||||
::glDepthMask(flag);
|
||||
}
|
||||
|
||||
bool m_ShadeModelCalled;
|
||||
GLint m_OriginalShadeModel;
|
||||
inline void glShadeModel(GLint mode)
|
||||
{
|
||||
if(!m_ShadeModelCalled) {
|
||||
m_ShadeModelCalled = true;
|
||||
glGetIntegerv(GL_SHADE_MODEL, &m_OriginalShadeModel);
|
||||
}
|
||||
::glShadeModel(mode);
|
||||
}
|
||||
|
||||
bool m_CullFaceCalled;
|
||||
GLint m_OriginalCullFace;
|
||||
void glCullFace(GLenum mode)
|
||||
{
|
||||
if(!m_ShadeModelCalled) {
|
||||
m_ShadeModelCalled = true;
|
||||
glGetIntegerv(GL_CULL_FACE_MODE, &m_OriginalCullFace);
|
||||
}
|
||||
::glCullFace(mode);
|
||||
}
|
||||
|
||||
bool m_PointSizeCalled;
|
||||
GLfloat m_OriginalPointSize;
|
||||
void glPointSize(GLfloat size)
|
||||
{
|
||||
if(!m_PointSizeCalled) {
|
||||
m_PointSizeCalled = true;
|
||||
glGetFloatv(GL_POINT_SIZE, &m_OriginalPointSize);
|
||||
}
|
||||
::glPointSize(size);
|
||||
}
|
||||
|
||||
bool m_LineWidthCalled;
|
||||
GLfloat m_OriginalLineWidth;
|
||||
void glLineWidth(GLfloat width)
|
||||
{
|
||||
if(!m_LineWidthCalled) {
|
||||
m_LineWidthCalled = true;
|
||||
glGetFloatv(GL_LINE_WIDTH, &m_OriginalLineWidth);
|
||||
}
|
||||
::glLineWidth(width);
|
||||
|
||||
}
|
||||
|
||||
bool m_ColorMaskCalled;
|
||||
GLboolean m_OriginalColorMask[4];
|
||||
inline void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
|
||||
{
|
||||
if(!m_ColorMaskCalled) {
|
||||
m_ColorMaskCalled = true;
|
||||
glGetBooleanv(GL_COLOR_WRITEMASK, m_OriginalColorMask);
|
||||
}
|
||||
::glColorMask(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
bool m_ViewportCalled;
|
||||
GLint m_OriginalViewport[4];
|
||||
inline void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
|
||||
{
|
||||
if(!m_ViewportCalled) {
|
||||
m_ViewportCalled = true;
|
||||
glGetIntegerv(GL_VIEWPORT, m_OriginalViewport);
|
||||
}
|
||||
::glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
std::stack<CapabilityState> m_history;
|
||||
};
|
||||
|
||||
}
|
||||
98
Thirdparty/Pangolin/include/pangolin/gl/gltext.h
vendored
Normal file
98
Thirdparty/Pangolin/include/pangolin/gl/gltext.h
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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 <pangolin/gl/gl.h>
|
||||
#include <pangolin/gl/glchar.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
class PANGOLIN_EXPORT GlText
|
||||
{
|
||||
public:
|
||||
GlText();
|
||||
|
||||
GlText(const GlText& txt);
|
||||
|
||||
GlText(const GlTexture& font_tex);
|
||||
|
||||
void AddSpace(GLfloat s);
|
||||
|
||||
// Add specified charector to this string.
|
||||
void Add(unsigned char c, const GlChar& glc);
|
||||
|
||||
// Clear text
|
||||
void Clear();
|
||||
|
||||
// Render without transform in text-centric pixel coordinates
|
||||
void Draw() const;
|
||||
void DrawGlSl() const;
|
||||
|
||||
#ifdef BUILD_PANGOLIN_GUI
|
||||
// Render at (x,y,z)' in object coordinates,
|
||||
// keeping text size and orientation constant
|
||||
void Draw(GLfloat x, GLfloat y, GLfloat z = 0.0f) const;
|
||||
|
||||
// Render at (x,y,z)' in window coordinates.
|
||||
void DrawWindow(GLfloat x, GLfloat y, GLfloat z = 0.0f) const;
|
||||
#endif // BUILD_PANGOLIN_GUI
|
||||
|
||||
// Return text that this object signifies.
|
||||
const std::string& Text() const {
|
||||
return str;
|
||||
}
|
||||
|
||||
// Return width in pixels of this text.
|
||||
GLfloat Width() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
// Return height in pixels of this text.
|
||||
GLfloat Height() const {
|
||||
return ymax;
|
||||
}
|
||||
|
||||
// Return height in pixels of this text, including under baseline
|
||||
GLfloat FullHeight() const {
|
||||
return ymax - ymin;
|
||||
}
|
||||
|
||||
//protected:
|
||||
const GlTexture* tex;
|
||||
std::string str;
|
||||
GLfloat width;
|
||||
GLfloat ymin;
|
||||
GLfloat ymax;
|
||||
|
||||
std::vector<XYUV> vs;
|
||||
};
|
||||
|
||||
}
|
||||
116
Thirdparty/Pangolin/include/pangolin/gl/gltexturecache.h
vendored
Normal file
116
Thirdparty/Pangolin/include/pangolin/gl/gltexturecache.h
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/* 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/gl/gl.h>
|
||||
#include <pangolin/gl/glformattraits.h>
|
||||
#include <pangolin/gl/glpixformat.h>
|
||||
#include <pangolin/image/image.h>
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
class PANGOLIN_EXPORT TextureCache
|
||||
{
|
||||
public:
|
||||
static TextureCache& I();
|
||||
|
||||
GlTexture& GlTex(GLsizei w, GLsizei h, GLint internal_format, GLint glformat, GLenum gltype)
|
||||
{
|
||||
const long key =
|
||||
(((long)internal_format)<<20) ^
|
||||
(((long)glformat)<<10) ^ gltype;
|
||||
|
||||
// Lookup texture
|
||||
std::shared_ptr<GlTexture>& ptex = texture_map[key];
|
||||
if(!ptex) {
|
||||
ptex = std::shared_ptr<GlTexture>(new GlTexture());
|
||||
}
|
||||
GlTexture& tex = *ptex;
|
||||
|
||||
// Initialise if it didn't already exist or the size was too small
|
||||
if(!tex.tid || tex.width < w || tex.height < h) {
|
||||
tex.Reinitialise(
|
||||
std::max(tex.width,w), std::max(tex.height,h),
|
||||
internal_format, default_sampling_linear, 0,
|
||||
glformat, gltype
|
||||
);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
GlTexture& GlTex(GLsizei w, GLsizei h)
|
||||
{
|
||||
return GlTex( w, h,
|
||||
GlFormatTraits<T>::glinternalformat,
|
||||
GlFormatTraits<T>::glformat,
|
||||
GlFormatTraits<T>::gltype
|
||||
);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool default_sampling_linear;
|
||||
std::map<long, std::shared_ptr<GlTexture> > texture_map;
|
||||
|
||||
// Protected constructor
|
||||
TextureCache()
|
||||
: default_sampling_linear(true)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void RenderToViewport(Image<T>& image, bool flipx=false, bool flipy=false)
|
||||
{
|
||||
// Retrieve texture that is at least as large as image and of appropriate type.
|
||||
GlTexture& tex = TextureCache::I().GlTex<T>(image.w, image.h);
|
||||
tex.Upload(image.ptr,0,0, image.w, image.h, GlFormatTraits<T>::glformat, GlFormatTraits<T>::gltype);
|
||||
tex.RenderToViewport(Viewport(0,0,image.w, image.h), flipx, flipy);
|
||||
}
|
||||
|
||||
// This method may dissapear in the future
|
||||
inline void RenderToViewport(
|
||||
Image<unsigned char>& image,
|
||||
const pangolin::GlPixFormat& fmt,
|
||||
bool flipx=false, bool flipy=false,
|
||||
bool linear_sampling = true
|
||||
) {
|
||||
pangolin::GlTexture& tex = pangolin::TextureCache::I().GlTex((GLsizei)image.w, (GLsizei)image.h, fmt.scalable_internal_format, fmt.glformat, fmt.gltype);
|
||||
tex.Bind();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear_sampling ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear_sampling ? GL_LINEAR : GL_NEAREST);
|
||||
tex.Upload(image.ptr,0,0, (GLsizei)image.w, (GLsizei)image.h, fmt.glformat, fmt.gltype);
|
||||
tex.RenderToViewport(pangolin::Viewport(0,0,(GLint)image.w, (GLint)image.h), flipx, flipy);
|
||||
}
|
||||
|
||||
}
|
||||
225
Thirdparty/Pangolin/include/pangolin/gl/glvbo.h
vendored
Normal file
225
Thirdparty/Pangolin/include/pangolin/gl/glvbo.h
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
/* 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/gl.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Interface
|
||||
////////////////////////////////////////////////
|
||||
|
||||
void MakeTriangleStripIboForVbo(GlBuffer& ibo, int w, int h);
|
||||
|
||||
GlBuffer MakeTriangleStripIboForVbo(int w, int h);
|
||||
|
||||
void RenderVbo(GlBuffer& vbo, GLenum mode = GL_POINTS);
|
||||
|
||||
void RenderVboCbo(GlBuffer& vbo, GlBuffer& cbo, bool draw_color = true, GLenum mode = GL_POINTS);
|
||||
|
||||
void RenderVboIbo(GlBuffer& vbo, GlBuffer& ibo, bool draw_mesh = true);
|
||||
|
||||
void RenderVboIboCbo(GlBuffer& vbo, GlBuffer& ibo, GlBuffer& cbo, bool draw_mesh = true, bool draw_color = true);
|
||||
|
||||
void RenderVboIboNbo(GlBuffer& vbo, GlBuffer& ibo, GlBuffer& nbo, bool draw_mesh = true, bool draw_normals = true);
|
||||
|
||||
void RenderVboIboCboNbo(GlBuffer& vbo, GlBuffer& ibo, GlBuffer& cbo, GlBuffer& nbo, bool draw_mesh = true, bool draw_color = true, bool draw_normals = true);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Implementation
|
||||
////////////////////////////////////////////////
|
||||
|
||||
inline void MakeTriangleStripIboForVbo(GlBuffer& ibo, int w, int h)
|
||||
{
|
||||
const int num_elements = w*(h-1)*2;
|
||||
unsigned int* buffer = new unsigned int[num_elements];
|
||||
unsigned int* ptr = buffer;
|
||||
|
||||
for(int y=0; y < (h-1);)
|
||||
{
|
||||
for(int x=0; x<w; ++x) {
|
||||
(*ptr++) = y*w+x;
|
||||
(*ptr++) = (y+1)*w+x;
|
||||
}
|
||||
++y;
|
||||
|
||||
if(y>=(h-1)) break;
|
||||
for(int x=w-1; x>=0; --x) {
|
||||
(*ptr++) = y*w+x;
|
||||
(*ptr++) = (y+1)*w+x;
|
||||
}
|
||||
++y;
|
||||
}
|
||||
|
||||
ibo.Reinitialise(GlElementArrayBuffer, num_elements, GL_UNSIGNED_INT, 1, GL_STATIC_DRAW );
|
||||
ibo.Upload(buffer, sizeof(unsigned int)*num_elements );
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
inline GlBuffer MakeTriangleStripIboForVbo(int w, int h)
|
||||
{
|
||||
GlBuffer ibo;
|
||||
MakeTriangleStripIboForVbo(ibo,w,h);
|
||||
return ibo;
|
||||
}
|
||||
|
||||
inline void RenderVbo(GlBuffer& vbo, GLenum mode)
|
||||
{
|
||||
vbo.Bind();
|
||||
glVertexPointer(vbo.count_per_element, vbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glDrawArrays(mode, 0, vbo.num_elements);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
vbo.Unbind();
|
||||
}
|
||||
|
||||
inline void RenderVboCbo(GlBuffer& vbo, GlBuffer& cbo, bool draw_color, GLenum mode )
|
||||
{
|
||||
if(draw_color) {
|
||||
cbo.Bind();
|
||||
glColorPointer(cbo.count_per_element, cbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
RenderVbo(vbo,mode);
|
||||
|
||||
if(draw_color) {
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
cbo.Unbind();
|
||||
}
|
||||
}
|
||||
|
||||
inline void RenderVboIbo(GlBuffer& vbo, GlBuffer& ibo, bool draw_mesh)
|
||||
{
|
||||
vbo.Bind();
|
||||
glVertexPointer(vbo.count_per_element, vbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if(draw_mesh) {
|
||||
ibo.Bind();
|
||||
glDrawElements(GL_TRIANGLE_STRIP,ibo.num_elements, ibo.datatype, 0);
|
||||
ibo.Unbind();
|
||||
}else{
|
||||
glDrawArrays(GL_POINTS, 0, vbo.num_elements);
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
vbo.Unbind();
|
||||
}
|
||||
|
||||
inline void RenderVboIboCbo(GlBuffer& vbo, GlBuffer& ibo, GlBuffer& cbo, bool draw_mesh, bool draw_color )
|
||||
{
|
||||
if(draw_color) {
|
||||
cbo.Bind();
|
||||
glColorPointer(cbo.count_per_element, cbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
RenderVboIbo(vbo,ibo,draw_mesh);
|
||||
|
||||
if(draw_color) {
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
cbo.Unbind();
|
||||
}
|
||||
}
|
||||
|
||||
inline void RenderVboIboCboNbo(GlBuffer& vbo, GlBuffer& ibo, GlBuffer& cbo, GlBuffer& nbo, bool draw_mesh, bool draw_color, bool draw_normals)
|
||||
{
|
||||
if(draw_color) {
|
||||
cbo.Bind();
|
||||
glColorPointer(cbo.count_per_element, cbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
if(draw_normals) {
|
||||
nbo.Bind();
|
||||
glNormalPointer(nbo.datatype, (GLsizei)(nbo.count_per_element * GlDataTypeBytes(nbo.datatype)),0);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
vbo.Bind();
|
||||
glVertexPointer(vbo.count_per_element, vbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if(draw_mesh) {
|
||||
ibo.Bind();
|
||||
glDrawElements(GL_TRIANGLE_STRIP,ibo.num_elements, ibo.datatype, 0);
|
||||
ibo.Unbind();
|
||||
}else{
|
||||
glDrawArrays(GL_POINTS, 0, vbo.num_elements);
|
||||
}
|
||||
|
||||
if(draw_color) {
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
cbo.Unbind();
|
||||
}
|
||||
|
||||
if(draw_normals) {
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
nbo.Unbind();
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
vbo.Unbind();
|
||||
}
|
||||
|
||||
inline void RenderVboIboNbo(GlBuffer& vbo, GlBuffer& ibo, GlBuffer& nbo, bool draw_mesh, bool draw_normals)
|
||||
{
|
||||
vbo.Bind();
|
||||
glVertexPointer(vbo.count_per_element, vbo.datatype, 0, 0);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if(draw_normals) {
|
||||
nbo.Bind();
|
||||
glNormalPointer(nbo.datatype, (GLsizei)(nbo.count_per_element * GlDataTypeBytes(nbo.datatype)), 0);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
if(draw_mesh) {
|
||||
ibo.Bind();
|
||||
glDrawElements(GL_TRIANGLE_STRIP,ibo.num_elements, ibo.datatype, 0);
|
||||
ibo.Unbind();
|
||||
}else{
|
||||
glDrawArrays(GL_POINTS, 0, vbo.num_elements);
|
||||
}
|
||||
|
||||
if(draw_normals) {
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
nbo.Unbind();
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
vbo.Unbind();
|
||||
}
|
||||
|
||||
}
|
||||
116
Thirdparty/Pangolin/include/pangolin/handler/handler.h
vendored
Normal file
116
Thirdparty/Pangolin/include/pangolin/handler/handler.h
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/* 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 <pangolin/display/opengl_render_state.h>
|
||||
#include <pangolin/handler/handler_enums.h>
|
||||
|
||||
#if defined(HAVE_EIGEN) && !defined(__CUDACC__) //prevent including Eigen in cuda files
|
||||
#define USE_EIGEN
|
||||
#endif
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
#include <Eigen/Core>
|
||||
#endif
|
||||
|
||||
#ifdef _OSX_
|
||||
#define PANGO_DFLT_HANDLER3D_ZF (1.0f/50.0f)
|
||||
#else
|
||||
#define PANGO_DFLT_HANDLER3D_ZF (1.0f/10.0f)
|
||||
#endif
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
struct View;
|
||||
|
||||
/// Input Handler base class.
|
||||
/// Virtual methods which recurse into sub-displays.
|
||||
struct PANGOLIN_EXPORT Handler
|
||||
{
|
||||
virtual ~Handler() {}
|
||||
virtual void Keyboard(View&, unsigned char key, int x, int y, bool pressed);
|
||||
virtual void Mouse(View&, MouseButton button, int x, int y, bool pressed, int button_state);
|
||||
virtual void MouseMotion(View&, int x, int y, int button_state);
|
||||
virtual void PassiveMouseMotion(View&, int x, int y, int button_state);
|
||||
virtual void Special(View&, InputSpecial inType, float x, float y, float p1, float p2, float p3, float p4, int button_state);
|
||||
};
|
||||
|
||||
struct PANGOLIN_EXPORT HandlerScroll : Handler
|
||||
{
|
||||
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int button_state);
|
||||
void Special(View&, InputSpecial inType, float x, float y, float p1, float p2, float p3, float p4, int button_state);
|
||||
};
|
||||
|
||||
struct PANGOLIN_EXPORT Handler3D : Handler
|
||||
{
|
||||
Handler3D(OpenGlRenderState& cam_state, AxisDirection enforce_up=AxisNone, float trans_scale=0.01f, float zoom_fraction= PANGO_DFLT_HANDLER3D_ZF);
|
||||
|
||||
virtual bool ValidWinDepth(GLprecision depth);
|
||||
virtual void PixelUnproject( View& view, GLprecision winx, GLprecision winy, GLprecision winz, GLprecision Pc[3]);
|
||||
virtual void GetPosNormal(View& view, int x, int y, GLprecision p[3], GLprecision Pw[3], GLprecision Pc[3], GLprecision nw[3], GLprecision default_z = 1.0);
|
||||
|
||||
void Keyboard(View&, unsigned char key, int x, int y, bool pressed);
|
||||
void Mouse(View&, MouseButton button, int x, int y, bool pressed, int button_state);
|
||||
void MouseMotion(View&, int x, int y, int button_state);
|
||||
void Special(View&, InputSpecial inType, float x, float y, float p1, float p2, float p3, float p4, int button_state);
|
||||
|
||||
#ifdef USE_EIGEN
|
||||
// Return selected point in world coordinates
|
||||
inline Eigen::Vector3d Selected_P_w() const {
|
||||
return Eigen::Map<const Eigen::Matrix<GLprecision,3,1>>(Pw).cast<double>();
|
||||
}
|
||||
#endif
|
||||
inline int KeyState() const{
|
||||
return funcKeyState;
|
||||
}
|
||||
|
||||
protected:
|
||||
OpenGlRenderState* cam_state;
|
||||
const static int hwin = 8;
|
||||
AxisDirection enforce_up;
|
||||
float tf; // translation factor
|
||||
float zf; // zoom fraction
|
||||
CameraSpec cameraspec;
|
||||
GLprecision last_z;
|
||||
float last_pos[2];
|
||||
GLprecision rot_center[3];
|
||||
|
||||
GLprecision p[3];
|
||||
GLprecision Pw[3];
|
||||
GLprecision Pc[3];
|
||||
GLprecision n[3];
|
||||
|
||||
int funcKeyState;
|
||||
};
|
||||
|
||||
static Handler StaticHandler;
|
||||
static HandlerScroll StaticHandlerScroll;
|
||||
|
||||
}
|
||||
94
Thirdparty/Pangolin/include/pangolin/handler/handler_enums.h
vendored
Normal file
94
Thirdparty/Pangolin/include/pangolin/handler/handler_enums.h
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/* 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
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
// Supported Key modifiers for GlobalKeyPressCallback.
|
||||
// e.g. PANGO_CTRL + 'r', PANGO_SPECIAL + PANGO_KEY_RIGHT, etc.
|
||||
const int PANGO_SPECIAL = 128;
|
||||
const int PANGO_CTRL = -96;
|
||||
const int PANGO_OPTN = 132;
|
||||
|
||||
// Ordinary keys
|
||||
const int PANGO_KEY_TAB = 9;
|
||||
const int PANGO_KEY_ESCAPE = 27;
|
||||
|
||||
// Special Keys (same as GLUT_ defines)
|
||||
const int PANGO_KEY_F1 = 1;
|
||||
const int PANGO_KEY_F2 = 2;
|
||||
const int PANGO_KEY_F3 = 3;
|
||||
const int PANGO_KEY_F4 = 4;
|
||||
const int PANGO_KEY_F5 = 5;
|
||||
const int PANGO_KEY_F6 = 6;
|
||||
const int PANGO_KEY_F7 = 7;
|
||||
const int PANGO_KEY_F8 = 8;
|
||||
const int PANGO_KEY_F9 = 9;
|
||||
const int PANGO_KEY_F10 = 10;
|
||||
const int PANGO_KEY_F11 = 11;
|
||||
const int PANGO_KEY_F12 = 12;
|
||||
const int PANGO_KEY_LEFT = 100;
|
||||
const int PANGO_KEY_UP = 101;
|
||||
const int PANGO_KEY_RIGHT = 102;
|
||||
const int PANGO_KEY_DOWN = 103;
|
||||
const int PANGO_KEY_PAGE_UP = 104;
|
||||
const int PANGO_KEY_PAGE_DOWN = 105;
|
||||
const int PANGO_KEY_HOME = 106;
|
||||
const int PANGO_KEY_END = 107;
|
||||
const int PANGO_KEY_INSERT = 108;
|
||||
|
||||
enum MouseButton
|
||||
{
|
||||
MouseButtonLeft = 1,
|
||||
MouseButtonMiddle = 2,
|
||||
MouseButtonRight = 4,
|
||||
MouseWheelUp = 8,
|
||||
MouseWheelDown = 16,
|
||||
MouseWheelRight = 32,
|
||||
MouseWheelLeft = 64,
|
||||
};
|
||||
|
||||
enum KeyModifier
|
||||
{
|
||||
KeyModifierShift = 1<<16,
|
||||
KeyModifierCtrl = 1<<17,
|
||||
KeyModifierAlt = 1<<18,
|
||||
KeyModifierCmd = 1<<19,
|
||||
KeyModifierFnc = 1<<20
|
||||
};
|
||||
|
||||
enum InputSpecial
|
||||
{
|
||||
InputSpecialScroll,
|
||||
InputSpecialZoom,
|
||||
InputSpecialRotate,
|
||||
InputSpecialTablet
|
||||
};
|
||||
|
||||
}
|
||||
48
Thirdparty/Pangolin/include/pangolin/handler/handler_glbuffer.h
vendored
Normal file
48
Thirdparty/Pangolin/include/pangolin/handler/handler_glbuffer.h
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef HANDLER_GLBUFFER_H
|
||||
#define HANDLER_GLBUFFER_H
|
||||
|
||||
#include <pangolin/handler/handler.h>
|
||||
#include <pangolin/gl/gl.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
struct Handler3DFramebuffer : public pangolin::Handler3D
|
||||
{
|
||||
Handler3DFramebuffer(GlFramebuffer& fb, pangolin::OpenGlRenderState& cam_state, pangolin::AxisDirection enforce_up=pangolin::AxisNone, float trans_scale=0.01f);
|
||||
void GetPosNormal(pangolin::View& view, int x, int y, GLprecision p[3], GLprecision Pw[3], GLprecision Pc[3], GLprecision /*n*/[3], GLprecision default_z);
|
||||
|
||||
protected:
|
||||
GlFramebuffer& fb;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // HANDLER_GLBUFFER_H
|
||||
162
Thirdparty/Pangolin/include/pangolin/handler/handler_image.h
vendored
Normal file
162
Thirdparty/Pangolin/include/pangolin/handler/handler_image.h
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/* 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 <pangolin/image/image_utils.h>
|
||||
#include <pangolin/display/viewport.h>
|
||||
#include <pangolin/display/view.h>
|
||||
#include <pangolin/handler/handler.h>
|
||||
#include <pangolin/plot/range.h>
|
||||
#include <pangolin/gl/gl.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
class ImageViewHandler : public Handler
|
||||
{
|
||||
public:
|
||||
struct EventData {
|
||||
EventData(View& v, ImageViewHandler& h) : view(v), handler(h) {}
|
||||
View& view;
|
||||
ImageViewHandler& handler;
|
||||
};
|
||||
|
||||
struct OnSelectionEventData : public EventData {
|
||||
OnSelectionEventData(View& v, ImageViewHandler& h, bool dragging)
|
||||
: EventData(v,h), dragging(dragging) {}
|
||||
bool dragging;
|
||||
};
|
||||
|
||||
typedef std::function<void(OnSelectionEventData)> OnSelectionCallbackFn;
|
||||
|
||||
// Default constructor: User must call SetDimensions() once image dimensions are known.
|
||||
// Default range is [0,1] in x and y.
|
||||
ImageViewHandler();
|
||||
|
||||
// View ranges store extremes of image (boundary of pixels)
|
||||
// in 'discrete' coords, where 0,0 is center of top-left pixel.
|
||||
ImageViewHandler(size_t w, size_t h);
|
||||
|
||||
void SetDimensions(size_t w, size_t h);
|
||||
|
||||
void UpdateView();
|
||||
|
||||
void glSetViewOrtho();
|
||||
|
||||
void glRenderTexture(pangolin::GlTexture& tex);
|
||||
void glRenderTexture(GLuint tex, GLint width, GLint height);
|
||||
|
||||
void glRenderOverlay();
|
||||
|
||||
void ScreenToImage(Viewport& v, float xpix, float ypix, float& ximg, float& yimg);
|
||||
|
||||
void ImageToScreen(Viewport& v, float ximg, float yimg, float& xpix, float& ypix);
|
||||
|
||||
bool UseNN() const;
|
||||
|
||||
bool& UseNN();
|
||||
|
||||
bool& FlipTextureX();
|
||||
|
||||
bool& FlipTextureY();
|
||||
|
||||
pangolin::XYRangef& GetViewToRender();
|
||||
|
||||
float GetViewScale();
|
||||
|
||||
pangolin::XYRangef& GetView();
|
||||
|
||||
pangolin::XYRangef& GetDefaultView();
|
||||
|
||||
pangolin::XYRangef& GetSelection();
|
||||
|
||||
void GetHover(float& x, float& y);
|
||||
|
||||
void SetView(const pangolin::XYRangef& range);
|
||||
|
||||
void SetViewSmooth(const pangolin::XYRangef& range);
|
||||
|
||||
void ScrollView(float x, float y);
|
||||
|
||||
void ScrollViewSmooth(float x, float y);
|
||||
|
||||
void ScaleView(float x, float y, float cx, float cy);
|
||||
|
||||
void ScaleViewSmooth(float x, float y, float cx, float cy);
|
||||
|
||||
void ResetView();
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
/// pangolin::Handler
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
void Keyboard(View&, unsigned char key, int /*x*/, int /*y*/, bool pressed) override;
|
||||
|
||||
void Mouse(View& view, pangolin::MouseButton button, int x, int y, bool pressed, int button_state) override;
|
||||
|
||||
void MouseMotion(View& view, int x, int y, int button_state) override;
|
||||
|
||||
void PassiveMouseMotion(View&, int /*x*/, int /*y*/, int /*button_state*/) override;
|
||||
|
||||
void Special(View& view, pangolin::InputSpecial inType, float x, float y, float p1, float p2, float /*p3*/, float /*p4*/, int /*button_state*/) override;
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
/// Callbacks
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
OnSelectionCallbackFn OnSelectionCallback;
|
||||
|
||||
protected:
|
||||
void FixSelection(XYRangef& sel);
|
||||
|
||||
void AdjustScale();
|
||||
|
||||
void AdjustTranslation();
|
||||
|
||||
static ImageViewHandler* to_link;
|
||||
static float animate_factor;
|
||||
|
||||
ImageViewHandler* linked_view_handler;
|
||||
|
||||
pangolin::XYRangef rview_default;
|
||||
pangolin::XYRangef rview_max;
|
||||
pangolin::XYRangef rview;
|
||||
pangolin::XYRangef target;
|
||||
pangolin::XYRangef selection;
|
||||
|
||||
float hover_img[2];
|
||||
int last_mouse_pos[2];
|
||||
|
||||
bool use_nn;
|
||||
bool flipTextureX;
|
||||
bool flipTextureY;
|
||||
};
|
||||
|
||||
}
|
||||
45
Thirdparty/Pangolin/include/pangolin/image/copy.h
vendored
Normal file
45
Thirdparty/Pangolin/include/pangolin/image/copy.h
vendored
Normal 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
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
// Hold a reference to an object to be copied
|
||||
template<typename T>
|
||||
struct CopyObject {
|
||||
CopyObject(const T& obj) : obj(obj) { }
|
||||
const T& obj;
|
||||
};
|
||||
|
||||
// Return copy wrapper for assignment to another object.
|
||||
template<typename T>
|
||||
typename pangolin::CopyObject<T> Copy(const T& obj) {
|
||||
return typename pangolin::CopyObject<T>(obj);
|
||||
}
|
||||
|
||||
}
|
||||
428
Thirdparty/Pangolin/include/pangolin/image/image.h
vendored
Normal file
428
Thirdparty/Pangolin/include/pangolin/image/image.h
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
/* 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/image/memcpy.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef PANGO_ENABLE_BOUNDS_CHECKS
|
||||
# define PANGO_BOUNDS_ASSERT(...) PANGO_ENSURE(##__VA_ARGS__)
|
||||
#else
|
||||
# define PANGO_BOUNDS_ASSERT(...) ((void)0)
|
||||
#endif
|
||||
|
||||
// Allow user defined macro to be inserted into Image class.
|
||||
#ifndef PANGO_EXTENSION_IMAGE
|
||||
# define PANGO_EXTENSION_IMAGE
|
||||
#endif
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
// Simple image wrapper
|
||||
template<typename T>
|
||||
struct Image
|
||||
{
|
||||
using PixelType = T;
|
||||
|
||||
inline Image()
|
||||
: pitch(0), ptr(0), w(0), h(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline Image(T* ptr, size_t w, size_t h, size_t pitch)
|
||||
: pitch(pitch), ptr(ptr), w(w), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
size_t SizeBytes() const
|
||||
{
|
||||
return pitch * h;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
size_t Area() const
|
||||
{
|
||||
return w * h;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool IsValid() const
|
||||
{
|
||||
return ptr != 0;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool IsContiguous() const
|
||||
{
|
||||
return w*sizeof(T) == pitch;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Iterators
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T* begin()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T* end()
|
||||
{
|
||||
return RowPtr(h-1) + w;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T* begin() const
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T* end() const
|
||||
{
|
||||
return RowPtr(h-1) + w;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
size_t size() const
|
||||
{
|
||||
return w*h;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Image transforms
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
template<typename UnaryOperation>
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Transform(UnaryOperation unary_op)
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
|
||||
for(size_t y=0; y < h; ++y) {
|
||||
T* el = RowPtr(y);
|
||||
const T* el_end = el+w;
|
||||
for( ; el != el_end; ++el) {
|
||||
*el = unary_op(*el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Fill(const T& val)
|
||||
{
|
||||
Transform( [&](const T&) {return val;} );
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Replace(const T& oldval, const T& newval)
|
||||
{
|
||||
Transform( [&](const T& val) {
|
||||
return (val == oldval) ? newval : val;
|
||||
});
|
||||
}
|
||||
|
||||
inline
|
||||
void Memset(unsigned char v = 0)
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
if(IsContiguous()) {
|
||||
::pangolin::Memset((char*)ptr, v, pitch*h);
|
||||
}else{
|
||||
for(size_t y=0; y < h; ++y) {
|
||||
::pangolin::Memset((char*)RowPtr(y), v, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyFrom(const Image<T>& img)
|
||||
{
|
||||
if(IsValid() && img.IsValid()) {
|
||||
PANGO_ASSERT(w >= img.w && h >= img.h);
|
||||
PitchedCopy((char*)ptr,pitch,(char*)img.ptr,img.pitch, std::min(img.w,w)*sizeof(T), std::min(img.h,h) );
|
||||
}else if( img.IsValid() != IsValid() ){
|
||||
PANGO_ASSERT(false && "Cannot copy from / to an unasigned image." );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Reductions
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
template<typename BinaryOperation>
|
||||
PANGO_HOST_DEVICE inline
|
||||
T Accumulate(const T init, BinaryOperation binary_op)
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
|
||||
T val = init;
|
||||
for(size_t y=0; y < h; ++y) {
|
||||
T* el = RowPtr(y);
|
||||
const T* el_end = el+w;
|
||||
for(; el != el_end; ++el) {
|
||||
val = binary_op(val, *el);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
std::pair<T,T> MinMax() const
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
|
||||
std::pair<T,T> minmax(std::numeric_limits<T>::max(), std::numeric_limits<T>::lowest());
|
||||
for(size_t r=0; r < h; ++r) {
|
||||
const T* ptr = RowPtr(r);
|
||||
const T* end = ptr + w;
|
||||
while( ptr != end) {
|
||||
minmax.first = std::min(*ptr, minmax.first);
|
||||
minmax.second = std::max(*ptr, minmax.second);
|
||||
++ptr;
|
||||
}
|
||||
}
|
||||
return minmax;
|
||||
}
|
||||
|
||||
template<typename Tout=T>
|
||||
Tout Sum() const
|
||||
{
|
||||
return Accumulate((T)0, [](const T& lhs, const T& rhs){ return lhs + rhs; });
|
||||
}
|
||||
|
||||
template<typename Tout=T>
|
||||
Tout Mean() const
|
||||
{
|
||||
return Sum<Tout>() / Area();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Direct Pixel Access
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T* RowPtr(size_t y)
|
||||
{
|
||||
return (T*)((unsigned char*)(ptr) + y*pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T* RowPtr(size_t y) const
|
||||
{
|
||||
return (T*)((unsigned char*)(ptr) + y*pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T& operator()(size_t x, size_t y)
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(x,y) );
|
||||
return RowPtr(y)[x];
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T& operator()(size_t x, size_t y) const
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(x,y) );
|
||||
return RowPtr(y)[x];
|
||||
}
|
||||
|
||||
template<typename TVec>
|
||||
PANGO_HOST_DEVICE inline
|
||||
T& operator()(const TVec& p)
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(p[0],p[1]) );
|
||||
return RowPtr(p[1])[p[0]];
|
||||
}
|
||||
|
||||
template<typename TVec>
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T& operator()(const TVec& p) const
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(p[0],p[1]) );
|
||||
return RowPtr(p[1])[p[0]];
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T& operator[](size_t ix)
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InImage(ptr+ix) );
|
||||
return ptr[ix];
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T& operator[](size_t ix) const
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InImage(ptr+ix) );
|
||||
return ptr[ix];
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Bounds Checking
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE
|
||||
bool InImage(const T* ptest) const
|
||||
{
|
||||
return ptr <= ptest && ptest < RowPtr(h);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool InBounds(int x, int y) const
|
||||
{
|
||||
return 0 <= x && x < (int)w && 0 <= y && y < (int)h;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool InBounds(float x, float y, float border) const
|
||||
{
|
||||
return border <= x && x < (w-border) && border <= y && y < (h-border);
|
||||
}
|
||||
|
||||
template<typename TVec, typename TBorder>
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool InBounds( const TVec& p, const TBorder border = (TBorder)0 ) const
|
||||
{
|
||||
return border <= p[0] && p[0] < ((int)w - border) && border <= p[1] && p[1] < ((int)h - border);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Obtain slices / subimages
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const Image<const T> SubImage(size_t x, size_t y, size_t width, size_t height) const
|
||||
{
|
||||
PANGO_ASSERT( (x+width) <= w && (y+height) <= h);
|
||||
return Image<const T>( RowPtr(y)+x, width, height, pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<T> SubImage(size_t x, size_t y, size_t width, size_t height)
|
||||
{
|
||||
PANGO_ASSERT( (x+width) <= w && (y+height) <= h);
|
||||
return Image<T>( RowPtr(y)+x, width, height, pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const Image<T> Row(int y) const
|
||||
{
|
||||
return SubImage(0,y,w,1);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<T> Row(int y)
|
||||
{
|
||||
return SubImage(0,y,w,1);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const Image<T> Col(int x) const
|
||||
{
|
||||
return SubImage(x,0,1,h);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<T> Col(int x)
|
||||
{
|
||||
return SubImage(x,0,1,h);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Data mangling
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
template<typename TRecast>
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<TRecast> Reinterpret() const
|
||||
{
|
||||
PANGO_ASSERT(sizeof(TRecast) == sizeof(T), "sizeof(TRecast) must match sizeof(T): % != %", sizeof(TRecast), sizeof(T) );
|
||||
return UnsafeReinterpret<TRecast>();
|
||||
}
|
||||
|
||||
template<typename TRecast>
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<TRecast> UnsafeReinterpret() const
|
||||
{
|
||||
return Image<TRecast>((TRecast*)ptr,w,h,pitch);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Deprecated methods
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// PANGOLIN_DEPRECATED inline
|
||||
Image(size_t w, size_t h, size_t pitch, T* ptr)
|
||||
: pitch(pitch), ptr(ptr), w(w), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
// Use RAII/move aware pangolin::ManagedImage instead
|
||||
// PANGOLIN_DEPRECATED inline
|
||||
void Dealloc()
|
||||
{
|
||||
if(ptr) {
|
||||
::operator delete(ptr);
|
||||
ptr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Use RAII/move aware pangolin::ManagedImage instead
|
||||
// PANGOLIN_DEPRECATED inline
|
||||
void Alloc(size_t w, size_t h, size_t pitch)
|
||||
{
|
||||
Dealloc();
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->pitch = pitch;
|
||||
this->ptr = (T*)::operator new(h*pitch);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Data members
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
size_t pitch;
|
||||
T* ptr;
|
||||
size_t w;
|
||||
size_t h;
|
||||
|
||||
PANGO_EXTENSION_IMAGE
|
||||
};
|
||||
|
||||
}
|
||||
31
Thirdparty/Pangolin/include/pangolin/image/image_convert.h
vendored
Normal file
31
Thirdparty/Pangolin/include/pangolin/image/image_convert.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/image/managed_image.h>
|
||||
#include <pangolin/utils/compontent_cast.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
template <typename To, typename T>
|
||||
void ImageConvert(Image<To>& dst, const Image<T>& src, To scale = 1.0)
|
||||
{
|
||||
for(unsigned int y = 0; y < dst.h; ++y)
|
||||
{
|
||||
const T* prs = src.RowPtr(y);
|
||||
To* prd = dst.RowPtr(y);
|
||||
for(unsigned int x = 0; x < dst.w; ++x)
|
||||
{
|
||||
*(prd++) = scale * ComponentCast<To, T>::cast(*(prs++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename To, typename T>
|
||||
ManagedImage<To> ImageConvert(const Image<T>& src, To scale = 1.0)
|
||||
{
|
||||
ManagedImage<To> dst(src.w, src.h);
|
||||
ImageConvert<To,T>(dst,src,scale);
|
||||
return dst;
|
||||
}
|
||||
|
||||
}
|
||||
65
Thirdparty/Pangolin/include/pangolin/image/image_io.h
vendored
Normal file
65
Thirdparty/Pangolin/include/pangolin/image/image_io.h
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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 <pangolin/platform.h>
|
||||
|
||||
#include <pangolin/image/typed_image.h>
|
||||
#include <pangolin/utils/file_extension.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(std::istream& in, ImageFileType file_type);
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(const std::string& filename, ImageFileType file_type);
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(const std::string& filename);
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(const std::string& filename, const PixelFormat& raw_fmt, size_t raw_width, size_t raw_height, size_t raw_pitch);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, std::ostream& out, ImageFileType file_type, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, const std::string& filename, ImageFileType file_type, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, const std::string& filename, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const TypedImage& image, const std::string& filename, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
}
|
||||
185
Thirdparty/Pangolin/include/pangolin/image/image_utils.h
vendored
Normal file
185
Thirdparty/Pangolin/include/pangolin/image/image_utils.h
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
/* 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 <limits>
|
||||
#include <utility>
|
||||
|
||||
#include <pangolin/image/image.h>
|
||||
#include <pangolin/plot/range.h>
|
||||
#include <pangolin/gl/gl.h>
|
||||
#include <pangolin/gl/glpixformat.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
std::pair<float, float> GetMinMax(const Image<T>& img, size_t channels)
|
||||
{
|
||||
const size_t max_channels = 3;
|
||||
const size_t colour_channels = std::min(channels, max_channels);
|
||||
std::pair<float, float> chan_mm[max_channels];
|
||||
for(size_t c = 0; c < max_channels; ++c)
|
||||
{
|
||||
chan_mm[c].first = +std::numeric_limits<float>::max();
|
||||
chan_mm[c].second = -std::numeric_limits<float>::max();
|
||||
}
|
||||
|
||||
for(size_t y = 0; y < img.h; ++y)
|
||||
{
|
||||
T* pix = (T*)((char*)img.ptr + y * img.pitch);
|
||||
for(size_t x = 0; x < img.w; ++x)
|
||||
{
|
||||
for(size_t c = 0; c < colour_channels; ++c)
|
||||
{
|
||||
if(pix[c] < chan_mm[c].first)
|
||||
chan_mm[c].first = (float)pix[c];
|
||||
if(pix[c] > chan_mm[c].second)
|
||||
chan_mm[c].second = (float)pix[c];
|
||||
}
|
||||
|
||||
pix += channels;
|
||||
}
|
||||
}
|
||||
|
||||
// Find min / max of all channels, ignoring 4th alpha channel
|
||||
std::pair<float, float> mm = chan_mm[0];
|
||||
for(size_t c = 1; c < colour_channels; ++c)
|
||||
{
|
||||
mm.first = std::min(mm.first, chan_mm[c].first);
|
||||
mm.second = std::max(mm.second, chan_mm[c].second);
|
||||
}
|
||||
|
||||
return mm;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
pangolin::Image<T> GetImageRoi( pangolin::Image<T> img, size_t channels, const pangolin::XYRangei& roi )
|
||||
{
|
||||
return pangolin::Image<T>(
|
||||
img.RowPtr(std::min(roi.y.min,roi.y.max)) + channels*std::min(roi.x.min,roi.x.max),
|
||||
roi.x.AbsSize(), roi.y.AbsSize(),
|
||||
img.pitch
|
||||
);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::pair<float,float> GetOffsetScale(const pangolin::Image<T>& img, size_t channels, float type_max, float format_max)
|
||||
{
|
||||
// Find min / max of all channels, ignoring 4th alpha channel
|
||||
const std::pair<float,float> mm = internal::GetMinMax<T>(img,channels);
|
||||
const float type_scale = format_max / type_max;
|
||||
const float offset = -type_scale* mm.first;
|
||||
const float scale = type_max / (mm.second - mm.first);
|
||||
return std::pair<float,float>(offset, scale);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
float GetScaleOnly(const pangolin::Image<T>& img, size_t channels, float type_max, float /*format_max*/)
|
||||
{
|
||||
// Find min / max of all channels, ignoring 4th alpha channel
|
||||
const std::pair<float,float> mm = internal::GetMinMax<T>(img,channels);
|
||||
const float scale = type_max / mm.second;
|
||||
return scale;
|
||||
}
|
||||
|
||||
} // internal
|
||||
|
||||
inline std::pair<float, float> GetMinMax(
|
||||
const Image<unsigned char>& img,
|
||||
XYRangei iroi, const GlPixFormat& glfmt
|
||||
) {
|
||||
using namespace internal;
|
||||
|
||||
iroi.Clamp(0, (int)img.w - 1, 0, (int)img.h - 1);
|
||||
|
||||
const size_t num_channels = pangolin::GlFormatChannels(glfmt.glformat);
|
||||
|
||||
if(glfmt.gltype == GL_UNSIGNED_BYTE) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<unsigned char>(), num_channels, iroi), num_channels);
|
||||
} else if(glfmt.gltype == GL_UNSIGNED_SHORT) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<unsigned short>(), num_channels, iroi), num_channels);
|
||||
} else if(glfmt.gltype == GL_FLOAT) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<float>(), num_channels, iroi), num_channels);
|
||||
} else if(glfmt.gltype == GL_DOUBLE) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<double>(), num_channels, iroi), num_channels);
|
||||
} else {
|
||||
return std::pair<float, float>(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest());
|
||||
}
|
||||
}
|
||||
|
||||
inline std::pair<float,float> GetOffsetScale(
|
||||
const pangolin::Image<unsigned char>& img,
|
||||
pangolin::XYRangei iroi, const pangolin::GlPixFormat& glfmt
|
||||
) {
|
||||
using namespace internal;
|
||||
|
||||
iroi.Clamp(0, (int)img.w-1, 0, (int)img.h-1 );
|
||||
|
||||
const size_t num_channels = pangolin::GlFormatChannels(glfmt.glformat);
|
||||
|
||||
if(glfmt.gltype == GL_UNSIGNED_BYTE) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<unsigned char>(), num_channels, iroi), num_channels, 255.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_UNSIGNED_SHORT) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<unsigned short>(), num_channels, iroi), num_channels, 65535.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_FLOAT) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<float>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_DOUBLE) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<double>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else{
|
||||
return std::pair<float,float>(0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
inline float GetScaleOnly(
|
||||
const pangolin::Image<unsigned char>& img,
|
||||
pangolin::XYRangei iroi, const pangolin::GlPixFormat& glfmt
|
||||
) {
|
||||
using namespace internal;
|
||||
|
||||
iroi.Clamp(0, (int)img.w-1, 0, (int)img.h-1 );
|
||||
|
||||
const size_t num_channels = pangolin::GlFormatChannels(glfmt.glformat);
|
||||
|
||||
if(glfmt.gltype == GL_UNSIGNED_BYTE) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<unsigned char>(), num_channels, iroi), num_channels, 255.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_UNSIGNED_SHORT) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<unsigned short>(), num_channels, iroi), num_channels, 65535.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_FLOAT) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<float>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_DOUBLE) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<double>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else{
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
175
Thirdparty/Pangolin/include/pangolin/image/managed_image.h
vendored
Normal file
175
Thirdparty/Pangolin/include/pangolin/image/managed_image.h
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/* 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/image/image.h>
|
||||
#include <pangolin/image/copy.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
template<class T> using DefaultImageAllocator = std::allocator<T>;
|
||||
|
||||
// Image that manages it's own memory, storing a strong pointer to it's memory
|
||||
template<typename T, class Allocator = DefaultImageAllocator<T> >
|
||||
class ManagedImage : public Image<T>
|
||||
{
|
||||
public:
|
||||
// Destructor
|
||||
inline
|
||||
~ManagedImage()
|
||||
{
|
||||
Deallocate();
|
||||
}
|
||||
|
||||
// Null image
|
||||
inline
|
||||
ManagedImage()
|
||||
{
|
||||
}
|
||||
|
||||
// Row image
|
||||
inline
|
||||
ManagedImage(size_t w)
|
||||
: Image<T>(
|
||||
Allocator().allocate(w),
|
||||
w, 1, w*sizeof(T)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ManagedImage(size_t w, size_t h)
|
||||
: Image<T>(
|
||||
Allocator().allocate(w*h),
|
||||
w, h, w*sizeof(T)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ManagedImage(size_t w, size_t h, size_t pitch_bytes)
|
||||
: Image<T>(
|
||||
Allocator().allocate( (h*pitch_bytes) / sizeof(T) + 1),
|
||||
w, h, pitch_bytes
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
// Not copy constructable
|
||||
inline
|
||||
ManagedImage( const ManagedImage<T>& other ) = delete;
|
||||
|
||||
// Move constructor
|
||||
inline
|
||||
ManagedImage(ManagedImage<T,Allocator>&& img)
|
||||
{
|
||||
*this = std::move(img);
|
||||
}
|
||||
|
||||
// Move asignment
|
||||
inline
|
||||
void operator=(ManagedImage<T,Allocator>&& img)
|
||||
{
|
||||
Deallocate();
|
||||
Image<T>::pitch = img.pitch;
|
||||
Image<T>::ptr = img.ptr;
|
||||
Image<T>::w = img.w;
|
||||
Image<T>::h = img.h;
|
||||
img.ptr = nullptr;
|
||||
}
|
||||
|
||||
// Explicit copy constructor
|
||||
template<typename TOther>
|
||||
ManagedImage( const CopyObject<TOther>& other )
|
||||
{
|
||||
CopyFrom(other.obj);
|
||||
}
|
||||
|
||||
// Explicit copy assignment
|
||||
template<typename TOther>
|
||||
void operator=(const CopyObject<TOther>& other)
|
||||
{
|
||||
CopyFrom(other.obj);
|
||||
}
|
||||
|
||||
inline
|
||||
void Swap(ManagedImage<T>& img)
|
||||
{
|
||||
std::swap(img.pitch, Image<T>::pitch);
|
||||
std::swap(img.ptr, Image<T>::ptr);
|
||||
std::swap(img.w, Image<T>::w);
|
||||
std::swap(img.h, Image<T>::h);
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyFrom(const Image<T>& img)
|
||||
{
|
||||
if(!Image<T>::IsValid() || Image<T>::w != img.w || Image<T>::h != img.h) {
|
||||
Reinitialise(img.w,img.h);
|
||||
}
|
||||
Image<T>::CopyFrom(img);
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h)
|
||||
{
|
||||
if(!Image<T>::ptr || Image<T>::w != w || Image<T>::h != h) {
|
||||
*this = ManagedImage<T,Allocator>(w,h);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h, size_t pitch)
|
||||
{
|
||||
if(!Image<T>::ptr || Image<T>::w != w || Image<T>::h != h || Image<T>::pitch != pitch) {
|
||||
*this = ManagedImage<T,Allocator>(w,h,pitch);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Deallocate()
|
||||
{
|
||||
if (Image<T>::ptr) {
|
||||
Allocator().deallocate(Image<T>::ptr, (Image<T>::h * Image<T>::pitch) / sizeof(T) );
|
||||
Image<T>::ptr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Move asignment
|
||||
template<typename TOther, typename AllocOther> inline
|
||||
void OwnAndReinterpret(ManagedImage<TOther,AllocOther>&& img)
|
||||
{
|
||||
Deallocate();
|
||||
Image<T>::pitch = img.pitch;
|
||||
Image<T>::ptr = (T*)img.ptr;
|
||||
Image<T>::w = img.w;
|
||||
Image<T>::h = img.h;
|
||||
img.ptr = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
110
Thirdparty/Pangolin/include/pangolin/image/memcpy.h
vendored
Normal file
110
Thirdparty/Pangolin/include/pangolin/image/memcpy.h
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/* 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 <cstring>
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
# include <cuda_runtime.h>
|
||||
#endif
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
template<typename T>
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool IsDevicePtr(T* ptr)
|
||||
{
|
||||
#ifdef HAVE_CUDA
|
||||
cudaPointerAttributes attributes;
|
||||
cudaError_t res = cudaPointerGetAttributes(&attributes,ptr);
|
||||
|
||||
//Flushing the error flag for future CUDA error checks
|
||||
if(res != cudaSuccess)
|
||||
{
|
||||
cudaGetLastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return attributes.memoryType == cudaMemoryTypeDevice;
|
||||
#else
|
||||
PANGOLIN_UNUSED(ptr);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void MemCopy(void *dst, const void *src, size_t size_bytes)
|
||||
{
|
||||
#ifdef HAVE_CUDA
|
||||
cudaMemcpy(dst,src, size_bytes, cudaMemcpyDefault);
|
||||
#else
|
||||
std::memcpy(dst, src, size_bytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline
|
||||
void PitchedCopy(char* dst, unsigned int dst_pitch_bytes, const char* src, unsigned int src_pitch_bytes, unsigned int width_bytes, unsigned int height)
|
||||
{
|
||||
#ifdef HAVE_CUDA
|
||||
cudaMemcpy2D(dst, dst_pitch_bytes, src, src_pitch_bytes, width_bytes, height, cudaMemcpyDefault);
|
||||
#else
|
||||
if(dst_pitch_bytes == width_bytes && src_pitch_bytes == width_bytes ) {
|
||||
std::memcpy(dst, src, height * width_bytes);
|
||||
}else{
|
||||
for(unsigned int row=0; row < height; ++row) {
|
||||
std::memcpy(dst, src, width_bytes);
|
||||
dst += dst_pitch_bytes;
|
||||
src += src_pitch_bytes;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Memset(char* ptr, unsigned char v, size_t size_bytes)
|
||||
{
|
||||
#ifdef __CUDA_ARCH__
|
||||
// Called in kernel
|
||||
char* end = ptr + size_bytes;
|
||||
for(char* p=ptr; p != end; ++p) *p = v;
|
||||
#else
|
||||
# ifdef HAVE_CUDA
|
||||
if(IsDevicePtr(ptr))
|
||||
{
|
||||
cudaMemset(ptr, v, size_bytes);
|
||||
}else
|
||||
# endif // HAVE_CUDA
|
||||
{
|
||||
std::memset(ptr, v, size_bytes);
|
||||
}
|
||||
#endif // __CUDA_ARCH__
|
||||
}
|
||||
|
||||
}
|
||||
66
Thirdparty/Pangolin/include/pangolin/image/pixel_format.h
vendored
Normal file
66
Thirdparty/Pangolin/include/pangolin/image/pixel_format.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011-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 <pangolin/platform.h>
|
||||
#include <string>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
struct PANGOLIN_EXPORT PixelFormat
|
||||
{
|
||||
// Previously, VideoInterface::PixFormat returned a string.
|
||||
// For compatibility, make this string convertable
|
||||
inline operator std::string() const { return format; }
|
||||
|
||||
std::string format;
|
||||
unsigned int channels;
|
||||
unsigned int channel_bits[4]; //Of the data type
|
||||
unsigned int bpp; //Of the data type
|
||||
unsigned int channel_bit_depth; //Of the data
|
||||
bool planar;
|
||||
};
|
||||
|
||||
|
||||
//! Return Pixel Format properties given string specification in
|
||||
//! FFMPEG notation.
|
||||
PANGOLIN_EXPORT
|
||||
PixelFormat PixelFormatFromString(const std::string& format);
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// Deprecated aliases for above
|
||||
|
||||
PANGOLIN_DEPRECATED
|
||||
typedef PixelFormat VideoPixelFormat;
|
||||
PANGOLIN_DEPRECATED
|
||||
inline PixelFormat VideoFormatFromString(const std::string& format) {
|
||||
return PixelFormatFromString(format);
|
||||
}
|
||||
|
||||
}
|
||||
91
Thirdparty/Pangolin/include/pangolin/image/typed_image.h
vendored
Normal file
91
Thirdparty/Pangolin/include/pangolin/image/typed_image.h
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/* 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 <pangolin/image/managed_image.h>
|
||||
#include <pangolin/image/pixel_format.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
struct TypedImage : public ManagedImage<unsigned char>
|
||||
{
|
||||
typedef ManagedImage<unsigned char> Base;
|
||||
|
||||
inline TypedImage()
|
||||
: Base()
|
||||
{
|
||||
}
|
||||
|
||||
inline TypedImage(size_t w, size_t h, const PixelFormat& fmt)
|
||||
: Base(w,h,w*fmt.bpp/8), fmt(fmt)
|
||||
{
|
||||
}
|
||||
|
||||
inline TypedImage(size_t w, size_t h, const PixelFormat& fmt, size_t pitch )
|
||||
: Base(w,h, pitch), fmt(fmt)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h, const PixelFormat& fmt)
|
||||
{
|
||||
Base::Reinitialise(w, h, w*fmt.bpp/8);
|
||||
this->fmt = fmt;
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h, const PixelFormat& fmt, size_t pitch)
|
||||
{
|
||||
Base::Reinitialise(w, h, pitch);
|
||||
this->fmt = fmt;
|
||||
}
|
||||
|
||||
// Not copy constructable
|
||||
inline
|
||||
TypedImage( const TypedImage& other ) = delete;
|
||||
|
||||
// Move constructor
|
||||
inline
|
||||
TypedImage(TypedImage&& img)
|
||||
{
|
||||
*this = std::move(img);
|
||||
}
|
||||
|
||||
// Move asignment
|
||||
inline
|
||||
void operator=(TypedImage&& img)
|
||||
{
|
||||
fmt = img.fmt;
|
||||
Base::operator =( std::move(img));
|
||||
}
|
||||
|
||||
|
||||
PixelFormat fmt;
|
||||
};
|
||||
|
||||
}
|
||||
36
Thirdparty/Pangolin/include/pangolin/ios/PangolinAppDelegate.h
vendored
Normal file
36
Thirdparty/Pangolin/include/pangolin/ios/PangolinAppDelegate.h
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "PangolinUIView.h"
|
||||
|
||||
@interface PangolinAppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
22
Thirdparty/Pangolin/include/pangolin/ios/PangolinUIView.h
vendored
Normal file
22
Thirdparty/Pangolin/include/pangolin/ios/PangolinUIView.h
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// GlTestViewController.h
|
||||
// gltest
|
||||
//
|
||||
// Created by Steven Lovegrove on 30/01/2014.
|
||||
// Copyright (c) 2014 Steven Lovegrove. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
|
||||
@interface PangolinUIView : UIView {
|
||||
CAEAGLLayer* _eaglLayer;
|
||||
EAGLContext* _context;
|
||||
|
||||
GLuint _colorRenderBuffer;
|
||||
GLuint _depthRenderBuffer;
|
||||
}
|
||||
|
||||
@end
|
||||
70
Thirdparty/Pangolin/include/pangolin/log/packet.h
vendored
Normal file
70
Thirdparty/Pangolin/include/pangolin/log/packet.h
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* 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 <mutex>
|
||||
|
||||
#include <pangolin/log/packetstream.h>
|
||||
#include <pangolin/log/packetstream_source.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
// Encapsulate serialized reading of Packet from stream.
|
||||
struct Packet
|
||||
{
|
||||
Packet(PacketStream& s, std::unique_lock<std::recursive_mutex>&& mutex, std::vector<PacketStreamSource>& srcs);
|
||||
Packet(const Packet&) = delete;
|
||||
Packet(Packet&& o);
|
||||
~Packet();
|
||||
|
||||
size_t BytesRead() const;
|
||||
int BytesRemaining() const;
|
||||
|
||||
PacketStream& Stream()
|
||||
{
|
||||
return _stream;
|
||||
}
|
||||
|
||||
PacketStreamSourceId src;
|
||||
int64_t time;
|
||||
size_t size;
|
||||
size_t sequence_num;
|
||||
picojson::value meta;
|
||||
std::streampos frame_streampos;
|
||||
|
||||
private:
|
||||
void ParsePacketHeader(PacketStream& s, std::vector<PacketStreamSource>& srcs);
|
||||
void ReadRemaining();
|
||||
|
||||
PacketStream& _stream;
|
||||
|
||||
std::unique_lock<std::recursive_mutex> lock;
|
||||
|
||||
std::streampos data_streampos;
|
||||
size_t _data_len;
|
||||
};
|
||||
|
||||
}
|
||||
111
Thirdparty/Pangolin/include/pangolin/log/packetstream.h
vendored
Normal file
111
Thirdparty/Pangolin/include/pangolin/log/packetstream.h
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* 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 <fstream>
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
#include <pangolin/log/packetstream_tags.h>
|
||||
#include <pangolin/utils/file_utils.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
class PacketStream: public std::ifstream
|
||||
{
|
||||
public:
|
||||
PacketStream()
|
||||
: _is_pipe(false)
|
||||
{
|
||||
cclear();
|
||||
}
|
||||
|
||||
PacketStream(const std::string& filename)
|
||||
: Base(filename.c_str(), std::ios::in | std::ios::binary),
|
||||
_is_pipe(IsPipe(filename))
|
||||
{
|
||||
cclear();
|
||||
}
|
||||
|
||||
bool seekable() const
|
||||
{
|
||||
return is_open() && !_is_pipe;
|
||||
}
|
||||
|
||||
void open(const std::string& filename)
|
||||
{
|
||||
close();
|
||||
_is_pipe = IsPipe(filename);
|
||||
Base::open(filename.c_str(), std::ios::in | std::ios::binary);
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
cclear();
|
||||
if (Base::is_open()) Base::close();
|
||||
}
|
||||
|
||||
void seekg(std::streampos target);
|
||||
|
||||
void seekg(std::streamoff off, std::ios_base::seekdir way);
|
||||
|
||||
std::streampos tellg();
|
||||
|
||||
size_t read(char* target, size_t len);
|
||||
|
||||
char get();
|
||||
|
||||
size_t skip(size_t len);
|
||||
|
||||
size_t readUINT();
|
||||
|
||||
int64_t readTimestamp();
|
||||
|
||||
pangoTagType peekTag();
|
||||
|
||||
pangoTagType readTag();
|
||||
|
||||
pangoTagType readTag(pangoTagType);
|
||||
|
||||
pangoTagType syncToTag();
|
||||
|
||||
private:
|
||||
using Base = std::ifstream;
|
||||
|
||||
bool _is_pipe;
|
||||
pangoTagType _tag;
|
||||
|
||||
// Amount of frame data left to read. Tracks our position within a data block.
|
||||
|
||||
|
||||
void cclear() {
|
||||
_tag = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
120
Thirdparty/Pangolin/include/pangolin/log/packetstream_reader.h
vendored
Normal file
120
Thirdparty/Pangolin/include/pangolin/log/packetstream_reader.h
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* 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 <fstream>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <pangolin/log/packet.h>
|
||||
|
||||
#include <pangolin/log/sync_time.h>
|
||||
#include <pangolin/utils/file_utils.h>
|
||||
#include <pangolin/utils/timer.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
class PANGOLIN_EXPORT PacketStreamReader
|
||||
{
|
||||
public:
|
||||
PacketStreamReader();
|
||||
|
||||
PacketStreamReader(const std::string& filename);
|
||||
|
||||
~PacketStreamReader();
|
||||
|
||||
void Open(const std::string& filename);
|
||||
|
||||
void Close();
|
||||
|
||||
const std::vector<PacketStreamSource>&
|
||||
Sources() const
|
||||
{
|
||||
return _sources;
|
||||
}
|
||||
|
||||
// Grab Next available frame packetstream
|
||||
Packet NextFrame();
|
||||
|
||||
// Grab Next available frame in packetstream from src, discarding other frames.
|
||||
Packet NextFrame(PacketStreamSourceId src);
|
||||
|
||||
bool Good() const
|
||||
{
|
||||
return _stream.good();
|
||||
}
|
||||
|
||||
// Jumps to a particular packet.
|
||||
size_t Seek(PacketStreamSourceId src, size_t framenum);
|
||||
|
||||
// Jumps to the first packet with time >= time
|
||||
size_t Seek(PacketStreamSourceId src, SyncTime::TimePoint time);
|
||||
|
||||
void FixFileIndex();
|
||||
|
||||
private:
|
||||
bool GoodToRead();
|
||||
|
||||
bool SetupIndex();
|
||||
|
||||
void ParseHeader();
|
||||
|
||||
void ParseNewSource();
|
||||
|
||||
bool ParseIndex();
|
||||
|
||||
void RebuildIndex();
|
||||
|
||||
void AppendIndex();
|
||||
|
||||
std::streampos ParseFooter();
|
||||
|
||||
void SkipSync();
|
||||
|
||||
void ReSync() {
|
||||
_stream.syncToTag();
|
||||
}
|
||||
|
||||
std::string _filename;
|
||||
std::vector<PacketStreamSource> _sources;
|
||||
SyncTime::TimePoint packet_stream_start;
|
||||
|
||||
PacketStream _stream;
|
||||
std::recursive_mutex _mutex;
|
||||
|
||||
bool _is_pipe;
|
||||
int _pipe_fd;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user