Developer Documentation

PointNode.cc
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 //
49 // CLASS PointNode - IMPLEMENTATION
50 //
51 //=============================================================================
52
53 //== INCLUDES =================================================================
54
55 #include "PointNode.hh"
56 #include <ACG/GL/IRenderer.hh>
57
58 //== NAMESPACES ===============================================================
59
60 namespace ACG {
61 namespace SceneGraph {
62
63
64 //== IMPLEMENTATION ==========================================================
65
66
67 void
68 PointNode::
69 boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
70 {
71 ConstPointIter p_it=points_.begin(), p_end=points_.end();
72 for (; p_it!=p_end; ++p_it) {
73 _bbMin.minimize(*p_it);
74 _bbMax.maximize(*p_it);
75 }
76 }
77
78
79 //----------------------------------------------------------------------------
80
81
82 DrawModes::DrawMode
83 PointNode::
84 availableDrawModes() const
85 {
86 return ( DrawModes::POINTS |
87 DrawModes::POINTS_SHADED |
88 DrawModes::POINTS_COLORED );
89 }
90
91
92 //----------------------------------------------------------------------------
93
94
95 void
96 PointNode::
97 draw(GLState& /* _state */ , const DrawModes::DrawMode& _drawMode)
98 {
99 if (points_.empty())
100 return;
101
102 // points
103 if (_drawMode & DrawModes::POINTS)
104 {
105 ACG::GLState::disable(GL_LIGHTING);
106 ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
107 ACG::GLState::vertexPointer(&points_[0]);
108 glDrawArrays(GL_POINTS, 0, int(points_.size()));
109 }
110
111
112 // points and normals
113 if (_drawMode & DrawModes::POINTS_SHADED)
114 {
115 if (points_.size() == normals_.size())
116 {
117 ACG::GLState::enable(GL_LIGHTING);
118 ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
119 ACG::GLState::vertexPointer(&points_[0]);
120 ACG::GLState::enableClientState(GL_NORMAL_ARRAY);
121 ACG::GLState::normalPointer(&normals_[0]);
122 glDrawArrays(GL_POINTS, 0, int(points_.size()));
123 }
124 }
125
126
127 // points and colors
128 if (_drawMode & DrawModes::POINTS_COLORED)
129 {
130 if (points_.size() == colors_.size())
131 {
132 ACG::GLState::disable(GL_LIGHTING);
133 ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
134 ACG::GLState::vertexPointer(&points_[0]);
135 ACG::GLState::enableClientState(GL_COLOR_ARRAY);
136 ACG::GLState::colorPointer(&colors_[0]);
137 glDrawArrays(GL_POINTS, 0, int(points_.size()));
138 } else
139 std::cerr << "Mismatch size!" << std::endl;
140 }
141
142
143 // disable arrays
144 ACG::GLState::disableClientState(GL_VERTEX_ARRAY);
145 ACG::GLState::disableClientState(GL_NORMAL_ARRAY);
146 ACG::GLState::disableClientState(GL_COLOR_ARRAY);
147 }
148
149 void
150 PointNode::
151 getRenderObjects( IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat )
152 {
153 if (points_.empty())
154 return;
155
156 // setup RenderObject
157 RenderObject ro;
158 ro.debugName = "PointNode";
159
160
161 // define vertex format
162 // buffer address may change so do this every frame
163
164 vertexDecl_.clear();
165 vertexDecl_.addElement(GL_DOUBLE, 3, VERTEX_USAGE_POSITION, &points_[0]);
166 if (!normals_.empty())
167 vertexDecl_.addElement(GL_DOUBLE, 3, VERTEX_USAGE_NORMAL, &normals_[0]);
168 if (!colors_.empty())
169 vertexDecl_.addElement(GL_FLOAT, 4, VERTEX_USAGE_COLOR, &colors_[0]);
170
171 vertexDecl_.setVertexStride(0);
172
173 ro.vertexDecl = &vertexDecl_;
174
175 for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
176 {
177 const DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
178
179 if (props->primitive() == DrawModes::PRIMITIVE_POINT)
180 {
181 // reset renderobject
182 ro.initFromState(&_state);
183 ro.setMaterial(_mat);
184 ro.setupShaderGenFromDrawmode(props);
185
186 ro.priority = 0;
187 ro.depthTest = true;
188 ro.depthWrite = true;
189 ro.depthFunc = GL_LESS;
190
191 // use pointsize shader
192 QString geomTemplate = ShaderProgGenerator::getShaderDir();
193 geomTemplate += "PointSize/geometry.tpl";
194
195 QString fragTemplate = ShaderProgGenerator::getShaderDir();
196 fragTemplate += "PointSize/fragment.tpl";
197
198 ro.shaderDesc.geometryTemplateFile = geomTemplate;
199 ro.shaderDesc.fragmentTemplateFile = fragTemplate;
200
201 // shader uniforms
202 ro.setUniform("screenSize", Vec2f((float)_state.viewport_width(), (float)_state.viewport_height()));
203 ro.setUniform("pointSize", _mat->pointSize());
204
205 ro.glDrawArrays(GL_POINTS, 0, (GLsizei)points_.size());
206 _renderer->addRenderObject(&ro);
207 }
208 }
209 }
210
211
212 //=============================================================================
213 } // namespace SceneGraph
214 } // namespace ACG
215 //=============================================================================
OpenMesh::VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:563
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::RenderObject::setupShaderGenFromDrawmode
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
Definition: RenderObject.cc:137
ACG::SceneGraph::ACG::GLState::normalPointer
static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glNormalPointer, supports locking
ACG::SceneGraph::DrawModes::POINTS_SHADED
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
ACG::SceneGraph::ACG::GLState::colorPointer
static void colorPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glColorPointer, supports locking
ACG::SceneGraph::DrawModes::POINTS_COLORED
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
ACG::SceneGraph::ACG::GLState::enable
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
ACG::SceneGraph::Material::pointSize
void pointSize(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:224
ACG::SceneGraph::PointNode::boundingBox
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
Definition: PointNode.cc:69
ACG::RenderObject::initFromState
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:61
ACG::GLState::viewport_width
int viewport_width() const
get viewport width
Definition: GLState.hh:822
ACG::SceneGraph::ACG::GLState::disable
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
ACG::VERTEX_USAGE_COLOR
"inColor"
Definition: VertexDeclaration.hh:68
ACG::RenderObject
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
ACG::SceneGraph::DrawModes::DrawMode::getNumLayers
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:531
ACG::GLState
Definition: GLState.hh:213
ACG::RenderObject::depthFunc
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
Definition: RenderObject.hh:240
ACG::Vec2f
VectorT< float, 2 > Vec2f
Definition: VectorT.hh:102
ACG::SceneGraph::ACG::GLState::vertexPointer
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
ACG::SceneGraph::ACG::GLState::disableClientState
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
ACG::VertexDeclaration::setVertexStride
void setVertexStride(unsigned int _stride)
Definition: VertexDeclaration.cc:564
ACG::VertexDeclaration::addElement
void addElement(const VertexElement *_pElement)
Definition: VertexDeclaration.cc:115
ACG::GLState::viewport_height
int viewport_height() const
get viewport height
Definition: GLState.hh:824
ACG::RenderObject::setUniform
void setUniform(const char *_name, GLint _value)
set values for int uniforms
Definition: RenderObject.cc:413
ACG::SceneGraph::ACG::GLState::enableClientState
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
ACG::SceneGraph::PointNode::availableDrawModes
DrawModes::DrawMode availableDrawModes() const
return available draw modes
Definition: PointNode.cc:84
ACG::IRenderer::addRenderObject
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
Definition: IRenderer.cc:104
ACG::SceneGraph::Material
Definition: MaterialNode.hh:79
ACG::ShaderProgGenerator::getShaderDir
static QString getShaderDir()
Definition: ShaderGenerator.cc:2451
ACG::SceneGraph::PointNode::draw
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw points and normals
Definition: PointNode.cc:97
ACG::VertexDeclaration::clear
void clear()
Definition: VertexDeclaration.cc:570
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::RenderObject::shaderDesc
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Definition: RenderObject.hh:225
OpenMesh::VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:535
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::DrawModes::DrawMode::getLayer
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:535
ACG::SceneGraph::PointNode::getRenderObjects
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
draw points and normals via renderer plugin
Definition: PointNode.cc:151
ACG::IRenderer
Definition: IRenderer.hh:78
ACG::VERTEX_USAGE_NORMAL
"inNormal"
Definition: VertexDeclaration.hh:66
ACG::VERTEX_USAGE_POSITION
"inPosition"
Definition: VertexDeclaration.hh:65
ACG::RenderObject::vertexDecl
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
Definition: RenderObject.hh:208
ACG::SceneGraph::DrawModes::POINTS
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
ACG::SceneGraph::DrawModes::DrawModeProperties
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
ACG::RenderObject::priority
int priority
Priority to allow sorting of objects.
Definition: RenderObject.hh:116