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


1.3
date	95.01.10.02.53.32;	author rjj;	state Exp;
branches;
next	1.2;

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

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


desc
@Template version of the histogram algorithm.
@


1.3
log
@Added standard header.
@
text
@// histogram.c          Section: 9.3 Histogram & 9.4 Cumulative Histogram
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
//
// This is the implementation file for the template versions of
//      the histogram and cumulative histogram programs.
//


#include "histogram.h"
#include "PSIter.h"
#include "DDTempl.h"
#include "IntConv.h"
#include "UcharConv.h"
#include "ClosureDT.h"


//////////////////////////////////////////////////////////////////
//
// class IA_HistogramTemplate<I>
//
//////////////////////////////////////////////////////////////////

// Create a parameterized template which will evaluate
//   to a one point image at each point in the
//   parameterized template domain.

template <class I>
class IA_HistogramTemplate:
public IA_ClosureDT<IA_Image<IA_Point<int>,int> >
{
private:
    I im;

public:
    IA_HistogramTemplate( const I &inImage )
    : IA_ClosureDT<IA_Image<IA_Point<int>,int> >(inImage.domain()),
      im(inImage) {}
    
    IA_Image<IA_Point<int>,int>  operator() (const IA_Point<int> &aPt) const;
    
    IA_ClosureDT<IA_Image<IA_Point<int>,int> > *clone_self() const;
    
    ostream &print_this(ostream &o) const;
};



template <class I>
IA_Image<IA_Point<int>,int>
IA_HistogramTemplate<I>::operator() (const IA_Point<int> &aPt) const {

    // We return an image that is defined only on the support,
    // namely the one point associated with a non-zero value.

    return
	IA_Image<IA_Point<int>,int>( // Construct a one point image
	    IA_Set<IA_Point<int> >( IA_Point<int>(im(aPt)) ),
	    1 );
}


template <class I>
IA_ClosureDT<IA_Image<IA_Point<int>,int> > *
IA_HistogramTemplate<I>::clone_self() const {
    return new IA_HistogramTemplate<I>(this->im);
}


template <class I>
ostream &
IA_HistogramTemplate<I>::print_this(ostream &o) const {

    // Define an iterator over the histogram template point set
    IA_PSIter< IA_Point<int> >
	htIter( (this->im).domain() );

    IA_Point<int>
	iPt;

    while ( htIter( iPt ) ) {  // for each point in the domain
	o   << "(" << iPt << ","
	    << this->operator()(iPt)  // range value is an image
	    << ")";
    }
    return o;
}


template <class I>
IA_Image<IA_Point<int>,int>
histogram( const I & a ) {

    // Declare h as the histogram template of image a
    IA_HistogramTemplate<I>
	h(a);

    // The point set of the resultant histogram is:
    IA_Set<IA_Point<int> >
	a_histogram_ps = IA_boxy_pset( IA_Point<int>(min(a)),
				       IA_Point<int>(max(a)) );

    // The actual histogram is simply the sum of the histogram template,
    //   which we know has a domain over the previously defined point set.
    //
    // A subtlety of the usage of the template sum() function below is
    //   that there is no exact match for these arguments.
    //   However, it works because there is a constructor for
    //   template closure classes to make them IA_DDTemplate<I> objects.
    //   Thus the argument  h  get automagically converted.
    //
    return
	sum( a.domain(), h, a_histogram_ps );
}



//////////////////////////////////////////////////////////////////
//
// class IA_CumulativeHistogramTemplate<I>
//
//////////////////////////////////////////////////////////////////


template <class I>
class
IA_CumulativeHistogramTemplate:
public IA_ClosureDT<IA_Image<IA_Point<int>,int> > {

private:
    I im;

public:
    IA_CumulativeHistogramTemplate( const I &inImage )
    : IA_ClosureDT<IA_Image<IA_Point<int>,int> >(inImage.domain()),
      im(inImage) {}
    
    IA_Image<IA_Point<int>,int>  operator() (const IA_Point<int> &aPt) const;
    
    IA_ClosureDT<IA_Image<IA_Point<int>,int> > *clone_self() const;
    
    ostream &print_this(ostream &o) const;
};



template <class I>
IA_Image<IA_Point<int>,int>
IA_CumulativeHistogramTemplate<I>::
operator() (const IA_Point<int> &aPt) const
{
    // Return an image which indicates this value should be include
    // for all values >= im(aPt).
    return
	IA_Image<IA_Point<int>,int>(
	    IA_Set<IA_Point<int> >( IA_Point<int>(im(aPt)),
			    IA_Point<int>(max(im)) ),
	    1 );
}


template <class I>
IA_ClosureDT<IA_Image<IA_Point<int>,int> > *
IA_CumulativeHistogramTemplate<I>::clone_self() const {
    return new IA_CumulativeHistogramTemplate<I>(this->im);
}


template <class I>
ostream & IA_CumulativeHistogramTemplate<I>::print_this(ostream &o) const {

    IA_PSIter<IA_Point<int> >
	htIter( (this->im).domain() );

    IA_Point<int>          iPt;

    while ( htIter( iPt ) ) {  // for each point in the domain
	o   << "(" << iPt << ","
	    << this->operator()(iPt)  // range value is an image
	    << ") ";
    }
    return o;
}


template <class I>
IA_Image<IA_Point<int>,int>
cumulative_histogram( const I & a ) {
    IA_DDTemplate<IA_Image<IA_Point<int>,int> >
	ch( IA_CumulativeHistogramTemplate<I>(a) );

    // The point set of the resultant histogram is:
    IA_Set<IA_Point<int> >
	a_cumhistogram_ps = IA_boxy_pset( IA_Point<int>(min(a)),
					  IA_Point<int>(max(a)) );

    return
	sum( a.domain(), ch, a_cumhistogram_ps );

    return a_cumhistogram;
}
@


1.2
log
@Modified include files to be iac++ v2.0 compliant.
@
text
@d1 1
a1 1
// histogram.c          Section: 9.3 & 9.4
d4 1
@


1.1
log
@Initial revision
@
text
@d12 2
a13 2
#include "IntConvolutions.h"
#include "UcharConvolutions.h"
@
