Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Primitives.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2008, 2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __Primitives_hh__
26 #define __Primitives_hh__
27 
28 #include <OpenGLFramework/Base/glfBatch.hh>
29 #include <OpenGLFramework/Base/glfVertexBuffer.hh>
30 #include <OpenGLFramework/Base/glfElementBuffer.hh>
31 #include <Geometry/ProjectionParametersPerspective.hh>
32 #include <bias_config.h>
33 
34 #include <OpenGLFramework/Base/glfVertexArrayObject.hh>
35 
36 
37 namespace BIAS {
38 
39  /** Helper class for creating primitives.
40  * \ingroup g_openglframework
41  * \author bartczak 04/2008
42  **/
43  class BIASOpenGLFramework_EXPORT Primitives {
44  public:
45  /**
46  * Vertex Order:\n
47  * 3--2 \n
48  * | | \n
49  * 0--1 \n
50  *
51  * Vertex Coordinates:\n
52  * (-1, 1) -- (1, 1) \n
53  * | | \n
54  * | | \n
55  * | | \n
56  * (-1,-1) -- (1, -1)\n
57  *
58  * unflipped texture coordinates: \n
59  * (0,1) -- (1,1) \n
60  * | | \n
61  * | | \n
62  * (0,0) -- (1,0) \n
63  *
64  * Generates the quad.
65  *
66  **/
67  static void PlainQuad2DWithTexture2D(BIAS::glfVertexBuffer& vb, BIAS::glfElementBuffer& eb, bool flip=false);
68 
69  /**
70  * Vertex Order:\n
71  * 3--2 \n
72  * | | \n
73  * 0--1 \n
74  *
75  * Vertex Coordinates:\n
76  * (-1, 1) -- (1, 1) \n
77  * | | \n
78  * | | \n
79  * | | \n
80  * (-1,-1) -- (1, -1)\n
81  *
82  * \attention memory space must be allocated properly!
83  */
84  static void AddPlain2DQuadVertices(float* supplementedArray,
85  unsigned int offset, unsigned int stride);
86 
87  /**
88  * Vertex Order: \n
89  * 3--2 \n
90  * | | \n
91  * 0--1 \n
92  *
93  * unflipped texture coordinates: \n
94  * (0,1) -- (1,1) \n
95  * | | \n
96  * | | \n
97  * (0,0) -- (1,0) \n
98  *
99  * \attention memory space must be allocated properly!
100  */
101  static void AddPlain2DTextureCoordinates(float* supplementedArray,
102  unsigned int offset, unsigned int stride, bool flip=false);
103 
104  static void LocalPerspectiveQuad(const BIAS::ProjectionParametersPerspective& ppp,
106 
107  static void LocalPerspectivePatches(const BIAS::ProjectionParametersPerspective& ppp,
108  const std::vector<unsigned int>& posX,
109  const std::vector<unsigned int>& posY,
110  const unsigned int hw,
112 
113  /** Patch encloses a region around a complete image line.
114  * \author bartczak
115  * \date 08/2010
116  */
117  static void LocalPerspectivePatchOverLine(const BIAS::ProjectionParametersPerspective& ppp,
118  const unsigned int posY,
119  const unsigned int hw,
121 
122  /** Generates a vertex list of textured 3d vertices.
123  Their vertex coordinates can be interpreted as the optical ray directions belonging to
124  their respective pixel centers in camera coordinates. The vertex array is constructed
125  row wise starting with the top pixel row. */
126  static void LocalNormalizedVertexCloud(const BIAS::ProjectionParametersPerspective& ppp,
127  BIAS::glfVertexBuffer& vb, bool normalizeZ, bool invertS);
128 
129  static void LocalNormalizedPointCloud(const BIAS::ProjectionParametersPerspective& ppp,
130  BIAS::glfVertexBuffer& vb, BIAS::glfElementBuffer& eb, bool normalizeZ, bool invertS);
131 
132  static void LocalNormalizedTriangleStrip(const BIAS::ProjectionParametersPerspective& pppSource,
134  bool normalizeZ=false);
135 
136  static void LocalNormalizedTriangleMesh(const BIAS::ProjectionParametersPerspective& pppSource,
138  bool normalizeZ, bool invertS);
139 
140 #ifdef GL_VERSION_3_0
141  /**
142  Calculates 3D optical ray in the local coordinate frame of ppb.
143  Moreover the corresponding texture coordinates for accessing an input image can be calculated.
144  The results are assigned to the passed glfVertexArrayObject, which is assumed to already be created (Create()).
145  \param ppb the intirinsics of this parameters are used.
146  \param vao is the object modified by this method.
147  \param count is the number of returned attributes.
148  \param normalizeZ decides upon the normalization of the rays, if this param is false the rays will be set to have an eucledean length of one otherwise
149  they are scaled so that the z-component will be one
150  \param VertexCoordSlot determines the VertexAttributeSlot which is used to assigne the calculated vertex coordinates to, if this is set to -1 no vertex coordinates will be generated.
151  \param TexCoordSlot determines the VertexAttributeSlot which is used to assigne the calculated texture coordinates to, if this is set to -1 no texture coordinates will be generated.
152  <b> TexCoordSlot </b> contains two versions of texture coordinates are calculated. The first set assignes texture coordinates (s = (x+0.5)/width, t = (y+0.5)/height*y) to a vertex
153  corresponding to pixel coordinates (x,y). The second set flips the direction of the t-component, i.e (s = (x+0.5)/width, t = 1-(y+0.5)/height*y). This sets are packed together, so
154  that the first component of the vertex attribute contains the s component (which is the same for both sets), the second component contains the increasing values version and the
155  third is the decreasing values version.
156 
157  E.g. one could use the following GLSL vertex shader source to access the texture coordinates:
158  \code
159  #version 130 //will not work with previous versions!
160 
161  in vec3 packedTexCoords;//bound to appropriate slotindex
162 
163  vec2 incTexCoord() {
164  return vec2(packedTexCoords[0], packedTexCoords[1]);
165  }
166  vec2 decTexCoord() {
167  return vec2(packedTexCoords[0], packedTexCoords[2]);
168  }
169  \endcode
170 
171  \attention it is not allowed to assign vertex coordinates and texture coordinates to the same slot!
172  \attention normalizeZ is not applicable with cameras of fov of 180Deg and larger (Fisheye)!
173  **/
174  static void CalculateLocalRayField(const ProjectionParametersBase& ppb, glfVertexArrayObject& vao,
175  GLsizei& count,
176  GLint VertexCoordSlot=0, GLint TexCoordSlot=1, bool normalizeZ=false);
177 #endif
178 
179  /** Calculates 2D patches in the image plane suited for rendering with identity rendering parameters,
180  * patches are valid for a reference resolution and symmetrically centered around a pixel position.
181  **/
182  static void AddRelativeQuadPatches(const unsigned int referenceWidth,
183  const unsigned int referenceHeight,
184  const std::vector<unsigned int>& posX,
185  const std::vector<unsigned int>& posY,
186  const unsigned int hw,
188  const bool flip);
189 
190  /** Adds a patch suited for rendering with identity rendering parameters that exactly fits over an image line in the image plane.
191  */
192  static void AddRelativeQuadPatchOverImageLine(const unsigned int referenceWidth,
193  const unsigned int referenceHeight,
194  const unsigned int linePos,
195  const unsigned int hw,
197  const bool flip);
198 
199  private:
200 
201  /** Slave of AddRelativeQuadPatches().
202  **/
203  static void AddRelativeQuadPatch_(const float scaleToSpace[2],
204  const float shiftToSpace[2],
205  const float scaleToTex[2],
206  const float shiftToTex[2],
207  const float scaleToTexFlipped[2],
208  const float shiftToTexFlipped[2],
209  const int ul[2],
210  const int lr[2],
211  float* supplementedArray,
212  unsigned int& offset,
213  const bool flip);
214 
215  };
216 }
217 
218 
219 
220 #endif
An element buffer contains vertex indices that form primitives.
Helper class for creating primitives.
Definition: Primitives.hh:43
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
A vertex buffer contains an array of vertices that can be used for rendering.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...