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 |
|
---|
40 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 | using System.Drawing;
|
---|
44 | using OpenTK;
|
---|
45 | using OpenTK.Graphics;
|
---|
46 | using OpenTK.Graphics.OpenGL;
|
---|
47 | using OpenTK.Graphics.OpenGL.Enums;
|
---|
48 | using ILNumerics.Drawing;
|
---|
49 | using ILNumerics.Drawing.Interfaces;
|
---|
50 | using ILNumerics.Drawing.Labeling;
|
---|
51 |
|
---|
52 | namespace ILNumerics.Drawing.Platform.OpenGL {
|
---|
53 | /// <summary>
|
---|
54 | /// OpenGL implementation of ILAxis (X axis)
|
---|
55 | /// </summary>
|
---|
56 | class ILOGLZAxis : ILOGLAxis {
|
---|
57 |
|
---|
58 | /// <summary>
|
---|
59 | /// Constructor - this class should be created only from within ILNumerics assemblies!
|
---|
60 | /// </summary>
|
---|
61 | /// <param name="clippingView">panels clipping view</param>
|
---|
62 | /// <param name="layout">instance with layout informations</param>
|
---|
63 | /// <param name="panel">the panel containing the axis</param>
|
---|
64 | internal ILOGLZAxis (ILClippingData clippingView,
|
---|
65 | ILLayoutData layout,
|
---|
66 | ILOGLPanel panel)
|
---|
67 | : base (AxisNames.ZAxis,clippingView,layout,panel) { }
|
---|
68 |
|
---|
69 | /// <summary>
|
---|
70 | /// draw all lines for the axis
|
---|
71 | /// </summary>
|
---|
72 | /// <param name="g">graphics object (ignored)</param>
|
---|
73 | /// <param name="background">true: draw lines in the back only, false: draw foreground lines</param>
|
---|
74 | protected override void iDrawAxis(ILRenderProperties p, bool background) {
|
---|
75 | // create vertex data: main axis and ticks
|
---|
76 | if (!m_visible) return;
|
---|
77 | float tickLen;
|
---|
78 | float x, y, z
|
---|
79 | , xmin = m_clipping.XMin
|
---|
80 | , xmax = m_clipping.XMax
|
---|
81 | , ymin = m_clipping.YMin
|
---|
82 | , ymax = m_clipping.YMax
|
---|
83 | , zmin = m_clipping.ZMin
|
---|
84 | , zmax = m_clipping.ZMax;
|
---|
85 | tickLen = m_labeledTicks.TickFraction
|
---|
86 | * ((m_labeledTicks.Direction == TickDirection.Inside) ? m_clipping.WidthF : -m_clipping.WidthF);
|
---|
87 | //ConfigureOGLLineProperties(LineStyle.Solid,1);
|
---|
88 | // must draw ticks?
|
---|
89 | bool drawticks,drawlines = false;
|
---|
90 | if (m_labeledTicks.Display == TickDisplay.BothSides) {
|
---|
91 | drawticks = true;
|
---|
92 | } else {
|
---|
93 | drawticks = (background && !m_layoutData.CameraPosition.LooksFromTop)
|
---|
94 | ||(!background && m_layoutData.CameraPosition.LooksFromTop);
|
---|
95 | }
|
---|
96 | x = xmin; y = ymin; z = zmin;
|
---|
97 | float x2, y2, tickLen2 = tickLen;
|
---|
98 | switch (m_layoutData.CameraPosition.Quadrant) {
|
---|
99 | case CameraQuadrant.TopLeftFront: // Q1
|
---|
100 | case CameraQuadrant.BottomLeftFront:
|
---|
101 | x = xmin;
|
---|
102 | x2 = xmin;
|
---|
103 | y = ymax;
|
---|
104 | y2 = ymin;
|
---|
105 | //tickLen2 *= -1.0f;
|
---|
106 | break;
|
---|
107 | case CameraQuadrant.TopLeftBack: // Q2
|
---|
108 | case CameraQuadrant.BottomLeftBack:
|
---|
109 | x = xmax;
|
---|
110 | y = ymax;
|
---|
111 | x2 = xmin;
|
---|
112 | y2 = ymax;
|
---|
113 | tickLen *= -1.0f;
|
---|
114 | break;
|
---|
115 | case CameraQuadrant.TopRightBack: // Q3
|
---|
116 | case CameraQuadrant.BottomRightBack:
|
---|
117 | x = xmax;
|
---|
118 | x2 = xmax;
|
---|
119 | y = ymin;
|
---|
120 | y2 = ymax;
|
---|
121 | tickLen *= -1.0f;
|
---|
122 | tickLen2 *= -1.0f;
|
---|
123 | break;
|
---|
124 | case CameraQuadrant.TopRightFront:
|
---|
125 | case CameraQuadrant.BottomRightFront: // Q4
|
---|
126 | default:
|
---|
127 | x = xmin;
|
---|
128 | x2 = xmax;
|
---|
129 | y = ymin;
|
---|
130 | y2 = ymin;
|
---|
131 | tickLen2 *= -1.0f;
|
---|
132 | break;
|
---|
133 | }
|
---|
134 | if (background) {
|
---|
135 | if (x == xmin) x = xmax; else x = xmin;
|
---|
136 | if (y == ymin) y = ymax; else y = ymin;
|
---|
137 | if (x2 == xmin) x2 = xmax; else x2 = xmin;
|
---|
138 | if (y2 == ymin) y2 = ymax; else y2 = ymin;
|
---|
139 | GL.Disable(EnableCap.DepthTest);
|
---|
140 | if (m_farLines.Visible) {
|
---|
141 | drawlines = true;
|
---|
142 | ILOGLPanel.SetupLineStyle(m_farLines);
|
---|
143 | }
|
---|
144 | } else {
|
---|
145 | if (m_nearLines.Visible) {
|
---|
146 | drawlines = true;
|
---|
147 | ILOGLPanel.SetupLineStyle(m_nearLines);
|
---|
148 | }
|
---|
149 | }
|
---|
150 | if (drawlines) {
|
---|
151 | GL.Begin(BeginMode.Lines);
|
---|
152 | GL.Vertex3(x,y,z);
|
---|
153 | z = zmax;
|
---|
154 | GL.Vertex3(x,y,z);
|
---|
155 | GL.Vertex3(x2,y2,z);
|
---|
156 | z = zmin;
|
---|
157 | GL.Vertex3(x2,y2,z);
|
---|
158 | GL.End();
|
---|
159 | }
|
---|
160 | if (m_labeledTicks.Display == TickDisplay.BothSides || (!background && drawlines)) {
|
---|
161 | #region create ticks
|
---|
162 | GL.Enable(EnableCap.DepthTest);
|
---|
163 | if (background) {
|
---|
164 | GL.Color3(m_labeledTicks.FarColor);
|
---|
165 | tickLen *= -1.0f;
|
---|
166 | tickLen2 *= -1.0f;
|
---|
167 | } else
|
---|
168 | GL.Color3(m_labeledTicks.NearColor);
|
---|
169 | GL.Disable(EnableCap.LineStipple);
|
---|
170 | GL.Begin(BeginMode.Lines);
|
---|
171 | foreach (LabeledTick tick in m_labeledTicks) {
|
---|
172 | if (tick.Position >= m_clipping.ZMin
|
---|
173 | && tick.Position <= m_clipping.ZMax) {
|
---|
174 | z = tick.Position;
|
---|
175 | GL.Vertex3(x,y,z);
|
---|
176 | x += tickLen;
|
---|
177 | GL.Vertex3(x,y,z);
|
---|
178 | x -= tickLen;
|
---|
179 | GL.Vertex3(x2,y2,z);
|
---|
180 | x2 += tickLen2;
|
---|
181 | GL.Vertex3(x2,y2,z);
|
---|
182 | x2 -= tickLen2;
|
---|
183 | }
|
---|
184 | }
|
---|
185 | GL.End();
|
---|
186 | #endregion
|
---|
187 | }
|
---|
188 | if (background && m_grid.Visible)
|
---|
189 | drawGrid();
|
---|
190 | }
|
---|
191 |
|
---|
192 | /// <summary>
|
---|
193 | /// draw all grid lines for axis
|
---|
194 | /// </summary>
|
---|
195 | protected override void drawGrid() {
|
---|
196 | float x1,y1,z;
|
---|
197 | float x2,y2,x3,y3;
|
---|
198 | float xmin = m_clipping.XMin;
|
---|
199 | float ymin = m_clipping.YMin;
|
---|
200 | float xmax = m_clipping.XMax;
|
---|
201 | float ymax = m_clipping.YMax;
|
---|
202 |
|
---|
203 | ILOGLPanel.SetupLineStyle(m_grid);
|
---|
204 | GL.Disable(EnableCap.DepthTest);
|
---|
205 | GL.Enable(EnableCap.Blend);
|
---|
206 | GL.Begin(BeginMode.Lines);
|
---|
207 | #region determine which side to draw on
|
---|
208 | switch (m_layoutData.CameraPosition.Quadrant)
|
---|
209 | {
|
---|
210 | case CameraQuadrant.TopLeftFront:
|
---|
211 | case CameraQuadrant.BottomLeftFront:
|
---|
212 | x1 = xmin; y1 = ymax;
|
---|
213 | x2 = xmax; y2 = ymax;
|
---|
214 | x3 = xmax; y3 = ymin;
|
---|
215 | break;
|
---|
216 | case CameraQuadrant.TopLeftBack:
|
---|
217 | case CameraQuadrant.BottomLeftBack:
|
---|
218 | x1 = xmax; y1 = ymax;
|
---|
219 | x2 = xmax; y2 = ymin;
|
---|
220 | x3 = xmin; y3 = ymin;
|
---|
221 | break;
|
---|
222 | case CameraQuadrant.TopRightBack:
|
---|
223 | case CameraQuadrant.BottomRightBack:
|
---|
224 | x1 = xmax; y1 = ymin;
|
---|
225 | x2 = xmin; y2 = ymin;
|
---|
226 | x3 = xmin; y3 = ymax;
|
---|
227 | break;
|
---|
228 | default:
|
---|
229 | case CameraQuadrant.TopRightFront:
|
---|
230 | case CameraQuadrant.BottomRightFront:
|
---|
231 | x1 = xmin; y1 = ymin;
|
---|
232 | x2 = xmin; y2 = ymax;
|
---|
233 | x3 = xmax; y3 = ymax;
|
---|
234 | break;
|
---|
235 | }
|
---|
236 | #endregion
|
---|
237 | foreach (LabeledTick tick in m_labeledTicks) {
|
---|
238 | if (tick.Position >= m_clipping.ZMin
|
---|
239 | && tick.Position <= m_clipping.ZMax) {
|
---|
240 | z = tick.Position;
|
---|
241 | GL.Vertex3(x1,y1,z);
|
---|
242 | GL.Vertex3(x2,y2,z);
|
---|
243 | GL.Vertex3(x2,y2,z);
|
---|
244 | GL.Vertex3(x3,y3,z);
|
---|
245 | }
|
---|
246 | }
|
---|
247 | GL.End();
|
---|
248 | }
|
---|
249 |
|
---|
250 | }
|
---|
251 | }
|
---|