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.general; 034 035import java.util.ArrayList; 036import java.util.List; 037 038import javax.media.opengl.GL2; 039import javax.media.opengl.GLAutoDrawable; 040 041import org.openimaj.image.colour.RGBColour; 042import org.openimaj.vis.Visualisation3D; 043import org.openimaj.vis.general.XYPlotVisualisation.LocatedObject; 044import org.openimaj.vis.general.XYZVisualisation3D.LocatedObject3D; 045 046/** 047 * 3 dimensional plot of objects. This class provides the axes and the rendering context 048 * in which items may be plotted. Provide an {@link ItemPlotter3D} for plotting the items 049 * in the visualisation. 050 * 051 * @author David Dupplaw (dpd@ecs.soton.ac.uk) 052 * @created 11 Jul 2013 053 * @version $Author$, $Revision$, $Date$ 054 * @param <D> Plottable item 055 */ 056public class XYZVisualisation3D<D> extends Visualisation3D<List<LocatedObject3D<D>>> 057{ 058 /** 059 * An extension of a {@link LocatedObject} into 3D. 060 * 061 * @author David Dupplaw (dpd@ecs.soton.ac.uk) 062 * @created 11 Jul 2013 063 * @version $Author$, $Revision$, $Date$ 064 * @param <D> The type of the object 065 */ 066 public static class LocatedObject3D<D> extends LocatedObject<D> 067 { 068 /** The Z position */ 069 public double z; 070 071 /** 072 * Constructor 073 * @param x x-coordinate 074 * @param y y-coordinate 075 * @param z z-coordinate 076 * @param object The object to plot 077 */ 078 public LocatedObject3D( final double x, final double y, final double z, final D object ) 079 { 080 super( x, y, object ); 081 this.z = z; 082 } 083 } 084 085 private AxesRenderer3D axesRenderer; 086 087 /** The name of the x axis */ 088 private String xAxisName = "X-Axis"; 089 090 /** The name of the y axis */ 091 private String yAxisName = "Y-Axis"; 092 093 /** The name of the z axis */ 094 private String zAxisName = "Z-Axis"; 095 096 /** The colour of the x axis */ 097 private Float[] xAxisColour = RGBColour.WHITE; 098 099 /** The colour of the y axis */ 100 private Float[] yAxisColour = RGBColour.GREEN; 101 102 /** The colour of the z axis */ 103 private Float[] zAxisColour = RGBColour.BLUE; 104 105 /** Whether to automatically calculate the maximum value and scale */ 106 private boolean autoScale = true; 107 108 /** The plotter for the items in the display */ 109 protected ItemPlotter3D<D> plotter = null; 110 111 /** 112 * Constructor that takes the item plotter 113 * @param width 114 * @param height 115 * @param plotter 116 */ 117 public XYZVisualisation3D( final int width, final int height, final ItemPlotter3D<D> plotter ) 118 { 119 super( width, height ); 120 this.plotter = plotter; 121 this.init(); 122 } 123 124 /** 125 * Constructor that takes the item plotter 126 * @param width 127 * @param height 128 */ 129 public XYZVisualisation3D( final int width, final int height ) 130 { 131 super( width, height ); 132 this.init(); 133 } 134 135 /** 136 * Initialisation routine 137 */ 138 private void init() 139 { 140 this.data = new ArrayList<LocatedObject3D<D>>(); 141 this.axesRenderer = new AxesRenderer3D(); 142 } 143 144 /** 145 * {@inheritDoc} 146 * @see org.openimaj.vis.VisualisationImageProvider#updateVis() 147 */ 148 @Override 149 public void updateVis() 150 { 151 } 152 153 /** 154 * Returns the object rendering the axes 155 * @return The axes renderer 156 */ 157 public AxesRenderer3D getAxesRenderer() 158 { 159 return this.axesRenderer; 160 } 161 162 @Override 163 protected void renderVis( final GLAutoDrawable drawable ) 164 { 165 if( drawable == null || this.axesRenderer == null ) return; 166 167 final GL2 gl = drawable.getGL().getGL2(); 168 169 this.axesRenderer.renderAxis( drawable ); 170 171 final List<LocatedObject3D<D>> x = new ArrayList<XYZVisualisation3D.LocatedObject3D<D>>(); 172 x.addAll( this.data ); 173 for( final LocatedObject3D<D> d : x ) 174 { 175 gl.glPushMatrix(); 176 this.plotter.plotObject( drawable, d, this.axesRenderer ); 177 gl.glPopMatrix(); 178 } 179 } 180 181 /** 182 * @return the xAxisName 183 */ 184 public String getxAxisName() 185 { 186 return this.xAxisName; 187 } 188 189 /** 190 * @param xAxisName the xAxisName to set 191 */ 192 public void setxAxisName( final String xAxisName ) 193 { 194 this.xAxisName = xAxisName; 195 } 196 197 /** 198 * @return the yAxisName 199 */ 200 public String getyAxisName() 201 { 202 return this.yAxisName; 203 } 204 205 /** 206 * @param yAxisName the yAxisName to set 207 */ 208 public void setyAxisName( final String yAxisName ) 209 { 210 this.yAxisName = yAxisName; 211 } 212 213 /** 214 * @return the zAxisName 215 */ 216 public String getzAxisName() 217 { 218 return this.zAxisName; 219 } 220 221 /** 222 * @param zAxisName the zAxisName to set 223 */ 224 public void setzAxisName( final String zAxisName ) 225 { 226 this.zAxisName = zAxisName; 227 } 228 229 /** 230 * @return the xAxisColour 231 */ 232 public Float[] getxAxisColour() 233 { 234 return this.xAxisColour; 235 } 236 237 /** 238 * @param xAxisColour the xAxisColour to set 239 */ 240 public void setxAxisColour( final Float[] xAxisColour ) 241 { 242 this.xAxisColour = xAxisColour; 243 } 244 245 /** 246 * @return the yAxisColour 247 */ 248 public Float[] getyAxisColour() 249 { 250 return this.yAxisColour; 251 } 252 253 /** 254 * @param yAxisColour the yAxisColour to set 255 */ 256 public void setyAxisColour( final Float[] yAxisColour ) 257 { 258 this.yAxisColour = yAxisColour; 259 } 260 261 /** 262 * @return the zAxisColour 263 */ 264 public Float[] getzAxisColour() 265 { 266 return this.zAxisColour; 267 } 268 269 /** 270 * @param zAxisColour the zAxisColour to set 271 */ 272 public void setzAxisColour( final Float[] zAxisColour ) 273 { 274 this.zAxisColour = zAxisColour; 275 } 276 277 /** 278 * @return the autoScale 279 */ 280 public boolean isAutoScale() 281 { 282 return this.autoScale; 283 } 284 285 /** 286 * @param autoScale the autoScale to set 287 */ 288 public void setAutoScale( final boolean autoScale ) 289 { 290 this.autoScale = autoScale; 291 } 292 293 /** 294 * @return the plotter 295 */ 296 public ItemPlotter3D<D> getPlotter() 297 { 298 return this.plotter; 299 } 300 301 /** 302 * @param plotter the plotter to set 303 */ 304 public void setPlotter( final ItemPlotter3D<D> plotter ) 305 { 306 this.plotter = plotter; 307 } 308}