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 ILNumerics;
|
---|
44 | using ILNumerics.Drawing;
|
---|
45 | using ILNumerics.Drawing.Graphs;
|
---|
46 | using ILNumerics.Drawing.Shapes;
|
---|
47 | using ILNumerics.Drawing.Labeling;
|
---|
48 | using System.Drawing;
|
---|
49 |
|
---|
50 | namespace ILNumerics.Drawing.Plots {
|
---|
51 | /// <summary>
|
---|
52 | /// the plot displays a simple colored lit 3D box
|
---|
53 | /// </summary>
|
---|
54 | public class ILLitBox3D : ILPlot {
|
---|
55 |
|
---|
56 | #region public enums
|
---|
57 | /// <summary>
|
---|
58 | /// enum for all
|
---|
59 | /// </summary>
|
---|
60 | public static class QuadIndices {
|
---|
61 | public static readonly int front = 0;
|
---|
62 | public static readonly int right = 1;
|
---|
63 | public static readonly int back = 2;
|
---|
64 | public static readonly int left = 3;
|
---|
65 | public static readonly int top = 4;
|
---|
66 | public static readonly int bottom = 5;
|
---|
67 | }
|
---|
68 | #endregion
|
---|
69 |
|
---|
70 | #region attributes
|
---|
71 | ILLitQuad[] m_quads;
|
---|
72 | ILLineProperties m_lineProperties;
|
---|
73 | Color m_gradColor;
|
---|
74 | Color m_fillColor;
|
---|
75 | Color m_topColor;
|
---|
76 | byte m_opacity = 255;
|
---|
77 | ILWorldLabel m_valLabel;
|
---|
78 | ILShapeLabel m_topLabel;
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | #region properties
|
---|
82 | /// <summary>
|
---|
83 | /// get the opacity for the box or set it
|
---|
84 | /// </summary>
|
---|
85 | public byte Opacity {
|
---|
86 | get { return m_opacity; }
|
---|
87 | set {
|
---|
88 | foreach (ILLitQuad s in m_quads) {
|
---|
89 | s.Opacity = value;
|
---|
90 | for (int i = 0; i < s.Vertices.Length; i++) {
|
---|
91 | s.Vertices[i].Alpha = value;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | m_opacity = value; }
|
---|
95 | }
|
---|
96 | /// <summary>
|
---|
97 | /// the color used at one corner for each quad to generate a simple gradient effect
|
---|
98 | /// </summary>
|
---|
99 | public Color GradientColor {
|
---|
100 | get { return m_gradColor; }
|
---|
101 | set {
|
---|
102 | m_gradColor = value;
|
---|
103 | updateColors();
|
---|
104 | }
|
---|
105 | }
|
---|
106 | /// <summary>
|
---|
107 | /// properties of the edge lines
|
---|
108 | /// </summary>
|
---|
109 | public ILLineProperties Edges {
|
---|
110 | get {
|
---|
111 | return m_lineProperties;
|
---|
112 | }
|
---|
113 | }
|
---|
114 | /// <summary>
|
---|
115 | /// overall fill color (bottom and lower area of color gradient)
|
---|
116 | /// </summary>
|
---|
117 | public Color FillColor {
|
---|
118 | get { return m_fillColor; }
|
---|
119 | set {
|
---|
120 | m_fillColor = value;
|
---|
121 | updateColors();
|
---|
122 | }
|
---|
123 | }
|
---|
124 | /// <summary>
|
---|
125 | /// top color (top and upper area of color gradient)
|
---|
126 | /// </summary>
|
---|
127 | public Color TopColor {
|
---|
128 | get { return m_topColor; }
|
---|
129 | set {
|
---|
130 | m_topColor = value;
|
---|
131 | updateColors();
|
---|
132 | }
|
---|
133 | }
|
---|
134 | /// <summary>
|
---|
135 | /// reference to the label which renders the current z-value onto the top area (world coords)
|
---|
136 | /// </summary>
|
---|
137 | public ILWorldLabel ValueLabel {
|
---|
138 | get {
|
---|
139 | return m_valLabel;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | /// <summary>
|
---|
143 | /// label drawn in screen coords on top of the lit box
|
---|
144 | /// </summary>
|
---|
145 | public ILShapeLabel TopLabel {
|
---|
146 | get { return m_topLabel; }
|
---|
147 | }
|
---|
148 | /// <summary>
|
---|
149 | /// get reference to the quads, the lit box is assembled out of
|
---|
150 | /// </summary>
|
---|
151 | public ILLitQuad[] Quads {
|
---|
152 | get { return m_quads; }
|
---|
153 | }
|
---|
154 | #endregion
|
---|
155 |
|
---|
156 | #region constructor
|
---|
157 | /// <summary>
|
---|
158 | /// create new lit 3D box
|
---|
159 | /// </summary>
|
---|
160 | /// <param name="panel">panel hosting the scene</param>
|
---|
161 | /// <param name="min">minimum coordinates defining the box' dimensions (x,y,z)</param>
|
---|
162 | /// <param name="max">minimum coordinates defining the box' dimensions (x,y,z)</param>
|
---|
163 | /// <param name="fillColor">overall color for the box</param>
|
---|
164 | /// <param name="topColor">color used to color the top edges of the box</param>
|
---|
165 | public ILLitBox3D(ILPanel panel, ILPoint3Df min, ILPoint3Df max, Color fillColor, Color topColor)
|
---|
166 | : base(panel) {
|
---|
167 | m_lineProperties = new ILLineProperties();
|
---|
168 | m_lineProperties.Changed += new EventHandler(m_lineProperties_Changed);
|
---|
169 | m_valLabel = new ILWorldLabel(panel);
|
---|
170 | m_valLabel.Text = ""; // (max * 1000).Z.ToString("F3");
|
---|
171 |
|
---|
172 | ILPoint3Df mi = ILPoint3Df.Min(min, max);
|
---|
173 | ILPoint3Df ma = ILPoint3Df.Max(min, max);
|
---|
174 | m_valLabel.PositionMax = new ILPoint3Df(ma.X,mi.Y,ma.Z);
|
---|
175 | m_valLabel.PositionMin = new ILPoint3Df(mi.X, ma.Y, ma.Z); ;
|
---|
176 |
|
---|
177 | m_topLabel = new ILShapeLabel(panel);
|
---|
178 | m_topLabel.Color = Color.Blue;
|
---|
179 | //m_topLabel.Font = new Font("Arial", 10, FontStyle.Bold);
|
---|
180 | string tval = max.Z.ToString("F2");
|
---|
181 | m_topLabel.Text = String.Format("{0}",tval);
|
---|
182 | m_topLabel.Anchor = new PointF(0.5f, 1);
|
---|
183 |
|
---|
184 | m_topColor = topColor;
|
---|
185 |
|
---|
186 | #region setup quads
|
---|
187 | m_quads = new ILLitQuad[6];
|
---|
188 |
|
---|
189 | // front
|
---|
190 | ILLitQuad quad = new ILLitQuad(m_panel);
|
---|
191 | quad.Vertices[0].Position = new ILPoint3Df(min.X, min.Y, min.Z);
|
---|
192 | quad.Vertices[1].Position = new ILPoint3Df(min.X, min.Y, max.Z);
|
---|
193 | quad.Vertices[2].Position = new ILPoint3Df(max.X, min.Y, max.Z);
|
---|
194 | quad.Vertices[3].Position = new ILPoint3Df(max.X, min.Y, min.Z);
|
---|
195 | m_quads[QuadIndices.front] = quad;
|
---|
196 | // right
|
---|
197 | quad = new ILLitQuad(m_panel);
|
---|
198 | quad.Vertices[0].Position = new ILPoint3Df(max.X, min.Y, min.Z);
|
---|
199 | quad.Vertices[1].Position = new ILPoint3Df(max.X, min.Y, max.Z);
|
---|
200 | quad.Vertices[2].Position = new ILPoint3Df(max.X, max.Y, max.Z);
|
---|
201 | quad.Vertices[3].Position = new ILPoint3Df(max.X, max.Y, min.Z);
|
---|
202 | m_quads[QuadIndices.right] = quad;
|
---|
203 | // back
|
---|
204 | quad = new ILLitQuad(m_panel);
|
---|
205 | quad.Vertices[0].Position = new ILPoint3Df(max.X, max.Y, min.Z);
|
---|
206 | quad.Vertices[1].Position = new ILPoint3Df(max.X, max.Y, max.Z);
|
---|
207 | quad.Vertices[2].Position = new ILPoint3Df(min.X, max.Y, max.Z);
|
---|
208 | quad.Vertices[3].Position = new ILPoint3Df(min.X, max.Y, min.Z);
|
---|
209 | m_quads[QuadIndices.back] = quad;
|
---|
210 | // left
|
---|
211 | quad = new ILLitQuad(m_panel);
|
---|
212 | quad.Vertices[0].Position = new ILPoint3Df(min.X, max.Y, min.Z);
|
---|
213 | quad.Vertices[1].Position = new ILPoint3Df(min.X, max.Y, max.Z);
|
---|
214 | quad.Vertices[2].Position = new ILPoint3Df(min.X, min.Y, max.Z);
|
---|
215 | quad.Vertices[3].Position = new ILPoint3Df(min.X, min.Y, min.Z);
|
---|
216 | m_quads[QuadIndices.left] = quad;
|
---|
217 | // top
|
---|
218 | quad = new ILLitQuad(m_panel);
|
---|
219 | quad.Vertices[0].Position = new ILPoint3Df(min.X, min.Y, max.Z);
|
---|
220 | quad.Vertices[1].Position = new ILPoint3Df(max.X, min.Y, max.Z);
|
---|
221 | quad.Vertices[2].Position = new ILPoint3Df(max.X, max.Y, max.Z);
|
---|
222 | quad.Vertices[3].Position = new ILPoint3Df(min.X, max.Y, max.Z);
|
---|
223 | m_quads[QuadIndices.top] = quad;
|
---|
224 | // bottom
|
---|
225 | quad = new ILLitQuad(m_panel);
|
---|
226 | quad.Vertices[0].Position = new ILPoint3Df(min.X, min.Y, min.Z);
|
---|
227 | quad.Vertices[1].Position = new ILPoint3Df(max.X, min.Y, min.Z);
|
---|
228 | quad.Vertices[2].Position = new ILPoint3Df(max.X, max.Y, min.Z);
|
---|
229 | quad.Vertices[3].Position = new ILPoint3Df(min.X, max.Y, min.Z);
|
---|
230 | m_quads[QuadIndices.bottom] = quad;
|
---|
231 | #endregion
|
---|
232 | EventingSuspend();
|
---|
233 | foreach (ILLitQuad s in m_quads) {
|
---|
234 | s.Label.Text = "";
|
---|
235 | s.Shading = ShadingStyles.Interpolate;
|
---|
236 | s.Opacity = m_opacity;
|
---|
237 | s.Border.Color = Color.Gray;
|
---|
238 | s.Border.Width = 1;
|
---|
239 | s.Border.Visible = true;
|
---|
240 | s.Border.Antialiasing = false;
|
---|
241 | Add(s);
|
---|
242 | }
|
---|
243 | EventingResume();
|
---|
244 | m_fillColor = fillColor;
|
---|
245 | updateColors();
|
---|
246 | }
|
---|
247 | #endregion
|
---|
248 |
|
---|
249 | #region public interface
|
---|
250 | /// <summary>
|
---|
251 | /// (internally used) draws the plot
|
---|
252 | /// </summary>
|
---|
253 | /// <param name="props"></param>
|
---|
254 | internal override void Draw(ILRenderProperties props) {
|
---|
255 | base.Draw(props);
|
---|
256 | m_valLabel.Draw(props);
|
---|
257 | ILPoint3Df labPos = m_quads[QuadIndices.top].Center;
|
---|
258 | labPos.Z = Math.Max(m_quads[QuadIndices.top].Center.Z,m_quads[QuadIndices.bottom].Center.Z);
|
---|
259 | m_topLabel.Draw(props,labPos);
|
---|
260 | }
|
---|
261 | #endregion
|
---|
262 |
|
---|
263 | #region private helpers
|
---|
264 | /// <summary>
|
---|
265 | /// update all quad borders with new settings
|
---|
266 | /// </summary>
|
---|
267 | /// <param name="sender"></param>
|
---|
268 | /// <param name="e"></param>
|
---|
269 | void m_lineProperties_Changed(object sender, EventArgs e) {
|
---|
270 | foreach (ILLitQuad quad in m_quads) {
|
---|
271 | quad.Border.CopyFrom(m_lineProperties);
|
---|
272 | }
|
---|
273 |
|
---|
274 | }
|
---|
275 | /// <summary>
|
---|
276 | /// distribute changed color settings to all quads
|
---|
277 | /// </summary>
|
---|
278 | private void updateColors() {
|
---|
279 | SetColorGradient(m_quads[QuadIndices.front], m_fillColor, m_topColor, m_topColor, m_gradColor);
|
---|
280 | SetColorGradient(m_quads[QuadIndices.right], m_fillColor, m_topColor, m_topColor, m_gradColor);
|
---|
281 | SetColorGradient(m_quads[QuadIndices.back], m_fillColor, m_topColor, m_topColor, m_gradColor);
|
---|
282 | SetColorGradient(m_quads[QuadIndices.left], m_fillColor, m_topColor, m_topColor, m_gradColor);
|
---|
283 | SetColorGradient(m_quads[QuadIndices.top], m_topColor, m_topColor, m_topColor, m_topColor);
|
---|
284 | SetColorGradient(m_quads[QuadIndices.bottom], m_topColor, m_topColor, m_topColor, m_topColor);
|
---|
285 | }
|
---|
286 | /// <summary>
|
---|
287 | /// color settings helper
|
---|
288 | /// </summary>
|
---|
289 | /// <param name="quad">quad index</param>
|
---|
290 | /// <param name="col0">color 1</param>
|
---|
291 | /// <param name="col1">color 2</param>
|
---|
292 | /// <param name="col2">color 3</param>
|
---|
293 | /// <param name="col3">color 4</param>
|
---|
294 | private void SetColorGradient(
|
---|
295 | ILLitQuad quad, Color col0, Color col1, Color col2, Color col3) {
|
---|
296 | quad.Vertices[0].Color = col0;
|
---|
297 | quad.Vertices[0].Alpha = m_opacity;
|
---|
298 | quad.Vertices[1].Color = col1;
|
---|
299 | quad.Vertices[1].Alpha = m_opacity;
|
---|
300 | quad.Vertices[2].Color = col2;
|
---|
301 | quad.Vertices[2].Alpha = m_opacity;
|
---|
302 | quad.Vertices[3].Color = col3;
|
---|
303 | quad.Vertices[3].Alpha = m_opacity;
|
---|
304 | }
|
---|
305 | #endregion
|
---|
306 | }
|
---|
307 | }
|
---|