void operator()(const segment_type& _a, const linestring_type& _b, output_type& _out, JUNCTION _j) { if (_b.empty()) { _out.push_back(_a.front()); _out.push_back(_a.back()); return; } _out.push_back(_a.front()); _j(_a,_b,_out); _out.insert(_out.end(),_a.begin()+1,_a.end()); }
Arrangement segment_cost_characterization( const segment_type & segment ) { /* obtain the level supports of F */ double zerocost = 0. ; // cost of a matching with "zero assistance" map<int, double> level_support ; { int level = 0 ; segment_type::const_iterator lbound, rbound ; for ( rbound = segment.begin(), lbound = rbound++ ; rbound != segment.end() ; lbound++, rbound++ ) { double y1, y2, len ; y1 = lbound->first, y2 = rbound->first, len = y2 - y1 ; const place_data & temp = lbound->second ; level += temp.P_indices.size() - temp.Q_indices.size() ; zerocost += len * abs( level ) ; level_support[level] += len ; } } cout << "supports " << level_support << endl ; /* create a linear arrangement from level supports */ Arrangement value_arr ; //int numlevels = level_support.size() ; //list<vertex_struct> vertex_data ; //list<interval_struct> interval_data ; double length = 0. ; for ( map<int,double>::iterator it = level_support.begin() ; it != level_support.end() ; ++it ) { int f = it->first ; double supp = it->second ; Arrangement::Vertex & v = value_arr.insert( f ) ; v.local_data.support = supp ; length += supp ; } // about to traverse the arrangement Arrangement::Vertex * v_left = & value_arr.vertices.begin()->second ; Arrangement::Vertex * v_zero ; Arrangement::Interval * I_left = & *v_left->left ; // some initialization //interval_data.push_front( interval_struct() ) ; I_left->local_data.slope = length ; // length won't compile... Arrangement::Vertex * v_curr ; Arrangement::Interval * I_curr ; // traverse left-to-right to compute slopes { double slope = I_left->local_data.slope ; v_curr = v_left ; while ( true ) { if ( (int) v_curr->y == 0 ) v_zero = v_curr ; // remember the zero vertex, plox I_curr = & *v_curr->right ; slope -= 2 * v_curr->local_data.support ; I_curr->local_data.slope = slope ; if ( I_curr->right == NULL ) break ; v_curr = I_curr->right ; } } // traverse zero-to-left, then zero-to-right, to obtain offsets { double offset = zerocost ; v_curr = v_zero ; while ( true ) { I_curr = & *v_curr->left ; I_curr->local_data.offset = offset ; offset -= I_curr->local_data.slope * I_curr->length() ; // subtract, since negative direction if ( I_curr->left == NULL ) break ; v_curr = I_curr->left ; } } { double offset = zerocost ; v_curr = v_zero ; while ( true ) { I_curr = & *v_curr->right ; I_curr->local_data.offset = offset ; offset += I_curr->local_data.slope * I_curr->length() ; // add, since positive direction if ( I_curr->right == NULL ) break ; v_curr = I_curr->right ; } } return value_arr ; }