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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3075 - (download) (as text) (annotate)
Mon Mar 16 15:28:50 2015 UTC (4 years, 6 months ago) by jhr
File size: 6494 byte(s)
  bug fixing for border control
/*! \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

// Utility function for clamping an image index
STATIC_INLINE int __IndexClamp (int size, int idx)
{
    return (idx < 0) ? 0 : (idx < size) ? idx : (size-1);
}

// Utility function for mirroring an image index
STATIC_INLINE int __IndexMirror (int size, int idx)
{
    if (idx < 0) {
	idx = -1 - idx;
    }
    if (idx < size)
	return idx;
  // here size <= idx
    int div = idx / size;
    int rem = idx - size * div;
    return (div & 1) ? (size - 1) - rem : rem;
}

// Utility function for wrapping an image index
STATIC_INLINE int __IndexWrap (int size, int idx)
{
    if (idx < 0) {
	return (size - 1) + (idx + 1) % size;
    }
    else if (idx < size) {
	return idx;
    }
    else {
	return idx % size;
    }
}


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

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

STATIC_INLINE int IndexClamp1 (Diderot_image1D_t *img, int dim, int idx)
{
    return __IndexClamp (img->size[0], idx);
}

STATIC_INLINE int IndexMirror1 (Diderot_image1D_t *img, int dim, int idx)
{
    return __IndexMirror (img->size[0], idx);
}

STATIC_INLINE int IndexWrap1 (Diderot_image1D_t *img, int dim, int idx)
{
    return __IndexWrap (img->size[0], idx);
}

STATIC_INLINE Diderot_real_t ToImageSpace1 (Diderot_image1D_t *img, Diderot_real_t pos)
{
    return img->s * pos + img->t;
}


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

// check if pos is inside the img, assuming that we have a border of width s.
//
STATIC_INLINE bool Inside2 (Diderot_vec2_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

    Diderot_union2_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 int IndexClamp2 (Diderot_image2D_t *img, int dim, int idx)
{
    return __IndexClamp (img->size[dim], idx);
}

STATIC_INLINE int IndexMirror2 (Diderot_image2D_t *img, int dim, int idx)
{
    return __IndexMirror (img->size[dim], idx);
}

STATIC_INLINE int IndexWrap2 (Diderot_image2D_t *img, int dim, int idx)
{
    return __IndexWrap (img->size[dim], idx);
}

STATIC_INLINE Diderot_vec2_t ToImageSpace2 (Diderot_image2D_t *img, Diderot_vec2_t p)
{
    return vec2(dot2(img->w2i[0].v, p), dot2(img->w2i[1].v, p)) + img->tVec;
}

STATIC_INLINE Diderot_vec2_t ToWorldSpace2 (Diderot_image2D_t *img, Diderot_vec2_t g)
{
    return vec2(
	dot2(img->w2iT[0].v, g),
	dot2(img->w2iT[1].v, g));
}

STATIC_INLINE void ToWorldSpace2x2 (Diderot_Mat2x2_t dst, Diderot_image2D_t *img, Diderot_Mat2x2_t src)
{
    Diderot_Mat2x2_t tmp;
    mulMat2x2Mat2x2 (tmp, img->w2iT, src);
    mulMat2x2Mat2x2 (dst, tmp, img->w2i);
}

STATIC_INLINE void ToWorldSpace2x2x2 (Diderot_Ten2x2x2_t dst, Diderot_image2D_t *img, Diderot_Ten2x2x2_t src)
{
#define PROD(m,n,p)     img->w2i[i].r[m] * img->w2i[j].r[n] * img->w2i[k].r[p] * src[m][n].r[p]

    for (int i = 0;  i < 2;  i++) {
        for (int j = 0;  j < 2;  j++) {
            for (int k = 0;  k < 2;  k++) {
                dst[i][j].r[k] =
                    PROD(0,0,0) + PROD(0,0,1) + PROD(0,1,0) + PROD(0,1,1) +
                    PROD(1,0,0) + PROD(1,0,1) + PROD(1,1,0) + PROD(1,1,1);
            }
        }
    }

#undef PROD
}


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

// check if pos is inside the img, assuming that we have a border of width s.
//
STATIC_INLINE bool Inside3 (Diderot_vec3_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

    Diderot_union3_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 int IndexClamp3 (Diderot_image3D_t *img, int dim, int idx)
{
    return __IndexClamp (img->size[dim], idx);
}

STATIC_INLINE int IndexMirror3 (Diderot_image3D_t *img, int dim, int idx)
{
    return __IndexMirror (img->size[dim], idx);
}

STATIC_INLINE int IndexWrap3 (Diderot_image3D_t *img, int dim, int idx)
{
    return __IndexWrap (img->size[dim], idx);
}

STATIC_INLINE Diderot_vec3_t ToImageSpace3 (Diderot_image3D_t *img, Diderot_vec3_t p)
{
    return vec3(dot3(img->w2i[0].v, p), dot3(img->w2i[1].v, p), dot3(img->w2i[2].v, p)) + img->tVec;
}

STATIC_INLINE Diderot_vec3_t ToWorldSpace3 (Diderot_image3D_t *img, Diderot_vec3_t g)
{
    return vec3(
	dot3(img->w2iT[0].v, g),
	dot3(img->w2iT[1].v, g),
	dot3(img->w2iT[2].v, g));
}

STATIC_INLINE void ToWorldSpace3x3 (Diderot_Mat3x3_t dst, Diderot_image3D_t *img, Diderot_Mat3x3_t src)
{
    Diderot_Mat3x3_t tmp;
    mulMat3x3Mat3x3 (tmp, img->w2iT, src);
    mulMat3x3Mat3x3 (dst, tmp, img->w2i);
}

STATIC_INLINE void ToWorldSpace3x3x3 (Diderot_Ten3x3x3_t dst, Diderot_image3D_t *img, Diderot_Ten3x3x3_t src)
{
#define PROD(m,n,p)     img->w2i[i].r[m] * img->w2i[j].r[n] * img->w2i[k].r[p] * src[m][n].r[p]

    for (int i = 0;  i < 3;  i++) {
        for (int j = 0;  j < 3;  j++) {
            for (int k = 0;  k < 3;  k++) {
                dst[i][j].r[k] =
                    PROD(0,0,0) + PROD(0,0,1) + PROD(0,0,2) +
		    PROD(0,1,0) + PROD(0,1,1) + PROD(0,1,2) +
		    PROD(0,2,0) + PROD(0,2,1) + PROD(0,2,2) +
                    PROD(1,0,0) + PROD(1,0,1) + PROD(1,0,2) +
		    PROD(1,1,0) + PROD(1,1,1) + PROD(1,1,2) +
		    PROD(1,2,0) + PROD(1,2,1) + PROD(1,2,2) +
                    PROD(2,0,0) + PROD(2,0,1) + PROD(2,0,2) +
		    PROD(2,1,0) + PROD(2,1,1) + PROD(2,1,2) +
		    PROD(2,2,0) + PROD(2,2,1) + PROD(2,2,2);
            }
        }
    }

#undef PROD
}

#endif /* !_DIDEROT_INLINE_IMAGE_H_ */

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