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,15 +17,17 @@ 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) {
// Instantiate variables
numFacet = 0;
// Input Stream setup // Input Stream setup
ifstream inputfile(filename, ifstream::in); ifstream inputfile(filename, ifstream::in);
string line; string line;
@@ -39,48 +52,39 @@ class ReadSTL {
// Get first word in line // Get first word in line
lineStream >> token; lineStream >> token;
if(!token.compare("facet")) { if(!token.compare("facet")) {
// Process facet
// Facet header // Facet header
// Iterate past "normal" // Iterate past "normal"
lineStream >> token; lineStream >> token;
// Coord double value // Coord double value
double coord; double coord;
// Convert coord string to double
// X Coord // X Coord
lineStream >> token; lineStream >> token;
coord = stod(token); coord = stod(token);
// X Min
if((coord < Xmin) || numFacet == 0) { if((coord < Xmin) || numFacet == 0) {
Xmin = coord; Xmin = coord;
} }
// X Max
if((coord > Xmax) || numFacet == 0) { if((coord > Xmax) || numFacet == 0) {
Xmax = coord; Xmax = coord;
} }
// Y Coord // Y Coord
lineStream >> token; lineStream >> token;
coord = stod(token); coord = stod(token);
// Min
if((coord < Ymin) || numFacet == 0) { if((coord < Ymin) || numFacet == 0) {
Ymin = coord; Ymin = coord;
} }
// Max
if((coord > Ymax) || numFacet == 0) { if((coord > Ymax) || numFacet == 0) {
Ymax = coord; Ymax = coord;
} }
// Z Coord // Z Coord
lineStream >> token; lineStream >> token;
coord = stod(token); coord = stod(token);
// Min
if((coord < Zmin) || numFacet == 0) { if((coord < Zmin) || numFacet == 0) {
Zmin = coord; Zmin = coord;
} }
// Max
if((coord > Zmax) || numFacet == 0) { if((coord > Zmax) || numFacet == 0) {
Zmax = coord; Zmax = coord;
} }
// End facet header // End facet header
do { do {
// Get next line // Get next line
getline(inputfile, line); getline(inputfile, line);
@@ -99,9 +103,8 @@ class ReadSTL {
lineStream.clear(); lineStream.clear();
lineStream >> token; lineStream >> token;
if(!token.compare("vertex")) { if(!token.compare("vertex")) {
//Process vertex // Process vertex
// No functionality needed // No additional functionality required
// Does nothing but iterate through each coord
// X coord // X coord
lineStream >> token; lineStream >> token;
// Y coord // Y coord
@@ -120,27 +123,65 @@ class ReadSTL {
inputfile.close(); 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