Main Page | File List

TriangleMesh.h

Go to the documentation of this file.
00001 /**
00002  *\file         TriangleMesh.h
00003  *
00004  *\brief        For reading from an obj 3D model file.
00005  *
00006  *\author       Xianming Chen\n
00007  *              Computer Science Department\n
00008  *              University of Utah
00009  *
00010  *\date         11 Jul 2004\n
00011  *              Copyright (c) 2004, University of Utah
00012  */
00013 
00014 
00015 #ifndef _TRIANGLEMESH_H
00016 #define _TRIANGLEMESH_H
00017 
00018 #include "BBox.h"
00019 #include <vector>
00020 
00021 
00022 namespace columbia
00023 {
00024   struct TriangleFace
00025   {
00026       TriangleFace(int I, int J, int K, int Ti=-1, int Tj=-1, int Tk=-1, int Ni=-1, int Nj=-1, int Nk=-1) : 
00027         i(I), j(J), k(K), ti(Ti), tj(Tj), tk(Tk), ni(Ni), nj(Nj), nk(Nk) { }
00028       int i, j, k;                                               // indices of 3 vertices.
00029       int ni, nj, nk;                                            // indices of 3 normals.
00030       int ti, tj, tk;                                            // indices of 3 tex coords.
00031   };
00032   
00033   struct TriangleMesh
00034   {
00035       TriangleMesh(const char* obj_fname);
00036       TriangleMesh()       { }
00037       void TriangulateSphere(int depth = 1);
00038       
00039       std :: vector<Vertex> V;           // vertex (x, y, z)
00040       std :: vector<Vector> N;           // normal (x, y, z)
00041       std :: vector<Vertex> T;           // texture (s, t, w)
00042       std :: vector<TriangleFace> F;     // triangle (i, j, k)
00043       int total_triangles;
00044       bool has_normal;
00045       BBox bbox;
00046   };
00047 
00048   inline ostream& operator<< (ostream& os, TriangleMesh const& msh)
00049   {
00050     for(int i=1; i<msh.V.size(); i++)
00051     {
00052       os << "v " << msh.V[i].x << " " << msh.V[i].y << " " << msh.V[i].z << endl;
00053     }
00054     os << endl;
00055 
00056     for(int i=1; i<msh.N.size(); i++)
00057     {
00058       os << "vn " << msh.N[i].x << " " << msh.N[i].y << " " << msh.N[i].z << endl;
00059     }
00060     os << endl;
00061 
00062     for(int i=0; i<msh.F.size(); i++)
00063     {
00064       if(msh.has_normal)
00065         os << "f " << msh.F[i].i << "//" << msh.F[i].ni << " " << msh.F[i].j << "//" << msh.F[i].nj << " " << msh.F[i].k << "//" << msh.F[i].nk << endl;
00066       else
00067         os << "f " << msh.F[i].i << " " << msh.F[i].j <<  " " << msh.F[i].k << endl;
00068     }
00069     os << endl;
00070     return os;
00071   }
00072     
00073 
00074 }//end namespace xchen
00075 
00076 
00077 #endif

Generated on Wed Jul 14 19:41:55 2004 by doxygen 1.3.6