Created
April 21, 2014 14:33
-
-
Save andikan/11144474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in setupMesh function | |
if(!meshTemp.checkLargeTriangle((*triangles)[i])) { | |
spineEdgeSet = meshTemp.getSkeletonPointSet(*meshTemp.ps); | |
spineEdgeSet = meshTemp.getSimplifiedPointEdgeSet(spineEdgeSet); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Mesh::findNextSimplifiedPointEdge(std::vector<Point*> &simplePointEdgeSet, std::vector<Point*> &edgePoints, Point* currentPoint, | |
Point* prevPoint, Point* prevJointPoint, std::vector<Point*> &tempPoints) | |
{ | |
// avoid infinite loop | |
if(simplePointEdgeSet.size() > edgePoints.size()) { | |
return; | |
} | |
vector<Point*> neighborPoints; | |
neighborPoints = getNeighborPoint(currentPoint, edgePoints); | |
// current is joint point | |
if(neighborPoints.size() > 2) | |
{ | |
int triangleNum = 6; | |
int divideNum = (int)(tempPoints.size()/triangleNum); | |
if(divideNum == 0 || divideNum == 1) { | |
simplePointEdgeSet.push_back(prevJointPoint); | |
simplePointEdgeSet.push_back(currentPoint); | |
} | |
else { | |
for(int i=0; i<divideNum; i++) { | |
if(i == 0) { | |
simplePointEdgeSet.push_back(prevJointPoint); | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i+1))-1]); | |
} | |
else if(i == divideNum-1) { | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i))-1]); | |
simplePointEdgeSet.push_back(currentPoint); | |
} | |
else { | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i))-1]); | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i+1))-1]); | |
} | |
} | |
} | |
tempPoints.clear(); | |
for(int i=0; i<neighborPoints.size(); i++) | |
{ | |
if(!neighborPoints[i]->isEqualTo(prevPoint)) | |
{ | |
findNextSimplifiedPointEdge(simplePointEdgeSet, edgePoints, neighborPoints[i], currentPoint, currentPoint, tempPoints); | |
} | |
} | |
return; | |
} | |
// current is sleeve point | |
else if(neighborPoints.size() == 2) | |
{ | |
tempPoints.push_back(currentPoint); | |
for(int i=0; i<neighborPoints.size(); i++) | |
{ | |
if(!neighborPoints[i]->isEqualTo(prevPoint)) | |
{ | |
findNextSimplifiedPointEdge(simplePointEdgeSet, edgePoints, neighborPoints[i], currentPoint, prevJointPoint, tempPoints); | |
} | |
} | |
return; | |
} | |
// current is terminal point | |
else if(neighborPoints.size() == 1) | |
{ | |
int triangleNum = 6; | |
int divideNum = (int)(tempPoints.size()/triangleNum); | |
if(divideNum == 0 || divideNum == 1) { | |
simplePointEdgeSet.push_back(prevJointPoint); | |
simplePointEdgeSet.push_back(currentPoint); | |
} | |
else { | |
for(int i=0; i<divideNum; i++) { | |
if(i == 0) { | |
simplePointEdgeSet.push_back(prevJointPoint); | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i+1))-1]); | |
} | |
else if(i == divideNum-1) { | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i))-1]); | |
simplePointEdgeSet.push_back(currentPoint); | |
} | |
else { | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i))-1]); | |
simplePointEdgeSet.push_back(tempPoints[(triangleNum*(i+1))-1]); | |
} | |
} | |
} | |
tempPoints.clear(); | |
return; | |
} | |
} | |
bool Mesh::checkLargeTriangle(std::vector<p2t::Triangle*> triangles) | |
{ | |
float maxArea = 0; | |
for(uint i=0; i<triangles.size(); i++) | |
{ | |
p2t::Triangle t = *triangles[i]; | |
p2t::Point a = *t.GetPoint(0); | |
p2t::Point b = *t.GetPoint(1); | |
p2t::Point c = *t.GetPoint(2); | |
// Heron's formula | |
float abLength = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); | |
float bcLength = sqrt((b.x-c.x)*(b.x-c.x) + (b.y-c.y)*(b.y-c.y)); | |
float caLength = sqrt((c.x-a.x)*(c.x-a.x) + (c.y-a.y)*(c.y-a.y)); | |
float halfLength = (abLength + bcLength + caLength)/2; | |
float triangleArea = sqrt(halfLength*(halfLength-abLength)*(halfLength-bcLength)*(halfLength-caLength)); | |
if(triangleArea > maxArea) { | |
maxArea = triangleArea; | |
} | |
} | |
if(maxArea > 1200) { | |
return true; | |
} | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mesh class | |
bool checkLargeTriangle(std::vector<p2t::Triangle*> triangles); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment