lots of progress on lab 1

This commit is contained in:
2022-03-14 14:49:24 -05:00
parent 91babda1ed
commit 7fa13c0f6d
7 changed files with 172 additions and 43 deletions

129
Lab1/ReadSTL.cpp Normal file
View File

@@ -0,0 +1,129 @@
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
class ReadSTL {
private:
int numFacet;
double Xmin = 0;
double Xmax = 0;
double Ymin = 0;
double Ymax = 0;
double Zmin = 0;
double Zmax = 0;
public:
ReadSTL(string filename) {
// Input Stream setup
ifstream inputfile(filename, ifstream::in);
string line;
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
do {
// Process entire solid, looping through each facet
getline(inputfile, line);
istringstream lineStream(line);
lineStream >> token;
if(!token.compare("facet")) {
// Process facet
do {
// Process facet header
// "normal"
lineStream >> token;
// Coord double value
double coord;
// Convert coord string to double
// X Coord
lineStream >> token;
coord = stod(token);
// Min
if(coord < Xmin) {
Xmin = coord;
}
// Max
if(coord > Xmax) {
Xmax = coord;
}
// Y Coord
lineStream >> token;
coord = stod(token);
// Min
if(coord < Ymin) {
Ymin = coord;
}
// Max
if(coord > Ymax) {
Ymax = coord;
}
// Z Coord
lineStream >> token;
coord = stod(token);
// Min
if(coord < Zmin) {
Zmin = coord;
}
// Max
if(coord > Zmax) {
Zmax = coord;
}
// End facet header
do {
getline(inputfile, line);
istringstream lineStream(line);
lineStream >> token;
if(token.compare("vertex")) {
//Process vertex
// No functionality needed
// Does nothing but iterate through each coord
// X coord
lineStream >> token;
// Y coord
lineStream >> token;
// Z coord
lineStream >> token;
} // End vertex line
} while(line.compare("endloop")); // Endloop
} while(line.compare("endfacet")); // Endfacet
// Iterate facet counter
numFacet++;
}
} while (token.compare("endsolid"));
// Close file
inputfile.close();
}
int getNumFacets(){
return numFacet;
}
double getXmin() {
return Xmin;
}
double getXmax() {
return Xmax;
}
double getYmin() {
return Ymin;
}
double getYmax() {
return Ymax;
}
double getZmin() {
return Zmin;
}
double getZmax() {
return Zmax;
}
};

12306
Lab1/STLFiles/brianascii.stl Normal file

File diff suppressed because it is too large Load Diff

26
Lab1/STLFiles/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

18
Lab1/main.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "ReadSTL.cpp"
using namespace std;
int main(int argc, char** argv) {
ReadSTL stl1(argv[1]);
cout << "Facets in file:" << stl1.getNumFacets() << endl;
cout << "X Min: " << stl1.getXmin() << endl;
cout << "X Max: " << stl1.getXmax() << endl;
cout << "Y Min: " << stl1.getYmin() << endl;
cout << "Y Max: " << stl1.getYmax() << endl;
cout << "Z Min: " << stl1.getZmin() << endl;
cout << "Z Max: " << stl1.getZmax() << endl;
return 0;
}

25
Lab1/makefile Normal file
View File

@@ -0,0 +1,25 @@
# lab1barnestr Makefile
CC = g++
CFLAGS = -c -MMD
LFLAGS =
# Change w/ every new project
SOURCES = ReadSTL.cpp main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = lab1barnestr
all: $(EXECUTABLE) $(SOURCES)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LFLAGS) -o $@ $(OBJECTS)
-include * .d
%.o:%.cpp
$(CC) $(CFLAGS) $<
clean:
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f *.d