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 javax.media.opengl.GLAutoDrawable;
036
037import org.openimaj.vis.DataUnitsTransformer;
038
039/**
040 *      A class for generating X, Y and Z axes in a 3D visualisation and providing
041 *      data unit transformations.
042 *
043 *      // TODO: Need to add getters/setters ***
044 *
045 *      @author David Dupplaw (dpd@ecs.soton.ac.uk)
046 *  @created 10 Jul 2013
047 */
048public class AxesRenderer3D implements DataUnitsTransformer<float[], double[], double[]>
049{
050        /** The x axis renderer */
051        private final AxisRenderer3D xAxisRenderer = new AxisRenderer3D();
052
053        /** The y axis renderer */
054        private final AxisRenderer3D yAxisRenderer = new AxisRenderer3D();
055
056        /** The z axis renderer */
057        private final AxisRenderer3D zAxisRenderer = new AxisRenderer3D();
058
059        /**
060         *
061         */
062        public AxesRenderer3D()
063        {
064                this.xAxisRenderer.setGridDirection( -1 );
065                this.yAxisRenderer.getConfig().setOrientation( new double[] { 90, 0, 0, 1, 180, 1, 0, 0 } );
066                this.zAxisRenderer.getConfig().setOrientation( new double[] { 90, 0, 1, 0 } );
067                this.yAxisRenderer.getConfig().getRenderingConfig().setNameOrientation(
068                                new double[] { 90, 0, 0, 1 } );
069                this.yAxisRenderer.getConfig().getRenderingConfig().setNameDirection( -1 );
070                this.zAxisRenderer.getConfig().getRenderingConfig().setNameOrientation(
071                                new double[] { 90, 0, 1, 0, -90, 1, 0, 0 } );
072                this.zAxisRenderer.getConfig().getRenderingConfig().setNameDirection( -1 );
073                this.xAxisRenderer.getConfig().setName( "x-axis" );
074                this.yAxisRenderer.getConfig().setName( "y-axis" );
075                this.zAxisRenderer.getConfig().setName( "z-axis" );
076
077                this.setAxisThickness( 4 );
078                this.setDrawMajorGrid( false );
079                this.setDrawMinorGrid( false );
080        }
081
082        /**
083         *      @param b
084         */
085        public void setDrawMajorGrid( final boolean b )
086        {
087                this.xAxisRenderer.getConfig().getRenderingConfig().setDrawMajorGrid( b );
088                this.yAxisRenderer.getConfig().getRenderingConfig().setDrawMajorGrid( b );
089                this.zAxisRenderer.getConfig().getRenderingConfig().setDrawMajorGrid( b );
090        }
091
092        /**
093         *      @param b
094         */
095        public void setDrawMinorGrid( final boolean b )
096        {
097                this.xAxisRenderer.getConfig().getRenderingConfig().setDrawMinorGrid( b );
098                this.yAxisRenderer.getConfig().getRenderingConfig().setDrawMinorGrid( b );
099                this.zAxisRenderer.getConfig().getRenderingConfig().setDrawMinorGrid( b );
100        }
101
102        /**
103         *      Set the maximum x value
104         *      @param d The new maximum
105         */
106        public void setMaxXValue( final double d )
107        {
108                this.xAxisRenderer.getConfig().setMaxValue( d );
109        }
110
111        /**
112         *      Set the maximum y value
113         *      @param d The new maximum
114         */
115        public void setMaxYValue( final double d )
116        {
117                this.yAxisRenderer.getConfig().setMaxValue( d );
118        }
119
120        /**
121         *      Set the maximum z value
122         *      @param d The new maximum
123         */
124        public void setMaxZValue( final double d )
125        {
126                this.zAxisRenderer.getConfig().setMaxValue( d );
127        }
128
129        /**
130         *      Set the Minimum x value
131         *      @param d The new Minimum
132         */
133        public void setMinXValue( final double d )
134        {
135                this.xAxisRenderer.getConfig().setMinValue( d );
136        }
137
138        /**
139         *      Set the Minimum y value
140         *      @param d The new Minimum
141         */
142        public void setMinYValue( final double d )
143        {
144                this.yAxisRenderer.getConfig().setMinValue( d );
145        }
146
147        /**
148         *      Set the Minimum z value
149         *      @param d The new Minimum
150         */
151        public void setMinZValue( final double d )
152        {
153                this.zAxisRenderer.getConfig().setMinValue( d );
154        }
155
156        /**
157         *
158         *      @param minX
159         *      @param maxX
160         *      @param minY
161         *      @param maxY
162         *      @param minZ
163         *      @param maxZ
164         */
165        public void setAxesRanges( final double minX, final double maxX, final double minY,
166                        final double maxY, final double minZ, final double maxZ )
167        {
168                this.setMinXValue( minX );
169                this.setMaxXValue( maxX );
170                this.setMinYValue( minY );
171                this.setMaxYValue( maxY );
172                this.setMinZValue( minZ );
173                this.setMaxZValue( maxZ );
174        }
175
176        /**
177         *      @param glad
178         */
179        public void renderAxis( final GLAutoDrawable glad )
180        {
181                this.xAxisRenderer.setGLAD( glad );
182                this.yAxisRenderer.setGLAD( glad );
183                this.zAxisRenderer.setGLAD( glad );
184
185                this.xAxisRenderer.renderAxis();
186                this.yAxisRenderer.renderAxis();
187                this.zAxisRenderer.renderAxis();
188        }
189
190        /**
191         *      @param d
192         */
193        public void setAxisThickness( final double d )
194        {
195                this.xAxisRenderer.getConfig().getRenderingConfig().setThickness( d );
196        }
197
198        /**
199         *      @param glad
200         */
201        public void setGLAutoDrawable( final GLAutoDrawable glad )
202        {
203
204        }
205
206        @Override
207        public void precalc()
208        {
209        }
210
211        @Override
212        public double[] calculatePosition( final double[] units )
213        {
214                return new double[] {
215                        this.xAxisRenderer.calculatePosition( units[0] ),
216                        this.yAxisRenderer.calculatePosition( units[1] ),
217                        this.zAxisRenderer.calculatePosition( units[2] )
218                };
219        }
220
221        @Override
222        public double[] calculateUnitsAt( final double[] position )
223        {
224                return new double[] {
225                                this.xAxisRenderer.calculateUnitsAt( position[0] ),
226                                this.yAxisRenderer.calculateUnitsAt( position[1] ),
227                                this.zAxisRenderer.calculateUnitsAt( position[2] )
228                        };
229        }
230
231        @Override
232        public double[] scaleDimension( final double[] dimension )
233        {
234                return new double[]
235                {
236                                this.xAxisRenderer.scaleDimension( dimension[0] ),
237                                this.yAxisRenderer.scaleDimension( dimension[1] ),
238                                this.zAxisRenderer.scaleDimension( dimension[2] ),
239                };
240        }
241
242        /**
243         *      @return the xAxisRenderer
244         */
245        public AxisRenderer3D getxAxisRenderer()
246        {
247                return this.xAxisRenderer;
248        }
249
250        /**
251         *      @return the yAxisRenderer
252         */
253        public AxisRenderer3D getyAxisRenderer()
254        {
255                return this.yAxisRenderer;
256        }
257
258        /**
259         *      @return the zAxisRenderer
260         */
261        public AxisRenderer3D getzAxisRenderer()
262        {
263                return this.zAxisRenderer;
264        }
265}