finally working

This commit is contained in:
2022-03-14 21:19:38 -05:00
parent ba62640018
commit 9801aaebfb
7 changed files with 12421 additions and 67 deletions

View File

@@ -6,7 +6,7 @@ using namespace std;
class ReadSTL {
private:
int numFacet;
int numFacet = 0;
double Xmin = 0;
double Xmax = 0;
double Ymin = 0;
@@ -18,27 +18,30 @@ class ReadSTL {
// Input Stream setup
ifstream inputfile(filename, ifstream::in);
string line;
string token;
string solidName;
// Solid header line
getline(inputfile, line);
// Input string stream for each line
istringstream lineStream(line);
string token;
// Iterate stream past "solid"
lineStream >> token; // Might not be a valid way of iterating stream
// Get solid name
lineStream >> token;
solidName = token; // Might not work
// Get solid name
lineStream >> solidName;
do {
// Process entire solid, looping through each facet
// Get next line
getline(inputfile, line);
istringstream lineStream(line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
// Get first word in line
lineStream >> token;
if(!token.compare("facet")) {
// Process facet
do {
// Process facet header
// "normal"
// Facet header
// Iterate past "normal"
lineStream >> token;
// Coord double value
double coord;
@@ -46,42 +49,56 @@ class ReadSTL {
// X Coord
lineStream >> token;
coord = stod(token);
// Min
if(coord < Xmin) {
// X Min
if((coord < Xmin) || numFacet == 0) {
Xmin = coord;
}
// Max
if(coord > Xmax) {
// X Max
if((coord > Xmax) || numFacet == 0) {
Xmax = coord;
}
// Y Coord
lineStream >> token;
coord = stod(token);
// Min
if(coord < Ymin) {
if((coord < Ymin) || numFacet == 0) {
Ymin = coord;
}
// Max
if(coord > Ymax) {
if((coord > Ymax) || numFacet == 0) {
Ymax = coord;
}
// Z Coord
lineStream >> token;
coord = stod(token);
// Min
if(coord < Zmin) {
if((coord < Zmin) || numFacet == 0) {
Zmin = coord;
}
// Max
if(coord > Zmax) {
if((coord > Zmax) || numFacet == 0) {
Zmax = coord;
}
// End facet header
do {
// Get next line
getline(inputfile, line);
istringstream lineStream(line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token;
if(token.compare("vertex")) {
if (!token.compare("outer")) {
do {
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token;
if(!token.compare("vertex")) {
//Process vertex
// No functionality needed
// Does nothing but iterate through each coord
@@ -92,8 +109,9 @@ class ReadSTL {
// Z coord
lineStream >> token;
} // End vertex line
} while(line.compare("endloop")); // Endloop
} while(line.compare("endfacet")); // Endfacet
} while(token.compare("endloop")); // Endloop
}
}while(token.compare("endfacet")); // Endfacet
// Iterate facet counter
numFacet++;
}

12306
Lab1/brianascii.stl Normal file

File diff suppressed because it is too large Load Diff

BIN
Lab1/lab1 Executable file

Binary file not shown.

BIN
Lab1/main Executable file

Binary file not shown.

View File

@@ -1,9 +1,13 @@
#include <iostream>
#include <string>
#include "ReadSTL.cpp"
using namespace std;
int main(int argc, char** argv) {
ReadSTL stl1(argv[1]);
cout << "Enter name of STL file: " << endl;
string filename;
cin >> filename;
ReadSTL stl1(filename);
cout << "Facets in file: " << stl1.getNumFacets() << endl;
cout << "X Min: " << stl1.getXmin() << endl;
cout << "X Max: " << stl1.getXmax() << endl;

View File

@@ -1,4 +1,4 @@
# lab1barnestr Makefile
# lab1 Makefile
CC = g++
CFLAGS = -c -MMD
@@ -7,7 +7,7 @@ LFLAGS =
SOURCES = ReadSTL.cpp main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = lab1barnestr
EXECUTABLE = lab1
all: $(EXECUTABLE) $(SOURCES)

26
Lab1/shape.stl Normal file
View File

@@ -0,0 +1,26 @@
solid Shape
facet normal 0.00441668 -0.0110034 -0.99993
outer loop
vertex 3.44187 5.90737 22.4502
vertex 3.45978 5.88253 22.4505
vertex 3.20279 5.6495 22.4519
endloop
endfacet
facet normal -0.840637 -0.386028 -0.379884
outer loop
vertex 0.546978 18.4458 9.70707
vertex 0.231294 19.1332 9.70707
vertex 0.517646 19.2217 8.98353
endloop
endfacet
facet normal -0.840637 -0.386028 -0.379884
outer loop
vertex 0.546978 18.4458 9.70707
vertex 0.231294 19.1332 9.70707
vertex 0.517646 19.2217 8.98353
endloop
endfacet
endsolid Shape