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


1.2
date	95.01.11.06.03.09;	author rjj;	state Exp;
branches;
next	1.1;

1.1
date	95.01.11.05.29.05;	author rjj;	state Exp;
branches;
next	;


desc
@First version of euler program using a LUT.
This version declares the class E_LUT which is used in the
   composition.
@


1.2
log
@Changed from using a IA_Closure<int,int> to a simple function
   to perform the compose.  This simplified the code.
@
text
@// euler-lut.c          Section: 11.6, Euler Number
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.


#include "euler.h"
#include "IntDI.h"
#include "DDTempl.h"
#include "IntConv.h"

static  int e4_lut[] = { 0, 1, 2, 1, 0,-1, 2,-1, 0 };

static  int e8_lut[] = { 0, 1,-2, 1, 0,-1,-2,-1, 0 };

int f( int r ) {
    return e4_lut[r];
}

int g( int r ) {
    return e8_lut[r];
}

IA_DDTemplate<IA_Image<IA_Point<int>, int> >
euler_template() {
    // Create template t

    IA_Image<IA_Point<int>,int>
	t_im( IA_boxy_pset( IA_Point<int>(0,0), IA_Point<int>(1,1) ),
	      int(3) ); // a common value

    t_im[ IA_Point<int>(1, 0) ] = 1;
    t_im[ IA_Point<int>(0, 1) ] = 1;

    // template t created.
    return
	IA_DDTemplate<IA_Image<IA_Point<int>, int> >( 2, t_im );
}



//////////////////////////////////////////////////////////////////
// 4-connected Euler Number
int
euler_number_e4( const IA_Image<IA_Point<int>,IA_Bit> & image ) {

    // Convert the input to a IDI and perform the convolution.
    IA_Image<IA_Point<int>,int>
	a = image,
	b = linear_product( a, euler_template() );

    return
	sum( compose( f, b ) ) / 4;
}


//////////////////////////////////////////////////////////////////
// 8-connected Euler Number
int
euler_number_e8( const IA_Image<IA_Point<int>,IA_Bit> & image ) {

    // Convert the input to a IDI and perform the convolution.
    IA_Image<IA_Point<int>,int>
	a = image,
	b = linear_product( a, euler_template() );

    return
	sum( compose( g, b ) ) / 4;
}
@


1.1
log
@Initial revision
@
text
@a6 1
#include "Closure.h"
d15 2
a16 25

class  E_LUT: public IA_Closure<int,int> {
private:
    int lut[9];
public:
    E_LUT( const int * elut );

    E_LUT( const E_LUT & e );

    int  operator() (const int & c ) const {
	return  lut[ c ];
    }

    IA_Closure<int,int> *
    clone_self() const {
	return  new E_LUT( *this );
    }
};

// Cfront complains about for stmts inside of inline functions
//   if these are defined in the class definition above.
E_LUT::E_LUT( const int * elut ) {
    for ( int i=0; i<9; i++ ) {
	lut[i] = elut[i];
    }
d19 2
a20 4
E_LUT::E_LUT( const E_LUT & e ) {
    for ( int i=0; i<9; i++ ) {
	lut[i] = e.lut[i];
    }
a22 2


d52 1
a52 1
	sum( compose( E_LUT( e4_lut ), b ) ) / 4;
d67 1
a67 1
	sum( compose( E_LUT( e8_lut ), b ) ) / 4;
@
