Commit 0e6860b6 by Daniel

Simplified compareAndAdd3DVertices

parent 5d2fc9a6
......@@ -15,9 +15,9 @@ class Contour3D {
void start();
void addBox(double x1, double x2, double y1, double y2, double z1, double z2);
void addVisibleVertex(Vertex& toAdd, double z, bool back);
void compareAndAdd3DVertices(Slice2D base, Slice2D toCompare);
void triCompareAndAdd3DVertices(Slice2D base, Slice2D mid, Slice2D toCompare);
void addVisibleVertex(const Vertex& toAdd, double z, bool back);
void compareAndAdd3DVertices(const Slice2D& base, const Slice2D& toCompare);
void triCompareAndAdd3DVertices(const Slice2D& base, const Slice2D& mid, const Slice2D& toCompare);
void outputVertices();
void outputObj();
void outputVerticesAndFaceDegrees();
......@@ -37,6 +37,7 @@ class Contour3D {
void writeVisibleVerticesObj();
vector<Slice2D> generate2DContours();
void checkECase(const Slice2D& base, const Slice2D& toCompare, unsigned int& baseIndex, unsigned int& compIndex);
};
#endif // 3DCONTOUR_H
......@@ -62,7 +62,7 @@ bool vertexSortYX(const Vertex & v1, const Vertex & v2) {
}
//creates a 3D vertex fron the 3D one, adding z and updating the z face degree, and adds it to the list
void Contour3D::addVisibleVertex(Vertex& toAdd, double z, bool back) {
void Contour3D::addVisibleVertex(const Vertex& toAdd, double z, bool back) {
Vertex3D v3d = {toAdd.x, toAdd.y, z, toAdd.fd};
if(back) {
v3d.fd.zm++;
......@@ -73,35 +73,6 @@ void Contour3D::addVisibleVertex(Vertex& toAdd, double z, bool back) {
visibleVertices.emplace_back(v3d);
}
/*
void temp() {
Vertex bottom = slice.v[i];
Vertex top = slice.v[i + 1];
if(bottom.y <= v.y and top.y >= v.y) {
if(bottom.x == v.x) {
if(bottom.y < v.y and top.y > v.y) { //it's on a vertical edge
Vertex toCompare = bottom;
if(i > 0) {
Vertex previous = slice.v[i-1];
if(toCompare.y == previous.y and toCompare.x == previous.x and previous.fd.ym == 1) {
toCompare = previous;
}
}
//if convex, vertex and edge must both "point" to the same way, if not convex, opposite ways
return v.fd.convex == (v.fd.x == toCompare.fd.x);
}
//it's on a vertex
return false;
}
}
if(bottom.y <= v.y and top.y > v.y) {
//each edge we cross makes us change from being inside to outside the polygon
inside = !inside;
}
}*/
//determines if vertex v is inside the region defined by set of vertices slice
bool isInside(const Vertex& v, const Slice2D& slice) {
//at this point, slice.v is sorted in x,y
......@@ -206,8 +177,32 @@ Vertex swapFaceDegrees(const Vertex& input) {
return toRet;
}
void Contour3D::checkECase(const Slice2D& base, const Slice2D& toCompare, unsigned int& baseIndex, unsigned int& compIndex) {
//we compare both vertices to the next ones, in case any are equal, we're in case -e
if(compIndex < toCompare.v.size() -1 and
toCompare.v[compIndex+1].x == base.v[baseIndex].x and toCompare.v[compIndex+1].y == base.v[baseIndex].y) {
//case -e
Vertex v2d = swapFaceDegrees(base.v[baseIndex]);
addVisibleVertex(v2d, base.z, true);
++baseIndex;
compIndex += 2;
return;
}
if(baseIndex < base.v.size() -1 and
toCompare.v[compIndex].x == base.v[baseIndex+1].x and toCompare.v[compIndex].y == base.v[baseIndex+1].y) {
//case -e
Vertex v2d = swapFaceDegrees(toCompare.v[compIndex]);
addVisibleVertex(v2d, base.z, false);
++compIndex;
baseIndex += 2;
return;
}
}
//compares two slices via xor merge, and adds the resulting vertices to the output list
void Contour3D::compareAndAdd3DVertices(Slice2D base, Slice2D toCompare) {
void Contour3D::compareAndAdd3DVertices(const Slice2D& base, const Slice2D& toCompare) {
unsigned int compIndex = 0;
unsigned int baseIndex = 0;
......@@ -219,7 +214,7 @@ void Contour3D::compareAndAdd3DVertices(Slice2D base, Slice2D toCompare) {
++baseIndex;
break;
case POSEQUAL: //same position, different convexity: cases g, h, and i
case POSEQUAL: {//same position, different convexity: cases g, h, and i
//false positive, advancing both
if(base.z == toCompare.z) {
......@@ -228,50 +223,22 @@ void Contour3D::compareAndAdd3DVertices(Slice2D base, Slice2D toCompare) {
break;
}
//we compare both vertices to the next ones, in case any are equal, we're in case -e
if(compIndex < toCompare.v.size() -1 and
toCompare.v[compIndex+1].x == base.v[baseIndex].x and toCompare.v[compIndex+1].y == base.v[baseIndex].y) {
//case -e
Vertex v2d = swapFaceDegrees(base.v[baseIndex]);
addVisibleVertex(v2d, base.z, true);
++baseIndex;
compIndex += 2;
break;
}
if(baseIndex < base.v.size() -1 and
toCompare.v[compIndex].x == base.v[baseIndex+1].x and toCompare.v[compIndex].y == base.v[baseIndex+1].y) {
//case -e
Vertex v2d = swapFaceDegrees(toCompare.v[compIndex]);
addVisibleVertex(v2d, base.z, false);
++compIndex;
baseIndex += 2;
break;
}
checkECase(base, toCompare, baseIndex, compIndex);
if(toCompare.v[compIndex].fd.x != base.v[baseIndex].fd.x and toCompare.v[compIndex].fd.y != base.v[baseIndex].fd.y) {
//case i, non-convex vertex added with no changes needed
if(!toCompare.v[compIndex].fd.convex) {
addVisibleVertex(toCompare.v[compIndex], base.z, false);
++compIndex;
}
else {
addVisibleVertex(base.v[baseIndex], base.z, true);
++baseIndex;
}
bool oppositeDirs = toCompare.v[compIndex].fd.x != base.v[baseIndex].fd.x and toCompare.v[compIndex].fd.y != base.v[baseIndex].fd.y;
//oppositeDirs --> case i, non-convex vertex added with no changes needed
//not oppositeDirs --> cases g and h, z uses direction of nonconvex vertex, we add convex vertex, but use opposite Z
if(toCompare.v[compIndex].fd.convex == oppositeDirs) { //2, 4
addVisibleVertex(base.v[baseIndex], base.z, oppositeDirs);
++baseIndex;
}
else {
//cases g and h, z uses direction of nonconvex vertex
//we add convex vertex, but use opposite Z
if(toCompare.v[compIndex].fd.convex) {
addVisibleVertex(toCompare.v[compIndex], base.z, true);
++compIndex;
}
else {
addVisibleVertex(base.v[baseIndex], base.z, false);
++baseIndex;
}
addVisibleVertex(toCompare.v[compIndex], base.z, !oppositeDirs);
++compIndex;
}
}
break;
case FIRST: //base < toComp
......@@ -307,7 +274,7 @@ void Contour3D::compareAndAdd3DVertices(Slice2D base, Slice2D toCompare) {
}
}
void Contour3D::triCompareAndAdd3DVertices(Slice2D base, Slice2D mid, Slice2D toCompare) {
void Contour3D::triCompareAndAdd3DVertices(const Slice2D& base, const Slice2D& mid, const Slice2D& toCompare) {
unsigned int midIndex = 0;
compareAndAdd3DVertices(base, toCompare);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment