示例#1
0
void TextureWarpShader::renderTexture(GLenum mode, GLuint target, GLuint id, const Eigen::Matrix3fr &homography, const Eigen::Vector2i &imageSize, const Eigen::Vector4f *vertices,
	const Eigen::Vector2f *textureCoords, int count)
{
    assert(target == GL_TEXTURE_2D);

    glUseProgram(mProgram.getId());

	Eigen::Matrix3f finalH;
	finalH = adjustHomography(imageSize, homography);
    glUniformMatrix3fv(mUniformHomographyMatrix, 1, false, finalH.data());

    // setup uniforms
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(target, id);
    glUniform1i(mUniformTexture, 0);

    // drawing quad
    glVertexAttribPointer(mAttribPosCoord, 4, GL_FLOAT, GL_FALSE, 0, vertices);
    glVertexAttribPointer(mAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
    glEnableVertexAttribArray(mAttribPosCoord);
    glEnableVertexAttribArray(mAttribTexCoord);
    glDrawArrays(mode, 0, count);
    glDisableVertexAttribArray(mAttribPosCoord);
    glDisableVertexAttribArray(mAttribTexCoord);
}
示例#2
0
void ObjectRenderer::set_uniform(const char* name, const Eigen::Matrix3f& value)
{
    assert(program.isLinked());
    program.bind();
    GLuint id = glGetUniformLocation(program.programId(),name);
    if(id==-1)
        printf("!!!WARNING: shader '%d' does not contain uniform variable '%s'\n", program.programId(), name);
    glUniformMatrix3fv(id, 1, GL_FALSE, value.data());
    program.release();
}
示例#3
0
void Cube::render(const Eigen::Matrix4f& mvMatrix, const Eigen::Matrix4f& prMatrix, const Eigen::Matrix3f& nmMatrix) {
	m_prog.use();

	m_prog.setUniformMat4("mvM", mvMatrix.data());
	m_prog.setUniformMat4("prM", prMatrix.data());
	m_prog.setUniformMat3("nmM", nmMatrix.data());

	m_geom.bind();
	glDrawElements(GL_TRIANGLE_STRIP, 14, GL_UNSIGNED_INT, (char*)NULL);
	m_geom.release();
}
bool ShaderProgram::setUniformValue(const std::string& name,
                                    const Eigen::Matrix3f& matrix)
{
  GLint location = static_cast<GLint>(findUniform(name));
  if (location == -1) {
    m_error = "Could not set uniform " + name + ". No such uniform.";
    return false;
  }
  glUniformMatrix3fv(location, 1, GL_FALSE,
                     static_cast<const GLfloat*>(matrix.data()));
  return true;
}
示例#5
0
mat3 pca(PointCloud &pc) {
    mat3 cov = pc.calcCov();
    Eigen::Matrix3f mat = Eigen::Map<Eigen::Matrix3f>(value_ptr(cov));
    Eigen::EigenSolver<Eigen::Matrix3f> solver(mat);
    Eigen::Vector3f eigenVals = solver.eigenvalues().real();
    Eigen::Matrix3f eigenVecs = solver.eigenvectors().real();

    // Matrix containing eigenvectors in COLUMNS
    mat3 eigM;
    memcpy(value_ptr(eigM), eigenVecs.data(), sizeof(mat3));

    // Sort on eigenvalues (quick bubble-sort)
    float x = 0.0f, y = 0.0f, z = 0.0f;
    int xI = 0, yI = 0, zI = 0;
    for (int i = 0; i < 3; i++) {
        float e = eigenVals[i];
        if (e > x) {
            // shuffle down
            z = y;
            zI = yI;
            y = x;
            yI = xI;
            x = e;
            xI = i;
        }
        else if (e > y) {
            z = y;
            zI = yI;
            y = e;
            yI = i;
        }
        else {
            z = e;
            zI = i;
        }
    }

    // Ordered eigenvectors
    mat3 sortedEig;
    sortedEig[0] = eigM[xI];
    sortedEig[1] = eigM[yI];
    sortedEig[2] = eigM[zI];
    static mat3 prevEig = sortedEig;

    // Stabilization - match up the dot-sign
    for (int i = 0; i < 3; i++) {
        sortedEig[i] *= (dot(sortedEig[i], prevEig[i]) < 0) ? -1 : 1;
    }
    prevEig = sortedEig;
    return sortedEig;
}
void CUDABuildLinearSystemRGBD::applyBL(CameraTrackingInput cameraTrackingInput, Eigen::Matrix3f& intrinsics, CameraTrackingParameters cameraTrackingParameters, float3 anglesOld, float3 translationOld, unsigned int imageWidth, unsigned int imageHeight, unsigned int level, Matrix6x7f& res, LinearSystemConfidence& conf) 
{
	unsigned int localWindowSize = 12;
	if(level != 0) localWindowSize = max(1, localWindowSize/(4*level));

	const unsigned int blockSize = 64;
	const unsigned int dimX = (unsigned int)ceil(((float)imageWidth*imageHeight)/(localWindowSize*blockSize));

	Eigen::Matrix3f intrinsicsRowMajor = intrinsics.transpose(); // Eigen is col major / cuda is row major
	computeNormalEquations(imageWidth, imageHeight, d_output, cameraTrackingInput, intrinsicsRowMajor.data(), cameraTrackingParameters, anglesOld, translationOld, localWindowSize, blockSize);

	cutilSafeCall(cudaMemcpy(h_output, d_output, sizeof(float)*30*dimX, cudaMemcpyDeviceToHost));

	// Copy to CPU
	res = reductionSystemCPU(h_output, dimX, conf);
}
示例#7
0
// Eigen types to GLM types
glm::mat3 eigen_matrix3f_to_glm_mat3(const Eigen::Matrix3f &m)
{
    return glm::make_mat3x3((const float *)m.data());
}
示例#8
0
void WarpPosShader::setHomography(const Eigen::Matrix3f &h)
{
	glUseProgram(mProgram.getId());
	glUniformMatrix3fv(mUniformHomography, 1, false, h.data());
}