Difference between revisions of "Customized video montages"

From Dynamo
Jump to navigation Jump to search
Line 41: Line 41:
 
== Subclassed montages ==
 
== Subclassed montages ==
  
The underlying generic class for video montages is <tt>mbvid.guis.Montage</tt>.  
+
Using this options involves a minimal comprehension of Object Oriented Programming. The underlying generic class for video montages is <tt>mbvid.guis.Montage</tt>.  
 +
 
 +
=== Basic use of a video Montage object===
  
 
Showing  the GUI of an user-defined subclass  <tt>myVideoMontage</tt>of <tt>mbvid.guis.Montage</tt> requires first creating the instance
 
Showing  the GUI of an user-defined subclass  <tt>myVideoMontage</tt>of <tt>mbvid.guis.Montage</tt> requires first creating the instance
Line 54: Line 56:
  
 
  <tt>gui.show();</tt>
 
  <tt>gui.show();</tt>
 +
 +
Before the show operation, there are different options that you can assign beforehand:
 +
<nowiki>rows
 +
columns
 +
width
 +
height
 +
title</nowiki>
  
 
=== Structure of a video montage object ===
 
=== Structure of a video montage object ===
Line 77: Line 86:
 
The usual practice is to include this definition in the constructor method of the GUI, to ensure this assignation is ran before the GUI is shown.
 
The usual practice is to include this definition in the constructor method of the GUI, to ensure this assignation is ran before the GUI is shown.
  
==== Example ====
+
==== Example of subclassing====
  
 
In order to create a new class, you can use the usual Matlab system, or just type:
 
In order to create a new class, you can use the usual Matlab system, or just type:
Line 111: Line 120:
 
  <tt>dlookfor createFrame </tt>
 
  <tt>dlookfor createFrame </tt>
  
you can find examples  across ''Dynamo'' that implement this method in different subclasses.
+
you can find examples  across ''Dynamo'' that implement this method in different subclasses. In our case, imagine that we want to plot a sine of the -sorted- values of the data contained in each stream entry. Moreover, in this sine we want to use a frequency that changes linearly with the number of frame. This requirement already sets us outside of the realm of  [[Customized Video Montages #Inline montages| inline montages]], as we cannot enter the number of frame in the dependencies of the customizing function <tt>gui.depictorOnAxesFcn</tt>.
 +
 
 +
Further, for this example we introduce a modification of the plotting axes themselves, making them cover the full panel object, also overcoming the limitation of inlines of type  <tt>mbvid.guis.montages.cells.Inline</tt>. We just provide the class <tt>myFrameManager</tt> with the methods <tt>createFrame</tt> and <tt>updateFrame</tt>
 +
 
 +
<nowiki>      function createFrame(obj);
 +
          haxis = axes('Parent',obj.hPanel);
 +
         
 +
          set(haxis,'Position',[0,0,1,1]);
 +
         
 +
          myVideo = obj.gui.getVideo();
 +
          myData = myVideo.read(obj.frameNumber); 
 +
         
 +
          % change the data differently for each frame
 +
          representedData = sin(sort(myData)*obj.frameNumber);
 +
          plot(representedData,'Parent',haxis);
 +
      end
 +
     
 +
        function updateFrame(obj);
 +
            % Just recreates the frame
 +
            % Not recommended for performance-critic applications
 +
            obj.createFrame();
 +
      end </nowiki>
 +
 
 +
[[File:CustomVideoMontageSinuses.png |thumb|center|500px| Customized video montage to show the histograms of a cell array of vectors. ]]

Revision as of 12:38, 11 October 2017

Video montages are widely used in Dynamo to show in a single montage part of a stream of data. The user can slide on the subset of the data that is represented at a given moment. Examples of this are found in the slider GUIs used to explore sets of particles, slices inside a given volume, or selections of gold beads.

In this page, we explain how to use the underlying Dynamo objects to create your own visualization systems. We explain two possible approaches:

  • Inline montages

Can be defined easily from the command line without definition of further classes.

  • Subclassed montages

Advanced method. This method offers full flexibility at the cost of requiring from the user the creation of new classes.

Inline montages

You can use the class mbvid.guis.montages.cells.Inline, that allows inline definition of the action to be computed at each frame. For instance, imagine that you have a set of 1000 vectors, and you want to quickly explore their histograms separately. Let's generate a random data set:.

 for k=1:1000;
  myData{k} = randn(20000,1); 
end

For 1000 elements, you probably don't want to show them all in a single screen, but rather slide through the data. Thus, we create the object that represents the GUI

  gui = mbvid.guis.montages.cells.Inline(); 

we link now this object with the stream of data

   gui.setVideo(myData); 

My data is a matlab cell array in this example, but you could pass any other object that implicitly defines an stream of data. If you pass, for instance, a volume of dimensions lx x ly x lz, the stream will be defined as a succesion on lz frames.

Now, we have to tell the GUI object what to do on each frame. This is done by defining the method depictorOnAxesFcn to be an inline function of two variables. The first is a dummy variable that represents the content of the stream for a given frame. The second is the graphical axis associated to the frame in the montage. Thus:

gui.depictorOnAxesFcn = @(x,haxis) hist(haxis,x(:),100);

This command reads as: "for a frame in position i, take the position i in the stream (i.e., the i-th entry in the cell array myData associated to the gui object), and show its histogram (with 100 bins) on the axis associated to the frame".

Now we are ready to go:

  gui.show();
Customized video montage to show the histograms of a cell array of vectors.

Subclassed montages

Using this options involves a minimal comprehension of Object Oriented Programming. The underlying generic class for video montages is mbvid.guis.Montage.

Basic use of a video Montage object

Showing the GUI of an user-defined subclass myVideoMontageof mbvid.guis.Montage requires first creating the instance

gui  = myVideoMontage();

then attaching the video stream (if it is not included in the constructor)

 gui  = myVideoMontage();

and them invoking the show method:

gui.show();

Before the show operation, there are different options that you can assign beforehand:

rows
columns
width
height
title

Structure of a video montage object

A video montage object is basically the result of combining of two different types of objectc:

  • An scene manager object that runs the general layout and sliding of the scene.
  • Objects of the frameManager class that control what is depicting on each panel.

Frame manager class

This object controls the creation and updating of a frame when its representation is invoked by the scene manager in the videomontage GUI. The basic frame class is mbvid.controls.VideoMontageFrameManager. Custom frame managers need to be subclasses of this class.

Defining the action of a frame

You need to define the method createFrame in your subclass (let's call it myFrameManager). This will pass the properties 'gui' , 'frameNumber', 'hPanel' .

Linking a frame class to a GUI

In order to link a frame class to a particular class of GUI, we can assign the name of the class to the property of the GUI object.

gui.frameManagerType = 'mbvid.controls.VideoMontageFrameManager' 

The usual practice is to include this definition in the constructor method of the GUI, to ensure this assignation is ran before the GUI is shown.

Example of subclassing

In order to create a new class, you can use the usual Matlab system, or just type:

mbnew myFrameManager . mbvid.controls.montageFrameManager 

which will open the editor with this predefined content for the class @myFrameManager, created in the current directory.

 %
% class definition
%
classdef myFrameManager < mbvid.controls.montageFrameManager
  
    properties 
  
    end 
  
  
    methods 
  
       function obj=myFrameManager(varargin)
  
             obj=obj@mbvid.controls.montageFrameManager(varargin{:});
       end
              
  
    end 
  
end 

You can the define the method createFrame() inside this file, using the properties 'gui' , 'frameNumber', 'hPanel' that will be available in the obj during runtime. With

dlookfor createFrame 

you can find examples across Dynamo that implement this method in different subclasses. In our case, imagine that we want to plot a sine of the -sorted- values of the data contained in each stream entry. Moreover, in this sine we want to use a frequency that changes linearly with the number of frame. This requirement already sets us outside of the realm of inline montages, as we cannot enter the number of frame in the dependencies of the customizing function gui.depictorOnAxesFcn.

Further, for this example we introduce a modification of the plotting axes themselves, making them cover the full panel object, also overcoming the limitation of inlines of type mbvid.guis.montages.cells.Inline. We just provide the class myFrameManager with the methods createFrame and updateFrame

function createFrame(obj); haxis = axes('Parent',obj.hPanel); set(haxis,'Position',[0,0,1,1]); myVideo = obj.gui.getVideo(); myData = myVideo.read(obj.frameNumber); % change the data differently for each frame representedData = sin(sort(myData)*obj.frameNumber); plot(representedData,'Parent',haxis); end function updateFrame(obj); % Just recreates the frame % Not recommended for performance-critic applications obj.createFrame(); end

Customized video montage to show the histograms of a cell array of vectors.