// Emacs: -*- C++ -*-

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


//
// $Log:	unary-op.templ,v $
// Revision 1.2  93/05/27  11:49:04  thoth
// Copyright Notices
// 
// Revision 1.1  93/03/10  13:50:00  thoth
// Initial revision
// 

#ifndef vec_scalar_ATYPE_LTYPE_OPNAME
#define vec_scalar_ATYPE_LTYPE_OPNAME
static IA_DiscreteImage<ATYPE>
vec_uo_OPNAME(const IA_VectorDI<LTYPE> *lhs)
{
    const IA_IntPointSet domain = lhs->domain();
    const unsigned sz = domain.card();
    ATYPE *const vec = new ATYPE[sz];

    {
	ATYPE *ds = vec;
	const LTYPE *ls = lhs->vec;
	for (unsigned i=0; i<sz; i++) {
	    *(ds++) = SUBOP(*(ls++));
	}
    }
    return IA_DiscreteImage<ATYPE>(domain, vec, sz, 1);
}
#endif // vec_scalar_ATYPE_LTYPE_OPNAME

// scalar-scalar operation is trivial

#ifndef iter_scalar_ATYPE_LTYPE_OPNAME
#define iter_scalar_ATYPE_LTYPE_OPNAME
static IA_DiscreteImage<ATYPE>
iter_uo_OPNAME(IA_DiscreteImage<LTYPE> lhs)
{
    const IA_IntPointSet domain = lhs.domain();
    const unsigned sz = domain.card();
    ATYPE *const vec = new ATYPE[sz];

    {
	ATYPE *ds = vec;
	LTYPE ltmp;
	IA_DIVIter<LTYPE>	liter(lhs);
	for (unsigned i=0; i<sz; i++) {
	    liter(ltmp);
	    *(ds++) = SUBOP(ltmp);
	}
    }
    return IA_DiscreteImage<ATYPE>(domain, vec, sz, 1);
}
#endif // iter_scalar_ATYPE_LTYPE_OPNAME

IA_DiscreteImage<ATYPE>
OP ( const IA_DiscreteImage<LTYPE> &arg)
{
    if (arg.type() == IA_VectorDI<LTYPE>::s_type()) {
	return vec_uo_OPNAME((IA_VectorDI<LTYPE> *)arg.bdip);
    } else if (arg.type() == IA_ConstDI<LTYPE>::s_type()) {
	return IA_DiscreteImage<ATYPE> (arg.domain(), SUBOP(((IA_ConstDI<LTYPE> *)arg.bdip)->value));
    } else {
	return iter_uo_OPNAME(arg);
    }
}
