Skip to content

Commit 41d0af8

Browse files
author
Peter Andreas Entschev
committed
FAST will return (af_)features instead of (af_)features *
1 parent 50e173e commit 41d0af8

File tree

12 files changed

+98
-106
lines changed

12 files changed

+98
-106
lines changed

include/af/features.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace af
2121

2222
class AFAPI features {
2323
private:
24-
af_features * feat;
24+
af_features feat;
2525

2626
public:
2727
features();
2828
features(const size_t n);
29-
features(af_features* f);
29+
features(af_features f);
3030

3131
size_t getNumFeatures();
3232
array getX();
@@ -47,7 +47,7 @@ namespace af
4747
void setSize(const array size);
4848
void setSize(const af_array size);
4949

50-
af_features * get();
50+
af_features get();
5151
};
5252

5353
}

include/af/image.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ AFAPI void grad(array& rows, array& cols, const array& in);
5252

5353
AFAPI array regions(const array& in, af_connectivity_type connectivity=AF_CONNECTIVITY_4, af_dtype type=f32);
5454

55-
AFAPI features * fast(const array& in, const float thr=20.0f, const unsigned arc_length=9, const bool non_max=true, const float feature_ratio=0.05);
55+
AFAPI features fast(const array& in, const float thr=20.0f, const unsigned arc_length=9, const bool non_max=true, const float feature_ratio=0.05);
5656

5757
}
5858
#endif
@@ -118,7 +118,7 @@ extern "C" {
118118
AFAPI af_err af_regions(af_array *out, const af_array in, af_connectivity_type connectivity, af_dtype ty);
119119

120120
// Compute FAST corners from input image
121-
AFAPI af_err af_fast(af_features **out, const af_array in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio);
121+
AFAPI af_err af_fast(af_features *out, const af_array in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio);
122122

123123
#ifdef __cplusplus
124124
}

src/api/c/fast.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ using af::dim4;
2020
using namespace detail;
2121

2222
template<typename T>
23-
static af_features * fast(af_array const &in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio)
23+
static af_features fast(af_array const &in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio)
2424
{
25-
return fast<T>(getArray<T>(in), thr, arc_length, non_max, feature_ratio)->get();
25+
return fast<T>(getArray<T>(in), thr, arc_length, non_max, feature_ratio).get();
2626
}
2727

28-
af_err af_fast(af_features **out, const af_array in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio)
28+
af_err af_fast(af_features *out, const af_array in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio)
2929
{
3030
try {
3131
ArrayInfo info = getInfo(in);
@@ -39,18 +39,16 @@ af_err af_fast(af_features **out, const af_array in, const float thr, const unsi
3939
dim_type in_ndims = dims.ndims();
4040
DIM_ASSERT(1, (in_ndims <= 3 && in_ndims >= 2));
4141

42-
af_features * output;
4342
af_dtype type = info.getType();
4443
switch(type) {
45-
case f32: output = fast<float >(in, thr, arc_length, non_max, feature_ratio); break;
46-
case f64: output = fast<double>(in, thr, arc_length, non_max, feature_ratio); break;
47-
case b8 : output = fast<char >(in, thr, arc_length, non_max, feature_ratio); break;
48-
case s32: output = fast<int >(in, thr, arc_length, non_max, feature_ratio); break;
49-
case u32: output = fast<uint >(in, thr, arc_length, non_max, feature_ratio); break;
50-
case u8 : output = fast<uchar >(in, thr, arc_length, non_max, feature_ratio); break;
44+
case f32: *out = fast<float >(in, thr, arc_length, non_max, feature_ratio); break;
45+
case f64: *out = fast<double>(in, thr, arc_length, non_max, feature_ratio); break;
46+
case b8 : *out = fast<char >(in, thr, arc_length, non_max, feature_ratio); break;
47+
case s32: *out = fast<int >(in, thr, arc_length, non_max, feature_ratio); break;
48+
case u32: *out = fast<uint >(in, thr, arc_length, non_max, feature_ratio); break;
49+
case u8 : *out = fast<uchar >(in, thr, arc_length, non_max, feature_ratio); break;
5150
default : TYPE_ERROR(1, type);
5251
}
53-
*out = output;
5452
}
5553
CATCHALL;
5654

src/api/c/feature.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,112 +16,110 @@ namespace af
1616

1717
features::features()
1818
{
19-
feat = new af_features;
20-
feat->n = 0;
19+
feat.n = 0;
2120
}
2221

2322
features::features(const size_t n)
2423
{
25-
feat = new af_features;
26-
feat->n = n;
27-
feat->x = array(n, f32).get();
28-
feat->y = array(n, f32).get();
29-
feat->score = array(n, f32).get();
30-
feat->orientation = array(n, f32).get();
31-
feat->size = array(n, f32).get();
24+
feat.n = n;
25+
feat.x = array(n, f32).get();
26+
feat.y = array(n, f32).get();
27+
feat.score = array(n, f32).get();
28+
feat.orientation = array(n, f32).get();
29+
feat.size = array(n, f32).get();
3230
}
3331

34-
features::features(af_features* f) : feat(f)
32+
features::features(af_features f) : feat(f)
3533
{
36-
feat->n = f->n;
34+
feat.n = f.n;
3735
}
3836

3937
size_t features::getNumFeatures()
4038
{
41-
return feat->n;
39+
return feat.n;
4240
}
4341

4442
array features::getX()
4543
{
46-
return array(feat->x);
44+
return array(feat.x);
4745
}
4846

4947
array features::getY()
5048
{
51-
return array(feat->y);
49+
return array(feat.y);
5250
}
5351

5452
array features::getScore()
5553
{
56-
return array(feat->score);
54+
return array(feat.score);
5755
}
5856

5957
array features::getOrientation()
6058
{
61-
return array(feat->orientation);
59+
return array(feat.orientation);
6260
}
6361

6462
array features::getSize()
6563
{
66-
return array(feat->size);
64+
return array(feat.size);
6765
}
6866

6967
void features::setNumFeatures(const size_t n)
7068
{
71-
feat->n = n;
69+
feat.n = n;
7270
}
7371

7472
void features::setX(const array x)
7573
{
76-
feat->x = x.get();
74+
feat.x = x.get();
7775
}
7876

7977
void features::setX(const af_array x)
8078
{
81-
feat->x = x;
79+
feat.x = x;
8280
}
8381

8482
void features::setY(const array y)
8583
{
86-
feat->y = y.get();
84+
feat.y = y.get();
8785
}
8886

8987
void features::setY(const af_array y)
9088
{
91-
feat->y = y;
89+
feat.y = y;
9290
}
9391

9492
void features::setScore(const array score)
9593
{
96-
feat->score = score.get();
94+
feat.score = score.get();
9795
}
9896

9997
void features::setScore(const af_array score)
10098
{
101-
feat->score = score;
99+
feat.score = score;
102100
}
103101

104102
void features::setOrientation(const array orientation)
105103
{
106-
feat->orientation = orientation.get();
104+
feat.orientation = orientation.get();
107105
}
108106

109107
void features::setOrientation(const af_array orientation)
110108
{
111-
feat->orientation = orientation;
109+
feat.orientation = orientation;
112110
}
113111

114112
void features::setSize(const array size)
115113
{
116-
feat->size = size.get();
114+
feat.size = size.get();
117115
}
118116

119117
void features::setSize(const af_array size)
120118
{
121-
feat->size = size;
119+
feat.size = size;
122120
}
123121

124-
af_features * features::get()
122+
af_features features::get()
125123
{
126124
return feat;
127125
}

src/api/cpp/fast.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
namespace af
1414
{
1515

16-
features * fast(const array& in, const float thr, const unsigned arc_length,
16+
features fast(const array& in, const float thr, const unsigned arc_length,
1717
const bool non_max, const float feature_ratio)
1818
{
19-
af_features * temp = 0;
19+
af_features temp;
2020
AF_THROW(af_fast(&temp, in.get(), thr, arc_length, non_max, feature_ratio));
21-
features * out = new features(temp);
21+
features out(temp);
2222
return out;
2323
}
2424

src/backend/cpu/fast.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ void non_maximal(
241241
}
242242

243243
template<typename T>
244-
features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
245-
const bool nonmax, const float feature_ratio)
244+
features fast(const Array<T> &in, const float thr, const unsigned arc_length,
245+
const bool nonmax, const float feature_ratio)
246246
{
247247
dim4 in_dims = in.dims();
248248
const unsigned max_feat = ceil(in.elements() * feature_ratio);
@@ -337,20 +337,20 @@ features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
337337
}
338338
}
339339

340-
features * feat = new features;
341-
feat->setNumFeatures(feat_found);
342-
feat->setX(getHandle<float>(*x_out));
343-
feat->setY(getHandle<float>(*y_out));
344-
feat->setScore(getHandle<float>(*score_out));
345-
feat->setOrientation(getHandle<float>(*orientation_out));
346-
feat->setSize(getHandle<float>(*size_out));
340+
features feat;
341+
feat.setNumFeatures(feat_found);
342+
feat.setX(getHandle<float>(*x_out));
343+
feat.setY(getHandle<float>(*y_out));
344+
feat.setScore(getHandle<float>(*score_out));
345+
feat.setOrientation(getHandle<float>(*orientation_out));
346+
feat.setSize(getHandle<float>(*size_out));
347347

348348
return feat;
349349
}
350350

351351
#define INSTANTIATE(T)\
352-
template features * fast<T>(const Array<T> &in, const float thr, const unsigned arc_length, \
353-
const bool nonmax, const float feature_ratio);
352+
template features fast<T>(const Array<T> &in, const float thr, const unsigned arc_length, \
353+
const bool nonmax, const float feature_ratio);
354354

355355
INSTANTIATE(float )
356356
INSTANTIATE(double)

src/backend/cpu/fast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace cpu
1616
{
1717

1818
template<typename T>
19-
features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
20-
const bool non_max, const float feature_ratio);
19+
features fast(const Array<T> &in, const float thr, const unsigned arc_length,
20+
const bool non_max, const float feature_ratio);
2121

2222
}

src/backend/cuda/fast.cu

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace cuda
2323
{
2424

2525
template<typename T>
26-
features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
26+
features fast(const Array<T> &in, const float thr, const unsigned arc_length,
2727
const bool non_max, const float feature_ratio)
2828
{
2929
const dim4 dims = in.dims();
@@ -44,20 +44,20 @@ features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
4444
Array<float> * orientation = createValueArray<float>(out_dims, 0.0f);
4545
Array<float> * size = createValueArray<float>(out_dims, 1.0f);
4646

47-
features * feat = new features;
48-
feat->setNumFeatures(nfeat);
49-
feat->setX(getHandle<float>(*x));
50-
feat->setY(getHandle<float>(*y));
51-
feat->setScore(getHandle<float>(*score));
52-
feat->setOrientation(getHandle<float>(*orientation));
53-
feat->setSize(getHandle<float>(*size));
47+
features feat;
48+
feat.setNumFeatures(nfeat);
49+
feat.setX(getHandle<float>(*x));
50+
feat.setY(getHandle<float>(*y));
51+
feat.setScore(getHandle<float>(*score));
52+
feat.setOrientation(getHandle<float>(*orientation));
53+
feat.setSize(getHandle<float>(*size));
5454

5555
return feat;
5656
}
5757

5858
#define INSTANTIATE(T)\
59-
template features * fast<T>(const Array<T> &in, const float thr, const unsigned arc_length, \
60-
const bool non_max, const float feature_ratio);
59+
template features fast<T>(const Array<T> &in, const float thr, const unsigned arc_length, \
60+
const bool non_max, const float feature_ratio);
6161

6262
INSTANTIATE(float )
6363
INSTANTIATE(double)

src/backend/cuda/fast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace cuda
1616
{
1717

1818
template<typename T>
19-
features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
20-
const bool non_max, const float feature_ratio);
19+
features fast(const Array<T> &in, const float thr, const unsigned arc_length,
20+
const bool non_max, const float feature_ratio);
2121

2222
}

src/backend/opencl/fast.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace opencl
2323
{
2424

2525
template<typename T>
26-
features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
27-
const bool nonmax, const float feature_ratio)
26+
features fast(const Array<T> &in, const float thr, const unsigned arc_length,
27+
const bool nonmax, const float feature_ratio)
2828
{
2929
unsigned nfeat;
3030

@@ -106,20 +106,20 @@ features * fast(const Array<T> &in, const float thr, const unsigned arc_length,
106106

107107
const dim4 out_dims(nfeat);
108108

109-
features * feat = new features;
110-
feat->setNumFeatures(nfeat);
111-
feat->setX(getHandle<float>(*createParamArray<float>(x)));
112-
feat->setY(getHandle<float>(*createParamArray<float>(y)));
113-
feat->setScore(getHandle<float>(*createParamArray<float>(score)));
114-
feat->setOrientation(getHandle<float>(*createValueArray<float>(out_dims, 0.0f)));
115-
feat->setSize(getHandle<float>(*createValueArray<float>(out_dims, 1.0f)));
109+
features feat;
110+
feat.setNumFeatures(nfeat);
111+
feat.setX(getHandle<float>(*createParamArray<float>(x)));
112+
feat.setY(getHandle<float>(*createParamArray<float>(y)));
113+
feat.setScore(getHandle<float>(*createParamArray<float>(score)));
114+
feat.setOrientation(getHandle<float>(*createValueArray<float>(out_dims, 0.0f)));
115+
feat.setSize(getHandle<float>(*createValueArray<float>(out_dims, 1.0f)));
116116

117117
return feat;
118118
}
119119

120120
#define INSTANTIATE(T)\
121-
template features * fast<T>(const Array<T> &in, const float thr, const unsigned arc_length, \
122-
const bool non_max, const float feature_ratio);
121+
template features fast<T>(const Array<T> &in, const float thr, const unsigned arc_length, \
122+
const bool non_max, const float feature_ratio);
123123

124124
INSTANTIATE(float )
125125
INSTANTIATE(double)

0 commit comments

Comments
 (0)