00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define ACG_STATUS_NODES_C
00054
00055
00056
00057
00058
00059 #include "StatusNodesT.hh"
00060 #include "../GL/gl.hh"
00061
00062
00063
00064
00065
00066 namespace ACG {
00067 namespace SceneGraph {
00068
00069
00070
00071
00072
00073 template <class Mesh, class Mod>
00074 StatusNodeT<Mesh, Mod>::
00075 StatusNodeT( const Mesh& _mesh,
00076 BaseNode* _parent,
00077 const std::string& _name )
00078 : MaterialNode(_parent, _name), mesh_(_mesh),
00079 bbMin_(FLT_MAX, FLT_MAX, FLT_MAX),
00080 bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX)
00081 {
00082 depthFunc(GL_LEQUAL);
00083
00084 set_line_width(3);
00085 set_point_size(5);
00086 }
00087
00088
00089
00090
00091
00092 template <class Mesh, class Mod>
00093 void
00094 StatusNodeT<Mesh, Mod>::
00095 boundingBox(Vec3f& _bbMin, Vec3f& _bbMax)
00096 {
00097 _bbMin.minimize(bbMin_);
00098 _bbMax.maximize(bbMax_);
00099 }
00100
00101
00102
00103
00104
00105 template <class Mesh, class Mod>
00106 unsigned int
00107 StatusNodeT<Mesh, Mod>::
00108 availableDrawModes() const
00109 {
00110 return (DrawModes::POINTS |
00111 DrawModes::WIREFRAME |
00112 DrawModes::SOLID_FLAT_SHADED);
00113 }
00114
00115
00116
00117
00118
00119 template <class Mesh, class Mod>
00120 void
00121 StatusNodeT<Mesh, Mod>::
00122 update_cache()
00123 {
00124 bbMin_ = Vec3f(FLT_MAX, FLT_MAX, FLT_MAX);
00125 bbMax_ = Vec3f(-FLT_MAX, -FLT_MAX, -FLT_MAX);
00126
00127 typename Mesh::ConstVertexIter v_it(mesh_.vertices_sbegin()),
00128 v_end(mesh_.vertices_end());
00129
00130 v_cache_.clear();
00131 for (; v_it!=v_end; ++v_it)
00132 {
00133 if (Mod::is_vertex_selected(mesh_, v_it.handle()))
00134 {
00135 v_cache_.push_back(v_it.handle().idx());
00136 }
00137 bbMin_.minimize((Vec3f)mesh_.point(v_it));
00138 bbMax_.maximize((Vec3f)mesh_.point(v_it));
00139 }
00140
00141
00142
00143 typename Mesh::ConstEdgeIter e_it(mesh_.edges_sbegin()),
00144 e_end(mesh_.edges_end());
00145 typename Mesh::VertexHandle vh;
00146
00147 e_cache_.clear();
00148 for (; e_it!=e_end; ++e_it)
00149 {
00150 if (Mod::is_edge_selected(mesh_, e_it))
00151 {
00152 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0));
00153 e_cache_.push_back(vh.idx());
00154 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1));
00155 e_cache_.push_back(vh.idx());
00156 }
00157 }
00158
00159
00160
00161 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
00162 f_end(mesh_.faces_end());
00163 typename Mesh::ConstFaceVertexIter fv_it;
00164
00165 f_cache_.clear();
00166 fh_cache_.clear();
00167 for (; f_it!=f_end; ++f_it)
00168 {
00169 if (Mod::is_face_selected(mesh_, f_it))
00170 {
00171 fv_it = mesh_.cfv_iter(f_it);
00172 f_cache_.push_back(fv_it.handle().idx()); ++fv_it;
00173 f_cache_.push_back(fv_it.handle().idx()); ++fv_it;
00174 f_cache_.push_back(fv_it.handle().idx());
00175 fh_cache_.push_back(f_it);
00176 }
00177 }
00178 }
00179
00180
00181
00182
00183
00184 template <class Mesh, class Mod>
00185 void
00186 StatusNodeT<Mesh, Mod>::
00187 draw(GLState& , unsigned int _drawMode)
00188 {
00189 bool shaded = (_drawMode & ( DrawModes::SOLID_FLAT_SHADED |
00190 DrawModes::SOLID_SMOOTH_SHADED |
00191 DrawModes::SOLID_PHONG_SHADED |
00192 DrawModes::SOLID_TEXTURED_SHADED |
00193 DrawModes::POINTS_SHADED ));
00194
00195 bool wires = (_drawMode & ( DrawModes::WIREFRAME |
00196 DrawModes::HIDDENLINE ));
00197
00198 bool smooth = (_drawMode & ( DrawModes::SOLID_SMOOTH_SHADED |
00199 DrawModes::SOLID_PHONG_SHADED |
00200 DrawModes::SOLID_TEXTURED_SHADED ));
00201
00202 bool points = ((drawMode() == DrawModes::DEFAULT) |
00203 (_drawMode & DrawModes::POINTS));
00204
00205 bool edges = ((drawMode() == DrawModes::DEFAULT) |
00206 (_drawMode & DrawModes::WIREFRAME));
00207
00208 bool faces = ((drawMode() == DrawModes::DEFAULT) |
00209 (_drawMode & DrawModes::SOLID_FLAT_SHADED));
00210
00211
00212 glDepthFunc(depthFunc());
00213
00214 if (shaded) glEnable(GL_LIGHTING);
00215 else glDisable(GL_LIGHTING);
00216
00217 if (smooth) glShadeModel(GL_SMOOTH);
00218 else glShadeModel(GL_FLAT);
00219
00220
00221 if (shaded && mesh_.has_vertex_normals())
00222 {
00223 glEnableClientState(GL_NORMAL_ARRAY);
00224 glNormalPointer(mesh_.vertex_normals());
00225 }
00226
00227
00228 glEnableClientState(GL_VERTEX_ARRAY);
00229 glVertexPointer(mesh_.points());
00230
00231
00232
00233
00234 if (points)
00235 draw_points();
00236
00237
00238
00239 if (edges)
00240 draw_edges();
00241
00242
00243 if (shaded && !smooth)
00244 glDisableClientState(GL_NORMAL_ARRAY);
00245
00246
00247
00248 if (faces)
00249 {
00250 if (wires)
00251 {
00252 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00253 draw_faces(smooth);
00254 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00255 }
00256 else
00257 {
00258 glDepthRange(0.01, 1.0);
00259 draw_faces(smooth);
00260 glDepthRange(0.0, 1.0);
00261 }
00262 }
00263
00264 glDisableClientState(GL_NORMAL_ARRAY);
00265 glDisableClientState(GL_VERTEX_ARRAY);
00266
00267 glDepthFunc(GL_LESS);
00268 }
00269
00270
00271
00272
00273
00274 template <class Mesh, class Mod>
00275 void
00276 StatusNodeT<Mesh, Mod>::
00277 draw_points()
00278 {
00279
00280 if ( !v_cache_.empty() )
00281 glDrawElements(GL_POINTS,
00282 v_cache_.size(),
00283 GL_UNSIGNED_INT,
00284 &v_cache_[0]);
00285 }
00286
00287
00288
00289
00290
00291 template <class Mesh, class Mod>
00292 void
00293 StatusNodeT<Mesh, Mod>::
00294 draw_edges()
00295 {
00296 if ( !e_cache_.empty() )
00297 glDrawElements(GL_LINES,
00298 e_cache_.size(),
00299 GL_UNSIGNED_INT,
00300 &e_cache_[0]);
00301 }
00302
00303
00304
00305
00306
00307 template <class Mesh, class Mod>
00308 void
00309 StatusNodeT<Mesh, Mod>::
00310 draw_faces(bool _per_vertex)
00311 {
00312 typename std::vector<FaceHandle>::const_iterator fh_it(fh_cache_.begin()),
00313 fh_end(fh_cache_.end());
00314 typename Mesh::CFVIter fv_it;
00315
00316
00317
00318 if (mesh_.is_trimesh()) {
00319
00320 if (!_per_vertex) {
00321 glBegin(GL_TRIANGLES);
00322 for (; fh_it!=fh_end; ++fh_it) {
00323 glNormal(mesh_.normal(*fh_it));
00324 glVertex(mesh_.point(fv_it=mesh_.cfv_iter(*fh_it)));
00325 glVertex(mesh_.point(++fv_it));
00326 glVertex(mesh_.point(++fv_it));
00327 }
00328
00329 glEnd();
00330 } else {
00331 if ( !f_cache_.empty() )
00332 glDrawElements(GL_TRIANGLES,
00333 f_cache_.size(),
00334 GL_UNSIGNED_INT,
00335 &f_cache_[0]);
00336 }
00337
00338
00339 } else {
00340 if (!_per_vertex) {
00341 for (; fh_it!=fh_end; ++fh_it) {
00342 glBegin(GL_POLYGON);
00343 glNormal(mesh_.normal(*fh_it));
00344 for (fv_it=mesh_.cfv_iter(*fh_it); fv_it; ++fv_it)
00345 glVertex(mesh_.point(fv_it));
00346 glEnd();
00347 }
00348 } else {
00349 for (; fh_it!=fh_end; ++fh_it) {
00350 glBegin(GL_POLYGON);
00351 for (fv_it=mesh_.cfv_iter(*fh_it); fv_it; ++fv_it) {
00352 glNormal(mesh_.normal(fv_it));
00353 glArrayElement(fv_it.handle().idx());
00354 }
00355 glEnd();
00356 }
00357 }
00358 }
00359 }
00360
00361
00362
00363 }
00364 }
00365