head	1.2;
access
	monica
	thoth;
symbols;
locks; strict;
comment	@// @;


1.2
date	94.10.26.00.06.28;	author monica;	state Exp;
branches;
next	1.1;

1.1
date	94.02.18.18.41.24;	author thoth;	state Exp;
branches;
next	;


desc
@N-linear interpolation class.
@


1.2
log
@updated types
@
text
@// Emacs: -*- C++ -*-

//
// $Log: BLinterp.h,v $
// Revision 1.1  1994/02/18  18:41:24  thoth
// Initial revision
//

#include	<math.h>

#include "ClosureI.h"
#include "Image.h"

template <class T>
class IA_BLInterp : public IA_ClosureI<IA_Point<double>,T> {
  IA_Image<IA_Point<int> ,T>	im;
 public:
  IA_BLInterp(IA_Image<IA_Point<int> ,T> im_)
    :IA_ClosureI<IA_Point<double>,T>(IA_CWhiteHole(im_.domain().dim())),
    im(im_) {}
  T operator()(const IA_Point<double> &fp) const;
  IA_ClosureI<IA_Point<double>,T> *clone_self() const { return new IA_BLInterp(*this); }
};

template <class T>
T IA_BLInterp<T>::operator() (const IA_Point<double> &fp) const
{
  int 	ncorners = 1<<fp.dim();
  T	*vals = new T[ncorners];
  int	*point = new int[fp.dim()];
  double	*offset = new double[fp.dim()];

  int i;
  for (i=0; i<fp.dim(); i++)
    offset[i] = fp[i] - floor(fp[i]);

  for (i=0; i<ncorners; i++) {
    int	k=i;
    for (int idx=0; idx<fp.dim(); idx++) {
      point[idx] = (int)floor(fp[idx]) + (k&1);
      k >>= 1;
    }
    IA_Point<int> 	p(point, fp.dim());
    vals[i] = im.domain().contains(p)?im(p):0;
  }

  int	k=fp.dim()-1;
  ncorners >>=1;
  while (ncorners) {
    for (i=0; i<ncorners; i++) {
      vals[i] += (vals[i+ncorners] - vals[i])*offset[k];
    }
    ncorners >>=1;
    k--;
  }

  T	rval = vals[0];
  delete[] offset;
  delete[] vals;
  delete[] point;

  return rval;
}
@


1.1
log
@Initial revision
@
text
@d4 4
a7 1
// $Log:	test001.c,v $
d15 2
a16 2
class IA_BLInterp : public IA_ClosureI<IA_FloatPoint,T> {
  IA_Image<IA_IntPoint,T>	im;
d18 2
a19 2
  IA_BLInterp(IA_Image<IA_IntPoint,T> im_)
    :IA_ClosureI<IA_FloatPoint,T>(IA_CWhiteHole(im_.domain().dim())),
d21 2
a22 2
  T operator()(const IA_FloatPoint &fp) const;
  IA_ClosureI<IA_FloatPoint,T> *clone_self() const { return new IA_BLInterp(*this); }
d26 1
a26 1
T IA_BLInterp<T>::operator() (const IA_FloatPoint &fp) const
d43 1
a43 1
    IA_IntPoint	p(point, fp.dim());
@
