Developer Documentation
OBJNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 //=============================================================================
47 //
48 // CLASS FastMesh
49 //
50 //=============================================================================
51 
52 
53 #ifndef ACG_OBJ_NODE_HH
54 #define ACG_OBJ_NODE_HH
55 
56 
57 //== INCLUDES =================================================================
58 
59 #include "BaseNode.hh"
60 #include "DrawModes.hh"
61 #include "../Math/VectorT.hh"
62 #include <string>
63 #include <vector>
64 
65 
66 //== FORWARD DECLARATION ======================================================
67 
68 
69 //== NAMESPACES ===============================================================
70 
71 
72 namespace ACG {
73 namespace SceneGraph {
74 
75 
76 //== CLASS DEFINITION =========================================================
77 
78 
79 class ACGDLLEXPORT OBJNode : public BaseNode
80 {
81 
82 public:
83 
85  OBJNode( BaseNode* _parent=0,
86  const std::string& _name="<OBJNode>" )
87  : BaseNode(_parent, _name)
88  {}
89 
90 
92  virtual ~OBJNode() {}
93 
94 
95  ACG_CLASSNAME(OBJNode);
96 
97 
99  DrawModes::DrawMode availableDrawModes() const;
100 
102  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
103 
105  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
106 
108  void pick(GLState& _state, PickTarget _target);
109 
110 
111  struct Face
112  {
113  Face(int _i0=-1, int _i1=-1, int _i2=-1,
114  int _t0=-1, int _t1=-1, int _t2=-1)
115  : i0(_i0), i1(_i1), i2(_i2),
116  t0(_t0), t1(_t1), t2(_t2) {}
117  int i0, i1, i2, t0, t1, t2;
118  };
119 
120 
122  size_t n_vertices() const { return vertices_.size(); }
124  size_t n_faces() const { return faces_.size(); }
126  size_t n_normals() const { return normals_.size(); }
128  size_t n_texcoords() const { return texCoords_.size(); }
129 
130 
132  void clear()
133  {
134  vertices_.clear();
135  faces_.clear();
136  normals_.clear();
137  texCoords_.clear();
138  }
139 
140 
142  size_t add_vertex(const Vec3f& _v)
143  {
144  vertices_.push_back(_v);
145  return vertices_.size()-1;
146  }
147 
148 
150  size_t add_face(const Face& _f)
151  {
152  faces_.push_back(_f);
153  return faces_.size()-1;
154  }
155 
157  size_t add_face(unsigned int _i0,
158  unsigned int _i1,
159  unsigned int _i2)
160  {
161  faces_.push_back(Face(_i0, _i1, _i2));
162  return faces_.size()-1;
163  }
164 
165 
167  Vec3f& vertex(unsigned int _i)
168  {
169  assert(_i < n_vertices());
170  return vertices_[_i];
171  }
173  const Vec3f& vertex(unsigned int _i) const
174  {
175  assert(_i < n_vertices());
176  return vertices_[_i];
177  }
178 
179 
181  const Face& face(unsigned int _i) const
182  {
183  assert(_i < n_faces());
184  return faces_[_i];
185  }
187  Face& face(unsigned int _i)
188  {
189  assert(_i < n_faces());
190  return faces_[_i];
191  }
192 
193 
195  const Vec3f& normal(unsigned int _i) const
196  {
197  assert(_i < n_normals());
198  return normals_[_i];
199  }
201  Vec3f& normal(unsigned int _i)
202  {
203  assert(_i < n_normals());
204  return normals_[_i];
205  }
206 
207 
209  bool read(const std::string& _filename);
210 
211 
213  void update_face_normals();
214 
215 
216 private:
217 
218  void draw_obj() const;
219  void draw_obj_tex() const;
220 
221  std::vector<Vec3f> vertices_;
222  std::vector<Vec3f> normals_;
223  std::vector<Vec2f> texCoords_;
224  std::vector<Face> faces_;
225 };
226 
227 
228 //=============================================================================
229 } // namespace SceneGraph
230 } // namespace ACG
231 //=============================================================================
232 #endif // ACG_OBJ_NODE_HH
233 //=============================================================================
Vec3f & vertex(unsigned int _i)
get i&#39;th vertex
Definition: OBJNode.hh:167
Namespace providing different geometric functions concerning angles.
size_t n_faces() const
number of faces
Definition: OBJNode.hh:124
const Vec3f & normal(unsigned int _i) const
get i&#39;th normal
Definition: OBJNode.hh:195
Face & face(unsigned int _i)
get i&#39;th face
Definition: OBJNode.hh:187
size_t n_normals() const
number of normals
Definition: OBJNode.hh:126
virtual ~OBJNode()
destructor
Definition: OBJNode.hh:92
Vec3f & normal(unsigned int _i)
get i&#39;th normal
Definition: OBJNode.hh:201
size_t add_face(unsigned int _i0, unsigned int _i1, unsigned int _i2)
add triangle
Definition: OBJNode.hh:157
const Face & face(unsigned int _i) const
get i&#39;th face
Definition: OBJNode.hh:181
size_t n_vertices() const
number of vertices
Definition: OBJNode.hh:122
void clear()
clear the node
Definition: OBJNode.hh:132
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
size_t add_vertex(const Vec3f &_v)
add vertex
Definition: OBJNode.hh:142
size_t n_texcoords() const
number of texcoords
Definition: OBJNode.hh:128
const Vec3f & vertex(unsigned int _i) const
get i&#39;th vertex
Definition: OBJNode.hh:173
OBJNode(BaseNode *_parent=0, const std::string &_name="<OBJNode>")
Default constructor.
Definition: OBJNode.hh:85
size_t add_face(const Face &_f)
add triangle
Definition: OBJNode.hh:150