Doodleverse / holodoodler

HoloDoodler; semi-interactive image segmentation implemented using HoloViews
3 stars 1 forks source link

Clear doodles button bug #12

Closed venuswku closed 1 year ago

venuswku commented 1 year ago

Issues

After the results of a segmentation appear, I usually click the Clear segmentation button and then the Clear doodles button to continue testing my code. The segmentation gets cleared instantly, but my doodles don't disappear when I click the Clear doodles button for the first time. I need to click the button again for a second time in order for my doodles to disappear. consistent_clear_doodles_bug As you can see in the GIF above, another encountered issue is that any subsequent doodles instantly disappear whenever I change the doodle class/label. This is similar to Sharon's issue, except my issue happens consistently.

Fix

If you use the print statements that I added (removed now) in the DoodleDrawer class, you can see that the _draw and _drawn doodle plots are updated correctly. That means something went wrong when the Application class was displaying these doodle plots. The Application class uses _img_pane to display the doodle plots, so I added the line below to update _img_pane whenever the Clear doodles button is clicked.

## doodler > components.py
# ...
class DoodleDrawer(pn.viewable.Viewer):
    # ...
    clear_all = param.Event(label='Clear doodles', doc='Button to clear all the doodles')
    # ...
    @property
    def plot(self):
        return self._drawn * self._draw
# ...
class Application(param.Parameterized):
    def __init__(self, **params):
        self._img_pane = pn.pane.HoloViews(sizing_mode='scale_height')
        super().__init__(**params)

    @param.depends('doodle_drawer.clear_all', watch=True)   # <- line that I added
    def _update_img_pane(self):
        self._img_pane.object = (self.input_image.plot * self.doodle_drawer.plot).opts(responsive='height')
    # ...
    @property
    def plot_pane(self):
        return self._img_pane

## app.py
# ...
doodle_drawer = DoodleDrawer(class_color_mapping=CLASS_COLOR_MAPPING, class_toggle_group_type=ClassToggleGroup)
# ...
app = Application(settings=settings, doodle_drawer=doodle_drawer, info=info, input_image=input_image)
# ...
main = app.plot_pane
# ...
template = pn.template.MaterialTemplate(
    title='Doodler',
    logo='assets/1280px-USGS_logo.png',
    header_background='#000000',
    sidebar=side_bar,
    main=[main],
)

The DoodleDrawer class's clear_all parameter changes whenever the Clear doodles button is clicked, so making the _update_img_pane() function depend on DoodleDrawer's clear_all parameter would reassign _img_pane with the recently updated doodle plots. fixed_clear_doodles_bug Now the doodles don't disappear when I clear all the doodles and choose a new class/label. @2320sharon, when you have time can you test my branch and check if the bug still appears for you? Hope the bug doesn't happen randomly anymore.🤞🏻

dbuscombe-usgs commented 1 year ago

Great work