head	1.5;
access;
symbols
	bobbase:1.3
	bob:1.3.1
	r2_1:1.3
	r2_0:1.3
	r1_1_beta:1.3
	r1_1_alpha:1.3
	r1_0:1.3
	r0_11:1.3
	r0_10:1.2
	r0_9:1.2;
locks
	fjsoria:1.5; strict;
comment	@// @;


1.5
date	95.01.11.15.43.58;	author fjsoria;	state Exp;
branches;
next	1.4;

1.4
date	94.12.22.19.14.31;	author fjsoria;	state Exp;
branches;
next	1.3;

1.3
date	94.03.14.15.48.33;	author thoth;	state Exp;
branches
	1.3.1.1;
next	1.2;

1.2
date	93.11.17.18.29.07;	author thoth;	state Exp;
branches;
next	1.1;

1.1
date	93.09.15.12.57.38;	author thoth;	state Exp;
branches;
next	;

1.3.1.1
date	94.12.28.16.56.06;	author thoth;	state Exp;
branches;
next	;


desc
@Vector image implementation.
@


1.5
log
@patched problem with operator<< with dummy_op()
@
text
@// Emacs: -*- C++ -*-

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


//
// $Log: VectorI.c,v $
// Revision 1.4  1994/12/22  19:14:31  fjsoria
// added gaurd around static data member template
//
// Revision 1.3  1994/03/14  15:48:33  thoth
// ValueSet has been replaced by container class Set.
//
// Revision 1.2  1993/11/17  18:29:07  thoth
// IPSIter is now PSIter<IntPoint>.
//
// Revision 1.1  1993/09/15  12:57:38  thoth
// Initial revision
//

#include "VectorI.h"
#include "PSIter.h"
#include "VectorImageIter.h"


template < class P,class T>
IA_VectorI<P,T>::IA_VectorI(IA_Set<P> pset, T *v, unsigned sz,
			    int giveaway)
: IA_BaseImage<P,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 P,class T>
IA_VectorI<P,T>::IA_VectorI(const IA_Set<P> &pset, const T& v)
:IA_BaseImage<P,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 P,class T>
IA_Set<T> IA_VectorI<P,T>::range() const {
    return IA_Set<T>(vec, size);
}
#else
template < class P,class T>
T* IA_VectorI<P,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 P,class T>
IA_Array<T> IA_VectorI<P,T>::value_array() const
{
    return IA_Array<T>(vec, size);
}

template < class P,class T>
ostream& IA_VectorI<P,T>::print_this(ostream &o) const
{
    IA_PSIter<P> iter(this->ps);
    P p;
    int i;

    o << "VectorI - (point,value) pairs follow:\n";
    i = 0;
    while(iter(p)) {
#ifdef IA_UNRESOLVED_OPERATOR
    dummy_op(dummy_op(o << "(", p) << ",", this->vec[i++]) << ") ";
#else
      o << "(" << p << "," << this->vec[i++] << ") ";
#endif
    }
    return o << "\n";
}

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

}

template < class P,class T>
void IA_VectorI<P,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
	}
    }
}

#if 0
template < class P,class T>
IA_BaseImage<P,T> * IA_VectorI<P,T>::restricted_to(const IA_Set<P> &ips) const
{
    IA_SetStructure	ss;
    IA_Set<P>	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_VectorI<P,T>(result_domain, dest, sz, 1);
}
#endif

//
//
//

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

//
// iterator support below
//

template < class P,class T>
IA_BaseIVIter<P,T> *IA_VectorI<P,T>::value_iterator() const
{
    return new IA_VectorIVIter<P,T>(this);
}

template < class P,class T>
IA_BaseIPIter<P,T> *IA_VectorI<P,T>::pixel_iterator() const
{
  return new IA_VectorIPIter<P,T>(this);
}


#ifndef IA_NO_AUTOINST_OF_STATIC_DATA 
template < class P,class T>
char IA_VectorI<P,T>::dummy;
#endif








@


1.4
log
@added gaurd around static data member template
@
text
@d11 3
d28 1
d90 5
a94 1
	o << "(" << p << "," << this->vec[i++] << ") ";
@


1.3
log
@ValueSet has been replaced by container class Set.
@
text
@d11 3
a25 3
char IA_VectorI<P,T>::dummy;

template < class P,class T>
d185 1
a185 1
    return new IA_VectorIPIter<P,T>(this);
d187 14
@


1.3.1.1
log
@Conversion to classes for throw.
@
text
@a10 3
// Revision 1.3  1994/03/14  15:48:33  thoth
// ValueSet has been replaced by container class Set.
//
a20 1
#include "image_errors.h"
d31 1
a31 1
	ia_throw( Image_VectorConstructorSizeMismatch_Exception(__FILE__, __LINE__));
@


1.2
log
@IPSIter is now PSIter<IntPoint>.
@
text
@d11 3
d57 2
a58 2
IA_ValueSet<T> IA_VectorI<P,T>::range() const {
    return IA_ValueSet<T>(vec, size);
@


1.1
log
@Initial revision
@
text
@d10 4
a13 1
// $Log:	VectorDI.c,v $
d16 1
a16 1
#include "IPSIter.h"
@
