head	1.12;
access;
symbols
	r0_10:1.12
	Eglin_alpha_1:1.12;
locks; strict;
comment	@// @;


1.12
date	93.05.27.11.19.24;	author thoth;	state Exp;
branches;
next	1.11;

1.11
date	93.05.18.21.38.45;	author thoth;	state Exp;
branches;
next	1.10;

1.10
date	93.04.17.18.44.57;	author thoth;	state Exp;
branches;
next	1.9;

1.9
date	93.04.08.13.05.08;	author thoth;	state Exp;
branches;
next	1.8;

1.8
date	93.03.10.13.31.23;	author thoth;	state Exp;
branches;
next	1.7;

1.7
date	93.02.23.14.04.59;	author thoth;	state Exp;
branches;
next	1.6;

1.6
date	93.02.20.12.28.08;	author thoth;	state Exp;
branches;
next	1.5;

1.5
date	93.02.08.11.31.54;	author thoth;	state Exp;
branches;
next	1.4;

1.4
date	93.01.19.14.55.33;	author jnw;	state Exp;
branches;
next	1.3;

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

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

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


desc
@Initial revision
@


1.12
log
@Copyright Notices
@
text
@// Emacs: -*- C++ -*-

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


// $Log:	BaseDI.h,v $
// Revision 1.11  93/05/18  21:38:45  thoth
// range method returns ValueSet again.
// new value_array method gives an Array of image values.
// 
// 
// Revision 1.10  93/04/17  18:44:57  thoth
// Iterator support is no longer based on a switch statement.  We now
// use a virtual method.  The user can now provide faster iterators.
// 
// Revision 1.9  93/04/08  13:05:08  thoth
// restriction to a pointset and translation by a point are
// now virtual methods.
// 
// Revision 1.8  93/03/10  13:31:23  thoth
// range method no longer returns valueset due to
// difficulties with template implementation.
// 
// Revision 1.7  93/02/23  14:04:59  thoth
// clone_self_extensively and range now have default versions.
// 
// Revision 1.6  93/02/20  12:28:08  thoth
// Refcounting procedures are no longer virtual since we redid the
// ErrorDI mechanism.
// Cleaned up some #if 1s.
// Equality testing does not belong in BaseDI or derived classes.
// 
// Revision 1.5  93/02/08  11:31:54  thoth
// refcount consistency is now enforced.  Derived classes should not worry
// about it any more.
// 
// Revision 1.4  93/01/19  14:55:33  jnw
// Modified to support IA_ naming convention
// 
// Revision 1.3  92/11/14  09:32:47  jnw
// got rid of val and ref and substituted () and [] with int argument
// These may be extraneous (they aren't used right now).  It seems that
// whenever one wants to get at the storage order of a BaseDI, they already
// know what the underlying derived type is.  I'll leave them in however,
// because it's always possible we'll add some new extensive representations.
// 
// Revision 1.2  92/11/13  13:49:29  jnw
// Updated to include all sorts of new goodies
// 
// Revision 1.1  92/10/05  11:43:11  jnw
// Initial revision
// 

#ifndef BaseDI_h_
#define BaseDI_h_

#include <iostream.h>
//#include <stdlib.h>
#include "ia.h"
#include "IntPoint.h"
#include "IntPointSet.h"
#include "ValueSet.h"

typedef const char* const IA_DiscreteImageType;

template <class T> class IA_DiscreteImage;
template <class T> class IA_BaseDIVIter;
template <class T> class IA_BaseDIPIter;


template <class T>
class IA_BaseDI{
protected:
    IA_IntPointSet ps;

    // refcount counts the number of references to this BaseDI object
    //   from DiscreteImage container class objects.
    // It is maintained by container classes.
    int refcount;


public:
    // Constructor for BaseDI takes care of initting the refcount.
    // Derived classes need not frob it.
    // It is the responsibility of the container to maintain the refcount!

    IA_BaseDI(const IA_IntPointSet &p):ps(p) {
	refcount = 0;
    }

    int get_ref() { return refcount; }
    int incr_ref() { return ++refcount; }
    int decr_ref() { return --refcount; }

    // If the following method returns nonzero, then operator[]
    // is meaningful and clone_self_extensively is not necessary
    // unless the image is shared.
    virtual int extensivep() const =0;

    // For the next two functions, we expect our container to trap
    // out-of-bounds points
    virtual T operator ()(const IA_IntPoint &) const =0;

    // This method returns a modifiable reference to a value in the
    // image.  It should not be called for objects that return
    // extensivep()==0.  Modifying through the reference returned
    // alters the image, so make sure the image is not shared.
    virtual T& operator [](const IA_IntPoint &);

    // Each class derived from BaseDI must support the member function
    // type which returns a DiscreteImageType value (a pointer to an int).
    // To distinguish between the different classes derived from BaseDI,
    // we make certain that type will be distinct for each of these classes
    // as follows:
    //	Each class derived from BaseDI defines a static function member dummy:
    //		static int dummy;
    //  The class definition for derived class "classname" must also be
    //	followed by a declaration of form
    //		template <class T> int classname<T>::dummy = 0;
    //	The member function type() in each class derived from BaseDI returns
    //	the address of dummy.
    // Thus each class returns a unique value for a call of type().

    virtual IA_DiscreteImageType type() const = 0;

    virtual ~IA_BaseDI() {};

    // The default version of this is not blazingly fast.
    // If you can do faster in a specific implementation, please do.
    virtual IA_BaseDI* clone_self_extensively() const;

    IA_IntPointSet domain() const { return this->ps; }

    // The default version of this is not blazingly fast.
    // If you can do faster in a specific implementation, please do.
    virtual IA_ValueSet<T> range() const;

    virtual IA_Array<T> value_array() const;

    virtual IA_BaseDI *restricted_to(const IA_IntPointSet &) const;

    virtual IA_BaseDI *xlated_by(const IA_IntPoint &) const;

    virtual IA_BaseDIVIter<T> *value_iterator() const;
    virtual IA_BaseDIPIter<T> *pixel_iterator() const;

    virtual ostream& print_this(ostream&) const = 0;
    
    friend ostream& operator <<(ostream&, const IA_BaseDI<T>&);

    friend class IA_DiscreteImage<T>;
};

template <class T>
ostream& operator <<(ostream&, const IA_BaseDI<T>&);

#endif
@


1.11
log
@range method returns ValueSet again.
new value_array method gives an Array of image values.

@
text
@d3 6
d10 5
@


1.10
log
@Iterator support is no longer based on a switch statement.  We now
use a virtual method.  The user can now provide faster iterators.
@
text
@d4 4
d128 3
a130 1
    virtual T *range(unsigned *n) const;
@


1.9
log
@restriction to a pointset and translation by a point are
now virtual methods.
@
text
@d4 4
d55 2
d129 3
@


1.8
log
@range method no longer returns valueset due to
difficulties with template implementation.
@
text
@d4 4
d50 1
a50 2
template <class T>
class IA_DiscreteImage;
d52 1
d119 4
@


1.7
log
@clone_self_extensively and range now have default versions.
@
text
@d4 3
d114 1
a114 1
    virtual IA_ValueSet<T> range() const;
@


1.6
log
@Refcounting procedures are no longer virtual since we redid the
ErrorDI mechanism.
Cleaned up some #if 1s.
Equality testing does not belong in BaseDI or derived classes.
@
text
@d4 6
a40 6
//enum DiscreteImageType {
//    CONST_DI, VECTOR_DI, FUNCTION_DI, FUNCTION_REF_DI,
//	LAZY_Add_DI, LAZY_Sub_DI, LAZY_Mult_DI, LAZY_Div_DI,
//	LAZY_UnaryMinus_DI,
//    };

d70 3
a72 7
    // extensivep returns true if the image has an extensive valuemap
    // representation.  We do not support any image reprsentations
    // involving an extensive valuemap and a comprehensive pointset.
    //
    // N.B.
    //

d79 4
a84 19
#if 0
    // T& operator[](int) must be supported by extensive derived
    // image types.  It yields a reference to the value of the
    // pixel associated with the ith point in the PointSet iteration
    // order.

    virtual T& operator [](int) {
	ia_throw( IA::IMAGE_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
	return *(new T());
    }
#endif
#if 0
    virtual T operator ()(int) const {
	T val;
	ia_throw( IA::IMAGE_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
	return val;
    }
#endif

d103 3
a105 2
    // provide default based on IPSIter and image::[]
    virtual IA_BaseDI* clone_self_extensively() const = 0;
d107 1
a107 1
    virtual IA_IntPointSet domain() const { return this->ps; }
d109 3
a111 5
    virtual IA_ValueSet<T> range() const {
	// Need to be more specific here!
	ia_throw( IA::INVALID_OPERATION, __FILE__, __LINE__);
	return IA_ValueSet<T>();
    }
@


1.5
log
@refcount consistency is now enforced.  Derived classes should not worry
about it any more.
@
text
@d4 4
d29 1
a29 1
#include <stdlib.h>
d58 3
a61 6
    //IA_BaseDI(): ps() { refcount = 0; } 
    // N.B.
    // Constructor for BaseDI and all its derived classes
    // must leave the refcount at 0.  It is the responsibility of
    // its container to maintain the refcount!

d66 3
a68 3
    virtual int get_ref() { return refcount; }
    virtual int incr_ref() { return ++refcount; }
    virtual int decr_ref() { return --refcount; }
d77 1
a77 9
    virtual int extensivep() const
#if 1
	=0;
#else
	{
	    ia_throw( IA::IMAGE_REQUIRE_VALUE, __FILE__, __LINE__);
	    return 0;
	}
#endif
d79 3
a81 9
    virtual T operator ()(const IA_IntPoint &) const
#if 1
	=0;
#else
	 {
	ia_throw( IA::IMAGE_REQUIRE_VALUE, __FILE__, __LINE__);
	return *(new T());
    }
#endif
d83 1
a83 4
    virtual T& operator [](const IA_IntPoint &) {
	ia_throw( IA::IMAGE_REQUIRE_EXTENSIVE, __FILE__, __LINE__);
	return *(new T());
    }
d85 1
a85 1

d95 1
a95 1

a103 4
    virtual int equal(const IA_BaseDI* other) const {
	return other->ps == this->ps;
    }

d122 1
@


1.4
log
@Modified to support IA_ naming convention
@
text
@d4 3
d55 1
a55 1
    IA_BaseDI(): ps() { refcount = 0; } 
d61 3
a63 1
    IA_BaseDI(const IA_IntPointSet &p) { this->ps = p; refcount = 0; }
a65 1

a66 1

d76 9
a84 4
    virtual int extensivep() const {
	ia_throw( IA::IMAGE_REQUIRE_VALUE, __FILE__, __LINE__);
	return 0;
    }
d86 5
a90 1
    virtual T operator ()(const IA_IntPoint &) const {
d94 1
d112 1
d118 1
d149 1
a149 1
	return *(new IA_ValueSet<T>);
@


1.3
log
@got rid of val and ref and substituted () and [] with int argument
These may be extraneous (they aren't used right now).  It seems that
whenever one wants to get at the storage order of a BaseDI, they already
know what the underlying derived type is.  I'll leave them in however,
because it's always possible we'll add some new extensive representations.
@
text
@d4 7
d34 1
a34 1
typedef const char* const DiscreteImageType;
d37 1
a37 1
class DiscreteImage;
d40 1
a40 1
class BaseDI{
d42 1
a42 1
    IntPointSet ps;
d52 1
a52 1
    BaseDI(): ps() { refcount = 0; } 
d58 1
a58 1
    BaseDI(const IntPointSet &p) { this->ps = p; refcount = 0; }
d78 1
a78 1
    virtual T operator ()(const IntPoint &) const {
d83 1
a83 1
    virtual T& operator [](const IntPoint &) {
d105 1
a105 1
    virtual int equal(const BaseDI* other) const {
d123 1
a123 1
    virtual DiscreteImageType type() const = 0;
d125 1
a125 1
    virtual ~BaseDI() {};
d127 1
a127 1
    virtual BaseDI* clone_self_extensively() const = 0;
d129 1
a129 1
    virtual IntPointSet domain() const { return this->ps; }
d131 1
a131 1
    virtual ValueSet<T> range() const {
d134 1
a134 1
	return *(new ValueSet<T>);
d139 1
a139 1
    friend ostream& operator <<(ostream&, const BaseDI<T>&);
d141 1
a141 1
    friend class DiscreteImage<T>;
d145 1
a145 1
ostream& operator <<(ostream&, const BaseDI<T>&);
@


1.2
log
@Updated to include all sorts of new goodies
@
text
@d4 3
d82 1
a82 1
    // Member function "ref" must be supported by extensive derived
d87 1
a87 1
    virtual T& ref(int) {
d92 1
a92 1
    virtual T val(int) const {
@


1.1
log
@Initial revision
@
text
@d3 4
a6 1
// $Log$
d16 1
a69 2
// try this guy out
	this->extensivep();
a73 1
	abort();
d89 6
d118 8
@
