52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
|
#include <fstream>
|
||
|
#include <iostream>
|
||
|
|
||
|
#include "object.h"
|
||
|
|
||
|
void Object::load(std::string file, std::string txtpos) {
|
||
|
|
||
|
std::string line;
|
||
|
|
||
|
std::ifstream ifile;
|
||
|
ifile.open (file);
|
||
|
|
||
|
bool first = true;
|
||
|
|
||
|
if (ifile.is_open()) {
|
||
|
while ( getline (ifile,line) ) {
|
||
|
if (first) {
|
||
|
if (line != "OBJECT") {
|
||
|
std::cerr << "File " << file << " does not contain OBJECT signature (" << line << ")." << std::endl;
|
||
|
return;
|
||
|
}
|
||
|
first = false;
|
||
|
} else if (line == "" ) {
|
||
|
return;
|
||
|
} else {
|
||
|
this->plns.push_back(new Plane(line));
|
||
|
}
|
||
|
}
|
||
|
ifile.close();
|
||
|
} else {
|
||
|
std::cerr << "Could not open file " << file << std::endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this->pts = new Point(txtpos);
|
||
|
}
|
||
|
|
||
|
std::vector<Plane*> Object::getSides() { return this->plns; }
|
||
|
bool Object::isContained() { return true; };
|
||
|
|
||
|
std::ostream & operator<<(std::ostream& os, Object& o){
|
||
|
return o.print(os);
|
||
|
}
|
||
|
|
||
|
std::ostream& Object::print(std::ostream& os) {
|
||
|
os << " - Object " << this << std::endl;
|
||
|
for (Plane* i: this->getSides()) {
|
||
|
os << (*i);
|
||
|
}
|
||
|
return os;
|
||
|
}
|