00001 #include "Model.h"
00002
00003 using namespace model;
00004
00020 Model::~Model() {
00021
00022 }
00023
00042 void Model::setVertexs(vector<Vertex*> vertexs) {
00043 m_vertexs = vertexs;
00044 }
00045
00067 Vertex* Model::getVertex(int i) {
00068 return m_vertexs[i];
00069 }
00070
00089 vector<Vertex*> Model::getVertexs() {
00090 return m_vertexs;
00091 }
00092
00111 Matrix Model::getModelVertexs() {
00112 int size = m_vertexs.size();
00113 Matrix v(size*3,1);
00114 for(int i=0; i<(int)m_vertexs.size(); i++) {
00115 IvVector3* tmp = m_vertexs[i]->getCoordinates();
00116 v((i*3)+1,1) = tmp->x;
00117 v((i*3)+2,1) = tmp->y;
00118 v((i*3)+3,1) = tmp->z;
00119 }
00120 return v;
00121 }
00122
00141 void Model::addVertex(Vertex* vertex) {
00142 vertex->setIndex(m_vertexs.size());
00143 m_vertexs.push_back(vertex);
00144 }
00145
00164 void Model::removeVertex(Vertex* vertex) {
00165
00166 }
00167
00186 void Model::updateVertices(Matrix vertexs) {
00187 printf("Model::updateVertices\n");
00188 for(int i=0; i<(int)m_vertexs.size();i++) {
00189 float x = (float)vertexs(i*3+1,1);
00190 float y = (float)vertexs(i*3+2,1);
00191 float z = (float)vertexs(i*3+3,1);
00192 m_vertexs[i]->updateCoordinates(x,y,z);
00193 }
00194 }
00195
00196
00215 void Model::setFaces(vector<Face*> faces) {
00216 m_faces = faces;
00217 }
00218
00240 Face* Model::getFace(int i) {
00241 return m_faces[i];
00242 }
00243
00262 vector<Face*> Model::getFaces() {
00263 return m_faces;
00264 }
00265
00284 void Model::addFace(Face* face) {
00285 m_faces.push_back(face);
00286 }
00287
00306 void Model::removeFace(Face* face) {
00307
00308 }
00309
00328 void Model::setLandmarks(vector<Landmark*> landmarks) {
00329 m_landmarks = landmarks;
00330 }
00331
00350 vector<Landmark*> Model::getLandmarks() {
00351 return m_landmarks;
00352 }
00353
00372 void Model::addLandmark(Landmark* landmark) {
00373 m_landmarks.push_back(landmark);
00374 }
00375
00394 void Model::removeLandmark(Landmark* landmark) {
00395
00396 }
00397
00416 void Model::setContours(vector<Contour*> contours) {
00417 m_contours = contours;
00418 }
00419
00438 vector<Contour*> Model::getContours() {
00439 return m_contours;
00440 }
00441
00460 void Model::addContour(Contour* contour) {
00461 m_contours.push_back(contour);
00462 }
00463
00482 void Model::removeContour(Contour* contour) {
00483
00484 }
00485
00504 void Model::setAnnotations(vector<Annotation*> annotations) {
00505 m_annotations = annotations;
00506 }
00507
00526 vector<Annotation*> Model::getAnnotations() {
00527 return m_annotations;
00528 }
00529
00548 void Model::addAnnotation(Annotation* annotation) {
00549 m_annotations.push_back(annotation);
00550 }
00551
00570 void Model::removeAnnotation(Annotation* annotation) {
00571
00572 }
00573
00595 bool Model::save(char* filename) {
00596 ofstream saveFile(filename);
00597 bool res = save(&saveFile);
00598 saveFile.close();
00599 return res;
00600 }
00601
00623 bool Model::save(ofstream* saveFile) {
00624 if(saveFile->is_open()) {
00625 *saveFile << "Vertex\n";
00626 for(int i=0;i<(int)m_vertexs.size();i++) {
00627 *saveFile << m_vertexs[i]->getCoordinates()->x << " ";
00628 *saveFile << m_vertexs[i]->getCoordinates()->y << " ";
00629 *saveFile << m_vertexs[i]->getCoordinates()->z << ",";
00630 }
00631 *saveFile << "\n";
00632 for(int i=0;i<(int)m_vertexs.size();i++) {
00633 *saveFile << m_vertexs[i]->getNormal()->x << " ";
00634 *saveFile << m_vertexs[i]->getNormal()->y << " ";
00635 *saveFile << m_vertexs[i]->getNormal()->z << ",";
00636 }
00637 *saveFile << "\nFace\n";
00638 for(int i=0;i<(int)m_faces.size();i++) {
00639 *saveFile << m_faces[i]->getVertex(0)->getIndex() << " ";
00640 *saveFile << m_faces[i]->getVertex(1)->getIndex() << " ";
00641 *saveFile << m_faces[i]->getVertex(2)->getIndex() << ",";
00642 }
00643 *saveFile << "\nLandmark\n";
00644 for(int i=0;i<(int)m_landmarks.size();i++) {
00645
00646 }
00647 *saveFile << "\nContour\n";
00648 for(int i=0;i<(int)m_contours.size();i++) {
00649
00650 }
00651 *saveFile << "\nAnnotation\n";
00652 for(int i=0;i<(int)m_annotations.size();i++) {
00653
00654 }
00655 *saveFile << "\n";
00656 return true;
00657 } else {
00658 return false;
00659 }
00660 }
00661
00683 bool Model::load(char* filename) {
00684 ifstream loadFile(filename);
00685 bool res = load(&loadFile);
00686 loadFile.close();
00687 return res;
00688 }
00689
00711 bool Model::load(ifstream* loadFile) {
00712 m_vertexs.clear();
00713 m_faces.clear();
00714 m_landmarks.clear();
00715 m_contours.clear();
00716 m_annotations.clear();
00717
00718
00719 string line;
00720 vector<string> tokens;
00721 vector<string> coords;
00722 if(loadFile->is_open()) {
00723 getline(*loadFile,line);
00724 getline(*loadFile,line);
00725 tokens.clear();
00726 Tokenize(line,tokens,",");
00727 for(int i=0;i<(int)tokens.size();i++) {
00728 coords.clear();
00729 Tokenize(tokens[i],coords," ");
00730 Vertex* vertex = new Vertex();
00731 vertex->setCoordinates(convertTo<float>(coords[0]),convertTo<float>(coords[1]),convertTo<float>(coords[2]));
00732 addVertex(vertex);
00733 }
00734 getline(*loadFile,line);
00735 tokens.clear();
00736 Tokenize(line,tokens,",");
00737 for(int i=0;i<(int)tokens.size();i++) {
00738 coords.clear();
00739 Tokenize(tokens[i],coords," ");
00740 Vertex* vertex = getVertex(i);
00741 vertex->setNormal(convertTo<float>(coords[0]),convertTo<float>(coords[1]),convertTo<float>(coords[2]));
00742 }
00743 getline(*loadFile,line);
00744 getline(*loadFile,line);
00745 tokens.clear();
00746 Tokenize(line,tokens,",");
00747 for(int i=0;i<(int)tokens.size();i++) {
00748 coords.clear();
00749 Tokenize(tokens[i],coords," ");
00750 Face* face = new Face();
00751 face->setVertices(m_vertexs[convertTo<int>(coords[0])],m_vertexs[convertTo<int>(coords[1])],m_vertexs[convertTo<int>(coords[2])]);
00752 addFace(face);
00753 }
00754 getline(*loadFile,line);
00755 getline(*loadFile,line);
00756 tokens.clear();
00757 Tokenize(line,tokens,",");
00758 for(int i=0;i<(int)tokens.size();i++) {
00759 coords.clear();
00760 Tokenize(tokens[i],coords," ");
00761
00762 }
00763 getline(*loadFile,line);
00764 getline(*loadFile,line);
00765 tokens.clear();
00766 Tokenize(line,tokens,",");
00767 for(int i=0;i<(int)tokens.size();i++) {
00768 coords.clear();
00769 Tokenize(tokens[i],coords," ");
00770 }
00771 getline(*loadFile,line);
00772 getline(*loadFile,line);
00773 tokens.clear();
00774 Tokenize(line,tokens,",");
00775 for(int i=0;i<(int)tokens.size();i++) {
00776 coords.clear();
00777 Tokenize(tokens[i],coords," ");
00778 }
00779 return true;
00780 } else {
00781 return false;
00782 }
00783 }
00784