View to display an image. More...
#include <cvb/ui/image_view.hpp>
Inherits QGraphicsView.
Public Member Functions | |
ImageView (QWidget *parent=nullptr) | |
Create an image view. More... | |
ImageView (class ImageScene *scene, QWidget *parent=nullptr) | |
void | Refresh (Cvb::UI::RefreshMode refreshMode) |
Refresh the view using a specified mode. More... | |
void | Refresh () |
Refresh the view. More... | |
void | Refresh (const ImagePtr &image, Cvb::UI::RefreshMode refreshMode, AutoRefresh autoRefresh=AutoRefresh::Off) |
Share the image and refresh the view. More... | |
void | Refresh (const ImagePtr &image, AutoRefresh autoRefresh=AutoRefresh::Off) |
Share the image and refresh the view. More... | |
void | Refresh (const class Image &image, Cvb::UI::RefreshMode refreshMode) |
Refresh the view using the specified image and mode. More... | |
void | Refresh (const class Image &image) |
Refresh the view using the specified image. More... | |
void | ReleaseRefreshShare () noexcept |
Releases the shared image. More... | |
void | SetEventRefreshEnabled (bool enabled) noexcept |
Enables and disables automatic refreshing caused by events. More... | |
bool | IsEventRefreshEnabled () const noexcept |
Check if automatic refreshing by events is set. More... | |
void | SetWaitForRepaintEnabled (bool enabled) |
Enable and disables waiting for repaints. More... | |
bool | IsWaitForRepaintEnabled () const noexcept |
Checks if waiting for repaint is set. More... | |
void | CustomWaitForRepaint (std::function< void()> customWaitForRepaint) noexcept |
Set a custom callback associated with a refresh mode. More... | |
void | ResetCustomWaitForRepaint () noexcept |
Reset to the default value. More... | |
void | CustomScheduleRepaint (std::function< void()> scheduleRepaint) noexcept |
Set a custom callback associated with a refresh mode. More... | |
void | ResetCustomScheduleRepaint () noexcept |
Reset to the default value. More... | |
Cvb::UI::RefreshMode | RefreshMode () const noexcept |
Get the current refresh mode. More... | |
void | SetRefreshMode (Cvb::UI::RefreshMode refreshMode) noexcept |
Set the current refresh mode. More... | |
Cvb::UI::UploadMode | UploadMode () const noexcept |
Get the current upload mode. More... | |
void | SetUploadMode (Cvb::UI::UploadMode uploadMode) |
Set the current upload mode. More... | |
ImagePtr | Image () const noexcept |
Get the currently shared image. More... | |
class ImageScene * | ImageScene () const noexcept |
Get the image scene. More... | |
bool | TryZoomIn () noexcept |
Tries to zoom in. More... | |
bool | TryZoomOut () noexcept |
Tries to zoom out. More... | |
ZoomDescriptor | Zoom () const noexcept |
Get the current zoom descriptor. More... | |
void | SetZoom (ZoomDescriptor zoomDescriptor) noexcept |
Set the current zoom descriptor. More... | |
Cvb::UI::RenderEngine | RenderEngine () const noexcept |
Get the current render engine. More... | |
void | SetRenderEngine (Cvb::UI::RenderEngine renderEngine) |
Set the current render engine. More... | |
Cvb::EventCookie | RegisterEventMouseMoved (std::function< void(Cvb::Point2D< int >, const std::vector< double > &)> handler) |
Register a callback to get pixel values under the moving mouse. More... | |
void | UnregisterEventMouseMoved (Cvb::EventCookie eventCookie) noexcept |
Unregister a callback to get pixel values under the moving mouse. More... | |
Protected Member Functions | |
void | closeEvent (QCloseEvent *event) override |
Handles close events. More... | |
void | scrollContentsBy (int dx, int dy) override |
Handles scrolling the view. More... | |
void | resizeEvent (QResizeEvent *event) override |
Handle resize events. More... | |
void | showEvent (QShowEvent *event) override |
Handle show events. More... | |
void | wheelEvent (QWheelEvent *event) override |
Handle mouse wheel events to zoom. More... | |
void | mouseMoveEvent (QMouseEvent *event) override |
Handle mouse move events. More... | |
View to display an image.
This is the main class to display an image in a widget based Qt application. It supports all the features provided by QtGraphicsView, with the exception, that it is not possible to have multiple views on the same scene.
Create an image view.
[in] | parent | Parent object in Qt's object hierarchie. |
Any | exception derived from std::exception including CvbException. |
|
inlineexplicit |
[in] | scene | Scene to use with this view. |
[in] | parent | Parent object in Qt's object hierarchie. |
Any | exception derived from std::exception including CvbException. |
Use this constructor only if you must associate the view with you own subclass of a ImageScene.
|
inlineoverrideprotectedvirtual |
|
inlinenoexcept |
Set a custom callback associated with a refresh mode.
[in] | scheduleRepaint | Custom callback. |
Does | not throw any exception. |
This is useful for manual optimization and synchronization if multiple image views are used.
|
inlinenoexcept |
Set a custom callback associated with a refresh mode.
[in] | customWaitForRepaint | Custom callback. |
Does | not throw any exception. |
This is useful for manual optimization and synchronization if multiple image views are used.
Get the currently shared image.
Does | not throw any exception. |
|
inlinenoexcept |
Get the image scene.
Does | not throw any exception. |
This is useful for accessing Qt features, that are not exposed through this image view.
|
inlinenoexcept |
Check if automatic refreshing by events is set.
Does | not throw any exception. |
|
inlinenoexcept |
Checks if waiting for repaint is set.
Does | not throw any exception. |
|
inlineoverrideprotectedvirtual |
Handle mouse move events.
[in] | event | The Qt event. |
Does | not throw any exception. |
The default implementation will run all registered callbacks if there are any.
Reimplement if you need a different behavior.
Reimplemented from QGraphicsView.
|
inline |
Refresh the view.
Any | exception derived from std::exception including CvbException. |
This is equivalent to calling ImageView::Refresh(enum class RefreshMode) with the defualt mode.
|
inline |
Refresh the view using the specified image.
[in] | image | The image, which is not shared with the display. |
Any | exception derived from std::exception including CvbException. |
This is equivalent to calling ImageView::Refresh(const class Image &, enum class RefreshMode) with the default mode.
|
inline |
Refresh the view using the specified image and mode.
[in] | image | The image, which is not shared with the display. |
[in] | refreshMode | The refresh mode |
Any | exception derived from std::exception including CvbException. |
Refreshing will trigger an image upload and rendering the pixel content in the view. Depending on the selected RenderRngine, upload and rendering may happen in different threads as QGraphicsView does not allow multi threaded access to OpenGL.
RenderEngine | Upload Thread | Render Thread |
---|---|---|
RenderEngine::Raster | Calling Thread | Main Thread |
RenderEngine::OpenGL2 | Main Thread | Main Thread |
RenderEngine::OpenGL3 | Main Thread | Main Thread |
All Refresh() versions are thread safe with limitations and may be called from either the main thread or the acquisition thread. Depending on the mode this method may block until the main thread has actually rendered the image. This introduces an unavoidable risk for a deadlock. If e.g. the main thread is waiting for the a acquisition thread to finish while acquisition thread is waiting for the main thread to render. In order to prevent that must manually abort the waiting.
All Refresh() versions that take a reference instaed of a pointer will not share the image. So before using a refernce version make sure, that there is no shared image in the display ReleaseRefreshShare(). As a consequence of not sharing the image only Cvb::UI::UploadMode::Image is supported. Furthermore anything registered with RegisterEventMouseMoved will not be called.
|
inline |
Share the image and refresh the view.
[in] | image | The image, which will be shared with the display. |
[in] | autoRefresh | Switch to control automatic refreshing. |
Any | exception derived from std::exception including CvbException. |
This is equivalent to calling ImageView::Refresh(const ImagePtr &, enum class RefreshMode, AutoRefresh autoRefresh) with the default mode.
|
inline |
Share the image and refresh the view.
[in] | image | The image, which will be shared with the display. |
[in] | refreshMode | The refresh mode |
[in] | autoRefresh | Switch to control automatic refreshing. |
Any | exception derived from std::exception including CvbException. |
Any previously shared image will be released. Once an image has been shared you may call ImageView::Refresh() or ImageView::Refresh(enum class RefreshMode).
|
inline |
Refresh the view using a specified mode.
[in] | refreshMode | The refresh mode. |
Any | exception derived from std::exception including CvbException. |
This method will refresh the view with the content of the shared image. This is equivalent to calling ImageView::Refresh(const class Image & image, enum class RefreshMode refreshMode) with the currently shared image. If there is no shared image this method will throw.
|
inlinenoexcept |
Get the current refresh mode.
Does | not throw any exception. |
|
inline |
Register a callback to get pixel values under the moving mouse.
[in] | handler | The callback. |
Any | exception derived from std::exception including CvbException. |
|
inlinenoexcept |
Releases the shared image.
Does | not throw any exception. |
Use this method if you must release the shared image manually. Setting a new shared image and destroying this image view will automatically release the shared image.
|
inlinenoexcept |
Get the current render engine.
Does | not throw any exception. |
|
inlinenoexcept |
Reset to the default value.
Does | not throw any exception. |
|
inlinenoexcept |
Reset to the default value.
Does | not throw any exception. |
|
inlineoverrideprotectedvirtual |
Handle resize events.
[in] | event | The Qt event. |
Does | not throw any exception. |
Reimplement if you need a different behavior.
Reimplemented from QGraphicsView.
|
inlineoverrideprotectedvirtual |
Handles scrolling the view.
[in] | dx | Distance covered in x. |
[in] | dy | Distance covered in Y. |
Does | not throw any exception. |
Reimplement if you need a different behavior.
Reimplemented from QGraphicsView.
|
inlinenoexcept |
Enables and disables automatic refreshing caused by events.
[in] | enabled | True to enable, false to disable. |
Does | not throw any exception. |
In this case events refer to UI events sent to QWidget based classes. E.g these are caused by resizing or scrolling the image view. Obviously these events should trigger a repaint to provide a smooth user experience. Unfortunately such events can trigger each other, potentially causing several unneeded refreshes that in turn may impact performance. This method is used to prevent such behavior during event handling.
|
inlinenoexcept |
Set the current refresh mode.
[in] | refreshMode | The new refresh mode. |
Does | not throw any exception. |
|
inline |
Set the current render engine.
[in] | renderEngine | The new Render engine. |
Any | exception derived from std::exception including CvbException. |
If the new render engine is cannot be set, the call is ignored.
|
inline |
Set the current upload mode.
[in] | uploadMode | The new upload mode. |
Any | exception derived from std::exception including CvbException. |
|
inline |
Enable and disables waiting for repaints.
[in] | enabled | True to enable, false to disable. |
Any | exception derived from std::exception including CvbException. |
This is used to prevent a deadlock condition that can happen between the main thread and the acquisition thread if RefreshMode::UploadAndWaitForRepaint is set. Disabling the wait will abort any current waiting and cause blocking calls to ImageView::Refresh() to return. All further calls will not block, until waiting is enabled again. While the waiting is disabled rendering will fall back to RefreshMode::UploadAndScheduleRepaint.
This method must be called from the UI thread.
|
inlinenoexcept |
Set the current zoom descriptor.
[in] | zoomDescriptor | The new zoom descriptor. |
Does | not throw any exception. |
|
inlineoverrideprotectedvirtual |
Handle show events.
[in] | event | The Qt event. |
Does | not throw any exception. |
Reimplement if you need a different behavior.
Reimplemented from QGraphicsView.
|
inlinenoexcept |
Tries to zoom in.
Does | not throw any exception. |
|
inlinenoexcept |
Tries to zoom out.
Does | not throw any exception. |
|
inlinenoexcept |
Unregister a callback to get pixel values under the moving mouse.
[in] | eventCookie | Cookie obtained when the callback was registered. |
Does | not throw any exception. |
|
inlinenoexcept |
Get the current upload mode.
Does | not throw any exception. |
|
inlineoverrideprotectedvirtual |
Handle mouse wheel events to zoom.
[in] | event | The Qt event. |
Does | not throw any exception. |
Reimplement if you need a different behavior.
Reimplemented from QGraphicsView.
|
inlinenoexcept |
Get the current zoom descriptor.
Does | not throw any exception. |