openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:0e0631af0305 1 /***********************************************************************
RyoheiHagimoto 0:0e0631af0305 2 * Software License Agreement (BSD License)
RyoheiHagimoto 0:0e0631af0305 3 *
RyoheiHagimoto 0:0e0631af0305 4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
RyoheiHagimoto 0:0e0631af0305 5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
RyoheiHagimoto 0:0e0631af0305 6 *
RyoheiHagimoto 0:0e0631af0305 7 * THE BSD LICENSE
RyoheiHagimoto 0:0e0631af0305 8 *
RyoheiHagimoto 0:0e0631af0305 9 * Redistribution and use in source and binary forms, with or without
RyoheiHagimoto 0:0e0631af0305 10 * modification, are permitted provided that the following conditions
RyoheiHagimoto 0:0e0631af0305 11 * are met:
RyoheiHagimoto 0:0e0631af0305 12 *
RyoheiHagimoto 0:0e0631af0305 13 * 1. Redistributions of source code must retain the above copyright
RyoheiHagimoto 0:0e0631af0305 14 * notice, this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 15 * 2. Redistributions in binary form must reproduce the above copyright
RyoheiHagimoto 0:0e0631af0305 16 * notice, this list of conditions and the following disclaimer in the
RyoheiHagimoto 0:0e0631af0305 17 * documentation and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 18 *
RyoheiHagimoto 0:0e0631af0305 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
RyoheiHagimoto 0:0e0631af0305 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
RyoheiHagimoto 0:0e0631af0305 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
RyoheiHagimoto 0:0e0631af0305 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
RyoheiHagimoto 0:0e0631af0305 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
RyoheiHagimoto 0:0e0631af0305 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
RyoheiHagimoto 0:0e0631af0305 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
RyoheiHagimoto 0:0e0631af0305 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
RyoheiHagimoto 0:0e0631af0305 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
RyoheiHagimoto 0:0e0631af0305 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RyoheiHagimoto 0:0e0631af0305 29 *************************************************************************/
RyoheiHagimoto 0:0e0631af0305 30
RyoheiHagimoto 0:0e0631af0305 31 /***********************************************************************
RyoheiHagimoto 0:0e0631af0305 32 * Author: Vincent Rabaud
RyoheiHagimoto 0:0e0631af0305 33 *************************************************************************/
RyoheiHagimoto 0:0e0631af0305 34
RyoheiHagimoto 0:0e0631af0305 35 #ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_
RyoheiHagimoto 0:0e0631af0305 36 #define OPENCV_FLANN_DYNAMIC_BITSET_H_
RyoheiHagimoto 0:0e0631af0305 37
RyoheiHagimoto 0:0e0631af0305 38 #ifndef FLANN_USE_BOOST
RyoheiHagimoto 0:0e0631af0305 39 # define FLANN_USE_BOOST 0
RyoheiHagimoto 0:0e0631af0305 40 #endif
RyoheiHagimoto 0:0e0631af0305 41 //#define FLANN_USE_BOOST 1
RyoheiHagimoto 0:0e0631af0305 42 #if FLANN_USE_BOOST
RyoheiHagimoto 0:0e0631af0305 43 #include <boost/dynamic_bitset.hpp>
RyoheiHagimoto 0:0e0631af0305 44 typedef boost::dynamic_bitset<> DynamicBitset;
RyoheiHagimoto 0:0e0631af0305 45 #else
RyoheiHagimoto 0:0e0631af0305 46
RyoheiHagimoto 0:0e0631af0305 47 #include <limits.h>
RyoheiHagimoto 0:0e0631af0305 48
RyoheiHagimoto 0:0e0631af0305 49 #include "dist.h"
RyoheiHagimoto 0:0e0631af0305 50
RyoheiHagimoto 0:0e0631af0305 51 namespace cvflann {
RyoheiHagimoto 0:0e0631af0305 52
RyoheiHagimoto 0:0e0631af0305 53 /** Class re-implementing the boost version of it
RyoheiHagimoto 0:0e0631af0305 54 * This helps not depending on boost, it also does not do the bound checks
RyoheiHagimoto 0:0e0631af0305 55 * and has a way to reset a block for speed
RyoheiHagimoto 0:0e0631af0305 56 */
RyoheiHagimoto 0:0e0631af0305 57 class DynamicBitset
RyoheiHagimoto 0:0e0631af0305 58 {
RyoheiHagimoto 0:0e0631af0305 59 public:
RyoheiHagimoto 0:0e0631af0305 60 /** default constructor
RyoheiHagimoto 0:0e0631af0305 61 */
RyoheiHagimoto 0:0e0631af0305 62 DynamicBitset()
RyoheiHagimoto 0:0e0631af0305 63 {
RyoheiHagimoto 0:0e0631af0305 64 }
RyoheiHagimoto 0:0e0631af0305 65
RyoheiHagimoto 0:0e0631af0305 66 /** only constructor we use in our code
RyoheiHagimoto 0:0e0631af0305 67 * @param sz the size of the bitset (in bits)
RyoheiHagimoto 0:0e0631af0305 68 */
RyoheiHagimoto 0:0e0631af0305 69 DynamicBitset(size_t sz)
RyoheiHagimoto 0:0e0631af0305 70 {
RyoheiHagimoto 0:0e0631af0305 71 resize(sz);
RyoheiHagimoto 0:0e0631af0305 72 reset();
RyoheiHagimoto 0:0e0631af0305 73 }
RyoheiHagimoto 0:0e0631af0305 74
RyoheiHagimoto 0:0e0631af0305 75 /** Sets all the bits to 0
RyoheiHagimoto 0:0e0631af0305 76 */
RyoheiHagimoto 0:0e0631af0305 77 void clear()
RyoheiHagimoto 0:0e0631af0305 78 {
RyoheiHagimoto 0:0e0631af0305 79 std::fill(bitset_.begin(), bitset_.end(), 0);
RyoheiHagimoto 0:0e0631af0305 80 }
RyoheiHagimoto 0:0e0631af0305 81
RyoheiHagimoto 0:0e0631af0305 82 /** @brief checks if the bitset is empty
RyoheiHagimoto 0:0e0631af0305 83 * @return true if the bitset is empty
RyoheiHagimoto 0:0e0631af0305 84 */
RyoheiHagimoto 0:0e0631af0305 85 bool empty() const
RyoheiHagimoto 0:0e0631af0305 86 {
RyoheiHagimoto 0:0e0631af0305 87 return bitset_.empty();
RyoheiHagimoto 0:0e0631af0305 88 }
RyoheiHagimoto 0:0e0631af0305 89
RyoheiHagimoto 0:0e0631af0305 90 /** set all the bits to 0
RyoheiHagimoto 0:0e0631af0305 91 */
RyoheiHagimoto 0:0e0631af0305 92 void reset()
RyoheiHagimoto 0:0e0631af0305 93 {
RyoheiHagimoto 0:0e0631af0305 94 std::fill(bitset_.begin(), bitset_.end(), 0);
RyoheiHagimoto 0:0e0631af0305 95 }
RyoheiHagimoto 0:0e0631af0305 96
RyoheiHagimoto 0:0e0631af0305 97 /** @brief set one bit to 0
RyoheiHagimoto 0:0e0631af0305 98 * @param index
RyoheiHagimoto 0:0e0631af0305 99 */
RyoheiHagimoto 0:0e0631af0305 100 void reset(size_t index)
RyoheiHagimoto 0:0e0631af0305 101 {
RyoheiHagimoto 0:0e0631af0305 102 bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_));
RyoheiHagimoto 0:0e0631af0305 103 }
RyoheiHagimoto 0:0e0631af0305 104
RyoheiHagimoto 0:0e0631af0305 105 /** @brief sets a specific bit to 0, and more bits too
RyoheiHagimoto 0:0e0631af0305 106 * This function is useful when resetting a given set of bits so that the
RyoheiHagimoto 0:0e0631af0305 107 * whole bitset ends up being 0: if that's the case, we don't care about setting
RyoheiHagimoto 0:0e0631af0305 108 * other bits to 0
RyoheiHagimoto 0:0e0631af0305 109 * @param index
RyoheiHagimoto 0:0e0631af0305 110 */
RyoheiHagimoto 0:0e0631af0305 111 void reset_block(size_t index)
RyoheiHagimoto 0:0e0631af0305 112 {
RyoheiHagimoto 0:0e0631af0305 113 bitset_[index / cell_bit_size_] = 0;
RyoheiHagimoto 0:0e0631af0305 114 }
RyoheiHagimoto 0:0e0631af0305 115
RyoheiHagimoto 0:0e0631af0305 116 /** resize the bitset so that it contains at least sz bits
RyoheiHagimoto 0:0e0631af0305 117 * @param sz
RyoheiHagimoto 0:0e0631af0305 118 */
RyoheiHagimoto 0:0e0631af0305 119 void resize(size_t sz)
RyoheiHagimoto 0:0e0631af0305 120 {
RyoheiHagimoto 0:0e0631af0305 121 size_ = sz;
RyoheiHagimoto 0:0e0631af0305 122 bitset_.resize(sz / cell_bit_size_ + 1);
RyoheiHagimoto 0:0e0631af0305 123 }
RyoheiHagimoto 0:0e0631af0305 124
RyoheiHagimoto 0:0e0631af0305 125 /** set a bit to true
RyoheiHagimoto 0:0e0631af0305 126 * @param index the index of the bit to set to 1
RyoheiHagimoto 0:0e0631af0305 127 */
RyoheiHagimoto 0:0e0631af0305 128 void set(size_t index)
RyoheiHagimoto 0:0e0631af0305 129 {
RyoheiHagimoto 0:0e0631af0305 130 bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_);
RyoheiHagimoto 0:0e0631af0305 131 }
RyoheiHagimoto 0:0e0631af0305 132
RyoheiHagimoto 0:0e0631af0305 133 /** gives the number of contained bits
RyoheiHagimoto 0:0e0631af0305 134 */
RyoheiHagimoto 0:0e0631af0305 135 size_t size() const
RyoheiHagimoto 0:0e0631af0305 136 {
RyoheiHagimoto 0:0e0631af0305 137 return size_;
RyoheiHagimoto 0:0e0631af0305 138 }
RyoheiHagimoto 0:0e0631af0305 139
RyoheiHagimoto 0:0e0631af0305 140 /** check if a bit is set
RyoheiHagimoto 0:0e0631af0305 141 * @param index the index of the bit to check
RyoheiHagimoto 0:0e0631af0305 142 * @return true if the bit is set
RyoheiHagimoto 0:0e0631af0305 143 */
RyoheiHagimoto 0:0e0631af0305 144 bool test(size_t index) const
RyoheiHagimoto 0:0e0631af0305 145 {
RyoheiHagimoto 0:0e0631af0305 146 return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0;
RyoheiHagimoto 0:0e0631af0305 147 }
RyoheiHagimoto 0:0e0631af0305 148
RyoheiHagimoto 0:0e0631af0305 149 private:
RyoheiHagimoto 0:0e0631af0305 150 std::vector<size_t> bitset_;
RyoheiHagimoto 0:0e0631af0305 151 size_t size_;
RyoheiHagimoto 0:0e0631af0305 152 static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t);
RyoheiHagimoto 0:0e0631af0305 153 };
RyoheiHagimoto 0:0e0631af0305 154
RyoheiHagimoto 0:0e0631af0305 155 } // namespace cvflann
RyoheiHagimoto 0:0e0631af0305 156
RyoheiHagimoto 0:0e0631af0305 157 #endif
RyoheiHagimoto 0:0e0631af0305 158
RyoheiHagimoto 0:0e0631af0305 159 #endif // OPENCV_FLANN_DYNAMIC_BITSET_H_