/// @overload QGLWidget void paintGL(){ vao.bind(); program.bind(); { ///--- Update modelview #ifdef WITH_QGLVIEWER /// use the trackball to specify the matrices setup_modelview(camera(), program); #else ///--- simple unit cube orthographic view static Eigen::Matrix4f M = Eigen::Matrix4f::Identity(); static Eigen::Matrix4f P = Eigen::ortho(-1.0f, +1.0f, -1.0f, +1.0f, -1.0f, +1.0f); static Eigen::Matrix4f V = Eigen::Matrix4f::Identity(); static Eigen::Matrix4f MV = V*M; static Eigen::Matrix4f MVP = P*MV; GLint MVP_id = glGetUniformLocation(program.programId(), "MVP"); glUniformMatrix4fv(MVP_id, 1, GL_FALSE, MVP.data()); GLint MV_id = glGetUniformLocation(program.programId(), "MV"); glUniformMatrix4fv(MV_id, 1, GL_FALSE, MV.data()); #endif ///--- clear & draw glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glDrawElements(GL_TRIANGLES, triangles.size(), GL_UNSIGNED_INT, 0); } vao.release(); program.release(); }
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(); }
void TextureWarpShader::setMVPMatrix(const Eigen::Matrix4f &mvp) { //Transpose to opengl column-major format glUseProgram(mProgram.getId()); glUniformMatrix4fv(mUniformMVPMatrix, 1, false, mvp.data()); glUseProgram(mProgram_Alpha.getId()); glUniformMatrix4fv(mUniformMVPMatrix_Alpha, 1, false, mvp.data()); glUseProgram(mProgram_Color.getId()); glUniformMatrix4fv(mUniformMVPMatrix_Color, 1, false, mvp.data()); }
void stabilityWindow::updateCoM() { if (!comVisu || comVisu->getNumChildren() == 0) { return; } // Draw CoM Eigen::Matrix4f globalPoseCoM; globalPoseCoM.setIdentity(); if (currentRobotNodeSet) { globalPoseCoM.block(0, 3, 3, 1) = currentRobotNodeSet->getCoM(); } else if (robot) { globalPoseCoM.block(0, 3, 3, 1) = robot->getCoMGlobal(); } SoMatrixTransform* m = dynamic_cast<SoMatrixTransform*>(comVisu->getChild(0)); if (m) { SbMatrix ma(reinterpret_cast<SbMat*>(globalPoseCoM.data())); // mm -> m ma[3][0] *= 0.001f; ma[3][1] *= 0.001f; ma[3][2] *= 0.001f; m->matrix.setValue(ma); } // Draw CoM projection if (currentRobotNodeSet && comProjectionVisu && comProjectionVisu->getNumChildren() > 0) { globalPoseCoM(2, 3) = 0; m = dynamic_cast<SoMatrixTransform*>(comProjectionVisu->getChild(0)); if (m) { SbMatrix ma(reinterpret_cast<SbMat*>(globalPoseCoM.data())); // mm -> m ma[3][0] *= 0.001f; ma[3][1] *= 0.001f; ma[3][2] *= 0.001f; m->matrix.setValue(ma); } } }
void nsgl::sendUniMat4(Program &prog, const std::string & uniName, const Eigen::Matrix4f & mat4) { if (prog.getUniform(uniName).isValid()) { glUniformMatrix4fv(prog.getUniform(uniName).location, 1, GL_FALSE, mat4.data()); } }
void nsgl::sendUniMat4v(Program &prog, const std::string & uniName, int numToSend, const Eigen::Matrix4f & firstMat4) { if (prog.getUniform(uniName).isValid()) { glUniformMatrix4fv(prog.getUniform(uniName).location, numToSend, GL_FALSE, firstMat4.data()); } }
void stabilityWindow::comTargetMovedX(int value) { if(!currentRobotNodeSet) return; Eigen::Matrix4f T; T.setIdentity(); m_CoMTarget(0) = value; T.block(0, 3, 2, 1) = m_CoMTarget; if(comTargetVisu && comTargetVisu->getNumChildren() > 0) { SoMatrixTransform *m = dynamic_cast<SoMatrixTransform *>(comTargetVisu->getChild(0)); if(m) { SbMatrix ma(reinterpret_cast<SbMat*>(T.data())); // mm -> m ma[3][0] *= 0.001f; ma[3][1] *= 0.001f; ma[3][2] *= 0.001f; m->matrix.setValue(ma); } } performCoMIK(); }
void view() { // 透視変換を操作するお!と宣言 glMatrixMode(GL_PROJECTION); // 正規行列を読み込む glLoadIdentity(); glViewport(0, 0, Width, Height); // 透視変換行列を作成して適用 // glFrustum(GLdouble left, GLdouble right, // GLdouble bottom, GLdouble top, // GLdouble near, GLdouble far); // 左端の座標、右端の座標 // 下端の座標、上端の座標 // 最前面までの距離、最前面までの距離(距離はどちらも0より大きい値) /*glFrustum( -1, 1, 1, -1, 0.5, 20.0);*/ // Eigenの行列をOpenGLに渡す float aspect = Width / float(Height); Eigen::Matrix4f m = perspectiveView(36, aspect, 0.5, 50); glMultMatrixf(m.data()); // モデリング行列を操作するお!と宣言 glMatrixMode(GL_MODELVIEW); // 正規行列を読み込む glLoadIdentity(); }
// had to separate declaration from implementation due to compilation errors on linux void ObjectRenderer::set_uniform(const char* name, const Eigen::Matrix4f& 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); glUniformMatrix4fv(id, 1, GL_FALSE, value.data()); program.release(); }
HRESULT DX11BuildLinearSystem::applyBL( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11ShaderResourceView* correspondenceSRV, ID3D11ShaderResourceView* correspondenceNormalsSRV, D3DXVECTOR3& mean, float meanStDev, Eigen::Matrix4f& deltaTransform, unsigned int imageWidth, unsigned int imageHeight, unsigned int level, Matrix6x7f& res, LinearSystemConfidence& conf ) { HRESULT hr = S_OK; unsigned int dimX = (unsigned int)ceil(((float)imageWidth*imageHeight)/(GlobalCameraTrackingState::getInstance().s_localWindowSize[level]*m_blockSizeBL)); Eigen::Matrix4f deltaTransformT = deltaTransform.transpose(); // Initialize Constant Buffer D3D11_MAPPED_SUBRESOURCE mappedResource; V_RETURN(context->Map(m_constantBufferBL, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource)) CBufferBL *cbuffer = (CBufferBL*)mappedResource.pData; cbuffer->imageWidth = (int)imageWidth; cbuffer->imageHeigth = (int)imageHeight; memcpy(cbuffer->deltaTransform, deltaTransformT.data(), 16*sizeof(float)); cbuffer->imageHeigth = (int)imageHeight; memcpy(cbuffer->mean, (float*)mean, 3*sizeof(float)); cbuffer->meanStDevInv = 1.0f/meanStDev; context->Unmap(m_constantBufferBL, 0); // Setup Pipeline context->CSSetShaderResources(0, 1, &inputSRV); context->CSSetShaderResources(1, 1, &correspondenceSRV); context->CSSetShaderResources(2, 1, &correspondenceNormalsSRV); context->CSSetUnorderedAccessViews(0, 1, &m_pOutputFloatUAV, 0); context->CSSetConstantBuffers(0, 1, &m_constantBufferBL); context->CSSetShader(m_pComputeShaderBL[level], 0, 0); // Start Compute Shader context->Dispatch(dimX, 1, 1); assert(dimX <= D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION); // De-Initialize Pipeline ID3D11ShaderResourceView* nullSAV[1] = { NULL }; ID3D11UnorderedAccessView* nullUAV[1] = { NULL }; ID3D11Buffer* nullCB[1] = { NULL }; context->CSSetShaderResources(0, 1, nullSAV); context->CSSetShaderResources(1, 1, nullSAV); context->CSSetShaderResources(2, 1, nullSAV); context->CSSetUnorderedAccessViews(0, 1, nullUAV, 0); context->CSSetConstantBuffers(0, 1, nullCB); context->CSSetShader(0, 0, 0); // Copy to CPU context->CopyResource(m_pOutputFloatCPU, m_pOutputFloat); V_RETURN(context->Map(m_pOutputFloatCPU, 0, D3D11_MAP_READ, 0, &mappedResource)); res = reductionSystemCPU((float*)mappedResource.pData, dimX, conf); context->Unmap(m_pOutputFloatCPU, 0); return hr; }
bool ShaderProgram::setUniformValue(const std::string& name, const Eigen::Matrix4f& matrix) { GLint location = static_cast<GLint>(findUniform(name)); if (location == -1) { m_error = "Could not set uniform " + name + ". No such uniform."; return false; } glUniformMatrix4fv(location, 1, GL_FALSE, static_cast<const GLfloat*>(matrix.data())); return true; }
void MainCamera::perspView() { float f = float(1. / std::tan(toRadians(fovy_) * 0.5)); float g = -((far_ + near_) / (far_ - near_)); float h = -((2 * far_ * near_) / (far_ - near_)); float i = f / aspect_; Eigen::Matrix4f m; m << i, 0.0f, 0.0f, 0.0f, 0.0f, f, 0.0f, 0.0f, 0.0f, 0.0f, g, h, 0.0f, 0.0f, -1, 0.0f; glMultMatrixf(m.data()); }
void display_form(int form, Eigen::Matrix4f marker_matrix, float falling){ glMatrixMode(GL_MODELVIEW); glColor4f(1.0, 0.0, 0.0, 1.0); //transform to marker glLoadTransposeMatrixf(marker_matrix.data()); glTranslatef(0.0, 0.0, falling); //move to marker position if(form == 0){ glutSolidSphere(0.02, 10, 100); } else { drawCube(0.04); } }
void display_fallthrough(Eigen::Matrix4f marker_matrix){ glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glColor4f(0.0, 0.0, 0.0, 1.0); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); //transform to marker glLoadTransposeMatrixf(marker_matrix.data()); glTranslatef(0.0, 0.0, 0.06); drawCube(0.08); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); }
Eigen::Matrix4f orthoMatrix( GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLfloat nearz, GLfloat farz ) { GLfloat const tx = -((right + left) / (right - left)); GLfloat const ty = -((top + bottom) / (top - bottom)); GLfloat const tz = -((farz + nearz) / (farz - nearz)); GLfloat const matrix[] = { 2.0f / (right - left), 0.0f, 0.0f, tx, 0.0f, 2.0f / (top - bottom), 0.0f, ty, 0.0f, 0.0f, -2.0f / (farz - nearz), tz, 0.0f, 0.0f, 0.0f, 1.0f, }; Eigen::Matrix4f result; ::memcpy(result.data(), matrix, sizeof(matrix)); result.matrix().transposeInPlace(); return result; }
void MainCamera::lookToTarget() { Vec3f z = getForward() / getForward().length(); Vec3f b = up_.cross(z); Vec3f x = b / b.length(); Vec3f y = z.cross(x); Eigen::Matrix4f R; R << x.x, x.y, x.z, 0.0f, y.x, y.y, y.z, 0.0f, z.x, z.y, z.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f; Eigen::Matrix4f T; T << 1.0f, 0.0f, 0.0f, -pos_.x, 0.0f, 1.0f, 0.0f, -pos_.y, 0.0f, 0.0f, 1.0f, -pos_.z, 0.0f, 0.0f, 0.0f, 1.0f; Eigen::Matrix4f m = R * T; glMultMatrixf(m.data()); }
bool CameraPoseFinderICP::estimateCameraPose(const DepthFrameData& depth_frame,const ColorFrameData& color_frame) { if(depth_frame.frameId()==0) { return true; } //prepare datas cudaDownSampleNewVertices(); cudaDownSampleNewNormals(); cudaDownSampleModelVertices(); cudaDownSampleModelNormals(); Mat44 cur_transform=_pose; Mat44 last_transform_inv=_pose.getInverse(); Eigen::Matrix<float, 6, 1, 0, 6, 1> delta_dof; for(int l=_iter_nums.size()-1;l>=0;l--) { int it_nums=_iter_nums[l]; while(it_nums--) { // findCorresSet(l,cur_transform,last_transform_inv); if(false==minimizePointToPlaneErrFunc(l,delta_dof,cur_transform,last_transform_inv)) return false; Eigen::Matrix4f t = Eigen::Matrix4f::Identity(); if (false==vector6ToTransformMatrix(delta_dof, t) ) { cout<<"camera shaking detected"<<endl; return false; } //eigen matrix to mat44 Eigen::Matrix4f tt = t.transpose(); Mat44 mat_t(tt.data()); cur_transform = mat_t*cur_transform; } } _pose=cur_transform; return true; }
Eigen::Matrix4f perspectiveMatrix( GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLfloat nearz, GLfloat farz ) { GLfloat const A = (right + left) / (right - left); GLfloat const B = (top + bottom) / (top - bottom); GLfloat const C = -(farz + nearz) / (farz - nearz); GLfloat const D = -(2.0f*farz*nearz) / (farz - nearz); GLfloat const matrix[] = { 2.0f * nearz / (right - left), 0.0f, A, 0.0f, 0.0f, 2.0f * nearz / (top - bottom), B, 0.0f, 0.0f, 0.0f, C, D, 0.0f, 0.0f, -1.0f, 0.0f, }; Eigen::Matrix4f result; ::memcpy(result.data(), matrix, sizeof(matrix)); result.matrix().transposeInPlace(); return result; }
//------------------------------------------------------------------------------ int main(int argc, char** argv) { //GRAPHICS SETUP glfwSetErrorCallback(error_callback); if(!glfwInit()) { std::cerr << "ERROR - glfwInit" << std::endl; exit(EXIT_FAILURE); } GLFWwindow* window = glfwCreateWindow(800, 600, "Ray 1!", NULL, NULL); if (!window) { std::cerr << "ERROR - glfwCreateWindow" << std::endl; glfwTerminate(); exit(EXIT_FAILURE); } glfwSetKeyCallback(window, key_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; //GEOMETRY //geometry: textured quad float quad[] = {-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f}; float texcoord[] = {0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; //OpenGL >= 3.3 core requires a vertex array object containing multiple attribute //buffers GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); //geometry buffer GLuint quadvbo; glGenBuffers(1, &quadvbo); glBindBuffer(GL_ARRAY_BUFFER, quadvbo); glBufferData(GL_ARRAY_BUFFER, 6 * 4 * sizeof(float), &quad[0], GL_STATIC_DRAW); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); //texture coordinate buffer GLuint texbo; glGenBuffers(1, &texbo); glBindBuffer(GL_ARRAY_BUFFER, texbo); glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(float), &texcoord[0], GL_STATIC_DRAW); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); //OPENGL RENDERING SHADERS GLuint glprogram = create_program(vertexShaderSrc, fragmentShaderSrc); //enable gl program glUseProgram(glprogram); //extract ids of shader variables GLint mvpID = glGetUniformLocation(glprogram, "MVP"); assert(mvpID>=0); GLint textureID = glGetUniformLocation(glprogram, "cltexture"); assert(textureID>=0); //beckground color glClearColor(0.0f, 0.0f, 0.4f, 1.0f); g_Backbuffer = std::make_shared<Backbuffer>(); int width, height; glfwGetFramebufferSize(window, &width, &height); framebuffer_size_callback(window, width, height); //RENDER LOOP //rendering & simulation loop while (!glfwWindowShouldClose(window)) { // Clear the screen glClear(GL_COLOR_BUFFER_BIT); //setup OpenGL matrices const Eigen::Matrix4f modelView = Eigen::Matrix4f::Identity(); const Eigen::Matrix4f MVP = g_Backbuffer->m_Projection * modelView; glUniformMatrix4fv(mvpID, 1, GL_FALSE, MVP.data()); //only need texture unit 0 glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, g_Backbuffer->m_Texture); glUniform1i(textureID, 0); //select geometry to render glBindVertexArray(vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); //draw glDrawArrays(GL_TRIANGLES, 0, 6); //unbind glBindVertexArray(0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glBindTexture(GL_TEXTURE_2D, 0); //put pixels on screen glfwSwapBuffers(window); //query events glfwPollEvents(); } //CLEANUP glDeleteBuffers(1, &quadvbo); glDeleteBuffers(1, &texbo); glDeleteVertexArrays(1, &vao); g_Backbuffer.reset(); glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); return 0; }
void Scene::DrawScene(ParticleSystem* m, double strainSize, bool drawPoints) { int pSize; int cSize; //float* points = m->GetPositions3d(&pSize); //float* colors = m->GetColors(&cSize, strainSize); float *points, *colors; switch(drawMode) { case 0: points = m->GetSurfaceTriangles3d(&pSize); colors = m->GetTriColors(&cSize, strainSize); break; case 1: points = m->GetPositions3d(&pSize, prevMode); colors = m->GetColors(&cSize, strainSize, xpos, ypos, zpos); break; case 2: points = m->GetSurfaceTriangles3d(&pSize); colors = m->GetStrainSurfaceTriColors(&cSize, strainSize); break; case 3: points = m->GetTetCenter(&pSize); colors = m->GetCenterColors(&cSize, strainSize); break; case 4: points = m->GetAllTriangles3d(&pSize); colors = m->GetStrainAllTriColors(&cSize, strainSize); break; } Eigen::Matrix4f rotationMatrix; Eigen::Matrix4f projectionMatrix; rotationMatrix.setZero(); projectionMatrix.setZero(); Eigen::Vector3f pos, target, up; pos << xpos, ypos, zpos; m->GetCameraPosAndSize(&xtarg, &ytarg, &ztarg); target << xtarg, ytarg, ztarg; up << 0, -1, 0; RotationMatrix(pos, target, up, rotationMatrix); PerspectiveMatrix((65*PI)/180.0, ((float)DDWIDTH)/DDHEIGHT, .5, 100, projectionMatrix); g_viewMatrix = projectionMatrix * rotationMatrix; DrawDelegate::BeginFrame(); DrawDelegate::SetViewMatrix(g_viewMatrix.data()); Scene::DrawGrid(1, m->groundLevel); if (drawPoints) { DrawDelegate::SetLineSize(3); switch(drawMode) { case 0: DrawDelegate::DrawTriangles(points, pSize, colors, cSize); break; case 1: DrawDelegate::DrawLines(points, pSize, colors, cSize); break; case 2: DrawDelegate::DrawTriangles(points, pSize, colors, cSize); break; case 3: DrawDelegate::DrawPoints(points, pSize, colors, cSize); break; case 4: DrawDelegate::DrawTriangles(points, pSize, colors, cSize); break; } } }
glm::mat4 eigen_matrix4f_to_glm_mat4(const Eigen::Matrix4f &m) { return glm::make_mat4x4((const float *)m.data()); }
int main() { if (!glfwInit()) return -1; GLFWwindow* window = glfwCreateWindow(Width, Height, "08 Matrix", nullptr, nullptr); if (!window) { glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Windowのサイズが変更された際に呼ばれる関数を設定 glfwSetWindowSizeCallback(window, resize); glfwSwapInterval(1); float angle = 0.0f; while (!glfwWindowShouldClose(window)) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); view(); glTranslatef(0.0f, 0.0f, -1.5f); // 回転行列を適用 // angle: 回転量(単位:degrees) 一周360c // x, y, z: 回転軸を表すベクトル(単位ベクトルでなくてよい) glRotatef(angle, 0.0f, 1.0f, 0.0f); //angle += 1.0f; drawCircle(Vec2f(0, 0), 5, 0.4, Color(1, 1, 1)); view(); static Eigen::Vector3f camera_pos(0, 0, 2.0); static Eigen::Vector3f target_pos(0, 0, 0); static Eigen::Vector3f camera_up(0, 1, 0); Eigen::Matrix4f cm = lookAt(camera_pos, target_pos, camera_up); glMultMatrixf(cm.data()); static Eigen::Vector3f camera_rotate(0, 0, 0); //camera_rotate.x() += 0.1f; camera_rotate.y() += 0.1f; glRotatef(-camera_rotate.x(), 1.0f, 0.0f, 0.0f); glRotatef(-camera_rotate.y(), 0.0f, 1.0f, 0.0f); glRotatef(-camera_rotate.z(), 0.0f, 0.0f, 1.0f); glTranslatef(-camera_pos.x(), -camera_pos.y(), -camera_pos.z()); drawCircle(Vec2f(0, 0), 5, 0.2, Color(0, 0, 1)); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; }
void OpenGLRenderer::SetProjectionMatrix(const Eigen::Matrix4f& m) { glMatrixMode(GL_PROJECTION); glLoadMatrixf(m.data()); }
Matrix4 Helper::convertFromEigenMatrix(const Eigen::Matrix4f &M) { Matrix4 mat = *(Matrix4 *)M.data(); return mat; }
void glsl_program::set_uniform(unsigned loc, const Eigen::Matrix4f& value) const { if (used_program != this) throw runtime_error("glsl_program::set_uniform, program not bound!"); glUniformMatrix4fv(loc, 1, false, value.data()); }
int volumetric_knt_cuda(int argc, char **argv) { Timer timer; int vol_size = vx_count * vx_size; float half_vol_size = vol_size * 0.5f; Eigen::Vector3i voxel_size(vx_size, vx_size, vx_size); Eigen::Vector3i volume_size(vol_size, vol_size, vol_size); Eigen::Vector3i voxel_count(vx_count, vx_count, vx_count); int total_voxels = voxel_count.x() * voxel_count.y() * voxel_count.z(); std::cout << std::fixed << "Voxel Count : " << voxel_count.transpose() << std::endl << "Voxel Size : " << voxel_size.transpose() << std::endl << "Volume Size : " << volume_size.transpose() << std::endl << "Total Voxels : " << total_voxels << std::endl << std::endl; timer.start(); KinectFrame knt(filepath); timer.print_interval("Importing knt frame : "); Eigen::Affine3f grid_affine = Eigen::Affine3f::Identity(); grid_affine.translate(Eigen::Vector3f(0, 0, half_vol_size)); grid_affine.scale(Eigen::Vector3f(1, 1, -1)); // z is negative inside of screen Eigen::Matrix4f grid_matrix = grid_affine.matrix(); float knt_near_plane = 0.1f; float knt_far_plane = 10240.0f; Eigen::Matrix4f projection = perspective_matrix<float>(KINECT_V2_FOVY, KINECT_V2_DEPTH_ASPECT_RATIO, knt_near_plane, knt_far_plane); Eigen::Matrix4f projection_inverse = projection.inverse(); Eigen::Matrix4f view_matrix = Eigen::Matrix4f::Identity(); std::vector<float4> vertices(knt.depth.size(), make_float4(0, 0, 0, 1)); std::vector<float4> normals(knt.depth.size(), make_float4(0, 0, 1, 1)); std::vector<Eigen::Vector2f> grid_voxels_params(total_voxels); // // setup image parameters // unsigned short image_width = 2; unsigned short image_height = 2; uchar4* image_data = new uchar4[image_width * image_height]; memset(image_data, 0, image_width * image_height * sizeof(uchar4)); float4* debug_buffer = new float4[image_width * image_height]; memset(debug_buffer, 0, image_width * image_height * sizeof(float4)); knt_cuda_setup( vx_count, vx_size, grid_matrix.data(), projection.data(), projection_inverse.data(), *grid_voxels_params.data()->data(), KINECT_V2_DEPTH_WIDTH, KINECT_V2_DEPTH_HEIGHT, KINECT_V2_DEPTH_MIN, KINECT_V2_DEPTH_MAX, vertices.data()[0], normals.data()[0], image_width, image_height, *image_data, *debug_buffer ); timer.start(); knt_cuda_allocate(); knt_cuda_init_grid(); timer.print_interval("Allocating gpu : "); timer.start(); knt_cuda_copy_host_to_device(); knt_cuda_copy_depth_buffer_to_device(knt.depth.data()); timer.print_interval("Copy host to device : "); timer.start(); knt_cuda_normal_estimation(); timer.print_interval("Normal estimation : "); timer.start(); knt_cuda_update_grid(view_matrix.data()); timer.print_interval("Update grid : "); timer.start(); knt_cuda_grid_params_copy_device_to_host(); knt_cuda_copy_device_to_host(); timer.print_interval("Copy device to host : "); timer.start(); knt_cuda_free(); timer.print_interval("Cleanup gpu : "); timer.start(); Eigen::Affine3f grid_affine_2 = Eigen::Affine3f::Identity(); grid_affine_2.translate(Eigen::Vector3f(-half_vol_size, -half_vol_size, -vol_size)); export_volume( "../../data/grid_volume_gpu_knt.obj", voxel_count, voxel_size, grid_voxels_params); //grid_affine_2.matrix()); export_obj_with_colors("../../data/knt_grid_frame_normals.obj", vertices, normals); timer.print_interval("Exporting volume : "); return 0; }
void AutoBlend::init() { // Add widget auto toolsWidgetContainer = new QWidget(); widget = new Ui::AutoBlendWidget(); widget->setupUi(toolsWidgetContainer); widgetProxy = new QGraphicsProxyWidget(this); widgetProxy->setWidget(toolsWidgetContainer); // Place at bottom left corner auto delta = widgetProxy->sceneBoundingRect().bottomLeft() - scene()->views().front()->rect().bottomLeft(); widgetProxy->moveBy(-delta.x(), -delta.y()); // Fill categories box { for(auto cat : document->categories.keys()){ widget->categoriesBox->insertItem(widget->categoriesBox->count(), cat); } int idx = widget->categoriesBox->findText(document->categoryOf(document->firstModelName())); widget->categoriesBox->setCurrentIndex(idx); } // Create gallery of shapes gallery = new Gallery(this, QRectF(0,0,this->bounds.width(), 220)); // Create container that holds results results = new Gallery(this, QRectF(0,0, this->bounds.width(), bounds.height() - gallery->boundingRect().height()), QRectF(0,0,256,256), true); results->moveBy(0, gallery->boundingRect().height()); // Gallery on top of results gallery->setZValue(results->zValue() + 10); auto dropShadow = new QGraphicsDropShadowEffect(); dropShadow->setOffset(0, 5); dropShadow->setColor(QColor(0, 0, 0, 150)); dropShadow->setBlurRadius(10); gallery->setGraphicsEffect(dropShadow); // Connect UI with actions { connect(widget->categoriesBox, &QComboBox::currentTextChanged, [&](QString text){ document->currentCategory = text; }); connect(widget->analyzeButton, &QPushButton::pressed, [&](){ document->computePairwise(widget->categoriesBox->currentText()); }); // Default view angle { // Camera target and initial position auto camera = new Eigen::Camera(); auto frame = camera->frame(); frame.position = Eigen::Vector3f(-1, 0, 0.5); camera->setTarget(Eigen::Vector3f(0, 0, 0.5)); camera->setFrame(frame); int deltaZoom = document->extent().length() * 1.0; // Default view angle double theta1 = acos(-1) * 0.75; double theta2 = acos(-1) * 0.10; camera->rotateAroundTarget(Eigen::Quaternionf(Eigen::AngleAxisf(theta1, Eigen::Vector3f::UnitY()))); camera->zoom(-(4+deltaZoom)); camera->rotateAroundTarget(Eigen::Quaternionf(Eigen::AngleAxisf(theta2, Eigen::Vector3f::UnitX()))); auto cp = camera->position(); cameraPos = QVector3D(cp[0], cp[1], cp[2]); // Camera settings camera->setViewport(128, 128); Eigen::Matrix4f p = camera->projectionMatrix(); Eigen::Matrix4f v = camera->viewMatrix().matrix(); p.transposeInPlace(); v.transposeInPlace(); cameraMatrix = QMatrix4x4(p.data()) * QMatrix4x4(v.data()); } connect(document, &Document::categoryAnalysisDone, [=](){ if (gallery == nullptr) return; // Fill gallery gallery->clearThumbnails(); auto catModels = document->categories[document->currentCategory].toStringList(); for (auto targetName : catModels) { auto targetModel = document->cacheModel(targetName); auto t = gallery->addTextItem(targetName); QVariantMap data = t->data; data["targetName"].setValue(targetName); t->setData(data); t->setCamera(cameraPos, cameraMatrix); t->setFlag(QGraphicsItem::ItemIsSelectable); // Add parts of target shape for (auto n : targetModel->nodes){ t->addAuxMesh(toBasicMesh(targetModel->getMesh(n->id), n->vis_property["color"].value<QColor>())); } scene()->update(t->sceneBoundingRect()); } scene()->update(this->sceneBoundingRect()); QTimer::singleShot(500, [=]{ gallery->update(); }); }); // Do blend connect(widget->blendButton, SIGNAL(pressed()), SLOT(doBlend())); } }
void set_uniform_matrix(GLuint programID, const char* NAME, const Eigen::Matrix4f& matrix) { GLuint matrix_id = glGetUniformLocation(programID, NAME); glUniformMatrix4fv(matrix_id, 1, GL_FALSE, matrix.data()); }
void WarpPosShader::setMVPMatrix(const Eigen::Matrix4f &mvp) { glUseProgram(mProgram.getId()); glUniformMatrix4fv(mUniformMVPMatrix, 1, false, mvp.data()); }
void OpenGLRenderer::SetModelViewMatrix(const Eigen::Matrix4f& m) { glMatrixMode(GL_MODELVIEW); glLoadMatrixf(m.data()); }