Skip to content

Commit

Permalink
Implemented join and glue operations, bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rodschulz committed Jun 5, 2015
1 parent f05fb93 commit 3a92064
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
79 changes: 71 additions & 8 deletions src/Front.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ void Front::joinAndFix(const pair<int, TrianglePtr> &_data, Pivoter &_pivoter)
/**
* This is the easy case, the new point has not been used
*/

// Add new edges
EdgePtr edge0 = _data.second->getEdge(0);
EdgePtr edge1 = _data.second->getEdge(1);
front.insert(pos, edge0);
front.insert(pos, edge1);
for (int i = 0; i < 2; i++)
{
EdgePtr edge = _data.second->getEdge(i);
front.insert(pos, edge);
cout << "\tEdge added: " << *edge << "\n";
}

cout << "\tEdge added: " << *edge0 << "\n";
cout << "\tEdge added: " << *edge1 << "\n";
// Add new point to the 'in front' map
PointData data = _data.second->getVertex(1);
frontPoints[data.first] = data.second;

// Remove replaced edge
cout << "\tEdge removed: " << **pos << "\n";
Expand All @@ -84,11 +86,72 @@ void Front::joinAndFix(const pair<int, TrianglePtr> &_data, Pivoter &_pivoter)
}
else
{
cout << "*** Glue operation not implemented yet!\n";
PointNormal *point = _pivoter.getPoint(_data.first);
if (inFront(point))
{
/**
* Point in front, so orientation must be check, and join and glue must be done
*/
int added = 0;

for (int i = 0; i < 2; i++)
{
EdgePtr edge = _data.second->getEdge(i);
list<EdgePtr>::iterator it;
if ((it = isPresent(edge)) != front.end())
{
// Remove the 'coincident' edge
cout << "\tEdge removed: " << **it << "\n";
front.erase(it);
}
else
{
front.insert(pos, edge);
added++;
cout << "\tEdge added: " << *edge << "\n";
}
}

// Remove the old edge
cout << "\tEdge removed: " << **pos << "\n";
front.erase(pos);

// Move iterator to the first added new edge
advance(pos, -added);

// Delete point from the front
frontPoints.erase(point);
cout << "Point removed from front: " << _data.first << "\n";
}
else
{
/**
* The point is not part of any front edge, hence is an internal
* point, so this edge can't be done. In consequence this a boundary
*/
(*pos)->setActive(false);
cout << "Edge marked as boundary: " << **pos << "\n";
}
}
}

bool Front::inFront(PointNormal *_point)
{
return frontPoints.find(_point) != frontPoints.end();
}

list<EdgePtr>::iterator Front::isPresent(const EdgePtr &_edge)
{
int vertex0 = _edge->getVertex(0).second;
int vertex1 = _edge->getVertex(1).second;

for (list<EdgePtr>::iterator it = front.begin(); it != front.end(); it++)
{
int v0 = (*it)->getVertex(0).second;
int v1 = (*it)->getVertex(1).second;
if ((v0 == vertex1 && v1 == vertex0) || (v0 == vertex0 && v1 == vertex1))
return it;
}

return front.end();
}
2 changes: 2 additions & 0 deletions src/Front.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Front
bool inFront(PointNormal *_point);

private:
list<EdgePtr>::iterator isPresent(const EdgePtr &_edge);

list<EdgePtr> front;
list<EdgePtr>::iterator pos;
map<PointNormal *, int> frontPoints;
Expand Down
5 changes: 5 additions & 0 deletions src/Pivoter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ TrianglePtr Pivoter::findSeed()
return seed;
}

PointNormal *Pivoter::getPoint(const int _index) const
{
return &cloud->at(_index);
}

pair<Vector3f, double> Pivoter::getCircumscribedCircle(const Vector3f &_p0, const Vector3f &_p1, const Vector3f &_p2) const
{
Vector3f d10 = _p1 - _p0;
Expand Down
1 change: 1 addition & 0 deletions src/Pivoter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Pivoter

pair<int, TrianglePtr> pivot(const EdgePtr &_edge);
TrianglePtr findSeed();
PointNormal *getPoint(const int _index) const;

bool isUsed(const int _index) const;
void setUsed(const int _index);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main(int _argn, char **_argv)
}
else
{
cout << "Edge" << data.first << " set as boundary\n";
cout << "Edge marked as boundary" << *edge << "\n";
edge->setActive(false);
}
}
Expand Down

0 comments on commit 3a92064

Please sign in to comment.