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


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

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

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

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

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

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

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

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

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

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

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

1.1
date	92.10.05.11.43.49;	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.
//


static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.11 93/05/26 17:03:26 thoth Exp Locker: thoth $";

// $Log:	VectorDI.c,v $
// Revision 1.11  93/05/26  17:03:26  thoth
// range is once again ValueSet.
// value_array() is fairly quick.
// 
// Revision 1.10  93/04/17  18:45:11  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:21:12  thoth
// removed cruft.
// new pointset restriction method.
// new translation method.
// 
// Revision 1.8  93/03/10  13:37:00  thoth
// range method no longer returns valueset due to
// difficulties with template implementation.
// 
// Revision 1.7  93/02/20  15:13:16  thoth
// Constructor with no values is not useful yet.
// We only need one vector constructor.
// Generic equality testing is not the domain of the BaseDI derived classes.
// The pointset should go first in an image constructor.
// 
// Revision 1.6  93/02/17  11:04:37  thoth
// minor cleaning up within the constructors.
// 
// Revision 1.5  93/02/08  13:03:42  thoth
// BaseDI takes care of common DI stuff.
// made array constructor consistent with IACC style (giveaway).
// equal method no longer loops infinitely.
// 
// Revision 1.4  93/01/19  14:56:39  jnw
// Modified to support IA_ naming convention
// 
// Revision 1.3  92/12/10  09:58:48  jnw
// Removed ancient debugging code
// 
// Revision 1.2  92/11/12  16:58:39  jnw
// Major modifications
// 
// 
// Revision 1.1  92/10/05  11:43:49  jnw
// Initial revision
// 

#include "VectorDI.h"
#include "IPSIter.h"
#include "VectorDIVIter.h"
#include "VectorDIPIter.h"

template <class T>
char IA_VectorDI<T>::dummy;

template <class T>
IA_VectorDI<T>::IA_VectorDI(IA_IntPointSet pset, T *v, unsigned sz,
			    int giveaway)
: IA_BaseDI<T>(pset), size(pset.card())
{
    if (sz != size) {
	ia_throw( IA::PSET_SIZE_MISMATCH, __FILE__, __LINE__);
	abort();		// unrecoverable error
    }

    if (giveaway) {
	this->vec = v;
    } else {
	this->vec = new T [this->size];
	for(int j=0; j<this->size; j++){
	    this->vec[j] = v[j];
	}
    }
}

template <class T>
IA_VectorDI<T>::IA_VectorDI(const IA_IntPointSet &pset, const T& v)
:IA_BaseDI<T>(pset), size(pset.card())
{
    this->vec = new T [this->size];
    for( int j=0; j<this->size; j++){
	this->vec[j] = v;
    }
}

#if 1
template <class T>
IA_ValueSet<T> IA_VectorDI<T>::range() const {
    return IA_ValueSet<T>(vec, size);
}
#else
template <class T>
T* IA_VectorDI<T>::range(unsigned *sz) const {
    T	*temp = new T[*sz = size];
    for (unsigned i=0; i<size; i++)
	temp[i] = vec[i];
    return temp;
}
#endif

template <class T>
IA_Array<T> IA_VectorDI<T>::value_array() const
{
    return IA_Array<T>(vec, size);
}

template <class T>
ostream& IA_VectorDI<T>::print_this(ostream &o) const
{
    IA_IPSIter iter(this->ps);
    IA_IntPoint p;
    int i;

    o << "VectorDI - (point,value) pairs follow:\n";
    i = 0;
    while(iter(p)) {
	o << "(" << p << "," << this->vec[i++] << ") ";
    }
    return o << "\n";
}

template <class T>
IA_BaseDI<T>* IA_VectorDI<T>::clone_self_extensively() const
{
    return (IA_BaseDI<T> *) new IA_VectorDI<T>
	( this->ps, this->vec, this->size, 0);

}

template <class T>
void IA_VectorDI<T>::vec_2_vec_structcopy
(const T** source_vec, T** dest_vec, const IA_SetStructure &ss)
//
// Copies values provided by the source vector into the
// vector pointed at by dest_vec according to the SetStructure ss.
//
// *source_vec	  MODIFIED
// *dest_vec	  MODIFIED
// ss		UNmodified
//
{
    int i,j;

    // for each interval in the current set structure, do the appropriate
    //	copying.
    for(i=0; i<ss.nintervals(); i++){
	const IA_ss_interval &ssi = ss.retrieve_interval(i);

	if (ssi.substructure == IA_SetStructure::BOTH) {
	    // These pixels are in the intersection -- copy them!
	    for(j=0; j < ssi.count; j++)
		*((*dest_vec)++) = *((*source_vec)++);

	} else if (ssi.substructure == IA_SetStructure::FIRST_ONLY) {
	    // These pixels aren\'t in the intersection -- skip them!
	    (*source_vec) += ssi.count;

	} else if (ssi.substructure != IA_SetStructure::SECOND_ONLY) {
	    // Make recursive calls on complicated structure
	    for(j=0; j<ssi.count; j++)
		vec_2_vec_structcopy(source_vec, dest_vec, ssi.substructure);

	} else { // ssi.substructure == IA_SetStructure::SECOND_ONLY
	    // These points aren\'t in the image being restricted
	}
    }
}

template <class T>
IA_BaseDI<T> * IA_VectorDI<T>::restricted_to(const IA_IntPointSet &ips) const
{
    IA_SetStructure	ss;
    IA_IntPointSet	result_domain =
	intersect_with_structure(this->domain(), ips, &ss);
    if (result_domain == this->domain())
	// clue to reuse this object
	return 0;

    const unsigned	sz = result_domain.card();
    T * const	dest = new T[sz];
    {
	const T	*src = this->vec;
	T	*scan = dest;
	vec_2_vec_structcopy(&src,&scan,ss);
    }

    return new IA_VectorDI<T>(result_domain, dest, sz, 1);
}

//
//
//

template <class T>
IA_BaseDI<T> * IA_VectorDI<T>::xlated_by(const IA_IntPoint & p) const
{
    // the constructor will copy the vector of values
    return new IA_VectorDI<T>(this->domain()+p, vec, size, 0);
}

//
// iterator support below
//

template <class T>
IA_BaseDIVIter<T> *IA_VectorDI<T>::value_iterator() const
{
    return new IA_VectorDIVIter<T>(this);
}

template <class T>
IA_BaseDIPIter<T> *IA_VectorDI<T>::pixel_iterator() const
{
    return new IA_VectorDIPIter<T>(this);
}
@


1.11
log
@range is once again ValueSet.
value_array() is fairly quick.
@
text
@d3 4
a6 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.10 93/04/17 18:45:11 thoth Exp Locker: thoth $";
d8 3
d12 4
@


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
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.9 93/04/08 13:21:12 thoth Exp Locker: thoth $";
d6 4
d85 1
d87 5
d97 7
@


1.9
log
@removed cruft.
new pointset restriction method.
new translation method.
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.8 93/03/10 13:37:00 thoth Exp Locker: thoth $";
d6 5
d45 2
d181 16
@


1.8
log
@range method no longer returns valueset due to
difficulties with template implementation.
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.7 93/02/20 15:13:16 thoth Exp Locker: thoth $";
d6 4
a43 1
#if 0
a44 9
IA_VectorDI<T>::IA_VectorDI(const IA_IntPointSet& pset)
:IA_BaseDI<T>(pset)
{
    this->size = pset.card();
    this->vec = new T [this->size];
}
#endif

template <class T>
a63 1
#if 0
a64 19
IA_VectorDI<T>::IA_VectorDI(T* const &v, IA_IntPointSet pset,
			    unsigned sz, int giveaway)
: IA_BaseDI<T>(pset)
{
    if (sz != pset.card())
	ia_throw( IA::PSET_SIZE_MISMATCH, __FILE__, __LINE__);

    if (!giveaway){
	this->vec = new T [this->size];
	for( int j=0; j<this->size; j++){
	    this->vec[j] = v[j];
	}
    } else {
	this->vec = v;
    }
}
#endif

template <class T>
d103 71
@


1.7
log
@Constructor with no values is not useful yet.
We only need one vector constructor.
Generic equality testing is not the domain of the BaseDI derived classes.
The pointset should go first in an image constructor.
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.6 93/02/17 11:04:37 thoth Exp Locker: thoth $";
d6 6
d101 5
a105 2
IA_ValueSet<T> IA_VectorDI<T>::range() const {
    return IA_ValueSet<T>(this->vec, this->size);
@


1.6
log
@minor cleaning up within the constructors.
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.5 93/02/08 13:03:42 thoth Exp Locker: thoth $";
d6 3
d34 1
d42 1
d45 1
a45 1
IA_VectorDI<T>::IA_VectorDI(T *v, IA_IntPointSet pset, unsigned sz,
d47 1
a47 1
: IA_BaseDI<T>(pset)
d49 1
a49 1
    if (sz != pset.card())
d51 3
a53 1
    this->size = pset.card();
a55 1
	v = 0;
d72 1
a72 1
    this->size = pset.card();
d85 2
a86 2
IA_VectorDI<T>::IA_VectorDI(const T& v, const IA_IntPointSet &pset)
:IA_BaseDI<T>(pset)
a87 1
    this->size = pset.card();
a99 17
int IA_VectorDI<T>::equal(const IA_BaseDI<T>* other) const
{
    IA_VectorDI<T> *ot = (IA_VectorDI<T> *)other;
    
    if (this->domain()==other->domain()
	&& this->type()==other->type()
	&& this->size==ot->size) {
	for( int i=0; i<this->size; i++){
	    if (this->vec[i] != ot->vec[i])
		return 0;
	}
	return 1;
    }
    return 0;
}

template <class T>
d117 2
a118 2
    return (IA_BaseDI<T> *) new IA_VectorDI<T>( this->vec, this->ps, 
						this->ps.card(), 0);
@


1.5
log
@BaseDI takes care of common DI stuff.
made array constructor consistent with IACC style (giveaway).
equal method no longer loops infinitely.
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.4 93/01/19 14:56:39 jnw Exp Locker: thoth $";
d6 5
d40 2
a41 2
IA_VectorDI<T>::IA_VectorDI(T *&v, const IA_IntPointSet &pset, const int sz,
		      const int giveaway)
d58 1
d60 2
a61 2
IA_VectorDI<T>::IA_VectorDI(T* const &v, const IA_IntPointSet &pset,
			    const int sz, const int giveaway)
d76 1
@


1.4
log
@Modified to support IA_ naming convention
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.3 92/12/10 09:58:48 jnw Exp Locker: jnw $";
d6 3
d24 3
d28 1
a28 1
//:IA_BaseDI<T>(psset)
a29 1
    this->ps = pset;
d37 1
a37 1
//: IA_BaseDI<T>(pset)
a38 1
    this->ps = pset;
d47 1
a47 1
	for( int j=0; j<this->size; j++){
d55 2
a56 2
			    const int sz, const int copy)
//: IA_BaseDI<T>(pset)
a57 1
    this->ps = pset;
d61 1
a61 1
    if (copy){
d73 1
a73 1
//:IA_BaseDI<T>(pset)
a74 1
    this->ps = pset;
d92 3
a94 3
    if  (((IA_BaseDI<T> *)this)->equal(other)
	 && this->type()==other->type()
	 && this->size==ot->size) {
@


1.3
log
@Removed ancient debugging code
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.2 92/11/12 16:58:39 jnw Exp Locker: jnw $";
d6 3
d21 2
a22 2
VectorDI<T>::VectorDI(const IntPointSet& pset)
//:BaseDI<T>(psset)
d30 1
a30 1
VectorDI<T>::VectorDI(T *&v, const IntPointSet &pset, const int sz,
d32 1
a32 1
//: BaseDI<T>(pset)
d50 3
a52 3
VectorDI<T>::VectorDI(T* const &v, const IntPointSet &pset, const int sz,
		      const int copy)
//: BaseDI<T>(pset)
d69 2
a70 2
VectorDI<T>::VectorDI(const T& v, const IntPointSet &pset)
//:BaseDI<T>(pset)
d81 2
a82 2
ValueSet<T> VectorDI<T>::range() const {
    return ValueSet<T>(this->vec, this->size);
d86 1
a86 1
int VectorDI<T>::equal(const BaseDI<T>* other) const
d88 1
a88 1
    VectorDI<T> *ot = (VectorDI<T> *)other;
d90 1
a90 1
    if  (((BaseDI<T> *)this)->equal(other)
d103 1
a103 1
ostream& VectorDI<T>::print_this(ostream &o) const
d105 2
a106 2
    IPSIter iter(this->ps);
    IntPoint p;
d118 1
a118 1
BaseDI<T>* VectorDI<T>::clone_self_extensively() const
d120 2
a121 2
    return (BaseDI<T> *) new VectorDI<T>( this->vec, this->ps, 
					  this->ps.card(), 0);
@


1.2
log
@Major modifications

@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id: VectorDI.c,v 1.1 92/10/05 11:43:49 jnw Exp Locker: jnw $";
d6 4
d79 1
a79 4
    cerr << "Extracting Range from vector of size " << this->size << "\n";
    ValueSet<T> result(this->vec, this->size);
    cout << "Seem to have extracted this result: " << result << "\n";
    return result;
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
static char VectorDIrcsid[] = "$Id$";
d5 4
a8 1
// $Log$
d71 8
@
