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


1.14
date	93.06.10.17.24.02;	author thoth;	state Exp;
branches;
next	1.13;

1.13
date	93.05.27.11.19.40;	author thoth;	state Exp;
branches;
next	1.12;

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

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

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

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

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

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

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

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

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

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

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

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


desc
@Initial revision
@


1.14
log
@Workaround for 3.0.1 bug.
@
text
@// Emacs: -*- C++ -*-

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


// $Log:	DiscreteImage.h,v $
// Revision 1.13  93/05/27  11:19:40  thoth
// Copyright Notices
// 
// Revision 1.12  93/05/26  17:00:18  thoth
// Read and write of IAA image files.
// 
// Revision 1.11  93/05/18  21:39:51  thoth
// New Point-Point composition closure object.
// New value_array method gives an Array of image values.
// New value-value composition functions.
// 
// Revision 1.10  93/04/29  11:19:18  thoth
// Support for point-point-function and image composition.
// Support for fast vector boxy extension in convolution.
// 
// Revision 1.9  93/04/08  13:11:46  thoth
// restriction is now a virtual method of the BaseDI.
// image translation is now available.
// 
// Revision 1.8  93/03/10  13:34:38  thoth
// range method no longer returns valueset due to
// difficulties with template implementation.
// FunctionDI constructor was not truly generic.
// 
// Revision 1.7  93/02/23  14:17:20  thoth
// set_and_reference_image method encodes common initialization semantics.
// User-defined OtherDIs are now supported.
// FunctionRef images are now supported for quick-hacks.
// 
// Revision 1.6  93/02/20  15:10:06  thoth
// errorDI is used differently now.
// The pointset should go first in an image constructor.
// Function images are no longer supported.
// Image restriction and extension have been revamped.
// 
// Revision 1.5  93/02/17  11:00:48  thoth
// We now have the ability to give away the value vector.
// restriction and extension are no longer operators.  They are methods.
// 
// Revision 1.4  93/02/08  12:58:19  thoth
// The user does not need to know about ErrorDI.
// 
// Revision 1.3  93/01/19  14:56:05  jnw
// Modified to support IA_ naming convention
// 
// Revision 1.2  92/11/13  13:50:02  jnw
// Updated to include all sorts of new goodies
// 
// Revision 1.1  92/10/05  11:42:52  jnw
// Initial revision
// 

#ifndef DiscreteImage_h_
#define DiscreteImage_h_

#include <stream.h>
#include "ia.h"
#include "IntPoint.h"
#include "IntPointSet.h"

#include "BaseDI.h"

template <class T> class IA_ValueSet;

template <class T> class IA_DIVIter;
template <class T> class IA_DIPIter;

#if 0
template <class T> class IA_OtherDI;
#else
#include "OtherDI.h"
#endif

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


template <class T>
class IA_DiscreteImage {
protected:

    // INVARIANT:  bdip has a value in every image.  The uninitialized
    //		   value is errorDI.
    IA_BaseDI<T> *bdip;

    // Places a valid value in bdip and refcounts appropriately.
    void set_and_reference_image(IA_BaseDI<T> *i);

    // Decrement the BaseDI\'s refcount and delete if necessary.
    void disassociate_image();

    // no one else should be tossing BaseDIs around
    IA_DiscreteImage(IA_BaseDI<T> *base) {
	set_and_reference_image(base);
    }

public:
    IA_DiscreteImage();

    // copy constructor
    IA_DiscreteImage(const IA_DiscreteImage&);

    // const image constructor
    IA_DiscreteImage(const IA_IntPointSet&, const T&);

    // vector image constructor
    IA_DiscreteImage(const IA_IntPointSet&, T *, unsigned, int giveaway);
    IA_DiscreteImage(const IA_IntPointSet&, const T *, unsigned);
    IA_DiscreteImage(const IA_OtherDI<T>& i);
    IA_DiscreteImage(const IA_IntPointSet&, T (*)(const IA_IntPoint&));

    virtual ~IA_DiscreteImage();

    IA_DiscreteImage& operator =(const IA_DiscreteImage &);

    // keep the domain, but make all values the same
    IA_DiscreteImage& operator =(const T&);

    // what sort of image is this?
    IA_DiscreteImageType type() const { return bdip->type(); }

    // retrieve a value from the image
    T operator ()(const IA_IntPoint& p) const {
	if (!domain().contains(p)) {
	    abort();		// throw
	}
	return (*this->bdip)(p);
    }

    // retrieve a reference to a value in the image
    T& operator [](const IA_IntPoint&);

    IA_DiscreteImage restrict( const IA_IntPointSet&) const;
    IA_DiscreteImage restrict( const IA_ValueSet<T>&) const;
    // the next one looks gratuitous --thoth
    //IA_DiscreteImage restrict( int (*)(const IA_IntPoint&)) const;

    // Image Extension -- NOT ASSOCIATIVE!!!
  private:
#define FUNKY_ERROR
    static void vec_vec_2_vec_structcopy (const T **lhs_data,
					  const T **rhs_data,
					  T **dest, const IA_SetStructure &ss);
    static void vec_iter_2_vec_structcopy(const T **lhs_data,
#ifdef FUNKY_ERROR
					  void *rhs_iter,
#else
					  IA_DIVIter<T> *rhs_iter,
#endif
					  T **dest,
					  const IA_SetStructure &ss);
    static void iter_vec_2_vec_structcopy( //
#ifdef FUNKY_ERROR
					   void *lhs_iter,
#else
					   IA_DIVIter<T> *lhs_iter,
#endif
					   const T **rhs_data,
					   T **dest,
					   const IA_SetStructure &ss);
    static void iter_iter_2_vec_structcopy( //
#ifdef FUNKY_ERROR
					    void *lhs_iter,
					    void *rhs_iter,
#else
					    IA_DIVIter<T> *lhs_iter,
					    IA_DIVIter<T> *rhs_iter,
#endif
					    T **dest,
					    const IA_SetStructure &ss);
  public:
    IA_DiscreteImage extend( const IA_DiscreteImage&) const;

    IA_DiscreteImage xlated( const IA_IntPoint &) const;

    IA_IntPointSet domain() const { return this->bdip->domain(); }
    
    IA_ValueSet<T> range() const;
    IA_Array<T> value_array() const { return this->bdip->value_array(); }

    int card() const { return this->domain().card(); }

    int extensivep() const { return this->bdip->extensivep(); }

    T reduce(T (*)(const T&, const T&),T) const;

    T reduce(T (*) (T, T), T) const;

    friend ostream& operator <<(ostream&, const IA_DiscreteImage<T>&);

    static IA_DiscreteImage read_IAA(istream &header, istream &values);
    static IA_DiscreteImage read_IAA(const char *fname1,
				     const char *fname2);
    static IA_DiscreteImage read_IAA(const char *fname);

    void write_IAA(ostream &header, ostream &values) const;

    void write_IAA(const char *fname1, const char *fname2) const;
    void write_IAA(const char *fname) const;

    friend class IA_DIVIter<T>;
    friend class IA_DIPIter<T>;

    friend zero_extend(const IA_DiscreteImage<T> &, const IA_IntPointSet&,
		       T*, T);
};

#include "PPComp.h"

template <class T>
IA_DiscreteImage<T> compose
(const IA_DiscreteImage<T>&,
 const IA_PPCompClosure<IA_IntPoint, IA_IntPoint> &);

template <class T>
IA_DiscreteImage<T> compose(const IA_DiscreteImage<T>&,
			    IA_IntPoint (*)(const IA_IntPoint&));

template <class T>
IA_DiscreteImage<T> compose(T (*)(T), const IA_DiscreteImage<T> &);

template <class S, class T>
IA_DiscreteImage<S> compose(S (*)(T), const IA_DiscreteImage<T> &, const S*);

template <class R, class S, class T>
IA_DiscreteImage<R> compose(R (*)(S), const IA_DiscreteImage<T> &, const R*, const S*);

template <class Q, class R, class S, class T>
IA_DiscreteImage<Q> compose(R (*)(S), const IA_DiscreteImage<T> &, const Q*, const R*, const S*);

#endif
@


1.13
log
@Copyright Notices
@
text
@d10 3
d77 1
d79 3
@


1.12
log
@Read and write of IAA image files.
@
text
@d3 6
d10 3
@


1.11
log
@New Point-Point composition closure object.
New value_array method gives an Array of image values.
New value-value composition functions.
@
text
@d4 5
d184 10
d215 1
a215 1
template <class S,class T>
d217 6
@


1.10
log
@Support for point-point-function and image composition.
Support for fast vector boxy extension in convolution.
@
text
@d4 4
d167 1
d186 2
d189 5
d196 6
@


1.9
log
@restriction is now a virtual method of the BaseDI.
image translation is now available.
@
text
@d4 4
d54 1
a55 1
template <class T> class IA_DIPIter;
d177 2
a178 2
    friend IA_DiscreteImage<T> gcon_inv(const IA_DiscreteImage<T> &img,
					const IA_DiscreteImage<T> &invtempl);
d180 4
@


1.8
log
@range method no longer returns valueset due to
difficulties with template implementation.
FunctionDI constructor was not truly generic.
@
text
@d4 5
a112 15
#define FUNKY_ERROR
    // Image Restriction -- NOT ASSOCIATIVE!!!
  private:
    // there are problems if the following two are not members.
    static void vec_2_vec_structcopy(const T** source_vec, T** dest_vec, 
				     const IA_SetStructure &ss);
    static void iter_2_vec_structcopy(
#ifdef FUNKY_ERROR
	void *source_iter,
#else
	IA_DIVIter<T> *source_iter,
#endif
				      T** result_vec, 
				      const IA_SetStructure &ss);
  public:
d120 1
d153 2
@


1.7
log
@set_and_reference_image method encodes common initialization semantics.
User-defined OtherDIs are now supported.
FunctionRef images are now supported for quick-hacks.
@
text
@d4 5
d85 1
a85 1
    IA_DiscreteImage(const IA_IntPointSet&, int (*)(const IA_IntPoint&));
d165 1
a165 1
    IA_ValueSet<T> range() const { return this->bdip->range(); }
d179 3
@


1.6
log
@errorDI is used differently now.
The pointset should go first in an image constructor.
Function images are no longer supported.
Image restriction and extension have been revamped.
@
text
@d4 6
d42 1
d45 4
d56 4
a59 1
    void set_and_reference_image();
a60 1
    // Removes the current heap storage associated with *this.
d64 1
a64 1
	base->incr_ref(); this->bdip = base;
d79 3
a81 5
#if 0
    // two function image constructors
    IA_DiscreteImage(T (*)(const IA_IntPoint&), const IA_IntPointSet&);
    IA_DiscreteImage(T (*)(IA_IntPoint), const IA_IntPointSet&);
#endif
d170 1
a170 1
    friend ostream& operator <<(ostream&, IA_DiscreteImage<T>);
@


1.5
log
@We now have the ability to give away the value vector.
restriction and extension are no longer operators.  They are methods.
@
text
@d4 4
d28 1
a36 2
template <class T> class IA_ErrorDI;

d38 1
a38 1
class IA_DiscreteImage{
d45 1
a48 2
    static IA_ErrorDI<T> errorDI;

d55 1
a55 1
    IA_DiscreteImage() { this->bdip = (IA_BaseDI<T> *) &errorDI; }
d61 1
a61 1
    IA_DiscreteImage(const T&, const IA_IntPointSet&);
d64 3
a66 3
    IA_DiscreteImage(T *, const IA_IntPointSet&, unsigned, int giveaway);
    IA_DiscreteImage(T *, const IA_IntPointSet&, unsigned);

d70 1
a70 1

d82 6
a87 1
    T operator ()(const IA_IntPoint& p) const { return (*this->bdip)(p); }
d92 1
d94 15
a108 1
    IA_DiscreteImage& restrict( const IA_IntPointSet&) const;
d110 1
a110 2
    IA_DiscreteImage& restrict( int (*)(const IA_IntPoint&)) const;
    IA_DiscreteImage& restrict( const IA_ValueSet<T>&) const;
d113 33
a145 1
    IA_DiscreteImage& extend( const IA_DiscreteImage&) const;
a146 1
    // should change reference to bdip data member to function!
@


1.4
log
@The user does not need to know about ErrorDI.
@
text
@d4 3
d62 2
a63 1
    IA_DiscreteImage(T *, const IA_IntPointSet&, int);
d76 2
a77 4
    int operator ==(const IA_DiscreteImage &im) const { 
	// This is a first cut.  Fix!!!!
	return this->bdip->equal( im.bdip);
    }
d86 1
a86 1
    IA_DiscreteImage& operator &( const IA_IntPointSet&) const;
d88 2
a89 2
    IA_DiscreteImage& operator &( int (*)(const IA_IntPoint&)) const;
    IA_DiscreteImage& operator &( const IA_ValueSet<T>&) const;
d92 1
a92 1
    IA_DiscreteImage& operator |( const IA_DiscreteImage&) const;
@


1.3
log
@Modified to support IA_ naming convention
@
text
@d4 3
a21 1
#include "ErrorDI.h"
d23 1
a23 2
template <class T>
class IA_ValueSet;
d25 1
a25 2
template <class T>
class IA_DIVIter;
d27 1
a27 2
template <class T>
class IA_DIPIter;
d29 2
a42 2
public:
    IA_DiscreteImage() { this->bdip = (IA_BaseDI<T> *) &errorDI; }
d44 1
d49 4
d55 1
d58 1
d61 1
a62 1

d65 1
a65 1
    virtual ~IA_DiscreteImage(){ this->disassociate_image(); }
d69 1
d77 1
d80 1
d85 1
a85 1

a86 1

@


1.2
log
@Updated to include all sorts of new goodies
@
text
@d4 3
d22 1
a22 1
class ValueSet;
d25 1
a25 1
class DIVIter;
d28 1
a28 1
class DIPIter;
d31 1
a31 1
class DiscreteImage{
d36 1
a36 1
    BaseDI<T> *bdip;
d41 1
a41 1
    static ErrorDI<T> errorDI;
d43 1
a43 1
    DiscreteImage() { this->bdip = (BaseDI<T> *) &errorDI; }
d45 3
a47 1
    DiscreteImage(BaseDI<T> *base) { base->incr_ref(); this->bdip = base; }
d49 1
a49 1
    DiscreteImage(const DiscreteImage&);
d51 1
a51 1
    DiscreteImage(const T&, const IntPointSet&);
d53 1
a53 1
    DiscreteImage(T *, const IntPointSet&, int);
d55 1
a55 1
    DiscreteImage(T (*)(const IntPoint&), const IntPointSet&);
d57 1
a57 1
    DiscreteImage(T (*)(IntPoint), const IntPointSet&);
d59 1
a59 1
    virtual ~DiscreteImage(){ this->disassociate_image(); }
d61 1
a61 1
    DiscreteImage& operator =(const DiscreteImage &);
d63 1
a63 1
    DiscreteImage& operator =(const T&);
d65 1
a65 1
    int operator ==(const DiscreteImage &im) const { 
d70 1
a70 1
    T operator ()(const IntPoint& p) const { return (*this->bdip)(p); }
d72 1
a72 1
    T& operator [](const IntPoint&);
d75 1
a75 1
    DiscreteImage& operator &( const IntPointSet&) const;
d77 1
a77 1
    DiscreteImage& operator &( int (*)(const IntPoint&)) const;
d79 1
a79 1
    DiscreteImage& operator &( const ValueSet<T>&) const;
d82 1
a82 1
    DiscreteImage& operator |( const DiscreteImage&) const;
d85 1
a85 1
    IntPointSet domain() const { return this->bdip->domain(); }
d87 1
a87 1
    ValueSet<T> range() const { return this->bdip->range(); }
d97 1
a97 1
    friend ostream& operator <<(ostream&, DiscreteImage<T>);
d99 2
a100 2
    friend class DIVIter<T>;
    friend class DIPIter<T>;
@


1.1
log
@Initial revision
@
text
@d3 4
a6 1
// $Log$
d22 1
a22 1
class DIIter;
d25 3
d31 2
a32 1
    // INVARIANT:  bipd==0 if there is no base image binding.
a73 2
    DiscreteImage& operator &( int (*)(IntPoint)) const;

d80 3
a82 1
    IntPointSet domain() const { return this->bdip->ps; }
d88 1
a88 1
    T reduce(T (*)(const T&, const T&),T);
d90 1
a90 1
    T reduce(T (*) (T, T), T);
d94 2
a95 1
    friend class DIIter<T>;
a96 3

template <class T>
ErrorDI<T> DiscreteImage<T>::errorDI;
@
