From df471369e26b08232000763b2128d6f58a916f82 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 28 Jan 2014 18:35:46 +0600 Subject: Bundle latest Libmv from upstream Currently no functional changes, but we might want to have scoped_array in the future. --- extern/libmv/ChangeLog | 32 +++++++++++++------- extern/libmv/libmv/base/scoped_ptr.h | 45 ++++++++++++++++++++++++++++ extern/libmv/libmv/simple_pipeline/detect.cc | 19 ++++-------- 3 files changed, 73 insertions(+), 23 deletions(-) (limited to 'extern') diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index f9ddbb8c1b9..1a87097a8c3 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,25 @@ +commit da4607f010bca0b3532cd4444afbb10bc774fc32 +Author: Sergey Sharybin +Date: Tue Jan 28 18:32:39 2014 +0600 + + Implemented scoped_array and use it in detector + + scoped_array is pretty much the same as scoped_ptr + with the only difference that it'll free memory using + delete[] operator. + + It also gives some additional API functions to access + array elements. + + Currently it only used to manage images denoted as byte + arrays in detector. + + Reviewers: keir + + Reviewed By: keir + + Differential Revision: https://developer.blender.org/D266 + commit cd7eb3eff2e69ce5e08570ead83ae6d35ee48857 Author: Sergey Sharybin Date: Tue Jan 28 17:23:47 2014 +0600 @@ -676,13 +698,3 @@ Date: Sat Apr 6 20:49:05 2013 +0600 Discovered when was doing unit-tests for brute region tracker. This reverts commit daa354c0735b954b0cd7725626e9a3d67416d46b. - -commit 5bd89d9b8fb620e7e88bcbfa74165309b872f529 -Author: Sergey Sharybin -Date: Sat Apr 6 18:37:37 2013 +0600 - - Added basic test for brute region tracker - - It is failing at this moment and this is caused because - of how SampleLinear works - seems it's assumption about - pixel center is not correct for internal sampling. diff --git a/extern/libmv/libmv/base/scoped_ptr.h b/extern/libmv/libmv/base/scoped_ptr.h index f1e89eb5625..b9cd4854213 100644 --- a/extern/libmv/libmv/base/scoped_ptr.h +++ b/extern/libmv/libmv/base/scoped_ptr.h @@ -21,6 +21,9 @@ #ifndef LIBMV_BASE_SCOPED_PTR_H #define LIBMV_BASE_SCOPED_PTR_H +#include +#include + namespace libmv { /** @@ -55,6 +58,48 @@ class scoped_ptr { T *resource_; }; +// Same as scoped_ptr but caller must allocate the data +// with new[] and the destructor will free the memory +// using delete[]. +template +class scoped_array { + public: + scoped_array(T *array) : array_(array) {} + ~scoped_array() { reset(NULL); } + + T *get() const { return array_; } + + T& operator[](std::ptrdiff_t i) const { + assert(i >= 0); + assert(array_ != NULL); + return array_[i]; + } + + void reset(T *new_array) { + if (sizeof(T)) { + delete array_; + } + array_ = new_array; + } + + T *release() { + T *released_array = array_; + array_ = NULL; + return released_array; + } + + private: + T *array_; + + // Forbid comparison of different scoped_array types. + template bool operator==(scoped_array const& p2) const; + template bool operator!=(scoped_array const& p2) const; + + // Disallow evil constructors + scoped_array(const scoped_array&); + void operator=(const scoped_array&); +}; + } // namespace libmv #endif // LIBMV_BASE_SCOPED_PTR_H diff --git a/extern/libmv/libmv/simple_pipeline/detect.cc b/extern/libmv/libmv/simple_pipeline/detect.cc index 1ddb23dcd28..09adfccf96e 100644 --- a/extern/libmv/libmv/simple_pipeline/detect.cc +++ b/extern/libmv/libmv/simple_pipeline/detect.cc @@ -99,14 +99,12 @@ void DetectFAST(const FloatImage &grayscale_image, const int height = grayscale_image.Width() - 2 * margin; const int stride = grayscale_image.Width(); - // TODO(sergey): Use scoped_array to guard de-allocation of the array. - // Same goes to `scores` and `all` arrays here. - unsigned char *byte_image = FloatImageToUCharArray(grayscale_image); + scoped_array byte_image(FloatImageToUCharArray(grayscale_image)); const int byte_image_offset = margin * stride + margin; // TODO(MatthiasF): Support targetting a feature count (binary search trackness) int num_features; - xy *all = fast9_detect(byte_image + byte_image_offset, + xy *all = fast9_detect(byte_image.get() + byte_image_offset, width, height, stride, @@ -114,10 +112,9 @@ void DetectFAST(const FloatImage &grayscale_image, &num_features); if (num_features == 0) { free(all); - delete [] byte_image; return; } - int *scores = fast9_score(byte_image + byte_image_offset, + int *scores = fast9_score(byte_image.get() + byte_image_offset, stride, all, num_features, @@ -125,7 +122,6 @@ void DetectFAST(const FloatImage &grayscale_image, // TODO(MatthiasF): merge with close feature suppression xy *nonmax = nonmax_suppression(all, scores, num_features, &num_features); free(all); - delete [] byte_image; // Remove too close features // TODO(MatthiasF): A resolution independent parameter would be better than // distance e.g. a coefficient going from 0 (no minimal distance) to 1 @@ -181,13 +177,12 @@ void DetectMORAVEC(const FloatImage &grayscale_image, const int height = grayscale_image.Width() - 2 * margin; const int stride = grayscale_image.Width(); - // TODO(sergey): Use scoped_array to guard de-allocation of the array. - unsigned char *byte_image = FloatImageToUCharArray(grayscale_image); + scoped_array byte_image(FloatImageToUCharArray(grayscale_image)); unsigned short histogram[256]; memset(histogram, 0, sizeof(histogram)); - ubyte* scores = new ubyte[width*height]; - memset(scores, 0, width*height); + scoped_array scores(new ubyte[width*height]); + memset(scores.get(), 0, width*height); const int r = 1; // radius for self similarity comparison for (int y = distance; y < height-distance; y++) { for (int x = distance; x < width-distance; x++) { @@ -240,8 +235,6 @@ void DetectMORAVEC(const FloatImage &grayscale_image, } } } - delete[] scores; - delete[] byte_image; } void DetectHarris(const FloatImage &grayscale_image, -- cgit v1.2.3