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.demos.sandbox.vis;
034
035
036import org.apache.commons.vfs2.FileSystemException;
037import org.openimaj.data.dataset.VFSGroupDataset;
038import org.openimaj.image.ImageUtilities;
039import org.openimaj.image.MBFImage;
040import org.openimaj.vis.general.DiversityAxis;
041import org.openimaj.vis.general.ImageThumbnailPlotter;
042
043/**
044 *      A mock-up of an opinion visualisation using the diveristy axis visualisation.
045 *
046 *      @author David Dupplaw (dpd@ecs.soton.ac.uk)
047 *  @created 6 Jun 2013
048 *      @version $Author$, $Revision$, $Date$
049 */
050public class OpinionDiversityAxisVisExample
051{
052        /**
053         *      @param args
054         *      @throws FileSystemException
055         */
056        public static void main( final String[] args ) throws FileSystemException
057        {
058                // Use some images from a directory on the disk
059                final VFSGroupDataset<MBFImage> i = new VFSGroupDataset<MBFImage>(
060                                "/data/faces/lfw", ImageUtilities.MBFIMAGE_READER );
061
062                // Set up the diversity axis to plot thumbnail images.
063                final ImageThumbnailPlotter itp = new ImageThumbnailPlotter();
064                final DiversityAxis<MBFImage> dv = new DiversityAxis<MBFImage>( 1600, 800, itp )
065                {
066                        /** */
067                        private static final long serialVersionUID = 1L;
068
069                        @Override
070                        public void bandSizeKnown( final int bandSize )
071                        {
072                                itp.setThumbnailSize( bandSize );
073                        }
074                };
075                dv.setDiversityAxisName( "Opinion" );
076
077                int maxGroups = 10;
078                int groupCount = 1;
079                for( final String group: i.getGroups() )
080                {
081                        for( final MBFImage img : i.get( group ) )
082                        {
083                                // Pretend we've found x number of duplicates for this image
084                                final int x = (int)(Math.random() * 3)+1;
085                                for( int j = 0; j < x; j++ )
086                                {
087                                        // Mock-up an opinion value for each image
088                                        final double opinionValue = (Math.random() - 0.5) * 2;
089
090                                        // Add it to the diversity axis
091                                        dv.addObject( groupCount, opinionValue, img );
092                                }
093
094                                groupCount++;
095
096                                // Let's not show too many groups
097                                maxGroups--;
098                                if( maxGroups == 0 ) break;
099                        }
100
101                        if( maxGroups == 0 ) break;
102                }
103
104                // Show the vis.
105                dv.repaint();
106                dv.showWindow( "Opinion VisualisationImpl" );
107        }
108}