25 #include <OpenGLFramework/Utils/Primitives.hh>
26 #include <OpenGLFramework/Base/glfVertexFormat.hh>
40 const unsigned int referenceHeight,
41 const unsigned int linePos,
42 const unsigned int hw,
48 const unsigned int numPatches = 1;
55 unsigned int numVertices = 4 * numPatches;
56 float* vertexData =
new float[numVertices * (VERTEX2D + 2* TEXTURE2D) ];
61 float W =
static_cast<float>(referenceWidth);
62 float H =
static_cast<float>(referenceHeight);
67 float scaleToSpace[2] = { 2.0f/W, 2.0f/H};
68 float shiftToSpace[2] = {1.0f/W - 1.0f, 1.0f/H-1.0f};
72 float scaleToTex[2] = {1.0f/W, -1.0f/H};
73 float shiftToTex[2] = {1.0f/(2.0f*W), 1.0f - 1.0f/(2.0f*H)};
75 float scaleToTexFlipped[2] = {1.0f/W, 1.0f/H};
76 float shiftToTexFlipped[2] = {1.0f/(2.0f*W), 1.0f/(2.0f*H)};
79 unsigned int offset=0;
80 for(
unsigned int p=0; p<numPatches; p++) {
81 int ul[2] = {0,
static_cast<int>(linePos)-static_cast<int>(hw)};
82 int lr[2] = {
static_cast<int>(referenceWidth)-1, static_cast<int>(linePos)+
static_cast<int>(hw)};
85 AddRelativeQuadPatch_(scaleToSpace, shiftToSpace,
86 scaleToTex, shiftToTex,
87 scaleToTexFlipped, shiftToTexFlipped,
89 vertexData, offset, !flip);
94 vb.
Create(numVertices, vertexFrmt, vertexData);
97 GLuint* indices =
new GLuint[numVertices];
98 for(
unsigned int i=0; i<numVertices; i++) indices[i] = i;
99 eb.
Create(numVertices, GL_UNSIGNED_INT, GL_QUADS, indices);
108 const unsigned int referenceHeight,
109 const std::vector<unsigned int>& posX,
110 const std::vector<unsigned int>& posY,
111 const unsigned int hw,
117 unsigned int numPatches = posX.size();
118 BIASASSERT(numPatches == posY.size());
125 unsigned int numVertices = 4 * numPatches;
126 float* vertexData =
new float[numVertices * (VERTEX2D + 2* TEXTURE2D) ];
131 float W =
static_cast<float>(referenceWidth);
132 float H =
static_cast<float>(referenceHeight);
137 float scaleToSpace[2] = { 2.0f/W, 2.0f/H};
138 float shiftToSpace[2] = {1.0f/W - 1.0f, 1.0f/H-1.0f};
142 float scaleToTex[2] = {1.0f/W, -1.0f/H};
143 float shiftToTex[2] = {1.0f/(2.0f*W), 1.0f - 1.0f/(2.0f*H)};
145 float scaleToTexFlipped[2] = {1.0f/W, 1.0f/H};
146 float shiftToTexFlipped[2] = {1.0f/(2.0f*W), 1.0f/(2.0f*H)};
149 unsigned int offset=0;
150 for(
unsigned int p=0; p<numPatches; p++) {
151 int ul[2] = {
static_cast<int>(posX[p])-static_cast<int>(hw),
152 static_cast<int>(posY[p])-static_cast<int>(hw)};
153 int a = posX[p]+hw,b = posY[p]+hw;
157 AddRelativeQuadPatch_(scaleToSpace, shiftToSpace,
158 scaleToTex, shiftToTex,
159 scaleToTexFlipped, shiftToTexFlipped,
161 vertexData, offset, !flip);
166 vb.
Create(numVertices, vertexFrmt, vertexData);
167 delete [] vertexData;
169 GLuint* indices =
new GLuint[numVertices];
170 for(
unsigned int i=0; i<numVertices; i++) indices[i] = i;
171 eb.
Create(numVertices, GL_UNSIGNED_INT, GL_QUADS, indices);
178 AddRelativeQuadPatch_(
const float scaleToSpace[2],
179 const float shiftToSpace[2],
180 const float scaleToTex[2],
181 const float shiftToTex[2],
182 const float scaleToTexFlipped[2],
183 const float shiftToTexFlipped[2],
186 float* supplementedArray,
187 unsigned int& offset,
195 float texFlippedUL[2];
196 float texFlippedLR[2];
197 float tmpTexFlippedUL[2];
198 float tmpTexFlippedLR[2];
204 for(
unsigned int i=0; i<2; i++) {
205 spaceUL[i] = scaleToSpace[i]*(
static_cast<float>(ul[i])-0.5)+shiftToSpace[i];
206 spaceLR[i] = scaleToSpace[i]*(
static_cast<float>(lr[i])+0.5)+shiftToSpace[i];
207 texUL[i] = scaleToTex[i]*(
static_cast<float>(ul[i])-0.5)+shiftToTex[i];
208 texLR[i] = scaleToTex[i]*(
static_cast<float>(lr[i])+0.5)+shiftToTex[i];
209 tmpTexFlippedUL[i] = scaleToTexFlipped[i]*(
static_cast<float>(ul[i])-0.5)+shiftToTexFlipped[i];
210 tmpTexFlippedLR[i] = scaleToTexFlipped[i]*(
static_cast<float>(lr[i])+0.5)+shiftToTexFlipped[i];
212 texFlippedUL[i] = tmpTexFlippedUL[i];
213 texFlippedLR[i] = tmpTexFlippedLR[i];
215 texFlippedUL[i] = texUL[i];
216 texFlippedLR[i] = texLR[i];
217 texUL[i] = tmpTexFlippedUL[i];
218 texLR[i] = tmpTexFlippedLR[i];
228 supplementedArray[offset++] = spaceUL[0];
229 supplementedArray[offset++] = spaceLR[1];
231 supplementedArray[offset++] = texUL[0];
232 supplementedArray[offset++] = texLR[1];
233 supplementedArray[offset++] = texFlippedUL[0];
234 supplementedArray[offset++] = texFlippedLR[1];
236 supplementedArray[offset++] = spaceLR[0];
237 supplementedArray[offset++] = spaceLR[1];
239 supplementedArray[offset++] = texLR[0];
240 supplementedArray[offset++] = texLR[1];
241 supplementedArray[offset++] = texFlippedLR[0];
242 supplementedArray[offset++] = texFlippedLR[1];
244 supplementedArray[offset++] = spaceLR[0];
245 supplementedArray[offset++] = spaceUL[1];
247 supplementedArray[offset++] = texLR[0];
248 supplementedArray[offset++] = texUL[1];
249 supplementedArray[offset++] = texFlippedLR[0];
250 supplementedArray[offset++] = texFlippedUL[1];
252 supplementedArray[offset++] = spaceUL[0];
253 supplementedArray[offset++] = spaceUL[1];
255 supplementedArray[offset++] = texUL[0];
256 supplementedArray[offset++] = texUL[1];
257 supplementedArray[offset++] = texFlippedUL[0];
258 supplementedArray[offset++] = texFlippedUL[1];
270 float* vertexData =
new float[4 * (VERTEX2D + 2* TEXTURE2D) ];
271 AddPlain2DQuadVertices(vertexData, 0, 4);
272 AddPlain2DTextureCoordinates(vertexData, 2, 4, flip);
273 AddPlain2DTextureCoordinates(vertexData, 4, 4, !flip);
275 vb.
Create(4, vertexFrmt, vertexData);
276 delete [] vertexData;
278 GLuint* indices =
new GLuint[4];
279 for(
unsigned int i=0; i<4; i++) indices[i] = i;
280 eb.
Create(4, GL_UNSIGNED_INT, GL_QUADS, indices);
295 unsigned int i=offset;
296 supplementedArray[i++] = -1.0;
297 supplementedArray[i++] = -1.0;
300 supplementedArray[i++] = 1.0;
301 supplementedArray[i++] = -1.0;
304 supplementedArray[i++] = 1.0;
305 supplementedArray[i++] = 1.0;
308 supplementedArray[i++] = -1.0;
309 supplementedArray[i++] = 1.0;
323 unsigned int i=offset;
324 supplementedArray[i++] = 0.0;
325 supplementedArray[i++] = (!flip)? 0.0 : 1.0;
328 supplementedArray[i++] = 1.0;
329 supplementedArray[i++] = (!flip)? 0.0 : 1.0;
332 supplementedArray[i++] = 1.0;
333 supplementedArray[i++] = (!flip)? 1.0 : 0.0;
336 supplementedArray[i++] = 0.0;
337 supplementedArray[i++] = (!flip)? 1.0 : 0.0;
347 unsigned int width, height;
353 float* vertexData =
new float [4 * VERTEX4D];
356 enum {ul =0, ll, lr, ur};
359 imgPoint.
Set(-0.5, -0.5);
361 ray[ul] /= ray[ul][2];
363 imgPoint.
Set(-0.5,
float(height)-0.5);
365 ray[ll] /= ray[ll][2];
367 imgPoint.
Set(
float(width)-0.5,
float(height)-0.5);
369 ray[lr] /= ray[lr][2];
371 imgPoint.
Set(
float(width)-0.5, -0.5);
373 ray[ur] /= ray[ur][2];
375 unsigned int count = 0;
377 for(
unsigned int i =0; i< 4; i++) {
379 vertexData[count++] =
380 static_cast<float>(ray[i][0]);
381 vertexData[count++] =
382 static_cast<float>(ray[i][1]);
383 vertexData[count++] =
384 static_cast<float>(ray[i][2]);
385 vertexData[count++] = 1.0;
389 vb.
Create(4, vertexFormat, vertexData);
390 delete [] vertexData;
392 GLuint* indices =
new GLuint[4];
393 for(
unsigned int i=0; i<4; i++) indices[i] = i;
394 eb.
Create(4, GL_UNSIGNED_INT, GL_QUADS, indices);
402 const std::vector<unsigned int>& posX,
403 const std::vector<unsigned int>& posY,
404 const unsigned int hw,
408 unsigned int numPatches = posX.size();
409 BIASASSERT(numPatches == posY.size());
412 unsigned int width, height;
418 float* vertexData =
new float [numPatches * 4 * VERTEX4D];
421 enum {ul =0, ll, lr, ur};
424 unsigned int count = 0;
425 for(
unsigned int p=0; p<numPatches; p++) {
429 imgPoint.
Set(posX[p]-hw-0.5, posY[p]-hw-0.5);
432 imgPoint.
Set(posX[p]-hw-0.5, posY[p]+hw+0.5);
435 imgPoint.
Set(posX[p]+hw+0.5, posY[p]+hw+0.5);
438 imgPoint.
Set(posX[p]+hw+0.5, posY[p]-hw-0.5);
443 for(
unsigned int i =0; i< 4; i++) {
445 vertexData[count++] =
446 static_cast<float>(ray[i][0]);
447 vertexData[count++] =
448 static_cast<float>(ray[i][1]);
449 vertexData[count++] =
450 static_cast<float>(ray[i][2]);
451 vertexData[count++] = 1.0;
455 vb.
Create(4 * numPatches, vertexFormat, vertexData);
456 delete [] vertexData;
458 GLuint* indices =
new GLuint[4 * numPatches];
459 for(
unsigned int i=0; i< 4 * numPatches; i++) indices[i] = i;
460 eb.
Create(4*numPatches, GL_UNSIGNED_INT, GL_QUADS, indices);
468 const unsigned int posY,
469 const unsigned int hw,
473 unsigned int numPatches = 1;
476 unsigned int width, height;
482 float* vertexData =
new float [numPatches * 4 * VERTEX4D];
485 enum {ul =0, ll, lr, ur};
488 unsigned int count = 0;
493 imgPoint.
Set(-0.5, posY-hw-0.5);
496 imgPoint.
Set(-0.5, posY+hw+0.5);
499 imgPoint.
Set(width-0.5, posY+hw+0.5);
502 imgPoint.
Set(width-0.5, posY-hw-0.5);
507 for(
unsigned int i =0; i< 4; i++) {
509 vertexData[count++] =
510 static_cast<float>(ray[i][0]);
511 vertexData[count++] =
512 static_cast<float>(ray[i][1]);
513 vertexData[count++] =
514 static_cast<float>(ray[i][2]);
515 vertexData[count++] = 1.0;
519 vb.
Create(4 * numPatches, vertexFormat, vertexData);
520 delete [] vertexData;
522 GLuint* indices =
new GLuint[4 * numPatches];
523 for(
unsigned int i=0; i< 4 * numPatches; i++) indices[i] = i;
524 eb.
Create(4*numPatches, GL_UNSIGNED_INT, GL_QUADS, indices);
534 bool normalizeZ,
bool invertS)
536 unsigned int width, height;
543 float* vertexData =
new float[width*height * (VERTEX3D + TEXTURE2D)];
545 unsigned int pos = 0;
546 for(
unsigned int y=0; y<height; y++) {
547 for(
unsigned int x=0; x<width; x++) {
555 vertexData[pos++] =
static_cast<float>(dir[0]);
556 vertexData[pos++] =
static_cast<float>(dir[1]);
557 vertexData[pos++] =
static_cast<float>(dir[2]);
560 vertexData[pos++] = (
static_cast<float>(x)+0.5)/
static_cast<float>(width);
562 vertexData[pos++] = 1.0 - (
static_cast<float>(y)+0.5)/
static_cast<float>(height);
564 vertexData[pos++] = (
static_cast<float>(y)+0.5)/
static_cast<float>(height);
570 vb.
Create(width*height, vertexFormat, vertexData);
571 delete [] vertexData;
581 unsigned int width, height;
584 LocalNormalizedVertexCloud(ppp, vb, normalizeZ, invertS);
586 GLuint* indices =
new GLuint[width*height];
587 for(
unsigned int i=0; i<width*height; i++) indices[i] = i;
588 eb.
Create(width*height, GL_UNSIGNED_INT, GL_POINTS, indices);
599 unsigned int width, height;
602 LocalNormalizedVertexCloud(pppSource, vb, normalizeZ,
true);
609 GLuint* triangleIndices =
610 new GLuint [width*(height-1)*2];
611 unsigned int numTriangleIndex = 0;
613 for(
unsigned int y=0; y<height-1; y++) {
614 for(
unsigned int x=0; x<width; x++) {
621 triangleIndices[numTriangleIndex++] = y*width+x;
622 triangleIndices[numTriangleIndex++] = (y+1)*width+x;
625 eb.
Create(width*(height-1)*2,
630 delete [] triangleIndices;
637 bool normalizeZ,
bool invertS)
639 unsigned int width, height;
642 LocalNormalizedVertexCloud(pppSource, vb, normalizeZ, invertS);
661 const int numIndices = (width*height - width - height + 1)*6;
662 GLuint* triangleIndices =
new GLuint [numIndices];
664 unsigned int cIdx = 0;
665 for(
unsigned int y=0; y<height-1; y++) {
666 for(
unsigned int x=0; x<width-1; x++) {
668 triangleIndices[cIdx++] = y*width+x;
669 triangleIndices[cIdx++] =(y+1)*width+x;
670 triangleIndices[cIdx++] = y * width+x+1;
673 triangleIndices[cIdx++] = y*width+ x+1;
674 triangleIndices[cIdx++] =(y+1)*width+ x;
675 triangleIndices[cIdx++] =(y+1)*width+ x+1;
684 delete [] triangleIndices;
687 #ifdef GL_VERSION_3_0
691 GLint VertexCoordSlot, GLint TexCoordSlot,
bool normalizeZ)
694 if(VertexCoordSlot != -1 || TexCoordSlot != -1) {
695 BIASASSERT(VertexCoordSlot!=TexCoordSlot)
699 if(VertexCoordSlot == -1 && TexCoordSlot == -1) {
700 BIASWARN(
"This function call has no effect!");
704 unsigned int width, height;
706 float* vertexData = (VertexCoordSlot != -1) ?
new float[width*height*3] : NULL;
707 float* texCoordData = (TexCoordSlot != -1) ?
new float[width*height*3] : NULL;
710 unsigned int posVertexCoord = 0;
711 unsigned int posTexCoord = 0;
713 for(
unsigned int y=0; y<height; y++) {
714 for(
unsigned int x=0; x<width; x++) {
717 if(dir[0] == 0 && dir[1] == 0 && dir[2] == 0)
continue;
720 BIASERR(
"ray is valid but z-component is zero!");
726 if(VertexCoordSlot != -1) {
729 vertexData[posVertexCoord++] =
static_cast<float>(dir[0]);
730 vertexData[posVertexCoord++] =
static_cast<float>(dir[1]);
731 vertexData[posVertexCoord++] =
static_cast<float>(dir[2]);
734 if(TexCoordSlot != -1) {
735 texCoordData[posTexCoord++] = (
static_cast<float>(x)+0.5)/
static_cast<float>(width);
736 texCoordData[posTexCoord++] = (
static_cast<float>(y)+0.5)/
static_cast<float>(height);
737 texCoordData[posTexCoord++] = 1.0 - (
static_cast<float>(y)+0.5)/
static_cast<float>(height);
741 unsigned int numValues = width*height;
742 if(VertexCoordSlot != -1)
743 vao.UploadData(VertexCoordSlot, 3, vertexData, numValues);
744 if(TexCoordSlot != -1)
745 vao.UploadData(TexCoordSlot, 3, texCoordData, numValues);
747 delete [] vertexData;
748 delete [] texCoordData;
static void LocalPerspectivePatchOverLine(const BIAS::ProjectionParametersPerspective &ppp, const unsigned int posY, const unsigned int hw, glfVertexBuffer &vb, glfElementBuffer &eb)
Patch encloses a region around a complete image line.
static void LocalPerspectiveQuad(const BIAS::ProjectionParametersPerspective &ppp, BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb)
An element buffer contains vertex indices that form primitives.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
static void LocalNormalizedTriangleMesh(const BIAS::ProjectionParametersPerspective &pppSource, BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, bool normalizeZ, bool invertS)
static void LocalNormalizedTriangleStrip(const BIAS::ProjectionParametersPerspective &pppSource, BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, bool normalizeZ=false)
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
static void AddRelativeQuadPatchOverImageLine(const unsigned int referenceWidth, const unsigned int referenceHeight, const unsigned int linePos, const unsigned int hw, BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, const bool flip)
Adds a patch suited for rendering with identity rendering parameters that exactly fits over an image ...
A vertex buffer contains an array of vertices that can be used for rendering.
void Create(int numVertices, const glfVertexFormat &format, const void *data=NULL, bool useBufferIfPossible=true)
Creates the vertex buffer for the given number of vertices and vertex format.
static void LocalNormalizedVertexCloud(const BIAS::ProjectionParametersPerspective &ppp, BIAS::glfVertexBuffer &vb, bool normalizeZ, bool invertS)
Generates a vertex list of textured 3d vertices.
class Vector4 contains a Vector of dim.
static void LocalPerspectivePatches(const BIAS::ProjectionParametersPerspective &ppp, const std::vector< unsigned int > &posX, const std::vector< unsigned int > &posY, const unsigned int hw, glfVertexBuffer &vb, glfElementBuffer &eb)
static void AddPlain2DTextureCoordinates(float *supplementedArray, unsigned int offset, unsigned int stride, bool flip=false)
Vertex Order: 3–2 | | 0–1 .
static void LocalNormalizedPointCloud(const BIAS::ProjectionParametersPerspective &ppp, BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, bool normalizeZ, bool invertS)
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const =0
Calculates the view ray, which belongs to the given position on the image plane, in local coordinates...
static void PlainQuad2DWithTexture2D(BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, bool flip=false)
Vertex Order: 3–2 | | 0–1 .
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
void Create(int numIndices, GLenum type, GLenum mode, const void *indices)
Creates the element buffer for the given number of indices.
static void AddRelativeQuadPatches(const unsigned int referenceWidth, const unsigned int referenceHeight, const std::vector< unsigned int > &posX, const std::vector< unsigned int > &posY, const unsigned int hw, BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, const bool flip)
Calculates 2D patches in the image plane suited for rendering with identity rendering parameters...
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &pointOnRay, Vector3< double > &direction, bool IgnoreDistortion=false) const
calculates the viewing ray from the camera center (in the camera coordinate system) which belongs to ...
static void AddPlain2DQuadVertices(float *supplementedArray, unsigned int offset, unsigned int stride)
Vertex Order: 3–2 | | 0–1 .
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
void Set(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y)
set elementwise with given 2 euclidean scalar values.
class BIASGeometryBase_EXPORT HomgPoint2D