|
degate 0.1.1
|
#include <LineSegmentExtraction.h>
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 |
Line segment map.
Definition at line 118 of file LineSegmentExtraction.h.
| 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.
| typedef std::list<LineSegment_shptr> degate::LineSegmentMap::list_type |
Definition at line 121 of file LineSegmentExtraction.h.
| degate::LineSegmentMap::LineSegmentMap | ( | ) | [inline] |
Definition at line 131 of file LineSegmentExtraction.h.
{ }
| void degate::LineSegmentMap::add | ( | LineSegment_shptr | segment | ) | [inline] |
Definition at line 142 of file LineSegmentExtraction.h.
References lines.
{
lines.push_back(segment);
}
| iterator degate::LineSegmentMap::begin | ( | ) | [inline] |
| const_iterator degate::LineSegmentMap::begin | ( | ) | const [inline] |
| const_iterator degate::LineSegmentMap::end | ( | ) | const [inline] |
| iterator degate::LineSegmentMap::end | ( | ) | [inline] |
| void degate::LineSegmentMap::erase | ( | LineSegment_shptr | segment | ) | [inline] |
| void degate::LineSegmentMap::erase | ( | iterator | iter | ) | [inline] |
| 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();
}


| 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);
}
}

| size_t degate::LineSegmentMap::size | ( | ) | const [inline] |
| 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();
}
list_type degate::LineSegmentMap::lines [private] |
1.7.4