summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2010-01-14 08:14:52 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2010-01-14 08:14:52 (GMT)
commitd349412aefa34723ddfb4cc532f6ca6621d6e3cc (patch)
treeedc2f9d642e4335802703c4d0ba22c0c3a3647c4
parente1d58382d94de47354080bb2c86099809d82e74a (diff)
Clifford Wolf:
Improved handling of imported STL with small or thin triangles git-svn-id: http://svn.clifford.at/openscad/trunk@283 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--TODO.txt7
-rw-r--r--dxfdata.cc2
-rw-r--r--dxftess-glu.cc2
-rw-r--r--nef2dxf.cc9
-rw-r--r--openscad.h7
-rw-r--r--polyset.cc14
6 files changed, 24 insertions, 17 deletions
diff --git a/TODO.txt b/TODO.txt
index 94f7d86..e0681b1 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -5,9 +5,7 @@ o Some invalid DXF data gets pass the import checks and breaks the tessing code
o Broken polyhedron() entities are not correctly detected and cause CGAL segfaults
o Tesselation via GLU sometimes produces strange results
o Non-manifold objects make CGAL crash (e.g. two cubes which touch at one edge)
-o crash: polygon(points=[[0,0],[10,0],[10,10],[0,10]],
- paths=[[0,1,2],[2,3,1]]);
-o crash: DiscButton_Pegs_Array_20100112.scad
+o crash: polygon(points=[[0,0],[10,0],[10,10],[0,10]], paths=[[0,1,2],[2,3,1]]);
USER INTERFACE
--------------
@@ -60,6 +58,9 @@ o Language Frontend
o DXF Import
- Support for POLYLINE entity
- Support for SPLINE entity
+o Mesh optimization on STL export
+ - Remove super small triangles (all sides are short)
+ - Replace super thin triangles (one h is short)
o Misc
- Add symbolic colors to the color() statement
- Go through default values of parameters (e.g. cube() has x,y,z=1 while linear_extrude() has height=100)
diff --git a/dxfdata.cc b/dxfdata.cc
index 86a942d..9829033 100644
--- a/dxfdata.cc
+++ b/dxfdata.cc
@@ -50,7 +50,7 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
}
QTextStream stream(&f);
- Grid2d< QVector<int> > grid;
+ Grid2d< QVector<int> > grid(GRID_COARSE);
QList<Line> lines; // Global lines
QHash< QString, QList<Line> > blockdata; // Lines in blocks
diff --git a/dxftess-glu.cc b/dxftess-glu.cc
index 3256b4f..6bf0ad5 100644
--- a/dxftess-glu.cc
+++ b/dxftess-glu.cc
@@ -211,7 +211,7 @@ void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_trian
gluTessNormal(tobj, 0, 0, +1);
}
- Grid3d< QPair<int,int> > point_to_path;
+ Grid3d< QPair<int,int> > point_to_path(GRID_COARSE);
for (int i = 0; i < dxf->paths.count(); i++) {
if (!dxf->paths[i].is_closed)
diff --git a/nef2dxf.cc b/nef2dxf.cc
index c116260..9c69e84 100644
--- a/nef2dxf.cc
+++ b/nef2dxf.cc
@@ -24,7 +24,7 @@
DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
{
- Grid2d<int> grid;
+ Grid2d<int> grid(GRID_COARSE);
typedef CGAL_Nef_polyhedron2::Explorer Explorer;
typedef Explorer::Face_const_iterator fci_t;
@@ -34,7 +34,7 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit)
{
heafcc_t fcirc(E.halfedge(fit)), fend(fcirc);
- int first_point = -1;
+ int first_point = -1, last_point = -1;
CGAL_For_all(fcirc, fend) {
if (E.is_standard(E.target(fcirc))) {
Explorer::Point ep = E.point(E.target(fcirc));
@@ -50,7 +50,10 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
paths.append(Path());
first_point = this_point;
}
- paths.last().points.append(&points[this_point]);
+ if (this_point != last_point) {
+ paths.last().points.append(&points[this_point]);
+ last_point = this_point;
+ }
}
}
if (first_point >= 0) {
diff --git a/openscad.h b/openscad.h
index 8ad164d..d5d08f8 100644
--- a/openscad.h
+++ b/openscad.h
@@ -70,6 +70,9 @@ class AbstractIntersectionNode;
class AbstractPolyNode;
struct CGAL_Nef_polyhedron;
+const double GRID_COARSE = 0.001;
+const double GRID_FINE = 0.0000001;
+
template <typename T>
class Grid2d
{
@@ -77,7 +80,7 @@ public:
double res;
QHash<QPair<int,int>, T> db;
- Grid2d(double resolution = 0.001) {
+ Grid2d(double resolution) {
res = resolution;
}
T &align(double &x, double &y) {
@@ -133,7 +136,7 @@ public:
double res;
QHash<QPair<QPair<int,int>,int>, T> db;
- Grid3d(double resolution = 0.001) {
+ Grid3d(double resolution) {
res = resolution;
}
T &align(double &x, double &y, double &z) {
diff --git a/polyset.cc b/polyset.cc
index 2c25257..5bccd6a 100644
--- a/polyset.cc
+++ b/polyset.cc
@@ -32,7 +32,7 @@ PolySet::ps_cache_entry::~ps_cache_entry() {
ps->unlink();
}
-PolySet::PolySet()
+PolySet::PolySet() : grid(GRID_FINE)
{
is2d = false;
convexity = 1;
@@ -325,8 +325,8 @@ public:
{
CGAL_Polybuilder B(hds, true);
- QVector<PolySet::Point> vertices;
- Grid3d<int> vertices_idx;
+ QList<PolySet::Point> vertices;
+ Grid3d<int> vertices_idx(GRID_FINE);
for (int i = 0; i < ps->polygons.size(); i++) {
const PolySet::Polygon *poly = &ps->polygons[i];
@@ -371,14 +371,14 @@ public:
for (int j = 0; j < poly->size(); j++) {
const PolySet::Point *p = &poly->at(j);
#ifdef GEN_SURFACE_DEBUG
- printf(" %d", vertices_idx.data(p->x, p->y, p->z));
+ printf(" %d (%f,%f,%f)", vertices_idx.data(p->x, p->y, p->z), p->x, p->y, p->z);
#endif
if (!facet_is_degenerated)
B.add_vertex_to_facet(vertices_idx.data(p->x, p->y, p->z));
}
#ifdef GEN_SURFACE_DEBUG
if (facet_is_degenerated)
- printf(" (degenerated)\n");
+ printf(" (degenerated)");
printf("\n");
#endif
if (!facet_is_degenerated)
@@ -406,7 +406,7 @@ CGAL_Nef_polyhedron PolySet::render_cgal_nef_polyhedron() const
typedef point_list_t::iterator point_list_it;
std::list< point_list_t > pdata_point_lists;
std::list < std::pair < point_list_it, point_list_it > > pdata;
- Grid2d<CGAL_Nef_polyhedron2::Point> grid;
+ Grid2d<CGAL_Nef_polyhedron2::Point> grid(GRID_COARSE);
for (int i = 0; i < this->polygons.size(); i++) {
pdata_point_lists.push_back(point_list_t());
@@ -430,7 +430,7 @@ CGAL_Nef_polyhedron PolySet::render_cgal_nef_polyhedron() const
return CGAL_Nef_polyhedron(N);
#else
CGAL_Nef_polyhedron2 N;
- Grid2d<CGAL_Nef_polyhedron2::Point> grid;
+ Grid2d<CGAL_Nef_polyhedron2::Point> grid(GRID_COARSE);
for (int i = 0; i < this->polygons.size(); i++) {
std::list<CGAL_Nef_polyhedron2::Point> plist;
contact: Jan Huwald // Impressum