Skip to content

Commit

Permalink
Edit matlab wrapper to reflect processing_block api refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Lior Ramati committed Oct 24, 2018
1 parent 2993136 commit 0def593
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 119 deletions.
10 changes: 3 additions & 7 deletions wrappers/matlab/align.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Wraps librealsense2 align class
classdef align < handle
classdef align < librealsense.processing_block
properties (SetAccess = private, Hidden = true)
objectHandle;
end
Expand All @@ -9,14 +9,10 @@
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 = [email protected]_block(out);
end

% Destructor
function delete(this)
if (this.objectHandle ~= 0)
realsense.librealsense_mex('rs2::align', 'delete', this.objectHandle);
end
end
% Destructor (uses base class destructor)

% Functions
function frames = process(this, frame)
Expand Down
13 changes: 9 additions & 4 deletions wrappers/matlab/colorizer.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
% Wraps librealsense2 colorizer class
classdef colorizer < realsense.options
classdef colorizer < realsense.processing_block
methods
% Constructor
function this = colorizer()
out = realsense.librealsense_mex('rs2::colorizer', 'new');
this = [email protected](out);
function this = colorizer(color_scheme)
if (nargin == 0)
out = realsense.librealsense_mex('rs2::colorizer', 'new');
else
validateattributes(color_scheme, {'numeric'}, {'scalar', 'nonnegative', 'real'});
out = realsense.librealsense_mex('rs2::colorizer', 'new', double(color_scheme));
end
this = [email protected]_block(out);
end

% Destructor (uses base class destructor)
Expand Down
13 changes: 9 additions & 4 deletions wrappers/matlab/decimation_filter.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
% Wraps librealsense2 decimation_filter class
classdef decimation_filter < realsense.process_interface
classdef decimation_filter < realsense.processing_block
methods
% Constructor
function this = decimation_filter()
out = realsense.librealsense_mex('rs2::decimation_filter', 'new');
this = [email protected]_interface(out);
function this = decimation_filter(magnitude)
if (nargin == 0)
out = realsense.librealsense_mex('rs2::decimation_filter', 'new');
else
validateattributes(magnitude, {'numeric'}, {'scalar', 'nonnegative', 'real'});
out = realsense.librealsense_mex('rs2::decimation_filter', 'new', double(magnitude));
end
this = [email protected]_block(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.process_interface
classdef disparity_transform < realsense.processing_block
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.process_interface(out);
this = this@realsense.processing_block(out);
end

% Destructor (uses base class destructor)
Expand Down
13 changes: 9 additions & 4 deletions wrappers/matlab/hole_filling_filter.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
% Wraps librealsense2 hole_filling_filter class
classdef hole_filling_filter < realsense.process_interface
classdef hole_filling_filter < realsense.processing_block
methods
% Constructor
function this = hole_filling_filter()
out = realsense.librealsense_mex('rs2::hole_filling_filter', 'new');
this = [email protected]_interface(out);
function this = hole_filling_filter(mode)
if (nargin == 0)
out = realsense.librealsense_mex('rs2::hole_filling_filter', 'new');
else
validateattributes(mode, {'numeric'}, {'scalar', 'real', 'integer'});
out = realsense.librealsense_mex('rs2::hole_filling_filter', 'new', int64(mode));
end
this = [email protected]_block(out);
end

% Destructor (uses base class destructor)
Expand Down
90 changes: 62 additions & 28 deletions wrappers/matlab/librealsense_mex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,32 @@ void make_factory(){
});
factory->record(frame_queue_factory);
}
{
ClassFactory processing_block_factory("rs2::processing_block");
processing_block_factory.record("process", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
auto thiz = MatlabParamParser::parse<rs2::processing_block>(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);
}
{
ClassFactory pointcloud_factory("rs2::pointcloud");
pointcloud_factory.record("new", 1, 0, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
pointcloud_factory.record("new", 1, 0, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
outv[0] = MatlabParamParser::wrap(rs2::pointcloud());
if (inc == 0) {
outv[0] = MatlabParamParser::wrap(rs2::pointcloud());
return;
}
auto stream = MatlabParamParser::parse<rs2_stream>(inv[0]);
if (inc == 1)
outv[0] = MatlabParamParser::wrap(rs2::pointcloud(stream));
else {
auto index = MatlabParamParser::parse<int>(inv[1]);
outv[0] = MatlabParamParser::wrap(rs2::pointcloud(stream, index));
}
});
pointcloud_factory.record("calculate", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
Expand Down Expand Up @@ -976,10 +997,7 @@ void make_factory(){
auto align_to = MatlabParamParser::parse<rs2_stream>(inv[0]);
outv[0] = MatlabParamParser::wrap(rs2::align(align_to));
});
align_factory.record("delete", 0, 1, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
MatlabParamParser::destroy<rs2::align>(inv[0]);
});
// TODO: how does this interact with the processing_block variant? Why are the separate?
align_factory.record("process", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
auto thiz = MatlabParamParser::parse<rs2::align>(inv[0]);
Expand All @@ -990,9 +1008,13 @@ void make_factory(){
}
{
ClassFactory colorizer_factory("rs2::colorizer");
colorizer_factory.record("new", 1, 0, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
colorizer_factory.record("new", 1, 0, 1, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
outv[0] = MatlabParamParser::wrap(rs2::colorizer());
if (inc == 0) outv[0] = MatlabParamParser::wrap(rs2::colorizer());
else {
auto color_scheme = MatlabParamParser::parse<float>(inv[0]);
outv[0] = MatlabParamParser::wrap(rs2::colorizer(color_scheme));
}
});
colorizer_factory.record("colorize", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
Expand All @@ -1002,38 +1024,46 @@ void make_factory(){
});
factory->record(colorizer_factory);
}
{
ClassFactory process_interface_factory("rs2::process_interface");
process_interface_factory.record("process", 1, 2, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
// TODO: will this work?
auto *thiz = MatlabParamParser::parse<rs2::process_interface*>(inv[0]);
auto frame = MatlabParamParser::parse<rs2::frame>(inv[1]);
outv[0] = MatlabParamParser::wrap(thiz->process(frame));
});
factory->record(process_interface_factory);
}
{
ClassFactory decimation_filter_factory("rs2::decimation_filter");
decimation_filter_factory.record("new", 1, 0, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
decimation_filter_factory.record("new", 1, 0, 1, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
outv[0] = MatlabParamParser::wrap(rs2::decimation_filter());
if (inc == 0) outv[0] = MatlabParamParser::wrap(rs2::decimation_filter());
else {
auto magnitude = MatlabParamParser::parse<float>(inv[0]);
outv[0] = MatlabParamParser::wrap(rs2::decimation_filter(magnitude));
}
});
factory->record(decimation_filter_factory);
}
{
ClassFactory temporal_filter_factory("rs2::temporal_filter");
temporal_filter_factory.record("new", 1, 0, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
temporal_filter_factory.record("new", 1, 0, 3, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
outv[0] = MatlabParamParser::wrap(rs2::temporal_filter());
if (inc == 0) outv[0] = MatlabParamParser::wrap(rs2::temporal_filter());
else if (inc == 3) {
auto smooth_alpha = MatlabParamParser::parse<float>(inv[0]);
auto smooth_delta = MatlabParamParser::parse<float>(inv[1]);
auto persistence_control = MatlabParamParser::parse<int>(inv[2]);
outv[0] = MatlabParamParser::wrap(rs2::temporal_filter(smooth_alpha, smooth_delta, persistence_control));
}
else mexErrMsgTxt("rs2::temporal_filter::new: Wrong number of Inputs");
});
factory->record(temporal_filter_factory);
}
{
ClassFactory spatial_filter_factory("rs2::spatial_filter");
spatial_filter_factory.record("new", 1, 0, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
outv[0] = MatlabParamParser::wrap(rs2::spatial_filter());
spatial_filter_factory.record("new", 1, 0, 4, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
if (inc == 0) outv[0] = MatlabParamParser::wrap(rs2::spatial_filter());
else if (inc == 4) {
auto smooth_alpha = MatlabParamParser::parse<float>(inv[0]);
auto smooth_delta = MatlabParamParser::parse<float>(inv[1]);
auto magnitude = MatlabParamParser::parse<float>(inv[2]);
auto hole_fill = MatlabParamParser::parse<float>(inv[3]);
outv[0] = MatlabParamParser::wrap(rs2::spatial_filter(smooth_alpha, smooth_delta, magnitude, hole_fill));
}
else mexErrMsgTxt("rs2::spatial_filter::new: Wrong number of Inputs");
});
factory->record(spatial_filter_factory);
}
Expand All @@ -1053,9 +1083,13 @@ void make_factory(){
}
{
ClassFactory hole_filling_filter_factory("rs2::hole_filling_filter");
hole_filling_filter_factory.record("new", 1, 0, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
hole_filling_filter_factory.record("new", 1, 0, 1, [](int outc, mxArray* outv[], int inc, const mxArray* inv[])
{
outv[0] = MatlabParamParser::wrap(rs2::hole_filling_filter());
if (inc == 0) outv[0] = MatlabParamParser::wrap(rs2::hole_filling_filter());
else {
auto mode = MatlabParamParser::parse<int>(inv[0]);
outv[0] = MatlabParamParser::wrap(rs2::hole_filling_filter(mode));
}
});
factory->record(hole_filling_filter_factory);
}
Expand Down
2 changes: 1 addition & 1 deletion wrappers/matlab/librealsense_mex.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
<None Include="pointcloud.m" />
<None Include="points.m" />
<None Include="pose_frame.m" />
<None Include="process_interface.m" />
<None Include="processing_block.m" />
<None Include="recorder.m" />
<None Include="roi_sensor.m" />
<None Include="rosbag_example.m" />
Expand Down
6 changes: 3 additions & 3 deletions wrappers/matlab/librealsense_mex.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@
<None Include="syncer.m">
<Filter>Matlab Files\Classes</Filter>
</None>
<None Include="process_interface.m">
<Filter>Matlab Files\Classes</Filter>
</None>
<None Include="colorizer.m">
<Filter>Matlab Files\Classes</Filter>
</None>
Expand Down Expand Up @@ -181,5 +178,8 @@
<None Include="rosbag_example.m">
<Filter>Matlab Files\Examples</Filter>
</None>
<None Include="processing_block.m">
<Filter>Matlab Files\Classes</Filter>
</None>
</ItemGroup>
</Project>
18 changes: 14 additions & 4 deletions wrappers/matlab/pointcloud.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
% Wraps librealsense2 pointcloud class
classdef pointcloud < realsense.options
classdef pointcloud < realsense.processing_block
methods
% Constructor
function this = pointcloud()
out = realsense.librealsense_mex('rs2::pointcloud', 'new');
this = [email protected](out);
function this = pointcloud(stream, index)
switch nargin
case 0
out = realsense.librealsense_mex('rs2::pointcloud', 'new');
case 1
validateattributes(stream, {'realsense.stream', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.stream.count});
out = realsense.librealsense_mex('rs2::pointcloud', 'new', int64(stream));
case 2
validateattributes(stream, {'realsense.stream', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.stream.count});
validateattributes(index, {'numeric'}, {'scalar', 'nonnegative', 'real', 'integer'});
out = realsense.librealsense_mex('rs2::pointcloud', 'new', int64(stream), int64(index));
end
this = [email protected]_block(out);
end

% Destructor (uses base class destructor)
Expand Down
19 changes: 0 additions & 19 deletions wrappers/matlab/process_interface.m

This file was deleted.

19 changes: 19 additions & 0 deletions wrappers/matlab/processing_block.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
% Wraps librealsense2 processing_block class
classdef processing_block < realsense.options
methods
% Constructor
function this = processing_block(handle)
this = [email protected](handle);
end

% Destructor (uses base class destructor)

% Functions
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_frame = realsense.frame(out);
end
end
end
Loading

0 comments on commit 0def593

Please sign in to comment.