head	1.6;
access;
symbols
	bobbase:1.6
	bob:1.6.1
	r2_1:1.6
	r2_0:1.6
	r1_1_beta:1.6
	r1_1_alpha:1.5
	r1_0:1.5
	r0_11:1.5;
locks
	thoth:1.6.1.2
	thoth:1.6; strict;
comment	@// @;


1.6
date	94.07.25.17.26.39;	author thoth;	state Exp;
branches
	1.6.1.1;
next	1.5;

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

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

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

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

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

1.6.1.1
date	94.12.28.16.56.06;	author thoth;	state Exp;
branches;
next	1.6.1.2;

1.6.1.2
date	95.01.13.19.37.42;	author thoth;	state Exp;
branches;
next	;


desc
@Meta-code for the forward template-image product.
@


1.6
log
@Name sanitization
@
text
@// Emacs: -*- C++ -*-

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


//
// $Log: templ-img-product,v $
// Revision 1.5  1994/04/15  13:20:18  thoth
// zero_extend is now a function template.
//
// Revision 1.4  1994/03/30  14:02:11  thoth
// zero_extension is now a template function.
//
// Revision 1.3  1994/03/14  15:54:35  thoth
// We now use the FBI to extract the baseptr.
//
// Revision 1.2  1994/02/24  18:26:06  thoth
// prepare for alterations in sed script that allow passing of base
// template container type instead of derived.
//
// Revision 1.1  1994/02/12  19:45:43  thoth
// Initial revision
//


//
// foward convolutions
//

static IA_Image<IA_Point<int>,RTYPE>
forw_CONV_inv_core(IA_Point<int> src_infimum,
	      IA_Point<int> src_width,
	      const IBTYPE *src_data, // length is prod(src_width)
	      const IA_Image<IA_Point<int>,TBTYPE> &templ,
	      IA_Set<IA_Point<int> > dest_ps)
{
    const int	dimen = src_width.dim();

    IA_Set<IA_Point<int> >	templ_ps = templ.domain();
    int		templ_sz = templ_ps.card();
    TBTYPE	*const templ_data = new TBTYPE[templ_sz];
    int	*const templ_offsets = new int[templ_sz];

    {
	TBTYPE	*d_scan = templ_data;
	int	*o_scan = templ_offsets;
	IA_IPIter<IA_Point<int>,TBTYPE>	iter(templ);
	IA_Point<int>	ip;
	while (iter(ip, *d_scan)) {
	    *o_scan = -ip[0];
	    for (unsigned i=1; i<dimen; i++) {
		*o_scan *= src_width[i];
		*o_scan -= ip[i];
	    }
	    d_scan++;
	    o_scan++;
	}
    }

    IA_PSIter<IA_Point<int> >	iter(dest_ps);
    IA_Point<int>	ip;
    RTYPE *const	dest_data = new RTYPE[dest_ps.card()];
    RTYPE *	valp = dest_data;
    while (iter(ip)) {
	int	offset= ip[0] - src_infimum[0];
	unsigned i;
	for (i=1; i<dimen; i++) {
	    offset *= src_width[i];
	    offset += ip[i] - src_infimum[i];
	}
	const IBTYPE *const base = src_data + offset;

	// _IVAL_=(base[templ_offsets[i]])
	// _TVAL_=(templ_data[i])
	// _IRESULT_=(*valp)

	INITIALIZE ;

	for (i=0; i<templ_sz; i++) {
	    ACCUMULATE ;
	}
	{
	    RESULT ;
	}
	valp++;
    }
    delete[] templ_offsets;
    delete[] templ_data;

    return IA_Image<IA_Point<int>,RTYPE>(dest_ps, dest_data, dest_ps.card(), 1);
}

static
IA_Image<IA_Point<int>,RTYPE>
forw_CONV_inv(const IA_Image<IA_Point<int>,IBTYPE> &img,
	const IA_Image<IA_Point<int>,TBTYPE> &invtempl,
	IA_Set<IA_Point<int> > dest_ps)
{
    IA_Point<int>	inf_ = dest_ps.inf()-invtempl.domain().sup();
    IA_Point<int>	sup_ = dest_ps.sup()-invtempl.domain().inf();
    IA_Set<IA_Point<int> >	src_ps = IA_Set<IA_Point<int> >(inf_,sup_);

    IBTYPE	*const src_data = new IBTYPE[src_ps.card()];

    zero_extend(img, src_ps, (IBTYPE*)src_data, IBTYPE(ZERO));
    IA_Image<IA_Point<int>,RTYPE>	rval =
	forw_CONV_inv_core(inf_, sup_-inf_ + 1, src_data, invtempl, dest_ps);

    delete[] src_data;

    return rval;
}

IA_Image<IA_Point<int>,RTYPE>
CONV(const IA_DDTemplate<TITYPE > &templ_,
     const IA_CoreImage<IA_Point<int>,IBTYPE> &img_,
     IA_Set<IA_Point<int> > dest_ps)
{
    IA_Image<IA_Point<int>,IBTYPE>	img(img_);
    /*PROMOTE*/IA_DDTemplate<TITYPE > templ(templ_);

    if (templ.type() == IA_InvariantDT<TITYPE >::s_type()) {
	return forw_CONV_inv
	    (img, ((IA_InvariantDT<TITYPE >*)IA_FBI<IA_Point<int>, IA_Point<int>, IBTYPE, IBTYPE, TBTYPE>::extract_baseptr(templ))->value, dest_ps);
    } else {
	unsigned	size = dest_ps.card();
	RTYPE *const	dest_data = new RTYPE[size];

	for (int i=0; i<size; i++) {
	    // _IRESULT_=dest_data[i]
	    // INITIALIZE ;
	    IRESULT=ZERO;
	}

	IA_PSIter<IA_Point<int> >	src_iter(img.domain());
	IA_Point<int>	base_ip;
	while (src_iter(base_ip)) {
	    IA_CoreImage<IA_Point<int>,TBTYPE>	tv = templ(base_ip);

	    IA_IPIter<IA_Point<int>,TBTYPE>	templ_iter(tv);
	    IA_Point<int>	templ_ip;
	    TBTYPE	templ_val;
	    IBTYPE	ival = img(base_ip);

	    // _IVAL_=ival
	    // _TVAL_=templ_val
	    // _IRESULT_=(*valp)

	    while ( templ_iter(templ_ip, templ_val) ) {
		const IA_Point<int>	ip = templ_ip; //+base_ip;
		if (! dest_ps.contains(templ_ip))
		    continue;
		unsigned	offset = dest_ps.index(templ_ip);
		RTYPE	*valp = dest_data + offset;
//		cout << "templ(" << base_ip << ") =  " << tv << " and templ()("
//		     << templ_ip <<") = " << templ_val << endl;
		ACCUMULATEVAR ;
	    }
	}
	return IA_Image<IA_Point<int>,RTYPE>(dest_ps, dest_data,
						      size, 1);
    }
}
@


1.6.1.1
log
@Conversion to classes for throw.
@
text
@a10 3
// Revision 1.6  1994/07/25  17:26:39  thoth
// Name sanitization
//
a101 5
    if (img.domain().dim() != invtempl.domain().dim()) {
	ia_throw(Template_DimensionMismatch2_Exception(__FILE__, __LINE__));
	return IA_Image<IA_Point<int>,RTYPE>();
    }

d104 1
a104 1
    IA_Set<IA_Point<int> >	src_ps = IA_boxy_pset(inf_,sup_);
@


1.6.1.2
log
@CoreImage has been re-merged with Image.  All special stuff should be
friends of FBI now.
@
text
@a10 3
// Revision 1.6.1.1  1994/12/28  16:56:06  thoth
// Conversion to classes for throw.
//
d127 1
a127 1
     const IA_Image<IA_Point<int>,IBTYPE> &img_,
d149 1
a149 1
	    IA_Image<IA_Point<int>,TBTYPE>	tv = templ(base_ip);
@


1.5
log
@zero_extend is now a function template.
@
text
@d11 3
d33 3
a35 3
static IA_Image<IA_IntPoint,RTYPE>
forw_CONV_inv_core(IA_IntPoint src_infimum,
	      IA_IntPoint src_width,
d37 2
a38 2
	      const IA_Image<IA_IntPoint,TBTYPE> &templ,
	      IA_IntPointSet dest_ps)
d42 1
a42 1
    IA_IntPointSet	templ_ps = templ.domain();
d50 2
a51 2
	IA_IPIter<IA_IntPoint,TBTYPE>	iter(templ);
	IA_IntPoint	ip;
d63 2
a64 2
    IA_PSIter<IA_IntPoint>	iter(dest_ps);
    IA_IntPoint	ip;
d93 1
a93 1
    return IA_Image<IA_IntPoint,RTYPE>(dest_ps, dest_data, dest_ps.card(), 1);
d97 4
a100 4
IA_Image<IA_IntPoint,RTYPE>
forw_CONV_inv(const IA_Image<IA_IntPoint,IBTYPE> &img,
	const IA_Image<IA_IntPoint,TBTYPE> &invtempl,
	IA_IntPointSet dest_ps)
d102 3
a104 3
    IA_IntPoint	inf_ = dest_ps.inf()-invtempl.domain().sup();
    IA_IntPoint	sup_ = dest_ps.sup()-invtempl.domain().inf();
    IA_IntPointSet	src_ps = IA_IntPointSet(inf_,sup_);
d109 1
a109 1
    IA_Image<IA_IntPoint,RTYPE>	rval =
d117 1
a117 1
IA_Image<IA_IntPoint,RTYPE>
d119 2
a120 2
     const IA_CoreImage<IA_IntPoint,IBTYPE> &img_,
     IA_IntPointSet dest_ps)
d122 1
a122 1
    IA_Image<IA_IntPoint,IBTYPE>	img(img_);
d127 1
a127 1
	    (img, ((IA_InvariantDT<TITYPE >*)IA_FBI<IA_IntPoint, IA_IntPoint, IBTYPE, IBTYPE, TBTYPE>::extract_baseptr(templ))->value, dest_ps);
d138 2
a139 2
	IA_PSIter<IA_IntPoint>	src_iter(img.domain());
	IA_IntPoint	base_ip;
d141 1
a141 1
	    IA_CoreImage<IA_IntPoint,TBTYPE>	tv = templ(base_ip);
d143 2
a144 2
	    IA_IPIter<IA_IntPoint,TBTYPE>	templ_iter(tv);
	    IA_IntPoint	templ_ip;
d153 1
a153 1
		const IA_IntPoint	ip = templ_ip; //+base_ip;
d163 1
a163 1
	return IA_Image<IA_IntPoint,RTYPE>(dest_ps, dest_data,
@


1.4
log
@zero_extension is now a template function.
@
text
@d11 3
a23 71

#ifndef zero_extend_scan_IBTYPE
#define zero_extend_scan_IBTYPE

static void zero_extend_vec_scan(const IA_SetStructure &ss,
				 const IBTYPE **src,
				 IBTYPE **dest,
				 IBTYPE zero)
{
    for (unsigned i=0; i<ss.nintervals(); i++) {
	IA_ss_interval	temp(ss.retrieve_interval(i));
	if (temp.substructure == IA_SetStructure::FIRST_ONLY) {
	    (*src) += temp.count;
	} else if (temp.substructure == IA_SetStructure::BOTH) {
	    for (unsigned j=0; j<temp.count; j++) {
		*((*dest)++) = *((*src)++);
	    }
	} else if (temp.substructure == IA_SetStructure::SECOND_ONLY) {
	    for (unsigned j=0; j<temp.count; j++)
		*((*dest)++) = zero;
	} else {
	    for (unsigned j=0; j<temp.count; j++)
		zero_extend_vec_scan(temp.substructure, src, dest, zero);
	}
    }
}

static void zero_extend_iter_scan(const IA_SetStructure &ss,
				  IA_IVIter<IA_IntPoint,IBTYPE> *srciter,
				  IBTYPE **dest,
				  IBTYPE zero)
{
    for (unsigned i=0; i<ss.nintervals(); i++) {
	IA_ss_interval	temp(ss.retrieve_interval(i));
	if (temp.substructure == IA_SetStructure::FIRST_ONLY) {
	    IBTYPE	blah;
	    for (unsigned j=0; j<temp.count; j++) 
		(*srciter)(blah);
	} else if (temp.substructure == IA_SetStructure::BOTH) {
	    IBTYPE	blah;
	    for (unsigned j=0; j<temp.count; j++) {
		(*srciter)(blah);
		*((*dest)++) = blah;
	    }
	} else if (temp.substructure == IA_SetStructure::SECOND_ONLY) {
	    for (unsigned j=0; j<temp.count; j++)
		*((*dest)++) = zero;
	} else {
	    for (unsigned j=0; j<temp.count; j++)
		zero_extend_iter_scan(temp.substructure, srciter, dest, zero);
	}
    }
}

static void zero_extend(const IA_CoreImage<IA_IntPoint,IBTYPE> &srcimg,
			const IA_IntPointSet &dest_ps, IBTYPE *dest_data,
			IBTYPE zero)
{
    IA_SetStructure	ss;
    intersect_with_dualstruct(srcimg.domain(), dest_ps, &ss);

    if (srcimg.type() == IA_VectorI<IA_IntPoint,IBTYPE>::s_type()) {
	IBTYPE	*srcdata = ((IA_VectorI<IA_IntPoint,IBTYPE>*)srcimg.bip)->vec;
	zero_extend_vec_scan(ss, &srcdata, &dest_data, zero);
    } else {
	IA_IVIter<IA_IntPoint,IBTYPE>	iter(srcimg);
	zero_extend_iter_scan(ss, &iter, &dest_data, zero);
    }
}

#endif
@


1.3
log
@We now use the FBI to extract the baseptr.
@
text
@d11 3
d173 1
a173 1
    zero_extend(img, src_ps, src_data, ZERO);
d192 1
a192 1
	    (img, ((IA_InvariantDT<TITYPE >*)IA_FBI<IA_IntPoint,IBTYPE>::extract_baseptr(templ))->value, dest_ps);
@


1.2
log
@prepare for alterations in sed script that allow passing of base
template container type instead of derived.
@
text
@d11 4
d189 1
a189 1
	    (img, ((IA_InvariantDT<TITYPE >*)templ.bdtp)->value, dest_ps);
@


1.1
log
@Initial revision
@
text
@d10 4
a13 1
// $Log: absorber,v $
d176 1
a176 1
CONV(const IA_DDTemplate<TITYPE > &templ,
d181 1
@
