Main Page | Alphabetical List | Class List | 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. The model is translated so the center of the BBox is (0,0,0).
00005  *
00006  *\author       Xianming Chen
00007  *
00008  *\date         11 Jul 2004
00009  */
00010 
00011 
00012 #ifndef _TRIANGLEMESH_H
00013 #define _TRIANGLEMESH_H
00014 
00015 #include "Canvas.h"
00016 #include <vector>
00017 
00018 /**
00019  * A triangle has 3 vertexes, and additionaly it may have normals and/or texture coordinates at these three vertexes.
00020  * All these values are of Point(Vector) type, and are specified only by the index value into some container which
00021  * is maintained in TriangleMesh class.
00022  *
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 
00029     int i, j, k;                                               // indices of 3 vertices.
00030     int ni, nj, nk;                                            // indices of 3 normals.
00031     int ti, tj, tk;                                            // indices of 3 tex coords.
00032 };
00033   
00034 
00035 /**
00036  * Read in OBJ 3D model file, and provide access to its triangle data.
00037  */
00038 struct TriangleMesh
00039 {
00040     TriangleMesh(const string obj_fname);
00041     TriangleMesh()       { }
00042 
00043     void Draw(Canvas& canvas) const { }
00044       
00045     void init();
00046 
00047     std :: vector<Point> V;            // container of vertexes (x, y, z)
00048     std :: vector<Vector> N;           // container of normals (nx, ny, nz)
00049     std :: vector<RGB> T;              // container of textures (s, t, w)
00050     std :: vector<TriangleFace> F;     // container of triangles (i, j, k,  ni, nj, nk,  ti, tj, tk). 
00051     int total_triangles;
00052 
00053     bool has_normal;                            
00054     bool has_texture;
00055     Canvas* texture;                  // apply texture mapping only if this is non-zero and the trianglemesh has texture.
00056 };
00057 
00058 
00059 #endif

Generated on Sun Aug 8 13:47:41 2004 by doxygen 1.3.6