head     1.4;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @// @;


1.4
date     93.02.17.11.05.41;  author thoth;  state Exp;
branches ;
next     1.3;

1.3
date     93.01.19.14.56.49;  author jnw;  state Exp;
branches ;
next     1.2;

1.2
date     92.11.12.17.00.47;  author jnw;  state Exp;
branches ;
next     1.1;

1.1
date     92.10.05.11.46.46;  author jnw;  state Exp;
branches ;
next     ;


desc
@Initial revision
@


1.4
log
@fixed some typos.
repaired some anachronisms.
it still doesn't work.
@
text
@// Emacs: -*- C++ -*-
divert(-1)
#
# This is a set of m4 macros and defines for turning ArithDI.C.m4
# into the files ArithDI.C
#
# usage: "/local/gnu/m4 arithdefines.m4 ArithDI.C.m4 \
#			>ArithDI.C
#
# There are some gotchas using m4, however!  If the program text (or this file)
# uses m4 predefined macro keywords,  they must be quoted -- here's the list:
#
# `builtin'	`changecom'	`changequote'	`debugfile'	`debugmode'	`decr'
# `define'	`defn'		`divert'	`divnum'	`dnl'		`dumpdef'
# `errprint'	`esyscmd'	`eval'		`file'		`format'	`ifdef'
# `ifelse'	`include'	`incr'		`index'		`indir'		`len'
# `line'	`m4exit'	`m4wrap'	`maketemp'	`patsubst'	`popdef'
# `pushdef'	`regexp'	`shift'		`sinclude'	`substr'	`syscmd'
# `sysval'	`traceoff'	`traceon'	`translit'	`undefine'	`undivert'
#
# Fischer wrote eloquent information about m4 here.  I'd direct you to
# the defines.m4 in the point subdirectory of this distribution, or better
# yet to Fischer himself:
#
#	G.R. Fischer, 615NW 31st Pl, Gainesville, FL 32607 904/375-7015
#
divert
define(`LAZY_COMMUTATIVE_CLASS',`
	template <class T>
	int IA_Lazy$2DI<T>::equal(const IA_BaseDI<T>* other) const
	{
	    IA_Lazy$2DI<T> * ot = (IA_Lazy$2DI<T> *)other;
	    return (((IA_BaseDI<T> *)this)->equal(other)
		    && this->type()==other->type()
		    && (((this->left_op == ot->left_op) &&
			 (this->right_op == ot->right_op))
			|| ((this->left_op == ot->right_op) &&
			    (this->right_op == ot->left_op))));
	}
REST_LAZY($1, $2)')

define(`LAZY_NONCOMMUTATIVE_CLASS',`
	template <class T>
	int IA_Lazy$2DI<T>::equal(const IA_BaseDI<T>* other) const
	{
	    IA_Lazy$2DI<T> * ot = (IA_Lazy$2DI<T> *)other;
	    return (((IA_BaseDI<T> *)this)->equal(other)
		    && this->type()==other->type()
		    && ((this->left_op == ot->left_op) &&
			 (this->right_op == ot->right_op)));

	}
REST_LAZY($1, $2)')

define(`REST_LAZY',`
	template <class T>
	T IA_Lazy$2DI<T>::operator ()(const IA_IntPoint& p) const {
	       if(!this->ps.contains(p))
		   ia_throw( IA::IMAGE_DOMAIN_ERROR, __FILE__, __LINE__);
	       return this->left_op(p) $1 this->right_op(p);
	}

	template <class T>
        IA_BaseDI<T>*
	IA_Lazy$2DI<T>::clone_self_extensively() const
	{
	    if (this->ps.extensivep()) {
		// Create an extensive version of this image and return
		// a pointer to the referenced element.

		T *vec;
		vec = new T[this->ps.card()];

		IA_IPSIter iter(this->ps);
		IA_IntPoint p;
	
		// We assume that IntPointSet iteration order == storage order
	
		int i = 0;
		while (iter(p)) {
		     vec[i++] = this->left_op(p) $1 this->right_op(p);
	        }
                return (IA_BaseDI<T> *) new
			IA_VectorDI<T>(vec, this->ps,
				       this->ps.card(), 0);
	    } else {
		ia_throw(  IA::PSET_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
	    }
	}
	
	template <class T>
	ostream& IA_Lazy$2DI<T>::print_this(ostream& o) const
	{
	    o << "Lazy$2DI -";
	    if (this->ps.extensivep()){
		IA_IPSIter iter(this->ps);
		IA_IntPoint p;
		o << "(point,value) pairs follow:\n";
		while(iter(p)) {
		    o << "(" << p << ", " <<
			this->left_op(p) $1 this->right_op(p) << ") ";
		}
	    } else {
		o << "PointSet : Comprehensive";
	    }
	    return o << "\n";
	}')


define(`LAZY_UNARY_CLASS',`
template <class T>
IA_BaseDI<T>* IA_Lazy$2DI<T>::clone_self_extensively() const
{
    if (this->ps.extensivep()) {
	// Create an extensive version of this image and return
	// a pointer to the referenced element.
	IA_BaseDI<T>* result = (IA_BaseDI<T> *) new IA_VectorDI<T>(this->ps);
	IA_IPSIter iter(this->ps);
	IA_IntPoint p;
	
	// We assume that IntPointSet iteration order == storage order
	
	int i = 0;
	while (iter(p)) {
	    result->operator[](i++) = $1 this->op(p);
	}
	return result;
    } else {
	ia_throw(  IA::PSET_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
    }
}


template <class T>
T IA_Lazy$2DI<T>::operator ()(const IA_IntPoint& p) const
{
    if(!this->ps.contains(p))
	ia_throw(IA::IMAGE_DOMAIN_ERROR, __FILE__, __LINE__);
    return $1 this->op(p);
}

template <class T>
int IA_Lazy$2DI<T>::equal(const IA_BaseDI<T>* other) const
{
    IA_Lazy$2DI<T> * ot = (IA_Lazy$2DI<T> *)other;
    return (((IA_BaseDI<T> *)this)->equal(other)
	    && this->type()==other->type()
	    && ((this->op == ot->op)));
}

template <class T>
ostream& IA_Lazy$2DI<T>::print_this(ostream& o) const
{
    o << "Lazy$2DI -";
    if (this->ps.extensivep()){
	IA_IPSIter iter(this->ps);
	IA_IntPoint p;
	o << "(point,value) pairs follow:\n";
	while(iter(p)) {
	    o << "(" << p << ", " <<
		$1 this->op(p) << ") ";
	}
    } else {
	o << "PointSet : Comprehensive";
    }
    return o << "\n";
}')



define(`OPS',`
       template <class T>
       IA_DiscreteImage<T>&
       $3<T>::operator $1= (const IA_DiscreteImage<T>& arg)
       {
	   if ( this->domain() != arg.domain() ) {
	       ia_throw( IA::PSET_MISMATCH, __FILE__, __LINE__);
	       return *this;
	   }
	   if (!this->extensivep() || !arg.extensivep()) {
	       
	       // Need to construct a Lazy result.
	       
	       IA_BaseDI<T> *result;
	       
	       result = (IA_BaseDI<T> *) new IA_Lazy$2DI<T>( *this, arg);
	       this->disassociate_image();
	       *this = $3<T>(result);
	   } else {
	       for (int i=0; i < this->domain().card(); i++) {
		   this->bdip->operator[](i) $1= arg.bdip->operator[](i);
	       }
	   }
	   return *this;
       }
    
       template <class T>
       IA_DiscreteImage<T>&
       $3<T>::operator $1= (const T& arg)
       {
	   if (!this->extensivep()) {
	       
	       // Need to construct a Lazy result.
	       
	       IA_BaseDI<T> *result;
	       
	       result = (IA_BaseDI<T> *) new
 			    IA_Lazy$2DI<T>(*this, IA_DiscreteImage<T>(
                                                    arg,this->domain()));
	       this->disassociate_image();
	       *this = $3<T>(result);
	   } else {
	       for (int i=0; i < this->domain().card(); i++) {
		   this->bdip->operator[](i) $1= arg;
	       }
	   }
	   return *this;
       }
    
       template <class T>
       IA_DiscreteImage<T>
       $3<T>::operator $1 (const IA_DiscreteImage<T>& right)
       {
	   $3<T> result = *this;
	   
	   return result $1= right;
       }

       template <class T>
       IA_DiscreteImage<T> operator $1 (const T& scalar,
				        const IA_DiscreteImage<T>& image)
       {
	   $3<T> result = image;
	   
	   return result $1= scalar;
       }

       template <class T>
       IA_DiscreteImage<T> operator $1 (const IA_DiscreteImage<T>& image,
				        const T& scalar)
       {
	   $3<T> result = image;
	   
	   return result $1= scalar;
       }')


define(`UNARY_OP',`
template <class T>
IA_DiscreteImage<T> $3<T>::operator $1 () const
{
    IA_BaseDI<T> *result;
	
    if (!this->extensivep()) {
	
	// Need to construct a Lazy result.
	
	result = new IA_Lazy$2DI<T>( *this);
    } else {
	T *vec;
	vec = new T[this->domain().card()];
	for (int i=0; i < this->domain().card(); i++) {
	    vec[i] = $1 this->bdip->operator[](i);
	}
	result = new
		IA_VectorDI<T>(vec, this->domain(), this->domain().card(), 0);
    }
    return $3<T>(result);
}')


@


1.3
log
@Modified to support IA_ naming convention
@
text
@d46 1
a46 1
	    IA_Lazy$2DI<T> * ot = IA_(Lazy$2DI<T> *)other;
d125 1
a125 1
	    result->ref(i++) = $1 this->op(p);
d145 1
a145 1
    IA_Lazy$2DI<T> * ot = IA_(Lazy$2DI<T> *)other;
d191 1
a191 1
		   this->bdip->ref(i) $1= arg.bdip->ref(i);
d214 1
a214 1
		   this->bdip->ref(i) $1= arg;
d224 1
a224 1
	   IA_DiscreteImage<T> result = this;
d250 1
a250 1
$3<T> $3<T>::operator $1 () const
d263 1
a263 1
	    vec[i] = $1 this->bdip->ref(i);
@


1.2
log
@Modified to incorporate use by Bitwise and Lattice
@
text
@d30 1
a30 1
	int Lazy$2DI<T>::equal(const BaseDI<T>* other) const
d32 2
a33 2
	    Lazy$2DI<T> * ot = (Lazy$2DI<T> *)other;
	    return (((BaseDI<T> *)this)->equal(other)
d44 1
a44 1
	int Lazy$2DI<T>::equal(const BaseDI<T>* other) const
d46 2
a47 2
	    Lazy$2DI<T> * ot = (Lazy$2DI<T> *)other;
	    return (((BaseDI<T> *)this)->equal(other)
d57 1
a57 1
	T Lazy$2DI<T>::operator ()(const IntPoint& p) const {
d64 2
a65 2
        BaseDI<T>*
	Lazy$2DI<T>::clone_self_extensively() const
d74 2
a75 2
		IPSIter iter(this->ps);
		IntPoint p;
d83 3
a85 3
                return (BaseDI<T> *) new
			VectorDI<T>(vec, this->ps,
				    this->ps.card(), 0);
d92 1
a92 1
	ostream& Lazy$2DI<T>::print_this(ostream& o) const
d96 2
a97 2
		IPSIter iter(this->ps);
		IntPoint p;
d112 1
a112 1
BaseDI<T>* Lazy$2DI<T>::clone_self_extensively() const
d117 3
a119 3
	BaseDI<T>* result = (BaseDI<T> *) new VectorDI<T>(this->ps);
	IPSIter iter(this->ps);
	IntPoint p;
d135 1
a135 1
T Lazy$2DI<T>::operator ()(const IntPoint& p) const
d143 1
a143 1
int Lazy$2DI<T>::equal(const BaseDI<T>* other) const
d145 2
a146 2
    Lazy$2DI<T> * ot = (Lazy$2DI<T> *)other;
    return (((BaseDI<T> *)this)->equal(other)
d152 1
a152 1
ostream& Lazy$2DI<T>::print_this(ostream& o) const
d156 2
a157 2
	IPSIter iter(this->ps);
	IntPoint p;
d173 2
a174 2
       DiscreteImage<T>&
       $3<T>::operator $1= (const DiscreteImage<T>& arg)
d184 1
a184 1
	       BaseDI<T> *result;
d186 1
a186 1
	       result = (BaseDI<T> *) new Lazy$2DI<T>( *this, arg);
d198 1
a198 1
       DiscreteImage<T>&
d205 1
a205 1
	       BaseDI<T> *result;
d207 3
a209 3
	       result = (BaseDI<T> *) new
 			    Lazy$2DI<T>(*this,
		 	                DiscreteImage<T>(arg,this->domain()));
d221 2
a222 2
       DiscreteImage<T>
       $3<T>::operator $1 (const DiscreteImage<T>& right)
d224 1
a224 1
	   DiscreteImage<T> result = this;
d230 2
a231 2
       DiscreteImage<T> operator $1 (const T& scalar,
				     const DiscreteImage<T>& image)
d239 2
a240 2
       DiscreteImage<T> operator $1 (const DiscreteImage<T>& image,
				     const T& scalar)
d252 1
a252 1
    BaseDI<T> *result;
d258 1
a258 1
	result = new Lazy$2DI<T>( *this);
d266 1
a266 1
		VectorDI<T>(vec, this->domain(), this->domain().card(), 0);
@


1.1
log
@Initial revision
@
text
@a170 1

d173 2
a174 2
       $3<T>&
       $3<T>::operator $1= (const $3<T>& arg)
d198 1
a198 1
       $3<T>&
d221 2
a222 1
       $3<T> operator $1 (const $3<T>& left, const $3<T>& right)
d224 1
a224 1
	   $3<T> result = left;
d230 2
a231 1
       $3<T> operator $1 (const T& left, const $3<T>& right)
d233 1
a233 1
	   $3<T> result = right;
d235 1
a235 1
	   return result $1= left;
d239 2
a240 1
       $3<T> operator $1 (const $3<T>& left, const T& right)
d242 1
a242 1
	   $3<T> result = left;
d244 1
a244 1
	   return result $1= right;
d270 1
@
