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

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

static char copyright[] = "Copyright 1993, Center for Computer Vision and Visualization,\nUniversity of Florida.  All rights reserved.\n";

static char ComplexDI_rcsid[] = "$Id: CplxDI.c,v 1.6.1.2 1995/01/13 19:45:08 thoth Exp thoth $";

//
// $Log: CplxDI.c,v $
// Revision 1.6.1.2  1995/01/13  19:45:08  thoth
// CoreImage has been re-merged with Image.  All special stuff should be
// friends of FBI now.
//
// Revision 1.6.1.1  1994/12/28  16:56:06  thoth
// Conversion to classes for throw.
//
// Revision 1.6  1994/08/22  15:20:29  thoth
// DOS-inspired name rework.
//
// Revision 1.5  1994/07/25  17:26:39  thoth
// Name sanitization
//
// Revision 1.4  1994/05/17  12:53:27  thoth
// Image Operations now get their own files.
//
// Revision 1.3  1994/03/14  15:50:10  thoth
// ValueSet has been replaced by container class Set.
//
// Revision 1.2  1994/01/07  15:10:00  thoth
// Image class is now CoreImage and named image types are
// Image<P,T>.
//
// Revision 1.1  1993/11/29  22:20:39  thoth
// Initial revision
//
//


#include	<math.h>
#include	<fstream.h>
#include	"VectorI.h"
#include	"ConstI.h"
#include	"ClosureI.h"
#include	"ErrorI.h"
#include	"ImageIter.h"
#include	"PSIter.h"
#include	"CplxDI.h"


//
//
//

#include "restrict.h"

IA_BaseImage<IA_Point<int>,complex> *restrict_toD(const IA_BaseImage<IA_Point<int>, complex> *im, const IA_Set<IA_Point<int> > &ips) {
    return restrictD_toD(im, ips);
}


//
//


IA_Image<IA_Point<int>,complex>
IA_CplxDI(const IA_Image<IA_Point<int>,float> &re,
	 const IA_Image<IA_Point<int>,float> &im)
{
    if(im.domain() != re.domain()) {
	ia_throw(Image_DomainMismatch_Exception(__FILE__,__LINE__));
	return IA_Image<IA_Point<int>,complex>();
    }

    const unsigned      sz = re.domain().card();
    complex * const     vec = new complex[sz];
    complex *scan = vec;
    float   re_temp,im_temp;
    IA_IVIter<IA_Point<int>,float>       re_iter(re),im_iter(im);

    while(re_iter(re_temp) && im_iter(im_temp)) {
        *(scan++) = complex(re_temp,im_temp);
    }

    return IA_Image<IA_Point<int>,complex> (re.domain(), vec, sz, 1);
}

//
//
//

#if 0

class blah : public IA_ClosureI<IA_Point<int>,complex> {
  public:
    blah() 
    :IA_ClosureI<IA_Point<int>,complex>(IA_Set<IA_Point<int> >()) {}
    ostream &print_this(ostream &o) const { return o;}
    complex operator()(const IA_Point<int> &) const { return 0; }
    IA_ClosureI<IA_Point<int>,complex>* clone_self() const { return 0; }
};
static void dummy001()
{
    IA_Point<int>		ip;
    IA_Set<IA_Point<int> >	ps;
    IA_Image<IA_Point<int>,complex>	i1;
    IA_Image<IA_Point<int>,complex>
	i2(i1),
	i3(ps,0.0),
	i4(ps, (complex*)0, 0, 1),
	i5(ps, (complex*)0, 0),
	i6(blah()),
	i7(ps, (complex(*)(const IA_Point<int>&))0),
	i10(IA_Image<IA_Point<int>, complex>());
    i1 = i1.restrict(i2.range());
    i1 = i1.translate(ip);
    (IA_Image<IA_Point<int>, complex>&)i1 = 2;
    (void)i1.type();
    i1[ip] = i1(ip);
    i1 = i1.restrict(i2.domain());
    (void)i1.extend(i2);
    (void)i1.reduce((complex (*)(const complex&,const complex&)) 0, 0);
    (void)i1.reduce((complex (*)( complex, complex)) 0, 0);
    cout << (IA_Image<IA_Point<int>, complex>&)i1;

#if 0
    IA_Image<IA_Point<int>,complex>::read_IAA("");
    IA_Image<IA_Point<int>,complex>::read_IAA("","");

    i1.write_IAA("");
    i1.write_IAA("","");
#endif

    IA_IVIter<IA_Point<int>,complex>	iter1(i1), iter2;
    IA_IPIter<IA_Point<int>,complex>	iter3(i2), iter4;
    iter1 = iter2;
    iter3 = iter4;

    compose(i1, (IA_Point<int>(*)(const IA_Point<int>&))0);
    compose(i1, *(IA_Closure<IA_Point<int>, IA_Point<int> >*)0);
    compose((complex(*)(complex))0, i1);
    compose((complex(*)(complex))0, (IA_Image<IA_Point<int>, complex>&)i1);
//    compose((u_char(*)(complex))0, i1, (u_char*)0);

    IA_Set<complex>	vs(i1.range());
    // I shouldn\'t have to do the following two lines
    // vs.value_type_compare(0,0);
}

#endif
