GPU-Accelerated Coverage  0.1.0
Compute coverage tours for known environment with articulated objects on GPU
VisibilityRenderer.h
1 /*
2  * Copyright (c) 2018, Stefan Osswald
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef INCLUDE_ARTICULATION_VISIBILITYRENDERER_H_
32 #define INCLUDE_ARTICULATION_VISIBILITYRENDERER_H_
33 
34 #include <gpu_coverage/AbstractRenderer.h>
35 #include <gpu_coverage/Programs.h>
36 #include <list>
37 
38 #undef GET_BUFFER_DIRECT
39 
40 namespace gpu_coverage {
41 
46 public:
53  VisibilityRenderer(const Scene * const scene, const bool renderToWindow, const bool countPixels);
54 
59 
67  virtual void display();
74  void display(const bool countPixels);
75 
90  void getPixelCounts(std::vector<GLuint>& counts);
91 
96  inline const GLuint& getTexture() const {
97  return textures[VISIBILITY];
98  }
104  inline const GLuint& getTexture(const size_t& i) const {
105  return textures[VISIBILITY + i];
106  }
107 
112  inline const int& getTextureHeight() const {
113  return textureHeight;
114  }
115 
120  inline const int& getTextureWidth() const {
121  return textureWidth;
122  }
123 
124 protected:
125  const bool renderToWindow;
126  const bool countPixels;
131  const int width;
132  const int height;
133  const int textureWidth;
134  const int textureHeight;
135  std::list<GLuint> pixelCounts;
137  GLuint framebuffers[2];
138  GLuint textures[20];
139  size_t numTextures;
140  GLuint vao;
141  GLuint vbo;
144  typedef std::list<std::pair<Node *, GLuint> > Targets;
145  Targets targets;
146 
147  enum TextureRole {
148  DEPTH = 0,
149  COLOR = 1,
151  COUNTER = 3,
153  };
154 
155 #ifndef GET_BUFFER_DIRECT
157  GLuint pbo[4];
158  const GLuint numPbo;
159  GLuint curPbo;
160  GLuint run;
161  GLuint vaoPoint;
162  GLuint vboPoint;
163  void readBack();
164 #endif
165 
166 };
167 
168 } // namespace gpu_coverage
169 
170 #endif /* INCLUDE_ARTICULATION_VISIBILITYRENDERER_H_ */
Definition: Programs.h:390
void getPixelCounts(std::vector< GLuint > &counts)
Returns the list of observed pixels of the previous frames.
const GLuint numPbo
Number of allocated pixel buffer objects.
Definition: VisibilityRenderer.h:158
GLuint pbo[4]
Pixel buffer objects as ring buffer.
Definition: VisibilityRenderer.h:157
Color buffer of the 3D scene, unused.
Definition: VisibilityRenderer.h:149
Texture for reading back pixel counter.
Definition: VisibilityRenderer.h:151
Depth buffer of the 3D scene.
Definition: VisibilityRenderer.h:148
Targets targets
List of targets (regions of interest) with corresponding texture.
Definition: VisibilityRenderer.h:145
virtual void display()
Renders the scene.
const bool renderToWindow
True if renderer should also render to window framebuffer.
Definition: VisibilityRenderer.h:125
void readBack()
Read back ring bufer.
VisibilityRenderer(const Scene *const scene, const bool renderToWindow, const bool countPixels)
Constructor.
GLuint run
Ring buffer index.
Definition: VisibilityRenderer.h:160
GLuint framebuffers[2]
Framebuffers for rendering 3D scene and for rendering visibility texture.
Definition: VisibilityRenderer.h:137
Visibility texture for debugging.
Definition: VisibilityRenderer.h:150
size_t numTextures
Number of allocated teextures.
Definition: VisibilityRenderer.h:139
Scene graph corresponding to Assimp&#39;s aiScene.
Definition: Scene.h:59
Scene graph node, corresponding to Assimp&#39;s aiNode.
Definition: Node.h:52
const GLuint & getTexture() const
Returns the OpenGL texture ID of the result texture.
Definition: VisibilityRenderer.h:96
ProgramPixelCounter * progPixelCounter
Shadere for counting observed pixels (only if countPixels is true)
Definition: VisibilityRenderer.h:130
AbstractCamera * camera
Camera observing the scene.
Definition: VisibilityRenderer.h:143
Node * projectionPlaneNode
Virtual surface where camera can be placed, only used to hide while rendering.
Definition: VisibilityRenderer.h:142
std::list< GLuint > pixelCounts
List of number of observed pixels in the previous frames, see getPixelCounts()
Definition: VisibilityRenderer.h:135
const Scene *const scene
Pointer to the scene to be rendered.
Definition: AbstractRenderer.h:101
const int textureWidth
Width of the result texture in pixels.
Definition: VisibilityRenderer.h:133
GLuint vaoPoint
Vertex array object for rendering single output pixel.
Definition: VisibilityRenderer.h:161
Definition: Programs.h:363
ProgramVisualFlat progFlat
Shader for 3D rendering without material (used to fill depth buffer)
Definition: VisibilityRenderer.h:127
GLuint curPbo
Current pixel buffer object.
Definition: VisibilityRenderer.h:159
Abstract superclass for all renderers.
Definition: AbstractRenderer.h:45
ProgramVisibility progVisibility
Shader for marking observed texels.
Definition: VisibilityRenderer.h:128
GLuint textures[20]
4 internal textures and up to 16 target textures
Definition: VisibilityRenderer.h:138
const int height
Height of the framebuffer for rendering the 3D scene in pixels.
Definition: VisibilityRenderer.h:132
GLuint vbo
Vertex buffer objeect.
Definition: VisibilityRenderer.h:141
const int textureHeight
Height of the result texture in pixels.
Definition: VisibilityRenderer.h:134
const int width
Width of the framebuffer for rendering the 3D scene in pixels.
Definition: VisibilityRenderer.h:131
Definition: AbstractCamera.h:41
GLuint vboPoint
Vertex buffer object for rendering single output pixel.
Definition: VisibilityRenderer.h:162
Abstract superclass for all cameras.
Definition: AbstractCamera.h:48
TextureRole
Definition: VisibilityRenderer.h:147
const int & getTextureWidth() const
Width of the result texture.
Definition: VisibilityRenderer.h:120
ProgramShowTexture * progShowTexture
Shader for rendering observation texture for debugging (only if renderToWindow is true) ...
Definition: VisibilityRenderer.h:129
const int & getTextureHeight() const
Height of the result texture.
Definition: VisibilityRenderer.h:112
const bool countPixels
True if observed pixels should be counted, can be overwritten by argument to display(const bool count...
Definition: VisibilityRenderer.h:126
std::list< std::pair< Node *, GLuint > > Targets
List of targets (regions of interest) with corresponding texture.
Definition: VisibilityRenderer.h:144
Definition: Programs.h:200
Definition: Programs.h:378
const GLuint & getTexture(const size_t &i) const
Returns the OpenGL texture ID of the result texture in case of multiple textures. ...
Definition: VisibilityRenderer.h:104
Result texture.
Definition: VisibilityRenderer.h:152
GLuint pixelCountBuffer
Atomic counter buffer for reading back pixels counts from GPU.
Definition: VisibilityRenderer.h:136
GLuint vao
Vertex array object.
Definition: VisibilityRenderer.h:140
ProgramCounterToFB * progCounterToFB
Shader counting pixels and writing result directly to framebuffer.
Definition: VisibilityRenderer.h:156
Definition: Programs.h:402
Determines regions visible from a given camera pose and marks the regions as observed on the texture...
Definition: VisibilityRenderer.h:45