diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Preferences.cc | 12 | ||||
-rw-r--r-- | src/export.cc | 40 | ||||
-rw-r--r-- | src/mainwin.cc | 1 |
3 files changed, 25 insertions, 28 deletions
diff --git a/src/Preferences.cc b/src/Preferences.cc index 1f52311..4c43f2d 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -47,8 +47,14 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent) // Setup default settings this->defaultmap["3dview/colorscheme"] = this->colorSchemeChooser->currentItem()->text(); - this->defaultmap["editor/fontfamily"] = this->fontChooser->currentText(); - this->defaultmap["editor/fontsize"] = this->fontSize->currentText().toUInt(); +#ifdef Q_WS_X11 + this->defaultmap["editor/fontfamily"] = "Mono"; +#elif defined (Q_WS_WIN) + this->defaultmap["editor/fontfamily"] = "Console"; +#elif defined (Q_WS_MAC) + this->defaultmap["editor/fontfamily"] = "Monaco"; +#endif + this->defaultmap["editor/fontsize"] = 12; this->defaultmap["advanced/opencsg_show_warning"] = true; this->defaultmap["advanced/enable_opencsg_opengl1x"] = true; @@ -212,7 +218,7 @@ void Preferences::updateGUI() if (!found.isEmpty()) this->colorSchemeChooser->setCurrentItem(found.first()); QString fontfamily = getValue("editor/fontfamily").toString(); - int fidx = this->fontChooser->findText(fontfamily); + int fidx = this->fontChooser->findText(fontfamily,Qt::MatchContains); if (fidx >= 0) { this->fontChooser->setCurrentIndex(fidx); } diff --git a/src/export.cc b/src/export.cc index 5ce2d15..5ac3ac0 100644 --- a/src/export.cc +++ b/src/export.cc @@ -83,32 +83,24 @@ void export_stl(CGAL_Nef_polyhedron *root_N, std::ostream &output, QProgressDial stream.str(""); stream << x3 << " " << y3 << " " << z3; std::string vs3 = stream.str(); + CGAL_Polyhedron::Traits::Vector_3 normal(1,0,0); if (vs1 != vs2 && vs1 != vs3 && vs2 != vs3) { - // The above condition ensures that vs1-vs2, vs1-vs3, and their cross - // product are non-zero. Floating point arithmetic may however truncate - // small values to 0. This can be avoided by first scaling the components - // of vs1-vs2 and vs1-vs3. This has no effect on the resulting unit - // normal vector. - double dn[6] = { x1-x2, y1-y2, z1-z2, x1-x3, y1-y3, z1-z3 }; - double maxdn = 0; - int i; - for (i = 0; i < 6; ++i) { - double dx = dn[i]; - if (dx < 0) dx = -dx; - if (dx > maxdn) maxdn = dx; - } - for (i = 0; i < 6; ++i) dn[i] /= maxdn; - double nx = dn[1]*dn[5] - dn[2]*dn[4]; - double ny = dn[2]*dn[3] - dn[0]*dn[5]; - double nz = dn[0]*dn[4] - dn[1]*dn[3]; - double nlength = sqrt(nx*nx + ny*ny + nz*nz); - // Avoid generating normals for polygons with zero area - double eps = 0.000001; - if (nlength < eps) nlength = 1.0; + // The above condition ensures that there are 3 distinct vertices, but + // they may be collinear. If they are, the unit normal is meaningless + // so the default value of "1 0 0" can be used. If the vertices are not + // collinear then the unit normal must be calculated from the + // components. + if (!CGAL::collinear(v1.point(),v2.point(),v3.point())) { + // Pseudocode: CGAL kernel must be set up to enable unit_normal and + // Vector type must be declared as Vector_3<Kernel>. + // http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Function_unit_normal.html + normal = CGAL::normal(v1.point(),v2.point(),v3.point()); + normal = normal / sqrt(CGAL::to_double(normal.squared_length())); + } output << " facet normal " - << nx / nlength << " " - << ny / nlength << " " - << nz / nlength << "\n"; + << CGAL::to_double(normal.x()) << " " + << CGAL::to_double(normal.y()) << " " + << CGAL::to_double(normal.z()) << "\n"; output << " outer loop\n"; output << " vertex " << vs1 << "\n"; output << " vertex " << vs2 << "\n"; diff --git a/src/mainwin.cc b/src/mainwin.cc index f9029d0..2c52eeb 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -178,7 +178,6 @@ MainWindow::MainWindow(const QString &filename) editor->setTabStopWidth(30); #endif editor->setLineWrapping(true); // Not designable - setFont("", 12); // Init default font this->glview->statusLabel = new QLabel(this); statusBar()->addWidget(this->glview->statusLabel); |