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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1685 - (download) (as text) (annotate)
Sun Jan 22 15:23:36 2012 UTC (7 years, 4 months ago) by jhr
Original Path: branches/vis12/src/include/Diderot/cl-inline-image.h
File size: 4628 byte(s)
  Create a branch to implement things that we need for the Vis 2012 paper
/*! \file cl-inline-image.h
 *
 * \author Lamont Samuels
 */

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

#ifndef _DIDEROT_CL_INLINE_IMAGE_H_
#define _DIDEROT_CL_INLINE_IMAGE_H_
 
#ifndef _DIDEROT_CL_TYPES_H_
#  include "cl-types.h"
#endif
#ifndef _DIDEROT_CL_INLINE_MATRIX_H_
#  include "cl-inline-matrix.h"
#endif


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

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

inline float ToImageSpace1f ( __global Diderot_image1D_t *img, float 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.
//
inline bool Inside2f (float2 posArg, __global Diderot_image2D_t *img, int s)
{
    return ((s-1 < posArg.s0) && (posArg.s0 < (img->size[0] - s))
        &&  (s-1 < posArg.s1) && (posArg.s1 < (img->size[1] - s)));
}

inline float2 ToImageSpace2f (__global Diderot_image2D_t *img, float2 p)
{
    return (float2)(dot(img->w2i[0], p), dot(img->w2i[1], p)) + img->tVec;
}

inline float2 ToWorldSpace2f (__global Diderot_image2D_t *img, float2 g)
{
    return (float2)(
        dot(img->w2iT[0], g),
        dot(img->w2iT[1], g));
}

inline void ToWorldSpace2x2f ( Diderot_Mat2x2_t dst, __global Diderot_image2D_t *img,  Diderot_Mat2x2_t src)
{
    /* Diderot_Mat2x2_t tmp;
    mulMat2x2Mat2x2f (tmp, img->w2iT, src);
    mulMat2x2Mat2x2f (dst, tmp, img->w2i); */ 
    
    Diderot_Mat2x2_t tmp;
    
    tmp[0] = (float2)(
        dot(img->w2iT[0], (float2)(src[0].s0, src[1].s0)),
        dot(img->w2iT[0], (float2)(src[0].s1, src[1].s1)));
    tmp[1] = (float2)(
        dot(img->w2iT[1], (float2)(src[0].s0, src[1].s0)),
        dot(img->w2iT[1], (float2)(src[0].s1, src[1].s1)));
    
    dst[0] = (float2)(
        dot(tmp[0], (float2)(img->w2i[0].s0, img->w2i[1].s0)),
        dot(tmp[0], (float2)(img->w2i[0].s1, img->w2i[1].s1)));
    dst[1] = (float2)(
        dot(tmp[1], (float2)(img->w2i[0].s0, img->w2i[1].s0)),
        dot(tmp[1], (float2)(img->w2i[0].s1, img->w2i[1].s1)));

}

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

// check if pos is inside the img, assuming that we have a border of width s.
//
inline bool Inside3f (float3 posArg, __global Diderot_image3D_t *img, int s)
{
    return ((s-1 < posArg.s0) && (posArg.s0 < (img->size[0] - s))
        &&  (s-1 < posArg.s1) && (posArg.s1 < (img->size[1] - s))
        &&  (s-1 < posArg.s2) && (posArg.s2 < (img->size[2] - s)));
}

inline float3 ToImageSpace3f (__global Diderot_image3D_t *img, float3 p)
{
    return VEC3(dot(img->w2i[0], p), dot(img->w2i[1], p), dot(img->w2i[2], p)) + img->tVec;
}

inline float3 ToWorldSpace3f (__global Diderot_image3D_t *img, float3 g)
{
    return VEC3(
        dot(img->w2iT[0], g),
        dot(img->w2iT[1], g),
        dot(img->w2iT[2], g));
}

inline void ToWorldSpace3x3f ( Diderot_Mat3x3_t dst, __global Diderot_image3D_t *img,  Diderot_Mat3x3_t src)
{
    Diderot_Mat3x3_t tmp;
    
    tmp[0] = VEC3(
          dot(img->w2iT[0], VEC3(src[0].s0, src[1].s0, src[2].s0)),
          dot(img->w2iT[0], VEC3(src[0].s1, src[1].s1, src[2].s1)),
          dot(img->w2iT[0], VEC3(src[0].s2, src[1].s2, src[2].s2)));
    tmp[1] = VEC3(
          dot(img->w2iT[1], VEC3(src[0].s0, src[1].s0, src[2].s0)),
          dot(img->w2iT[1], VEC3(src[0].s1, src[1].s1, src[2].s1)),
          dot(img->w2iT[1], VEC3(src[0].s2, src[1].s2, src[2].s2)));
    tmp[2] = VEC3(
          dot(img->w2iT[2], VEC3(src[0].s0, src[1].s0, src[2].s0)),
          dot(img->w2iT[2], VEC3(src[0].s1, src[1].s1, src[2].s1)),
          dot(img->w2iT[2], VEC3(src[0].s2, src[1].s2, src[2].s2)));
    
    dst[0] = VEC3(
          dot(tmp[0], VEC3(img->w2i[0].s0, img->w2i[1].s0, img->w2i[2].s0)),
          dot(tmp[0], VEC3(img->w2i[0].s1, img->w2i[1].s1, img->w2i[2].s1)),
          dot(tmp[0], VEC3(img->w2i[0].s2, img->w2i[1].s2, img->w2i[2].s2)));
    dst[1] = VEC3(
          dot(tmp[1], VEC3(img->w2i[0].s0, img->w2i[1].s0, img->w2i[2].s0)),
          dot(tmp[1], VEC3(img->w2i[0].s1, img->w2i[1].s1, img->w2i[2].s1)),
          dot(tmp[1], VEC3(img->w2i[0].s2, img->w2i[1].s2, img->w2i[2].s2)));
    dst[2] = VEC3(
          dot(tmp[2], VEC3(img->w2i[0].s0, img->w2i[1].s0, img->w2i[2].s0)),
          dot(tmp[2], VEC3(img->w2i[0].s1, img->w2i[1].s1, img->w2i[2].s1)),
          dot(tmp[2], VEC3(img->w2i[0].s2, img->w2i[1].s2, img->w2i[2].s2)));

}

#endif /* !_DIDEROT_CL_INLINE_IMAGE_H_ */
 

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