Skip to content

Commit

Permalink
Merge pull request #1038 from lramati/matlab
Browse files Browse the repository at this point in the history
Matlab Wrapper Inital PR
  • Loading branch information
dorodnic authored Aug 15, 2018
2 parents f78e562 + 5e3048b commit 72c1521
Show file tree
Hide file tree
Showing 70 changed files with 4,252 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ option(BUILD_EXAMPLES "Build realsense examples and tools." ON)
option(ENFORCE_METADATA "Require WinSDK with Metadata support during compilation. Windows OS Only" OFF)
option(BUILD_PYTHON_BINDINGS "Build Python bindings" OFF)
option(BUILD_CSHARP_BINDINGS "Build C# bindings" OFF)
#option(BUILD_MATLAB_BINDINGS "Build Matlab bindings" OFF)
option(BUILD_UNITY_BINDINGS "Copy the unity project to the build folder with the required dependencies" OFF)
option(BUILD_CV_EXAMPLES "Build OpenCV examples" OFF)
option(BUILD_PCL_EXAMPLES "Build PCL examples" OFF)
Expand Down Expand Up @@ -882,6 +883,10 @@ if (BUILD_WITH_CUDA)
add_definitions(-DRS2_USE_CUDA)
endif()

if (BUILD_MATLAB_BINDINGS)
add_subdirectory(wrappers/matlab)
endif()


# Check for unreferenced files
FILE(GLOB_RECURSE AllSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
2 changes: 1 addition & 1 deletion include/librealsense2/h/rs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void rs2_delete_device_hub(const rs2_device_hub* hub);
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored.
* \return device object
*/
rs2_device* rs2_device_hub_wait_for_device(rs2_context* ctx, const rs2_device_hub* hub, rs2_error** error);
rs2_device* rs2_device_hub_wait_for_device(const rs2_device_hub* hub, rs2_error** error);

/**
* Checks if device is still connected
Expand Down
17 changes: 10 additions & 7 deletions include/librealsense2/hpp/rs_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ namespace rs2
rs2::error::handle(e);
}

context(std::shared_ptr<rs2_context> ctx)
: _context(ctx)
{}
explicit operator std::shared_ptr<rs2_context>() { return _context; };
protected:
friend class rs2::pipeline;
friend class rs2::device_hub;

context(std::shared_ptr<rs2_context> ctx)
: _context(ctx)
{}

std::shared_ptr<rs2_context> _context;
};

Expand All @@ -224,11 +226,10 @@ namespace rs2
{
public:
explicit device_hub(context ctx)
: _ctx(std::move(ctx))
{
rs2_error* e = nullptr;
_device_hub = std::shared_ptr<rs2_device_hub>(
rs2_create_device_hub(_ctx._context.get(), &e),
rs2_create_device_hub(ctx._context.get(), &e),
rs2_delete_device_hub);
error::handle(e);
}
Expand All @@ -241,7 +242,7 @@ namespace rs2
{
rs2_error* e = nullptr;
std::shared_ptr<rs2_device> dev(
rs2_device_hub_wait_for_device(_ctx._context.get(), _device_hub.get(), &e),
rs2_device_hub_wait_for_device(_device_hub.get(), &e),
rs2_delete_device);

error::handle(e);
Expand All @@ -262,8 +263,10 @@ namespace rs2
return res > 0 ? true : false;

}

explicit operator std::shared_ptr<rs2_device_hub>() { return _device_hub; }
explicit device_hub(std::shared_ptr<rs2_device_hub> hub) : _device_hub(std::move(hub)) {}
private:
context _ctx;
std::shared_ptr<rs2_device_hub> _device_hub;
};

Expand Down
9 changes: 6 additions & 3 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ namespace rs2
virtual ~device()
{
}

explicit operator std::shared_ptr<rs2_device>() { return _dev; };
explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev) {}
protected:
friend class rs2::context;
friend class rs2::device_list;
friend class rs2::pipeline_profile;
friend class rs2::device_hub;

std::shared_ptr<rs2_device> _dev;
explicit device(std::shared_ptr<rs2_device> dev) : _dev(dev)
{
}

};

class debug_protocol : public device
Expand Down Expand Up @@ -283,6 +284,8 @@ namespace rs2
return _list.get();
}

operator std::shared_ptr<rs2_device_list>() { return _list; };

private:
std::shared_ptr<rs2_device_list> _list;
};
Expand Down
20 changes: 10 additions & 10 deletions include/librealsense2/hpp/rs_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ namespace rs2
Operator implement, return the internal stream profile instance.
* \return rs2_stream_profile* - internal instance to communicate with real implementation.
*/
operator const rs2_stream_profile*()
{
return _profile;
}
/**
* Get the extrinsic transformation between two profiles (representing physical sensors)
* \param[in] stream_profile to - the stream profile (another sensor) to be based to return the extrinsic
Expand All @@ -169,12 +165,7 @@ namespace rs2
error::handle(e);
}

protected:
friend class rs2::sensor;
friend class rs2::frame;
friend class rs2::pipeline_profile;
friend class software_sensor;

bool is_cloned() { return bool(_clone); }
explicit stream_profile(const rs2_stream_profile* profile) : _profile(profile)
{
rs2_error* e = nullptr;
Expand All @@ -185,6 +176,14 @@ namespace rs2
error::handle(e);

}
operator const rs2_stream_profile*() { return _profile; }
explicit operator std::shared_ptr<rs2_stream_profile>() { return _clone; }

protected:
friend class rs2::sensor;
friend class rs2::frame;
friend class rs2::pipeline_profile;
friend class software_sensor;

const rs2_stream_profile* _profile;
std::shared_ptr<rs2_stream_profile> _clone;
Expand Down Expand Up @@ -493,6 +492,7 @@ namespace rs2
* \return rs2_frame - internal frame handle.
*/
rs2_frame* get() const { return frame_ref; }
explicit operator rs2_frame*() { return frame_ref; }

protected:
/**
Expand Down
20 changes: 10 additions & 10 deletions include/librealsense2/hpp/rs_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ namespace rs2
return _pipeline_profile != nullptr;
}

private:
explicit operator std::shared_ptr<rs2_pipeline_profile>() { return _pipeline_profile; }
pipeline_profile(std::shared_ptr<rs2_pipeline_profile> profile) :
_pipeline_profile(profile)
{

}
_pipeline_profile(profile){}
private:

std::shared_ptr<rs2_pipeline_profile> _pipeline_profile;
friend class config;
friend class pipeline;
Expand Down Expand Up @@ -316,12 +315,14 @@ namespace rs2
{
return _config;
}
private:
config(std::shared_ptr<rs2_config> config) : _config(config)
explicit operator std::shared_ptr<rs2_config>() const
{
return _config;
}
std::shared_ptr<rs2_config> _config;

config(std::shared_ptr<rs2_config> config) : _config(config) {}
private:
std::shared_ptr<rs2_config> _config;
};

/**
Expand All @@ -343,7 +344,6 @@ namespace rs2
* \param[in] ctx The context allocated by the application. Using the platform context by default.
*/
pipeline(context ctx = context())
: _ctx(ctx)
{
rs2_error* e = nullptr;
_pipeline = std::shared_ptr<rs2_pipeline>(
Expand Down Expand Up @@ -509,9 +509,9 @@ namespace rs2
{
return _pipeline;
}
explicit pipeline(std::shared_ptr<rs2_pipeline> ptr) : _pipeline(ptr) {}

private:
context _ctx;
std::shared_ptr<rs2_pipeline> _pipeline;
friend class config;
};
Expand Down
17 changes: 12 additions & 5 deletions include/librealsense2/hpp/rs_sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace rs2
{

class notification
{
public:
Expand Down Expand Up @@ -211,6 +212,8 @@ namespace rs2
_options = other._options;
return *this;
}
// if operator= is ok, this should be ok too
options(const options& other) : _options(other._options) {}

virtual ~options() = default;
protected:
Expand All @@ -223,7 +226,7 @@ namespace rs2
return *this;
}

options(const options& other) : _options(other._options) {}


private:
rs2_options* _options;
Expand Down Expand Up @@ -411,6 +414,12 @@ namespace rs2
return extension;
}

explicit sensor(std::shared_ptr<rs2_sensor> dev)
:options((rs2_options*)dev.get()), _sensor(dev)
{
}
explicit operator std::shared_ptr<rs2_sensor>() { return _sensor; }

protected:
friend context;
friend device_list;
Expand All @@ -420,10 +429,7 @@ namespace rs2

std::shared_ptr<rs2_sensor> _sensor;

explicit sensor(std::shared_ptr<rs2_sensor> dev)
:options((rs2_options*)dev.get()), _sensor(dev)
{
}

};

inline bool operator==(const sensor& lhs, const sensor& rhs)
Expand Down Expand Up @@ -495,6 +501,7 @@ namespace rs2
}

operator bool() const { return _sensor.get() != nullptr; }
explicit depth_sensor(std::shared_ptr<rs2_sensor> dev) : depth_sensor(sensor(dev)) {}
};

class depth_stereo_sensor : public depth_sensor
Expand Down
18 changes: 9 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Linux/MacOS | Windows |
-----------------

## Overview
**Intel® RealSense™ SDK 2.0** is a cross-platform library for Intel® RealSense™ depth cameras (D400 series and the SR300).
**Intel® RealSense™ SDK 2.0** is a cross-platform library for Intel® RealSense™ depth cameras (D400 series and the SR300).

> :pushpin: For other Intel® RealSense™ devices (F200, R200, LR200 and ZR300), please refer to the [latest legacy release](https://github.com/IntelRealSense/librealsense/tree/v1.12.1).
Expand Down Expand Up @@ -37,7 +37,7 @@ Information about the Intel® RealSense™ technology at [realsense.intel.com](h
| **[Depth Quality Tool](./tools/depth-quality)** | This application allows you to test the camera’s depth quality, including: standard deviation from plane fit, normalized RMS – the subpixel accuracy, distance accuracy and fill rate. You should be able to easily get and interpret several of the depth quality metrics and record and save the data for offline analysis. |[**Depth.Quality.Tool.exe**](https://github.com/IntelRealSense/librealsense/releases) |
| **[Debug Tools](./tools/)** | Device enumeration, FW logger, etc as can be seen at the tools directory | Included in [**Intel.RealSense.SDK.exe**](https://github.com/IntelRealSense/librealsense/releases)|
| **[Code Samples](./examples)** |These simple examples demonstrate how to easily use the SDK to include code snippets that access the camera into your applications. Check some of the [**C++ examples**](./examples) including capture, pointcloud and more and basic [**C examples**](./examples/C) | Included in [**Intel.RealSense.SDK.exe**](https://github.com/IntelRealSense/librealsense/releases) |
| **[Wrappers](https://github.com/IntelRealSense/librealsense/tree/development/wrappers)** | [Python](./wrappers/python), [C#/.NET](./wrappers/csharp), [Node.js](./wrappers/nodejs) API, as well as integration with the following 3rd-party technologies: [ROS](https://github.com/intel-ros/realsense/releases), [LabVIEW](./wrappers/labview), [OpenCV](./wrappers/opencv), [PCL](./wrappers/pcl), [Unity](./wrappers/unity), and more to come, including Matlab and OpenNI. | |
| **[Wrappers](https://github.com/IntelRealSense/librealsense/tree/development/wrappers)** | [Python](./wrappers/python), [C#/.NET](./wrappers/csharp), [Node.js](./wrappers/nodejs) API, as well as integration with the following 3rd-party technologies: [ROS](https://github.com/intel-ros/realsense/releases), [LabVIEW](./wrappers/labview), [OpenCV](./wrappers/opencv), [PCL](./wrappers/pcl), [Unity](./wrappers/unity), [Matlab](./wrappers/matlab) and more to come, including OpenNI. | |


## Ready to Hack!
Expand All @@ -55,19 +55,19 @@ p.start();
while (true)
{
// Block program until frames arrive
rs2::frameset frames = p.wait_for_frames();
rs2::frameset frames = p.wait_for_frames();

// Try to get a frame of a depth image
rs2::depth_frame depth = frames.get_depth_frame();
rs2::depth_frame depth = frames.get_depth_frame();

// Get the depth frame's dimensions
float width = depth.get_width();
float height = depth.get_height();

// Query the distance from the camera to the object in the center of the image
float dist_to_center = depth.get_distance(width / 2, height / 2);
// Print the distance

// Print the distance
std::cout << "The camera is facing an object " << dist_to_center << " meters away \r";
}
```
Expand All @@ -77,5 +77,5 @@ For more information on the library, please follow our [examples](./examples), a
In order to contribute to Intel RealSense SDK, please follow our [contribution guidelines](CONTRIBUTING.md).

## License
This project is licensed under the [Apache License, Version 2.0](LICENSE).
This project is licensed under the [Apache License, Version 2.0](LICENSE).
Copyright 2017 Intel Corporation
5 changes: 5 additions & 0 deletions src/device_hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,10 @@ namespace librealsense
std::unique_lock<std::mutex> lock(_mutex);
return dev.is_valid();
}

std::shared_ptr<librealsense::context> device_hub::get_context()
{
return _ctx;
}
}

2 changes: 2 additions & 0 deletions src/device_hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace librealsense
*/
bool is_connected(const device_interface& dev);

std::shared_ptr<librealsense::context> get_context();

~device_hub()
{
_ctx->stop();
Expand Down
7 changes: 3 additions & 4 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,13 @@ void rs2_delete_device_hub(const rs2_device_hub* hub) BEGIN_API_CALL
}
NOEXCEPT_RETURN(, hub)

rs2_device* rs2_device_hub_wait_for_device(rs2_context* ctx, const rs2_device_hub* hub, rs2_error** error) BEGIN_API_CALL
rs2_device* rs2_device_hub_wait_for_device(const rs2_device_hub* hub, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(hub);
VALIDATE_NOT_NULL(ctx);
auto dev = hub->hub->wait_for_device();
return new rs2_device{ ctx->ctx, std::make_shared<readonly_device_info>(dev), dev };
return new rs2_device{ hub->hub->get_context(), std::make_shared<readonly_device_info>(dev), dev };
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, hub, ctx)
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, hub)

int rs2_device_hub_is_device_connected(const rs2_device_hub* hub, const rs2_device* device, rs2_error** error) BEGIN_API_CALL
{
Expand Down
5 changes: 4 additions & 1 deletion wrappers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if (BUILD_CV_EXAMPLES)
add_subdirectory(opencv)
endif()

if(BUILD_MATLAB_BINDINGS)
add_subdirectory(matlab)
endif()

if (BUILD_PCL_EXAMPLES)
add_subdirectory(pcl)
endif()
Expand Down Expand Up @@ -63,4 +67,3 @@ if(BUILD_CSHARP_BINDINGS)
add_subdirectory(csharp)
endif()


Loading

0 comments on commit 72c1521

Please sign in to comment.