head     1.3;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @@;


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

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

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


desc
@Created to match ArithDI.m4c and BitwiseDI.m4c in style
@


1.3
log
@a ' within a comment confused m4
@
text
@// Emacs: -*- C++ -*-

static char LatticeDIrcsid[] = "$Id: LatticeDI.m4c,v 1.2 93/01/19 14:56:33 jnw Exp Locker: thoth $";

// $Log:	LatticeDI.m4c,v $
Revision 1.2  93/01/19  14:56:33  jnw
Modified to support IA_ naming convention

Revision 1.1  92/11/12  17:00:20  jnw
Initial revision


#include <stream.h>
#include "ia.h"
#include "DiscreteImage.h"
#include "LatticeDI.h"
#include "IPSIter.h"

define(`LAZY_NONCOMMUTATIVE_LATTICE_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)));

	}


	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(`REL_OPS',`
       template <class T>
       int $2<T>::operator $1 (const IA_DiscreteImage<T>& arg)
       {
	   if ( this->domain() != arg.domain() ) {
	       ia_throw( IA::PSET_MISMATCH, __FILE__, __LINE__);
	       return 0;
	   }
	   if (!this->extensivep() && !arg.extensivep()) {
	       // Cant return a result!
	       ia_throw( IA::IMAGE_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
	       return 0;
	   } else if (!this->extensivep() || !arg.extensivep()) {
	       IA_IPSIter iter(this->domain());
	       IA_IntPoint p;

	       while(iter(p)) {
		   if ((*(this->bdip))(p) $2 (*(arg.bdip))(p))
		       return $5;
	       }
	       
	   } else {
	       for (int i=0; i < this->domain().card(); i++) {
		   if (this->bdip->ref(i) $2 arg.bdip->ref(i))
		       return $5;
	       }
	   }
	   return $4;
       }
    
       template <class T>
       int $2<T>::operator $1 (const T& arg)
       {
	   int result = 0;
	   
	   if ( this->domain() != arg.domain() ) {
	       ia_throw( IA::PSET_MISMATCH, __FILE__, __LINE__);
	       return 0;
	   }
	   if (!this->extensivep()) {
	       IA_IPSIter iter(this->domain());
	       IA_IntPoint p;
	       
	       while(iter(p)) {
		   if ((*(this->bdip))(p) $2 arg)
		       return $5;
	       }
	       
	   } else {
	       for (int i=0; i < this->domain().card(); i++) {
		   if (this->bdip->ref(i) $2 arg)
		       return $5;
	       }
	   }
	   return $4;
       }
    
       template <class T>
       int operator $1 (const T& scalar, const IA_DiscreteImage<T>& image)
       {
	   return image $1 scalar;
       }')


define(`LATTICE_OPS',`
       template <class T>
       IA_DiscreteImage<T>
       $3<T>::$2(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.
	       
	       return (IA_DiscreteImage<T> *) new IA_Lazy$2DI<T>( *this, arg);

	   } else {
	       IA_DiscreteImage<T> result(this->domain);
	       
	       for (int i=0; i < this->domain().card(); i++) {
		   result->ref(i) = this->bdip->ref(i) $1 arg.bdip->ref(i));
	       }
	       return result;
	   }
       }

    
       template <class T>
       IA_DiscreteImage<T>
       $3<T>::$2 (const T& arg)
       {
	   if (!this->extensivep()) {
	       
	       // Need to construct a Lazy result.
	       
	       return (IA_DiscreteImage<T> *) new
 			    IA_Lazy$2DI<T>(*this, IA_DiscreteImage<T>(
                                                    arg,this->domain()));
	   } else {
	       IA_DiscreteImage<T> result(this->domain);
	       
	       for (int i=0; i < this->domain().card(); i++) {
		   result->ref(i) = this->bdip->ref(i) $1 arg;
	       }
	       return result;
	   }
       }
    
       template <class T>
       IA_DiscreteImage<T> operator $2 (const T& scalar,
				        const IA_DiscreteImage<T>& image)
       {
	   
	   return image $1 scalar;
       }')


LAZY_NONCOMMUTATIVE_LATTICE_CLASS(<,Min,IA_LatticeDI)
LAZY_NONCOMMUTATIVE_LATTICE_CLASS(>,Max,IA_LatticeDI)


divert(-1)
# Usage: REL_OPS( operator symbol of created operation,
#		  operator symbol of reference relation,
#		  ClassName to which this operator belongs,
#		  value to return if the reference relation is not satisfied
#			at all points
#		  value to return if the reference relation IS satisfied
#		   	at some point
divert

REL_OPS(<,>=,IA_LatticeDI,1,0)
REL_OPS(<=,>,IA_LatticeDI,1,0)
REL_OPS(>,<=,IA_LatticeDI,1,0)
REL_OPS(>=,<,IA_LatticeDI,1,0)
REL_OPS(==,!=,IA_LatticeDI,1,0)
REL_OPS(!=,!=,IA_LatticeDI,0,1)

LATTICE_OPS(<,Min,IA_LatticeDI)
LATTICE_OPS(>,Max,IA_LatticeDI)
@


1.2
log
@Modified to support IA_ naming convention
@
text
@d3 1
a3 1
static char LatticeDIrcsid[] = "$Id: LatticeDI.m4c,v 1.1 92/11/12 17:00:20 jnw Exp Locker: jnw $";
d6 3
d96 1
a96 1
	       // Can\'t return a result!
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
static char LatticeDIrcsid[] = "$Id$";
d5 3
a7 1
// $Log$
d9 1
d18 1
a18 1
	int Lazy$2DI<T>::equal(const BaseDI<T>* other) const
d20 2
a21 2
	    Lazy$2DI<T> * ot = (Lazy$2DI<T> *)other;
	    return (((BaseDI<T> *)this)->equal(other)
d30 1
a30 1
	T Lazy$2DI<T>::operator ()(const IntPoint& p) const {
d37 2
a38 2
        BaseDI<T>*
	Lazy$2DI<T>::clone_self_extensively() const
d47 2
a48 2
		IPSIter iter(this->ps);
		IntPoint p;
d56 2
a57 2
                return (BaseDI<T> *) new
			VectorDI<T>(vec, this->ps,
d65 1
a65 1
	ostream& Lazy$2DI<T>::print_this(ostream& o) const
d69 2
a70 2
		IPSIter iter(this->ps);
		IntPoint p;
d86 1
a86 1
       int $2<T>::operator $1 (const DiscreteImage<T>& arg)
d97 2
a98 2
	       IPSIter iter(this->domain());
	       IntPoint p;
d124 2
a125 2
	       IPSIter iter(this->domain());
	       IntPoint p;
d142 1
a142 1
       int operator $1 (const T& scalar, const DiscreteImage<T>& image)
d150 2
a151 2
       DiscreteImage<T>
       $3<T>::$2(const DiscreteImage<T>& arg)
d161 1
a161 1
	       return (DiscreteImage<T> *) new Lazy$2DI<T>( *this, arg);
d164 1
a164 1
	       DiscreteImage<T> result(this->domain);
d175 1
a175 1
       DiscreteImage<T>
d182 3
a184 3
	       return (DiscreteImage<T> *) new
 			    Lazy$2DI<T>(*this,
		 	                DiscreteImage<T>(arg,this->domain()));
d186 1
a186 1
	       DiscreteImage<T> result(this->domain);
d196 2
a197 2
       DiscreteImage<T> operator $2 (const T& scalar,
				     const DiscreteImage<T>& image)
d204 2
a205 2
LAZY_NONCOMMUTATIVE_LATTICE_CLASS(<,Min,LatticeDI)
LAZY_NONCOMMUTATIVE_LATTICE_CLASS(>,Max,LatticeDI)
d218 6
a223 6
REL_OPS(<,>=,LatticeDI,1,0)
REL_OPS(<=,>,LatticeDI,1,0)
REL_OPS(>,<=,LatticeDI,1,0)
REL_OPS(>=,<,LatticeDI,1,0)
REL_OPS(==,!=,LatticeDI,1,0)
REL_OPS(!=,!=,LatticeDI,0,1)
d225 2
a226 2
LATTICE_OPS(<,Min,LatticeDI)
LATTICE_OPS(>,Max,LatticeDI)
@
