Cluster1.C


/*
file      Cluster1.C
date      Wed Apr 17 19:04:31 1996
author    Paul Walker
desc      A 1D "clustering" algorithm. 1D clustering is really easy. 
          So this is really short.
          Clusters a grid function flag into a list of bounding
          boxes result. Assume flag is a 1D real array
          with values of 0.0 or 1.0 for flag or no flag.
*/

#include "DAGH.h"

void Cluster1(GridData(1)<short> &flag,
	      double Efficiency,
	      int MinWidth,
	      int BufferWidth,
	      BBoxList &result) {
  GridData(1)<short> newflag(flag.bbox());
  int l=-1, u=-1;

  /* First buffer! */
  newflag = 0;

  for_1(i,flag.bbox(),flag.bbox().stepsize()) 
    if (flag(i)) {
      BBox where(1,i,i,flag.bbox().stepsize(0));
      where.grow(BufferWidth);
      newflag.equals(1.0, where);
    }
  end_for;

  /* Now just step along looking for zero crossings or end of
     the thing.  This defines our BBox */
  if (newflag(newflag.bbox().lower(0))) {
    l = newflag.bbox().lower(0);
  }
  int i;
  for (i=newflag.bbox().lower(0)+newflag.bbox().stepsize(0); 
       i < newflag.bbox().upper(0); 
       i+= newflag.bbox().stepsize(0)) {
    if (newflag(i) && !newflag(i-newflag.bbox().stepsize(0))) {
      l = i;
    }
    if (!newflag(i) && newflag(i-newflag.bbox().stepsize(0))) {
      u = i-newflag.bbox().stepsize(0);
      if (u-l > MinWidth) {
	BBox add(1,l,u,newflag.bbox().stepsize(0));
	result.add(add);
      } 
    }
  }
  if (u < l) {
    u = newflag.bbox().upper(0);
    BBox add(1,l,u,newflag.bbox().stepsize(0));
    result.add(add);
  }
}


Return to: Tutorial