Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Platform/OpenGL/ILOGLYAxis.cs @ 10102

Last change on this file since 10102 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 9.4 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Text;
43using System.Drawing;
44using OpenTK;
45using OpenTK.Graphics;
46using OpenTK.Graphics.OpenGL;
47using OpenTK.Graphics.OpenGL.Enums;
48using ILNumerics.Drawing;
49using ILNumerics.Drawing.Interfaces;
50using ILNumerics.Drawing.Labeling;
51
52
53namespace ILNumerics.Drawing.Platform.OpenGL {
54    /// <summary>
55    /// OpenGL implementation of ILAxis (X axis)
56    /// </summary>
57    class ILOGLYAxis : ILOGLAxis {
58       
59        /// <summary>
60        /// Constructor - this class should be created only from within ILNumerics assemblies!
61        /// </summary>
62        /// <param name="clippingView">panels clipping view</param>
63        /// <param name="layoutData">instance with layout informations</param>
64        /// <param name="panel">the panel containing the axis</param>
65        internal ILOGLYAxis (ILClippingData clippingView,
66                            ILLayoutData layoutData,
67                            ILOGLPanel panel)
68            : base (AxisNames.YAxis,clippingView,layoutData,panel) { }
69
70        /// <summary>
71        /// draw all lines for the axis
72        /// </summary>
73        /// <param name="p">render properties</param>
74        /// <param name="background">true: draw lines in the back only, false: draw foreground lines</param>
75        protected override void iDrawAxis(ILRenderProperties p, bool background) {
76            // create vertex data: main axis and ticks
77            if (m_visible) {
78                float tickLen;
79                float x, y, z
80                    , xmin = m_clipping.XMin
81                    , xmax = m_clipping.XMax
82                    , ymin = m_clipping.YMin
83                    , ymax = m_clipping.YMax
84                    , zmin = m_clipping.ZMin
85                    , zmax = m_clipping.ZMax;
86                tickLen = m_labeledTicks.TickFraction
87                    * ((m_labeledTicks.Direction == TickDirection.Inside) ? -m_clipping.WidthF : m_clipping.WidthF);
88                // must draw ticks?
89                bool drawticks = false, drawlines = false;
90                if (m_labeledTicks.Display == TickDisplay.BothSides) {
91                    drawticks = true;
92                } else {
93                    drawticks = (background ^ m_layoutData.CameraPosition.LooksFromTop);
94                }
95                y = ymin; z = zmin;
96                // determine which axis to draw: find front
97                if (!m_layoutData.CameraPosition.LooksFromLeft && !m_layoutData.CameraPosition.Is2DView) {
98                    x = xmax;
99                } else {
100                    x = xmin;
101                    tickLen *= -1.0f;
102                }
103                if (background) {
104                    if (x == xmin) x = xmax; else x = xmin;
105                    tickLen *= -1.0f;
106                    GL.Disable(EnableCap.DepthTest);
107                    if (m_farLines.Visible) {
108                        ILOGLPanel.SetupLineStyle(m_farLines);
109                        drawlines = true;
110                    }
111                } else {
112                    if (m_nearLines.Visible) {
113                        ILOGLPanel.SetupLineStyle(m_nearLines);
114                        drawlines = true;
115                    }
116                }
117                if (drawlines) {
118                    GL.Begin(BeginMode.Lines);
119                    GL.Vertex3(x,y,z);
120                    y = ymax;
121                    GL.Vertex3(x,y,z);
122                    if (m_layoutData.CameraPosition.SinRho > 1e-5) {
123                        z = zmax;
124                        GL.Vertex3(x,y,z);
125                        y = ymin;
126                        GL.Vertex3(x,y,z);
127                    }
128                    GL.End();
129                }
130                if (drawticks && drawlines) {
131                    #region create ticks
132                    if (!m_layoutData.CameraPosition.LooksFromTop) {
133                        //tickLen *= -1.0f;
134                        //x *= -1.0f;
135                        if (background)
136                            GL.Color3(m_labeledTicks.NearColor);
137                        else
138                            GL.Color3(m_labeledTicks.FarColor);
139                    } else {
140                        if (background)
141                            GL.Color3(m_labeledTicks.FarColor);
142                        else
143                            GL.Color3(m_labeledTicks.NearColor);
144                    }
145                    //scale = m_clipping.ScaleToUnitCube().Y;
146                    //offse = m_clipping.CenterToUnitCube().Y;
147                    GL.Enable(EnableCap.DepthTest);
148                    GL.Disable(EnableCap.LineStipple);
149                    GL.Begin(BeginMode.Lines);
150                    foreach (LabeledTick tick in m_labeledTicks) {
151                        if (tick.Position >= ymin
152                            && tick.Position <= ymax) {
153                            y = tick.Position;
154                            if (m_layoutData.CameraPosition.SinRho > 1e-5) {
155                                z = zmax;
156                                GL.Vertex3(x, y, z);
157                                x += tickLen;
158                                GL.Vertex3(x, y, z);
159                            } else {
160                                x += tickLen;
161                            }
162                            z = zmin;
163                            GL.Vertex3(x,y,z);
164                            x -= tickLen;               
165                            GL.Vertex3(x,y,z);
166                        }
167                    }
168                    GL.End();
169                }
170                if (background && m_grid.Visible)
171                    drawGrid();
172                #endregion
173            }
174        }
175
176        /// <summary>
177        /// draw all grid lines for axis
178        /// </summary>
179        protected override void drawGrid() {
180            GL.Color3(m_grid.Color);
181            float x,y,z;
182            float zmax = m_clipping.ZMax;
183            float zmin = m_clipping.ZMin;
184            float xmin = m_clipping.XMin;
185            float xmax = m_clipping.XMax;
186            bool drawBottom = m_layoutData.CameraPosition.LooksFromTop;
187            ILOGLPanel.SetupLineStyle(m_grid);
188            GL.Disable(EnableCap.DepthTest);
189            GL.Disable(EnableCap.Blend);
190            GL.Begin(BeginMode.Lines);
191            if (!m_layoutData.CameraPosition.LooksFromLeft) {
192                x = xmin;
193            } else {
194                x = xmax;
195            }
196            foreach (LabeledTick tick in m_labeledTicks) {
197                if (tick.Position >= m_clipping.YMin
198                    && tick.Position <= m_clipping.YMax) {
199                    y = tick.Position;
200                    if (!m_layoutData.CameraPosition.Is2DView) {
201                        z = zmax;
202                        GL.Vertex3(x, y, z);
203                        z = zmin;
204                        GL.Vertex3(x, y, z);
205                    } else {
206                        z = zmin;
207                    }
208                    if (drawBottom) {
209                        GL.Vertex3(x,y,z);
210                        if (x == xmin) x = xmax; else x = xmin;
211                        GL.Vertex3(x,y,z);
212                        if (x == xmin) x = xmax; else x = xmin;
213                    }
214                }
215            }
216            GL.End();
217        }
218
219
220
221    }
222}
Note: See TracBrowser for help on using the repository browser.