DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
//======================================================================= // Copyright 2007 Aaron Windsor // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= #ifndef __IS_STRAIGHT_LINE_DRAWING_HPP__ #define __IS_STRAIGHT_LINE_DRAWING_HPP__ #include
#include
//for next and prior #include
#include
#include
#include
#include
#include
#include
#include
namespace boost { // Return true exactly when the line segments s1 = ((x1,y1), (x2,y2)) and // s2 = ((a1,b1), (a2,b2)) intersect in a point other than the endpoints of // the line segments. The one exception to this rule is when s1 = s2, in // which case false is returned - this is to accomodate multiple edges // between the same pair of vertices, which shouldn't invalidate the straight // line embedding. A tolerance variable epsilon can also be used, which // defines how far away from the endpoints of s1 and s2 we want to consider // an intersection. bool intersects(double x1, double y1, double x2, double y2, double a1, double b1, double a2, double b2, double epsilon = 0.000001 ) { if (x1 - x2 == 0) { std::swap(x1,a1); std::swap(y1,b1); std::swap(x2,a2); std::swap(y2,b2); } if (x1 - x2 == 0) { BOOST_USING_STD_MAX(); BOOST_USING_STD_MIN(); //two vertical line segments double min_y = min BOOST_PREVENT_MACRO_SUBSTITUTION(y1,y2); double max_y = max BOOST_PREVENT_MACRO_SUBSTITUTION(y1,y2); double min_b = min BOOST_PREVENT_MACRO_SUBSTITUTION(b1,b2); double max_b = max BOOST_PREVENT_MACRO_SUBSTITUTION(b1,b2); if ((max_y > max_b && max_b > min_y) || (max_b > max_y && max_y > min_b) ) return true; else return false; } double x_diff = x1 - x2; double y_diff = y1 - y2; double a_diff = a2 - a1; double b_diff = b2 - b1; double beta_denominator = b_diff - (y_diff/((double)x_diff)) * a_diff; if (beta_denominator == 0) { //parallel lines return false; } double beta = (b2 - y2 - (y_diff/((double)x_diff)) * (a2 - x2)) / beta_denominator; double alpha = (a2 - x2 - beta*(a_diff))/x_diff; double upper_bound = 1 - epsilon; double lower_bound = 0 + epsilon; return (beta < upper_bound && beta > lower_bound && alpha < upper_bound && alpha > lower_bound); } template
bool is_straight_line_drawing(const Graph& g, GridPositionMap drawing, VertexIndexMap vm ) { typedef typename graph_traits
::vertex_descriptor vertex_t; typedef typename graph_traits
::vertex_iterator vertex_iterator_t; typedef typename graph_traits
::edge_descriptor edge_t; typedef typename graph_traits
::edge_iterator edge_iterator_t; typedef typename graph_traits
::edges_size_type e_size_t; typedef typename graph_traits
::vertices_size_type v_size_t; typedef std::size_t x_coord_t; typedef std::size_t y_coord_t; typedef boost::tuple
edge_event_t; typedef typename std::vector< edge_event_t > edge_event_queue_t; typedef tuple
active_map_key_t; typedef edge_t active_map_value_t; typedef std::map< active_map_key_t, active_map_value_t > active_map_t; typedef typename active_map_t::iterator active_map_iterator_t; edge_event_queue_t edge_event_queue; active_map_t active_edges; edge_iterator_t ei, ei_end; for(tie(ei,ei_end) = edges(g); ei != ei_end; ++ei) { edge_t e(*ei); vertex_t s(source(e,g)); vertex_t t(target(e,g)); edge_event_queue.push_back (make_tuple(e, static_cast
(drawing[s].x), static_cast
(drawing[s].y) ) ); edge_event_queue.push_back (make_tuple(e, static_cast
(drawing[t].x), static_cast
(drawing[t].y) ) ); } // Order by edge_event_queue by first, then second coordinate // (bucket_sort is a stable sort.) bucket_sort(edge_event_queue.begin(), edge_event_queue.end(), property_map_tuple_adaptor
() ); bucket_sort(edge_event_queue.begin(), edge_event_queue.end(), property_map_tuple_adaptor
() ); typedef typename edge_event_queue_t::iterator event_queue_iterator_t; event_queue_iterator_t itr_end = edge_event_queue.end(); for(event_queue_iterator_t itr = edge_event_queue.begin(); itr != itr_end; ++itr ) { edge_t e(get<0>(*itr)); vertex_t source_v(source(e,g)); vertex_t target_v(target(e,g)); if (drawing[source_v].x > drawing[target_v].x) std::swap(source_v, target_v); active_map_key_t key(get(drawing, source_v).y, get(drawing, target_v).y, get(drawing, source_v).x, get(drawing, target_v).x ); active_map_iterator_t a_itr = active_edges.find(key); if (a_itr == active_edges.end()) { active_edges[key] = e; } else { active_map_iterator_t before, after; if (a_itr == active_edges.begin()) before = active_edges.end(); else before = prior(a_itr); after = next(a_itr); if (after != active_edges.end() || before != active_edges.end()) { edge_t f = after != active_edges.end() ? after->second : before->second; vertex_t e_source(source(e,g)); vertex_t e_target(target(e,g)); vertex_t f_source(source(f,g)); vertex_t f_target(target(f,g)); if (intersects(drawing[e_source].x, drawing[e_source].y, drawing[e_target].x, drawing[e_target].y, drawing[f_source].x, drawing[f_source].y, drawing[f_target].x, drawing[f_target].y ) ) return false; } active_edges.erase(a_itr); } } return true; } template
bool is_straight_line_drawing(const Graph& g, GridPositionMap drawing) { return is_straight_line_drawing(g, drawing, get(vertex_index,g)); } } #endif // __IS_STRAIGHT_LINE_DRAWING_HPP__
is_straight_line_drawing.hpp
Page URL
File URL
Prev
46/95
Next
Download
( 7 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.