-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add Intel LibRealSense grabber and viewer #1633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d20fa4e
2911593
82d9475
dd63841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| ############################################################################### | ||
| # Find librealsense | ||
| # | ||
| # find_package(librealsense) | ||
| # | ||
| # Variables defined by this module: | ||
| # | ||
| # LIBREALSENSE_FOUND True if librealsense was found | ||
| # LIBREALSENSE_INCLUDE_DIRS The location(s) of librealsense headers | ||
| # LIBREALSENSE_LIBRARIES Libraries needed to use librealsense | ||
|
|
||
| if (LIBREALSENSE_LIBRARIES AND LIBREALSENSE_INCLUDE_DIRS) | ||
| # in cache already | ||
| set(LIBREALSENSE_FOUND TRUE) | ||
| else (LIBREALSENSE_LIBRARIES AND LIBREALSENSE_INCLUDE_DIRS) | ||
| find_path(LIBREALSENSE_DIR include/librealsense | ||
| PATHS $ENV{LIBREALSENSE_DIR} NO_DEFAULT_PATH) | ||
| if (WIN32) | ||
| set(LIBREALSENSE_RELEASE_NAME realsense.lib) | ||
| set(LIBREALSENSE_DEBUG_NAME realsense-d.lib) | ||
| set(LIBREALSENSE_SUFFIX Win32) | ||
| if (CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
| set(LIBREALSENSE_SUFFIX x64) | ||
| endif () | ||
| else (WIN32) | ||
| set(LIBREALSENSE_RELEASE_NAME librealsense.so) | ||
| set(LIBREALSENSE_DEBUG_NAME librealsense.a) | ||
| endif (WIN32) | ||
|
|
||
| find_path(LIBREALSENSE_INCLUDE_DIR | ||
| NAMES librealsense | ||
| PATHS /usr/local/include /usr/include /opt/local/include /sw/include ${LIBREALSENSE_DIR}/include NO_DEFAULT_PATH) | ||
|
|
||
| find_library(LIBREALSENSE_LIBRARY | ||
| NAMES ${LIBREALSENSE_RELEASE_NAME} | ||
| PATHS ${LIBREALSENSE_DIR}/bin/ /usr/local/lib /usr/lib /opt/local/lib /sw/lib ${LIBREALSENSE_DIR}/lib/ NO_DEFAULT_PATH | ||
| PATH_SUFFIXES ${LIBREALSENSE_SUFFIX}) | ||
| find_library(LIBREALSENSE_LIBRARY_DEBUG | ||
| NAMES ${LIBREALSENSE_DEBUG_NAME} | ||
| PATHS ${LIBREALSENSE_DIR}/bin/ ${LIBREALSENSE_DIR}/bin/debug/ ${LIBREALSENSE_DIR}/lib/ NO_DEFAULT_PATH | ||
| PATH_SUFFIXES ${LIBREALSENSE_SUFFIX}) | ||
| if (NOT LIBREALSENSE_LIBRARY_DEBUG) | ||
| set(LIBREALSENSE_LIBRARY_DEBUG ${LIBREALSENSE_LIBRARY}) | ||
| endif () | ||
|
|
||
| set(LIBREALSENSE_LIBRARIES optimized ${LIBREALSENSE_LIBRARY} debug ${LIBREALSENSE_LIBRARY_DEBUG}) | ||
| set(LIBREALSENSE_INCLUDE_DIRS ${LIBREALSENSE_INCLUDE_DIR}) | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(LIBREALSENSE LIBREALSENSE_LIBRARIES LIBREALSENSE_INCLUDE_DIRS) | ||
|
|
||
| endif (LIBREALSENSE_LIBRARIES AND LIBREALSENSE_INCLUDE_DIRS) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lack of new line at the end of the file. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| /* | ||
| * Software License Agreement (BSD License) | ||
| * | ||
| * Point Cloud Library (PCL) - www.pointclouds.org | ||
| * Copyright (c) 2015-, Open Perception, Inc. | ||
| * Copyright (c) 2016, Intel Corporation | ||
| * | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions | ||
| * are met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following | ||
| * disclaimer in the documentation and/or other materials provided | ||
| * with the distribution. | ||
| * * Neither the name of the copyright holder(s) nor the names of its | ||
| * contributors may be used to endorse or promote products derived | ||
| * from this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PCL_IO_REAL_SENSE_DEVICE_MANAGER_H | ||
| #define PCL_IO_REAL_SENSE_DEVICE_MANAGER_H | ||
|
|
||
| #include <boost/utility.hpp> | ||
| #include <boost/shared_ptr.hpp> | ||
| #include <boost/weak_ptr.hpp> | ||
| #include <boost/thread/mutex.hpp> | ||
| #include <vector> | ||
|
|
||
| #include <pcl/pcl_exports.h> | ||
|
|
||
| #include <librealsense/rs.hpp> | ||
|
|
||
| namespace pcl | ||
| { | ||
|
|
||
| class RealSenseGrabber; | ||
|
|
||
| namespace io | ||
| { | ||
|
|
||
| namespace real_sense | ||
| { | ||
|
|
||
| class RealSenseDevice; | ||
|
|
||
| class PCL_EXPORTS RealSenseDeviceManager : boost::noncopyable | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The moment you define your custom destructor the class is stripped of default copy operators, so this is not so usefull anymore. But then again, your destructor is not doing anything so it should just be deleted. |
||
| { | ||
|
|
||
| public: | ||
|
|
||
| typedef boost::shared_ptr<RealSenseDeviceManager> Ptr; | ||
|
|
||
| static Ptr& | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be a const reference? Your class is implemented as a lazy initialized singleton, so I assume you don't want to allow it to be reset and a new manager allocated later on. |
||
| getInstance () | ||
| { | ||
| static Ptr instance; | ||
| if (!instance) | ||
| { | ||
| boost::mutex::scoped_lock lock (mutex_); | ||
| if (!instance) | ||
| instance.reset (new RealSenseDeviceManager); | ||
| } | ||
| return (instance); | ||
| } | ||
|
|
||
| inline size_t | ||
| getNumDevices () | ||
| { | ||
| return (device_list_.size ()); | ||
| } | ||
|
|
||
| boost::shared_ptr<RealSenseDevice> | ||
| captureDevice (); | ||
|
|
||
| boost::shared_ptr<RealSenseDevice> | ||
| captureDevice (size_t index); | ||
|
|
||
| boost::shared_ptr<RealSenseDevice> | ||
| captureDevice (const std::string& sn); | ||
|
|
||
| ~RealSenseDeviceManager (); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this and subsequent definition. |
||
|
|
||
| private: | ||
|
|
||
| struct DeviceInfo | ||
| { | ||
| int index; | ||
| std::string serial; | ||
| bool isCaptured; | ||
| }; | ||
|
|
||
| /** If the device is already captured returns a pointer. */ | ||
| boost::shared_ptr<RealSenseDevice> | ||
| capture (DeviceInfo& device_info); | ||
|
|
||
| RealSenseDeviceManager (); | ||
|
|
||
| rs::context context_; | ||
|
|
||
| /** This function discovers devices that are capable of streaming | ||
| * depth data. */ | ||
| void | ||
| populateDeviceList (); | ||
|
|
||
| std::vector<DeviceInfo> device_list_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line will occure compile error in MSVC because vector header has not been included. (real_sense_device_manager.h #L123)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think an error like that would go by unnoticed in Travis. Did you get a compile error while trying to compile this yourself?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was confirm that the error occur when trying to compile this on MSVC. Possibly, I think "WITH_LIBREALSENSE" option is disabled (or librealsense is not found) when checked by Travis. In that case, this code is not compiled in test.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tried to compile librealsense backend on MSVC, I will try it and fix the problem.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have compiled librealsense backend on MSVC and fixed the problems, please check it out. @UnaNancyOwen :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was confirm that it can successfully compile. |
||
|
|
||
| static boost::mutex mutex_; | ||
| }; | ||
|
|
||
| class PCL_EXPORTS RealSenseDevice : boost::noncopyable | ||
| { | ||
| public: | ||
|
|
||
| typedef boost::shared_ptr<RealSenseDevice> Ptr; | ||
|
|
||
| inline const std::string& | ||
| getSerialNumber () { return (device_id_); } | ||
|
|
||
| inline rs::device* | ||
| getDevice () { return (device_); } | ||
|
|
||
| /** Reset the state of given device by releasing and capturing again. */ | ||
| static void | ||
| reset (RealSenseDevice::Ptr& device) | ||
| { | ||
| std::string id = device->getSerialNumber (); | ||
| device.reset (); | ||
| device = RealSenseDeviceManager::getInstance ()->captureDevice (id); | ||
| } | ||
|
|
||
| private: | ||
|
|
||
| friend class RealSenseDeviceManager; | ||
|
|
||
| std::string device_id_; | ||
| rs::device* device_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this very much. You're passing a pointer to the user which is managed by the realsense. If the user wants he can delete the pointer. Instead I propose to hold a reference to the rs::device. The user can do whatever he wants with the reference without being able to delete the resource. |
||
|
|
||
| RealSenseDevice (const std::string& id) : device_id_ (id) { }; | ||
|
|
||
| }; | ||
| } // namespace real_sense | ||
| } // namespace io | ||
| } // namespace pcl | ||
|
|
||
| #endif /* PCL_IO_REAL_SENSE_DEVICE_MANAGER_H */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New line at the end of the file. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make much sense, in contrast with the windows branch. The first one is the shared lib and the second the static one. But both can be either release or debug.