Very minor fixes: Uncrustify a few files and rename a shadowed var.
This commit is contained in:
parent
78e4787297
commit
146a78a8fb
|
@ -56,7 +56,7 @@ struct Point
|
||||||
std::vector<Edge*> edge_list;
|
std::vector<Edge*> edge_list;
|
||||||
|
|
||||||
/// Construct using coordinates.
|
/// Construct using coordinates.
|
||||||
Point( double x, double y ) : x( x ), y( y ) {}
|
Point( double ax, double ay ) : x( ax ), y( ay ) {}
|
||||||
|
|
||||||
/// Set this point to all zeros.
|
/// Set this point to all zeros.
|
||||||
void set_zero()
|
void set_zero()
|
||||||
|
|
|
@ -31,79 +31,105 @@
|
||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
AdvancingFront::AdvancingFront( Node& head, Node& tail )
|
||||||
AdvancingFront::AdvancingFront(Node& head, Node& tail)
|
|
||||||
{
|
{
|
||||||
head_ = &head;
|
head_ = &head;
|
||||||
tail_ = &tail;
|
tail_ = &tail;
|
||||||
search_node_ = &head;
|
search_node_ = &head;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* AdvancingFront::LocateNode(const double& x)
|
|
||||||
|
Node* AdvancingFront::LocateNode( const double& x )
|
||||||
{
|
{
|
||||||
Node* node = search_node_;
|
Node* node = search_node_;
|
||||||
|
|
||||||
if (x < node->value) {
|
if( x < node->value )
|
||||||
while ((node = node->prev) != NULL) {
|
{
|
||||||
if (x >= node->value) {
|
while( (node = node->prev) != NULL )
|
||||||
|
{
|
||||||
|
if( x >= node->value )
|
||||||
|
{
|
||||||
search_node_ = node;
|
search_node_ = node;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
while ((node = node->next) != NULL) {
|
else
|
||||||
if (x < node->value) {
|
{
|
||||||
|
while( (node = node->next) != NULL )
|
||||||
|
{
|
||||||
|
if( x < node->value )
|
||||||
|
{
|
||||||
search_node_ = node->prev;
|
search_node_ = node->prev;
|
||||||
return node->prev;
|
return node->prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* AdvancingFront::FindSearchNode(const double& x)
|
|
||||||
|
Node* AdvancingFront::FindSearchNode( const double& x )
|
||||||
{
|
{
|
||||||
(void)x; // suppress compiler warnings "unused parameter 'x'"
|
(void) x; // suppress compiler warnings "unused parameter 'x'"
|
||||||
// TODO: implement BST index
|
// TODO: implement BST index
|
||||||
return search_node_;
|
return search_node_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* AdvancingFront::LocatePoint(const Point* point)
|
|
||||||
|
Node* AdvancingFront::LocatePoint( const Point* point )
|
||||||
{
|
{
|
||||||
const double px = point->x;
|
const double px = point->x;
|
||||||
Node* node = FindSearchNode(px);
|
Node* node = FindSearchNode( px );
|
||||||
const double nx = node->point->x;
|
const double nx = node->point->x;
|
||||||
|
|
||||||
if (px == nx) {
|
if( px == nx )
|
||||||
if (point != node->point) {
|
{
|
||||||
|
if( point != node->point )
|
||||||
|
{
|
||||||
// We might have two nodes with same x value for a short time
|
// We might have two nodes with same x value for a short time
|
||||||
if (point == node->prev->point) {
|
if( point == node->prev->point )
|
||||||
|
{
|
||||||
node = node->prev;
|
node = node->prev;
|
||||||
} else if (point == node->next->point) {
|
}
|
||||||
|
else if( point == node->next->point )
|
||||||
|
{
|
||||||
node = node->next;
|
node = node->next;
|
||||||
} else {
|
}
|
||||||
assert(0);
|
else
|
||||||
|
{
|
||||||
|
assert( 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (px < nx) {
|
}
|
||||||
while ((node = node->prev) != NULL) {
|
else if( px < nx )
|
||||||
if (point == node->point) {
|
{
|
||||||
|
while( (node = node->prev) != NULL )
|
||||||
|
{
|
||||||
|
if( point == node->point )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
while ((node = node->next) != NULL) {
|
else
|
||||||
if (point == node->point)
|
{
|
||||||
|
while( (node = node->next) != NULL )
|
||||||
|
{
|
||||||
|
if( point == node->point )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(node) search_node_ = node;
|
|
||||||
|
if( node )
|
||||||
|
search_node_ = node;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AdvancingFront::~AdvancingFront()
|
AdvancingFront::~AdvancingFront()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,11 @@
|
||||||
#include "../common/shapes.h"
|
#include "../common/shapes.h"
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
struct Node;
|
struct Node;
|
||||||
|
|
||||||
// Advancing front node
|
// Advancing front node
|
||||||
struct Node {
|
struct Node
|
||||||
|
{
|
||||||
Point* point;
|
Point* point;
|
||||||
Triangle* triangle;
|
Triangle* triangle;
|
||||||
|
|
||||||
|
@ -48,71 +48,78 @@ struct Node {
|
||||||
|
|
||||||
double value;
|
double value;
|
||||||
|
|
||||||
Node(Point& p) : point(&p), triangle(NULL), next(NULL), prev(NULL), value(p.x)
|
Node( Point& p ) : point( &p ), triangle( NULL ), next( NULL ), prev( NULL ), value( p.x )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Node(Point& p, Triangle& t) : point(&p), triangle(&t), next(NULL), prev(NULL), value(p.x)
|
Node( Point& p, Triangle& t ) : point( &p ), triangle( &t ), next( NULL ), prev( NULL ), value(
|
||||||
|
p.x )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Advancing front
|
// Advancing front
|
||||||
class AdvancingFront {
|
class AdvancingFront
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AdvancingFront(Node& head, Node& tail);
|
AdvancingFront( Node& head, Node& tail );
|
||||||
// Destructor
|
// Destructor
|
||||||
~AdvancingFront();
|
~AdvancingFront();
|
||||||
|
|
||||||
Node* head();
|
Node* head();
|
||||||
void set_head(Node* node);
|
void set_head( Node* node );
|
||||||
Node* tail();
|
Node* tail();
|
||||||
void set_tail(Node* node);
|
void set_tail( Node* node );
|
||||||
Node* search();
|
Node* search();
|
||||||
void set_search(Node* node);
|
void set_search( Node* node );
|
||||||
|
|
||||||
/// Locate insertion point along advancing front
|
/// Locate insertion point along advancing front
|
||||||
Node* LocateNode(const double& x);
|
Node* LocateNode( const double& x );
|
||||||
|
|
||||||
Node* LocatePoint(const Point* point);
|
Node* LocatePoint( const Point* point );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Node* head_, *tail_, *search_node_;
|
Node* head_, * tail_, * search_node_;
|
||||||
|
|
||||||
Node* FindSearchNode(const double& x);
|
Node* FindSearchNode( const double& x );
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Node* AdvancingFront::head()
|
inline Node* AdvancingFront::head()
|
||||||
{
|
{
|
||||||
return head_;
|
return head_;
|
||||||
}
|
}
|
||||||
inline void AdvancingFront::set_head(Node* node)
|
|
||||||
|
|
||||||
|
inline void AdvancingFront::set_head( Node* node )
|
||||||
{
|
{
|
||||||
head_ = node;
|
head_ = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Node* AdvancingFront::tail()
|
inline Node* AdvancingFront::tail()
|
||||||
{
|
{
|
||||||
return tail_;
|
return tail_;
|
||||||
}
|
}
|
||||||
inline void AdvancingFront::set_tail(Node* node)
|
|
||||||
|
|
||||||
|
inline void AdvancingFront::set_tail( Node* node )
|
||||||
{
|
{
|
||||||
tail_ = node;
|
tail_ = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Node* AdvancingFront::search()
|
inline Node* AdvancingFront::search()
|
||||||
{
|
{
|
||||||
return search_node_;
|
return search_node_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void AdvancingFront::set_search(Node* node)
|
|
||||||
|
inline void AdvancingFront::set_search( Node* node )
|
||||||
{
|
{
|
||||||
search_node_ = node;
|
search_node_ = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,42 +31,46 @@
|
||||||
#include "cdt.h"
|
#include "cdt.h"
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
CDT::CDT( std::vector<Point*> polyline )
|
||||||
CDT::CDT(std::vector<Point*> polyline)
|
|
||||||
{
|
{
|
||||||
sweep_context_ = new SweepContext(polyline);
|
sweep_context_ = new SweepContext( polyline );
|
||||||
sweep_ = new Sweep;
|
sweep_ = new Sweep;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDT::AddHole(std::vector<Point*> polyline)
|
|
||||||
|
void CDT::AddHole( std::vector<Point*> polyline )
|
||||||
{
|
{
|
||||||
sweep_context_->AddHole(polyline);
|
sweep_context_->AddHole( polyline );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDT::AddPoint(Point* point) {
|
|
||||||
sweep_context_->AddPoint(point);
|
void CDT::AddPoint( Point* point )
|
||||||
|
{
|
||||||
|
sweep_context_->AddPoint( point );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CDT::Triangulate()
|
void CDT::Triangulate()
|
||||||
{
|
{
|
||||||
sweep_->Triangulate(*sweep_context_);
|
sweep_->Triangulate( *sweep_context_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<p2t::Triangle*> CDT::GetTriangles()
|
std::vector<p2t::Triangle*> CDT::GetTriangles()
|
||||||
{
|
{
|
||||||
return sweep_context_->GetTriangles();
|
return sweep_context_->GetTriangles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::list<p2t::Triangle*> CDT::GetMap()
|
std::list<p2t::Triangle*> CDT::GetMap()
|
||||||
{
|
{
|
||||||
return sweep_context_->GetMap();
|
return sweep_context_->GetMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDT::~CDT()
|
CDT::~CDT()
|
||||||
{
|
{
|
||||||
delete sweep_context_;
|
delete sweep_context_;
|
||||||
delete sweep_;
|
delete sweep_;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,111 +33,128 @@
|
||||||
#include "advancing_front.h"
|
#include "advancing_front.h"
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
SweepContext::SweepContext( std::vector<Point*> polyline ) :
|
||||||
SweepContext::SweepContext(std::vector<Point*> polyline) :
|
front_( 0 ),
|
||||||
front_(0),
|
head_( 0 ),
|
||||||
head_(0),
|
tail_( 0 ),
|
||||||
tail_(0),
|
af_head_( 0 ),
|
||||||
af_head_(0),
|
af_middle_( 0 ),
|
||||||
af_middle_(0),
|
af_tail_( 0 )
|
||||||
af_tail_(0)
|
|
||||||
{
|
{
|
||||||
basin = Basin();
|
basin = Basin();
|
||||||
edge_event = EdgeEvent();
|
edge_event = EdgeEvent();
|
||||||
|
|
||||||
points_ = polyline;
|
points_ = polyline;
|
||||||
|
|
||||||
InitEdges(points_);
|
InitEdges( points_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::AddHole(std::vector<Point*> polyline)
|
|
||||||
|
void SweepContext::AddHole( std::vector<Point*> polyline )
|
||||||
{
|
{
|
||||||
InitEdges(polyline);
|
InitEdges( polyline );
|
||||||
for(unsigned int i = 0; i < polyline.size(); i++) {
|
|
||||||
points_.push_back(polyline[i]);
|
for( unsigned int i = 0; i < polyline.size(); i++ )
|
||||||
|
{
|
||||||
|
points_.push_back( polyline[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::AddPoint(Point* point) {
|
|
||||||
points_.push_back(point);
|
void SweepContext::AddPoint( Point* point )
|
||||||
|
{
|
||||||
|
points_.push_back( point );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<Triangle*> SweepContext::GetTriangles()
|
std::vector<Triangle*> SweepContext::GetTriangles()
|
||||||
{
|
{
|
||||||
return triangles_;
|
return triangles_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::list<Triangle*> SweepContext::GetMap()
|
std::list<Triangle*> SweepContext::GetMap()
|
||||||
{
|
{
|
||||||
return map_;
|
return map_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SweepContext::InitTriangulation()
|
void SweepContext::InitTriangulation()
|
||||||
{
|
{
|
||||||
double xmax(points_[0]->x), xmin(points_[0]->x);
|
double xmax( points_[0]->x ), xmin( points_[0]->x );
|
||||||
double ymax(points_[0]->y), ymin(points_[0]->y);
|
double ymax( points_[0]->y ), ymin( points_[0]->y );
|
||||||
|
|
||||||
// Calculate bounds.
|
// Calculate bounds.
|
||||||
for (unsigned int i = 0; i < points_.size(); i++) {
|
for( unsigned int i = 0; i < points_.size(); i++ )
|
||||||
|
{
|
||||||
Point& p = *points_[i];
|
Point& p = *points_[i];
|
||||||
if (p.x > xmax)
|
|
||||||
|
if( p.x > xmax )
|
||||||
xmax = p.x;
|
xmax = p.x;
|
||||||
if (p.x < xmin)
|
|
||||||
|
if( p.x < xmin )
|
||||||
xmin = p.x;
|
xmin = p.x;
|
||||||
if (p.y > ymax)
|
|
||||||
|
if( p.y > ymax )
|
||||||
ymax = p.y;
|
ymax = p.y;
|
||||||
if (p.y < ymin)
|
|
||||||
|
if( p.y < ymin )
|
||||||
ymin = p.y;
|
ymin = p.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
double dx = kAlpha * (xmax - xmin);
|
double dx = kAlpha * (xmax - xmin);
|
||||||
double dy = kAlpha * (ymax - ymin);
|
double dy = kAlpha * (ymax - ymin);
|
||||||
head_ = new Point(xmax + dx, ymin - dy);
|
head_ = new Point( xmax + dx, ymin - dy );
|
||||||
tail_ = new Point(xmin - dx, ymin - dy);
|
tail_ = new Point( xmin - dx, ymin - dy );
|
||||||
|
|
||||||
// Sort points along y-axis
|
// Sort points along y-axis
|
||||||
std::sort(points_.begin(), points_.end(), cmp);
|
std::sort( points_.begin(), points_.end(), cmp );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::InitEdges(std::vector<Point*> polyline)
|
|
||||||
|
void SweepContext::InitEdges( std::vector<Point*> polyline )
|
||||||
{
|
{
|
||||||
int num_points = polyline.size();
|
int num_points = polyline.size();
|
||||||
for (int i = 0; i < num_points; i++) {
|
|
||||||
|
for( int i = 0; i < num_points; i++ )
|
||||||
|
{
|
||||||
int j = i < num_points - 1 ? i + 1 : 0;
|
int j = i < num_points - 1 ? i + 1 : 0;
|
||||||
edge_list.push_back(new Edge(*polyline[i], *polyline[j]));
|
edge_list.push_back( new Edge( *polyline[i], *polyline[j] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point* SweepContext::GetPoint(const int& index)
|
|
||||||
|
Point* SweepContext::GetPoint( const int& index )
|
||||||
{
|
{
|
||||||
return points_[index];
|
return points_[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::AddToMap(Triangle* triangle)
|
|
||||||
|
void SweepContext::AddToMap( Triangle* triangle )
|
||||||
{
|
{
|
||||||
map_.push_back(triangle);
|
map_.push_back( triangle );
|
||||||
}
|
}
|
||||||
|
|
||||||
Node& SweepContext::LocateNode(Point& point)
|
|
||||||
|
Node& SweepContext::LocateNode( Point& point )
|
||||||
{
|
{
|
||||||
// TODO implement search tree
|
// TODO implement search tree
|
||||||
return *front_->LocateNode(point.x);
|
return *front_->LocateNode( point.x );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::CreateAdvancingFront(std::vector<Node*> nodes)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
void SweepContext::CreateAdvancingFront( std::vector<Node*> nodes )
|
||||||
|
{
|
||||||
(void) nodes;
|
(void) nodes;
|
||||||
// Initial triangle
|
// Initial triangle
|
||||||
Triangle* triangle = new Triangle(*points_[0], *tail_, *head_);
|
Triangle* triangle = new Triangle( *points_[0], *tail_, *head_ );
|
||||||
|
|
||||||
map_.push_back(triangle);
|
map_.push_back( triangle );
|
||||||
|
|
||||||
af_head_ = new Node(*triangle->GetPoint(1), *triangle);
|
af_head_ = new Node( *triangle->GetPoint( 1 ), *triangle );
|
||||||
af_middle_ = new Node(*triangle->GetPoint(0), *triangle);
|
af_middle_ = new Node( *triangle->GetPoint( 0 ), *triangle );
|
||||||
af_tail_ = new Node(*triangle->GetPoint(2));
|
af_tail_ = new Node( *triangle->GetPoint( 2 ) );
|
||||||
front_ = new AdvancingFront(*af_head_, *af_tail_);
|
front_ = new AdvancingFront( *af_head_, *af_tail_ );
|
||||||
|
|
||||||
// TODO: More intuitive if head is middles next and not previous?
|
// TODO: More intuitive if head is middles next and not previous?
|
||||||
// so swap head and tail
|
// so swap head and tail
|
||||||
|
@ -147,50 +164,62 @@ void SweepContext::CreateAdvancingFront(std::vector<Node*> nodes)
|
||||||
af_tail_->prev = af_middle_;
|
af_tail_->prev = af_middle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::RemoveNode(Node* node)
|
|
||||||
|
void SweepContext::RemoveNode( Node* node )
|
||||||
{
|
{
|
||||||
delete node;
|
delete node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::MapTriangleToNodes(Triangle& t)
|
|
||||||
|
void SweepContext::MapTriangleToNodes( Triangle& t )
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; i++) {
|
for( int i = 0; i < 3; i++ )
|
||||||
if (!t.GetNeighbor(i)) {
|
{
|
||||||
Node* n = front_->LocatePoint(t.PointCW(*t.GetPoint(i)));
|
if( !t.GetNeighbor( i ) )
|
||||||
if (n)
|
{
|
||||||
|
Node* n = front_->LocatePoint( t.PointCW( *t.GetPoint( i ) ) );
|
||||||
|
|
||||||
|
if( n )
|
||||||
n->triangle = &t;
|
n->triangle = &t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::RemoveFromMap(Triangle* triangle)
|
|
||||||
|
void SweepContext::RemoveFromMap( Triangle* triangle )
|
||||||
{
|
{
|
||||||
map_.remove(triangle);
|
map_.remove( triangle );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::MeshClean(Triangle& triangle)
|
|
||||||
{
|
|
||||||
std::vector<Triangle *> triangles;
|
|
||||||
triangles.push_back(&triangle);
|
|
||||||
|
|
||||||
while(!triangles.empty()){
|
void SweepContext::MeshClean( Triangle& triangle )
|
||||||
Triangle *t = triangles.back();
|
{
|
||||||
|
std::vector<Triangle*> triangles;
|
||||||
|
|
||||||
|
triangles.push_back( &triangle );
|
||||||
|
|
||||||
|
while( !triangles.empty() )
|
||||||
|
{
|
||||||
|
Triangle* t = triangles.back();
|
||||||
triangles.pop_back();
|
triangles.pop_back();
|
||||||
|
|
||||||
if (t != NULL && !t->IsInterior()) {
|
if( t != NULL && !t->IsInterior() )
|
||||||
t->IsInterior(true);
|
{
|
||||||
triangles_.push_back(t);
|
t->IsInterior( true );
|
||||||
for (int i = 0; i < 3; i++) {
|
triangles_.push_back( t );
|
||||||
if (!t->constrained_edge[i])
|
|
||||||
triangles.push_back(t->GetNeighbor(i));
|
for( int i = 0; i < 3; i++ )
|
||||||
|
{
|
||||||
|
if( !t->constrained_edge[i] )
|
||||||
|
triangles.push_back( t->GetNeighbor( i ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SweepContext::~SweepContext()
|
SweepContext::~SweepContext()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Clean up memory
|
// Clean up memory
|
||||||
|
|
||||||
delete head_;
|
delete head_;
|
||||||
|
@ -202,15 +231,15 @@ SweepContext::~SweepContext()
|
||||||
|
|
||||||
typedef std::list<Triangle*> type_list;
|
typedef std::list<Triangle*> type_list;
|
||||||
|
|
||||||
for(type_list::iterator iter = map_.begin(); iter != map_.end(); ++iter) {
|
for( type_list::iterator iter = map_.begin(); iter != map_.end(); ++iter )
|
||||||
|
{
|
||||||
Triangle* ptr = *iter;
|
Triangle* ptr = *iter;
|
||||||
delete ptr;
|
delete ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned int i = 0; i < edge_list.size(); i++) {
|
for( unsigned int i = 0; i < edge_list.size(); i++ )
|
||||||
|
{
|
||||||
delete edge_list[i];
|
delete edge_list[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
// Inital triangle factor, seed triangle will extend 30% of
|
// Inital triangle factor, seed triangle will extend 30% of
|
||||||
// PointSet width to both left and right.
|
// PointSet width to both left and right.
|
||||||
const double kAlpha = 0.3;
|
const double kAlpha = 0.3;
|
||||||
|
@ -48,62 +47,66 @@ struct Node;
|
||||||
struct Edge;
|
struct Edge;
|
||||||
class AdvancingFront;
|
class AdvancingFront;
|
||||||
|
|
||||||
class SweepContext {
|
class SweepContext
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
SweepContext(std::vector<Point*> polyline);
|
SweepContext( std::vector<Point*> polyline );
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~SweepContext();
|
~SweepContext();
|
||||||
|
|
||||||
void set_head(Point* p1);
|
void set_head( Point* p1 );
|
||||||
|
|
||||||
Point* head();
|
Point* head();
|
||||||
|
|
||||||
void set_tail(Point* p1);
|
void set_tail( Point* p1 );
|
||||||
|
|
||||||
Point* tail();
|
Point* tail();
|
||||||
|
|
||||||
int point_count();
|
int point_count();
|
||||||
|
|
||||||
Node& LocateNode(Point& point);
|
Node& LocateNode( Point& point );
|
||||||
|
|
||||||
void RemoveNode(Node* node);
|
void RemoveNode( Node* node );
|
||||||
|
|
||||||
void CreateAdvancingFront(std::vector<Node*> nodes);
|
void CreateAdvancingFront( std::vector<Node*> nodes );
|
||||||
|
|
||||||
/// 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 MapTriangleToNodes( Triangle& t );
|
||||||
|
|
||||||
void AddToMap(Triangle* triangle);
|
void AddToMap( Triangle* triangle );
|
||||||
|
|
||||||
Point* GetPoint(const int& index);
|
Point* GetPoint( const int& index );
|
||||||
|
|
||||||
Point* GetPoints();
|
Point* GetPoints();
|
||||||
|
|
||||||
void RemoveFromMap(Triangle* triangle);
|
void RemoveFromMap( Triangle* triangle );
|
||||||
|
|
||||||
void AddHole(std::vector<Point*> polyline);
|
void AddHole( std::vector<Point*> polyline );
|
||||||
|
|
||||||
void AddPoint(Point* point);
|
void AddPoint( Point* point );
|
||||||
|
|
||||||
AdvancingFront* front();
|
AdvancingFront* front();
|
||||||
|
|
||||||
void MeshClean(Triangle& triangle);
|
void MeshClean( Triangle& triangle );
|
||||||
|
|
||||||
std::vector<Triangle*> GetTriangles();
|
std::vector<Triangle*> GetTriangles();
|
||||||
std::list<Triangle*> GetMap();
|
|
||||||
|
|
||||||
std::vector<Edge*> edge_list;
|
std::list<Triangle*> GetMap();
|
||||||
|
|
||||||
struct Basin {
|
std::vector<Edge*> edge_list;
|
||||||
|
|
||||||
|
struct Basin
|
||||||
|
{
|
||||||
Node* left_node;
|
Node* left_node;
|
||||||
Node* bottom_node;
|
Node* bottom_node;
|
||||||
Node* right_node;
|
Node* right_node;
|
||||||
double width;
|
double width;
|
||||||
bool left_highest;
|
bool left_highest;
|
||||||
|
|
||||||
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL), width(0.0), left_highest(false)
|
Basin() : left_node( NULL ), bottom_node( NULL ), right_node( NULL ), width( 0.0 ),
|
||||||
|
left_highest( false )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,40 +118,40 @@ struct Basin {
|
||||||
width = 0.0;
|
width = 0.0;
|
||||||
left_highest = false;
|
left_highest = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EdgeEvent {
|
struct EdgeEvent
|
||||||
|
{
|
||||||
Edge* constrained_edge;
|
Edge* constrained_edge;
|
||||||
bool right;
|
bool right;
|
||||||
|
|
||||||
EdgeEvent() : constrained_edge(NULL), right(false)
|
EdgeEvent() : constrained_edge( NULL ), right( false )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Basin basin;
|
Basin basin;
|
||||||
EdgeEvent edge_event;
|
EdgeEvent edge_event;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class Sweep;
|
friend class Sweep;
|
||||||
|
|
||||||
std::vector<Triangle*> triangles_;
|
std::vector<Triangle*> triangles_;
|
||||||
std::list<Triangle*> map_;
|
std::list<Triangle*> map_;
|
||||||
std::vector<Point*> points_;
|
std::vector<Point*> points_;
|
||||||
|
|
||||||
// Advancing front
|
// Advancing front
|
||||||
AdvancingFront* front_;
|
AdvancingFront* front_;
|
||||||
// head point used with advancing front
|
// head point used with advancing front
|
||||||
Point* head_;
|
Point* head_;
|
||||||
// tail point used with advancing front
|
// tail point used with advancing front
|
||||||
Point* tail_;
|
Point* tail_;
|
||||||
|
|
||||||
Node *af_head_, *af_middle_, *af_tail_;
|
Node* af_head_, * af_middle_, * af_tail_;
|
||||||
|
|
||||||
void InitTriangulation();
|
|
||||||
void InitEdges(std::vector<Point*> polyline);
|
|
||||||
|
|
||||||
|
void InitTriangulation();
|
||||||
|
void InitEdges( std::vector<Point*> polyline );
|
||||||
};
|
};
|
||||||
|
|
||||||
inline AdvancingFront* SweepContext::front()
|
inline AdvancingFront* SweepContext::front()
|
||||||
|
@ -156,31 +159,35 @@ inline AdvancingFront* SweepContext::front()
|
||||||
return front_;
|
return front_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int SweepContext::point_count()
|
inline int SweepContext::point_count()
|
||||||
{
|
{
|
||||||
return points_.size();
|
return points_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SweepContext::set_head(Point* p1)
|
|
||||||
|
inline void SweepContext::set_head( Point* p1 )
|
||||||
{
|
{
|
||||||
head_ = p1;
|
head_ = p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Point* SweepContext::head()
|
inline Point* SweepContext::head()
|
||||||
{
|
{
|
||||||
return head_;
|
return head_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SweepContext::set_tail(Point* p1)
|
|
||||||
|
inline void SweepContext::set_tail( Point* p1 )
|
||||||
{
|
{
|
||||||
tail_ = p1;
|
tail_ = p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Point* SweepContext::tail()
|
inline Point* SweepContext::tail()
|
||||||
{
|
{
|
||||||
return tail_;
|
return tail_;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue