Results 1 to 4 of 4

Thread: display mutliple images and sync viewing

  1. #1
    Join Date
    May 2010
    Posts
    13

    Default display mutliple images and sync viewing

    Folks, I can make an application to open an image file and to display it and interact with it (zooming, panning, etc). I usually read pgm, ppm, png or jpg images.

    Now, I want to go a step further and make an application that can show mulitple images at the same time. The objective is to display two to four images at the same time and to zoom and pan all of them together (want to send the signals from any image's slot to all the images). What is the best way to do this?

    The purpose is to examine a set of images taken with different parameters, each set taken at the same time and a series of such sets taken over a longer time. For example, I may capture 2 images at a time (different exposure setting in each), for every 1 hour. For example, after 10 hours, I will have 20 images, two for each time instance. Later, I want to view the the image pair together and to interact with both using either of the images, and also to move forward and backward in time (to scroll through the sets of images).

    Currently, I am writing an application using qgraphicsivew such that I have two such objects and each object displays one image of the set. But I see that I need to treat each object's signals to be sent to both. I am hoping to avoid the tediousness of this when there are four images in a set. Any suggestions on how to start designing this?

    Thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: display mutliple images and sync viewing

    I was faced with a similar problem is synchronizing multiple plots of scientific data. Each plot showed the same data, but with different parts highlighted. When the user zoomed in or out of one plot, all the others zoomed to the same state.

    The way I did this was to implement a template class I called a "ZoomManager"; it uses as a template parameter any class that has the following methods:

    Qt Code:
    1. void ZoomTo( double xMin, double xMax ); // Zooms x range, leaving y unchanged (or autoscaling to max y in range)
    2.  
    3. void ZoomTo( double xMin, double xMax, double yMin, double yMax ); // Zoom to rect
    To copy to clipboard, switch view to plain text mode 

    The template class is generic - we use it in both Qt and MFC apps, so it depends only on the STL and Boost libraries. You can easily modify it to be Qt-specific and to remove the Boost dependency.

    The way it works is that the app (or MainWindow) has a single instance of ZoomManager for each set of views that must be synchronized. For each of these view, call ZoomManager::AddLink() with a pointer to the view. You can optionally add a back pointer to the ZoomManager instance to each of the views, but this isn't strictly necessary. Call SetDefaultZoom() to tell the zoom manager the full rectangle extents.

    In the views, you need to handle the mouse events associated with zooming. Since you are already doing this in a single view, all you need is to add some signals to let the main window (or whoever holds the zoom manager instance) know what is going on. It is also important to move whatever code there is in your event handler that does the zooming to the ZoomTo() methods (and to let the zoom manager handle those calls - otherwise you get double updates).

    When one of the zoom manager's zoom or pan methods is called, it relays the zoom region to each of the linked views, so that all views are synchronized.

    The zoom manager also implements an optional zoom stack. Each zoom in operation pushes the current zoom level onto the stack, each zoom out pops the stack and restores the previous zoom level.

    Source code is attached.
    Attached Files Attached Files
    Last edited by d_stranz; 21st December 2014 at 20:44.

  3. #3
    Join Date
    May 2010
    Posts
    13

    Default Re: display mutliple images and sync viewing

    Thanks for sharing your solution and the code snippet. I will play around with it and let you know if I face any troubles in this.

  4. #4
    Join Date
    May 2010
    Posts
    13

    Default Re: display mutliple images and sync viewing

    Quote Originally Posted by d_stranz View Post
    In the views, you need to handle the mouse events associated with zooming. Since you are already doing this in a single view, all you need is to add some signals to let the main window (or whoever holds the zoom manager instance) know what is going on. It is also important to move whatever code there is in your event handler that does the zooming to the ZoomTo() methods (and to let the zoom manager handle those calls - otherwise you get double updates).

    When one of the zoom manager's zoom or pan methods is called, it relays the zoom region to each of the linked views, so that all views are synchronized.
    Finally got to make this work (my pet project, so takes its time). Zooming is working fine. I have a two~four (depends on my config) images showing and I can zoom on any one of them and the others zoom in sync.


    However, I have run into issues during panning.

    For panning, I have connected the horizontalscrollbar signal my derived graphicsview class thus:
    Qt Code:
    1. connect(this->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(panImage(int)));
    To copy to clipboard, switch view to plain text mode 

    and the panImage function is the following.
    Qt Code:
    1. void myGraphicsView::panImage(int nTmp) {
    2. if (nTmp != m_nCurrScrollPos) {
    3. if (NULL != m_pMain) {
    4. //get the panned scene's rectangle
    5. QRectF SceneRectPanned = mapToScene(viewport()->geometry()).boundingRect();
    6. float x1New = SceneRectPanned.left() ;
    7. float x2New = SceneRectPanned.right() ;
    8. float y1New = SceneRectPanned.top() ;
    9. float y2New = SceneRectPanned.bottom() ;
    10.  
    11. //ZoomXY just required the new rectangle, give it the panned rect to pan the views.
    12. m_pMain->m_pZM->ZoomXY(x1New, x2New, y1New, y2New);
    13. }
    14. m_nCurrScrollPos = nTmp;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    Here, m_pMain is the pointer to my class that shows the images, etc. and also contains the zoomer instance m_pZM.

    I seem to be running into recursions. I am pretty sure it is a basic mistake. But what !?


    Thanks.

Similar Threads

  1. How to display DDS images?
    By jamsession in forum Qt Programming
    Replies: 5
    Last Post: 12th June 2013, 22:18
  2. Viewing and zooming images
    By ecir.hana in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2013, 20:41
  3. Replies: 1
    Last Post: 29th June 2012, 07:43
  4. Display Images in a TREEVIEW
    By kamlmish in forum Qt Programming
    Replies: 2
    Last Post: 2nd December 2010, 04:41
  5. Display images and move them
    By AL in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2010, 17:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.