2015-07-14 20:23:13 +00:00
|
|
|
/*
|
|
|
|
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
|
|
|
|
* http://code.google.com/p/poly2tri/
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* 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>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace p2t {
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2015-07-14 20:23:13 +00:00
|
|
|
// Inital triangle factor, seed triangle will extend 30% of
|
|
|
|
// PointSet width to both left and right.
|
|
|
|
const double kAlpha = 0.3;
|
|
|
|
|
|
|
|
struct Point;
|
|
|
|
class Triangle;
|
|
|
|
struct Node;
|
|
|
|
struct Edge;
|
|
|
|
class AdvancingFront;
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
class SweepContext {
|
2015-07-14 20:23:13 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor
|
2017-11-23 16:20:27 +00:00
|
|
|
SweepContext(std::vector<Point*> polyline);
|
2015-07-14 20:23:13 +00:00
|
|
|
/// Destructor
|
2017-11-23 16:20:27 +00:00
|
|
|
~SweepContext();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void set_head(Point* p1);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Point* head();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void set_tail(Point* p1);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Point* tail();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
int point_count();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Node& LocateNode(Point& point);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void RemoveNode(Node* node);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void CreateAdvancingFront(std::vector<Node*> nodes);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
|
|
|
/// Try to map a node to all sides of this triangle that don't have a neighbor
|
2017-11-23 16:20:27 +00:00
|
|
|
void MapTriangleToNodes(Triangle& t);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void AddToMap(Triangle* triangle);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Point* GetPoint(const int& index);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Point* GetPoints();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void RemoveFromMap(Triangle* triangle);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void AddHole(std::vector<Point*> polyline);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void AddPoint(Point* point);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
AdvancingFront* front();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void MeshClean(Triangle& triangle);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
std::vector<Triangle*> GetTriangles();
|
|
|
|
std::list<Triangle*> GetMap();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
std::vector<Edge*> edge_list;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
struct Basin {
|
|
|
|
Node* left_node;
|
|
|
|
Node* bottom_node;
|
|
|
|
Node* right_node;
|
|
|
|
double width;
|
|
|
|
bool left_highest;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Basin() : left_node(NULL), bottom_node(NULL), right_node(NULL), width(0.0), left_highest(false)
|
|
|
|
{
|
|
|
|
}
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
left_node = NULL;
|
|
|
|
bottom_node = NULL;
|
|
|
|
right_node = NULL;
|
|
|
|
width = 0.0;
|
|
|
|
left_highest = false;
|
|
|
|
}
|
|
|
|
};
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
struct EdgeEvent {
|
|
|
|
Edge* constrained_edge;
|
|
|
|
bool right;
|
2016-07-22 06:59:17 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
EdgeEvent() : constrained_edge(NULL), right(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
Basin basin;
|
|
|
|
EdgeEvent edge_event;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
friend class Sweep;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
std::vector<Triangle*> triangles_;
|
|
|
|
std::list<Triangle*> map_;
|
|
|
|
std::vector<Point*> points_;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
|
|
|
// Advancing front
|
2017-11-23 16:20:27 +00:00
|
|
|
AdvancingFront* front_;
|
2015-07-14 20:23:13 +00:00
|
|
|
// head point used with advancing front
|
2017-11-23 16:20:27 +00:00
|
|
|
Point* head_;
|
2015-07-14 20:23:13 +00:00
|
|
|
// tail point used with advancing front
|
2017-11-23 16:20:27 +00:00
|
|
|
Point* tail_;
|
|
|
|
|
|
|
|
Node *af_head_, *af_middle_, *af_tail_;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void InitTriangulation();
|
|
|
|
void InitEdges(std::vector<Point*> polyline);
|
2015-07-14 20:23:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline AdvancingFront* SweepContext::front()
|
|
|
|
{
|
2017-11-23 16:20:27 +00:00
|
|
|
return front_;
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int SweepContext::point_count()
|
|
|
|
{
|
2017-11-23 16:20:27 +00:00
|
|
|
return points_.size();
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
inline void SweepContext::set_head(Point* p1)
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2017-11-23 16:20:27 +00:00
|
|
|
head_ = p1;
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Point* SweepContext::head()
|
|
|
|
{
|
2017-11-23 16:20:27 +00:00
|
|
|
return head_;
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
inline void SweepContext::set_tail(Point* p1)
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2017-11-23 16:20:27 +00:00
|
|
|
tail_ = p1;
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Point* SweepContext::tail()
|
|
|
|
{
|
2017-11-23 16:20:27 +00:00
|
|
|
return tail_;
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|