Skip to content

resolve #21014 by limiting number of ticks#21147

Merged
alalek merged 3 commits intoopencv:4.xfrom
mjmdavis:4.x
Dec 3, 2021
Merged

resolve #21014 by limiting number of ticks#21147
alalek merged 3 commits intoopencv:4.xfrom
mjmdavis:4.x

Conversation

@mjmdavis
Copy link
Copy Markdown
Contributor

@mjmdavis mjmdavis commented Nov 29, 2021

resolves #21014

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Mac,iOS

[[slider slider] setMinValue:0];
[[slider slider] setNumberOfTickMarks:(max+1)];
[[slider slider] setAllowsTickMarkValuesOnly:YES];
[[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set a limit on the number of TickMarks shown.

[[slider slider] setNumberOfTickMarks:(max+1)];
[[slider slider] setAllowsTickMarkValuesOnly:YES];
[[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)];
[[slider slider] setAllowsTickMarkValuesOnly:NO];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow selection of values without TickMarks. This is important for situations where there is a large range of values.

@mjmdavis
Copy link
Copy Markdown
Contributor Author

While it might be nicer to subclass NSSlider and override setNumberOfTickMarks, I'm not sure it's worth the extra complexity in this case. I could add a comment explaining why the limit is there.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix cvSetTrackbarMax() too.

(use max - min instead of max there)

Comment on lines 946 to 949
[[slider slider] setMinValue:0];
[[slider slider] setNumberOfTickMarks:(max+1)];
[[slider slider] setAllowsTickMarkValuesOnly:YES];
[[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)];
[[slider slider] setAllowsTickMarkValuesOnly:NO];
if(value)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just hide all ticks? (use 0 instead of 101)

[[slider slider] setNumberOfTickMarks:(max > 100 ? 0 : max+1)];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I think this is a better solution. You'd mentioned limiting the number of ticks as a preferred solution previously.

No ticks is simpler and solves the problem in a way that's less likely be reverted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I mean hiding for case with more than 100 values:

-[[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)];
+[[slider slider] setNumberOfTickMarks:(max > 100 ? 0 : max+1)];

Or

if (max <= 100)
{
    [[slider slider] setNumberOfTickMarks:(max+1)];
}

Please take a look on cvSetTrackbarMax() too. We have setNumberOfTickMarks call there too.

[[slider slider] setNumberOfTickMarks:((max - min) > 100 ? 0 : (max - min +1))];

Note: we need to call setNumberOfTickMarks:0 here if we want to hide ticks.


It makes sense to define constant in this file somewhere to avoid using of "magic" number 100 in multiple places (OPENCV_NSSLIDER_MAX_TICKS=100)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I search the code, there are no more mentions of setNumberOfTickMarks. Are you looking at a branch other than 4.x?

I will prepare another PR that does this. The behaviour will be a little inconsistent but ok I guess.

[[slider slider] setMaxValue:max];
[[slider slider] setMinValue:0];
[[slider slider] setNumberOfTickMarks:(max+1)];
[[slider slider] setAllowsTickMarkValuesOnly:YES];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now no TickMarks will be shown.

@mjmdavis
Copy link
Copy Markdown
Contributor Author

I believe this will work but I've somehow just run into "ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.". I might need to test it later.

@@ -944,8 +944,6 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
[[slider name] setStringValue:cvname];
[[slider slider] setMaxValue:max];
[[slider slider] setMinValue:0];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be min?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be a different issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general yes, it should be min.
In "createSliderWithName", we always have min = 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see that now.

@mjmdavis
Copy link
Copy Markdown
Contributor Author

mjmdavis commented Nov 29, 2021

It works but now the area of the track bar to the left of the slider is blue and the dragger is round. :)

Screenshot 2021-11-29 at 7 32 33 AM

Changing this might require some custom assets or the subclassing of NSSlider.

I'd say accept this for now as it makes the system functional and then create a new ticket to look at the rest.

@mjmdavis
Copy link
Copy Markdown
Contributor Author

Thinking more about it, what should the behaviour be if someone:

  1. Creates a trackbar with max 80.
  2. Updates the trackbar to have max 120.

Would then expect the trackbar to change in appearance? I believe it's better to offer a consistent UI in this situation. What do you think @alalek?

Also not that on this branch I did not find any other references to setNumberOfTickMarks so that must have been an existing oversight. Given that this PR removes tick marks completely, that is ok to leave uncorrected.

Options:

  1. Merge this now to resolve the 30s wait when trying to create a slider with large range. Figure out desired behaviour and make a ticket for it.
  2. Only allow 101 ticks. When there are more than 101 ticks, show 101 ticks and set setAllowsTickMarkValuesOnly: to NO. This is not preferred since it could create confusion for users who expect the ticks to line up with a number.

Right now, highgui trackbar with ticks around 10k is unusable on OSX so would love to get something in to restore functionality.

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 1, 2021

Sometime, on UI creation stage application don't know exact number of required ticks.
Ticks information may be available later (e.g., after choosing/loading of video file).
This is why we have cvSetTrackbarMax() in OpenCV API (which should be updated too).

Would then expect the trackbar to change in appearance? I believe it's better to offer a consistent UI in this situation.

I agree with that. It makes sense.

As a complete and consistent solution, I would vote for the option 2:

Only allow 101 ticks. When there are more than 101 ticks, show 101 ticks and set setAllowsTickMarkValuesOnly: to NO


I'm OK with the current PR state which removes ticks at all.

@alalek alalek merged commit d2f87ca into opencv:4.x Dec 3, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* remove tickmarks on NSSlider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance Regression on macOS

2 participants