Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ PCL_ADD_GRABBER_DEPENDENCY("Ensenso" "IDS-Imaging Ensenso camera support")
PCL_ADD_GRABBER_DEPENDENCY("davidSDK" "David Vision Systems SDK support")
PCL_ADD_GRABBER_DEPENDENCY("DSSDK" "DepthSense SDK support")
PCL_ADD_GRABBER_DEPENDENCY("RSSDK" "RealSense SDK support")
PCL_ADD_GRABBER_DEPENDENCY("librealsense" "Intel librealsense support")

# metslib
if (PKG_CONFIG_FOUND)
Expand Down
52 changes: 52 additions & 0 deletions cmake/Modules/Findlibrealsense.cmake
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)
Copy link
Member

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.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of new line at the end of the file.

24 changes: 18 additions & 6 deletions io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ON)
if(WIN32)
PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} OPT_DEPS openni openni2 ensenso davidSDK dssdk rssdk pcap png vtk)
else(WIN32)
PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} OPT_DEPS openni openni2 ensenso davidSDK dssdk pcap png vtk libusb-1.0)
PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} OPT_DEPS openni openni2 ensenso davidSDK dssdk pcap png vtk libusb-1.0 librealsense)
endif(WIN32)

PCL_ADD_DOC("${SUBSYS_NAME}")
Expand Down Expand Up @@ -151,13 +151,23 @@ if(build)
endif()

if(WITH_RSSDK)
set(RSSDK_GRABBER_INCLUDES
set(REALSENSE_GRABBER_INCLUDES
include/pcl/io/real_sense_grabber.h
)
set(RSSDK_GRABBER_SOURCES
set(REALSENSE_GRABBER_SOURCES
src/real_sense_grabber.cpp
src/real_sense/real_sense_device_manager.cpp
src/real_sense/sdk/real_sense_grabber.cpp
src/real_sense/sdk/real_sense_device_manager.cpp
)
elseif(WITH_LIBREALSENSE)
set(REALSENSE_GRABBER_INCLUDES
include/pcl/io/real_sense_grabber.h
)
set(REALSENSE_GRABBER_SOURCES
src/real_sense_grabber.cpp
src/real_sense/librealsense/real_sense_grabber.cpp
src/real_sense/librealsense/real_sense_device_manager.cpp
)
endif()

if(LIBUSB_1_FOUND)
Expand Down Expand Up @@ -226,7 +236,7 @@ if(build)
${ENSENSO_GRABBER_SOURCES}
${DAVIDSDK_GRABBER_SOURCES}
${DSSDK_GRABBER_SOURCES}
${RSSDK_GRABBER_SOURCES}
${REALSENSE_GRABBER_SOURCES}
)
if(PNG_FOUND)
list(APPEND srcs
Expand Down Expand Up @@ -274,7 +284,7 @@ if(build)
${ENSENSO_GRABBER_INCLUDES}
${DAVIDSDK_GRABBER_INCLUDES}
${DSSDK_GRABBER_INCLUDES}
${RSSDK_GRABBER_INCLUDES}
${REALSENSE_GRABBER_INCLUDES}
"include/pcl/${SUBSYS_NAME}/pxc_grabber.h" # contains only depreciation note
)

Expand Down Expand Up @@ -357,6 +367,8 @@ if(build)

if(WITH_RSSDK)
target_link_libraries(${LIB_NAME} ${RSSDK_LIBRARIES})
elseif(WITH_LIBREALSENSE)
target_link_libraries(${LIB_NAME} ${LIBREALSENSE_LIBRARIES})
endif()

if (PCAP_FOUND)
Expand Down
164 changes: 164 additions & 0 deletions io/include/pcl/io/real_sense/librealsense/real_sense_device_manager.h
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
Copy link
Member

Choose a reason for hiding this comment

The 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&
Copy link
Member

Choose a reason for hiding this comment

The 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 ();
Copy link
Member

Choose a reason for hiding this comment

The 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_;
Copy link
Member

@UnaNancyOwen UnaNancyOwen Jul 12, 2016

Choose a reason for hiding this comment

The 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)

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

@UnaNancyOwen UnaNancyOwen Jul 12, 2016

Choose a reason for hiding this comment

The 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.
https://travis-ci.org/PointCloudLibrary/pcl/jobs/144050092#L846
https://travis-ci.org/PointCloudLibrary/pcl/jobs/144050093#L891

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Author

@lebronzhang lebronzhang Jul 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backtrace it if possible.

Exception thrown at 0x00007FFBB6377ACE (intel-ias2.dll) in pcl_real_sense_viewer_debug.exe: 0xC0000005: Access violation reading location 0x0000000000000050.
Does anyone have any ideas?

Copy link
Author

Choose a reason for hiding this comment

The 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 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confirm that it can successfully compile.
I will do operation test within a few days. (I will get the RealSense camera in a few days.)


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_;
Copy link
Member

Choose a reason for hiding this comment

The 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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line at the end of the file.

1 change: 1 addition & 0 deletions io/include/pcl/io/real_sense_grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2015-, Open Perception, Inc.
* Copyright (c) 2016, Intel Corporation
*
* All rights reserved.
*
Expand Down
Loading