OBJNode.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS FastMesh
00048 //
00049 //=============================================================================
00050 
00051 
00052 #ifndef ACG_OBJ_NODE_HH
00053 #define ACG_OBJ_NODE_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include "BaseNode.hh"
00059 #include "DrawModes.hh"
00060 #include "../Math/VectorT.hh"
00061 #include <string>
00062 #include <vector>
00063 
00064 
00065 //== FORWARD DECLARATION ======================================================
00066 
00067 
00068 //== NAMESPACES ===============================================================
00069 
00070 
00071 namespace ACG {
00072 namespace SceneGraph {
00073 
00074 
00075 //== CLASS DEFINITION =========================================================
00076 
00077 
00078 class ACGDLLEXPORT OBJNode : public BaseNode
00079 {
00080 
00081 public:
00082 
00084   OBJNode( BaseNode*         _parent=0,
00085            std::string       _name="<OBJNode>" )
00086     : BaseNode(_parent, _name)
00087   {}
00088 
00089 
00091   virtual ~OBJNode() {}
00092 
00093 
00094   ACG_CLASSNAME(OBJNode);
00095 
00096 
00098   unsigned int availableDrawModes() const;
00099 
00101   void boundingBox(Vec3f& _bbMin, Vec3f& _bbMax);
00102 
00104   void draw(GLState& _state, unsigned int _drawMode);
00105 
00107   void pick(GLState& _state, PickTarget _target);
00108 
00109 
00110   struct Face
00111   {
00112     Face(int _i0=-1, int _i1=-1, int _i2=-1,
00113          int _t0=-1, int _t1=-1, int _t2=-1)
00114       : i0(_i0), i1(_i1), i2(_i2),
00115         t0(_t0), t1(_t1), t2(_t2) {}
00116     int i0, i1, i2, t0, t1, t2;
00117   };
00118 
00119 
00121   unsigned int n_vertices() const { return vertices_.size(); }
00123   unsigned int n_faces()    const { return faces_.size(); }
00125   unsigned int n_normals()  const { return normals_.size(); }
00127   unsigned int n_texcoords()  const { return texCoords_.size(); }
00128 
00129 
00131   void clear()
00132   {
00133     vertices_.clear();
00134     faces_.clear();
00135     normals_.clear();
00136     texCoords_.clear();
00137   }
00138 
00139 
00141   unsigned int add_vertex(const Vec3f& _v)
00142   {
00143     vertices_.push_back(_v);
00144     return vertices_.size()-1;
00145   }
00146 
00147 
00149   unsigned int add_face(const Face& _f)
00150   {
00151     faces_.push_back(_f);
00152     return faces_.size()-1;
00153   }
00154 
00156   unsigned int add_face(unsigned int _i0,
00157                         unsigned int _i1,
00158                         unsigned int _i2)
00159   {
00160     faces_.push_back(Face(_i0, _i1, _i2));
00161     return faces_.size()-1;
00162   }
00163 
00164 
00166   Vec3f& vertex(unsigned int _i)
00167   {
00168     assert(_i < n_vertices());
00169     return vertices_[_i];
00170   }
00172   const Vec3f& vertex(unsigned int _i) const
00173   {
00174     assert(_i < n_vertices());
00175     return vertices_[_i];
00176   }
00177 
00178 
00180   const Face&  face(unsigned int _i) const
00181   {
00182     assert(_i < n_faces());
00183     return faces_[_i];
00184   }
00186   Face&  face(unsigned int _i)
00187   {
00188     assert(_i < n_faces());
00189     return faces_[_i];
00190   }
00191 
00192 
00194   const Vec3f& normal(unsigned int _i) const
00195   {
00196     assert(_i < n_normals());
00197     return normals_[_i];
00198   }
00200   Vec3f& normal(unsigned int _i)
00201   {
00202     assert(_i < n_normals());
00203     return normals_[_i];
00204   }
00205 
00206 
00208   bool read(const std::string& _filename);
00209 
00210 
00212   void update_face_normals();
00213 
00214 
00215 private:
00216 
00217   void draw_obj() const;
00218   void draw_obj_tex() const;
00219 
00220   std::vector<Vec3f> vertices_;
00221   std::vector<Vec3f> normals_;
00222   std::vector<Vec2f> texCoords_;
00223   std::vector<Face>  faces_;
00224 };
00225 
00226 
00227 //=============================================================================
00228 } // namespace SceneGraph
00229 } // namespace ACG
00230 //=============================================================================
00231 #endif // ACG_OBJ_NODE_HH
00232 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .