head	1.13;
access;
symbols
	bobbase:1.10
	bob:1.10.1
	r2_1:1.7
	r2_0:1.7
	r1_1_beta:1.7
	r1_1_alpha:1.6
	r1_0:1.6
	r0_11:1.5
	r0_10:1.4
	r0_9:1.1;
locks
	thoth:1.10.1.2; strict;
comment	@// @;


1.13
date	94.12.30.19.17.06;	author fjsoria;	state Exp;
branches;
next	1.12;

1.12
date	94.12.22.21.36.40;	author fjsoria;	state Exp;
branches;
next	1.11;

1.11
date	94.12.22.19.12.06;	author fjsoria;	state Exp;
branches;
next	1.10;

1.10
date	94.11.14.15.53.02;	author thoth;	state Exp;
branches
	1.10.1.1;
next	1.9;

1.9
date	94.10.10.18.52.20;	author thoth;	state Exp;
branches;
next	1.8;

1.8
date	94.09.15.19.36.37;	author jnw;	state Exp;
branches;
next	1.7;

1.7
date	94.07.25.17.29.33;	author thoth;	state Exp;
branches;
next	1.6;

1.6
date	94.05.17.12.53.27;	author thoth;	state Exp;
branches;
next	1.5;

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

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

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

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

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

1.10.1.1
date	94.12.28.15.43.15;	author thoth;	state Exp;
branches;
next	1.10.1.2;

1.10.1.2
date	95.01.13.19.36.30;	author thoth;	state Exp;
branches;
next	;


desc
@Bit Discrete Image implementation
@


1.13
log
@added more static data
@
text
@// 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 BitDI_rcsid[] = "$Id: BitDI.c,v 1.12 1994/12/22 21:36:40 fjsoria Exp fjsoria $";

//
// $Log: BitDI.c,v $
// Revision 1.12  1994/12/22  21:36:40  fjsoria
// static data member template fix
//
// Revision 1.11  1994/12/22  19:12:06  fjsoria
// added static data member for IA_VectorI
//
// Revision 1.10  1994/11/14  15:53:02  thoth
// removed useless local variable.
//
// Revision 1.9  1994/10/10  18:52:20  thoth
// Fixed bug with input of ASCII PBM files.
//
// Revision 1.8  1994/09/15  19:36:37  jnw
// Added display function for IA_Image<IA_Point<int>, IA_Bit>
//
// Revision 1.7  1994/07/25  17:29:33  thoth
// Name sanitization
//
// Revision 1.6  1994/05/17  12:53:27  thoth
// Image Operations now get their own files.
//
// Revision 1.5  1994/03/14  15:48:33  thoth
// ValueSet has been replaced by container class Set.
//
// Revision 1.4  1994/01/31  15:38:40  thoth
// read and write PBM is now available.
//
// Revision 1.3  1994/01/07  15:15:14  thoth
// Image class is now CoreImage and named image types are
// Image<P,T>.
//
// Revision 1.2  1993/12/29  16:53:13  thoth
// Bit Discrete Image now uses separate Bit type.
//
// Revision 1.1  1993/11/29  22:20:39  thoth
// Initial revision
//
//

#include	"BitDI.h"
#include	"VectorI.h"
#include	"ConstI.h"
#include	"ClosureI.h"
#include	"ErrorI.h"
#include	"ImageIter.h"
#include	"PSIter.h"

#include	<math.h>
#include	<fstream.h>

#include        "display.h"

//
//
//

#include "restrict.h"


#ifdef IA_NO_AUTOINST_OF_STATIC_DATA
#include "FuncI.h"
#include "LazyXlationI.h"
char IA_VectorI<IA_Point<int>, IA_Bit>::dummy;
char IA_ConstI<IA_Point<int>, IA_Bit>::dummy;
char IA_ClosureI<IA_Point<int>, IA_Bit>::dummy;
char IA_FunctionRefI<IA_Point<int>, IA_Bit>::dummy = 0;
char IA_LazyXlationI<IA_Point<int>, IA_Bit>::dummy;
char IA_FunctionI<IA_Point<int>, IA_Bit>::dummy = 0;
#endif

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


//
//
//

istream &wsc(istream &);	// from UcharDI.c

IA_Image<IA_Point<int>,IA_Bit> IA_Image<IA_Point<int>,IA_Bit>::read_PBM(istream &i)
{
    int	width, height;
    int	code;
    if (i.get()=='P' && ((code=i.get())=='4' || code == '1')
	&& i>>wsc>>width>>wsc>>height) {
	{
	    int	ch = i.get();
	    if (ch!='\n')
		i.putback(ch);
	}

	const unsigned	size=width*height;
	IA_Bit	*data = new IA_Bit[size];

	if (code=='4') {
	    unsigned char	ch;
	    int	idx=0;
	    for (int y=0; y<height; y++) {
		for (int x=0; x<width; x+=8) {
		    ch = i.get();
		    for (int b=0; b<8 && b+x<width; b++, ch <<=1) 
			data[idx++] = (ch&0x80);
		}
	    }
	} else {
	    int	val;
	    int	idx=0;
	    for (int y=0; y<height; y++) {
		for (int x=0; x<width; x++) {
		    i >> val;
		    data[idx++] = val;
		}
	    }
	}
	if (i)		// no errors during reading
	    return IA_Image<IA_Point<int>,IA_Bit>
		(IA_Set<IA_Point<int> >(IA_Point<int>(0,0),
				IA_Point<int>(height-1,width-1)),
		 data, size, 1);
    }

    ia_throw(IA::PNM_IO_ERROR, __FILE__, __LINE__);
    return IA_Image<IA_Point<int>,IA_Bit>();
}

IA_Image<IA_Point<int>,IA_Bit> IA_Image<IA_Point<int>,IA_Bit>::read_PBM(const char *fname)
{
    ifstream	in(fname);
    return read_PBM(in);
}

ostream & IA_Image<IA_Point<int>,IA_Bit>::write_PBM(ostream & o) const
{
    // what if image dimension is not 2?

    IA_Point<int>	inf_(domain().inf());
    IA_Point<int>	extent(domain().sup()-domain().inf()+1);
    int	width = extent[1], height=extent[0];

    o << "P4\n";
    o << width << " " << height << "\n";

    for (int y=0; y<height; y++) {
	for (int x=0; x<width; x+=8) {
	    char	val=0;
	    int mask = 0x80;
	    for (int b=0; b<8 && b+x<width; b++, mask >>=1) {
		IA_Point<int>	p(y+inf_[0],x+b+inf_[1]);
		if (this->domain().contains(p) &&
		    (*this)(p))
		    val |= mask;
	    }
	    o.put(val);
	}
    }
    return o;
}

void IA_Image<IA_Point<int>,IA_Bit>::write_PBM(const char *fname) const
{
    ofstream out(fname);
    write_PBM(out);
}

//
//
//

#if 0

class blah : public IA_ClosureI<IA_Point<int>, IA_Bit> {
  public:
    blah() 
    :IA_ClosureI<IA_Point<int>, IA_Bit>(IA_Set<IA_Point<int> >()) {}
    ostream &print_this(ostream &o) const { return o;}
    IA_Bit operator()(const IA_Point<int> &) const { return 0; }
    IA_ClosureI<IA_Point<int>, IA_Bit>* clone_self() const { return 0; }
};
static void dummy001()
{
    IA_Point<int>		ip;
    IA_Set<IA_Point<int> >	ps;
    IA_Image<IA_Point<int>,IA_Bit>	i1;
    IA_Image<IA_Point<int>,IA_Bit>
	i2(i1),
	i3(ps,0),
	i4(ps, (IA_Bit*)0, 0, 1),
	i5(ps, (IA_Bit*)0, 0),
	i6(blah()),
	i7(ps, (IA_Bit(*)(const IA_Point<int>&))0),
	i10(IA_CoreImage<IA_Point<int>,IA_Bit>());
    IA_Bit sc;

    i1 = i1.restrict(i2.range());
    i1 = i1.translate(ip);
    (IA_CoreImage<IA_Point<int>,IA_Bit>&)i1 = 2;
    (void)i1.type();
    i1[ip] = i1(ip);
    i1 = i1.restrict(i2.domain());
    (void)i1.extend(i2);
    (void)i1.reduce((IA_Bit (*)(const IA_Bit&,const IA_Bit&)) 0, 0);
    (void)i1.reduce((IA_Bit (*)( IA_Bit, IA_Bit)) 0, 0);
    cout << (IA_CoreImage<IA_Point<int>,IA_Bit>&)i1;

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

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

    IA_IVIter<IA_Point<int>,IA_Bit>	iter1(i1), iter2;
    IA_IPIter<IA_Point<int>,IA_Bit>	iter3(i2), iter4;
    iter1 = iter2;
    iter3 = iter4;
#if 1
    iter1.reset();
    iter1(sc);
    iter3.reset();
    iter3(ip, sc);
#endif
    compose(i1, (IA_Point<int>(*)(const IA_Point<int>&))0);
    compose(i1, *(IA_Closure<IA_Point<int>, IA_Point<int> >*)0);
    compose((IA_Bit(*)(IA_Bit))0, i1);
    compose((IA_Bit(*)(IA_Bit))0, i1, (IA_Bit*)0);

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

// display
//
// Forks a process to display an IA_Image<IA_Point<int>, IA_Bit>.
//
// Returns: the uid of the process      if the fork succeeded
//          -1                          if the fork failed
//
// display writes the image to a temp file in pbm format.
//
// User can set environment variable whose name is given by define constant
//        IMAGE_DISPLAY_ENV_VAR to specify what image display application
//        is to be used to display the pbm image.
//
// Default display application name is given by DEFINE constant
//        DEFAULT_IMAGE_DISPLAY
//

pid_t display(IA_Image<IA_Point<int>,IA_Bit> img)
{
    char *display_program;
    pid_t pid;

    // always use a fresh tmp filename
    strcpy(display_filename + strlen(display_filename) - 6, "XXXXXX");

    // Get the image display program filename
    display_program = getenv(IMAGE_DISPLAY_ENV_VAR);
    if (!display_program) {
	display_program = DEFAULT_IMAGE_DISPLAY;
    }

    // Fork and exec the display program
    if ((pid=fork())==0){
	// pid is zero, so this is the child

	// Write the image to a tmp file with a unique pid
	img.write_PBM(mktemp(display_filename));

	char *buffer;
	buffer = new char [strlen(display_program) + strlen(SEPARATOR_STRING)
			   + strlen(display_filename) + strlen(CLEANUP_STRING)
			   + strlen(display_filename)];
	strcat(strcat(strcat(strcat(strcpy(buffer, display_program),
				    SEPARATOR_STRING),
			     display_filename),
		      CLEANUP_STRING),
	       display_filename);
	// should exec a csh -c
	system(buffer);
	exit(0);
    }
    return pid;
}


#endif
@


1.12
log
@static data member template fix
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.11 1994/12/22 19:12:06 fjsoria Exp fjsoria $";
d14 3
d75 1
d80 2
@


1.11
log
@added static data member for IA_VectorI
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.10 1994/11/14 15:53:02 thoth Exp fjsoria $";
d14 3
d69 1
d71 1
d73 3
@


1.10
log
@removed useless local variable.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.9 1994/10/10 18:52:20 thoth Exp thoth $";
d14 3
d65 4
@


1.10.1.1
log
@image I/O is now ROF.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.10 1994/11/14 15:53:02 thoth Exp thoth $";
a13 3
// Revision 1.10  1994/11/14  15:53:02  thoth
// removed useless local variable.
//
a55 1
#include "image_errors.h"
d74 1
a74 1
IA_Image<IA_Point<int>,IA_Bit> read_PBM(istream &i)
d111 1
a111 1
		(IA_boxy_pset(IA_Point<int>(0,0),
d116 1
a116 1
    ia_throw(Image_PNMIO_Exception(__FILE__, __LINE__));
d120 1
a120 1
IA_Image<IA_Point<int>,IA_Bit> read_PBM(const char *fname)
d126 1
a126 2
ostream & write_PBM(const IA_CoreImage<IA_Point<int>, IA_Bit> &img,
		    ostream & o)
d130 2
a131 2
    IA_Point<int>	inf_(img.domain().inf());
    IA_Point<int>	extent(img.domain().sup()-img.domain().inf()+1);
d143 2
a144 2
		if (img.domain().contains(p) &&
		    img(p))
d153 1
a153 2
void write_PBM(const IA_CoreImage<IA_Point<int>, IA_Bit> &img,
	       const char *fname)
d156 1
a156 1
    write_PBM(img, out);
@


1.10.1.2
log
@CoreImage has been re-merged with Image.  All special stuff should be
friends of FBI now.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.10.1.1 1994/12/28 15:43:15 thoth Exp thoth $";
a13 3
// Revision 1.10.1.1  1994/12/28  15:43:15  thoth
// image I/O is now ROF.
//
a56 2
#include	<string.h>
#include	<unistd.h>
d130 1
a130 1
ostream & write_PBM(const IA_Image<IA_Point<int>, IA_Bit> &img,
d158 1
a158 1
void write_PBM(const IA_Image<IA_Point<int>, IA_Bit> &img,
d165 68
d269 1
a269 1
	write_PBM(img,mktemp(display_filename));
d287 2
@


1.9
log
@Fixed bug with input of ASCII PBM files.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.8 1994/09/15 19:36:37 jnw Exp thoth $";
d14 3
d76 1
a76 1
    int	width, height,maxval;
@


1.8
log
@Added display function for IA_Image<IA_Point<int>, IA_Bit>
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.7 1994/07/25 17:29:33 thoth Exp jnw $";
d14 3
d100 1
a100 1
		for (int x=0; x<width; x+=8) {
@


1.7
log
@Name sanitization
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.6 1994/05/17 12:53:27 thoth Exp $";
d14 3
d49 2
d220 55
@


1.6
log
@Image Operations now get their own files.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.5 1994/03/14 15:48:33 thoth Exp thoth $";
d14 3
d63 1
a63 1
IA_Image<IA_IntPoint,IA_Bit> IA_Image<IA_IntPoint,IA_Bit>::read_PBM(istream &i)
d99 3
a101 3
	    return IA_Image<IA_IntPoint,IA_Bit>
		(IA_IntPointSet(IA_IntPoint(0,0),
				IA_IntPoint(height-1,width-1)),
d106 1
a106 1
    return IA_Image<IA_IntPoint,IA_Bit>();
d109 1
a109 1
IA_Image<IA_IntPoint,IA_Bit> IA_Image<IA_IntPoint,IA_Bit>::read_PBM(const char *fname)
d115 1
a115 1
ostream & IA_Image<IA_IntPoint,IA_Bit>::write_PBM(ostream & o) const
d119 2
a120 2
    IA_IntPoint	inf_(domain().inf());
    IA_IntPoint	extent(domain().sup()-domain().inf()+1);
d131 1
a131 1
		IA_IntPoint	p(y+inf_[0],x+b+inf_[1]);
d142 1
a142 1
void IA_Image<IA_IntPoint,IA_Bit>::write_PBM(const char *fname) const
d154 1
a154 1
class blah : public IA_ClosureI<IA_IntPoint, IA_Bit> {
d157 1
a157 1
    :IA_ClosureI<IA_IntPoint, IA_Bit>(IA_IntPointSet()) {}
d159 2
a160 2
    IA_Bit operator()(const IA_IntPoint &) const { return 0; }
    IA_ClosureI<IA_IntPoint, IA_Bit>* clone_self() const { return 0; }
d164 4
a167 4
    IA_IntPoint		ip;
    IA_IntPointSet	ps;
    IA_Image<IA_IntPoint,IA_Bit>	i1;
    IA_Image<IA_IntPoint,IA_Bit>
d173 2
a174 2
	i7(ps, (IA_Bit(*)(const IA_IntPoint&))0),
	i10(IA_CoreImage<IA_IntPoint,IA_Bit>());
d179 1
a179 1
    (IA_CoreImage<IA_IntPoint,IA_Bit>&)i1 = 2;
d186 1
a186 1
    cout << (IA_CoreImage<IA_IntPoint,IA_Bit>&)i1;
d189 2
a190 2
    IA_Image<IA_IntPoint,IA_Bit>::read_IAA("");
    IA_Image<IA_IntPoint,IA_Bit>::read_IAA("","");
d196 2
a197 2
    IA_IVIter<IA_IntPoint,IA_Bit>	iter1(i1), iter2;
    IA_IPIter<IA_IntPoint,IA_Bit>	iter3(i2), iter4;
d206 2
a207 2
    compose(i1, (IA_IntPoint(*)(const IA_IntPoint&))0);
    compose(i1, *(IA_Closure<IA_IntPoint, IA_IntPoint>*)0);
@


1.5
log
@ValueSet has been replaced by container class Set.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.4 1994/01/31 15:38:40 thoth Exp thoth $";
d14 3
a52 19

//
// below are included the implementations of every image-image
// and image-scalar operation we could think of for binary images.
//

template <class T>
inline T max(T a, T b)
{
    return (a<b)?b:a;
}

template <class T>
inline T min(T a, T b)
{
    return (a<b)?a:b;
}

#include "BitImageOps.c"
@


1.4
log
@read and write PBM is now available.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.3 1994/01/07 15:15:14 thoth Exp thoth $";
d14 3
d165 1
d224 1
a224 1
    IA_ValueSet<IA_Bit>	vs(i1.range());
d229 1
@


1.3
log
@Image class is now CoreImage and named image types are
Image<P,T>.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.2 1993/12/29 16:53:13 thoth Exp $";
d14 4
d64 62
a125 2
#if 0
inline u_char logical_xor(u_char a, u_char b)
d127 23
a149 1
    return (!a) != (!b);
d152 1
a152 1
inline u_char logical_eq(u_char a, u_char b)
d154 2
a155 1
    return (!a) == (!b);
a156 2
#endif
#include "BitImageOps.c"
@


1.2
log
@Bit Discrete Image now uses separate Bit type.
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id: BitDI.c,v 1.1 1993/11/29 22:20:39 thoth Exp thoth $";
d14 3
d90 2
a91 2
    IA_BitDiscreteImage	i1;
    IA_BitDiscreteImage
d98 1
a98 1
	i10(IA_Image<IA_IntPoint,IA_Bit>());
d103 1
a103 1
    (IA_Image<IA_IntPoint,IA_Bit>&)i1 = 2;
d110 1
a110 1
    cout << (IA_Image<IA_IntPoint,IA_Bit>&)i1;
d113 2
a114 2
    IA_BitDiscreteImage::read_IAA("");
    IA_BitDiscreteImage::read_IAA("","");
@


1.1
log
@Initial revision
@
text
@d10 1
a10 1
static char BitDI_rcsid[] = "$Id$";
d13 3
a15 1
// $Log$
d17 1
d34 6
d57 1
a57 1

d67 1
a67 1

d75 1
a75 1
class blah : public IA_ClosureI<IA_IntPoint, u_char> {
d78 1
a78 1
    :IA_ClosureI<IA_IntPoint, u_char>(IA_IntPointSet()) {}
d80 2
a81 2
    u_char operator()(const IA_IntPoint &) const { return 0; }
    IA_ClosureI<IA_IntPoint, u_char>* clone_self() const { return 0; }
d91 2
a92 2
	i4(ps, (u_char*)0, 0, 1),
	i5(ps, (u_char*)0, 0),
d94 3
a96 3
	i7(ps, (u_char(*)(const IA_IntPoint&))0),
	i10(IA_Image<IA_IntPoint,u_char>());
    u_char sc;
d100 1
a100 1
    (IA_Image<IA_IntPoint,u_char>&)i1 = 2;
d105 3
a107 3
    (void)i1.reduce((u_char (*)(const u_char&,const u_char&)) 0, 0);
    (void)i1.reduce((u_char (*)( u_char, u_char)) 0, 0);
    cout << (IA_Image<IA_IntPoint,u_char>&)i1;
d117 2
a118 2
    IA_IVIter<IA_IntPoint,u_char>	iter1(i1), iter2;
    IA_IPIter<IA_IntPoint,u_char>	iter3(i2), iter4;
d129 2
a130 2
    compose((u_char(*)(u_char))0, i1);
    compose((u_char(*)(u_char))0, i1, (u_char*)0);
d132 1
a132 1
    IA_ValueSet<u_char>	vs(i1.range());
@
