finally working
This commit is contained in:
@@ -6,7 +6,7 @@ using namespace std;
|
|||||||
|
|
||||||
class ReadSTL {
|
class ReadSTL {
|
||||||
private:
|
private:
|
||||||
int numFacet;
|
int numFacet = 0;
|
||||||
double Xmin = 0;
|
double Xmin = 0;
|
||||||
double Xmax = 0;
|
double Xmax = 0;
|
||||||
double Ymin = 0;
|
double Ymin = 0;
|
||||||
@@ -18,27 +18,30 @@ class ReadSTL {
|
|||||||
// Input Stream setup
|
// Input Stream setup
|
||||||
ifstream inputfile(filename, ifstream::in);
|
ifstream inputfile(filename, ifstream::in);
|
||||||
string line;
|
string line;
|
||||||
|
string token;
|
||||||
string solidName;
|
string solidName;
|
||||||
// Solid header line
|
// Solid header line
|
||||||
getline(inputfile, line);
|
getline(inputfile, line);
|
||||||
// Input string stream for each line
|
// Input string stream for each line
|
||||||
istringstream lineStream(line);
|
istringstream lineStream(line);
|
||||||
string token;
|
|
||||||
// Iterate stream past "solid"
|
// Iterate stream past "solid"
|
||||||
lineStream >> token; // Might not be a valid way of iterating stream
|
|
||||||
// Get solid name
|
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
solidName = token; // Might not work
|
// Get solid name
|
||||||
|
lineStream >> solidName;
|
||||||
do {
|
do {
|
||||||
// Process entire solid, looping through each facet
|
// Process entire solid, looping through each facet
|
||||||
|
// Get next line
|
||||||
getline(inputfile, line);
|
getline(inputfile, line);
|
||||||
istringstream lineStream(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;
|
||||||
if(!token.compare("facet")) {
|
if(!token.compare("facet")) {
|
||||||
// Process facet
|
// Process facet
|
||||||
do {
|
// Facet header
|
||||||
// Process facet header
|
// Iterate past "normal"
|
||||||
// "normal"
|
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
// Coord double value
|
// Coord double value
|
||||||
double coord;
|
double coord;
|
||||||
@@ -46,42 +49,56 @@ class ReadSTL {
|
|||||||
// X Coord
|
// X Coord
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
coord = stod(token);
|
coord = stod(token);
|
||||||
// Min
|
// X Min
|
||||||
if(coord < Xmin) {
|
if((coord < Xmin) || numFacet == 0) {
|
||||||
Xmin = coord;
|
Xmin = coord;
|
||||||
}
|
}
|
||||||
// Max
|
// X Max
|
||||||
if(coord > Xmax) {
|
if((coord > Xmax) || numFacet == 0) {
|
||||||
Xmax = coord;
|
Xmax = coord;
|
||||||
}
|
}
|
||||||
// Y Coord
|
// Y Coord
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
coord = stod(token);
|
coord = stod(token);
|
||||||
// Min
|
// Min
|
||||||
if(coord < Ymin) {
|
if((coord < Ymin) || numFacet == 0) {
|
||||||
Ymin = coord;
|
Ymin = coord;
|
||||||
}
|
}
|
||||||
// Max
|
// Max
|
||||||
if(coord > Ymax) {
|
if((coord > Ymax) || numFacet == 0) {
|
||||||
Ymax = coord;
|
Ymax = coord;
|
||||||
}
|
}
|
||||||
// Z Coord
|
// Z Coord
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
coord = stod(token);
|
coord = stod(token);
|
||||||
// Min
|
// Min
|
||||||
if(coord < Zmin) {
|
if((coord < Zmin) || numFacet == 0) {
|
||||||
Zmin = coord;
|
Zmin = coord;
|
||||||
}
|
}
|
||||||
// Max
|
// Max
|
||||||
if(coord > Zmax) {
|
if((coord > Zmax) || numFacet == 0) {
|
||||||
Zmax = coord;
|
Zmax = coord;
|
||||||
}
|
}
|
||||||
// End facet header
|
// End facet header
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
// Get next line
|
||||||
getline(inputfile, line);
|
getline(inputfile, line);
|
||||||
istringstream lineStream(line);
|
// Set string stream to new line
|
||||||
|
lineStream.str(line);
|
||||||
|
// Clear sstream error state
|
||||||
|
lineStream.clear();
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
if(token.compare("vertex")) {
|
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;
|
||||||
|
if(!token.compare("vertex")) {
|
||||||
//Process vertex
|
//Process vertex
|
||||||
// No functionality needed
|
// No functionality needed
|
||||||
// Does nothing but iterate through each coord
|
// Does nothing but iterate through each coord
|
||||||
@@ -92,12 +109,13 @@ class ReadSTL {
|
|||||||
// Z coord
|
// Z coord
|
||||||
lineStream >> token;
|
lineStream >> token;
|
||||||
} // End vertex line
|
} // End vertex line
|
||||||
} while(line.compare("endloop")); // Endloop
|
} while(token.compare("endloop")); // Endloop
|
||||||
} while(line.compare("endfacet")); // Endfacet
|
}
|
||||||
|
}while(token.compare("endfacet")); // Endfacet
|
||||||
// Iterate facet counter
|
// Iterate facet counter
|
||||||
numFacet++;
|
numFacet++;
|
||||||
}
|
}
|
||||||
} while (token.compare("endsolid"));
|
}while(token.compare("endsolid"));
|
||||||
// Close file
|
// Close file
|
||||||
inputfile.close();
|
inputfile.close();
|
||||||
}
|
}
|
||||||
|
|||||||
12306
Lab1/brianascii.stl
Normal file
12306
Lab1/brianascii.stl
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,14 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#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 << "Facets in file:" << stl1.getNumFacets() << endl;
|
cin >> filename;
|
||||||
|
ReadSTL stl1(filename);
|
||||||
|
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;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# lab1barnestr Makefile
|
# lab1 Makefile
|
||||||
|
|
||||||
CC = g++
|
CC = g++
|
||||||
CFLAGS = -c -MMD
|
CFLAGS = -c -MMD
|
||||||
@@ -7,7 +7,7 @@ LFLAGS =
|
|||||||
SOURCES = ReadSTL.cpp main.cpp
|
SOURCES = ReadSTL.cpp main.cpp
|
||||||
OBJECTS = $(SOURCES:.cpp=.o)
|
OBJECTS = $(SOURCES:.cpp=.o)
|
||||||
# Change w/ every new project
|
# Change w/ every new project
|
||||||
EXECUTABLE = lab1barnestr
|
EXECUTABLE = lab1
|
||||||
|
|
||||||
all: $(EXECUTABLE) $(SOURCES)
|
all: $(EXECUTABLE) $(SOURCES)
|
||||||
|
|
||||||
|
|||||||
26
Lab1/shape.stl
Normal file
26
Lab1/shape.stl
Normal 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
|
||||||
Reference in New Issue
Block a user