#1156 bugfix: Fix for polygons using the same vertex multiple times, but not consecutively

master
Marius Kintel 2015-01-15 22:01:30 -05:00
parent 3f4e6705e8
commit b23ca0407f
3 changed files with 32 additions and 21 deletions

View File

@ -0,0 +1,5 @@
50.95040130615234375,53.037654876708984375,9.35305023193359375
50.225086212158203125,53.049152374267578125,9.4121952056884765625
50.953746795654296875,53.037601470947265625,9.3527774810791015625
55.285125732421875,53.514209747314453125,9.3527774810791015625
50.953746795654296875,53.037601470947265625,9.3527774810791015625

View File

@ -10,6 +10,7 @@
#include "Reindexer.h"
#include "linalg.h"
#include "grid.h"
#include "printutils.h"
static void export_stl(const IndexedTriangleMesh &trimesh, std::ostream &output)
{
@ -106,6 +107,8 @@ bool import_polygon(IndexedPolygons &polyhole, const std::string &filename)
int main(int argc, char *argv[])
{
OpenSCAD::debug = "GeometryUtils";
IndexedPolygons polyhole;
Vector3f *normal = NULL;
if (argc >= 2) {

View File

@ -63,7 +63,9 @@ bool GeometryUtils::tessellatePolygonWithHoles(const IndexedPolygons &polygons,
int numContours = 0;
std::vector<TESSreal> contour;
std::vector<int> vflags(polygons.vertices.size()); // Inits with 0's
// Since libtess2's indices is based on the running number of points added, we need to map back
// to our indices. allindices does the mapping.
std::vector<int> allindices;
BOOST_FOREACH(const IndexedFace &face, polygons.faces) {
const Vector3f *verts = &polygons.vertices.front();
contour.clear();
@ -72,7 +74,7 @@ bool GeometryUtils::tessellatePolygonWithHoles(const IndexedPolygons &polygons,
contour.push_back(v[0]);
contour.push_back(v[1]);
contour.push_back(v[2]);
vflags[idx]++;
allindices.push_back(idx);
}
assert(face.size() >= 3);
PRINTDB("Contour: %d\n", face.size());
@ -104,7 +106,8 @@ bool GeometryUtils::tessellatePolygonWithHoles(const IndexedPolygons &polygons,
C) For each unused vertex, create a triangle connecting it to the existing mesh
*/
const IndexedFace &face = polygons.faces.front();
int inputSize = face.size();
int inputSize = allindices.size(); // inputSize is number of points added to libtess2
std::vector<int> vflags(inputSize); // Inits with 0's
IndexedTriangle tri;
for (int t=0;t<numelems;t++) {
@ -115,28 +118,28 @@ bool GeometryUtils::tessellatePolygonWithHoles(const IndexedPolygons &polygons,
else tri[i] = vidx; // A)
}
PRINTDB("%d (%d) %d (%d) %d (%d)",
elements[t*3 + 0] % vindices[elements[t*3 + 0]] %
elements[t*3 + 1] % vindices[elements[t*3 + 1]] %
elements[t*3 + 2] % vindices[elements[t*3 + 2]]);
elements[t*3 + 0] % allindices[vindices[elements[t*3 + 0]]] %
elements[t*3 + 1] % allindices[vindices[elements[t*3 + 1]]] %
elements[t*3 + 2] % allindices[vindices[elements[t*3 + 2]]]);
// FIXME: We ignore self-intersecting triangles rather than detecting and handling this
if (!err) {
triangles.push_back(tri);
vflags[tri[0]] = 0; // B)
vflags[tri[1]] = 0;
vflags[tri[2]] = 0;
vflags[tri[0]]++; // B)
vflags[tri[1]]++;
vflags[tri[2]]++;
triangles.push_back(IndexedTriangle(allindices[tri[0]], allindices[tri[1]], allindices[tri[2]]));
}
}
for (int i=0;i<inputSize;i++) {
if (vflags[face[i]]) { // vertex missing in output: C)
int startv = (i+inputSize-1)%inputSize;
if (!vflags[i]) { // vertex missing in output: C)
int starti = (i+inputSize-1)%inputSize;
int j;
for (j = i; j < inputSize && vflags[face[j]]; j++) {
for (j = i; j < inputSize && !vflags[j]; j++) {
// Create triangle fan from vertex i-1 to the first existing vertex
PRINTDB("(%d) (%d) (%d)\n", face[startv] % face[j] % face[((j+1)%inputSize)]);
tri[0] = face[startv];
tri[1] = face[j];
tri[2] = face[(j+1)%inputSize];
PRINTDB("(%d) (%d) (%d)\n", allindices[starti] % allindices[j] % allindices[((j+1)%inputSize)]);
tri[0] = allindices[starti];
tri[1] = allindices[j];
tri[2] = allindices[(j+1)%inputSize];
triangles.push_back(tri);
}
i = j;
@ -150,12 +153,12 @@ bool GeometryUtils::tessellatePolygonWithHoles(const IndexedPolygons &polygons,
for (int i=0;i<3;i++) {
int vidx = vindices[elements[t*3 + i]];
if (vidx == TESS_UNDEF) err = true;
else tri[i] = vidx;
else tri[i] = allindices[vidx];
}
PRINTDB("%d (%d) %d (%d) %d (%d)",
elements[t*3 + 0] % vindices[elements[t*3 + 0]] %
elements[t*3 + 1] % vindices[elements[t*3 + 1]] %
elements[t*3 + 2] % vindices[elements[t*3 + 2]]);
elements[t*3 + 0] % allindices[vindices[elements[t*3 + 0]]] %
elements[t*3 + 1] % allindices[vindices[elements[t*3 + 1]]] %
elements[t*3 + 2] % allindices[vindices[elements[t*3 + 2]]]);
// FIXME: We ignore self-intersecting triangles rather than detecting and handling this
if (!err) {
triangles.push_back(tri);