From c815c258783112bd67189f9ac9319c77d8bf3662 Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Thu, 23 Feb 2023 20:52:19 +1300 Subject: [PATCH 1/8] files changed to 1.31 changes by Marc Klein in 2019, from SourceForge --- C_reel.cxx | 2 +- StdAfx.h | 4 + c_reel.h | 2 +- stl2dat.cpp | 1069 +++++++++++++++++++++++++++------------------------ 4 files changed, 562 insertions(+), 515 deletions(-) diff --git a/C_reel.cxx b/C_reel.cxx index af26631..017ccf8 100644 --- a/C_reel.cxx +++ b/C_reel.cxx @@ -374,7 +374,7 @@ int_auto DLL_EXPORT double Mfround( return (r - remainder(r,y)); } -int_auto DLL_EXPORT long round( +int_auto DLL_EXPORT long l_round( const double r ) /*- diff --git a/StdAfx.h b/StdAfx.h index 03d534a..f5ccf67 100644 --- a/StdAfx.h +++ b/StdAfx.h @@ -2,6 +2,10 @@ // or project specific include files that are used frequently, but // are changed infrequently // +#ifdef WINVER +#undef WINVER +#endif +#define WINVER 0x0600 #if !defined(AFX_STDAFX_H__CD6A7C2E_D008_11D3_B3AD_0000E814D5B3__INCLUDED_) #define AFX_STDAFX_H__CD6A7C2E_D008_11D3_B3AD_0000E814D5B3__INCLUDED_ diff --git a/c_reel.h b/c_reel.h index 0646d13..8fe62cb 100644 --- a/c_reel.h +++ b/c_reel.h @@ -166,7 +166,7 @@ int_auto DLL_EXPORT double Mfround( ! Use: Round the real on the given precision. */ ; -int_auto DLL_EXPORT long round( +int_auto DLL_EXPORT long l_round( const double r ) /*- diff --git a/stl2dat.cpp b/stl2dat.cpp index e31ff38..1f9abab 100644 --- a/stl2dat.cpp +++ b/stl2dat.cpp @@ -1,6 +1,8 @@ -// 10/02/2011 1.22 Remove trace in nodebug mode. -// 10/02/2011 1.21 Correct bug that stopped reading of file when very small facet was encounterd. -// 10/02/2011 1.20 Add option -oeps used for remove unusefull facets, Debug : Use smaller eps when reading the facets +// 06/07/2019 1.31 Correct file reading problems. +// 13/04/2019 1.30 Adaptation to visual studio 2015. -scale, -scalemm, -berbose added. -silent by default. +// 11/07/2011 1.22 Remove trace in nodebug mode. +// 03/05/2011 1.21 Correct bug that stopped reading of file when very small facet was encounterd. +// 03/05/2011 1.20 Add option -oeps used for remove unusefull facets, Debug : Use smaller eps when reading the facets // 31/01/2011 1.19 Add option -raw (conversion without any optimisation or edge calculation) // 19/01/2011 1.18 Add option -out (output file name) // 18/01/2011 1.17 Correct bug of Author and partname was wrong when -o option is present @@ -40,6 +42,8 @@ #include "stl2dat.h" +#define version "1.31" + static double ag_lim; static double ag_lim_q; static double ag_lim_t; @@ -67,7 +71,7 @@ static bool bfc; static bool silent; static bool ldraw; static bool stl_raw; -static double optim_eps; +static double optim_eps; static bool noprim; static bool debug; @@ -86,14 +90,14 @@ istream & operator >> (istream & is, CString & string) return is; } -double ftrunc( double v, int precision); +double ftrunc(double v, int precision); stl_v stl_edge::coord(int i, int face) { - if (!adjacent[face]) - face = 1 - face; - if (!adjacent[face]) - return stl_v_zero; + if (!adjacent[face]) + face = 1 - face; + if (!adjacent[face]) + return stl_v_zero; int usage = adjacent[face]->usage; if (usage == 0) @@ -120,7 +124,7 @@ void stl_edge::set_coord(int i, int face, const stl_v & val) } } -bool stl_edge::colinear( const stl_v & vd) +bool stl_edge::colinear(const stl_v & vd) { return(coord(1) - coord(0)).paral(vd); } @@ -130,7 +134,7 @@ stl_facet::stl_facet() usage = 3; color = 16; surf = NULL; - for (int i=0; i < 4; i++) + for (int i = 0; i < 4; i++) { edge[i] = 0; vertex[i] = 0; @@ -146,7 +150,7 @@ static long number_edge = 0; stl_edge::stl_edge() { linetype = 2; - for (int i=0; i < 2; i++) + for (int i = 0; i < 2; i++) { coords[i] = 0; vertex[i] = 0; @@ -169,16 +173,16 @@ stl_vertex::stl_vertex(const stl_v & _coords) precision = 2; } -void stl_vertex::add_edge( stl_edge * edge) +void stl_vertex::add_edge(stl_edge * edge) { - edge_list = new stl_edge_list( edge, edge_list); + edge_list = new stl_edge_list(edge, edge_list); } stl_file::stl_file(const char * filename) { - is.open(filename, ios_base::in & ios::binary); + is.open(filename, std::ios::in | std::ios::binary); ok = is.is_open(); origin = stl_v_zero; @@ -236,8 +240,8 @@ bool stl_file::read_header() char header[80]; memset(header, 0, 80); //is.setmode(ios_base::binary); - is.read(header,80); -// is >> header; + is.read(header, 80); + // is >> header; int i = 0; bool cr = false; @@ -254,7 +258,7 @@ bool stl_file::read_header() result = token("solid"); if (result) { - is.get(header,80); + is.get(header, 80); desc = header; desc = desc.Trim(); } @@ -265,7 +269,7 @@ bool stl_file::read_header() i = 79; while (i >= 0 && header[i] == ' ') { - header[i] =0; + header[i] = 0; i--; } desc = CString(header); @@ -273,32 +277,38 @@ bool stl_file::read_header() return(result); } +int n = 1; bool stl_file::new_facet(const stl_v & normal, const stl_v vertex[]) { bool result = false; stl_facet * facet = new stl_facet; - + facet->read_normal = normal; bool identical = false; for (int i = 0; i < 3; i++) { -// facet->coords[i] = vertex[i] - origin; + // facet->coords[i] = vertex[i] - origin; facet->coords[i] = transf * vertex[i]; -/** + /**/ for (int j = 0; j < i; j++) -// if ((facet->coords[i] - facet->coords[j]).norm() < 0.001) + // if ((facet->coords[i] - facet->coords[j]).norm() < 0.001) if (facet->coords[i] == facet->coords[j]) identical = true; -/**/ + /**/ } + //cout << "coords " << n << ":" << facet->coords[0] << " ; " << facet->coords[1] << " ; " << facet->coords[2] << endl; n++; if (!identical) { facet->calculate_normal(); -// facet->normal = ((facet->coords[1] - facet->coords[0]) * -// (facet->coords[2] - facet->coords[0])).normaliz(); -// if (facet->normal != facet->read_normal) -// cout << "diff normal " << facet->normal - facet->read_normal << endl; + // facet->normal = ((facet->coords[1] - facet->coords[0]) * + // (facet->coords[2] - facet->coords[0])).normaliz(); + if (facet->normal != facet->read_normal) + { + cout << "diff normal " << facet->normal << " ; " << facet->read_normal << " ; " << facet->normal - facet->read_normal << endl; + } + if (facet->normal.null()) + facet->normal = facet->read_normal; if (!facet->normal.null()) { facet->nbr_facet = nbr_facet; @@ -313,7 +323,11 @@ bool stl_file::new_facet(const stl_v & normal, const stl_v vertex[]) result = true; } else + { cout << "Error facet normal null !" << endl; + cout << facet->coords[0] << " " << facet->coords[1] << " " << facet->coords[2] << " " << facet->read_normal << " " << facet->normal << endl; + facet->dump(); + } } return(result); } @@ -351,18 +365,18 @@ int stl_file::read_facet_text() } if (result) result = token("endloop"); if (result) result = token("endfacet"); - if (result) new_facet( normal, vertex); + if (result) new_facet(normal, vertex); return(result ? 0 : -1); } stl_v read_v(ifstream & is) { union { - float f[3]; - char buf[12]; + float f[3]; + char buf[12]; } u; - is.read(u.buf,12); - return( stl_v(u.f[0], u.f[1], u.f[2])); + is.read(u.buf, 12); + return(stl_v(u.f[0], u.f[1], u.f[2])); } bool stl_file::read_facet_bin() @@ -370,41 +384,46 @@ bool stl_file::read_facet_bin() bool result; stl_v normal; stl_v vertex[3]; - + normal = read_v(is); for (int i = 0; i < 3; i++) vertex[i] = read_v(is); char dummy[2]; - is.read(dummy,2); - result = new_facet( normal, vertex); + is.read(dummy, 2); result = !is.eof(); + if (result) + result = new_facet(normal, vertex); return(result); } bool stl_file::read() { - bool result = read_header(); - if (!result) - return(result); - + bool result = true; nbr_facet = 0; if (stl_bin) { + char header[80]; + is.read(header, 80); union { - long l; - char buf[4]; + long l; + char buf[4]; } u; - is.read(u.buf,4); + is.read(u.buf, 4); long face_number = u.l; while (nbr_facet < face_number && result) { if (result = read_facet_bin()) - nbr_facet++; + nbr_facet++; } + if (nbr_facet < face_number) + cout << "face_number " << face_number << " face read " << nbr_facet << endl; } else { + result = read_header(); + if (!result) + return(result); int err = 0; bool done = false; while (is && !done) @@ -516,8 +535,8 @@ bool stl_facet::check() { result = false; if (!silent) - cout << "check facet " << nbr_facet << " colinear vertices " << i << " " << j << " " << k<< endl; - is_convex(true); + cout << "check facet " << nbr_facet << " colinear vertices " << i << " " << j << " " << k << endl; + is_convex(!silent); } } @@ -559,18 +578,18 @@ bool stl_edge::check() cout << "check edge " << ident() << " : adjacent facet[1] deleted" << endl; } - if (result && adjacent[1] && - ((coord(0) != coord(0,1) && coord(0) != coord(1,1)) || - (coord(1) != coord(1,1) && coord(1) != coord(0,1)))) + if (result && adjacent[1] && + ((coord(0) != coord(0, 1) && coord(0) != coord(1, 1)) || + (coord(1) != coord(1, 1) && coord(1) != coord(0, 1)))) { result = false; if (!silent) cout << "check edge " << ident() << " : vertices do not correspond:" - << "[" << coords[0] << "]" << coord(0) << " != " - << "[" << coords[1] << "]" << coord(0,1) << " & " - << "[" << (coords[0] + 1) % adjacent[0]->usage << "]" << coord(1) << " != " - << "[" << (coords[1] + 1) % adjacent[1]->usage << "]" << coord(1,1) - << endl; + << "[" << coords[0] << "]" << coord(0) << " != " + << "[" << coords[1] << "]" << coord(0, 1) << " & " + << "[" << (coords[0] + 1) % adjacent[0]->usage << "]" << coord(1) << " != " + << "[" << (coords[1] + 1) % adjacent[1]->usage << "]" << coord(1, 1) + << endl; } if (result && (coord(0) - coord(1)).norm() < optim_eps) { @@ -580,14 +599,14 @@ bool stl_edge::check() } if (result) for (int i = 0; i < 2; i++) - if (adjacent[i] && adjacent[i]->adjacent[coords[i]] != adjacent[1-i]) + if (adjacent[i] && adjacent[i]->adjacent[coords[i]] != adjacent[1 - i]) { result = false; if (!silent) { - cout << "check edge : adjacent[" << 1-i << "] "; - if (adjacent[1-i]) - cout << adjacent[1-i]->nbr_facet << " "; + cout << "check edge : adjacent[" << 1 - i << "] "; + if (adjacent[1 - i]) + cout << adjacent[1 - i]->nbr_facet << " "; cout << " != facet "; if (adjacent[i] && adjacent[i]->adjacent[coords[i]]) cout << adjacent[i]->adjacent[coords[i]]->nbr_facet; @@ -668,7 +687,7 @@ bool stl_file::check() result = false; } else if ((cure->item->coord(0) == curf->item->coord(0) && cure->item->coord(1) == curf->item->coord(1)) || - (cure->item->coord(0) == curf->item->coord(1) && cure->item->coord(1) == curf->item->coord(0)) ) + (cure->item->coord(0) == curf->item->coord(1) && cure->item->coord(1) == curf->item->coord(0))) { if (!silent) cout << "check : same edge " << cure->item->ident() << " and " << curf->item->ident() << endl; @@ -698,7 +717,7 @@ static int cur_rand_col = 0; int random_color() { cur_rand_col = (cur_rand_col + 1) % 16; - return( cur_rand_col); + return(cur_rand_col); } bool stl_facet::recalculate_precision() @@ -719,15 +738,15 @@ bool stl_facet::recalculate_precision() } int face = 0; if (!adjacent[face]) - face = 1 - face; + face = 1 - face; if (adjacent[face]) { - double det = fabs(adjacent[face]->determinant()); - if (det > determinant_eps && precision < 8) - { - precision++; - result = recalculate_precision(); - } + double det = fabs(adjacent[face]->determinant()); + if (det > determinant_eps && precision < 8) + { + precision++; + result = recalculate_precision(); + } } } return(result); @@ -738,18 +757,18 @@ void stl_facet::write(ostream & os, int col3, int col4, int edgecolor, bool prin if (!printed) { printed = true; - switch(usage) - { -/* - case 2: - os << setprecision(5); - if (printedge) - os << "2 " << edgecolor << " " << coords[0] << " " << coords[1] << endl; - break; -*/ + switch (usage) + { + /* + case 2: + os << setprecision(5); + if (printedge) + os << "2 " << edgecolor << " " << coords[0] << " " << coords[1] << endl; + break; + */ case 3: - if (!no_line3) - { + if (!no_line3) + { if (debug) os << "0 facet " << nbr_facet << " " << normal /*<< " " << read_normal*/ << " " << surface3pt(coords[0], coords[1], coords[2]) << endl; os << setprecision(7); @@ -775,27 +794,27 @@ void stl_facet::write(ostream & os, int col3, int col4, int edgecolor, bool prin os << "2 " << edgecolor << " " << vertex[2] << " " << vertex[0] << endl; } } - } - break; + } + break; case 4: - if (!no_line4) - { + if (!no_line4) + { if (debug) os << "0 facet " << nbr_facet << " " << normal /*<< " " << read_normal*/ << endl; os << setprecision(7); cout << setprecision(7); if (printface) { -// int tmpcol = col4; -// double d = determinant(-1); -//if (fabs(d) > determinant_eps) -// if (d != 0) -// { -// tmpcol = 4; -//cout << "4 " << 4 << " " << vertex[0] << " " << vertex[1] << " " << vertex[2] << " " << vertex[3] << " det=" << d << endl; -// } + // int tmpcol = col4; + // double d = determinant(-1); + //if (fabs(d) > determinant_eps) + // if (d != 0) + // { + // tmpcol = 4; + //cout << "4 " << 4 << " " << vertex[0] << " " << vertex[1] << " " << vertex[2] << " " << vertex[3] << " det=" << d << endl; + // } os << "4 " << col4 << " " << vertex[0] << " " << vertex[1] << " " << vertex[2] << " " << vertex[3] << endl; -// for (int i=0;i<4;vertex[i++]->precision=4);os << "4 " << col4 << " " << vertex[0] << " " << vertex[1] << " " << vertex[2] << " " << vertex[3] << endl << "0 // (3)" << determinant(3) << " (4)" << determinant(4) << " (5)" << determinant(5) << endl; + // for (int i=0;i<4;vertex[i++]->precision=4);os << "4 " << col4 << " " << vertex[0] << " " << vertex[1] << " " << vertex[2] << " " << vertex[3] << endl << "0 // (3)" << determinant(3) << " (4)" << determinant(4) << " (5)" << determinant(5) << endl; } if (!printedge) { @@ -804,15 +823,15 @@ void stl_facet::write(ostream & os, int col3, int col4, int edgecolor, bool prin os << "2 " << edgecolor << " " << vertex[2] << " " << vertex[3] << endl; os << "2 " << edgecolor << " " << vertex[3] << " " << vertex[0] << endl; } - } - break; -/* - case 5: - os << setprecision(5); - if (printedge) - os << "5 " << edgecolor << " " << coords[0] << " " << coords[1] << " " << coords[2] << " " << coords[3] << endl; + } break; -*/ + /* + case 5: + os << setprecision(5); + if (printedge) + os << "5 " << edgecolor << " " << coords[0] << " " << coords[1] << " " << coords[2] << " " << coords[3] << endl; + break; + */ } for (int i = 0; i < usage; i++) if (edge[i]) @@ -823,14 +842,14 @@ void stl_facet::write(ostream & os, int col3, int col4, int edgecolor, bool prin CString stl_facet::ident() { char buf[16]; - sprintf_s(buf,"%d",nbr_facet); + sprintf_s(buf, "%d", nbr_facet); return(CString(buf)); } void stl_facet::calculate_normal() { - normal = ((coords[1] - coords[0]) * - (coords[2] - coords[0])).normaliz(); + normal = ((coords[1] - coords[0]) * + (coords[2] - coords[0])).normaliz(); } void stl_facet::dump() @@ -841,16 +860,16 @@ void stl_facet::dump() cout << "deleted" << endl; return; } - for (int i = 0 ; i < usage ; i++) + for (int i = 0; i < usage; i++) if (adjacent[i]) cout << adjacent[i]->ident() << " "; else cout << ". "; cout << " \t[ "; - for (int i = 0 ; i < usage ; i++) + for (int i = 0; i < usage; i++) cout << edge[i]->nbr_edge << " "; cout << "]\t"; - for (int i = 0 ; i < usage ; i++) + for (int i = 0; i < usage; i++) cout << "<" << coords[i] << "> "; cout << endl; } @@ -863,10 +882,10 @@ void stl_edge::dump() cout << "deleted" << endl; return; } - for (int i = 0 ; i < 2 ; i++) + for (int i = 0; i < 2; i++) cout << coords[i] << " "; cout << " "; - for (int i = 0 ; i < 2 ; i++) + for (int i = 0; i < 2; i++) cout << "<" << vertex[i]->coords << "> "; cout << endl; } @@ -890,17 +909,17 @@ void stl_vertex::dump() double small0(double v); -ostream & operator << ( - ostream & s, - const stl_vertex * v - ) +ostream & operator << ( + ostream & s, + const stl_vertex * v + ) { if (v) { - return (s << - small0(ftrunc(v->coords.x_coord(),-v->precision)) << " " << - small0(ftrunc(v->coords.y_coord(),-v->precision)) << " " << - small0(ftrunc(v->coords.z_coord(),-v->precision)) ); + return (s << + small0(ftrunc(v->coords.x_coord(), -v->precision)) << " " << + small0(ftrunc(v->coords.y_coord(), -v->precision)) << " " << + small0(ftrunc(v->coords.z_coord(), -v->precision))); } else { @@ -908,27 +927,27 @@ ostream & operator << ( } } -void stl_edge::write(ostream & os, int col2, int col5){ +void stl_edge::write(ostream & os, int col2, int col5) { if (!printed) { - switch(linetype) + switch (linetype) { case 2: - if (!no_line2) - { - os << setprecision(7); -// os << "2 " << col2 << " " << coord(0) << " " << coord(1) << endl; - os << "2 " << color << " " << vertx(0) << " " << vertx(1) << endl; - } - break; + if (!no_line2) + { + os << setprecision(7); + // os << "2 " << col2 << " " << coord(0) << " " << coord(1) << endl; + os << "2 " << color << " " << vertx(0) << " " << vertx(1) << endl; + } + break; case 5: - if (!no_line5) - { - os << setprecision(7); -// os << "5 " << col5 << " " << coord(0) << " " << coord(1) << " " << coord(2) << " " << coord(2,1) << endl; - os << "5 " << color << " " << vertx(0) << " " << vertx(1) << " " << vertx(2) << " " << vertx(2,1) << endl; - } - break; + if (!no_line5) + { + os << setprecision(7); + // os << "5 " << col5 << " " << coord(0) << " " << coord(1) << " " << coord(2) << " " << coord(2,1) << endl; + os << "5 " << color << " " << vertx(0) << " " << vertx(1) << " " << vertx(2) << " " << vertx(2, 1) << endl; + } + break; } printed = true; } @@ -937,7 +956,7 @@ void stl_edge::write(ostream & os, int col2, int col5){ CString stl_edge::ident() { char buf[16]; - sprintf_s(buf,"%d",nbr_edge); + sprintf_s(buf, "%d", nbr_edge); CString a0 = "-"; CString a1 = "-"; if (adjacent[0]) @@ -950,18 +969,18 @@ CString stl_edge::ident() void stl_prim::write(ostream & os) { - if (!no_line1) - { + if (!no_line1) + { if (bfc && !cw) os << "0 BFC INVERTNEXT" << endl; os << setprecision(5); os << "1 " << color << " " << transfo << " " << name << ".dat" << endl; - } + } } void stl_file::write_dat(bool print_geom) { - eps_empile( 0.0001); + eps_empile(0.0001); CString dat_name; if (ldr_out) dat_name = out_filename; @@ -975,32 +994,32 @@ void stl_file::write_dat(bool print_geom) extension = ".dat"; dat_name.MakeLower(); if (dat_name.Find(".stl")) - dat_name.Replace(".stl",extension); + dat_name.Replace(".stl", extension); else dat_name += extension; } ofstream fout(dat_name); fout << "0 " << partname << endl; - int f = max(dat_name.ReverseFind('/'),dat_name.ReverseFind('\\')); + int f = max(dat_name.ReverseFind('/'), dat_name.ReverseFind('\\')); if (f > 0) - dat_name = dat_name.Mid(f+1); + dat_name = dat_name.Mid(f + 1); fout << "0 Name: " << dat_name << endl; fout << "0 Author: " << author << endl; if (ldraw) { - if (name.Mid(0,2) == "s\\") - fout << "0 !LDRAW_ORG Unofficial_Subpart" << endl; - else if (name.Mid(0,2) == "p\\") - fout << "0 !LDRAW_ORG Unofficial_Primitive" << endl; - else if (name.Mid(0,5) == "p\\48\\") - fout << "0 !LDRAW_ORG Unofficial_48_Primitive" << endl; - else - fout << "0 !LDRAW_ORG Unofficial_Part" << endl; - fout << "0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt" << endl; + if (name.Mid(0, 2) == "s\\") + fout << "0 !LDRAW_ORG Unofficial_Subpart" << endl; + else if (name.Mid(0, 2) == "p\\") + fout << "0 !LDRAW_ORG Unofficial_Primitive" << endl; + else if (name.Mid(0, 5) == "p\\48\\") + fout << "0 !LDRAW_ORG Unofficial_48_Primitive" << endl; + else + fout << "0 !LDRAW_ORG Unofficial_Part" << endl; + fout << "0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt" << endl; } fout << endl; if (bfc) - fout << "0 BFC CERTIFY CCW" << endl; + fout << "0 BFC CERTIFY CCW" << endl; fout << endl; fout << "0 // Created with stl2dat conversion tool" << endl; stl_prim_list * curp = prim_list; @@ -1035,10 +1054,10 @@ void stl_file::write_dat(bool print_geom) if (!surf->prim) { fout << endl; - // eps_empile( 0.01); + // eps_empile( 0.01); if (print_geom) curs->item->write(fout); - // eps_depile(); + // eps_depile(); int col3 = col_line3; int col4 = col_line4; if (rand_col_surfaces || (rand_col_adj_cyl && surf->adj_cyl)) @@ -1101,7 +1120,7 @@ void stl_file::add_edge(int usage, const stl_v& v0, const stl_v& v1, const stl_v } // create vertex if necessary, link to facet and edge -void create_vertex( stl_vertex_list * & vertex_list, stl_edge * edge, stl_facet * fct1, stl_facet * fct2, int i1, int i2) +void create_vertex(stl_vertex_list * & vertex_list, stl_edge * edge, stl_facet * fct1, stl_facet * fct2, int i1, int i2) { bool reaffect = false; stl_vertex * result = fct1->vertex[i1]; @@ -1123,22 +1142,22 @@ void create_vertex( stl_vertex_list * & vertex_list, stl_edge * edge, stl_facet if (!result) { result = new stl_vertex(fct1->coords[i1]); - vertex_list = new stl_vertex_list( result, vertex_list); + vertex_list = new stl_vertex_list(result, vertex_list); } - result->add_edge( edge); + result->add_edge(edge); if (reaffect) { stl_edge_list * cur = vertex2->edge_list; while (cur) { - for (int i=0; i < 2; i++) + for (int i = 0; i < 2; i++) { if (cur->item->vertex[i] == vertex2) cur->item->vertex[i] = result; stl_facet * adj = cur->item->adjacent[i]; if (adj) { - for (int v=0; v < adj->usage; v++) + for (int v = 0; v < adj->usage; v++) if (adj->vertex[v] == vertex2) adj->vertex[v] = result; } @@ -1153,12 +1172,12 @@ void create_vertex( stl_vertex_list * & vertex_list, stl_edge * edge, stl_facet } void add_edge2( - stl_edge_list * & edge_list, - stl_vertex_list * & vertex_list, - stl_facet * fct1, - stl_facet * fct2, - int i1, int i2, int j2 - ) + stl_edge_list * & edge_list, + stl_vertex_list * & vertex_list, + stl_facet * fct1, + stl_facet * fct2, + int i1, int i2, int j2 +) { //cout << "add_edge2( [" << fct1->ident() << "], [" << fct2->ident() << "], " << i1 << ", " << i2 << ", " << j2 << ")" << endl; stl_edge * edge = new stl_edge(); @@ -1169,27 +1188,27 @@ void add_edge2( edge->coords[0] = i1; // number of vertex in adjacent[0] (minimum) edge->coords[1] = i2; // number of vertex in adjacent[1] (minimum) - int k1 = (i1+1) % fct1->usage; + int k1 = (i1 + 1) % fct1->usage; int k2 = 0; if (fct2) - k2 = (i2 == j2 ? (i2+1) % fct2->usage : i2); - create_vertex( vertex_list, edge, fct1, fct2, i1, j2); - create_vertex( vertex_list, edge, fct1, fct2, k1, k2); + k2 = (i2 == j2 ? (i2 + 1) % fct2->usage : i2); + create_vertex(vertex_list, edge, fct1, fct2, i1, j2); + create_vertex(vertex_list, edge, fct1, fct2, k1, k2); if (fct2) { fct2->edge[i2] = edge; fct2->adjacent[i2] = fct1; } - edge_list = new stl_edge_list( edge, edge_list); + edge_list = new stl_edge_list(edge, edge_list); } // Calculate edges between 2 facets int stl_file::create_edge(stl_facet * fct1, stl_facet * fct2) { int result = 0; - for (int i1=0; i1 < fct1->usage; i1++) + for (int i1 = 0; i1 < fct1->usage; i1++) if (!fct1->edge[i1]) - for (int i2=0; i2 < fct2->usage; i2++) + for (int i2 = 0; i2 < fct2->usage; i2++) if (!fct2->edge[i2]) { int j1 = (i1 + 1) % fct1->usage; @@ -1197,12 +1216,12 @@ int stl_file::create_edge(stl_facet * fct1, stl_facet * fct2) if (fct1->coords[i1] == fct2->coords[i2] && fct1->coords[j1] == fct2->coords[j2]) { result++; - add_edge2( edge_list, vertex_list, fct1, fct2, i1, i2, i2 ); + add_edge2(edge_list, vertex_list, fct1, fct2, i1, i2, i2); } else if (fct1->coords[i1] == fct2->coords[j2] && fct1->coords[j1] == fct2->coords[i2]) { result++; - add_edge2( edge_list, vertex_list, fct1, fct2, i1, i2, j2 ); + add_edge2(edge_list, vertex_list, fct1, fct2, i1, i2, j2); } } return(result); @@ -1224,13 +1243,13 @@ void stl_file::topo() { stl_facet * fct2 = cur2->item; if (fct2->usage) - nb_edge += create_edge(fct1,fct2); + nb_edge += create_edge(fct1, fct2); cur2 = cur2->next; } - for (int i1=0; i1 < fct1->usage; i1++) + for (int i1 = 0; i1 < fct1->usage; i1++) if (!fct1->edge[i1]) { - add_edge2( edge_list, vertex_list, fct1, NULL, i1, -1, -1 ); + add_edge2(edge_list, vertex_list, fct1, NULL, i1, -1, -1); } nb_edge++; } @@ -1239,30 +1258,30 @@ void stl_file::topo() if (!silent) cout << nb_edge << " edges created" << endl; #ifdef DEBUG -/* -if (!nodebug) - { - stl_edge_list * cure = edge_list; - while (cure) - { - if (cure->item->adjacent[1]) - cout << "edge adj(" << cure->item->adjacent[0]->nbr_facet << "," - << cure->item->adjacent[1]->nbr_facet << ")" << endl; - else - cout << "edge end(" << cure->item->adjacent[0]->nbr_facet << ")" << endl; - cure = cure->next; - } - stl_facet_list * curf = facet_list; - while (curf) + /* + if (!nodebug) { - cout << "facet(" << curf->item->nbr_facet << ") " << endl; - for (int i = 0 ; i < curf->item->usage ; i++) - if (curf->item->adjacent[i]) - cout << "adj[" << i << "]=(" << curf->item->adjacent[i]->nbr_facet << ")" << endl; - curf = curf->next; + stl_edge_list * cure = edge_list; + while (cure) + { + if (cure->item->adjacent[1]) + cout << "edge adj(" << cure->item->adjacent[0]->nbr_facet << "," + << cure->item->adjacent[1]->nbr_facet << ")" << endl; + else + cout << "edge end(" << cure->item->adjacent[0]->nbr_facet << ")" << endl; + cure = cure->next; + } + stl_facet_list * curf = facet_list; + while (curf) + { + cout << "facet(" << curf->item->nbr_facet << ") " << endl; + for (int i = 0 ; i < curf->item->usage ; i++) + if (curf->item->adjacent[i]) + cout << "adj[" << i << "]=(" << curf->item->adjacent[i]->nbr_facet << ")" << endl; + curf = curf->next; + } } - } -*/ + */ #endif //check(); } @@ -1284,23 +1303,23 @@ bool merge3(stl_facet * fct1, stl_facet * fct2) if (fct1->normal == fct2->normal && fct1->usage == 3 && fct2->usage == 3) { bool result = false; - for (int i1=0; i1 < 3 && !result; i1++) - for (int i2=0; i2 < 3 && !result; i2++) + for (int i1 = 0; i1 < 3 && !result; i1++) + for (int i2 = 0; i2 < 3 && !result; i2++) if (fct1->coords[i1] == fct2->coords[i2]) { - for (int j1=0; j1 < 3 && !result; j1++) - for (int j2=0; j2 < 3 && !result; j2++) + for (int j1 = 0; j1 < 3 && !result; j1++) + for (int j2 = 0; j2 < 3 && !result; j2++) if (j1 != i1 && j2 != i2 && fct1->coords[j1] == fct2->coords[j2]) { - int k1 = other(i1,j1); - int k2 = other(i2,j2); - if (fct1->coords[i1].colinear(fct1->coords[k1],fct2->coords[k2])) + int k1 = other(i1, j1); + int k2 = other(i2, j2); + if (fct1->coords[i1].colinear(fct1->coords[k1], fct2->coords[k2])) { fct1->coords[i1] = fct2->coords[k2]; fct2->usage = 0; return(true); } - else if (fct1->coords[j1].colinear(fct1->coords[k1],fct2->coords[k2])) + else if (fct1->coords[j1].colinear(fct1->coords[k1], fct2->coords[k2])) { fct1->coords[j1] = fct2->coords[k2]; fct2->usage = 0; @@ -1325,7 +1344,7 @@ void stl_file::optim3() while (cur) { fct2 = cur->item; - if (merge3(fct1,fct2)) + if (merge3(fct1, fct2)) opt3++; stl_facet_list * cur2 = cur->next; for (int c = 0; c < 200 && cur2; c++) @@ -1342,16 +1361,16 @@ void stl_file::optim3() cout << opt3 << " triangle facets merged" << endl; } -void stl_facet::calcul_angles( double & totag, double & minag, double & maxag) +void stl_facet::calcul_angles(double & totag, double & minag, double & maxag) { totag = 0; minag = 1000; maxag = -1000; for (int a = 0; a < 4; a++) { - int b = (a+1) % 4; - int c = (a+2) % 4; - double ag = (coords[a]-coords[b]).angle(coords[c]-coords[b], normal); + int b = (a + 1) % 4; + int c = (a + 2) % 4; + double ag = (coords[a] - coords[b]).angle(coords[c] - coords[b], normal); totag += ag; if (ag < minag) minag = ag; @@ -1368,20 +1387,20 @@ bool stl_facet::is_convex(bool trace) double totag; double minag; double maxag; - calcul_angles( totag, minag, maxag); + calcul_angles(totag, minag, maxag); if (trace) cout << "(" << nbr_facet << ") tot=" << degre(totag) << "° min=" << degre(minag) << "° max=" << degre(maxag) << "°" << endl; - if (equal(totag, 4*pi)) + if (equal(totag, 4 * pi)) { stl_v tmp = coords[0]; coords[0] = coords[1]; coords[1] = coords[2]; coords[2] = tmp; - calcul_angles( totag, minag, maxag); + calcul_angles(totag, minag, maxag); if (trace) cout << "(" << nbr_facet << ") tot=" << degre(totag) << "° min=" << degre(minag) << "° max=" << degre(maxag) << "°" << endl; } - result = (equal(totag, 2*pi) && maxag < pi - ag_lim_q) || (equal(totag, 6*pi) && minag > pi + ag_lim_q); + result = (equal(totag, 2 * pi) && maxag < pi - ag_lim_q) || (equal(totag, 6 * pi) && minag > pi + ag_lim_q); return(result); } @@ -1427,7 +1446,7 @@ double stl_facet::determinant(int precision) if (precision == -1) v[i] = vertex[i]->coords.ftrunc(-vertex[i]->precision); else - v[i] = vertex[i]->coords.ftrunc(-max(precision,-vertex[i]->precision)); + v[i] = vertex[i]->coords.ftrunc(-max(precision, -vertex[i]->precision)); } result = determinant4(v); } @@ -1453,10 +1472,10 @@ int stl_edge::side(stl_facet * m_facet) void stl_edge::reaffect(stl_facet * m_facet, stl_facet * repl_facet, int ve) { int s = side(m_facet); - adjacent[ s] = repl_facet; - coords[ s] = ve; - if (coords[ 1 - s] >= 0 && coords[ 1 - s] <= 3 && adjacent[ 1 - s]) - adjacent[ 1 - s]->adjacent[ coords[ 1 - s]] = repl_facet; + adjacent[s] = repl_facet; + coords[s] = ve; + if (coords[1 - s] >= 0 && coords[1 - s] <= 3 && adjacent[1 - s]) + adjacent[1 - s]->adjacent[coords[1 - s]] = repl_facet; } // Reaffect border edges to new merged facet @@ -1479,10 +1498,10 @@ void stl_facet::merge_facet(stl_edge * m_edge, stl_facet * m_facet, int ve0, int // Merge 2 adjacent triangles facet to 1 rectangle facet bool stl_edge::merge_adj() { -// cout << this << " merge_adj" << endl; + // cout << this << " merge_adj" << endl; bool result = false; if (adjacent[0] && adjacent[1] && - (adjacent[0]->normal == adjacent[1]->normal || adjacent[0]->normal == -adjacent[1]->normal) && + (adjacent[0]->normal == adjacent[1]->normal || adjacent[0]->normal == -adjacent[1]->normal) && adjacent[0]->usage == 3 && adjacent[1]->usage == 3) { // Insert new point to rectangle facet @@ -1492,8 +1511,8 @@ bool stl_edge::merge_adj() adjacent[0]->coords[i] = adjacent[0]->coords[i - 1]; adjacent[0]->vertex[i] = adjacent[0]->vertex[i - 1]; } - adjacent[0]->coords[j] = coord(2,1); - adjacent[0]->vertex[j] = vertx(2,1); + adjacent[0]->coords[j] = coord(2, 1); + adjacent[0]->vertex[j] = vertx(2, 1); // verify convex quadrilater adjacent[0]->usage = 4; int p = 2; @@ -1507,27 +1526,27 @@ bool stl_edge::merge_adj() if (det > determinant_eps) p++; } - adjacent[0]->precision = max(adjacent[0]->precision,p); + adjacent[0]->precision = max(adjacent[0]->precision, p); for (int i = 0; i < 4; i++) { - adjacent[0]->vertex[i]->precision = max(adjacent[0]->vertex[i]->precision,p); + adjacent[0]->vertex[i]->precision = max(adjacent[0]->vertex[i]->precision, p); } -//if (det > determinant_eps) -//{ -//cout << setprecision(7); -//cout << "4 " << 1 << " " << adjacent[0]->vertex[0] << " " << adjacent[0]->vertex[1] << " " << adjacent[0]->vertex[2] << " " << adjacent[0]->vertex[3] << " p=" << p << " det=" << det << endl; -//} - //cout << "merge4 " << det << endl; - //adjacent[0]->color = 4; + //if (det > determinant_eps) + //{ + //cout << setprecision(7); + //cout << "4 " << 1 << " " << adjacent[0]->vertex[0] << " " << adjacent[0]->vertex[1] << " " << adjacent[0]->vertex[2] << " " << adjacent[0]->vertex[3] << " p=" << p << " det=" << det << endl; + //} + //cout << "merge4 " << det << endl; + //adjacent[0]->color = 4; } if (adjacent[0]->is_convex() && det <= determinant_eps) { #ifdef DEBUG - if (!nodebug) - cout << "merge4 " << adjacent[0]->nbr_facet << " " << adjacent[1]->nbr_facet << endl; + if (!nodebug) + cout << "merge4 " << adjacent[0]->nbr_facet << " " << adjacent[1]->nbr_facet << endl; #endif result = true; - adjacent[0]->merge_facet( this, adjacent[1], coords[0], coords[1]); + adjacent[0]->merge_facet(this, adjacent[1], coords[0], coords[1]); adjacent[0]->usage = 4; adjacent[1]->usage = 0; linetype = -1; @@ -1582,7 +1601,7 @@ stl_edge * stl_edge::next(int & vx, stl_facet * & s_fct) } else */ - return(0); + return(0); } void stl_facet::replace_vertex(stl_vertex * ve_ori, stl_vertex * ve_repl) @@ -1594,15 +1613,15 @@ void stl_facet::replace_vertex(stl_vertex * ve_ori, stl_vertex * ve_repl) coords[i] = ve_repl->coords; int j = edge[i]->side(this); edge[i]->vertex[j] = ve_repl; -/* - for (int j = 0; j < 2; j++) - if (edge[i]->vertex[j] == ve_ori) - { - edge[i]->coords[j] = i; - } -*/ + /* + for (int j = 0; j < 2; j++) + if (edge[i]->vertex[j] == ve_ori) + { + edge[i]->coords[j] = i; + } + */ } -// ed->vertex[i] = ve_repl; + // ed->vertex[i] = ve_repl; } void stl_facet::replace_adjacent(stl_vertex * ve_ori, stl_edge * ed, bool del_edge) @@ -1623,7 +1642,7 @@ void stl_facet::replace_adjacent(stl_vertex * ve_ori, stl_edge * ed, bool del_ed if (fct0) { // replace adjencent pointers for facets - ad0 = fct0->side_edge( ed0); + ad0 = fct0->side_edge(ed0); fct0->adjacent[ad0] = fct1; for (int i = 0; i < fct0->usage; i++) @@ -1639,7 +1658,7 @@ void stl_facet::replace_adjacent(stl_vertex * ve_ori, stl_edge * ed, bool del_ed if (fct1) { // replace adjencent pointers for facets - int ad1 = fct1->side_edge( ed1); + int ad1 = fct1->side_edge(ed1); fct1->adjacent[ad1] = fct0; // replace coords in modified edges @@ -1660,7 +1679,7 @@ void stl_facet::replace_adjacent(stl_vertex * ve_ori, stl_edge * ed, bool del_ed usage = 0; } -/* +/* // replace adjency pointers for facets int ad0 = fct0->side_edge( ed0); int ad1 = fct1->side_edge( ed1); @@ -1709,18 +1728,18 @@ void stl_vertex::remove_vertex(stl_edge * ed_supr) { stl_facet * fct = ed->adjacent[0]; if (fct/* && fct != fct0 && fct != fct1*/) - fct->replace_vertex( this, ve_repl); + fct->replace_vertex(this, ve_repl); fct = ed->adjacent[1]; if (fct/* && fct != fct0 && fct != fct1*/) - fct->replace_vertex( this, ve_repl); + fct->replace_vertex(this, ve_repl); } cur = cur->next; } if (fct0) - fct0->replace_adjacent( this, ed_supr, false); + fct0->replace_adjacent(this, ed_supr, false); if (fct1) - fct1->replace_adjacent( this, ed_supr, false); + fct1->replace_adjacent(this, ed_supr, false); deleted = true; ed_supr->deleted = true; @@ -1867,8 +1886,8 @@ void stl_vertex::scan_edges(int nb_face) init_surface += cur->item->adjacent[a]->surface(); cur = cur->next; } - init_surface /= 2; -//cout << "init_surface=" << init_surface << endl; + init_surface /= 2; + //cout << "init_surface=" << init_surface << endl; cur = edge_list; bool found = false; while (cur && !found) @@ -1883,7 +1902,7 @@ void stl_vertex::scan_edges(int nb_face) cur2 = cur2->next; } cur_surface /= 2; -//cout << "cur_surface=" << cur_surface << endl; + //cout << "cur_surface=" << cur_surface << endl; found = is_small(cur_surface - init_surface); if (!found) cur = cur->next; @@ -1946,8 +1965,8 @@ void stl_file::optim_facets(int nb_face) cout << opt_v << " unusefull vertices removed" << endl; eps_depile(); #ifdef _DEBUG -if (!nodebug) - check(); + if (!nodebug) + check(); #endif } @@ -1971,7 +1990,7 @@ void stl_file::optim4() } // return plane corresponding to facet -void stl_facet::facetplan( stl_v & op, stl_v & vp) +void stl_facet::facetplan(stl_v & op, stl_v & vp) { //long orient; //scalplan(coords[0],coords[1],coords[2], op, vp, orient); @@ -1997,19 +2016,19 @@ bool stl_facet::is_adjacent(stl_facet * fct1) for (int i = 0; !result && i < usage; i++) for (int j = 0; !result && j < fct1->usage; j++) { - int i1 = (i+1) % usage; - int j1 = (j+1) % fct1->usage; + int i1 = (i + 1) % usage; + int j1 = (j + 1) % fct1->usage; result = (coords[i] == fct1->coords[j] && coords[i1] == fct1->coords[j1]) || - (coords[i] == fct1->coords[j1] && coords[i1] == fct1->coords[j]); + (coords[i] == fct1->coords[j1] && coords[i1] == fct1->coords[j]); } #ifdef DEBUG -if (!nodebug) - cout << "adjacent(" << nbr_facet << "," << fct1->nbr_facet << ") = " << result << endl; + if (!nodebug) + cout << "adjacent(" << nbr_facet << "," << fct1->nbr_facet << ") = " << result << endl; #endif return(result); } -void stl_file::add_prim( stl_prim * prim) +void stl_file::add_prim(stl_prim * prim) { stl_prim_list * prim_elem = new stl_prim_list; prim_elem->item = prim; @@ -2022,35 +2041,35 @@ void stl_file::add_prim( stl_prim * prim) } const stl_lin std_lin = stl_lin(stl_v(1.0, 0.0, 0.0), - stl_v(0.0, 0.0, 1.0), - stl_v(0.0, 1.0, 0.0), - stl_v(0.0, 0.0, 0.0)); + stl_v(0.0, 0.0, 1.0), + stl_v(0.0, 1.0, 0.0), + stl_v(0.0, 0.0, 0.0)); const int MAX_AXE = 128; /* -Line type 1's format is: - -Line Format: -1 colour x y z a b c d e f g h i part.dat -Fields a through i are orientation & scaling parameters, which can be used in 'standard' 3D transformation matrices. Fields x, y and z also fit into this matrix: - - | a d g 0 | - | b e h 0 | - | c f i 0 | - | x y z 1 | - -so that every point (x, y ,z) gets transformed to (x', y', z') : - - x' = a*x + b*y + c*z + x - y' = d*x + e*y + f*z + y - z' = g*x + h*y + i*z + z - -or, in matrix-math style: - | a d g 0 | - | X' Y' Z' 1 | = | X Y Z 1 | x | b e h 0 | - | c f i 0 | - | x y z 1 | +Line type 1's format is: + +Line Format: +1 colour x y z a b c d e f g h i part.dat +Fields a through i are orientation & scaling parameters, which can be used in 'standard' 3D transformation matrices. Fields x, y and z also fit into this matrix: + + | a d g 0 | + | b e h 0 | + | c f i 0 | + | x y z 1 | + +so that every point (x, y ,z) gets transformed to (x', y', z') : + + x' = a*x + b*y + c*z + x + y' = d*x + e*y + f*z + y + z' = g*x + h*y + i*z + z + +or, in matrix-math style: + | a d g 0 | + | X' Y' Z' 1 | = | X Y Z 1 | x | b e h 0 | + | c f i 0 | + | x y z 1 | */ @@ -2062,37 +2081,37 @@ stl_surf::stl_surf() adj_cyl = false; } -void stl_surf::write( ostream & os) +void stl_surf::write(ostream & os) { if (adj_cyl) os << " adjacent to cylinder" << endl; } -void stl_surf::set_facet( stl_facet * fct) +void stl_surf::set_facet(stl_facet * fct) { } -stl_cylinder::stl_cylinder( const stl_v & _od, const stl_v & _vd, double _radius, double _height) : stl_surf() +stl_cylinder::stl_cylinder(const stl_v & _od, const stl_v & _vd, double _radius, double _height) : stl_surf() { od = _od; vd = _vd; - sidrpl( od, vd, stl_v_zero, vd, od); + sidrpl(od, vd, stl_v_zero, vd, od); radius = _radius; height = _height; cw = false; } -void stl_cylinder::write( ostream & os) +void stl_cylinder::write(ostream & os) { os << setprecision(5); - os << "0 cylinder " << od << ", " << vd << ", " << Mfround(radius,001) << ", " << Mfround(height,001); + os << "0 cylinder " << od << ", " << vd << ", " << Mfround(radius, 001) << ", " << Mfround(height, 001); if (adj_cyl) os << " adjacent to cylinder"; os << endl; } -bool stl_cylinder::compatible( stl_facet * fct, stl_facet * adj) +bool stl_cylinder::compatible(stl_facet * fct, stl_facet * adj) { // Test if the two facets have same axis, radius and height bool result = false; @@ -2100,7 +2119,7 @@ bool stl_cylinder::compatible( stl_facet * fct, stl_facet * adj) if (cylinder) { result = ((vd == cylinder->vd || vd == -cylinder->vd) && - sapptdr( cylinder->od, od, vd) && + sapptdr(cylinder->od, od, vd) && equal(radius, cylinder->radius) && equal(height, cylinder->height)); delete cylinder; @@ -2118,14 +2137,14 @@ bool stl_cylinder::compatible( stl_facet * fct, stl_facet * adj) return(result); } -stl_plane::stl_plane( const stl_v & _op, const stl_v & _vp) : stl_surf() +stl_plane::stl_plane(const stl_v & _op, const stl_v & _vp) : stl_surf() { op = _op; vp = _vp; - sidrpl( stl_v_zero, vp, op, vp, op); + sidrpl(stl_v_zero, vp, op, vp, op); } -void stl_plane::write( ostream & os) +void stl_plane::write(ostream & os) { os << setprecision(5); os << "0 plane " << op << ", " << vp; @@ -2134,39 +2153,39 @@ void stl_plane::write( ostream & os) os << endl; } -bool stl_plane::compatible( stl_facet * fct, stl_facet *) +bool stl_plane::compatible(stl_facet * fct, stl_facet *) { bool result = false; stl_plane * plane = fct->new_plane(); if (plane) { #ifdef DEBUG - if (!nodebug) - { - cout << "compatible [" << op << "," << vp - << "] and [" << plane->op << "," << plane->vp << "] " - << (vp - plane->vp).norm() << " " - << spaplan( plane->op, op, vp) << " = " - << (vp == plane->vp && sapptpl( plane->op, op, vp)) << endl; - } + if (!nodebug) + { + cout << "compatible [" << op << "," << vp + << "] and [" << plane->op << "," << plane->vp << "] " + << (vp - plane->vp).norm() << " " + << spaplan(plane->op, op, vp) << " = " + << (vp == plane->vp && sapptpl(plane->op, op, vp)) << endl; + } #endif - result = (vp == plane->vp && sapptpl( plane->op, op, vp)); + result = (vp == plane->vp && sapptpl(plane->op, op, vp)); delete plane; } return(result); } - -stl_tangent::stl_tangent( stl_facet * fct) : stl_surf() + +stl_tangent::stl_tangent(stl_facet * fct) : stl_surf() { facet = fct; } -void stl_tangent::set_facet( stl_facet * fct) +void stl_tangent::set_facet(stl_facet * fct) { facet = fct; } -bool stl_tangent::compatible( stl_facet * fct, stl_facet *) +bool stl_tangent::compatible(stl_facet * fct, stl_facet *) { bool result = false; bool adj = false; @@ -2191,14 +2210,14 @@ stl_plane * stl_facet::new_plane() { stl_v f_op; stl_v f_vp; - facetplan( f_op, f_vp); - result = new stl_plane( f_op, f_vp); + facetplan(f_op, f_vp); + result = new stl_plane(f_op, f_vp); } return(result); } -stl_cylinder * stl_facet::new_cylinder( stl_facet * fct2, const stl_v & op, const stl_v & vp, const double angle_cyl) +stl_cylinder * stl_facet::new_cylinder(stl_facet * fct2, const stl_v & op, const stl_v & vp, const double angle_cyl) { stl_cylinder * result = 0; if (usage != 4 || fct2->usage != 4) @@ -2209,21 +2228,21 @@ stl_cylinder * stl_facet::new_cylinder( stl_facet * fct2, const stl_v & op, cons { double ag = normal.angle(fct2->normal, v_ref); #ifdef DEBUG -if (!nodebug) - cout << "angle(" << nbr_facet << "," << fct2->nbr_facet << ") = " << degre(ag) << "°" << endl; + if (!nodebug) + cout << "angle(" << nbr_facet << "," << fct2->nbr_facet << ") = " << degre(ag) << "°" << endl; #endif if (equal(ag, angle_cyl)) { stl_v op2; stl_v vp2; - fct2->facetplan( op2, vp2); + fct2->facetplan(op2, vp2); stl_v od1; stl_v vd1; double dist; stl_v p1; - stl_v p2; - int res = s_dist_drdr( op, vp, op2, vp2, dist, p1, p2); + stl_v p2; + int res = s_dist_drdr(op, vp, op2, vp2, dist, p1, p2); od1 = (p1 + p2) / 2; vd1 = (vp * vp2).normaliz(); double rad = 0; @@ -2235,7 +2254,7 @@ if (!nodebug) rad /= fct2->usage; double max = -1e5; - double min = 1e5; + double min = 1e5; for (int k = 0; k < usage; k++) { double dist = spaplan(coords[k], od1, vd1); @@ -2266,10 +2285,10 @@ if (!nodebug) } if (ok) - if (angle_cyl == pi/8) - result = new stl_cylinder( od1, vd1, rad, max - min); + if (angle_cyl == pi / 8) + result = new stl_cylinder(od1, vd1, rad, max - min); else - result = new stl_cylinder48( od1, vd1, rad, max - min); + result = new stl_cylinder48(od1, vd1, rad, max - min); else result = 0; } @@ -2277,44 +2296,44 @@ if (!nodebug) return(result); } -stl_cylinder * stl_facet::new_cylinder( stl_facet * fct2, const stl_v & op, const stl_v & vp) +stl_cylinder * stl_facet::new_cylinder(stl_facet * fct2, const stl_v & op, const stl_v & vp) { - return new_cylinder( fct2, op, vp, pi/8); + return new_cylinder(fct2, op, vp, pi / 8); } -stl_cylinder * stl_facet::new_cylinder48( stl_facet * fct2, const stl_v & op, const stl_v & vp) +stl_cylinder * stl_facet::new_cylinder48(stl_facet * fct2, const stl_v & op, const stl_v & vp) { - return new_cylinder( fct2, op, vp, pi/24); + return new_cylinder(fct2, op, vp, pi / 24); } -stl_cylinder * stl_facet::new_cylinder( stl_facet * adj) +stl_cylinder * stl_facet::new_cylinder(stl_facet * adj) { stl_cylinder * result = 0; if (!cyl_norm || normal != read_normal) { stl_v op; stl_v vp; - facetplan( op, vp); -// vp = read_normal; + facetplan(op, vp); + // vp = read_normal; if (adj) - result = new_cylinder( adj, op, vp); + result = new_cylinder(adj, op, vp); else for (int i = 0; i < usage && !result; i++) if (adjacent[i]/* && !adjacent[i]->surf*/) { - result = new_cylinder( adjacent[i], op, vp); + result = new_cylinder(adjacent[i], op, vp); } if (!result) { - if (adj) - result = new_cylinder48( adj, op, vp); - else - for (int i = 0; i < usage && !result; i++) - if (adjacent[i]/* && !adjacent[i]->surf*/) - { - result = new_cylinder48( adjacent[i], op, vp); - } + if (adj) + result = new_cylinder48(adj, op, vp); + else + for (int i = 0; i < usage && !result; i++) + if (adjacent[i]/* && !adjacent[i]->surf*/) + { + result = new_cylinder48(adjacent[i], op, vp); + } } } return(result); @@ -2327,7 +2346,7 @@ stl_tangent * stl_facet::new_tangent() if (adjacent[i]) { if (angle_between(adjacent[i]) < ag_lim) - result = new stl_tangent( this); + result = new stl_tangent(this); } return(result); } @@ -2339,8 +2358,8 @@ void stl_facet::calc_surf(stl_facet * fct, stl_surf_list * & surf_list) f_surf = fct->surf; //indent(level); #ifdef DEBUG -if (!nodebug) - cout << "calc_surf(" << nbr_facet << ")" << endl; + if (!nodebug) + cout << "calc_surf(" << nbr_facet << ")" << endl; #endif if (usage == 0 || surf) return; @@ -2348,7 +2367,7 @@ if (!nodebug) bool first_facet = false; if (f_surf) { - if (f_surf->compatible( this, fct)) + if (f_surf->compatible(this, fct)) { surf = f_surf; surf->count++; @@ -2364,7 +2383,7 @@ if (!nodebug) if (!no_tangent && !surf) surf = new_tangent(); if (surf) - surf_list = new stl_surf_list( surf, surf_list); + surf_list = new stl_surf_list(surf, surf_list); first_facet = true; } if (surf) @@ -2375,7 +2394,7 @@ if (!nodebug) surf->set_facet(this); //cout << "test " << nbr_facet << " " << adjacent[i]->nbr_facet << endl; adjacent[i]->calc_surf(this, surf_list); -//edge[i]->color = 4; + //edge[i]->color = 4; } if (first_facet && surf->count == 1) { @@ -2386,7 +2405,7 @@ if (!nodebug) } } -int stl_facet::side_edge( stl_facet * fct) +int stl_facet::side_edge(stl_facet * fct) { int result = 0; bool found = false; @@ -2402,7 +2421,7 @@ int stl_facet::side_edge( stl_facet * fct) return(result); } -int stl_facet::side_edge( stl_edge * edg) +int stl_facet::side_edge(stl_edge * edg) { int result = 0; bool found = false; @@ -2418,20 +2437,20 @@ int stl_facet::side_edge( stl_edge * edg) return(result); } -stl_facet * stl_facet::next_surf( stl_facet * fct) +stl_facet * stl_facet::next_surf(stl_facet * fct) { stl_facet * result = 0; - for (int i = 0; i < usage && !result ; i++) + for (int i = 0; i < usage && !result; i++) if (adjacent[i] && adjacent[i] != fct && adjacent[i]->surf == surf) result = adjacent[i]; return(result); } -void stl_surf::calc_prim( stl_facet * facet, stl_file & stl) +void stl_surf::calc_prim(stl_facet * facet, stl_file & stl) { } -int nb_zero( const stl_v & v) +int nb_zero(const stl_v & v) { int result = 0; for (int i = 0; i < 3; i++) @@ -2440,12 +2459,12 @@ int nb_zero( const stl_v & v) } void stl_cylinder::calc_extrem_partial( - stl_facet * facet, - stl_facet * & fct1, - stl_facet * & fct2, - stl_facet * & fct3, - stl_facet * & fct4 - ) + stl_facet * facet, + stl_facet * & fct1, + stl_facet * & fct2, + stl_facet * & fct3, + stl_facet * & fct4 +) { // Search extremity of partial cylinder fct1 = 0; @@ -2456,7 +2475,7 @@ void stl_cylinder::calc_extrem_partial( int tmp_count = count * nb_arete() / 16; while (fct2 && (fct2 != facet || i == 0) && i < count) { -// cout << "(1) fct2=" << fct2->nbr_facet << endl; + // cout << "(1) fct2=" << fct2->nbr_facet << endl; sfct2 = fct2; sfct1 = fct1; fct2 = fct2->next_surf(fct1); @@ -2473,23 +2492,23 @@ void stl_cylinder::calc_extrem_partial( fct4 = fct2; #ifdef DEBUG -if (!nodebug) - cout << "(2)" - << " fct1=" << (fct1 ? fct1->nbr_facet : 0) - << " fct2=" << (fct2 ? fct2->nbr_facet : 0) - << " fct3=" << (fct3 ? fct3->nbr_facet : 0) - << " fct4=" << (fct4 ? fct4->nbr_facet : 0) - <side_edge(fct3->next_surf(fct4)); + double min = 1e5; + // int i = fct3->side_edge(fct3->next_surf(fct4)); int i = fct4->side_edge(fct3); for (int j = 2; j < 4; j++) { @@ -2634,13 +2653,13 @@ void stl_cylinder::calc_center( min_p2.normalize(); min_p2 *= min_o.distance(max_p); if (min_p2.ps(min_p - min_o) < 0) - min_p = -(min_o + min_p2); + min_p = -(min_o + min_p2); else - min_p = (min_o + min_p2); - */ + min_p = (min_o + min_p2); + */ } -void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) +void stl_cylinder::calc_prim(stl_facet * facet, stl_file & stl) { int nb_cyl = 0; int primitives = 0; @@ -2650,7 +2669,7 @@ void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) stl_v min_o; stl_v min_z; stl_v max_z; -// stl_facet * fct0; + // stl_facet * fct0; int tmp_count = count * 16 / nb_arete(); if (tmp_count >= 4) @@ -2663,57 +2682,57 @@ void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) stl_facet * fct4 = 0; int i = 0; if (tmp_count < 16) - calc_extrem_partial( facet, fct1, fct2, fct3, fct4); + calc_extrem_partial(facet, fct1, fct2, fct3, fct4); else - calc_extrem_full( facet, fct1, fct2, fct3, fct4); + calc_extrem_full(facet, fct1, fct2, fct3, fct4); #ifdef DEBUG if (!nodebug) { - cout << "(4)" - << " fct1=" << (fct1 ? fct1->nbr_facet : 0) - << " fct2=" << (fct2 ? fct2->nbr_facet : 0) - << " fct3=" << (fct3 ? fct3->nbr_facet : 0) - << " fct4=" << (fct4 ? fct4->nbr_facet : 0) - <dump(); - fct2->dump(); - fct3->dump(); - fct4->dump(); + cout << "(4)" + << " fct1=" << (fct1 ? fct1->nbr_facet : 0) + << " fct2=" << (fct2 ? fct2->nbr_facet : 0) + << " fct3=" << (fct3 ? fct3->nbr_facet : 0) + << " fct4=" << (fct4 ? fct4->nbr_facet : 0) + << endl; + fct1->dump(); + fct2->dump(); + fct3->dump(); + fct4->dump(); } #endif if (!fct2) return; - calc_center( fct3, fct4, max_o, min_o, max_p, min_p ); + calc_center(fct3, fct4, max_o, min_o, max_p, min_p); // Calculate projection of facet on cylinder axis // to get cylinder width double max = -1e5; - double min = 1e5; + double min = 1e5; i = fct1->side_edge(fct2); for (int j = 2; j < 4; j++) { int k = (i + j) % fct1->usage; double dist = spaplan(fct1->coords[k], od, vd); -//cout << "k=" << k << " coords=" << fct1->coords[k] << " dist=" << dist << endl; + //cout << "k=" << k << " coords=" << fct1->coords[k] << " dist=" << dist << endl; if (dist < min) { min = dist; min_z = fct1->coords[k]; -//cout << "min=" << min << " min_z=" << min_z << endl; + //cout << "min=" << min << " min_z=" << min_z << endl; } if (dist > max) max = dist; } -//cout << "min=" << min << " max=" << max << endl; + //cout << "min=" << min << " max=" << max << endl; - // Verify that cylinder is not truncated + // Verify that cylinder is not truncated stl_facet * lst = facet; stl_facet * cur = lst->next_surf(0); do { double lmax = -1e5; - double lmin = 1e5; + double lmin = 1e5; for (int j = 0; j < 4; j++) { double dist = spaplan(cur->coords[j], od, vd); @@ -2722,14 +2741,13 @@ void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) if (dist > lmax) lmax = dist; } -//cout << "lmin=" << lmin << " lmax=" << lmax << endl; - if (!equal( min, lmin) || !equal( max, lmax)) + //cout << "lmin=" << lmin << " lmax=" << lmax << endl; + if (!equal(min, lmin) || !equal(max, lmax)) return; stl_facet * nxt = cur->next_surf(lst); lst = cur; cur = nxt; - } - while (cur && cur != facet); + } while (cur && cur != facet); if (rand_col_adj_cyl) { @@ -2746,8 +2764,7 @@ void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) stl_facet * nxt = cur->next_surf(lst); lst = cur; cur = nxt; - } - while (cur && cur != facet); + } while (cur && cur != facet); } // Calculate transformation matrix @@ -2773,42 +2790,42 @@ void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) while (tmp_count > 0) { - CString prefix(""); - int dec_count = 0; - //if (tmp_count == 4 || tmp_count == 8 || tmp_count == 12 || tmp_count == 16) - if (tmp_count >= 4 && tmp_count != 6 && tmp_count != 7) - { + CString prefix(""); + int dec_count = 0; + //if (tmp_count == 4 || tmp_count == 8 || tmp_count == 12 || tmp_count == 16) + if (tmp_count >= 4 && tmp_count != 6 && tmp_count != 7) + { prefix = CString((char)('0' + tmp_count / 4)) + CString("-4"); - dec_count = int( tmp_count / 4) * 4; - } - else if (tmp_count >= 2) - { + dec_count = int(tmp_count / 4) * 4; + } + else if (tmp_count >= 2) + { prefix = CString((char)('0' + tmp_count / 2)) + CString("-8"); - dec_count = int( tmp_count / 2) * 2; - } - else if (tmp_count == 1) - { + dec_count = int(tmp_count / 2) * 2; + } + else if (tmp_count == 1) + { prefix = "1-16"; dec_count = 1; - } - int col = col_line1; - if (rand_col_surfaces) - col = random_color(); + } + int col = col_line1; + if (rand_col_surfaces) + col = random_color(); if (nb_arete() == 48) prefix = "48\\" + prefix; - stl_prim * prim_cyl = new stl_prim(prefix + "cyli", col, cw); - stl_prim * prim_ed1 = new stl_prim(prefix + "edge", 16); - stl_prim * prim_ed2 = new stl_prim(prefix + "edge", 16); - prim_cyl->transfo = stl_lin(std_lin, stl_lin(min_p - min_o, max_o - min_o, min_z - min_o, min_o)) * lin_dec; - prim_ed1->transfo = stl_lin(std_lin, stl_lin(min_p - min_o, (max_o - min_o).normaliz(), min_z - min_o, min_o)) * lin_dec; - prim_ed2->transfo = stl_lin(std_lin, stl_lin(max_p - max_o, (max_o - min_o).normaliz(), min_z - min_o, max_o)) * lin_dec; - stl.add_prim(prim_cyl); - stl.add_prim(prim_ed1); - stl.add_prim(prim_ed2); - prim = prim_cyl; - tmp_count -= dec_count; - dec_count_tot += dec_count; - lin_dec = stl_lin(stl_v(cos(dec_count_tot * pi / 8), 0.0, sin(dec_count_tot * pi / 8)), + stl_prim * prim_cyl = new stl_prim(prefix + "cyli", col, cw); + stl_prim * prim_ed1 = new stl_prim(prefix + "edge", 16); + stl_prim * prim_ed2 = new stl_prim(prefix + "edge", 16); + prim_cyl->transfo = stl_lin(std_lin, stl_lin(min_p - min_o, max_o - min_o, min_z - min_o, min_o)) * lin_dec; + prim_ed1->transfo = stl_lin(std_lin, stl_lin(min_p - min_o, (max_o - min_o).normaliz(), min_z - min_o, min_o)) * lin_dec; + prim_ed2->transfo = stl_lin(std_lin, stl_lin(max_p - max_o, (max_o - min_o).normaliz(), min_z - min_o, max_o)) * lin_dec; + stl.add_prim(prim_cyl); + stl.add_prim(prim_ed1); + stl.add_prim(prim_ed2); + prim = prim_cyl; + tmp_count -= dec_count; + dec_count_tot += dec_count; + lin_dec = stl_lin(stl_v(cos(dec_count_tot * pi / 8), 0.0, sin(dec_count_tot * pi / 8)), stl_v(0.0, 1.0, 0.0), stl_v(cos((dec_count_tot + 4) * pi / 8), 0.0, sin((dec_count_tot + 4) * pi / 8)), stl_v(0.0, 0.0, 0.0)); @@ -2818,36 +2835,36 @@ void stl_cylinder::calc_prim( stl_facet * facet, stl_file & stl) //cout << prim_cyl.transfo << endl; } #ifdef DEBUG -if (!nodebug) -{ - cout << "stl_cylinder::calc_prim max_o=" << max_o - min_o - << " min_z=" << min_z - min_o - << " min_p=" << min_p - min_o - << " min_o=" << min_o - << endl; - cout << "2 4 " << min_p << " " << min_o << endl; - cout << "2 2 " << max_o << " " << min_o << endl; - cout << "2 1 " << min_z << " " << min_o << endl; -} + if (!nodebug) + { + cout << "stl_cylinder::calc_prim max_o=" << max_o - min_o + << " min_z=" << min_z - min_o + << " min_p=" << min_p - min_o + << " min_o=" << min_o + << endl; + cout << "2 4 " << min_p << " " << min_o << endl; + cout << "2 2 " << max_o << " " << min_o << endl; + cout << "2 1 " << min_z << " " << min_o << endl; + } #endif } -void stl_surf::calc_curv( stl_file & stl) +void stl_surf::calc_curv(stl_file & stl) { } -void stl_cylinder::calc_curv( stl_file & stl) +void stl_cylinder::calc_curv(stl_file & stl) { } -void stl_plane::calc_curv( stl_file & stl) +void stl_plane::calc_curv(stl_file & stl) { } void stl_file::primitives() { -// eps_empile(0.01); - // Bind facet together to faces + // eps_empile(0.01); + // Bind facet together to faces stl_facet_list * cur = facet_list; while (cur) { @@ -2864,7 +2881,7 @@ void stl_file::primitives() while (sur_ptr) { stl_surf * surf = sur_ptr->item; - surf->calc_curv( *this); + surf->calc_curv(*this); sur_ptr = sur_ptr->next; } // Search circle primitives @@ -2879,7 +2896,7 @@ void stl_file::primitives() stl_facet * fct = cur->item; if (fct->usage && fct->surf && !fct->surf->prim) { - fct->surf->calc_prim( fct, *this); + fct->surf->calc_prim(fct, *this); } cur = cur->next; } @@ -2914,7 +2931,7 @@ void stl_cylinder::clean(stl_facet * fct) for (int i = 0; i < fct->usage; i++) { if ((fct->adjacent[i] && fct->adjacent[i]->surf == fct->surf) || - !fct->edge[i]->colinear(vd)) + !fct->edge[i]->colinear(vd)) fct->edge[i]->printed = true; } fct->printed = true; @@ -2959,7 +2976,7 @@ bool stl_edge::calc_edge() if (opt5) { stl_v dir_e = (coord(1) - coord(2)).normaliz(); - int side = dir_e.ps( adjacent[0]->normal + adjacent[1]->normal) > 0; + int side = dir_e.ps(adjacent[0]->normal + adjacent[1]->normal) > 0; if (side) linetype = 5; else @@ -2971,13 +2988,13 @@ bool stl_edge::calc_edge() } } } - return( result); + return(result); } // Calculate edges between 2 adjacent facets void stl_file::calc_edge() { -// eps_empile(0.0001); + // eps_empile(0.0001); int nb_edge = 0; stl_edge_list * cur = edge_list; while (cur) @@ -2986,7 +3003,7 @@ void stl_file::calc_edge() nb_edge++; cur = cur->next; } -// eps_depile(); + // eps_depile(); if (!silent) cout << nb_edge << " edges cleared" << endl; } @@ -3046,6 +3063,8 @@ int main(int argc, char* argv[]) cout << "stl2dat v1.22" << endl; cout << "Usage : stl2dat filename [] [name [author]]" << endl; cout << " -out filename : name of the output file" << endl; + cout << " -scalemm : units of input file are in mm instead of ldraw units" << endl; + cout << " -scale S : S is scale factor" << endl; cout << " -o X Y Z : origin point" << endl; cout << " -m X Y Z A B C D E F G H I : transformation matrix" << endl; cout << " -a angle : angle is limit for optional edges" << endl; @@ -3055,7 +3074,7 @@ int main(int argc, char* argv[]) cout << " -teps value : minimum distance for coincidence" << endl; cout << " -deps value : maximum determinant for coplanar quads" << endl; cout << " -oeps value : epsilon used for remove unusefull facets" << endl; -// cout << " -o3 : merge triangles" << endl; + // cout << " -o3 : merge triangles" << endl; cout << " -o4 : no merge to quadrangles" << endl; cout << " -o5 : remove of internal (concave) optional edges" << endl; cout << " -op : no primitives calculation" << endl; @@ -3082,13 +3101,14 @@ int main(int argc, char* argv[]) cout << " -ldr : produces a .ldr file" << endl; cout << " -nobfc : no BFC instructions" << endl; cout << " -silent : does not display informations" << endl; + cout << " -verbose : display informations" << endl; cout << " -ldraw : does not add ldraw standard header" << endl; cout << " -raw : conversion without any optimisation or edge calculation" << endl; return 0; } #ifdef DEBUG -if (!nodebug) - cout << "File:" << argv[1] << endl; + if (!nodebug) + cout << "File:" << argv[1] << endl; #endif bool opt3 = false; @@ -3099,7 +3119,7 @@ if (!nodebug) bool opt_facets = true; ag_lim = radian(22.51); - ag_lim_q = pi / 20; + ag_lim_q = pi / 20; ag_lim_t = ag_lim / 2; bool b_ag_lim_t = false; bool auth_done = false; @@ -3124,7 +3144,7 @@ if (!nodebug) ldr_opt = false; ldr_out = false; bfc = true; - silent = false; + silent = true; ldraw = true; stl_raw = false; determinant_eps = 0.1; @@ -3163,10 +3183,10 @@ if (!nodebug) } stl.origin = stl_v(c[0], c[1], c[2]); stl.transf = stl_lin( - stl_v(1.0, 0.0, 0.0), - stl_v(0.0, 1.0, 0.0), - stl_v(0.0, 0.0, 1.0), - stl.origin); + stl_v(1.0, 0.0, 0.0), + stl_v(0.0, 1.0, 0.0), + stl_v(0.0, 0.0, 1.0), + stl.origin); } else if (attr == "-m") { @@ -3179,12 +3199,33 @@ if (!nodebug) c[i] = get_arg(argv, idx); } stl.transf = stl_lin( - stl_v(c[3], c[4], c[5]), - stl_v(c[6], c[7], c[8]), - stl_v(c[9],c[10],c[11]), - stl_v(c[0], c[1], c[2])); + stl_v(c[3], c[4], c[5]), + stl_v(c[6], c[7], c[8]), + stl_v(c[9], c[10], c[11]), + stl_v(c[0], c[1], c[2])); stl.origin = stl_v(c[0], c[1], c[2]); } + else if (attr == "-scale") + { + double s; + idx++; + if (idx < argc) + s = get_arg(argv, idx); + stl.transf = stl_lin( + stl_v(s, 0.0, 0.0), + stl_v(0.0, s, 0.0), + stl_v(0.0, 0.0, s), + stl.origin); + } + else if (attr == "-scalemm") + { + double s = 20 / 8; // mm to ldraw units + stl.transf = stl_lin( + stl_v(s, 0.0, 0.0), + stl_v(0.0, s, 0.0), + stl_v(0.0, 0.0, s), + stl.origin); + } else if (attr == "-a") { idx++; @@ -3297,8 +3338,8 @@ if (!nodebug) no_line4 = true; else if (attr == "-no5") no_line5 = true; -// else if (attr == "-o3") -// opt3 = false; + // else if (attr == "-o3") + // opt3 = false; else if (attr == "-o4") opt4 = false; else if (attr == "-o5") @@ -3325,6 +3366,8 @@ if (!nodebug) rand_col_adj_cyl = true; else if (attr == "-silent") silent = true; + else if (attr == "-verbose") + silent = false; else if (attr == "-ldraw") ldraw = false; else if (attr == "-raw") @@ -3366,8 +3409,8 @@ if (!nodebug) stl.author = argv[idx]; if (!silent) - cout << "stl2dat 1.22 (c) Marc Klein" << endl; - + cout << "stl2dat " << version << " (c) Marc Klein" << endl; + eps_empile(optim_eps); stl.read(); eps_depile(); @@ -3400,9 +3443,9 @@ if (!nodebug) stl.optim_facets(2); stl.optim_facets(1); } -//stl.dump(); -//stl.check(); - /**/ + //stl.dump(); + //stl.check(); + /**/ if (opt4) stl.optim4(); @@ -3413,8 +3456,8 @@ if (!nodebug) eps_depile(); if (opt_edge) stl.calc_edge(); -// if (opt3) -// stl.optim3(); + // if (opt3) + // stl.optim3(); } stl.write_dat(print_geom); From a2fe6c29910aeb370544745a9466f6f2552ff8f8 Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Fri, 24 Feb 2023 00:11:02 +1300 Subject: [PATCH 2/8] correct typo and grammar --- stl2dat.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index f37be5f..57a42b3 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -1,5 +1,5 @@ // 06/07/2019 1.31 Correct file reading problems. -// 13/04/2019 1.30 Adaptation to visual studio 2015. -scale, -scalemm, -berbose added. -silent by default. +// 13/04/2019 1.30 Adaptation to visual studio 2015. -scale, -scalemm, -verbose added. -silent by default. // 11/07/2011 1.22 Remove trace in nodebug mode. // 03/05/2011 1.21 Correct bug that stopped reading of file when very small facet was encounterd. // 03/05/2011 1.20 Add option -oeps used for remove unusefull facets, Debug : Use smaller eps when reading the facets @@ -3117,8 +3117,8 @@ int usage() cout << " -dat : produces a .dat file" << endl; cout << " -ldr : produces a .ldr file" << endl; cout << " -nobfc : no BFC instructions" << endl; - cout << " -silent : does not display informations" << endl; - cout << " -verbose : display informations" << endl; + cout << " -silent : does not display information (DEFAULT)" << endl; + cout << " -verbose : display information" << endl; cout << " -ldraw : does not add ldraw standard header" << endl; cout << " -raw : conversion without any optimisation or edge calculation" << endl; cout << " -h, --help : show this text and exit" << endl; From befef95e6d6524586eb8ede919ceeda4d18132ba Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Fri, 24 Feb 2023 00:37:53 +1300 Subject: [PATCH 3/8] correct UTF-8 for degree symbols and one e-acutre --- stl2dat.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index 57a42b3..1bd847b 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -733,7 +733,7 @@ bool stl_facet::recalculate_precision() bool result = false; if (usage == 4 && !no_line4) { - // On force la pr?cision max pour tous les vertex + // On force la précision max pour tous les vertex for (int i = 0; i < 4; i++) precision = max(vertex[i]->precision, precision); for (int i = 0; i < 4; i++) @@ -1408,7 +1408,7 @@ bool stl_facet::is_convex(bool trace) double maxag; calcul_angles(totag, minag, maxag); if (trace) - cout << "(" << nbr_facet << ") tot=" << degre(totag) << "° min=" << degre(minag) << "° max=" << degre(maxag) << "°" << endl; + cout << "(" << nbr_facet << ") tot=" << degre(totag) << "° min=" << degre(minag) << "° max=" << degre(maxag) << "°" << endl; if (equal(totag, 4 * pi)) { stl_v tmp = coords[0]; @@ -1417,7 +1417,7 @@ bool stl_facet::is_convex(bool trace) coords[2] = tmp; calcul_angles(totag, minag, maxag); if (trace) - cout << "(" << nbr_facet << ") tot=" << degre(totag) << "° min=" << degre(minag) << "° max=" << degre(maxag) << "°" << endl; + cout << "(" << nbr_facet << ") tot=" << degre(totag) << "° min=" << degre(minag) << "° max=" << degre(maxag) << "°" << endl; } result = (equal(totag, 2 * pi) && maxag < pi - ag_lim_q) || (equal(totag, 6 * pi) && minag > pi + ag_lim_q); return(result); @@ -1784,7 +1784,7 @@ void stl_vertex::scan_edges() ag_min = ag; ed_found = ed; } - cout << " fct(" << ed->ident() << ") ag=" << degre(ag) << "?" << " ag_min=" << degre(ag_min) << "?" << endl; + cout << " fct(" << ed->ident() << ") ag=" << degre(ag) << "°" << " ag_min=" << degre(ag_min) << "°" << endl; } cur = cur->next; } @@ -1815,7 +1815,7 @@ void stl_vertex::scan_edges() ln_min = ln; ed_found = ed; } - //cout << " fct(" << ed->ident() << ") ln=" << ln << "?" << " ln_min=" << ln_min << "?" << endl; + //cout << " fct(" << ed->ident() << ") ln=" << ln << "°" << " ln_min=" << ln_min << "°" << endl; cur = cur->next; } // if (ed_found && ln_min < 1 && ln_min > 0.01) @@ -1845,7 +1845,7 @@ if (ed->adjacent[1]) nbr_f = ed->adjacent[1]->nbr_facet; { ed_found = ed; } - //cout << " fct(" << ed->ident() << ") ln=" << ln << "?" << " ln_min=" << ln_min << "?" << endl; + //cout << " fct(" << ed->ident() << ") ln=" << ln << "°" << " ln_min=" << ln_min << "°" << endl; cur = cur->next; } if (ed_found) @@ -2248,7 +2248,7 @@ stl_cylinder * stl_facet::new_cylinder(stl_facet * fct2, const stl_v & op, const double ag = normal.angle(fct2->normal, v_ref); #ifdef DEBUG if (!nodebug) - cout << "angle(" << nbr_facet << "," << fct2->nbr_facet << ") = " << degre(ag) << "°" << endl; + cout << "angle(" << nbr_facet << "," << fct2->nbr_facet << ") = " << degre(ag) << "°" << endl; #endif if (equal(ag, angle_cyl)) { From 290e3001f0f1f2af1babf47b5ce8877c5b75a60d Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Fri, 24 Feb 2023 00:47:23 +1300 Subject: [PATCH 4/8] use version consistently --- stl2dat.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index 1bd847b..fe40b33 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -1040,7 +1040,7 @@ void stl_file::write_dat(bool print_geom) if (bfc) fout << "0 BFC CERTIFY CCW" << endl; fout << endl; - fout << "0 // Created with stl2dat conversion tool" << endl; + fout << "0 // Created with stl2dat conversion tool v" << version << endl; stl_prim_list * curp = prim_list; int prim_cpt = 0; while (curp) @@ -3077,7 +3077,7 @@ int iget_arg(char* argv[], int idx) int usage() { - cout << "stl2dat v1.31" << endl; + cout << "stl2dat v" << version << endl; cout << "Usage : stl2dat filename [] [name [author]]" << endl; cout << " -out filename : name of the output file" << endl; cout << " -scalemm : units of input file are in mm instead of ldraw units" << endl; @@ -3437,7 +3437,7 @@ int main(int argc, char* argv[]) stl.author = argv[idx]; if (!silent) - cout << "stl2dat " << version << " (c) Marc Klein" << endl; + cout << "stl2dat v" << version << " (c) Marc Klein" << endl; eps_empile(optim_eps); stl.read(); From acc25168136b1ed4522b3cfdbbb92b97754f8cdb Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Fri, 24 Feb 2023 11:45:24 +1300 Subject: [PATCH 5/8] remove unused code and empty comments, add 1 tab in comment for alignment --- stl2dat.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index fe40b33..b435171 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -285,7 +285,6 @@ bool stl_file::read_header() return(result); } -int n = 1; bool stl_file::new_facet(const stl_v & normal, const stl_v vertex[]) { bool result = false; @@ -298,14 +297,11 @@ bool stl_file::new_facet(const stl_v & normal, const stl_v vertex[]) { // facet->coords[i] = vertex[i] - origin; facet->coords[i] = transf * vertex[i]; - /**/ for (int j = 0; j < i; j++) // if ((facet->coords[i] - facet->coords[j]).norm() < 0.001) if (facet->coords[i] == facet->coords[j]) identical = true; - /**/ } - //cout << "coords " << n << ":" << facet->coords[0] << " ; " << facet->coords[1] << " ; " << facet->coords[2] << endl; n++; if (!identical) { facet->calculate_normal(); @@ -346,7 +342,7 @@ int stl_file::read_facet_text() // 0 : ok // -1 : error 'facet' or 'endsolid' expected // -2 : bad token found - // 1 : end of solid + // 1 : end of solid stl_v normal; stl_v vertex[3]; From b6ca61212c0814987ccb3e2b70fabca59321889a Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Fri, 24 Feb 2023 12:19:40 +1300 Subject: [PATCH 6/8] spelling: unusefull -> unuseful --- stl2dat.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index b435171..47a22fd 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -2,7 +2,7 @@ // 13/04/2019 1.30 Adaptation to visual studio 2015. -scale, -scalemm, -verbose added. -silent by default. // 11/07/2011 1.22 Remove trace in nodebug mode. // 03/05/2011 1.21 Correct bug that stopped reading of file when very small facet was encounterd. -// 03/05/2011 1.20 Add option -oeps used for remove unusefull facets, Debug : Use smaller eps when reading the facets +// 03/05/2011 1.20 Add option -oeps used for remove unuseful facets, Debug : Use smaller eps when reading the facets // 31/01/2011 1.19 Add option -raw (conversion without any optimisation or edge calculation) // 19/01/2011 1.18 Add option -out (output file name) // 18/01/2011 1.17 Correct bug of Author and partname was wrong when -o option is present @@ -14,8 +14,8 @@ // 18/07/2002 1.01 Add options -no1 to -no5 to exclude line type // 14/08/2001 b10 Use two or three cylinders primitives when the plain primitive does not exist (use new 1-16cyli and 1-16edge) // 12/11/2000 b9 Improve detection of cylinders by checking the height -// 01/09/2000 b8 Improve detection of unusefull edges by counting the different normal of faces surrounding the edge -// 02/05/2000 b7 Remove unusefull edges (experiment), transformation matrix +// 01/09/2000 b8 Improve detection of unuseful edges by counting the different normal of faces surrounding the edge +// 02/05/2000 b7 Remove unuseful edges (experiment), transformation matrix // 13/03/2000 b6 Reads binary stl files. Set origin // 13/03/2000 b5 Detects cylinder primitives by basing only on angle between facet // 18/02/2000 b4 Scan edges at begining, topologic structure (adjency) @@ -1943,7 +1943,7 @@ void stl_vertex::scan_edges(int nb_face) } -// scan all vertices, if it is unusefull, then remove it. +// scan all vertices, if it is unuseful, then remove it. void stl_file::optim_facets(int nb_face) { //check(); @@ -1977,7 +1977,7 @@ void stl_file::optim_facets(int nb_face) cur = cur->next; } if (!silent) - cout << opt_v << " unusefull vertices removed" << endl; + cout << opt_v << " unuseful vertices removed" << endl; eps_depile(); #ifdef _DEBUG if (!nodebug) @@ -3082,16 +3082,16 @@ int usage() cout << " -m X Y Z A B C D E F G H I : transformation matrix" << endl; cout << " -a angle : angle is limit for optional edges" << endl; cout << " -aq angle : angle is limit for quadrangles" << endl; - cout << " -at angle : angle is limit for remove unusefull facets" << endl; + cout << " -at angle : angle is limit for remove unuseful facets" << endl; cout << " -eps value" << endl; cout << " -teps value : minimum distance for coincidence" << endl; cout << " -deps value : maximum determinant for coplanar quads" << endl; - cout << " -oeps value : epsilon used for remove unusefull facets" << endl; + cout << " -oeps value : epsilon used for remove unuseful facets" << endl; // cout << " -o3 : merge triangles" << endl; cout << " -o4 : no merge to quadrangles" << endl; cout << " -o5 : remove of internal (concave) optional edges" << endl; cout << " -op : no primitives calculation" << endl; - cout << " -of : no remove of unusefull facets" << endl; + cout << " -of : no remove of unuseful facets" << endl; cout << " -pp : print geometric surfaces" << endl; cout << " -cn : detect cylinder with normal difference" << endl; cout << " -oe : no creation of edges" << endl; From a3fae01d82d447418a766e1f0244e0d267f37839 Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Sat, 25 Feb 2023 10:12:15 +1300 Subject: [PATCH 7/8] fix bug in 1.31 scalemm feature Was previously scaling by 2, not 2.5 --- stl2dat.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index 47a22fd..7e84e50 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -3243,7 +3243,7 @@ int main(int argc, char* argv[]) } else if (attr == "-scalemm") { - double s = 20 / 8; // mm to ldraw units + double s = 20.0 / 8; // mm to ldraw units stl.transf = stl_lin( stl_v(s, 0.0, 0.0), stl_v(0.0, s, 0.0), From f9a9ce192e0d156da8cf0b35da2127a98e1698a1 Mon Sep 17 00:00:00 2001 From: Chales Horn Date: Sat, 25 Feb 2023 10:45:35 +1300 Subject: [PATCH 8/8] bump version to 1.32 because of significant bugfix --- stl2dat.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stl2dat.cxx b/stl2dat.cxx index 7e84e50..c80d491 100644 --- a/stl2dat.cxx +++ b/stl2dat.cxx @@ -1,7 +1,8 @@ +// 25/02/2023 1.32 Fix bug in -scalemm. // 06/07/2019 1.31 Correct file reading problems. // 13/04/2019 1.30 Adaptation to visual studio 2015. -scale, -scalemm, -verbose added. -silent by default. // 11/07/2011 1.22 Remove trace in nodebug mode. -// 03/05/2011 1.21 Correct bug that stopped reading of file when very small facet was encounterd. +// 03/05/2011 1.21 Correct bug that stopped reading of file when very small facet was encountered. // 03/05/2011 1.20 Add option -oeps used for remove unuseful facets, Debug : Use smaller eps when reading the facets // 31/01/2011 1.19 Add option -raw (conversion without any optimisation or edge calculation) // 19/01/2011 1.18 Add option -out (output file name) @@ -48,7 +49,7 @@ using namespace std; -#define version "1.31" +#define version "1.32" static double ag_lim; static double ag_lim_q;