Skip to content

Commit

Permalink
fixed include; updated API; updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
greenm01 committed Feb 10, 2010
1 parent 60de0b9 commit 660ec61
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 10 deletions.
5 changes: 5 additions & 0 deletions poly2tri/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef UTILS_H
#define UTILS_H

#include <exception>
#include <math.h>
Expand Down Expand Up @@ -95,3 +98,5 @@ bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)

}

#endif

6 changes: 6 additions & 0 deletions poly2tri/poly2tri.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef POLY2TRI_H
#define POLY2TRI_H

#include "common/shapes.h"
#include "sweep/cdt.h"

#endif

5 changes: 5 additions & 0 deletions poly2tri/sweep/advancing_front.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef ADVANCED_FRONT_H
#define ADVANCED_FRONT_H

#include "../common/shapes.h"

namespace p2t {
Expand Down Expand Up @@ -112,3 +116,4 @@ inline void AdvancingFront::set_search(Node* node)

}

#endif
4 changes: 4 additions & 0 deletions poly2tri/sweep/cdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ void CDT::AddHole(std::vector<Point*> polyline)
sweep_context_->AddHole(polyline);
}

void CDT::AddPoint(Point* point) {
sweep_context_->AddPoint(point);
}

void CDT::Triangulate()
{
sweep_->Triangulate(*sweep_context_);
Expand Down
9 changes: 8 additions & 1 deletion poly2tri/sweep/cdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CDT_H
#define CDT_H

#include "advancing_front.h"
#include "sweep_context.h"
#include "sweep.h"
Expand All @@ -42,9 +46,10 @@ class CDT
CDT(std::vector<Point*> polyline);
/// Destructor
~CDT();

/// Add a hole
void AddHole(std::vector<Point*> polyline);
/// Add a single point
void AddPoint(Point* point);
/// Triangulate points
void Triangulate();
/// Get Delaunay triangles
Expand All @@ -60,3 +65,5 @@ Sweep* sweep_;
};

}

#endif
5 changes: 5 additions & 0 deletions poly2tri/sweep/sweep.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
*
* "FlipScan" Constrained Edge Algorithm invented by Thomas Åhlén, [email protected]
*/

#ifndef SWEEP_H
#define SWEEP_H

namespace p2t {

Expand Down Expand Up @@ -113,3 +116,5 @@ void FinalizationPolygon(SweepContext& tcx);
};

}

#endif
11 changes: 8 additions & 3 deletions poly2tri/sweep/sweep_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sweep_context.h"
#include <algorithm>
#include <GL/glfw.h>

#include "sweep_context.h"
#include "advancing_front.h"
#include <iostream>

namespace p2t {

SweepContext::SweepContext(std::vector<Point*> polyline)
{
basin = Basin();
edge_event = EdgeEvent();

points_ = polyline;

InitEdges(points_);
}

Expand All @@ -52,6 +53,10 @@ void SweepContext::AddHole(std::vector<Point*> polyline)
}
}

void SweepContext::AddPoint(Point* point) {
points_.push_back(point);
}

std::vector<Triangle*> SweepContext::GetTriangles()
{
return triangles_;
Expand Down
19 changes: 15 additions & 4 deletions poly2tri/sweep/sweep_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef SWEEP_CONTEXT_H
#define SWEEP_CONTEXT_H

#include <list>
#include <vector>

Expand All @@ -46,43 +50,48 @@ class AdvancingFront;
class SweepContext {
public:

// Constructor
/// Constructor
SweepContext(std::vector<Point*> polyline);
// Destructor
/// Destructor
~SweepContext();

void set_head(Point* p1);

Point* head();

void set_tail(Point* p1);

Point* tail();

int point_count();

Node& LocateNode(Point& point);

void RemoveNode(Node* node);

void CreateAdvancingFront();

// Try to map a node to all sides of this triangle that don't have a neighbor
/// Try to map a node to all sides of this triangle that don't have a neighbor
void MapTriangleToNodes(Triangle& t);

void AddToMap(Triangle* triangle);

Point* GetPoint(const int& index);

Point* GetPoints();

void RemoveFromMap(Triangle* triangle);

void AddHole(std::vector<Point*> polyline);

void AddPoint(Point* point);

AdvancingFront* front();

void MeshClean(Triangle& triangle);

std::vector<Triangle*> GetTriangles();
std::list<Triangle*> GetMap();

std::vector<Edge*> edge_list;

struct Basin {
Expand Down Expand Up @@ -172,3 +181,5 @@ inline Point* SweepContext::tail()
}

}

#endif
1 change: 1 addition & 0 deletions src/cdt.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cdef extern from "../poly2tri/sweep/cdt.h":
ctypedef struct c_CDT "p2t::CDT":
void AddHole(point_vec polyline)
void AddPoint(c_Point* point)
void Triangulate()
triangle_vec GetTriangles()
c_CDT *new_CDT "new p2t::CDT" (point_vec polyline)
Expand Down
4 changes: 4 additions & 0 deletions src/cdt.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ cdef class CDT:
for point in polyline:
hole.push_back(new_Point(point.x, point.y))
self.me.AddHole(hole)

def add_point(self, point):
cdef c_Point* p = new_Point(point.x, point.y)
self.me.AddPoint(p)

def __dealloc__(self):
del_CDT(self.me)
14 changes: 12 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def main(file_name, translate, zoom):
screen = pygame.display.set_mode(SCREEN_SIZE,0,8)
pygame.display.set_caption('poly2tri demo')

pygame.mouse.set_visible(True)

black = Color(0,0,0)
red = Color(255, 0, 0)
green = Color(0, 255, 0)
Expand All @@ -52,25 +54,33 @@ def main(file_name, translate, zoom):

##
## Step 1: Initialize
## NOTE: polyline must be a simple polygon. The polyline's points
## constitute constrained edges. No repeat points!!!
##
cdt = CDT(polyline)

##
## Step 2: Add holes if necessary
## Step 2: Add holes and interior Steiner points if necessary
##
if file_name == "data/dude.dat":
hole = []
for p in head_hole:
p[0] = p[0]*zoom + translate[0]
p[1] = p[1]*zoom + translate[1]
hole.append(Point(p[0],p[1]))
# Add a hole
cdt.add_hole(hole)
hole = []
for p in chest_hole:
p[0] = p[0]*zoom + translate[0]
p[1] = p[1]*zoom + translate[1]
hole.append(Point(p[0],p[1]))
# Add a hole
cdt.add_hole(hole)
# Add an interior Steiner point
x = 361*zoom + translate[0]
y = 381*zoom + translate[1]
cdt.add_point(Point(x, y))

##
## Step 3: Triangulate
Expand Down Expand Up @@ -134,7 +144,7 @@ def main(file_name, translate, zoom):
break
if( e.key == K_f ):
pygame.display.toggle_fullscreen()

return

if __name__=="__main__":
Expand Down

0 comments on commit 660ec61

Please sign in to comment.