Skip to content

Commit

Permalink
Update Matlab wrapper for processing_block refactor.
Browse files Browse the repository at this point in the history
Note: Things that derive from processing_block but not filter are currently unsupported
  • Loading branch information
Lior Ramati committed Nov 28, 2018
1 parent bffc18e commit 7d57753
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions wrappers/matlab/align.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
% Wraps librealsense2 align class
classdef align < realsense.processing_block
classdef align < realsense.filter
methods
% Constructor
function this = align(align_to)
narginchk(1, 1);
validateattributes(align_to, {'realsense.stream', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.stream.count});
this.objectHandle = realsense.librealsense_mex('rs2::align', 'new', int64(align_to));
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/colorizer.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 colorizer class
classdef colorizer < realsense.processing_block
classdef colorizer < realsense.filter
methods
% Constructor
function this = colorizer(color_scheme)
Expand All @@ -9,7 +9,7 @@
validateattributes(color_scheme, {'numeric'}, {'scalar', 'nonnegative', 'real'});
out = realsense.librealsense_mex('rs2::colorizer', 'new', double(color_scheme));
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/decimation_filter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 decimation_filter class
classdef decimation_filter < realsense.processing_block
classdef decimation_filter < realsense.filter
methods
% Constructor
function this = decimation_filter(magnitude)
Expand All @@ -9,7 +9,7 @@
validateattributes(magnitude, {'numeric'}, {'scalar', 'nonnegative', 'real'});
out = realsense.librealsense_mex('rs2::decimation_filter', 'new', double(magnitude));
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/disparity_transform.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 disparity_transform class
classdef disparity_transform < realsense.processing_block
classdef disparity_transform < realsense.filter
methods
% Constructor
function this = disparity_transform(transform_to_disparity)
Expand All @@ -9,7 +9,7 @@
validateattributes(transform_to_disparity, {'logical', 'numeric'}, {'scalar', 'real'});
out = realsense.librealsense_mex('rs2::disparity_transform', 'new', logical(transform_to_disparity));
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
% Wraps librealsense2 processing_block class
classdef processing_block < realsense.options
% Wraps librealsense2 filter class
classdef filter < realsense.options
methods
% Constructor
function this = processing_block(handle)
function this = filter(handle)
this = [email protected](handle);
end

Expand All @@ -12,7 +12,7 @@
function out_frame = process(this, frame)
narginchk(2, 2)
validateattributes(frame, {'realsense.frame'}, {'scalar'}, '', 'frame', 2);
out = realsense.librealsense_mex('rs2::processing_block', 'process', this.objectHandle, frame.objectHandle);
out = realsense.librealsense_mex('rs2::filter', 'process', this.objectHandle, frame.objectHandle);
out_frame = realsense.frame(out);
end
end
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/hole_filling_filter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 hole_filling_filter class
classdef hole_filling_filter < realsense.processing_block
classdef hole_filling_filter < realsense.filter
methods
% Constructor
function this = hole_filling_filter(mode)
Expand All @@ -9,7 +9,7 @@
validateattributes(mode, {'numeric'}, {'scalar', 'real', 'integer'});
out = realsense.librealsense_mex('rs2::hole_filling_filter', 'new', int64(mode));
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
14 changes: 10 additions & 4 deletions wrappers/matlab/librealsense_mex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,16 +919,22 @@ void make_factory(){
});
factory->record(frame_queue_factory);
}
// TODO: need to understand how to call matlab functions from within C++ before async things can be implemented.
// processing_block API is completely async.
// {
// ClassFactory processing_block_factory("rs2::processing_block");
//
// factory->record(processing_block_factory);
// }
{
ClassFactory processing_block_factory("rs2::processing_block");
processing_block_factory.record("process", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
ClassFactory filter_factory("rs2::filter");
filter_factory.record("process", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
auto thiz = MatlabParamParser::parse<rs2::filter>(inv[0]);
auto frame = MatlabParamParser::parse<rs2::frame>(inv[1]);
outv[0] = MatlabParamParser::wrap(thiz.process(frame));
});
// TODO: expose more functions?
factory->record(processing_block_factory);
factory->record(filter_factory);
}
{
ClassFactory pointcloud_factory("rs2::pointcloud");
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/pointcloud.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 pointcloud class
classdef pointcloud < realsense.processing_block
classdef pointcloud < realsense.filter
methods
% Constructor
function this = pointcloud(stream, index)
Expand All @@ -14,7 +14,7 @@
validateattributes(index, {'numeric'}, {'scalar', 'nonnegative', 'real', 'integer'});
out = realsense.librealsense_mex('rs2::pointcloud', 'new', int64(stream), int64(index));
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
3 changes: 3 additions & 0 deletions wrappers/matlab/rs2_type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ template<typename T> struct MatlabParamParser::type_traits<T, typename std::enab

// rs_sensor.hpp
template<> struct MatlabParamParser::type_traits<rs2::options> {
// since it is impossible to create an rs2::options object (you must cast from a deriving type)
// The carrier's job is to help jump bridge that gap. Each type that derives directly from rs2::options
// must be added to the carrier's logic
struct carrier {
void * ptr;
enum class types { rs2_sensor, rs2_processing_block } type;
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/spatial_filter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 spatial_filter class
classdef spatial_filter < realsense.processing_block
classdef spatial_filter < realsense.filter
methods
% Constructor
function this = spatial_filter(smooth_alpha, smooth_delta, magnitude, hole_fill)
Expand All @@ -14,7 +14,7 @@
else
% TODO: Error out on bad arg count
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down
4 changes: 2 additions & 2 deletions wrappers/matlab/temporal_filter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 temporal_filter class
classdef temporal_filter < realsense.processing_block
classdef temporal_filter < realsense.filter
methods
% Constructor
function this = temporal_filter(smooth_alpha, smooth_delta, persistence_control)
Expand All @@ -13,7 +13,7 @@
else
% TODO: Error out on bad arg count
end
this = this@realsense.processing_block(out);
this = this@realsense.filter(out);
end

% Destructor (uses base class destructor)
Expand Down

0 comments on commit 7d57753

Please sign in to comment.