Skip to content

Commit 706138f

Browse files
committed
[c++/m] Add MultiTag getByIndex functions
Implements the getByIndex functions on the c++ and the Matlab side and adds corresponding tests. - getReference - getFeature - getSource
1 parent 022085d commit 706138f

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed

+nix/MultiTag.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@
5656
retObj = nix.Utils.open_entity(obj, ...
5757
'MultiTag::openReferences', id_or_name, @nix.DataArray);
5858
end;
59-
59+
60+
function retObj = open_reference_idx(obj, idx)
61+
retObj = nix.Utils.open_entity(obj, ...
62+
'MultiTag::openReferenceIdx', idx, @nix.DataArray);
63+
end;
64+
6065
function data = retrieve_data(obj, pos_index, ref_index)
6166
% convert Matlab-like to C-like index
6267
assert(pos_index > 0, 'Position index must be positive');
@@ -101,6 +106,11 @@
101106
'MultiTag::openFeature', id_or_name, @nix.Feature);
102107
end;
103108

109+
function retObj = open_feature_idx(obj, idx)
110+
retObj = nix.Utils.open_entity(obj, ...
111+
'MultiTag::openFeatureIdx', idx, @nix.Feature);
112+
end;
113+
104114
function data = retrieve_feature_data(obj, pos_index, fea_index)
105115
% convert Matlab-like to C-like index
106116
assert(pos_index > 0, 'Position index must be positive');

nix_mx.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ void mexFunction(int nlhs,
345345
methods->add("MultiTag::addSources", nixmultitag::addSources);
346346
methods->add("MultiTag::createFeature", nixmultitag::createFeature);
347347
methods->add("MultiTag::addPositions", nixmultitag::addPositions);
348+
methods->add("MultiTag::openReferenceIdx", nixmultitag::openReferenceIdx);
349+
methods->add("MultiTag::openFeatureIdx", nixmultitag::openFeatureIdx);
350+
methods->add("MultiTag::openSourceIdx", nixmultitag::openSourceIdx);
348351

349352
classdef<nix::Section>("Section", methods)
350353
.desc(&nixsection::describe)

src/nixmultitag.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,22 @@ namespace nixmultitag {
8383
currObj.positions(input.str(2));
8484
}
8585

86+
void openReferenceIdx(const extractor &input, infusor &output) {
87+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
88+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
89+
output.set(0, currObj.getReference(idx));
90+
}
91+
92+
void openFeatureIdx(const extractor &input, infusor &output) {
93+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
94+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
95+
output.set(0, currObj.getFeature(idx));
96+
}
97+
98+
void openSourceIdx(const extractor &input, infusor &output) {
99+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
100+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
101+
output.set(0, currObj.getSource(idx));
102+
}
103+
86104
} // namespace nixmultitag

src/nixmultitag.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ namespace nixmultitag {
3131

3232
void addPositions(const extractor &input, infusor &output);
3333

34+
void openReferenceIdx(const extractor &input, infusor &output);
35+
36+
void openFeatureIdx(const extractor &input, infusor &output);
37+
38+
void openSourceIdx(const extractor &input, infusor &output);
39+
3440
} // namespace nixmultitag
3541

3642
#endif

tests/TestMultiTag.m

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
funcs{end+1} = @test_fetch_sources;
2626
funcs{end+1} = @test_fetch_features;
2727
funcs{end+1} = @test_open_source;
28+
funcs{end+1} = @test_open_source_idx;
2829
funcs{end+1} = @test_has_source;
2930
funcs{end+1} = @test_source_count;
3031
funcs{end+1} = @test_open_feature;
32+
funcs{end+1} = @test_open_feature_idx;
3133
funcs{end+1} = @test_open_reference;
34+
funcs{end+1} = @test_open_reference_idx;
3235
funcs{end+1} = @test_feature_count;
3336
funcs{end+1} = @test_reference_count;
3437
funcs{end+1} = @test_add_positions;
@@ -338,6 +341,24 @@
338341
assert(isempty(getSource));
339342
end
340343

344+
function [] = test_open_source_idx( varargin )
345+
%% Test Open Source by index
346+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
347+
b = f.create_block('testBlock', 'nixBlock');
348+
d = b.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Double, [2 9]);
349+
t = b.create_multi_tag('testMultiTag', 'nixMultiTag', d);
350+
s1 = b.create_source('testSource1', 'nixSource');
351+
s2 = b.create_source('testSource2', 'nixSource');
352+
s3 = b.create_source('testSource3', 'nixSource');
353+
t.add_source(s1);
354+
t.add_source(s2);
355+
t.add_source(s3);
356+
357+
assert(strcmp(f.blocks{1}.multiTags{1}.open_source_idx(0).name, s1.name));
358+
assert(strcmp(f.blocks{1}.multiTags{1}.open_source_idx(1).name, s2.name));
359+
assert(strcmp(f.blocks{1}.multiTags{1}.open_source_idx(2).name, s3.name));
360+
end
361+
341362
%% Test: has nix.Source by ID or entity
342363
function [] = test_has_source( varargin )
343364
fileName = 'testRW.h5';
@@ -391,6 +412,24 @@
391412
assert(isempty(getFeat));
392413
end
393414

415+
function [] = test_open_feature_idx( varargin )
416+
%% Test Open feature by index
417+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
418+
b = f.create_block('testBlock', 'nixBlock');
419+
d = b.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Double, [2 9]);
420+
t = b.create_multi_tag('testMultiTag', 'nixMultiTag', d);
421+
f1 = b.create_data_array('testFeature1', 'nixDataArray', nix.DataType.Bool, [2 2]);
422+
f2 = b.create_data_array('testFeature2', 'nixDataArray', nix.DataType.Bool, [2 2]);
423+
f3 = b.create_data_array('testFeature3', 'nixDataArray', nix.DataType.Bool, [2 2]);
424+
t.add_feature(f1, nix.LinkType.Tagged);
425+
t.add_feature(f2, nix.LinkType.Untagged);
426+
t.add_feature(f3, nix.LinkType.Indexed);
427+
428+
assert(f.blocks{1}.multiTags{1}.open_feature_idx(0).linkType == nix.LinkType.Tagged);
429+
assert(f.blocks{1}.multiTags{1}.open_feature_idx(1).linkType == nix.LinkType.Untagged);
430+
assert(f.blocks{1}.multiTags{1}.open_feature_idx(2).linkType == nix.LinkType.Indexed);
431+
end
432+
394433
%% Test: Open reference by ID or name
395434
function [] = test_open_reference( varargin )
396435
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
@@ -412,6 +451,24 @@
412451
assert(isempty(getRef));
413452
end
414453

454+
function [] = test_open_reference_idx( varargin )
455+
%% Test Open feature by index
456+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
457+
b = f.create_block('testBlock', 'nixBlock');
458+
d = b.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Double, [2 9]);
459+
t = b.create_multi_tag('testMultiTag', 'nixMultiTag', d);
460+
r1 = b.create_data_array('testReference1', 'nixDataArray', nix.DataType.Bool, [2 2]);
461+
r2 = b.create_data_array('testReference2', 'nixDataArray', nix.DataType.Bool, [2 2]);
462+
r3 = b.create_data_array('testReference3', 'nixDataArray', nix.DataType.Bool, [2 2]);
463+
t.add_reference(r1);
464+
t.add_reference(r2);
465+
t.add_reference(r3);
466+
467+
assert(strcmp(f.blocks{1}.multiTags{1}.open_reference_idx(0).name, r1.name));
468+
assert(strcmp(f.blocks{1}.multiTags{1}.open_reference_idx(1).name, r2.name));
469+
assert(strcmp(f.blocks{1}.multiTags{1}.open_reference_idx(2).name, r3.name));
470+
end
471+
415472
%% Test: Feature count
416473
function [] = test_feature_count( varargin )
417474
testFile = fullfile(pwd, 'tests', 'testRW.h5');

0 commit comments

Comments
 (0)