mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-12-02 10:13:29 +01:00
memory cleanup
This commit is contained in:
parent
bab616f9ea
commit
d6dd5da27c
@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
namespace p2t {
|
namespace p2t {
|
||||||
|
|
||||||
struct Node;
|
|
||||||
struct Edge;
|
struct Edge;
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
|
@ -102,9 +102,6 @@ Node* AdvancingFront::LocatePoint(const Point* point)
|
|||||||
|
|
||||||
AdvancingFront::~AdvancingFront()
|
AdvancingFront::~AdvancingFront()
|
||||||
{
|
{
|
||||||
delete head_;
|
|
||||||
delete search_node_;
|
|
||||||
delete tail_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@ Node& Sweep::PointEvent(SweepContext& tcx, Point& point)
|
|||||||
// x value than node due to how we fetch nodes from the front
|
// x value than node due to how we fetch nodes from the front
|
||||||
if (point.x <= node.point->x + EPSILON) {
|
if (point.x <= node.point->x + EPSILON) {
|
||||||
Fill(tcx, node);
|
Fill(tcx, node);
|
||||||
delete &node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tcx.AddNode(new_node);
|
//tcx.AddNode(new_node);
|
||||||
@ -221,6 +220,7 @@ void Sweep::Fill(SweepContext& tcx, Node& node)
|
|||||||
*/
|
*/
|
||||||
void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Fill right holes
|
// Fill right holes
|
||||||
Node* node = n.next;
|
Node* node = n.next;
|
||||||
|
|
||||||
@ -228,9 +228,7 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|||||||
double angle = HoleAngle(*node);
|
double angle = HoleAngle(*node);
|
||||||
if (angle > M_PI_2 || angle < -M_PI_2) break;
|
if (angle > M_PI_2 || angle < -M_PI_2) break;
|
||||||
Fill(tcx, *node);
|
Fill(tcx, *node);
|
||||||
Node *temp = node;
|
|
||||||
node = node->next;
|
node = node->next;
|
||||||
delete temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill left holes
|
// Fill left holes
|
||||||
@ -240,9 +238,7 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
|
|||||||
double angle = HoleAngle(*node);
|
double angle = HoleAngle(*node);
|
||||||
if (angle > M_PI_2 || angle < -M_PI_2) break;
|
if (angle > M_PI_2 || angle < -M_PI_2) break;
|
||||||
Fill(tcx, *node);
|
Fill(tcx, *node);
|
||||||
Node *temp = node;
|
|
||||||
node = node->prev;
|
node = node->prev;
|
||||||
delete temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill right basins
|
// Fill right basins
|
||||||
@ -529,22 +525,18 @@ void Sweep::FillBasinReq(SweepContext& tcx, Node* node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Fill(tcx, *node);
|
Fill(tcx, *node);
|
||||||
Node *temp = node;
|
|
||||||
|
|
||||||
if (node->prev == tcx.basin.left_node && node->next == tcx.basin.right_node) {
|
if (node->prev == tcx.basin.left_node && node->next == tcx.basin.right_node) {
|
||||||
delete node;
|
|
||||||
return;
|
return;
|
||||||
} else if (node->prev == tcx.basin.left_node) {
|
} else if (node->prev == tcx.basin.left_node) {
|
||||||
Orientation o = Orient2d(*node->point, *node->next->point, *node->next->next->point);
|
Orientation o = Orient2d(*node->point, *node->next->point, *node->next->next->point);
|
||||||
if (o == CW) {
|
if (o == CW) {
|
||||||
delete node;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node = node->next;
|
node = node->next;
|
||||||
} else if (node->next == tcx.basin.right_node) {
|
} else if (node->next == tcx.basin.right_node) {
|
||||||
Orientation o = Orient2d(*node->point, *node->prev->point, *node->prev->prev->point);
|
Orientation o = Orient2d(*node->point, *node->prev->point, *node->prev->prev->point);
|
||||||
if (o == CCW) {
|
if (o == CCW) {
|
||||||
delete node;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node = node->prev;
|
node = node->prev;
|
||||||
@ -557,7 +549,6 @@ void Sweep::FillBasinReq(SweepContext& tcx, Node* node)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete temp;
|
|
||||||
FillBasinReq(tcx, node);
|
FillBasinReq(tcx, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,5 +807,14 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sweep::~Sweep() {
|
||||||
|
|
||||||
|
// Clean up memory
|
||||||
|
for(int i = 0; i < nodes_.size(); i++) {
|
||||||
|
delete nodes_[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ class Sweep {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
void Triangulate(SweepContext& tcx);
|
void Triangulate(SweepContext& tcx);
|
||||||
|
~Sweep();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -121,28 +121,23 @@ Node& SweepContext::LocateNode(Point& point)
|
|||||||
|
|
||||||
void SweepContext::CreateAdvancingFront(std::vector<Node*> nodes)
|
void SweepContext::CreateAdvancingFront(std::vector<Node*> nodes)
|
||||||
{
|
{
|
||||||
Node *head, *middle, *tail;
|
|
||||||
// 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);
|
||||||
|
|
||||||
head = new Node(*triangle->GetPoint(1), *triangle);
|
af_head_ = new Node(*triangle->GetPoint(1), *triangle);
|
||||||
middle = new Node(*triangle->GetPoint(0), *triangle);
|
af_middle_ = new Node(*triangle->GetPoint(0), *triangle);
|
||||||
tail = new Node(*triangle->GetPoint(2));
|
af_tail_ = new Node(*triangle->GetPoint(2));
|
||||||
front_ = new AdvancingFront(*head, *tail);
|
front_ = new AdvancingFront(*af_head_, *af_tail_);
|
||||||
|
|
||||||
// Memory management :)
|
|
||||||
nodes.push_back(head);
|
|
||||||
nodes.push_back(middle);
|
|
||||||
nodes.push_back(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
|
||||||
head->next = middle;
|
af_head_->next = af_middle_;
|
||||||
middle->next = tail;
|
af_middle_->next = af_tail_;
|
||||||
middle->prev = head;
|
af_middle_->prev = af_head_;
|
||||||
tail->prev = middle;
|
af_tail_->prev = af_middle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SweepContext::RemoveNode(Node* node)
|
void SweepContext::RemoveNode(Node* node)
|
||||||
@ -180,9 +175,27 @@ void SweepContext::MeshClean(Triangle& triangle)
|
|||||||
|
|
||||||
SweepContext::~SweepContext()
|
SweepContext::~SweepContext()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Clean up memory
|
||||||
|
|
||||||
delete head_;
|
delete head_;
|
||||||
delete tail_;
|
delete tail_;
|
||||||
delete front_;
|
delete front_;
|
||||||
|
delete af_head_;
|
||||||
|
delete af_middle_;
|
||||||
|
delete af_tail_;
|
||||||
|
|
||||||
|
typedef std::list<Triangle*> type_list;
|
||||||
|
|
||||||
|
for(type_list::iterator iter = map_.begin(); iter != map_.end(); ++iter) {
|
||||||
|
Triangle* ptr = *iter;
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < edge_list.size(); i++) {
|
||||||
|
delete edge_list[i];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ void MeshClean(Triangle& triangle);
|
|||||||
|
|
||||||
std::vector<Triangle*> GetTriangles();
|
std::vector<Triangle*> GetTriangles();
|
||||||
std::list<Triangle*> GetMap();
|
std::list<Triangle*> GetMap();
|
||||||
|
|
||||||
std::vector<Edge*> edge_list;
|
std::vector<Edge*> edge_list;
|
||||||
|
|
||||||
struct Basin {
|
struct Basin {
|
||||||
@ -133,7 +134,6 @@ 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
|
||||||
@ -143,7 +143,7 @@ Point* head_;
|
|||||||
// tail point used with advancing front
|
// tail point used with advancing front
|
||||||
Point* tail_;
|
Point* tail_;
|
||||||
|
|
||||||
//EdgeEvent edgeEvent = new EdgeEvent();
|
Node *af_head_, *af_middle_, *af_tail_;
|
||||||
|
|
||||||
void InitTriangulation();
|
void InitTriangulation();
|
||||||
void InitEdges(std::vector<Point*> polyline);
|
void InitEdges(std::vector<Point*> polyline);
|
||||||
|
@ -199,6 +199,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
MainLoop(zoom);
|
MainLoop(zoom);
|
||||||
|
|
||||||
|
delete cdt;
|
||||||
ShutDown(0);
|
ShutDown(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
4
wscript
4
wscript
@ -34,8 +34,8 @@ def configure(conf):
|
|||||||
print(' calling the configuration')
|
print(' calling the configuration')
|
||||||
conf.check_tool('g++')
|
conf.check_tool('g++')
|
||||||
#conf.env.CXXFLAGS = ['-O0', '-pg', '-g']
|
#conf.env.CXXFLAGS = ['-O0', '-pg', '-g']
|
||||||
#conf.env.CXXFLAGS = ['-O0', '-g']
|
conf.env.CXXFLAGS = ['-O0', '-g']
|
||||||
conf.env.CXXFLAGS = ['-O3', '-ffast-math']
|
#conf.env.CXXFLAGS = ['-O3', '-ffast-math']
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user