14 #include "../geometry/Geom.h"
16 #include "../image/Image.h"
17 #include "../image/ImagePyramid.h"
31 _nbOrientations = nbOrientations;
32 _bound =
cos(
M_PI / (
float)_nbOrientations);
33 for (
unsigned int i = 0; i < _nbOrientations; ++i) {
34 _directions.emplace_back(
cos((
float)i *
M_PI / (
float)_nbOrientations),
35 sin((
float)i *
M_PI / (
float)_nbOrientations));
44 memset((_imagesPyramids), 0, (_nbOrientations + 1) *
sizeof(
ImagePyramid *));
56 for (i = 0; i <= _nbOrientations; ++i) {
70 if (_imagesPyramids) {
71 for (i = 0; i <= _nbOrientations; ++i) {
72 if (_imagesPyramids[i]) {
73 delete (_imagesPyramids)[i];
76 delete[] _imagesPyramids;
77 _imagesPyramids =
nullptr;
79 if (!_mapping.empty()) {
80 for (map<unsigned int, double *>::iterator m = _mapping.begin(), mend = _mapping.end();
97 double dotp =
fabs(dir * _directions[i]);
105 return cos((
float)_nbOrientations / 2.0 *
acos(dotp));
112 map<unsigned int, double *>::iterator o = _mapping.find(
id);
113 if (o != _mapping.end()) {
116 double *res =
new double[_nbOrientations];
117 for (i = 0; i < _nbOrientations; ++i) {
121 Vec2r o2d2(o2d3.
x(), o2d3.
y());
128 for (i = 0; i < _nbOrientations; ++i) {
129 res[i] = ComputeWeight(o2d2, i);
140 return _nbOrientations + 1;
144 unsigned winner = _nbOrientations + 1;
145 for (
unsigned int i = 0; i < _nbOrientations; ++i) {
146 double w = ComputeWeight(dir, i);
157 map<unsigned int, double *>::iterator o = _mapping.find(
id);
158 if (o != _mapping.end()) {
159 double *wvalues = (*o).second;
161 unsigned winner = _nbOrientations + 1;
162 for (
unsigned i = 0; i < _nbOrientations; ++i) {
163 double w = wvalues[i];
171 return _nbOrientations + 1;
179 for (
unsigned int i = 0; i <= _nbOrientations; ++i) {
188 _imagesPyramids[i] = svm;
197 cout <<
"Warning: this steerable ViewMap level doesn't exist" << endl;
201 if ((
x < 0) || (
x >= pyramid->
width()) || (
y < 0) || (
y >= pyramid->
height())) {
209 float v = pyramid->
pixel(
x, pyramid->
height() - 1 -
y, iLevel) / 32.0f;
215 return readSteerableViewMapPixel(_nbOrientations, iLevel,
x,
y);
220 if (_imagesPyramids[0]) {
221 return _imagesPyramids[0]->getNumberOfLevels();
228 for (
unsigned int i = 0; i <= _nbOrientations; ++i) {
229 if (_imagesPyramids[i] ==
nullptr) {
230 cerr <<
"SteerableViewMap warning: orientation " << i
231 <<
" of steerable View Map whas not been computed yet" << endl;
234 int ow = _imagesPyramids[i]->width(0);
235 int oh = _imagesPyramids[i]->height(0);
238 string base(
"SteerableViewMap");
239 stringstream filename;
241 for (
int j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) {
245 int rowbytes = ow * 4;
248 for (
int y = 0;
y < oh; ++
y) {
249 for (
int x = 0;
x < ow; ++
x) {
250 int c = (int)(coeff * _imagesPyramids[i]->pixel(
x,
y, j));
257 pix = (
char *)ibuf->
rect +
y * rowbytes +
x * 4;
258 pix[0] = pix[1] = pix[2] =
c;
264 filename << i <<
"-" << j <<
".png";
266 IMB_saveiff(ibuf,
const_cast<char *
>(filename.str().c_str()), 0);
269 QString base(
"SteerableViewMap");
270 for (
unsigned j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) {
271 GrayImage *img = _imagesPyramids[i]->getLevel(j);
272 int ow = img->
width();
275 QImage qtmp(ow, oh, 32);
276 for (
unsigned int y = 0;
y < oh; ++
y) {
277 for (
unsigned int x = 0;
x < ow; ++
x) {
278 int c = (int)(coeff * img->
pixel(
x,
y));
283 qtmp.setPixel(
x,
y, qRgb(
c,
c,
c));
286 qtmp.save(base + QString::number(i) +
"-" + QString::number(j) +
".png",
"PNG");
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
Contains defines and structs used throughout the imbuf module.
Classes to define a silhouette structure.
Convenient access to the steerable ViewMap to which any element of the ViewMap belongs to.
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Vec3r orientation2d() const
float pixel(unsigned x, unsigned y) const
virtual float pixel(int x, int y, int level=0)
virtual int height(int level=0)
virtual int width(int level=0)
float readSteerableViewMapPixel(unsigned iOrientation, int iLevel, int x, int y)
unsigned getSVMNumber(Vec2f dir)
double * AddFEdge(FEdge *iFEdge)
float readCompleteViewMapPixel(int iLevel, int x, int y)
void buildImagesPyramids(GrayImage **steerableBases, bool copy=false, unsigned iNbLevels=4, float iSigma=1.0f)
SteerableViewMap(unsigned int nbOrientations=4)
double ComputeWeight(const Vec2d &dir, unsigned iNOrientation)
unsigned int getNumberOfPyramidLevels() const
vector< Vec2d > _directions
map< unsigned int, double * > _mapping
virtual ~SteerableViewMap()
void saveSteerableViewMap() const
ImagePyramid ** _imagesPyramids
ccl_device_inline float2 fabs(const float2 &a)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)