2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-22 18:25:01 +00:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class to represent a pyramid of images
|
2012-12-22 18:25:01 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2012-12-22 18:25:01 +00:00
|
|
|
#include "../system/FreestyleConfig.h"
|
|
|
|
|
|
2013-05-13 22:58:27 +00:00
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
# include "MEM_guardedalloc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
class GrayImage;
|
2012-12-22 18:25:01 +00:00
|
|
|
|
2014-04-17 14:19:10 +09:00
|
|
|
class ImagePyramid {
|
2008-04-30 15:41:54 +00:00
|
|
|
protected:
|
2012-12-22 18:25:01 +00:00
|
|
|
std::vector<GrayImage *> _levels;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
public:
|
2023-03-29 16:50:54 +02:00
|
|
|
ImagePyramid() {}
|
2012-12-22 18:25:01 +00:00
|
|
|
ImagePyramid(const ImagePyramid &iBrother);
|
2023-07-25 12:51:50 +10:00
|
|
|
// ImagePyramid(const GrayImage& level0, uint nbLevels);
|
2012-12-22 18:25:01 +00:00
|
|
|
virtual ~ImagePyramid();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Builds the pyramid.
|
2012-12-22 18:25:01 +00:00
|
|
|
* must be overloaded by inherited classes.
|
|
|
|
|
* if nbLevels==0, the complete pyramid is built
|
|
|
|
|
*/
|
2023-07-25 12:51:50 +10:00
|
|
|
virtual void BuildPyramid(const GrayImage &level0, uint nbLevels) = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Builds a pyramid without copying the base level */
|
2023-07-25 12:51:50 +10:00
|
|
|
virtual void BuildPyramid(GrayImage *level0, uint nbLevels) = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-07 23:17:23 +00:00
|
|
|
virtual GrayImage *getLevel(int l);
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Returns the pixel x,y using bilinear interpolation.
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param x:
|
2012-12-22 18:25:01 +00:00
|
|
|
* the abscissa specified in the finest level coordinate system
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param y:
|
2012-12-22 18:25:01 +00:00
|
|
|
* the ordinate specified in the finest level coordinate system
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param level:
|
2012-12-22 18:25:01 +00:00
|
|
|
* the level from which we want the pixel to be evaluated
|
|
|
|
|
*/
|
|
|
|
|
virtual float pixel(int x, int y, int level = 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Returns the width of the level-th level image */
|
2012-12-22 18:25:01 +00:00
|
|
|
virtual int width(int level = 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Returns the height of the level-th level image */
|
2012-12-22 18:25:01 +00:00
|
|
|
virtual int height(int level = 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:57:33 +10:00
|
|
|
/** Returns the number of levels in the pyramid */
|
2012-12-22 18:25:01 +00:00
|
|
|
inline int getNumberOfLevels() const
|
|
|
|
|
{
|
|
|
|
|
return _levels.size();
|
|
|
|
|
}
|
2013-05-13 22:58:27 +00:00
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ImagePyramid")
|
|
|
|
|
#endif
|
2012-12-22 18:25:01 +00:00
|
|
|
};
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2014-04-17 14:19:10 +09:00
|
|
|
class GaussianPyramid : public ImagePyramid {
|
2008-04-30 15:41:54 +00:00
|
|
|
protected:
|
2012-12-22 18:25:01 +00:00
|
|
|
float _sigma;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
public:
|
2020-11-06 11:25:27 +11:00
|
|
|
GaussianPyramid(float iSigma = 1.0f) : ImagePyramid()
|
2012-12-22 18:25:01 +00:00
|
|
|
{
|
|
|
|
|
_sigma = iSigma;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 12:51:50 +10:00
|
|
|
GaussianPyramid(const GrayImage &level0, uint nbLevels, float iSigma = 1.0f);
|
|
|
|
|
GaussianPyramid(GrayImage *level0, uint nbLevels, float iSigma = 1.0f);
|
2012-12-22 18:25:01 +00:00
|
|
|
GaussianPyramid(const GaussianPyramid &iBrother);
|
2023-03-29 16:50:54 +02:00
|
|
|
virtual ~GaussianPyramid() {}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 12:51:50 +10:00
|
|
|
virtual void BuildPyramid(const GrayImage &level0, uint nbLevels);
|
|
|
|
|
virtual void BuildPyramid(GrayImage *level0, uint nbLevels);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-22 18:25:01 +00:00
|
|
|
/* accessors */
|
|
|
|
|
inline float getSigma() const
|
|
|
|
|
{
|
|
|
|
|
return _sigma;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-22 18:25:01 +00:00
|
|
|
/* modifiers */
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
2012-12-22 18:25:01 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|