1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/*
* Simd Library (http://ermig1979.github.io/Simd).
*
* Copyright (c) 2011-2017 Yermalayeu Ihar.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __SimdPyramid_hpp__
#define __SimdPyramid_hpp__
#include "Simd/SimdView.hpp"
#include <vector>
namespace Simd
{
/*! @ingroup cpp_pyramid
\short The Pyramid structure provides storage and manipulation of pyramid images.
The pyramid is a series of gray 8-bit images.
Every image in the series is lesser in two times than previous.
The structure is useful for image analysis.
\ref cpp_pyramid_functions.
*/
template <template<class> class A> struct Pyramid
{
typedef A<uint8_t> Allocator; /*!< Allocator type definition. */
/*!
Creates a new empty Pyramid structure.
*/
Pyramid();
/*!
Creates a new Pyramid structure with specified size.
\param [in] size - a size of pyramid's base (lowest and biggest image).
\param [in] levelCount - a number of pyramid levels.
*/
Pyramid(const Point<ptrdiff_t> & size, size_t levelCount);
/*!
Creates a new Pyramid structure with specified size.
\param [in] width - a width of pyramid's base (lowest and biggest image).
\param [in] height - a height of pyramid's base (lowest and biggest image).
\param [in] levelCount - a number of pyramid levels.
*/
Pyramid(size_t width, size_t height, size_t levelCount);
/*!
Re-create a Pyramid structure with specified size.
\param [in] size - a size of pyramid's base (lowest and biggest image).
\param [in] levelCount - a number of pyramid levels.
*/
void Recreate(Point<ptrdiff_t> size, size_t levelCount);
/*!
Re-create a Pyramid structure with specified size.
\param [in] width - a width of pyramid's base (lowest and biggest image).
\param [in] height - a height of pyramid's base (lowest and biggest image).
\param [in] levelCount - a number of pyramid levels.
*/
void Recreate(size_t width, size_t height, size_t levelCount);
/*!
Gets number of levels in the pyramid.
\return - number of levels in the pyramid.
*/
size_t Size() const;
/*!
Gets an image at given level of the pyramid.
\param [in] level - a level of the pyramid.
\return - a reference to the image at given level of the pyramid.
*/
View<A> & operator [] (size_t level);
/*!
Gets an image at given level of the pyramid.
\param [in] level - a level of the pyramid.
\return - a constant reference to the image at given level of the pyramid.
*/
const View<A> & operator [] (size_t level) const;
/*!
Gets an image at given level of the pyramid.
\param [in] level - a level of the pyramid.
\return - a reference to the image at given level of the pyramid.
*/
View<A> & At(size_t level);
/*!
Gets an image at on given level of the pyramid.
\param [in] level - a level of the pyramid.
\return - a constant reference to the image at given level of the pyramid.
*/
const View<A> & At(size_t level) const;
/*!
Gets an image at top level of the pyramid.
\return - a reference to the image at top level of the pyramid.
*/
View<A> & Top();
/*!
Gets an image at top level of the pyramid.
\return - a constant reference to the image at top level of the pyramid.
*/
const View<A> & Top() const;
/*!
Swaps two pyramids.
\param [in] pyramid - other pyramid.
*/
void Swap(Pyramid<A> & pyramid);
private:
std::vector< View<A> > _views;
};
/*! @ingroup cpp_pyramid_functions
\fn Point<ptrdiff_t> Scale(Point<ptrdiff_t> size, int scale = 2);
\short Scales size of an image.
\note This function is useful for Pyramid structure.
\param [in] size - an original image size.
\param [in] scale - a scale. It must be a multiple of 2. By default it is equal to 2.
\return scaled size.
*/
Point<ptrdiff_t> Scale(Point<ptrdiff_t> size, int scale = 2);
//-------------------------------------------------------------------------
// struct Pyramid implementation:
template <template<class> class A>
SIMD_INLINE Pyramid<A>::Pyramid()
{
}
template <template<class> class A>
SIMD_INLINE Pyramid<A>::Pyramid(const Point<ptrdiff_t> & size, size_t levelCount)
{
Recreate(size, levelCount);
}
template <template<class> class A>
SIMD_INLINE Pyramid<A>::Pyramid(size_t width, size_t height, size_t levelCount)
{
Recreate(width, height, levelCount);
}
template <template<class> class A>
SIMD_INLINE void Pyramid<A>::Recreate(Point<ptrdiff_t> size, size_t levelCount)
{
if (_views.size() && size == _views[0].Size())
return;
_views.resize(levelCount);
for (size_t level = 0; level < levelCount; ++level)
{
_views[level].Recreate(size, View<A>::Gray8);
size = Scale(size);
}
}
template <template<class> class A>
SIMD_INLINE void Pyramid<A>::Recreate(size_t width, size_t height, size_t levelCount)
{
Recreate(Point<ptrdiff_t>(width, height), levelCount);
}
template <template<class> class A>
SIMD_INLINE size_t Pyramid<A>::Size() const
{
return _views.size();
}
template <template<class> class A>
SIMD_INLINE View<A> & Pyramid<A>::operator [] (size_t level)
{
return _views[level];
}
template <template<class> class A>
SIMD_INLINE const View<A> & Pyramid<A>::operator [] (size_t level) const
{
return _views[level];
}
template <template<class> class A>
SIMD_INLINE View<A> & Pyramid<A>::At(size_t level)
{
return _views[level];
}
template <template<class> class A>
SIMD_INLINE const View<A> & Pyramid<A>::At(size_t level) const
{
return _views[level];
}
template <template<class> class A>
SIMD_INLINE View<A> & Pyramid<A>::Top()
{
return _views.back();
}
template <template<class> class A>
SIMD_INLINE const View<A> & Pyramid<A>::Top() const
{
return _views.back();
}
template <template<class> class A>
SIMD_INLINE void Pyramid<A>::Swap(Pyramid & pyramid)
{
_views.swap(pyramid._views);
}
// Pyramid utilities implementation:
SIMD_INLINE Point<ptrdiff_t> Scale(Point<ptrdiff_t> size, int scale)
{
while (scale > 1)
{
assert(scale % 2 == 0);
size.x = (size.x + 1) >> 1;
size.y = (size.y + 1) >> 1;
scale >>= 1;
}
return size;
}
}
#endif//__SimdPyramid_hpp__
|