Skip to content

Commit

Permalink
minor fix on edge selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenyaoKe committed Aug 7, 2016
1 parent e023950 commit 12e1769
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 94 deletions.
14 changes: 8 additions & 6 deletions shaders/edge_gs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
22 changes: 13 additions & 9 deletions shaders/uid_fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
73 changes: 27 additions & 46 deletions src/MeshViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
{
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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()
Expand All @@ -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<float>(scale));
uid_shader.setUniformValue("scale", static_cast<float>(view_scale));

switch (interactionState)
{
Expand Down Expand Up @@ -282,7 +268,7 @@ void MeshViewer::drawMeshToFBO()
}

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glLineWidth(2);
glLineWidth(10);
heRBO.vao.bind();


Expand Down Expand Up @@ -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
{
Expand All @@ -373,8 +361,9 @@ void MeshViewer::drawMeshToFBO()
break;
}
}
#ifdef _DEBUG
cout << "draw primitive id:" << renderID << endl;
#endif // DEBUG
}

void MeshViewer::paintGL()
Expand Down Expand Up @@ -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<float>(scale));
vtx_solid_shader.setUniformValue("scale", static_cast<float>(view_scale));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_BUFFER, vRBO.flag_tex);
glTexBuffer(GL_TEXTURE_BUFFER, GL_R16UI, vRBO.flag_tbo);
Expand All @@ -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<float>(scale));
face_solid_shader.setUniformValue("scale", static_cast<float>(view_scale));
// Bind Texture Buffer
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_BUFFER, fRBO.flag_tex);
Expand All @@ -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<float>(scale));
edge_solid_shader.setUniformValue("scale", static_cast<float>(view_scale));
// Bind Texture Buffer
glBindTexture(GL_TEXTURE_BUFFER, heRBO.flag_tex);
glTexBuffer(GL_TEXTURE_BUFFER, GL_R16UI, heRBO.flag_tbo);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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));
}
}
51 changes: 25 additions & 26 deletions src/MeshViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class MeshViewer
void toggleText();

private: // paint function
void resetCamera();
void allocateGL();

void initShader();
Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 27 additions & 1 deletion src/hds_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,10 @@ void HDS_Mesh::exportEdgeVBO(
unordered_set<he_t*> visitiedHE;
visitiedHE.reserve(heSetSize);


heIBOs->clear();
heIBOs->reserve(heSetSize);
heIDs->clear();
heIDs->reserve(heSetSize >> 1);
heFLAGs->clear();
heFLAGs->reserve(heSetSize >> 1);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/hds_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>;
void exportSelection(ui32q_t* selVTX, ui32q_t* selHE, ui32q_t* selFACE);

unordered_set<he_t*>& halfedges() { return heSet; }
unordered_set<face_t*> faces() const { return faceSet; }
Expand Down
Loading

0 comments on commit 12e1769

Please sign in to comment.