mlivesu / cinolib

A generic programming header only C++ library for processing polygonal and polyhedral meshes
MIT License
897 stars 98 forks source link

Interactive Selection in the viewer #26

Closed 461353349 closed 4 years ago

461353349 commented 4 years ago

If the selected elements could be shown or hidden, The inside of the model could be seen. It is useful for some applications. Will cinolib add the mouse selction api or functions? For example 1) Interactive rectangle selection of nodes or elements; 2) Hiding the selected nodes and elements. image

mlivesu commented 4 years ago

Hi, CinoLib is meant to provide basic ingredients to build research oriented software prototypes. To this end, the functionalities you mention are not strictly contained in the library, but all the ingredients are available, so that you can implement them with a few lines of code. As a representative example, I am attaching at the bottom of this message a simple implementation of the mouse_click callback which would allow you to show/hide a selected element from a volumetric mesh such as the one shown in the picture above with CTRL+click and SHIFT+click. To try it out you can literally copy/paste such code in the library examples, and play it.

A few extra notes on this tool:

Good luck!

gui.callback_mouse_press = [&](GLcanvas *c, QMouseEvent *e)
{
    if(e->modifiers() == Qt::ControlModifier)
    {
        vec3d p;
        vec2i click(e->x(), e->y());
        if (c->unproject(click, p))
        {
            uint pid = m.pick_poly(p);
            m.poly_data(pid).visible = false;
            m.updateGL();
            c->updateGL();
        }
    }
    else if(e->modifiers() == Qt::ShiftModifier)
    {
        vec3d p;
        vec2i click(e->x(), e->y());
        if(c->unproject(click, p))
        {
            uint fid = m.pick_face(p);
            for(uint pid : m.adj_f2p(fid)) m.poly_data(pid).visible = true;
            m.updateGL();
            c->updateGL();
        }
    }
};
461353349 commented 4 years ago

I see! Thank you very much!!!

yvanblanchard commented 1 year ago

Hello @mlivesu

could you please give an up-to-date sampel code for doing this without Qt (but GLFW instead) ? I tried this, but the 'visible' attribute is no longer available:

image

yvanblanchard commented 1 year ago

I found this: m.poly_data(pid).flags[HIDDEN] = false; and it seems to work.

But I am now wondering how the CTRL key is supposed to work: it seems to set tets as visible when selecting a tet witH CTRL key, but I don't know how it could work..

mlivesu commented 1 year ago

Hi, sorry for the late reply but I was on vacation :)

As you noticed some things have changed since my reply to this issue back in 2019. In the current version of cinolib manual selection facilities to show/hide elements have been incorporated in the VolumeMeshControls. More specifically, if you run the tetmesh viewer example and press the TAB key to show the side bar, you will notice that there is a menu item called Manual Digging. If you expand this, you can select an action between dig, undig, isolate. All these options are controlled with SHIFT + mouse click on a mesh element and serve to: hide an element (dig), show an element (undig) or to hide all the elements that are incident to a selected element (isolate).

I hope this will help you out! Marco