Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $Author$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51
52 //=============================================================================
53 //
54 // CLASS FastMesh
55 //
56 //=============================================================================
57
58
59 #ifndef ACG_OBJ_NODE_HH
60 #define ACG_OBJ_NODE_HH
61
62
63 //== INCLUDES =================================================================
64
65 #include "BaseNode.hh"
66 #include "DrawModes.hh"
67 #include "../Math/VectorT.hh"
68 #include <string>
69 #include <vector>
70
71
72 //== FORWARD DECLARATION ======================================================
73
74
75 //== NAMESPACES ===============================================================
76
77
78 namespace ACG {
79 namespace SceneGraph {
80
81
82 //== CLASS DEFINITION =========================================================
83
84
85 class ACGDLLEXPORT OBJNode : public BaseNode
86 {
87
88 public:
89
91 OBJNode( BaseNode* _parent=0,
92 std::string _name="<OBJNode>" )
93 : BaseNode(_parent, _name)
94 {}
95
96
98 virtual ~OBJNode() {}
99
100
101 ACG_CLASSNAME(OBJNode);
102
103
105 DrawModes::DrawMode availableDrawModes() const;
106
108 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
109
111 void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
112
114 void pick(GLState& _state, PickTarget _target);
115
116
117 struct Face
118 {
119 Face(int _i0=-1, int _i1=-1, int _i2=-1,
120 int _t0=-1, int _t1=-1, int _t2=-1)
121 : i0(_i0), i1(_i1), i2(_i2),
122 t0(_t0), t1(_t1), t2(_t2) {}
123 int i0, i1, i2, t0, t1, t2;
124 };
125
126
128 size_t n_vertices() const { return vertices_.size(); }
130 size_t n_faces() const { return faces_.size(); }
132 size_t n_normals() const { return normals_.size(); }
134 size_t n_texcoords() const { return texCoords_.size(); }
135
136
138 void clear()
139 {
140 vertices_.clear();
141 faces_.clear();
142 normals_.clear();
143 texCoords_.clear();
144 }
145
146
148 size_t add_vertex(const Vec3f& _v)
149 {
150 vertices_.push_back(_v);
151 return vertices_.size()-1;
152 }
153
154
156 size_t add_face(const Face& _f)
157 {
158 faces_.push_back(_f);
159 return faces_.size()-1;
160 }
161
163 size_t add_face(unsigned int _i0,
164 unsigned int _i1,
165 unsigned int _i2)
166 {
167 faces_.push_back(Face(_i0, _i1, _i2));
168 return faces_.size()-1;
169 }
170
171
173 Vec3f& vertex(unsigned int _i)
174 {
175 assert(_i < n_vertices());
176 return vertices_[_i];
177 }
179 const Vec3f& vertex(unsigned int _i) const
180 {
181 assert(_i < n_vertices());
182 return vertices_[_i];
183 }
184
185
187 const Face& face(unsigned int _i) const
188 {
189 assert(_i < n_faces());
190 return faces_[_i];
191 }
193 Face& face(unsigned int _i)
194 {
195 assert(_i < n_faces());
196 return faces_[_i];
197 }
198
199
201 const Vec3f& normal(unsigned int _i) const
202 {
203 assert(_i < n_normals());
204 return normals_[_i];
205 }
207 Vec3f& normal(unsigned int _i)
208 {
209 assert(_i < n_normals());
210 return normals_[_i];
211 }
212
213
215 bool read(const std::string& _filename);
216
217
219 void update_face_normals();
220
221
222 private:
223
224 void draw_obj() const;
225 void draw_obj_tex() const;
226
227 std::vector<Vec3f> vertices_;
228 std::vector<Vec3f> normals_;
229 std::vector<Vec2f> texCoords_;
230 std::vector<Face> faces_;
231 };
232
233
234 //=============================================================================
235 } // namespace SceneGraph
236 } // namespace ACG
237 //=============================================================================
238 #endif // ACG_OBJ_NODE_HH
239 //=============================================================================
ACG::SceneGraph::OBJNode::vertex
const Vec3f & vertex(unsigned int _i) const
get i'th vertex
Definition: OBJNode.hh:179
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
ACG::SceneGraph::OBJNode::vertex
Vec3f & vertex(unsigned int _i)
get i'th vertex
Definition: OBJNode.hh:173
ACG::SceneGraph::OBJNode::face
Face & face(unsigned int _i)
get i'th face
Definition: OBJNode.hh:193
ACG::SceneGraph::OBJNode::OBJNode
OBJNode(BaseNode *_parent=0, std::string _name="<OBJNode>")
Default constructor.
Definition: OBJNode.hh:91
ACG::GLState
Definition: GLState.hh:220
ACG::SceneGraph::OBJNode
Definition: OBJNode.hh:85
ACG::SceneGraph::OBJNode::normal
Vec3f & normal(unsigned int _i)
get i'th normal
Definition: OBJNode.hh:207
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:294
ACG::SceneGraph::OBJNode::add_vertex
size_t add_vertex(const Vec3f &_v)
add vertex
Definition: OBJNode.hh:148
ACG::SceneGraph::OBJNode::n_texcoords
size_t n_texcoords() const
number of texcoords
Definition: OBJNode.hh:134
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::OBJNode::clear
void clear()
clear the node
Definition: OBJNode.hh:138
ACG::SceneGraph::OBJNode::n_faces
size_t n_faces() const
number of faces
Definition: OBJNode.hh:130
ACG::SceneGraph::OBJNode::Face
Definition: OBJNode.hh:117
ACG::SceneGraph::OBJNode::n_vertices
size_t n_vertices() const
number of vertices
Definition: OBJNode.hh:128
ACG::SceneGraph::OBJNode::n_normals
size_t n_normals() const
number of normals
Definition: OBJNode.hh:132
ACG::SceneGraph::OBJNode::face
const Face & face(unsigned int _i) const
get i'th face
Definition: OBJNode.hh:187
ACG::SceneGraph::OBJNode::~OBJNode
virtual ~OBJNode()
destructor
Definition: OBJNode.hh:98
ACG::SceneGraph::OBJNode::add_face
size_t add_face(const Face &_f)
add triangle
Definition: OBJNode.hh:156
ACG::SceneGraph::OBJNode::normal
const Vec3f & normal(unsigned int _i) const
get i'th normal
Definition: OBJNode.hh:201
ACG::SceneGraph::OBJNode::add_face
size_t add_face(unsigned int _i0, unsigned int _i1, unsigned int _i2)
add triangle
Definition: OBJNode.hh:163