diff --git a/Lab 1/ReadSTL.cpp b/Lab 1/ReadSTL.cpp deleted file mode 100644 index a54943e..0000000 --- a/Lab 1/ReadSTL.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -class ReadSTL { - private: - int numFacet; - double Xmin; - double Xmax; - double Ymin; - double Ymax; - double Zmin; - double Zmax; - public: - ReadSTL(string filename) { - ifstream inputfile(filename, ifstream::in); - string line; - string solidName; - // Solid header line - getline(inputfile, line); - istringstream inputstream(line); - // Iterate stream past "solid" - - // Retrieve name of solid - inputstream >> solidName; - // Process entire solid, looping through each facet - getline(inputfile, line); - while(1) { - // Iterate stream past "facet" - // Process entire facet, - - } - } - -}; - -int main(int argc, char** argv) { - ReadSTL RF(argv[1]); - - return 0; -} \ No newline at end of file diff --git a/Lab1/ReadSTL.cpp b/Lab1/ReadSTL.cpp new file mode 100644 index 0000000..a9c87b1 --- /dev/null +++ b/Lab1/ReadSTL.cpp @@ -0,0 +1,129 @@ +#include +#include +#include +#include +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; + } +}; diff --git a/Lab 1/STLFiles/brianascii.stl b/Lab1/STLFiles/brianascii.stl similarity index 100% rename from Lab 1/STLFiles/brianascii.stl rename to Lab1/STLFiles/brianascii.stl diff --git a/Lab 1/STLFiles/shape.stl b/Lab1/STLFiles/shape.stl similarity index 100% rename from Lab 1/STLFiles/shape.stl rename to Lab1/STLFiles/shape.stl diff --git a/Lab1/main.cpp b/Lab1/main.cpp new file mode 100644 index 0000000..6e6f5a8 --- /dev/null +++ b/Lab1/main.cpp @@ -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; +} \ No newline at end of file diff --git a/Lab1/makefile b/Lab1/makefile new file mode 100644 index 0000000..7ad58cd --- /dev/null +++ b/Lab1/makefile @@ -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 \ No newline at end of file diff --git a/Lecture/Week1/main b/Lecture/Week1/main deleted file mode 100755 index faa6d0f..0000000 Binary files a/Lecture/Week1/main and /dev/null differ