www.pudn.com > GPUVision_5-13-05-2.zip > FindMaximum.cpp
#include "FindMaximum.h"
#include "IndexMtxPos.h"
using namespace std;
FindMaximum::FindMaximum(CGcontext context) : MtxOps(context){
_cgFileName="mtx_maximum_pos.cg";
this->_LoadCgPrograms();
this->_initParameters();
}
FindMaximum::~FindMaximum(){
}
void FindMaximum::_initParameters(){
cgGLEnableProfile(_fragmentProfile);
_textureAParam = cgGetNamedParameter (_fragmentProgram, "texture");
_kParam = cgGetNamedParameter (_fragmentProgram, "k");
_borderParam = cgGetNamedParameter (_fragmentProgram, "border");
if (_textureAParam == 0 ||
_kParam == 0 ||
_borderParam == 0) {
printf("Texture param aquisition failed!");
system("pause");
exit (1);
}
cgGLDisableProfile(_fragmentProfile);
}
void FindMaximum::execute(GPUVision *outImg, int arg1){
float kx, ky;
IndexMtxPos *idxMtxPos;
idxMtxPos = new IndexMtxPos(outImg->GetContext());
idxMtxPos->execute(outImg, arg1);
outImg->Begin();
cgGLBindProgram(_fragmentProgram);
cgGLSetTextureParameter(_textureAParam, outImg->GetRenderedTextureID());
cgGLEnableTextureParameter(_textureAParam);
cgGLEnableProfile(_fragmentProfile);
kx=outImg->GetWidth();
ky=outImg->GetHeight();
cgGLSetParameter2f(_borderParam, kx, ky);
while(kx>1 || ky>1){
kx=ceil(kx/2);
ky=ceil(ky/2);
cgGLSetParameter2f(_kParam, kx, ky);
_DrawFull(outImg->GetWidth(), outImg->GetHeight());
outImg->Flip();//ToDo:We need to change this.
}
cgGLDisableTextureParameter(_textureAParam);
cgGLDisableProfile(_fragmentProfile);
outImg->End();
}
void FindMaximum::execute(GPUVision *outImg, int arg1, bool removeBorder){
float kx, ky;
IndexMtxPos *idxMtxPos;
idxMtxPos = new IndexMtxPos(outImg->GetContext());
idxMtxPos->execute(outImg, arg1);
outImg->Begin();
cgGLBindProgram(_fragmentProgram);
cgGLSetTextureParameter(_textureAParam, outImg->GetRenderedTextureID());
cgGLEnableTextureParameter(_textureAParam);
cgGLEnableProfile(_fragmentProfile);
kx=(removeBorder)? outImg->GetWidth()-1:outImg->GetWidth();
ky=(removeBorder)? outImg->GetHeight()-1:outImg->GetHeight();
cgGLSetParameter2f(_borderParam, kx, ky);
while(kx>1 || ky>1){
kx=ceil(kx/2);
ky=ceil(ky/2);
cgGLSetParameter2f(_kParam, kx, ky);
_DrawFull(outImg->GetWidth(), outImg->GetHeight());
outImg->Flip();//ToDo:We need to change this.
}
cgGLDisableTextureParameter(_textureAParam);
cgGLDisableProfile(_fragmentProfile);
outImg->End();
}
GLfloat* FindMaximum::interpreteResult (float *colBuffer) {
GLfloat* ret = (GLfloat*)malloc(3*sizeof(GLfloat));
ret[0] = colBuffer[0];
ret[1] = colBuffer[1];
ret[2] = colBuffer[2];
delete colBuffer;
return ret;
}
void FindMaximum::showResultMtx(GPUVision* gpuVis, int m, int n){
GLfloat* result;
result=interpreteResult(gpuVis->DownloadTexture());
_printOutMtx(result, 1, 3);
}