ready for submission
This commit is contained in:
@@ -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 <fstream>
|
||||
#include <sstream>
|
||||
@@ -6,15 +17,17 @@ using namespace std;
|
||||
|
||||
class ReadSTL {
|
||||
private:
|
||||
int numFacet = 0;
|
||||
double Xmin = 0;
|
||||
double Xmax = 0;
|
||||
double Ymin = 0;
|
||||
double Ymax = 0;
|
||||
double Zmin = 0;
|
||||
double Zmax = 0;
|
||||
int numFacet;
|
||||
double Xmin;
|
||||
double Xmax;
|
||||
double Ymin;
|
||||
double Ymax;
|
||||
double Zmin;
|
||||
double Zmax;
|
||||
public:
|
||||
ReadSTL(string filename) {
|
||||
// Instantiate variables
|
||||
numFacet = 0;
|
||||
// Input Stream setup
|
||||
ifstream inputfile(filename, ifstream::in);
|
||||
string line;
|
||||
@@ -39,48 +52,39 @@ class ReadSTL {
|
||||
// Get first word in line
|
||||
lineStream >> token;
|
||||
if(!token.compare("facet")) {
|
||||
// Process facet
|
||||
// Facet header
|
||||
// Iterate past "normal"
|
||||
lineStream >> token;
|
||||
// Coord double value
|
||||
double coord;
|
||||
// Convert coord string to double
|
||||
// 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);
|
||||
@@ -99,9 +103,8 @@ class ReadSTL {
|
||||
lineStream.clear();
|
||||
lineStream >> token;
|
||||
if(!token.compare("vertex")) {
|
||||
//Process vertex
|
||||
// No functionality needed
|
||||
// Does nothing but iterate through each coord
|
||||
// Process vertex
|
||||
// No additional functionality required
|
||||
// X coord
|
||||
lineStream >> token;
|
||||
// Y coord
|
||||
@@ -120,27 +123,65 @@ class ReadSTL {
|
||||
inputfile.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for the number of facets
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int getNumFacets(){
|
||||
return numFacet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for Xmin
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
double getXmin() {
|
||||
return Xmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for Xmax
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
double getXmax() {
|
||||
return Xmax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for Ymin
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
double getYmin() {
|
||||
return Ymin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for Ymax
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
double getYmax() {
|
||||
return Ymax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for Zmin
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
double getZmin() {
|
||||
return Zmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Getter for Zmax
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
double getZmax() {
|
||||
return Zmax;
|
||||
}
|
||||
|
||||
12306
Lab1/brianascii.stl
12306
Lab1/brianascii.stl
File diff suppressed because it is too large
Load Diff
@@ -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 <iostream>
|
||||
#include "ReadSTL.cpp"
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
cout << "Enter name of STL file: " << endl;
|
||||
string filename;
|
||||
cin >> filename;
|
||||
ReadSTL stl1(filename);
|
||||
cout << "Facets in file: " << stl1.getNumFacets() << endl;
|
||||
ReadSTL stl1(argv[1]);
|
||||
cout << endl << "File read successfully!" << endl;
|
||||
// Formatted file info output
|
||||
cout << "Facets in file: " << stl1.getNumFacets() << endl << 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 Max: " << stl1.getYmax() << endl;
|
||||
cout << "Y Max: " << stl1.getYmax() << endl << endl;
|
||||
|
||||
cout << "Z Min: " << stl1.getZmin() << endl;
|
||||
cout << "Z Max: " << stl1.getZmax() << endl;
|
||||
cout << "Z Max: " << stl1.getZmax() << endl << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user