degate  0.1.2
Public Types | Public Member Functions | Private Attributes
degate::LineSegmentMap Class Reference

Line segment map. More...

#include <LineSegmentExtraction.h>

List of all members.

Public Types

typedef std::list
< LineSegment_shptr
list_type
typedef list_type::iterator iterator
typedef list_type::const_iterator const_iterator

Public Member Functions

 LineSegmentMap ()
void erase (iterator iter)
size_t size () const
void add (LineSegment_shptr segment)
void erase (LineSegment_shptr segment)
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
LineSegment_shptr find_adjacent (LineSegment_shptr elem, unsigned int search_radius_along, unsigned int search_radius_across) const
void merge (unsigned int search_radius_along, unsigned int search_radius_across)
void write () const

Private Attributes

list_type lines

Detailed Description

Line segment map.

Definition at line 118 of file LineSegmentExtraction.h.


Member Typedef Documentation

typedef list_type::const_iterator degate::LineSegmentMap::const_iterator

Definition at line 123 of file LineSegmentExtraction.h.

typedef list_type::iterator degate::LineSegmentMap::iterator

Definition at line 122 of file LineSegmentExtraction.h.

Definition at line 121 of file LineSegmentExtraction.h.


Constructor & Destructor Documentation

Definition at line 131 of file LineSegmentExtraction.h.

{ }

Member Function Documentation

void degate::LineSegmentMap::add ( LineSegment_shptr  segment) [inline]

Definition at line 142 of file LineSegmentExtraction.h.

References lines.

                                        {
      lines.push_back(segment);
    }

Definition at line 152 of file LineSegmentExtraction.h.

References lines.

{ return lines.begin(); }

Definition at line 154 of file LineSegmentExtraction.h.

References lines.

{ return lines.begin(); }

Definition at line 153 of file LineSegmentExtraction.h.

References lines.

{ return lines.end(); }

Definition at line 155 of file LineSegmentExtraction.h.

References lines.

{ return lines.end(); }
void degate::LineSegmentMap::erase ( iterator  iter) [inline]

Definition at line 133 of file LineSegmentExtraction.h.

References lines.

                              {
      lines.erase(iter);
    }

Definition at line 146 of file LineSegmentExtraction.h.

References lines.

                                          {
      iterator iter = find(lines.begin(), lines.end(), segment);
      if(iter != lines.end())
        lines.erase(iter);
    }
LineSegment_shptr degate::LineSegmentMap::find_adjacent ( LineSegment_shptr  elem,
unsigned int  search_radius_along,
unsigned int  search_radius_across 
) const [inline]

Definition at line 157 of file LineSegmentExtraction.h.

References degate::Point::get_distance(), degate::Point::get_x(), degate::Point::get_y(), and degate::LinearPrimitive::HORIZONTAL.

Referenced by merge().

                                                                             {

      BOOST_FOREACH(LineSegment_shptr elem2, *this) {
        if(elem != elem2 && elem2->get_orientation() == elem->get_orientation()) {

          Point a1 = elem->get_p1();
          Point a2 = elem->get_p2();
          Point b1 = elem2->get_p1();
          Point b2 = elem2->get_p2();


          if(a1.get_distance(b1) <= search_radius_along ||
             a1.get_distance(b2) <= search_radius_along ||
             a2.get_distance(b1) <= search_radius_along ||
             a2.get_distance(b2) <= search_radius_along) {

            if(elem->get_orientation() == LineSegment::HORIZONTAL) {
              int _min = std::min(a1.get_y(),
                                  std::min(a2.get_y(),
                                           std::min(b1.get_y(), b2.get_y())));
              int _max = std::max(a1.get_y(),
                                  std::max(a2.get_y(),
                                           std::max(b1.get_y(), b2.get_y())));
              if((unsigned int)(_max - _min) < search_radius_across) return elem2;
            }
            else {
              int _min = std::min(a1.get_x(),
                                  std::min(a2.get_x(),
                                           std::min(b1.get_x(), b2.get_x())));
              int _max = std::max(a1.get_x(),
                                  std::max(a2.get_x(),
                                           std::max(b1.get_x(), b2.get_x())));

              if((unsigned int)(_max - _min) < search_radius_across) return elem2;
            }
          }
        }
      }
      return LineSegment_shptr();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void degate::LineSegmentMap::merge ( unsigned int  search_radius_along,
unsigned int  search_radius_across 
) [inline]

Definition at line 200 of file LineSegmentExtraction.h.

References debug(), find_adjacent(), lines, and TM.

                                                  {

      unsigned int counter = 0;
      unsigned int max_rounds = lines.size();
      int distance = 1;
      int max_distance = search_radius_along;
      bool running = lines.size() > 0;

      while(running) {
        debug(TM, "#segments: %d", lines.size());
        running = false;

        LineSegment_shptr ls = lines.front();
        lines.pop_front();

        LineSegment_shptr ls2 = find_adjacent(ls, distance, search_radius_across);
        if(ls2 != NULL) {
          running = true;
          // We could check here if line segments differ in their angles
          ls->merge(ls2);

          iterator found = find(lines.begin(), lines.end(), ls2);
          assert(found != lines.end());
          lines.erase(found);

        }
        else {
          if(counter++ < max_rounds)
            running = true;
          else {
            if(distance <= max_distance) {
              distance++;
              counter = 0;
              running = true;
            }
            else running = false;
          }
        }

        lines.push_back(ls);
      }


    }

Here is the call graph for this function:

size_t degate::LineSegmentMap::size ( ) const [inline]

Definition at line 137 of file LineSegmentExtraction.h.

References lines.

                        {
      return lines.size();
    }
void degate::LineSegmentMap::write ( ) const [inline]

Definition at line 246 of file LineSegmentExtraction.h.

                       {
      std::ofstream myfile;
      myfile.open ("/tmp/example.txt");

      BOOST_FOREACH(LineSegment_shptr e, *this) {
        if(e->get_length() > 0) {
          myfile << "line "
                 << e->get_from_x() << "," << e->get_from_y()
                 << " "
                 << e->get_to_x() << "," << e->get_to_y()
                 << std::endl;
        }

      }
      myfile.close();
    }

Member Data Documentation

Definition at line 127 of file LineSegmentExtraction.h.

Referenced by add(), begin(), end(), erase(), merge(), and size().


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