www.pudn.com > GPUVision_5-13-05-2.zip > CalculateWMtx.cpp
#include "CalculateWMtx.h"
using namespace std;
CalculateWMtx::CalculateWMtx(CGcontext context) : MtxOps(context){
_texWidth=1000;//2048;
_texHeight=1000;//1950;
_width=10;//160000;
_height=10;//160000;
_cgFileName="cal_w_mtx.cg";
this->_LoadCgPrograms();
this->_initParameters();
}
CalculateWMtx::~CalculateWMtx(){
}
void CalculateWMtx::_initParameters(){
cgGLEnableProfile(_fragmentProfile);
_textureAParam = cgGetNamedParameter (_fragmentProgram, "a");
_betaParam = cgGetNamedParameter (_fragmentProgram, "beta");
if (_textureAParam == 0 ||
_betaParam == 0) {
printf("Texture param aquisition failed!");
system("pause");
exit (1);
}
cgGLDisableProfile(_fragmentProfile);
}
void CalculateWMtx::execute(GPUVision *outImg, int arg1, float beta){
bool res = outImg->IsReset();
outImg->Begin();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
cgGLBindProgram(_fragmentProgram);
cgGLSetParameter1f(_betaParam, beta);
cgGLSetTextureParameter(_textureAParam, arg1);
cgGLEnableTextureParameter(_textureAParam);
cgGLEnableProfile(_fragmentProfile);
_DrawFull(outImg->GetWidth(), outImg->GetHeight());
cgGLDisableTextureParameter(_textureAParam);
cgGLDisableProfile(_fragmentProfile);
outImg->Flip();
outImg->End();
}
GLfloat* CalculateWMtx::interpreteResult (float *colBuffer) {
GLfloat* ret = (GLfloat*)malloc(_height*_width*sizeof(GLfloat));
int i;
for (i=0; i<(_height*_width); i++) {
// red channel is g-Vector
ret[i] = colBuffer[i*4+1];
}
delete colBuffer;
return ret;
}
void CalculateWMtx::showResultMtx(GPUVision* gpuVis, int m, int n){
GLfloat* result;
result=interpreteResult(gpuVis->DownloadTexture());
_printOutMtx(result, m, n);
}