001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030/**
031 *
032 */
033package org.openimaj.vis;
034
035import org.openimaj.image.MBFImage;
036import org.openimaj.video.AnimatedVideo;
037import org.openimaj.video.VideoDisplay;
038import org.openimaj.vis.general.DotPlotVisualisation;
039import org.openimaj.vis.general.DotPlotVisualisation.ColouredDot;
040import org.openimaj.vis.world.WorldMap;
041
042
043/**
044 *      This class provides a means for generating a video representation of a
045 *      visualisationImpl. This has various advantages in that the visualisationImpl
046 *      can be rendered easily to a video file or the {@link VideoDisplay}
047 *      tools can be used to display the visualisationImpl.
048 *
049 *      @author David Dupplaw (dpd@ecs.soton.ac.uk)
050 *  @created 12 Jun 2013
051 */
052public class VideoVisualisation extends AnimatedVideo<MBFImage>
053{
054        private final Visualisation<?> visualisationImpl;
055
056        /**
057         *      Construct a video visualisationImpl using the given visualisationImpl.
058         *      @param v The visualisationImpl to make into a video.
059         */
060        public VideoVisualisation( final Visualisation<?> v )
061        {
062                super( v.getVisualisationImage() );
063                this.visualisationImpl = v;
064        }
065
066        /**
067         *      {@inheritDoc}
068         *      @see org.openimaj.video.AnimatedVideo#updateNextFrame(org.openimaj.image.Image)
069         */
070        @Override
071        protected void updateNextFrame( final MBFImage frame )
072        {
073                this.visualisationImpl.updateVis();
074                frame.internalAssign( this.visualisationImpl.getVisualisationImage() );
075        }
076
077        /**
078         *      Main method
079         *      @param args command-line args (unused)
080         */
081        public static void main( final String[] args )
082        {
083                // Create the visualisationImpl
084                final DotPlotVisualisation dpv = new DotPlotVisualisation();
085                final WorldMap<ColouredDot> wm = new WorldMap<ColouredDot>( 1280, 720, dpv );
086
087                // Create the video and the video display
088                final VideoVisualisation vv = new VideoVisualisation( wm );
089                final VideoDisplay<MBFImage> vd = VideoDisplay.createVideoDisplay( vv );
090
091                // Now run the sequence
092                final String[] countries = new String[] {"us","cn","gb","za","au","cl","ru"};
093                for( int i = 0; i < countries.length; i++ )
094                {
095                        wm.addHighlightCountry( countries[i] );
096                        try
097                        {
098                                Thread.sleep( 1000 );
099                        }
100                        catch( final InterruptedException e )
101                        {
102                                e.printStackTrace();
103                        }
104                        wm.removeHighlightCountry( countries[i] );
105                }
106
107                vd.close();
108        }
109}