head	1.3;
access
	monica
	thoth;
symbols;
locks
	monica:1.3; strict;
comment	@// @;


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

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

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


desc
@show off image read, restriction and extension
@


1.3
log
@updated, but not completely.
@
text
@// Emacs: -*- C++ -*-
static char test002rcsid[] = "$Id: Demo.c,v 1.2 93/03/10 13:52:14 thoth Exp Locker: thoth $";

// 
// $Log:	Demo.c,v $
// Revision 1.2  93/03/10  13:52:14  thoth
// test out the OtherDI constructor.
// 
// Revision 1.1  93/02/20  16:48:45  thoth
// Initial revision
// 

#define WORKAROUND_CFRONT_FRIEND_MANGLING_BUG
#include "ValueSet.h"
#undef WORKAROUND_CFRONT_FRIEND_MANGLING_BUG

#include "iostream.h"
//#include "iacc.h"
//#include "ImageDisplayProtocol.h"
#include	"IntDI.h"
#include	"ImageIter.h"
#include "ClosureI.h"

// #include "with-ia-pointset.h"

typedef IA_Image<IA_IntPoint,int>	IA_IntDiscreteImage;

char response;
#define Demo(arg) cout << "[ " << #arg << " ]\n";  cin.get(response); arg; cout << endl;

#if 0
template <class ValueType>
ostream& operator<< (ostream& st, IA_ValueSet<ValueType>& vs) {
    int last_index = vs.size-1;
    st << "<"; 
    if (vs.size > 0) {
	for (int i=0; i < last_index; i++)
	    st << vs.value_array[i] << " ";
	if (vs.size > 0)
	    st << vs.value_array[last_index];
    }
    st << ">" << '\n';
    return st;
}
#endif

#if 0
void read(char *fname, IA_DiscreteImage<int>& image)
{
    FILE *fp;

    fp = fopen(fname, "r");
    if (!fp) {
	perror("opening file");
	exit(1);
	}

    int width, height, maxval;
    if (3!=fscanf(fp, "P5 %d %d %d", &width, &height, &maxval)) {
	cerr << "Error: was expecting raw PGM (P5) image in file "
	     << fname << "\n";
	exit(1);
    }

    int size=width*height;

    unsigned char *vec = new unsigned char[size];
    int ch;
    if((ch=getc(fp))!='\n')
	ungetc(ch,fp);
    if(!fread(vec,size,1,fp)) {
	perror("reading");
	exit(1);
    }

    int *ivec = new int[size];
    for(int i=0; i<size; i++){
	ivec[i] = vec[i];
    }

    image = IA_DiscreteImage<int>(ivec,IntPointSet(IntPoint(0,0),
						   IntPoint(height-1,width-1)),
				  size);
    delete ivec;
    delete vec;
}
#endif

// IDP::ClientID cid;
// IDP::LinkID lid;


void display(IA_IntDiscreteImage image)
{
#if 1
    static int	count=0;
    char	filename[128];
    sprintf(filename, "temp.%d", ++count);

    image.write_PGM(filename);
#else
    IA_Array<unsigned> dimensions(2);
    dimensions[0] = image.domain().sup()[0] - image.domain().inf()[0] + 1;
    dimensions[1] = image.domain().sup()[1] - image.domain().inf()[1] + 1;

    IA_IntPointSet ps(image.domain().inf(), image.domain().sup());
    unsigned char *vec = new unsigned char[ps.card()];

    IA_DIVIter<int> iter(image.extend(IA_DiscreteImage<int>(ps,0)));
    int value, i=0;

    while(iter(value)){
	vec[i++] = value;
    }
    IDP::WriteImage(lid, "me", IDP::U_BYTE, 1, dimensions, vec);
#endif
}

int plus(int i, int j)
{
    return i + j; 
}

class RampDI: public IA_ClosureI<IA_IntPoint,int> {
  public:
    RampDI(IA_IntPointSet ps_)
    :IA_ClosureI<IA_IntPoint,int>(ps_) {
    }
    IA_ClosureI<IA_IntPoint,int> *clone_self() const {
	return new RampDI(ps);
    }
    int operator()(const IA_IntPoint &p) const {
	return (p[1]+p[0])/2;
    }
};

int rampfunc(IA_IntPoint p)
{
    return (p[1]+p[0])/2;
}

ostream& operator <<(ostream& o, const IA_IntPointSet& ps)
{
    ps.output(o);
    return o;
}

main()
{
#if 0
    char* disp=getenv("DISPLAY");
    if (disp==0){
	cerr << "No DISPLAY environment variable, yarrgh!\n";
	exit(1);
    }
    cid = IDP::NewClient("Demo");
    lid = IDP::CreateDisplay(cid, disp, IDP::READ_WRITE);
#endif

    Demo(IA_IntDiscreteImage sr71;);
    Demo(ifstream	infile("sr71.pgm"););
    Demo(sr71 = IA_IntDiscreteImage::read_PGM(infile));
    Demo(display(sr71););
    Demo(cout << sr71.domain(););
    Demo(IA_IntDiscreteImage patch(sr71.restrict(IA_ValueSet<int>(1))););
    Demo(cout << patch.domain(););
    Demo(cout << patch.reduce(plus,0) << endl;);
    Demo(cout << patch.domain().card() << endl;);
#if 1
    Demo(IA_ValueSet<int> vs;);
    Demo(vs = patch.range(););
    Demo(cout << vs << "\n";);
    Demo(patch = 16);
    Demo(vs = patch.range(););
    Demo(cout << vs << "\n";);
#if 1
    Demo(IA_IntDiscreteImage	ramp(RampDI(IA_IntPointSet(IA_IntPoint(16,16), IA_IntPoint(23,31)))););
    Demo(sr71 = ramp.extend(sr71););
    Demo(display(sr71););
#endif
    Demo(sr71 = patch.extend(sr71););
    Demo(display(sr71););
#endif
}
@


1.2
log
@test out the OtherDI constructor.
@
text
@d2 1
a2 1
static char test002rcsid[] = "$Id: Demo.c,v 1.1 93/02/20 16:48:45 thoth Exp Locker: thoth $";
d6 3
d19 6
a24 4
#include "ImageDisplayProtocol.h"
#include	"IntDiscreteImage.h"
#include	"DIVIter.h"
#include "OtherDI.h"
d26 1
a26 1
#include "with-ia-pointset.h"
d89 2
a90 2
IDP::ClientID cid;
IDP::LinkID lid;
d93 1
a93 1
void display(IA_DiscreteImage<int> image)
d95 8
a102 2

    Array<unsigned> dimensions(2);
d106 1
a106 1
    IntPointSet ps(image.domain().inf(), image.domain().sup());
d116 1
d124 1
a124 1
class RampDI: public IA_OtherDI<int> {
d127 1
a127 1
    :IA_OtherDI<int>(ps_) {
d129 1
a129 1
    IA_BaseDI<int> *clone_self() const {
d137 1
a137 1
int rampfunc(IntPoint p)
d150 1
a150 1

d158 1
a158 1

d160 1
a160 1
    Demo(IA_DiscreteImage<int> sr71;);
d165 1
a165 1
    Demo(IA_DiscreteImage<int> patch(sr71.restrict(IA_ValueSet<int>(1))););
d177 1
a177 1
    Demo(IA_DiscreteImage<int>	ramp(RampDI(IntPointSet(IntPoint(16,16), IntPoint(23,31)))););
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char test002rcsid[] = "$Id: test100.c,v 1.1 92/11/14 09:45:50 jnw Exp Locker: jnw $";
d5 4
a8 1
// $Log:	test100.c,v $
d19 1
d112 13
d164 2
a165 2
#if 0
    Demo(IA_DiscreteImage<int>	ramp(rampfunc, IntPointSet(IntPoint(16,16), IntPoint(23,31))););
@
