60 #define ACG_STATUS_NODES_C
66 #include "StatusNodesT.hh"
67 #include "../GL/gl.hh"
73 namespace SceneGraph {
78 template <
class Mesh,
class Mod>
82 const std::string& _name )
83 :
BaseClass(_parent, _name), mesh_(_mesh),
85 bbMin_(FLT_MAX, FLT_MAX, FLT_MAX),
86 bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX),
87 invalidGeometry_(true),
88 vertexIndexInvalid_(true),
89 halfedgeCacheInvalid_(true),
90 edgeIndexInvalid_(true),
91 faceIndexInvalid_(true)
93 this->set_line_width(3);
94 this->set_point_size(5);
101 template <
class Mesh,
class Mod>
106 _bbMin.minimize(bbMin_);
107 _bbMax.maximize(bbMax_);
114 template <
class Mesh,
class Mod>
116 StatusNodeT<Mesh, Mod>::
117 availableDrawModes()
const
129 template <
class Mesh,
class Mod>
134 if (invalidGeometry_) {
135 bbMin_ =
Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
136 bbMax_ =
Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
138 typename Mesh::ConstVertexIter v_it(mesh_.vertices_sbegin()), v_end(mesh_.vertices_end());
140 for (; v_it != v_end; ++v_it) {
141 bbMin_.minimize(mesh_.point(*v_it));
142 bbMax_.maximize(mesh_.point(*v_it));
145 invalidGeometry_ =
false;
151 if (vertexIndexInvalid_ || edgeIndexInvalid_ || halfedgeCacheInvalid_ || faceIndexInvalid_)
156 if (vertexIndexInvalid_) {
158 v_cache_.reserve(mesh_.n_vertices()/4);
160 typename Mesh::ConstVertexIter v_it(mesh_.vertices_sbegin()), v_begin(mesh_.vertices_sbegin()), v_end(mesh_.vertices_end());
161 for (v_it = v_begin; v_it != v_end; ++v_it) {
162 if (this->is_vertex_selected(mesh_, *v_it)) {
163 unsigned int vertexIndex = v_it->idx();
165 v_cache_.push_back(drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vertexIndex) : vertexIndex);
168 std::vector<unsigned int>(v_cache_.begin(), v_cache_.end()).swap(v_cache_);
169 vertexIndexInvalid_ =
false;
173 if (edgeIndexInvalid_) {
176 e_cache_.reserve(mesh_.n_edges()/4);
178 typename Mesh::ConstEdgeIter e_it(mesh_.edges_sbegin()), e_begin(mesh_.edges_sbegin()), e_end(mesh_.edges_end());
179 for (e_it = e_begin; e_it != e_end; ++e_it) {
180 if (this->is_edge_selected(mesh_, *e_it)) {
181 typename Mesh::VertexHandle vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0));
182 unsigned int vidx = vh.idx();
184 e_cache_.push_back(drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vidx) : vidx);
186 vh = mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1));
189 e_cache_.push_back(drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vidx) : vidx);
193 std::vector<unsigned int>(e_cache_.begin(), e_cache_.end()).swap(e_cache_);
194 edgeIndexInvalid_ =
false;
199 if (halfedgeCacheInvalid_) {
202 he_points_.reserve(mesh_.n_halfedges()/4);
204 he_normals_.reserve(he_points_.size());
206 typename Mesh::ConstHalfedgeIter he_it(mesh_.halfedges_sbegin()), he_begin(mesh_.halfedges_sbegin()), he_end(mesh_.halfedges_end());
207 for (he_it = he_begin; he_it != he_end; ++he_it) {
208 if (this->is_halfedge_selected(mesh_, *he_it)) {
210 he_points_.push_back(halfedge_point(*he_it));
211 he_points_.push_back(halfedge_point(mesh_.prev_halfedge_handle(*he_it)));
215 if (!mesh_.is_boundary(*he_it))
216 fh = mesh_.face_handle(*he_it);
218 fh = mesh_.face_handle(mesh_.opposite_halfedge_handle(*he_it));
220 he_normals_.push_back(mesh_.normal(fh));
221 he_normals_.push_back(mesh_.normal(fh));
225 std::vector<Point>(he_points_.begin(), he_points_.end()).swap(he_points_);
226 std::vector<Normal>(he_normals_.begin(), he_normals_.end()).swap(he_normals_);
227 halfedgeCacheInvalid_ =
false;
232 if (faceIndexInvalid_) {
235 fh_cache_.reserve(mesh_.n_faces()/4);
237 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()), f_begin(mesh_.faces_sbegin()), f_end(mesh_.faces_end());
238 for (f_it = f_begin; f_it != f_end; ++f_it)
239 if (this->is_face_selected(mesh_, *f_it))
240 fh_cache_.push_back(*f_it);
242 std::vector<FaceHandle>(fh_cache_.begin(), fh_cache_.end()).swap(fh_cache_);
246 f_cache_.resize(fh_cache_.size()*3);
247 for (
size_t i = 0; i < fh_cache_.size(); ++i)
250 unsigned int vidx = fv_it->idx();
251 f_cache_[i*3] = (drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vidx) : vidx);
255 f_cache_[i*3+1] = (drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vidx) : vidx);
259 f_cache_[i*3+2] = (drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vidx) : vidx);
265 poly_cache_.reserve(fh_cache_.size()*4);
267 typename std::vector<FaceHandle>::const_iterator fh_it(fh_cache_.begin()), fh_end(fh_cache_.end());
268 for (fh_it = fh_cache_.begin(); fh_it != fh_end; ++fh_it) {
269 typename Mesh::CFVIter fv_it = mesh_.cfv_iter(*fh_it);
272 unsigned int v0 = fv_it->idx();
276 unsigned int vPrev = fv_it->idx();
280 for (; fv_it.is_valid(); ++fv_it) {
281 poly_cache_.push_back(drawMesh_ ? drawMesh_->mapVertexToVBOIndex(v0) : v0);
282 poly_cache_.push_back(drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vPrev) : vPrev);
284 vPrev = fv_it->idx();
285 poly_cache_.push_back(drawMesh_ ? drawMesh_->mapVertexToVBOIndex(vPrev) : vPrev);
289 std::vector<unsigned int>(poly_cache_.begin(), poly_cache_.end()).swap(poly_cache_);
293 faceIndexInvalid_ =
false;
302 template <
class Mesh,
class Mod>
332 for (
unsigned int i = 0; i < _drawMode.
getNumLayers(); ++i)
361 drawMesh_->getVertexDeclaration()->activateFixedFunction();
373 if (shaded && mesh_.has_vertex_normals()) {
393 if (shaded && !smooth)
400 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
402 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
405 glPushAttrib( GL_ENABLE_BIT );
409 glPolygonOffset(0.001f, 0.0f);
435 template <
class Mesh,
class Mod>
437 StatusNodeT<Mesh, Mod>::
440 if ( !v_cache_.empty() )
441 glDrawElements(GL_POINTS,
442 int( v_cache_.size() ),
451 template <
class Mesh,
class Mod>
453 StatusNodeT<Mesh, Mod>::
456 if ( !e_cache_.empty() )
457 glDrawElements( GL_LINES,
458 int(e_cache_.size()),
467 template <
class Mesh,
class Mod>
469 StatusNodeT<Mesh, Mod>::
471 if ( !he_points_.empty()) {
476 if ( !he_normals_.empty())
479 glDrawArrays(GL_LINES, 0,
int(he_points_.size() ) );
488 template <
class Mesh,
class Mod>
490 StatusNodeT<Mesh, Mod>::
491 draw_faces(
bool _per_vertex)
493 typename std::vector<FaceHandle>::const_iterator fh_it(fh_cache_.begin()),
494 fh_end(fh_cache_.end());
495 typename Mesh::CFVIter fv_it;
502 glBegin(GL_TRIANGLES);
503 for (; fh_it!=fh_end; ++fh_it) {
505 glVertex(mesh_.point(*(fv_it=mesh_.cfv_iter(*fh_it))));
513 if ( !f_cache_.empty() )
514 glDrawElements(GL_TRIANGLES,
515 int(f_cache_.size()),
525 for (; fh_it!=fh_end; ++fh_it) {
528 for (fv_it=mesh_.cfv_iter(*fh_it); fv_it.is_valid(); ++fv_it)
535 for (; fh_it!=fh_end; ++fh_it) {
537 for (fv_it=mesh_.cfv_iter(*fh_it); fv_it.is_valid(); ++fv_it) {
541 glArrayElement(drawMesh_->mapVertexToVBOIndex(fv_it->idx()));
543 glArrayElement(fv_it->idx());
556 template <
class Mesh,
class Mod>
558 StatusNodeT<Mesh, Mod>::
559 halfedge_point(
const HalfedgeHandle _heh)
561 typename Mesh::Point p = mesh_.point(mesh_.to_vertex_handle (_heh));
562 typename Mesh::Point pp = mesh_.point(mesh_.from_vertex_handle(_heh));
563 typename Mesh::Point pn = mesh_.point(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(_heh)));
567 if( !mesh_.is_boundary(_heh))
568 fn = mesh_.normal(mesh_.face_handle(_heh));
570 fn = mesh_.normal(mesh_.face_handle(mesh_.opposite_halfedge_handle(_heh)));
572 typename Mesh::Point upd = ((fn%(pn-p)).normalize() + (fn%(p-pp)).normalize()).normalize();
574 upd *= ((pn-p).norm()+(p-pp).norm())*0.08;
588 template <
class Mesh,
class Mod>
612 ro.debugName =
"StatusNode";
621 pointVertexDecl_.clear();
624 if (shaded && mesh_.has_vertex_normals())
627 pointVertexDecl_.setVertexStride(24);
641 ro.
vertexDecl = drawMesh_->getVertexDeclaration();
647 if (points && !v_cache_.empty())
651 geomTemplate +=
"PointSize/geometry.tpl";
654 fragTemplate +=
"PointSize/fragment.tpl";
656 ro.
shaderDesc.geometryTemplateFile = geomTemplate;
657 ro.
shaderDesc.fragmentTemplateFile = fragTemplate;
662 ro.glDrawElements(GL_POINTS, static_cast<GLsizei>(v_cache_.size()), GL_UNSIGNED_INT, &v_cache_[0]);
670 if (edges && !e_cache_.empty())
674 geomTemplate +=
"Wireframe/geom_line2quad.tpl";
676 ro.
shaderDesc.geometryTemplateFile = geomTemplate;
681 ro.glDrawElements(GL_LINES, static_cast<GLsizei>(e_cache_.size()), GL_UNSIGNED_INT, &e_cache_[0]);
693 ro.glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(f_cache_.size()), GL_UNSIGNED_INT, &f_cache_[0]);
696 else if (!poly_cache_.empty())
698 ro.glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(poly_cache_.size()), GL_UNSIGNED_INT, &poly_cache_[0]);
705 if (halfedges && !he_points_.empty())
709 halfedgeVertexDecl_.clear();
715 ro.glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(he_points_.size()) );
725 template <
class Mesh,
class Mod>
727 invalidGeometry_ =
true;
731 template <
class Mesh,
class Mod>
733 vertexIndexInvalid_ =
true;
734 halfedgeCacheInvalid_ =
true;
735 edgeIndexInvalid_ =
true;
736 faceIndexInvalid_ =
true;
740 template <
class Mesh,
class Mod>
742 vertexIndexInvalid_ =
true;
743 halfedgeCacheInvalid_ =
true;
744 edgeIndexInvalid_ =
true;
745 faceIndexInvalid_ =
true;
749 template <
class Mesh,
class Mod>
751 drawMesh_ = _drawmesh;
void setDrawMesh(DrawMeshT< Mesh > *_drawmesh)
Set drawmesh.
VectorT< float, 2 > Vec2f
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Namespace providing different geometric functions concerning angles.
static void enable(GLenum _cap)
replaces glEnable, but supports locking
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
static void disable(GLenum _cap)
replaces glDisable, but supports locking
static bool is_trimesh()
Determine whether this is a PolyMeshT or TriMeshT ( This function does not check the per face vertex ...
Interface class between scenegraph and renderer.
float point_size() const
get point size
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
void updateGeometry()
set geometry invalid, topology and selection is kept
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Kernel::Point Point
Coordinate type.
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
VectorT< double, 3 > Vec3d
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
size_t getNumLayers() const
returns the layer count
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
int viewport_width() const
get viewport width
void updateSelection()
set selection invalid (Only selection changed, rest is kept)
DrawModeProperties stores a set of properties that defines, how to render an object.
ACG::SceneGraph::Material & material()
Get material object reference.
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
DrawMode POINTS
draw unlighted points using the default base color
void updateTopology()
set topology invalid (updates everything)
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glNormalPointer, supports locking
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
DrawMode WIREFRAME
draw wireframe
StatusNodeT(const Mesh &_mesh, BaseNode *_parent=0, const std::string &_name="<StatusNode>")
constructor
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const class Material *_mat)
support for shader-pipeline
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
float line_width() const
get line width
bool lighting() const
Is lighting enabled?
int priority
Priority to allow sorting of objects.
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
static QString getShaderDir()
int viewport_height() const
get viewport height