lots of progress on lab 1
This commit is contained in:
@@ -1,43 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
129
Lab1/ReadSTL.cpp
Normal file
129
Lab1/ReadSTL.cpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
18
Lab1/main.cpp
Normal file
18
Lab1/main.cpp
Normal file
@@ -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;
|
||||||
|
}
|
||||||
25
Lab1/makefile
Normal file
25
Lab1/makefile
Normal file
@@ -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
|
||||||
Binary file not shown.
Reference in New Issue
Block a user