Skip to content

Commit

Permalink
Add option -swapyz (same orientation as in stl)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondratu committed Oct 31, 2024
1 parent 1db61dc commit eb1a4fe
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
18 changes: 14 additions & 4 deletions stl2dat.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// 31/10/2024 1.40 Add option -swapyz (same orientation as in stl)
// 31/10/2024 Fix bug in stl_edge::dump
// 25/02/2023 1.32 Fix bug in -scalemm.
// 06/07/2019 1.31 Correct file reading problems.
Expand Down Expand Up @@ -50,7 +51,7 @@

using namespace std;

#define version "1.32"
#define version "1.40"

static double ag_lim;
static double ag_lim_q;
Expand Down Expand Up @@ -368,20 +369,23 @@ int stl_file::read_facet_text()
{
if (result) result = token("vertex");
if (result) is >> vertex[i];
if (swapyz) vertex[i].swapyz();
}
if (result) result = token("endloop");
if (result) result = token("endfacet");
if (result) new_facet(normal, vertex);
return(result ? 0 : -1);
}

stl_v read_v(ifstream & is)
stl_v read_v(ifstream & is, bool swapyz)
{
union {
float f[3];
char buf[12];
} u;
is.read(u.buf, 12);
if (swapyz)
return(stl_v(u.f[0], u.f[2], u.f[1]));
return(stl_v(u.f[0], u.f[1], u.f[2]));
}

Expand All @@ -391,9 +395,9 @@ bool stl_file::read_facet_bin()
stl_v normal;
stl_v vertex[3];

normal = read_v(is);
normal = read_v(is, swapyz);
for (int i = 0; i < 3; i++)
vertex[i] = read_v(is);
vertex[i] = read_v(is, swapyz);

char dummy[2];
is.read(dummy, 2);
Expand Down Expand Up @@ -3086,6 +3090,8 @@ int usage()
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 << " -swapyz : swap y and z coordinates as same orientation in stl"
<< 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 unuseful facets" << endl;
Expand Down Expand Up @@ -3268,6 +3274,10 @@ int main(int argc, char* argv[])
ag_lim_t = ag_lim / 2;
}
}
else if (attr == "-swapyz")
{
stl.swapyz = true;
}
else if (attr == "-aq")
{
idx++;
Expand Down
1 change: 1 addition & 0 deletions stl2dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class stl_file
int ok;
stl_v origin;
stl_lin transf;
bool swapyz = false;
int nbr_facet;
private:
stl_facet_list * facet_list;
Expand Down
5 changes: 5 additions & 0 deletions vect.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ stl_v::stl_v(
x[2] = b;
}

void stl_v::swapyz()
{
std::swap(x[1], x[2]);
}

void stl_v::x_coord_set(
const double r
)
Expand Down
4 changes: 3 additions & 1 deletion vect.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ friend std::ostream& operator<<(
/*-
! follow methods for datas interrogation.
*/


void swapyz();

void x_coord_set(
const double r // New X coordinate of the point/vector.
);
Expand Down

0 comments on commit eb1a4fe

Please sign in to comment.