head	1.2;
access
	monica
	thoth;
symbols;
locks; strict;
comment	@// @;


1.2
date	94.08.24.00.30.59;	author monica;	state Exp;
branches;
next	1.1;

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


desc
@more spatial transforms.
@


1.2
log
@int main & exit(0)
@
text
@// Emacs -*- C++ -*-
static char test115_rcsid[] = "$Id: test115.c,v 1.1 1994/02/18 19:01:55 thoth Exp monica $";

//
// more spatial transforms
//

//
// $Log: test115.c,v $
//Revision 1.1  1994/02/18  19:01:55  thoth
//Initial revision
//

#include <iostream.h>

#include "Image.h"
#include "IntDI.h"
#include "UcharDI.h"
#include "FloatDI.h"
#include "OtherI.h"
#include "FloatDDTempl.h"
#include "OtherDT.h"
#include "../test_image/BLinterp.h"

typedef IA_FloatDiscreteImage FDI;

const int scalefact=3;

IA_FloatPoint triple(const IA_FloatPoint &p)
{
    return p/scalefact;
}

const IA_FloatPoint	offset(9.5, 9.5);

IA_FloatPoint xlate(const IA_FloatPoint &p)
{
  return p+offset;
}

IA_FloatPoint unxlate(const IA_FloatPoint &p)
{
  return p-offset;
}

//

class rot : public IA_Closure<IA_FloatPoint, IA_FloatPoint> {
    const double	S,C;
  public:
    rot(double	theta)
    :S(sin(theta)), C(cos(theta)) { }
    IA_Closure<IA_FloatPoint, IA_FloatPoint>* clone_self() const {
	return new rot(*this);
    }
    IA_FloatPoint operator()(const IA_FloatPoint &p) const {
	return IA_FloatPoint(p[0]*C + p[1]*S, p[1]*C-p[0]*S);
    }
};

//

class shrinkDT: public IA_OtherDT<FDI> {
    int	fact;
  public:
    shrinkDT(unsigned dim, int fact_)
    :IA_OtherDT<FDI>(IA_WhiteHole(dim)) { fact = fact_; }
    IA_OtherDT<FDI> *clone_self() const { return new shrinkDT(*this); }

    FDI operator()(const IA_IntPoint &) const;
    ostream &print_this(ostream &o) const { return o<<"magnify by " << fact << "\n"; }
};

FDI shrinkDT::operator()(const IA_IntPoint &p) const
{
    IA_IntPoint		inf_ = p*fact;
    IA_IntPoint		sup_ = (p+1)*fact -1;
    IA_IntPointSet	ps(inf_, sup(inf_,sup_));
    return FDI(ps, 1.0/ps.card());
}

//

IA_IntDiscreteImage rotate(IA_FloatDiscreteImage im, double factor)
{
    IA_Image<IA_FloatPoint,float> interp(IA_BLInterp<float>(im));

    interp = compose(interp, xlate);
    interp = compose(interp, rot(2*M_PI * factor));
    interp = compose(interp, unxlate);

    interp = compose(interp, triple);

    im = interp.restrict(IA_IntPointSet(IA_IntPoint(-1,-1), 3*IA_IntPoint(20,20)-2));
    im = im.translated(IA_IntPoint(1,1));

    im = linear_product(im, IA_FloatDDTemplate(shrinkDT(2, scalefact)), IA_IntPointSet(IA_IntPoint(0,0), IA_IntPoint(19,19)));

    return to_uchar(im);
}

int main()
{
#if 0
    char	*disp=getenv("DISPLAY");
    if (disp==0) {
	cerr << "No DISPLAY environment variable, hasta.\n";
	exit(1);
    }
    IDP::ClientID	cid;
    IDP::LinkID		lid;
    cid = IDP::NewClient("iac++ test013");
#endif
    IA_FloatDiscreteImage	fdi = IA_IntDiscreteImage::read_PGM(cin);
    IA_IntDiscreteImage	idi(IA_IntPoint(1,1), 1);

    for (int i=0; i<4; i++) {
	idi = rotate(fdi, -i/16.0).translated(IA_IntPoint(20*i,0)).extend(idi);
    }

    idi.write_PGM(cout);

    exit(0);
}
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char test115_rcsid[] = "$Id: test105.c,v 1.1 93/03/10 13:57:00 thoth Exp $";
d9 4
a12 1
// $Log$
d102 1
a102 1
main()
d122 2
@
