diff --git a/shaders/edge_gs.glsl b/shaders/edge_gs.glsl index 5403e28..9ce02ad 100644 --- a/shaders/edge_gs.glsl +++ b/shaders/edge_gs.glsl @@ -18,17 +18,19 @@ void main() { p0.z -= 0.00125f; p1.z -= 0.00125f; - color = vec3(0.f, 1.f, 0.2f); + color = vec3(0.0f, 1.0f, 0.2f); } - else if (bool(flag & 2u)) + else// Regular edge { - color = vec3(1.f, 0.f, 0.f); + color = vec3(0.0f, 0.0f, 1.0f); } - else// Regular edge + + // Selected edge will override edge color + if (bool(flag & 2u)) { - color = vec3(0.f, 0.f, 1.f); + color = vec3(1.f, 0.25f, 0.0f); } - + gl_Position = p0; EmitVertex(); diff --git a/shaders/uid_fs.glsl b/shaders/uid_fs.glsl index 8120065..2945086 100644 --- a/shaders/uid_fs.glsl +++ b/shaders/uid_fs.glsl @@ -10,22 +10,26 @@ void main() switch (mode) { case 0://background + { frag_color = vec4(0.f, 0.f, 0.f, 0.f); break; + } case 1://vertex + { uid = gl_PrimitiveID; - frag_color = vec4(float(uid >> 16) / 255.0, - float((uid >> 8) & 0xFF) / 255.0, - float(uid & 0xFF) / 255.0, 1.0); + frag_color = vec4(float(uid >> 16) / 255.0f, + float((uid >> 8) & 0xFF) / 255.0f, + float(uid & 0xFF) / 255.0f, 1.0f); break; + } case 2://edge or face + { uid = int(texelFetch(id_tex, gl_PrimitiveID).r); - //uid = gl_PrimitiveID; - frag_color = vec4(float(uid >> 16) / 255.0, - float((uid >> 8) & 0xFF) / 255.0, - float(uid & 0xFF) / 255.0, 1.0); - break; - default: + frag_color = vec4(float(uid >> 16) / 255.0f, + float((uid >> 8) & 0xFF) / 255.0f, + float(uid & 0xFF) / 255.0f, 1.0f); break; } + default: break; + } } \ No newline at end of file diff --git a/src/MeshViewer.cpp b/src/MeshViewer.cpp index 2426767..14345ec 100644 --- a/src/MeshViewer.cpp +++ b/src/MeshViewer.cpp @@ -6,17 +6,16 @@ MeshViewer::MeshViewer(QWidget *parent) : QOpenGLWidget(parent) - //, vtx_vbo(oglBuffer::Type::VertexBuffer) , interactionState(ROAM_CAMERA) - //, selectionState(SingleSelect) , heMesh(nullptr) + , renderFlag(0) , shadingSate(SHADE_WF_FLAT) , dispComp(DispComp::DISP_GRID) , hlComp(HighlightComp::HIGHLIGHT_CUTEDGE) , grid(4, 6.0f, this) - , view_cam(QVector3D(4, 2, 4), QVector3D(0.0, 0.0, 0.0), QVector3D(0, 1, 0) - , 54.3, 1.67, 0.1, 100) - , mesh_changed(false), scale(1.0) + , view_cam(QVector3D(4, 2, 4), QVector3D(0, 0, 0), + QVector3D(0, 1, 0), 54.3, 1.67, 0.1, 100) + , mesh_changed(false), view_scale(1.0) , vRBO(this), fRBO(this), heRBO(this) { // Set surface format for current widget @@ -131,9 +130,14 @@ void MeshViewer::initializeGL() glGenBuffers(2, fRBO.tbo); } - void MeshViewer::allocateGL() { + // Clear Selection + while (!selVTX.empty()) selVTX.pop(); + while (!selHE.empty()) selHE.pop(); + while (!selFACE.empty()) selFACE.pop(); + heMesh->exportSelection(&selVTX, &selHE, &selFACE); + heMesh->exportVertVBO(&vtx_array, &vRBO.flags); heMesh->exportEdgeVBO(&heRBO.ibos, &heRBO.ids, &heRBO.flags); heMesh->exportFaceVBO(&fRBO.ibos, &fRBO.ids, &fRBO.flags); @@ -162,24 +166,6 @@ void MeshViewer::allocateGL() mesh_changed = false; } -/* -void MeshViewer::createPrimitiveBuffers(RenderBufferObject &RBO) -{ - // Bind VAO - RBO.vao.create(); - RBO.vao.bind(); - - RBO.vbo->bind(); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); - glEnableVertexAttribArray(0); - - RBO.ibo.create(); - RBO.ibo.setUsagePattern(oglBuffer::StaticDraw); - RBO.ibo.bind(); - - RBO.releaseAll(); -}*/ - void MeshViewer::initShader() { ////////////////////////////////////////////////////////////////////////// @@ -215,7 +201,7 @@ void MeshViewer::initShader() void MeshViewer::initializeFBO() { fbo.reset(new oglFBO(width(), height(), oglFBO::CombinedDepthStencil, GL_TEXTURE_2D)); -// selectionBuffer.resize(width()*height() * 4); + //selectionBuffer.resize(width()*height() * 4); } void MeshViewer::drawMeshToFBO() @@ -229,7 +215,7 @@ void MeshViewer::drawMeshToFBO() uid_shader.bind(); uid_shader.setUniformValue("proj_matrix", view_cam.CameraToScreen); uid_shader.setUniformValue("view_matrix", view_cam.WorldToCamera); - uid_shader.setUniformValue("scale", static_cast(scale)); + uid_shader.setUniformValue("scale", static_cast(view_scale)); switch (interactionState) { @@ -282,7 +268,7 @@ void MeshViewer::drawMeshToFBO() } glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glLineWidth(2); + glLineWidth(10); heRBO.vao.bind(); @@ -356,9 +342,11 @@ void MeshViewer::drawMeshToFBO() { if (selected) { - //renderID = heRBO.flags[renderID]; + auto he = heMesh->heMap.at(renderID); + auto hef = he->flip; selHE.push(renderID); - heMesh->heMap.at(renderID)->isPicked = true; + selHE.push(hef->index); + he->isPicked = hef->isPicked = true; } else { @@ -373,8 +361,9 @@ void MeshViewer::drawMeshToFBO() break; } } - +#ifdef _DEBUG cout << "draw primitive id:" << renderID << endl; +#endif // DEBUG } void MeshViewer::paintGL() @@ -434,7 +423,7 @@ void MeshViewer::paintGL() vtx_solid_shader.bind(); vtx_solid_shader.setUniformValue("proj_matrix", view_cam.CameraToScreen); vtx_solid_shader.setUniformValue("view_matrix", view_cam.WorldToCamera); - vtx_solid_shader.setUniformValue("scale", static_cast(scale)); + vtx_solid_shader.setUniformValue("scale", static_cast(view_scale)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_BUFFER, vRBO.flag_tex); glTexBuffer(GL_TEXTURE_BUFFER, GL_R16UI, vRBO.flag_tbo); @@ -457,7 +446,7 @@ void MeshViewer::paintGL() face_solid_shader.setUniformValue("proj_matrix", view_cam.CameraToScreen); face_solid_shader.setUniformValue("view_matrix", view_cam.WorldToCamera); glUniform1ui(oglUniLoc(face_solid_shader, "hl_comp"), hlComp); - face_solid_shader.setUniformValue("scale", static_cast(scale)); + face_solid_shader.setUniformValue("scale", static_cast(view_scale)); // Bind Texture Buffer glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_BUFFER, fRBO.flag_tex); @@ -481,7 +470,7 @@ void MeshViewer::paintGL() edge_solid_shader.setUniformValue("view_matrix", view_cam.WorldToCamera); //edge_solid_shader.setUniformValue("hl_comp", (GLuint)hlComp); glUniform1ui(oglUniLoc(edge_solid_shader, "hl_comp"), hlComp); - edge_solid_shader.setUniformValue("scale", static_cast(scale)); + edge_solid_shader.setUniformValue("scale", static_cast(view_scale)); // Bind Texture Buffer glBindTexture(GL_TEXTURE_BUFFER, heRBO.flag_tex); glTexBuffer(GL_TEXTURE_BUFFER, GL_R16UI, heRBO.flag_tbo); @@ -552,7 +541,10 @@ void MeshViewer::keyPressEvent(QKeyEvent* e) // } case Qt::Key_F: { - resetCamera(); + view_cam.WorldToCamera.setToIdentity(); + view_cam.WorldToCamera.lookAt(QVector3D(4, 2, 4), QVector3D(0, 0, 0), QVector3D(0, 1, 0)); + view_cam.CameraToWorld = view_cam.WorldToCamera.inverted(); + update(); break; } case Qt::Key_M: @@ -767,24 +759,18 @@ void MeshViewer::selectAll() for (auto f : heMesh->faces()) f->setPicked(true); heMesh->exportFaceVBO(nullptr, nullptr, &fRBO.flags); - //fRBO.destroy(); - //createPrimitiveBuffers(fRBO); fRBO.allocateTBO(); break; case SEL_EDGE: for (auto e : heMesh->halfedges()) e->setPicked(true); heMesh->exportEdgeVBO(nullptr, nullptr, &heRBO.flags); - //heRBO.destroy(); - //createPrimitiveBuffers(heRBO); heRBO.allocateTBO(); break; case SEL_VERT: for (auto v : heMesh->verts()) v->setPicked(true); heMesh->exportVertVBO(nullptr, &vRBO.flags); - //initialVBO(); - //allocateVertices(); vRBO.allocateTBO(1);// Bind only flag tbo break; default: @@ -826,9 +812,4 @@ void MeshViewer::selectInverse() break; } update(); -} - -void MeshViewer::resetCamera() -{ - view_cam = perspCamera(QVector3D(4, 2, 4), QVector3D(0.0, 0.0, 0.0)); -} +} \ No newline at end of file diff --git a/src/MeshViewer.h b/src/MeshViewer.h index 2925bfb..e5779b7 100644 --- a/src/MeshViewer.h +++ b/src/MeshViewer.h @@ -156,7 +156,6 @@ class MeshViewer void toggleText(); private: // paint function - void resetCamera(); void allocateGL(); void initShader(); @@ -174,13 +173,13 @@ class MeshViewer SingleSelect = 0, MultiSelect };*/ - enum InteractionState : uint32_t + enum InteractionState : uint8_t { ROAM_CAMERA = 0, - SEL_MULTI = 2, - SEL_VERT = 4, - SEL_FACE = 8, - SEL_EDGE = 16 + SEL_MULTI = 1 << 1, + SEL_VERT = 1 << 2, + SEL_FACE = 1 << 3, + SEL_EDGE = 1 << 4 }; enum DataTypeMark : uint8_t { @@ -254,26 +253,26 @@ class MeshViewer MouseState mouseState; - union SelectionID{ - size_t vertexID; - size_t faceID; - size_t edgeID; - size_t selID; - } selectionID; - private: - bool isCriticalPointModeSet = false; - bool isCutLocusModeset = false; - bool isSelecting; - bool showCLDistance; //show cut locus dists - bool showCPDistance; //show critical points dists - bool showCut; - bool showMultCut; - bool showOneCut; - bool showReebPoints; - bool showText; - bool showVIndex; // show vertex index - + union + { + uint16_t renderFlag; + struct + { + bool isCriticalPointModeSet : 1; + bool isCutLocusModeset : 1; + bool isSelecting : 1; + bool showCLDistance : 1; //show cut locus dists + bool showCPDistance : 1; //show critical points dists + bool showCut : 1; + bool showMultCut : 1; + bool showOneCut : 1; + bool showReebPoints : 1; + bool showText : 1; + bool showVIndex : 1; // show vertex index + }; + }; + uint8_t shadingSate; uint32_t dispComp;//Display Components Flag uint32_t hlComp;// Highlight Components Flag @@ -288,7 +287,7 @@ class MeshViewer HDS_Mesh* heMesh; // not own bool mesh_changed; - double scale; + double view_scale; //QMatrix4x4 model_matrix; // VBOs and VAOs diff --git a/src/hds_mesh.cpp b/src/hds_mesh.cpp index bc83f00..bb78f60 100644 --- a/src/hds_mesh.cpp +++ b/src/hds_mesh.cpp @@ -661,9 +661,10 @@ void HDS_Mesh::exportEdgeVBO( unordered_set visitiedHE; visitiedHE.reserve(heSetSize); - heIBOs->clear(); heIBOs->reserve(heSetSize); + heIDs->clear(); + heIDs->reserve(heSetSize >> 1); heFLAGs->clear(); heFLAGs->reserve(heSetSize >> 1); @@ -915,6 +916,31 @@ void HDS_Mesh::exportFaceVBO( } } +void HDS_Mesh::exportSelection(ui32q_t* selVTX, ui32q_t* selHE, ui32q_t* selFACE) +{ + if (selVTX != nullptr) + { + for (auto v : vertSet) + { + if (v->isPicked) selVTX->push(v->index); + } + } + if (selHE != nullptr) + { + for (auto he : heSet) + { + if (he->isPicked) selHE->push(he->index); + } + } + if (selFACE != nullptr) + { + for (auto f : faceSet) + { + if (f->isPicked) selFACE->push(f->index); + } + } +} + void HDS_Mesh::addHalfEdge(he_t* he) { heSet.insert(he); diff --git a/src/hds_mesh.h b/src/hds_mesh.h index 1024e09..dcb2fdf 100644 --- a/src/hds_mesh.h +++ b/src/hds_mesh.h @@ -89,6 +89,8 @@ class HDS_Mesh ui32s_t* heIDs = nullptr, ui16s_t* heFLAGs = nullptr) const; void exportFaceVBO(ui32s_t* fIBOs = nullptr, ui32s_t* fIDs = nullptr, ui16s_t* fFLAGs = nullptr) const; + using ui32q_t = queue; + void exportSelection(ui32q_t* selVTX, ui32q_t* selHE, ui32q_t* selFACE); unordered_set& halfedges() { return heSet; } unordered_set faces() const { return faceSet; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 354cd75..d858014 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -436,7 +436,7 @@ void MainWindow::createToolBar() connect(scaleValBox, static_cast(&QDoubleSpinBox::valueChanged), [&](double val) { - viewer->scale = val; viewer->update(); }); + viewer->view_scale = val; viewer->update(); }); ui->displayToolBar->addWidget(scaleValBox); ui->displayToolBar->addSeparator(); } @@ -882,7 +882,8 @@ void MainWindow::slot_disableclp() void MainWindow::slot_updateViewerColormap() { - //kkkkkkkkkkk + // TODO: Implement Update Colormap with New Viewer + // or Remove it //viewer->setCurvatureColormap(ceditor->getColormap()); } @@ -913,20 +914,21 @@ void MainWindow::updateCurrentMesh() } void MainWindow::slot_updateCriticalPointsMethod(int midx) { - //kkkkkkkkkkk + // TODO: Implement Critical Point Method with New Viewer //viewer->setCriticalPointsMethod(midx); viewer->update(); } void MainWindow::slot_updateCriticalPointsSmoothingTimes(int times) { - //kkkkkkkkkkk + + // TODO: Implement Critical Point Smooth Time Method with New Viewer //viewer->setCriticalPointsSmoothingTimes(times); viewer->update(); } void MainWindow::slot_updateCriticalPointsSmoothingType(int t) { cout << "Smoothing type = " << t << endl; - //kkkkkkkkkkk + // TODO: Implement Critical Point Smoothing Type Method with New Viewer //viewer->setCriticalPointsSmoothingType(t); viewer->update(); @@ -934,7 +936,7 @@ void MainWindow::slot_updateCriticalPointsSmoothingType(int t) { void MainWindow::slot_updateCutLocusMethod(int midx) { - //kkkkkkkkkkk + // TODO: Implement Cut Locus Method with New Viewer //viewer->setCutLocusMethod(midx); viewer->update();