Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/pure-cfg/src/include/Diderot/inline-image.h
ViewVC logotype

View of /branches/pure-cfg/src/include/Diderot/inline-image.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 983 - (download) (as text) (annotate)
Tue Apr 26 16:58:46 2011 UTC (10 years, 3 months ago) by jhr
File size: 3569 byte(s)
  Added partial support for mapping tensors from image space back to world space.
  Still need runtime system support for Hessians (see include/Diderot/inline-image.h)
/*! \file inline-image.h
 *
 * \author John Reppy
 */

/*
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 */

#ifndef _DIDEROT_INLINE_IMAGE_H_
#define _DIDEROT_INLINE_IMAGE_H_

#ifndef _DIDEROT_TYPES_H_
#  include "types.h"
#endif
#ifndef _DIDEROT_INLINE_VEC2_H_
#  include "inline-vec2.h"
#endif
#ifndef _DIDEROT_INLINE_VEC3_H_
#  include "inline-vec3.h"
#endif
#ifndef _DIDEROT_INLINE_VEC4_H_
#  include "inline-vec4.h"
#endif
#ifndef _DIDEROT_INLINE_MATRIX_H_
#  include "inline-matrix.h"
#endif

/***** 1D Image functions *****/

// check if pos is inside the img, assuming that we have a border of width s.
//
STATIC_INLINE bool Inside1f (float pos, Diderot_image1D_t *img, int s)
{
    return ((s-1 < pos) && (pos < (img->size[0] - s)));
}

STATIC_INLINE float ToImageSpace1f (Diderot_image1D_t *img, float pos)
{
    vec2f_t p = __extension__ vec2f(pos, 1.0f);

    return dot2f(img->mInv[0].v, p);
}

/***** 2D Image functions *****/

// check if pos is inside the img, assuming that we have a border of width s.
//
STATIC_INLINE bool Inside2f (vec2f_t posArg, Diderot_image2D_t *img, int s)
{
// NOTE: there might be a vectorized way to do this compare!
// cvtps2pi -- converts vector of floats to vector of int32_t values

    union2f_t pos;
    pos.v = posArg;
    return ((s-1 < pos.r[0]) && (pos.r[0] < (img->size[0] - s))
        &&  (s-1 < pos.r[1]) && (pos.r[1] < (img->size[1] - s)));
}

STATIC_INLINE vec2f_t ToImageSpace2f (Diderot_image2D_t *img, vec2f_t posArg)
{
    vec3f_t p = __extension__ vec3f(
	((union2f_t)posArg).r[0],
	((union2f_t)posArg).r[1],
	1.0f);

    return vec2f(
	dot3f(img->mInv[0].v, p),
	dot3f(img->mInv[1].v, p));
}

STATIC_INLINE vec2f_t ToWorldSpace2f (Diderot_image2D_t *img, vec2f_t gradArg)
{
    vec3f_t g = __extension__ vec3f(
	((union2f_t)gradArg).r[0],
	((union2f_t)gradArg).r[1],
	0.0f);

    return vec2f(
	dot3f(img->mInvT[0].v, g),
	dot3f(img->mInvT[1].v, g));
}

STATIC_INLINE void ToWorldSpace2x2f (Diderot_Mat2x2_t dst, Diderot_image2D_t *img, Diderot_Mat2x2_t src)
{
    copy2x2f(dst, src);  // FIXME: only works for identity transforms
}

/***** 3D Image functions *****/

// check if pos is inside the img, assuming that we have a border of width s.
//
STATIC_INLINE bool Inside3f (vec3f_t posArg, Diderot_image3D_t *img, int s)
{
// NOTE: there might be a vectorized way to do this compare!
// cvtps2pi -- converts vector of floats to vector of int32_t values

    union3f_t pos;
    pos.v = posArg;
    return ((s-1 < pos.r[0]) && (pos.r[0] < (img->size[0] - s))
        &&  (s-1 < pos.r[1]) && (pos.r[1] < (img->size[1] - s))
        &&  (s-1 < pos.r[2]) && (pos.r[2] < (img->size[2] - s)));
}

STATIC_INLINE vec3f_t ToImageSpace3f (Diderot_image3D_t *img, vec3f_t posArg)
{
    vec4f_t p = __extension__ vec4f(
	((union3f_t)posArg).r[0],
	((union3f_t)posArg).r[1],
	((union3f_t)posArg).r[2],
	1.0f);

    return vec3f(
	dot4f(img->mInv[0].v, p),
	dot4f(img->mInv[1].v, p),
	dot4f(img->mInv[2].v, p));
}

STATIC_INLINE vec3f_t ToWorldSpace3f (Diderot_image3D_t *img, vec3f_t gradArg)
{
    vec4f_t g = __extension__ vec4f(
	((union3f_t)gradArg).r[0],
	((union3f_t)gradArg).r[1],
	((union3f_t)gradArg).r[2],
	0.0f);

    return vec3f(
	dot4f(img->mInvT[0].v, g),
	dot4f(img->mInvT[1].v, g),
	dot4f(img->mInvT[2].v, g));
}

STATIC_INLINE void ToWorldSpace3x3f (Diderot_Mat3x3_t dst, Diderot_image3D_t *img, Diderot_Mat3x3_t src)
{
    copy3x3f(dst, src);  // FIXME: only works for identity transforms
}

#endif /* !_DIDEROT_INLINE_IMAGE_H_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0