Parallel Plane Sweep  0.1
Shared memory multithreaded version of the plane sweep algorithm
halfsegment.h
Go to the documentation of this file.
1 /*
2  * The MIT License (MIT)
3  * Copyright (c) <2016> <Mark McKenney>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6  *
7  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10  * */
11 
12 
13 #include <iostream>
14 #ifndef HALFSEGMENT_H
15 #define HALFSEGMENT_H
16 
17 //#define DEBUG_PRINT
18 
19 using namespace std;
20 
30 inline bool leftHandturn( double p1x, double p1y, double p2x, double p2y, double p3x, double p3y )
31 {
32  // returns true if when you start at p1, and walk towards p2, you have to make a left turn
33  // at p2 in order to continue walking to p3
34  return( ( ((p3y - p1y) * (p2x - p1x)) - ((p2y - p1y) * (p3x - p1x)) ) > 0 );
35 }
36 
37 
56 struct halfsegment {
58  double dx, dy, sx, sy;
60  int la, lb;
62  int stripID;
63  // the region this seg nelongs to
64  int regionID;
66  int ola, olb;
67 
71 halfsegment():dx( 0 ), dy(0), sx(0), sy(0), la(-1), lb(-1),
72  stripID(-1), regionID( -1 ), ola( -1 ), olb( -1 )
73  { }
74 
78 halfsegment( const halfsegment &rhs ): dx(rhs.dx), dy(rhs.dy),
79  sx(rhs.sx), sy(rhs.sy),
80  la(rhs.la), lb(rhs.lb),
81  stripID( rhs.stripID), regionID( rhs.regionID ),
82  ola( rhs.ola ), olb( rhs.olb )
83  { }
84 
85 
89  bool isLeft( ) const {
90  return( dx < sx || (dx == sx && dy < sy ) );
91  }
92 
97  halfsegment tmp( *this );
98  tmp.dx = sx;
99  tmp.dy = sy;
100  tmp.sx = dx;
101  tmp.sy = dy;
102  return tmp;
103  }
104 
112  bool operator==( const halfsegment &rhs ) const {
113  return dx == rhs.dx && dy == rhs.dy && sx == rhs.sx && sy == rhs.sy;
114  }
115 
124  bool operator<( const halfsegment &rhs ) const {
125  if( dx < rhs.dx || (dx == rhs.dx && dy < rhs.dy ) ) return true;
126  else if( dx == rhs.dx && dy == rhs.dy ) {
127  // dom points the same
128  if( isLeft() != rhs.isLeft( ) ) return !isLeft();
129  // both left or right hsegs
130  else if( this->colinear( rhs ) && (sx < rhs.sx || (sx == rhs.sx && sy < rhs.sy)) ) return true;
131  else if( leftHandturn( dx, dy, sx, sy, rhs.sx, rhs.sy ) ) return true;
132  }
133  return false;
134  }
135 
141  inline bool colinear( const halfsegment &rhs) const {
142  return 0 == ( ((rhs.dy - dy) * (sx - dx)) - ((sy - dy) * (rhs.dx - dx)) ) &&
143  0 == ( ((rhs.sy - dy) * (sx - dx)) - ((sy - dy) * (rhs.sx - dx)) ) ;
144  }
145 
155  double getYvalAtX( const double x ) const
156  {
157  if( x == dx ) return dy;
158  else if( x == sx ) return sy;
159  return( ( (sy*x - sy*dx - dy*x + dy*dx) / float((sx-dx))) + dy );
160  }
161 
165  friend ostream & operator<<( ostream & out, const halfsegment & rhs ) {
166  cerr <<"[(" << rhs.dx << "," << rhs.dy << ")(" << rhs.sx << "," << rhs.sy << ") " << rhs.la << ", " << rhs.lb << ", " << rhs.regionID << " <" << rhs.ola <<","<<rhs.olb<<">"<< "]";
167  return out;
168  }
169 
170 };
171 #endif
172 
173 
int ola
overlap labels.
Definition: parPlaneSweep.h:87
bool colinear(const halfsegment &rhs) const
Definition: halfsegment.h:141
holds a single halfsegment, along with labeling information and information indicating if the opposin...
Definition: parPlaneSweep.h:76
int regionID
The region the seg belongs to.
Definition: parPlaneSweep.h:85
bool leftHandturn(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y)
Definition: halfsegment.h:30
double getYvalAtX(const double x) const
Definition: halfsegment.h:155
bool operator<(const halfsegment &rhs) const
Definition: halfsegment.h:124
bool isLeft() const
Definition: halfsegment.h:89
double dx
dominating and submissive points
Definition: parPlaneSweep.h:79
int la
label above, label below
Definition: parPlaneSweep.h:81
friend ostream & operator<<(ostream &out, const halfsegment &rhs)
Definition: halfsegment.h:165
halfsegment(const halfsegment &rhs)
Definition: halfsegment.h:78
halfsegment getBrother() const
Definition: halfsegment.h:96
bool operator==(const halfsegment &rhs) const
Definition: halfsegment.h:112