59 #ifndef ACG_DRAW_MESH_HH
60 #define ACG_DRAW_MESH_HH
67 #include <OpenMesh/Core/Utils/Property.hh>
68 #include <OpenMesh/Core/IO/MeshIO.hh>
70 #include <ACG/GL/globjects.hh>
71 #include <ACG/GL/GLState.hh>
72 #include <ACG/GL/IRenderer.hh>
73 #include <ACG/GL/MeshCompiler.hh>
74 #include <ACG/ShaderUtils/GLSLShader.hh>
76 #include <ACG/Config/ACGDefines.hh>
100 void bindPickVertexIbo();
102 void createIndexBuffer();
103 void fillLineBuffer(
size_t n_edges,
void *data);
104 void fillVertexBuffer();
105 void fillInvVertexMap(
size_t n_vertices,
void *data);
108 unsigned int getNumTris()
const {
return numTris_; }
109 unsigned int getNumVerts()
const {
return numVerts_; }
114 unsigned int getNumSubsets()
const {
return meshComp_->
getNumSubsets();}
130 size_t numTris_, numVerts_;
171 template <
class Mesh>
179 unsigned long startIndex;
180 unsigned long numTris;
183 enum REBUILD_TYPE {REBUILD_NONE = 0, REBUILD_FULL = 1, REBUILD_GEOMETRY = 2, REBUILD_TOPOLOGY = 4, REBUILD_TEXTURES = 8};
240 void draw(std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
250 void addTriRenderObjects(IRenderer* _renderer,
const RenderObject* _baseObj, std::map< int, GLuint>* _textureMap,
bool _nonindexed =
false);
348 PROPERTY_SOURCE_VERTEX = 0,
349 PROPERTY_SOURCE_HALFEDGE,
350 PROPERTY_SOURCE_FACE,
358 void addVertexElement(
const std::string& _propertyName, PropertySource _source = PROPERTY_SOURCE_VERTEX );
390 const typename Mesh::HalfedgeHandle _hh,
391 const typename Mesh::FaceHandle _fh);
403 unsigned int getFaceColor(
const typename Mesh::FaceHandle _fh);
449 std::cerr <<
"Illegal request to pickVertexColorBuffer when buffer is empty!" << std::endl;
466 std::cerr <<
"Illegal request to pickVertexBuffer when buffer is empty!" << std::endl;
491 #ifdef GL_ARB_texture_buffer_object
494 if ( pickVertexMapTBO_.is_valid() )
495 return &pickVertexMapTBO_;
497 std::cerr <<
"Illegal request to pickVertexMap_opt when buffer is empty!" << std::endl;
502 #endif // GL_ARB_texture_buffer_object
512 #ifdef GL_ARB_texture_buffer_object
515 #endif // GL_ARB_texture_buffer_object
524 int pickVertexMethod_;
548 if ( !pickEdgeBuf_.empty() )
549 return &(pickEdgeBuf_)[0];
551 std::cerr <<
"Illegal request to pickEdgeColorBuffer when buffer is empty!" << std::endl;
578 std::vector< ACG::Vec4uc > pickEdgeBuf_;
601 if ( !pickFaceColBuf_.empty() )
602 return &(pickFaceColBuf_)[0];
604 std::cerr <<
"Illegal request to pickFaceColorBuffer when buffer is empty!" << std::endl;
618 if ( !pickFaceVertexBuf_.empty() )
619 return &(pickFaceVertexBuf_)[0];
621 std::cerr <<
"Illegal request to pickFaceVertexBuffer when buffer is empty!" << std::endl;
645 #ifdef GL_ARB_texture_buffer_object
648 if ( pickFaceTriToFaceMapTBO_.is_valid() )
649 return &pickFaceTriToFaceMapTBO_;
651 std::cerr <<
"Illegal request to pickFaceTriangleMap_opt when buffer is empty!" << std::endl;
660 std::vector< ACG::Vec3f > pickFaceVertexBuf_;
661 std::vector< ACG::Vec4uc > pickFaceColBuf_;
663 #ifdef GL_ARB_texture_buffer_object
665 TextureBuffer pickFaceTriToFaceMapTBO_;
666 #endif // GL_ARB_texture_buffer_object
690 if ( !pickAnyFaceColBuf_.empty() )
691 return &(pickAnyFaceColBuf_)[0];
693 std::cerr <<
"Illegal request to pickAnyFaceColorBuffer when buffer is empty!" << std::endl;
707 if ( !pickAnyEdgeColBuf_.empty() )
708 return &(pickAnyEdgeColBuf_)[0];
710 std::cerr <<
"Illegal request to pickAnyEdgeColorBuffer when buffer is empty!" << std::endl;
724 if ( !pickAnyVertexColBuf_.empty() )
725 return &(pickAnyVertexColBuf_)[0];
727 std::cerr <<
"Illegal request to pickAnyVertexColorBuffer when buffer is empty!" << std::endl;
752 std::vector< ACG::Vec4uc > pickAnyFaceColBuf_;
753 std::vector< ACG::Vec4uc > pickAnyEdgeColBuf_;
754 std::vector< ACG::Vec4uc > pickAnyVertexColBuf_;
771 unsigned int countTris(
unsigned int* _pOutMaxPolyVerts = 0,
unsigned int* _pOutNumIndices = 0);
818 void dumpObj(
const char* _filename)
const;
877 PropertySource source_;
932 void writeVertexElement(
void* _dstBuf,
unsigned int _vertex,
unsigned int _stride,
unsigned int _elementOffset,
unsigned int _elementSize,
const void* _elementData);
934 void writePosition(
unsigned int _vertex,
const ACG::Vec3d& _p);
936 void writeNormal(
unsigned int _vertex,
const ACG::Vec3d& _n);
938 void writeTexcoord(
unsigned int _vertex,
const ACG::Vec2f& _uv);
940 void writeColor(
unsigned int _vertex,
unsigned int _color);
979 GeometryBuffer vboFull_;
1027 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1062 int updatePerEdgeBuffers_;
1063 std::vector<ACG::Vec3f> perEdgeVertexBuf_;
1064 std::vector<ACG::Vec4f> perEdgeColorBuf_;
1066 int updatePerHalfedgeBuffers_;
1067 std::vector<ACG::Vec3f> perHalfedgeVertexBuf_;
1068 std::vector<ACG::Vec4f> perHalfedgeColorBuf_;
1077 template<
typename Mesh::Normal (DrawMeshT::*NormalLookup)(
typename Mesh::FaceHandle)>
1078 typename Mesh::Point
halfedge_point(
const typename Mesh::HalfedgeHandle _heh);
1081 typename Mesh::Normal cachedNormalLookup(
typename Mesh::FaceHandle fh) {
1082 return mesh_.normal(fh);
1086 typename Mesh::Normal computedTriMeshNormal(
typename Mesh::FaceHandle fh) {
1087 typename Mesh::FVIter fv_iter = mesh_.fv_begin(fh);
1088 const typename Mesh::Point p1 = mesh_.point(*fv_iter);
1089 const typename Mesh::Point p2 = mesh_.point(*(++fv_iter));
1090 const typename Mesh::Point p3 = mesh_.point(*(++fv_iter));
1091 return ( p1 + p2 + p3 ) / 3.0;
1095 typename Mesh::Normal computedNormal(
typename Mesh::FaceHandle fh) {
1096 unsigned int count = 0;
1098 for (
typename Mesh::FVIter fv_it = mesh_.fv_begin(fh), fv_end = mesh_.fv_end(fh); fv_it != fv_end; ++fv_it) {
1099 normal += mesh_.point(*fv_it);
1106 typename Mesh::HalfedgeHandle mapToHalfedgeHandle(
int _vertexId);
1114 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_DRAW_MESH_TCC)
1115 #define ACG_DRAW_MESH_TEMPLATES
1116 #include "DrawMeshT.cc"
1119 #endif // ACG_DRAW_MESH_HH defined
const void * propDataPtr_
memory address of property data
GLuint pickVertexIBO_
map from openmesh vertex to vbo vertex id
void updatePickingFaces_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
const std::string & getTextureIndexPropertyName() const
get the name of the texture index property
std::vector< VertexProperty > additionalElements_
additional optional elements
const VertexDeclaration * getHalfedgeVertexDeclaration() const
getter for vertex declarations
int perFaceTextureCoordinateAvailable()
Check if per Face Texture coordinates are available.
Mesh & mesh_
OpenMesh object to be rendered.
Namespace providing different geometric functions concerning angles.
int getNumSubsets() const
Get the number of subsets.
std::vector< ACG::Vec3f > pickVertBuf_
The vertex buffer used for vertex picking.
void addPointRenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
render vertices only, deferred draw call
void createVBO()
stores the vertex buffer on the gpu
void updateFullVBO()
update the full mesh vbo
MeshCompiler * getMeshCompiler()
get mesh compiler used to create the draw mesh
void addLineRenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
render the mesh in wireframe mode, deferred draw call
void drawPickingAny_opt(const GLMatrixf &_mvp, int _pickOffset)
Optimized rendering of any picking ids with a shader.
unsigned int countTris(unsigned int *_pOutMaxPolyVerts=0, unsigned int *_pOutNumIndices=0)
Number of triangles after triangulation of the mesh.
std::string vertexShaderInputName_
input name id in vertex shader
GLenum indexType_
support for 2 and 4 byte unsigned integers
void dumpObj(const char *_filename) const
dump current vertex/index buffer to wavefront obj
void updatePickingEdges(ACG::GLState &_state, uint _offset=0)
Update color picking array for edges.
void rebuild()
draw_mesh updater
ACG::Vec4uc * pickAnyVertexColorBuffer()
get a pointer to the any picking color buffer
ACG::Vec4uc * pickAnyFaceColorBuffer()
get a pointer to the any picking color buffer
void updatePickingEdges_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
unsigned int getVertexColor(const typename Mesh::VertexHandle _vh)
return a vertex color from mesh
void bindBuffers()
eventually rebuilds buffers used for rendering and binds index and vertex buffer
VertexDeclaration * vertexDeclEdgeCol_
vertex buffer layout declaration with per edge colors
Kernel::Point Point
Coordinate type.
void invalidateFullVBO()
the mesh has been changed
void drawVertices()
render vertices only
VertexDeclaration * vertexDeclHalfedgePos_
vertex buffer layout declaration with halfedge positions only
ACG::Vec3f * pickVertexBuffer()
get a pointer to the per vertex picking vertex buffer
void updatePickingVertices(ACG::GLState &_state, uint _offset=0)
int bVBOinFlatMode_
normals in VBO currently in flat / smooth mode
void updateTextures()
request an update for the textures
void updateTopology()
request an update for the mesh topology
GLuint lineIBO_
index buffer used in Wireframe / Hiddenline mode
std::string name_
property name in openmesh
Description of one vertex element.
int curVBOColorMode_
Color Mode of vbo.
int textureMode_
per vertex / halfedge texture mode toggle: 0: per vertex, 1: per halfedge
std::string textureIndexPropertyName_
Property for the per face texture index.
const void * testMeshPropertyTypeT(const OpenMesh::BaseProperty *_prop, unsigned int *_outSize) const
test mesh property for type T
const VertexDeclaration * getHalfedgeColoredVertexDeclaration() const
getter for vertex declarations
void draw(std::map< int, GLuint > *_textureMap, bool _nonindexed=false)
binds index and vertex buffer and executes draw calls
Mesh::Point halfedge_point(const typename Mesh::HalfedgeHandle _heh)
compute halfedge point compute visualization point for halfedge (shifted to interior of face) ...
const VertexDeclaration * getEdgeColoredVertexDeclaration() const
getter for vertex declarations
int colorMode_
Color Mode: 0: none, 1: per vertex, else: per face.
bool scanVertexShaderForInput(const std::string &_vertexShaderFile)
Scan vertex layout from vertex shader.
void drawPickingFaces_opt(const GLMatrixf &_mvp, int _pickOffset)
Optimized rendering of face picking ids with a shader.
GLuint pickVertexIBO_opt()
get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
void updatePerEdgeBuffers()
Update all per edge drawing buffers.
void bindBuffersToRenderObject(RenderObject *_obj)
eventually rebuilds buffers used for rendering and binds index and vertex buffer
void createIBO()
stores the index buffer on the gpu
GLuint getIBO()
get opengl index buffer id
int halfedgeNormalMode_
per vertex / halfedge normals mode toggle: 0: per vertex, 1: per halfedge
void createVertexDeclaration()
creates all vertex declarations needed for deferred draw call renderer
VertexDeclaration * getVertexDeclaration()
get vertex declaration of the current vbo layout
ACG::Vec3f * pickFaceVertexBuffer()
get a pointer to the per vertex picking color buffer
ACG::Vec3f * perHalfedgeVertexBuffer()
get a pointer to the per edge vertex buffer
unsigned int getFaceColor(const typename Mesh::FaceHandle _fh)
return a face color from mesh
void addTriRenderObjects(IRenderer *_renderer, const RenderObject *_baseObj, std::map< int, GLuint > *_textureMap, bool _nonindexed=false)
adds RenderObjects to a deferred draw call renderer
VertexDeclaration * vertexDecl_
vertex buffer layout declaration with per vertex colors
void updatePickingAny(ACG::GLState &_state)
Call this function to update the color picking array.
unsigned int * invVertexMap_
ACG::Vec4f * perHalfedgeColorBuffer()
get a pointer to the per edge color buffer
void updatePickingAny_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
unsigned int rebuild_
hint on what to rebuild
int declElementID_
element id in vertex declaration
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer
GLSL::Program * pickFaceShader_
optimized face picking shader
int bVBOinHalfedgeTexMode_
texcoords in VBO currently in per vertex / halfedge mode toggle
bool supportsPickingEdges_opt()
Check if optimized face picking is supported.
void setTextureIndexPropertyName(std::string _indexPropertyName)
set the name of the property used for texture index specification
void unbindBuffers()
disables vertex, normal, texcoord and color pointers in OpenGL
void readVertexFromVBO(unsigned int _vertex, void *_dst)
Read one vertex from the rendering vbo.
void invalidatePerEdgeBuffers()
Update of the buffers.
void updateFull()
request a full rebuild of the mesh
void updateEdgeHalfedgeVertexDeclarations()
updates per edge and halfedge vertex declarations
void updatePickingFaces(ACG::GLState &_state)
Update color picking array for faces.
unsigned int * indices_
final index buffer used for rendering
unsigned int getNumTextures()
returns the number of used textured of this mesh
unsigned int getMemoryUsage(bool _printReport=false)
measures the size in bytes of allocated memory. eventually prints a report to std::cout ...
Class to define the vertex input layout.
bool supportsPickingFaces_opt()
Check if optimized face picking is supported.
VertexDeclaration * vertexDeclHalfedgeCol_
vertex buffer layout declaration with per halfedge colors
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
void readVertex(unsigned int _vertex, const typename Mesh::VertexHandle _vh, const typename Mesh::HalfedgeHandle _hh, const typename Mesh::FaceHandle _fh)
reads a vertex from mesh_ and write it to vertex buffer
std::vector< ACG::Vec4uc > pickVertColBuf_
The color buffer used for vertex picking.
int flatMode_
flat / smooth shade mode toggle
void invalidatePerHalfedgeBuffers()
Update of the buffers.
ACG::Vec3f * perEdgeVertexBuffer()
get a pointer to the per edge vertex buffer
VertexElement destType_
property type as stored in vbo
int getTextureIDofTri(unsigned int _tri)
get the texture index of a triangle
unsigned int mapVertexToVBOIndex(unsigned int _v)
map from vertex index of the original mesh point buffer to the corresponding vertex index inside the ...
const void * getMeshPropertyType(OpenMesh::BaseProperty *_prop, GLuint *_outType, unsigned int *_outSize) const
get the data type of a mesh property
GLuint getVBO()
get opengl vertex buffer id
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
int perFaceTextureIndexAvailable()
Check if texture indices are available.
bool supportsPickingVertices_opt()
Check if optimized vertex picking is supported.
void setPerFaceTextureCoordinatePropertyName(std::string _perFaceTextureCoordinatePropertyName)
set the name of the property used for texture coordinate
GLenum getIndexType() const
get index type of index buffer
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
void updatePerHalfedgeBuffers()
Update all per edge drawing buffer n The updated buffers are: per edge vertex buffer ( 2 vertices per...
void addVertexElement(const std::string &_propertyName, PropertySource _source=PROPERTY_SOURCE_VERTEX)
Add custom elements to the vertex layout.
int bVBOinHalfedgeNormalMode_
normals in VBO currently in per vertex / halfedge mode toggle
void updatePickingVertices_opt(ACG::GLState &_state)
Update color picking array for the shader implementation.
void updateGeometry()
request an update for the mesh vertices
std::vector< char > vertices_
ACG::Vec4f * perEdgeColorBuffer()
get a pointer to the per edge color buffer
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
ACG::Vec4uc * pickAnyEdgeColorBuffer()
get a pointer to the any picking color buffer
bool supportsPickingAny_opt()
Check if optimized any picking is supported.
void drawPickingVertices_opt(const GLMatrixf &_mvp, int _pickOffset)
Optimized rendering of vertex picking ids with a shader.
void drawLines()
render the mesh in wireframe mode
int getTextureIDofFace(unsigned int _face)
get the texture index of a face
void drawPickingEdges_opt(const GLMatrixf &_mvp, int _pickOffset)
Optimized rendering of edge picking ids with a shader.
VertexElement sourceType_
property type as stored in openmesh
Kernel::Normal Normal
Normal type.
const size_t offsetPos_
fixed vertex elements:
void updateGPUBuffers()
eventually update vertex and index buffers