head	1.4;
access;
symbols
	bobbase:1.4
	bob:1.4.1
	r2_1:1.4
	C_8:1.4
	r2_0:1.4
	r1_1_beta:1.4
	r1_1_alpha:1.4
	r1_0:1.4
	r0_11:1.4
	r0_10:1.3
	r0_9:1.2;
locks; strict;
comment	@// @;


1.4
date	94.03.14.15.48.33;	author thoth;	state Exp;
branches
	1.4.1.1;
next	1.3;

1.3
date	93.12.29.17.03.16;	author thoth;	state Exp;
branches;
next	1.2;

1.2
date	93.11.17.18.10.45;	author thoth;	state Exp;
branches;
next	1.1;

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

1.4.1.1
date	94.12.28.15.40.44;	author thoth;	state Exp;
branches;
next	;


desc
@Base image implementation.
@


1.4
log
@ValueSet has been replaced by container class Set.
@
text
@// Emacs: -*- C++ -*-

//
//	Copyright 1993, Center for Computer Vision and Visualization,
//	University of Florida.  All rights reserved.
//


//
// $Log: BaseI.c,v $
// Revision 1.3  1993/12/29  17:03:16  thoth
// Improved error handling.
//
// Revision 1.2  1993/11/17  18:10:45  thoth
// IPSIter is now PSIter<IntPoint>
// LazyXlationI is in a separate .c file now.
// The default iterators are now in a separate file.
//
// Revision 1.1  1993/09/15  12:50:14  thoth
// Initial revision
//

#include "PSIter.h"
#include "BaseI.h"
//#include "OtherIIter.h"
#include "VectorI.h"
#include "BaseImageIter.h"


template < class P,class T>
T& IA_BaseImage<P,T>::operator[](const P&)
{
    ia_throw( IA::IMAGE_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
    IA::internal_error(__FILE__,__LINE__);
    return *(T*)0;
}

template < class P,class T>
IA_BaseImage<P,T>* IA_BaseImage<P,T>::clone_self_extensively() const
{
    // This will throw if the pointset is comprehensive, but
    // we can\'t clone extensively if our domain is comprehensive.
    const unsigned sz = ps.card();

    // We will build a VectorI
    T *const dest = new T[sz];

    {
	// Iterate over the domain.
	IA_PSIter<P>	iter(ps);
	// For each point
	P	ip;
	T *scan = dest;

	while (iter(ip))
	    // evaluate the image at that point and place it in the
	    // proper slot of the vector.
	    *(scan++) = (*this)(ip);
    }

    // Build a VectorI and give away the value vector.
    return new IA_VectorI<P,T>(ps, dest, sz, 1);
}

#if 1
template < class P,class T>
IA_Set<T> IA_BaseImage<P,T>::range() const
{
    // This will throw if the pointset is comprehensive, but
    // we can\'t compute the range if our domain is comprehensive.
    const unsigned sz = ps.card();

    // We will build a vector of values
    T *const dest = new T[sz];

    {
	// Iterate over the domain.
	IA_PSIter<P>	iter(ps);
	// For each point
	P	ip;
	T *scan = dest;

	while (iter(ip))
	    // evaluate the image at that point and place it in the vector.
	    *(scan++) = (*this)(ip);
    }

    IA_Set<T>	rval(dest, sz);
    delete[] dest;

    return rval;
}
#else
template < class P,class T>
T* IA_BaseImage<P,T>::range(unsigned *sz) const
{
    // This will throw if the pointset is comprehensive, but
    // we can\'t compute the range if our domain is comprehensive.
    *sz = ps.card();

    // We will build a vector of values
    T *const dest = new T[*sz];

    {
	// Iterate over the domain.
	IA_PSIter<P>	iter(ps);
	// For each point
	P	ip;
	T *scan = dest;

	while (iter(ip))
	    // evaluate the image at that point and place it in the vector.
	    *(scan++) = (*this)(ip);
    }

    return dest;
}
#endif

template < class P,class T>
IA_Array<T> IA_BaseImage<P,T>::value_array() const
{
    // This will throw if the pointset is comprehensive, but
    // we can\'t compute the value_array if our domain is comprehensive.
    const unsigned sz = ps.card();

    // We will build a vector of values
    T *const dest = new T[sz];

    {
	// Iterate over the domain.
	IA_PSIter<P>	iter(ps);
	// For each point
	P	ip;
	T *scan = dest;

	while (iter(ip))
	    // evaluate the image at that point and place it in the vector.
	    *(scan++) = (*this)(ip);
    }

    return IA_Array<T>(dest, sz, 1);
}


//
// restriction.  We have a LOT of problems with CFront
//

#include "restrict.h"

template <class P, class T>
IA_BaseImage<IA_Point<int>,T> *IA_BaseImage<P,T>::restricted_to(const IA_Set<IA_Point<int> > &ips) const
{
    return restrict_toD(this, ips);
}

template <class P, class T>
IA_BaseImage<P,T> *IA_BaseImage<P,T>::restricted_to(const IA_Set<IA_Point<double> > &/*fps*/) const
{
    return 0;			// NYI
}


//
//
//

#include "LazyXlationI.h"

template < class P,class T>
IA_BaseImage<P,T> *IA_BaseImage<P,T>::xlated_by(const P &p) const
{
    return new IA_LazyXlationI<P,T>(this, p);
}

//
//  iterator support below
//

#include "OtherImageIter.h"

template < class P,class T>
IA_BaseIVIter<P,T> *IA_BaseImage<P,T>::value_iterator() const
{
    return new IA_OtherIVIter<P,T>(this);
}

template < class P,class T>
IA_BaseIPIter<P,T> *IA_BaseImage<P,T>::pixel_iterator() const
{
    return new IA_OtherIPIter<P,T>(this);
}

//
//
//

template < class P,class T>
ostream& operator<<(ostream& o, const IA_BaseImage<P,T>& bdi)
{
    o << "**Image**\n";
    bdi.print_this(o);
    return o << "\n******************\n" ;
}

@


1.4.1.1
log
@Conversion to classes for throw.
new reflection method
@
text
@a10 3
// Revision 1.4  1994/03/14  15:48:33  thoth
// ValueSet has been replaced by container class Set.
//
d28 1
a28 1
#include "image_errors.h"
d33 1
a33 1
    ia_throw( Image_RequireExtensive_Exception(__FILE__, __LINE__));
a174 12
}

//
//

#include "LazyImage.h"

template < class P,class T>
IA_BaseImage<P,T> *IA_BaseImage<P,T>::reflection() const
{
    // cast away const
    return new IA_LazyReflectionImage<P,T>((IA_BaseImage<P,T>*)this);
@


1.3
log
@Improved error handling.
@
text
@d11 3
d67 1
a67 1
IA_ValueSet<T> IA_BaseImage<P,T>::range() const
d88 1
a88 1
    IA_ValueSet<T>	rval(dest, sz);
@


1.2
log
@IPSIter is now PSIter<IntPoint>
LazyXlationI is in a separate .c file now.
The default iterators are now in a separate file.
@
text
@d11 5
d31 1
a31 1
    abort(); // internal error
@


1.1
log
@Initial revision
@
text
@d10 4
a13 1
// $Log:	BaseDI.c,v $
d15 1
a15 1
#include "IPSIter.h"
d153 1
a153 1
    return 0;
d161 1
a161 33
template < class P,class T>
class IA_LazyXlationI: public IA_BaseImage<P,T> {
  private:
    static char	dummy;

    const P	offset;
    IA_BaseImage<P,T>	* base;
  public:
    IA_LazyXlationI(const IA_BaseImage<P,T> *base_, P offset_)
    :IA_BaseImage<P,T>(base_->domain() + offset_), offset(offset_),
     base((IA_BaseImage<P,T>*)base_) {
	base->incr_ref();
    }
    ~IA_LazyXlationI() {
	if (base->decr_ref()<=0)
	    delete base;
    }
    int extensivep() const { return 0; }
    T operator() (const P &p) const {
	return (*base)(p-offset);
    }
    IA_ImageType type() const { return &dummy; }
    IA_BaseImage<P,T> * xlated_by(const P &p) const {
	return new IA_LazyXlationI<P,T>(base, p+offset);
    }
    ostream& print_this(ostream&o) const {
	o<< "translation by " << offset << " of \n";
	return base->print_this(o);
    }
};

template < class P,class T>
char IA_LazyXlationI<P,T>::dummy;
d170 1
a170 1
// Value iterator support below
d173 1
a173 36

template < class P,class T>
class IA_OtherIVIter: public IA_BaseIVIter<P,T> {
  protected:
    // iterator over the domain
    IA_PSIter<P>	iter;

  public:
    IA_OtherIVIter(const IA_BaseImage<P,T> *);
    IA_OtherIVIter(const IA_OtherIVIter &);

    IA_BaseIVIter<P,T> * clone_self() { return new IA_OtherIVIter<P,T>(*this);}
    int next(T&);

    void reset() { iter.reset(); }
};


template < class P,class T>
IA_OtherIVIter<P,T>::IA_OtherIVIter(const IA_BaseImage<P,T>* img)
     :IA_BaseIVIter<P,T>(img), iter(img->domain()) { }


template < class P,class T>
IA_OtherIVIter<P,T>::IA_OtherIVIter(const IA_OtherIVIter<P,T>& iter)
     :IA_BaseIVIter<P,T>(iter.domain), iter(iter.iter) { }

template < class P,class T>
int IA_OtherIVIter<P,T>::next(T &v)
{
  P	ip;
  if (!iter(ip))
    return 0;
  v = (*domain)(ip);
  return 1;
}
a178 42
}

//
//

//
// Pixel iterator support below
//

template < class P,class T>
class IA_OtherIPIter: public IA_BaseIPIter<P,T> {
  protected:
    // iterator over the domain
    IA_PSIter<P>	iter;

  public:
    IA_OtherIPIter(const IA_BaseImage<P,T> *);
    IA_OtherIPIter(const IA_OtherIPIter &);

    IA_BaseIPIter<P,T> * clone_self() { return new IA_OtherIPIter<P,T>(*this);}
    int next(P&, T&);

    void reset() { iter.reset(); }
};


template < class P,class T>
IA_OtherIPIter<P,T>::IA_OtherIPIter(const IA_BaseImage<P,T>* img)
     :IA_BaseIPIter<P,T>(img), iter(img->domain()) { }


template < class P,class T>
IA_OtherIPIter<P,T>::IA_OtherIPIter(const IA_OtherIPIter<P,T>& iter)
     :IA_BaseIPIter<P,T>(iter.domain), iter(iter.iter) { }

template < class P,class T>
int IA_OtherIPIter<P,T>::next(P &ip, T &v)
{
  if (!iter(ip))
    return 0;
  v = (*domain)(ip);
  return 1;
@
