degate  0.1.2
Classes | Public Member Functions | Private Member Functions | Private Attributes
degate::ViaMatching Class Reference

#include <ViaMatching.h>

Inheritance diagram for degate::ViaMatching:
Inheritance graph

List of all members.


struct  match_found

Public Member Functions

 ViaMatching ()
virtual void init (BoundingBox const &bounding_box, Project_shptr project)
InvalidPointerExceptionThis exception is thrown, if project is an invalid pointer.

virtual void run ()
 Run the algorithm.
void set_threshold_match (double threshold_match)
void set_merge_n_vias (unsigned int merge_n_vias)
double get_threshold_match () const
unsigned int get_merge_n_vias () const
void set_diameter (unsigned int diameter)
 Set the diameter for vias.

Private Member Functions

void scan (BoundingBox const &bbox, BackgroundImage_shptr bg_img, MemoryImage_GS_BYTE_shptr tmpl_img, Via::DIRECTION direction)
bool add_via (unsigned int x, unsigned int y, unsigned int diameter, Via::DIRECTION direction, double corr_val, double threshold_hc)

Private Attributes

Layer_shptr layer
LogicModel_shptr lmodel
double threshold_match
unsigned int via_diameter
unsigned int merge_n_vias
BackgroundImage_shptr img
BoundingBox bounding_box

Detailed Description

Definition at line 32 of file ViaMatching.h.

Constructor & Destructor Documentation

Definition at line 31 of file

  threshold_match(0.9) {

Member Function Documentation

bool ViaMatching::add_via ( unsigned int  x,
unsigned int  y,
unsigned int  diameter,
Via::DIRECTION  direction,
double  corr_val,
double  threshold_hc 
) [private]

Definition at line 201 of file

References layer, and lmodel.

Referenced by scan().


  if(!layer->exists_type_in_region<Via>(x, x + diameter,
                                        y, y + diameter)) {

    Via_shptr via(new Via(x + diameter/2, y + diameter/2, diameter, direction));

    char dsc[100];
    snprintf(dsc, sizeof(dsc), "matched with corr=%.2f t_hc=%.2f", corr_val, threshold_hc);

    lmodel->add_object(layer, via);
    return true;
  return false;

Here is the caller graph for this function:

unsigned int ViaMatching::get_merge_n_vias ( ) const

Definition at line 77 of file

References merge_n_vias.

  return merge_n_vias;

Definition at line 73 of file

References threshold_match.

  return threshold_match;
void ViaMatching::init ( BoundingBox const &  bounding_box,
Project_shptr  project 
) [virtual]

InvalidPointerExceptionThis exception is thrown, if project is an invalid pointer.

DegateRuntimeExceptionThis exception is thrown, if there is no current layer in the logic model. This should not happen.

Implements degate::Matching.

Definition at line 36 of file

References bounding_box, img, layer, lmodel, and degate::ProgressControl::reset_progress().


  this->bounding_box = bounding_box;

  if(project == NULL)
    throw InvalidPointerException("Invalid pointer for parameter project.");

  lmodel = project->get_logic_model();
  assert(lmodel != NULL); // always has a logic model

  layer = lmodel->get_current_layer();
  if(layer == NULL)
    throw DegateRuntimeException("No current layer in project.");

  ScalingManager_shptr sm = layer->get_scaling_manager();
  assert(sm != NULL);

  img = sm->get_image(1).second;
  assert(img != NULL);


Here is the call graph for this function:

void ViaMatching::run ( ) [virtual]

Run the algorithm.

DegateLogicExceptionThis exception is thrown, if the diameter was not set.

Implements degate::Matching.

Definition at line 81 of file

References bounding_box, degate::copy_image(), debug(), degate::Via::DIRECTION_DOWN, degate::Via::DIRECTION_UP, degate::BoundingBox::get_height(), img, degate::join_pathes(), layer, lmodel, degate::merge_images(), merge_n_vias, degate::save_image(), scan(), degate::ProgressControl::set_progress_step_size(), TM, and via_diameter.


  if(via_diameter == 0) throw DegateLogicException("Parameter via diameter was not set.");

  unsigned int max_r = 0;

  // lists for images of vias on the current layer
  std::list<MemoryImage_shptr> vias_up, vias_down;

  // iterate over all placed vias (current layer) and determine their size
  for(LogicModel::via_collection::iterator viter = lmodel->vias_begin();
      viter != lmodel->vias_end(); ++viter) {
    Via_shptr via = viter->second;
    if(via->get_layer() == layer && via->get_diameter() > max_r) 
      max_r = via->get_diameter();
  debug(TM, "via matching: max diameter for image averaging: %d", max_r);
  int max_count_up = merge_n_vias, max_count_down = merge_n_vias;
  max_r = (max_r + 1) / 2;

  // iterate over all placed vias (current layer) and calculate a mean-image
  for(LogicModel::via_collection::iterator viter = lmodel->vias_begin();
      viter != lmodel->vias_end(); ++viter) {
    Via_shptr via = viter->second;

    if(via->get_layer() == layer) {
      // calculate new bounding box
      BoundingBox bb(via->get_x() - max_r, via->get_x() + max_r,
                     via->get_y() - max_r, via->get_y() + max_r);

      if(layer->get_bounding_box().complete_within(bb)) {

        // grab via's image
        MemoryImage_shptr img = grab_image<MemoryImage>(lmodel, layer, bb);
        assert(img != NULL);
        // insert image into one of the lists
        if(via->get_direction() == Via::DIRECTION_UP && 
           (merge_n_vias == 0 ? true : max_count_up-- > 0)) {
        else if(via->get_direction() == Via::DIRECTION_DOWN && 
                (merge_n_vias == 0 ? true : max_count_down-- > 0))
      else debug(TM, "via out of region");

  debug(TM, "via matching: size of vias_down=%d vias_up=%d", vias_down.size(), vias_up.size());

  // calculate the mean-image
  MemoryImage_shptr via_up = merge_images(vias_up);
  MemoryImage_shptr via_down = merge_images(vias_down);

  // save images for debugging
  if(via_up) save_image(join_pathes("/tmp", "01_via_up_merged.tif"), via_up);
  if(via_down) save_image(join_pathes("/tmp", "01_via_down_merged.tif"), via_down);

  // convert to greyscale
  MemoryImage_GS_BYTE_shptr via_up_gs, via_down_gs;

  if(via_up) {
    via_up_gs = MemoryImage_GS_BYTE_shptr(new MemoryImage_GS_BYTE(via_up->get_width(), via_up->get_height()));
    copy_image(via_up_gs, via_up);

  if(via_down) {
    via_down_gs = MemoryImage_GS_BYTE_shptr(new MemoryImage_GS_BYTE(via_down->get_width(), via_down->get_height()));
    copy_image(via_down_gs, via_down);

  // save images for debugging
  if(via_up_gs) save_image(join_pathes("/tmp", "02_via_up_gs.tif"), via_up_gs);
  if(via_down_gs) save_image(join_pathes("/tmp", "02_via_down_gs.tif"), via_down_gs);

  // set progress step size
  int substeps = 0;
  if(via_up_gs) substeps++;
  if(via_down_gs) substeps++;
  if(substeps > 0) set_progress_step_size(1.0/( substeps * (bounding_box.get_height()-max_r*2) ));

  // run via matching
  if(via_up_gs) scan(bounding_box, img, via_up_gs, Via::DIRECTION_UP);
  if(via_down_gs) scan(bounding_box, img, via_down_gs, Via::DIRECTION_DOWN);


Here is the call graph for this function:

void ViaMatching::scan ( BoundingBox const &  bbox,
BackgroundImage_shptr  bg_img,
MemoryImage_GS_BYTE_shptr  tmpl_img,
Via::DIRECTION  direction 
) [private]

Definition at line 221 of file

References add_via(), degate::average_and_stddev(), calc_xcorr(), compare_correlation(), degate::ViaMatching::match_found::correlation, debug(), degate::BoundingBox::get_max_x(), degate::BoundingBox::get_max_y(), degate::BoundingBox::get_min_x(), degate::BoundingBox::get_min_y(), degate::ProgressControl::is_canceled(), degate::ProgressControl::progress_step_done(), degate::ProgressControl::reset_progress(), threshold_match, TM, via_diameter, degate::ViaMatching::match_found::x, and degate::ViaMatching::match_found::y.

Referenced by run().


  std::list<match_found> matches;
  debug(TM, "run scanning");
  double f_avg, sigma_f;
  double t_avg, sigma_t;
  average_and_stddev(tmpl_img, 0, 0, 
                     tmpl_img->get_width(), tmpl_img->get_height(), 
                     &t_avg, &sigma_t);

  assert(bbox.get_max_x() >= 0);
  assert(bbox.get_max_y() >= 0);

  int max_x = static_cast<unsigned int>(bbox.get_max_x()) > tmpl_img->get_width() ? 
    bbox.get_max_x() - tmpl_img->get_width() : bbox.get_min_x();
  int max_y = static_cast<unsigned int>(bbox.get_max_y()) > tmpl_img->get_height() ? 
    bbox.get_max_y() - tmpl_img->get_height() : bbox.get_min_y();

  for(int y = bbox.get_min_y(); y < max_y; y++) {
    for(int x = bbox.get_min_x(); x < max_x; x++) {

      average_and_stddev(bg_img, x, y, 
                         tmpl_img->get_width(), tmpl_img->get_height(), 
                         &f_avg, &sigma_f);

      double xcorr = calc_xcorr(x, y,
                                bg_img, f_avg, sigma_f,
                                tmpl_img, t_avg, sigma_t);

      if(xcorr > threshold_match) {
        match_found m;
        m.x = x;
        m.y = y;
        m.correlation = xcorr;

        //debug(TM, "%d,%d -> %f sigma-f=%f sigma-t=%f f_avg=%f t_avg=%f", x, y, xcorr, sigma_f,sigma_t, f_avg, sigma_f);       

    // update progress

    // check if scanning was canceled
    if(is_canceled()) {


  BOOST_FOREACH(match_found const& m, matches) {
    add_via(m.x, m.y, via_diameter, direction, m.correlation, threshold_match);


Here is the call graph for this function:

Here is the caller graph for this function:

void ViaMatching::set_diameter ( unsigned int  diameter)

Set the diameter for vias.

Definition at line 61 of file

References via_diameter.

  via_diameter = diameter;
void ViaMatching::set_merge_n_vias ( unsigned int  merge_n_vias)

Definition at line 69 of file

References merge_n_vias.

  this->merge_n_vias = merge_n_vias;
void ViaMatching::set_threshold_match ( double  threshold_match)

Definition at line 65 of file

References threshold_match.

Member Data Documentation

Definition at line 43 of file ViaMatching.h.

Referenced by init(), and run().

Definition at line 41 of file ViaMatching.h.

Referenced by init(), and run().

Definition at line 36 of file ViaMatching.h.

Referenced by add_via(), init(), and run().

Definition at line 37 of file ViaMatching.h.

Referenced by add_via(), init(), and run().

unsigned int degate::ViaMatching::merge_n_vias [private]

Definition at line 40 of file ViaMatching.h.

Referenced by get_merge_n_vias(), run(), and set_merge_n_vias().

Definition at line 39 of file ViaMatching.h.

Referenced by get_threshold_match(), scan(), and set_threshold_match().

unsigned int degate::ViaMatching::via_diameter [private]

Definition at line 40 of file ViaMatching.h.

Referenced by run(), scan(), and set_diameter().

The documentation for this class was generated from the following files: