ready for submission

This commit is contained in:
2022-03-14 22:31:41 -05:00
parent 9801aaebfb
commit 8b7d0f9fe5
6 changed files with 173 additions and 12451 deletions

View File

@@ -1,4 +1,15 @@
#include <iostream> /**
* @file ReadSTL.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief A C++ file containing the functionality need to read in a .stl file.
* The ReadSTL class allows the min/max coordinates and total count of the STL
* facets be stored. The appropriate getters are also included.
* @version 1.0
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@@ -6,141 +17,171 @@ using namespace std;
class ReadSTL { class ReadSTL {
private: private:
int numFacet = 0; int numFacet;
double Xmin = 0; double Xmin;
double Xmax = 0; double Xmax;
double Ymin = 0; double Ymin;
double Ymax = 0; double Ymax;
double Zmin = 0; double Zmin;
double Zmax = 0; double Zmax;
public: public:
ReadSTL(string filename) { ReadSTL(string filename) {
// Input Stream setup // Instantiate variables
ifstream inputfile(filename, ifstream::in); numFacet = 0;
string line; // Input Stream setup
string token; ifstream inputfile(filename, ifstream::in);
string solidName; string line;
// Solid header line string token;
getline(inputfile, line); string solidName;
// Input string stream for each line // Solid header line
istringstream lineStream(line);
// Iterate stream past "solid"
lineStream >> token;
// Get solid name
lineStream >> solidName;
do {
// Process entire solid, looping through each facet
// Get next line
getline(inputfile, line); getline(inputfile, line);
// Set string stream to new line // Input string stream for each line
lineStream.str(line); istringstream lineStream(line);
// Clear sstream error state // Iterate stream past "solid"
lineStream.clear();
// Get first word in line
lineStream >> token; lineStream >> token;
if(!token.compare("facet")) { // Get solid name
// Process facet lineStream >> solidName;
// Facet header do {
// Iterate past "normal" // Process entire solid, looping through each facet
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
// Get first word in line
lineStream >> token; lineStream >> token;
// Coord double value if(!token.compare("facet")) {
double coord; // Facet header
// Convert coord string to double // Iterate past "normal"
// X Coord
lineStream >> token;
coord = stod(token);
// X Min
if((coord < Xmin) || numFacet == 0) {
Xmin = coord;
}
// X Max
if((coord > Xmax) || numFacet == 0) {
Xmax = coord;
}
// Y Coord
lineStream >> token;
coord = stod(token);
// Min
if((coord < Ymin) || numFacet == 0) {
Ymin = coord;
}
// Max
if((coord > Ymax) || numFacet == 0) {
Ymax = coord;
}
// Z Coord
lineStream >> token;
coord = stod(token);
// Min
if((coord < Zmin) || numFacet == 0) {
Zmin = coord;
}
// Max
if((coord > Zmax) || numFacet == 0) {
Zmax = coord;
}
// End facet header
do {
// Get next line
getline(inputfile, line);
// Set string stream to new line
lineStream.str(line);
// Clear sstream error state
lineStream.clear();
lineStream >> token; lineStream >> token;
if (!token.compare("outer")) { // Coord double value
do { double coord;
// Get next line // X Coord
getline(inputfile, line); lineStream >> token;
// Set string stream to new line coord = stod(token);
lineStream.str(line); if((coord < Xmin) || numFacet == 0) {
// Clear sstream error state Xmin = coord;
lineStream.clear(); }
lineStream >> token; if((coord > Xmax) || numFacet == 0) {
if(!token.compare("vertex")) { Xmax = coord;
//Process vertex }
// No functionality needed // Y Coord
// Does nothing but iterate through each coord lineStream >> token;
// X coord coord = stod(token);
if((coord < Ymin) || numFacet == 0) {
Ymin = coord;
}
if((coord > Ymax) || numFacet == 0) {
Ymax = coord;
}
// Z Coord
lineStream >> token;
coord = stod(token);
if((coord < Zmin) || numFacet == 0) {
Zmin = coord;
}
if((coord > Zmax) || numFacet == 0) {
Zmax = coord;
}
// End facet header
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("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; lineStream >> token;
// Y coord if(!token.compare("vertex")) {
lineStream >> token; // Process vertex
// Z coord // No additional functionality required
lineStream >> token; // X coord
} // End vertex line lineStream >> token;
} while(token.compare("endloop")); // Endloop // Y coord
} lineStream >> token;
}while(token.compare("endfacet")); // Endfacet // Z coord
// Iterate facet counter lineStream >> token;
numFacet++; } // End vertex line
} } while(token.compare("endloop")); // Endloop
}while(token.compare("endsolid")); }
// Close file }while(token.compare("endfacet")); // Endfacet
inputfile.close(); // Iterate facet counter
} numFacet++;
}
}while(token.compare("endsolid"));
// Close file
inputfile.close();
}
/**
* @brief Getter for the number of facets
*
* @return int
*/
int getNumFacets(){ int getNumFacets(){
return numFacet; return numFacet;
} }
/**
* @brief Getter for Xmin
*
* @return double
*/
double getXmin() { double getXmin() {
return Xmin; return Xmin;
} }
/**
* @brief Getter for Xmax
*
* @return double
*/
double getXmax() { double getXmax() {
return Xmax; return Xmax;
} }
/**
* @brief Getter for Ymin
*
* @return double
*/
double getYmin() { double getYmin() {
return Ymin; return Ymin;
} }
/**
* @brief Getter for Ymax
*
* @return double
*/
double getYmax() { double getYmax() {
return Ymax; return Ymax;
} }
/**
* @brief Getter for Zmin
*
* @return double
*/
double getZmin() { double getZmin() {
return Zmin; return Zmin;
} }
/**
* @brief Getter for Zmax
*
* @return double
*/
double getZmax() { double getZmax() {
return Zmax; return Zmax;
} }

File diff suppressed because it is too large Load Diff

BIN
Lab1/lab1

Binary file not shown.

BIN
Lab1/main

Binary file not shown.

View File

@@ -1,22 +1,35 @@
#include <iostream> /**
* @file main.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief The main driver file used to demonstrate the functionality of the
* ReadSTL class. The user enters the file location of the STL file as a
* command line arg and the console returns the min/max coords of the solid's
* facets as well as the total number of facets.
* @version 1.0
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <string> #include <string>
#include <iostream>
#include "ReadSTL.cpp" #include "ReadSTL.cpp"
using namespace std; using namespace std;
int main(int argc, char** argv) { int main(int argc, char** argv) {
cout << "Enter name of STL file: " << endl; ReadSTL stl1(argv[1]);
string filename; cout << endl << "File read successfully!" << endl;
cin >> filename; // Formatted file info output
ReadSTL stl1(filename); cout << "Facets in file: " << stl1.getNumFacets() << endl << endl;
cout << "Facets in file: " << stl1.getNumFacets() << endl;
cout << "X Min: " << stl1.getXmin() << endl; cout << "X Min: " << stl1.getXmin() << endl;
cout << "X Max: " << stl1.getXmax() << endl; cout << "X Max: " << stl1.getXmax() << endl << endl;
cout << "Y Min: " << stl1.getYmin() << endl; cout << "Y Min: " << stl1.getYmin() << endl;
cout << "Y Max: " << stl1.getYmax() << endl; cout << "Y Max: " << stl1.getYmax() << endl << endl;
cout << "Z Min: " << stl1.getZmin() << endl; cout << "Z Min: " << stl1.getZmin() << endl;
cout << "Z Max: " << stl1.getZmax() << endl; cout << "Z Max: " << stl1.getZmax() << endl << endl;
return 0; return 0;
} }

View File

@@ -1,26 +0,0 @@
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