tesseract  3.03
C_BLOB Class Reference

#include <stepblob.h>

Inheritance diagram for C_BLOB:
ELIST_LINK

List of all members.

Public Member Functions

 C_BLOB ()
 C_BLOB (C_OUTLINE_LIST *outline_list)
 C_BLOB (C_OUTLINE *outline)
void CheckInverseFlagAndDirection ()
C_OUTLINE_LIST * out_list ()
TBOX bounding_box ()
inT32 area ()
inT32 perimeter ()
inT32 outer_area ()
inT32 count_transitions (inT32 threshold)
void move (const ICOORD vec)
void rotate (const FCOORD &rotation)
void ComputeEdgeOffsets (int threshold, Pix *pix)
inT16 EstimateBaselinePosition ()
Pix * render ()
Pix * render_outline ()
void plot (ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
void plot_normed (const DENORM &denorm, ScrollView::Color blob_colour, ScrollView::Color child_colour, ScrollView *window)
C_BLOBoperator= (const C_BLOB &source)

Static Public Member Functions

static void ConstructBlobsFromOutlines (bool good_blob, C_OUTLINE_LIST *outline_list, C_BLOB_IT *good_blobs_it, C_BLOB_IT *bad_blobs_it)
static C_BLOBFakeBlob (const TBOX &box)
static C_BLOBdeep_copy (const C_BLOB *src)

Detailed Description

Definition at line 30 of file stepblob.h.


Constructor & Destructor Documentation

C_BLOB::C_BLOB ( ) [inline]

Definition at line 33 of file stepblob.h.

             {
    }
C_BLOB::C_BLOB ( C_OUTLINE_LIST *  outline_list) [explicit]

Definition at line 160 of file stepblob.cpp.

                                           {
  for (C_OUTLINE_IT ol_it(outline_list); !ol_it.empty(); ol_it.forward()) {
    C_OUTLINE* outline = ol_it.extract();
    // Position this outline in appropriate position in the hierarchy.
    position_outline(outline, &outlines);
  }
  CheckInverseFlagAndDirection();
}
C_BLOB::C_BLOB ( C_OUTLINE outline) [explicit]

Definition at line 171 of file stepblob.cpp.

                                 {
  C_OUTLINE_IT it(&outlines);
  it.add_to_end(outline);
}

Member Function Documentation

Definition at line 269 of file stepblob.cpp.

                   {  //area
  C_OUTLINE *outline;            //current outline
  C_OUTLINE_IT it = &outlines;   //outlines of blob
  inT32 total;                   //total area

  total = 0;
  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
    outline = it.data ();
    total += outline->area ();
  }
  return total;
}

Definition at line 250 of file stepblob.cpp.

                          {  //bounding box
  C_OUTLINE *outline;            //current outline
  C_OUTLINE_IT it = &outlines;   //outlines of blob
  TBOX box;                       //bounding box

  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
    outline = it.data ();
    box += outline->bounding_box ();
  }
  return box;
}

Definition at line 221 of file stepblob.cpp.

                                          {
  C_OUTLINE_IT ol_it(&outlines);
  for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
    C_OUTLINE* outline = ol_it.data();
    if (outline->turn_direction() < 0) {
      outline->reverse();
      reverse_outline_list(outline->child());
      outline->set_flag(COUT_INVERSE, TRUE);
    } else {
      outline->set_flag(COUT_INVERSE, FALSE);
    }
  }
}
void C_BLOB::ComputeEdgeOffsets ( int  threshold,
Pix *  pix 
)

Definition at line 408 of file stepblob.cpp.

                                                       {
  ComputeEdgeOffsetsOutlineList(threshold, pix, &outlines);
}
void C_BLOB::ConstructBlobsFromOutlines ( bool  good_blob,
C_OUTLINE_LIST *  outline_list,
C_BLOB_IT *  good_blobs_it,
C_BLOB_IT *  bad_blobs_it 
) [static]

Definition at line 186 of file stepblob.cpp.

                                                                 {
  // List of top-level outlines with correctly nested children.
  C_OUTLINE_LIST nested_outlines;
  for (C_OUTLINE_IT ol_it(outline_list); !ol_it.empty(); ol_it.forward()) {
    C_OUTLINE* outline = ol_it.extract();
    // Position this outline in appropriate position in the hierarchy.
    position_outline(outline, &nested_outlines);
  }
  // Check for legal nesting and reassign as required.
  for (C_OUTLINE_IT ol_it(&nested_outlines); !ol_it.empty(); ol_it.forward()) {
    C_OUTLINE* outline = ol_it.extract();
    bool blob_is_good = good_blob;
    if (!outline->IsLegallyNested()) {
      // The blob is illegally nested.
      // Mark it bad, and add all its children to the top-level list.
      blob_is_good = false;
      ol_it.add_list_after(outline->child());
    }
    C_BLOB* blob = new C_BLOB(outline);
    // Set inverse flag and reverse if needed.
    blob->CheckInverseFlagAndDirection();
    // Put on appropriate list.
    if (!blob_is_good && bad_blobs_it != NULL)
      bad_blobs_it->add_after_then_move(blob);
    else
      good_blobs_it->add_after_then_move(blob);
  }
}

Definition at line 329 of file stepblob.cpp.

                                 {
  C_OUTLINE *outline;            //current outline
  C_OUTLINE_IT it = &outlines;   //outlines of blob
  inT32 total;                   //total area

  total = 0;
  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
    outline = it.data ();
    total += outline->count_transitions (threshold);
  }
  return total;
}
static C_BLOB* C_BLOB::deep_copy ( const C_BLOB src) [inline, static]

Definition at line 113 of file stepblob.h.

                                                {
      C_BLOB* blob = new C_BLOB;
      *blob = *src;
      return blob;
    }

Definition at line 426 of file stepblob.cpp.

                                       {
  TBOX box = bounding_box();
  int left = box.left();
  int width = box.width();
  int bottom = box.bottom();
  if (outlines.empty() || perimeter() > width * kMaxPerimeterWidthRatio)
    return bottom;  // This is only for non-CJK blobs.
  // Get the minimum y coordinate at each x-coordinate.
  GenericVector<int> y_mins;
  y_mins.init_to_size(width + 1, box.top());
  C_OUTLINE_IT it(&outlines);
  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
    C_OUTLINE* outline = it.data();
    ICOORD pos = outline->start_pos();
    for (int s = 0; s < outline->pathlength(); ++s) {
      if (pos.y() < y_mins[pos.x() - left])
        y_mins[pos.x() - left] = pos.y();
      pos += outline->step(s);
    }
  }
  // Find the total extent of the bottom or bottom + 1.
  int bottom_extent = 0;
  for (int x = 0; x <= width; ++x) {
    if (y_mins[x] == bottom || y_mins[x] == bottom + 1)
      ++bottom_extent;
  }
  // Find the lowest run longer than the bottom extent that is not the bottom.
  int best_min = box.top();
  int prev_run = 0;
  int prev_y = box.top();
  int prev_prev_y = box.top();
  for (int x = 0; x < width; x += prev_run) {
    // Find the length of the current run.
    int y_at_x = y_mins[x];
    int run = 1;
    while (x + run <= width && y_mins[x + run] == y_at_x) ++run;
    if (y_at_x > bottom + 1) {
      // Possible contender.
      int total_run = run;
      // Find extent of current value or +1 to the right of x.
      while (x + total_run <= width &&
          (y_mins[x + total_run] == y_at_x ||
              y_mins[x + total_run] == y_at_x + 1)) ++total_run;
      // At least one end has to be higher so it is not a local max.
      if (prev_prev_y > y_at_x + 1 || x + total_run > width ||
          y_mins[x + total_run] > y_at_x + 1) {
        // If the prev_run is at y + 1, then we can add that too. There cannot
        // be a suitable run at y before that or we would have found it already.
        if (prev_run > 0 && prev_y == y_at_x + 1) total_run += prev_run;
        if (total_run > bottom_extent && y_at_x < best_min) {
          best_min = y_at_x;
        }
      }
    }
    prev_run = run;
    prev_prev_y = prev_y;
    prev_y = y_at_x;
  }
  return best_min == box.top() ? bottom : best_min;
}
C_BLOB * C_BLOB::FakeBlob ( const TBOX box) [static]

Definition at line 238 of file stepblob.cpp.

                                        {
  C_OUTLINE_LIST outlines;
  C_OUTLINE::FakeOutline(box, &outlines);
  return new C_BLOB(&outlines);
}
void C_BLOB::move ( const ICOORD  vec)

Definition at line 351 of file stepblob.cpp.

                   {
  C_OUTLINE_IT it(&outlines);  // iterator

  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
    it.data ()->move (vec);      // move each outline
}
C_BLOB& C_BLOB::operator= ( const C_BLOB source) [inline]

Definition at line 106 of file stepblob.h.

                                              {
      if (!outlines.empty ())
        outlines.clear();
      outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy);
      return *this;
    }
C_OUTLINE_LIST* C_BLOB::out_list ( ) [inline]

Definition at line 64 of file stepblob.h.

                               {  //get outline list
      return &outlines;
    }

Definition at line 308 of file stepblob.cpp.

                         {  //area
  C_OUTLINE *outline;            //current outline
  C_OUTLINE_IT it = &outlines;   //outlines of blob
  inT32 total;                   //total area

  total = 0;
  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
    outline = it.data ();
    total += outline->outer_area ();
  }
  return total;
}

Definition at line 288 of file stepblob.cpp.

                        {
  C_OUTLINE *outline;            // current outline
  C_OUTLINE_IT it = &outlines;   // outlines of blob
  inT32 total;                   // total perimeter

  total = 0;
  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
    outline = it.data();
    total += outline->perimeter();
  }
  return total;
}
void C_BLOB::plot ( ScrollView window,
ScrollView::Color  blob_colour,
ScrollView::Color  child_colour 
)

Definition at line 531 of file stepblob.cpp.

                                                {  // for holes
  plot_outline_list(&outlines, window, blob_colour, child_colour);
}
void C_BLOB::plot_normed ( const DENORM denorm,
ScrollView::Color  blob_colour,
ScrollView::Color  child_colour,
ScrollView window 
)

Definition at line 539 of file stepblob.cpp.

                                             {
  plot_normed_outline_list(denorm, &outlines, blob_colour, child_colour,
                           window);
}
Pix * C_BLOB::render ( )

Definition at line 508 of file stepblob.cpp.

                    {
  TBOX box = bounding_box();
  Pix* pix = pixCreate(box.width(), box.height(), 1);
  render_outline_list(&outlines, box.left(), box.top(), pix);
  return pix;
}

Definition at line 517 of file stepblob.cpp.

                            {
  TBOX box = bounding_box();
  Pix* pix = pixCreate(box.width(), box.height(), 1);
  render_outline_list_outline(&outlines, box.left(), box.top(), pix);
  return pix;
}
void C_BLOB::rotate ( const FCOORD rotation)

Definition at line 386 of file stepblob.cpp.

                                          {
  RotateOutlineList(rotation, &outlines);
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines