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 | #pragma warning disable 1591
|
---|
41 |
|
---|
42 | using System;
|
---|
43 | using System.Collections.Generic;
|
---|
44 | using System.Text;
|
---|
45 | using System.Drawing;
|
---|
46 | using System.Runtime.InteropServices;
|
---|
47 | using ILNumerics.Drawing.Graphs;
|
---|
48 |
|
---|
49 |
|
---|
50 | namespace ILNumerics.Drawing {
|
---|
51 |
|
---|
52 |
|
---|
53 | /// <summary>
|
---|
54 | /// Options for adapting ILPanel view limits
|
---|
55 | /// </summary>
|
---|
56 | public enum AutoZoomOptions {
|
---|
57 | /// <summary>
|
---|
58 | /// never adapt automatically, the view limits are handled by the user
|
---|
59 | /// </summary>
|
---|
60 | Never,
|
---|
61 | /// <summary>
|
---|
62 | /// Only adapt view limits once at startup, later changes of the data limits will not affect the view limits
|
---|
63 | /// </summary>
|
---|
64 | OnStartup,
|
---|
65 | /// <summary>
|
---|
66 | /// View limits will automatically adapt changes of data limits. (Default)
|
---|
67 | /// </summary>
|
---|
68 | OnDataChanges
|
---|
69 | }
|
---|
70 | /// <summary>
|
---|
71 | /// modes for projecting the rendering output to the available client area
|
---|
72 | /// </summary>
|
---|
73 | public enum AspectRatioMode {
|
---|
74 | /// <summary>
|
---|
75 | /// plots fill available rendering area of the PlotCubeScreenRectF rectangle
|
---|
76 | /// </summary>
|
---|
77 | StretchToFill,
|
---|
78 | /// <summary>
|
---|
79 | /// plots will be shrinked to fit inside PlotCubeScreeRectF but maintain data aspect ratio
|
---|
80 | /// </summary>
|
---|
81 | MaintainRatios
|
---|
82 | }
|
---|
83 | /// <summary>
|
---|
84 | /// defines the movement from current to new zoom setting
|
---|
85 | /// </summary>
|
---|
86 | public enum ZoomModes {
|
---|
87 | /// <summary>
|
---|
88 | /// No ramp, jump to new zoom setting
|
---|
89 | /// </summary>
|
---|
90 | Jump,
|
---|
91 | /// <summary>
|
---|
92 | /// morph softly to new zoom setting
|
---|
93 | /// </summary>
|
---|
94 | RollSoft,
|
---|
95 | /// <summary>
|
---|
96 | /// morph faster to new setting
|
---|
97 | /// </summary>
|
---|
98 | RollHard,
|
---|
99 | /// <summary>
|
---|
100 | /// morph to new setting by 'going over the limit'
|
---|
101 | /// </summary>
|
---|
102 | RollOverride
|
---|
103 | }
|
---|
104 | /// <summary>
|
---|
105 | /// predefined colormaps
|
---|
106 | /// </summary>
|
---|
107 | public enum Colormaps {
|
---|
108 | Autumn,
|
---|
109 | Bone,
|
---|
110 | //Colorcube,
|
---|
111 | Cool,
|
---|
112 | Copper,
|
---|
113 | Flag,
|
---|
114 | Gray,
|
---|
115 | Hot,
|
---|
116 | Hsv,
|
---|
117 | ILNumerics,
|
---|
118 | Jet,
|
---|
119 | Lines,
|
---|
120 | Pink,
|
---|
121 | Prism,
|
---|
122 | Spring,
|
---|
123 | Summer,
|
---|
124 | White,
|
---|
125 | Winter
|
---|
126 | }
|
---|
127 | /// <summary>
|
---|
128 | /// Orientation for labels and other purposes
|
---|
129 | /// </summary>
|
---|
130 | public enum TextOrientation {
|
---|
131 | Horizontal,
|
---|
132 | Vertical
|
---|
133 | }
|
---|
134 | /// <summary>
|
---|
135 | /// Alignment for
|
---|
136 | /// </summary>
|
---|
137 | public enum VerticalAlignment {
|
---|
138 | Lower,
|
---|
139 | Middle,
|
---|
140 | Upper
|
---|
141 | }
|
---|
142 |
|
---|
143 | /// <summary>
|
---|
144 | /// Suggest, how label positions for axis ticks are to be choosen
|
---|
145 | /// </summary>
|
---|
146 | public enum TickLabelRenderingHint {
|
---|
147 | /// <summary>
|
---|
148 | /// tick labels will optimally fill the whole axis length
|
---|
149 | /// </summary>
|
---|
150 | Filled,
|
---|
151 | /// <summary>
|
---|
152 | /// multiples of 10^n will be prefered for label steps
|
---|
153 | /// </summary>
|
---|
154 | Multiple1,
|
---|
155 | /// <summary>
|
---|
156 | /// multiples of 2*10^n will be prefered for label steps
|
---|
157 | /// </summary>
|
---|
158 | Multiple2,
|
---|
159 | /// <summary>
|
---|
160 | /// multiples of 5*10^n will be prefered for label steps
|
---|
161 | /// </summary>
|
---|
162 | Multiple5,
|
---|
163 | /// <summary>
|
---|
164 | /// Try to find the optimal division for tick label steps [default]
|
---|
165 | /// </summary>
|
---|
166 | /// <remarks>This method is the most computational intensive one.</remarks>
|
---|
167 | Auto
|
---|
168 | }
|
---|
169 |
|
---|
170 | /// <summary>
|
---|
171 | /// Names for all 3 axes
|
---|
172 | /// </summary>
|
---|
173 | public enum AxisNames {
|
---|
174 | XAxis = 0,
|
---|
175 | YAxis = 1,
|
---|
176 | ZAxis = 2
|
---|
177 | }
|
---|
178 |
|
---|
179 | /// <summary>
|
---|
180 | /// simple single unlabled tick
|
---|
181 | /// </summary>
|
---|
182 | public struct UnlabeledTick {
|
---|
183 | /// <summary>
|
---|
184 | /// Position of tick
|
---|
185 | /// </summary>
|
---|
186 | public float Position;
|
---|
187 | }
|
---|
188 | /// <summary>
|
---|
189 | /// Axis ticks spacing type: linear, logarithmic
|
---|
190 | /// </summary>
|
---|
191 | public enum AxisType {
|
---|
192 | /// <summary>
|
---|
193 | /// linear axis tick spacing
|
---|
194 | /// </summary>
|
---|
195 | Linear,
|
---|
196 | /// <summary>
|
---|
197 | /// logarithmic axis tick spacing
|
---|
198 | /// </summary>
|
---|
199 | Logarithmic
|
---|
200 | }
|
---|
201 | /// <summary>
|
---|
202 | /// On which sides ticks will be displayed
|
---|
203 | /// </summary>
|
---|
204 | public enum TickDisplay {
|
---|
205 | /// <summary>
|
---|
206 | /// ticks for axis will be displayed on label side only
|
---|
207 | /// </summary>
|
---|
208 | LabelSide,
|
---|
209 | /// <summary>
|
---|
210 | /// ticks for axis will be displayed on label - and the opposite site
|
---|
211 | /// </summary>
|
---|
212 | BothSides
|
---|
213 | }
|
---|
214 | /// <summary>
|
---|
215 | /// how ticks are displayed (inside/outside)
|
---|
216 | /// </summary>
|
---|
217 | public enum TickDirection {
|
---|
218 | /// <summary>
|
---|
219 | /// Ticks will lay inside the rendering cube
|
---|
220 | /// </summary>
|
---|
221 | Inside,
|
---|
222 | /// <summary>
|
---|
223 | /// Ticks will lay outside the rendering cube
|
---|
224 | /// </summary>
|
---|
225 | Outside
|
---|
226 | }
|
---|
227 |
|
---|
228 | /// <summary>
|
---|
229 | /// orientation for axis labels (not implemented)
|
---|
230 | /// </summary>
|
---|
231 | public enum ILAxisLabelOrientation {
|
---|
232 | Normal,
|
---|
233 | Rotate90,
|
---|
234 | Rotate180,
|
---|
235 | Rotate270,
|
---|
236 | Arbitrary
|
---|
237 | }
|
---|
238 | /// <summary>
|
---|
239 | /// TickModes - automatic or manual axis tick positioning
|
---|
240 | /// </summary>
|
---|
241 | public enum TickMode {
|
---|
242 | /// <summary>
|
---|
243 | /// find tick positions automatically
|
---|
244 | /// </summary>
|
---|
245 | Auto,
|
---|
246 | /// <summary>
|
---|
247 | /// manually create ticks
|
---|
248 | /// </summary>
|
---|
249 | Manual
|
---|
250 | }
|
---|
251 | /// <summary>
|
---|
252 | /// options for the sizing of the projection of the plot cube onto the 2D screen client area of the control
|
---|
253 | /// </summary>
|
---|
254 | public enum PlotBoxScreenSizeMode {
|
---|
255 | /// <summary>
|
---|
256 | /// the projection of the plot cube drawing area fills the whole controls space (labels may be hidden)
|
---|
257 | /// </summary>
|
---|
258 | Maximum,
|
---|
259 | /// <summary>
|
---|
260 | /// the size of plot cube projection rectangle is automatically determined, taking labels size into account
|
---|
261 | /// </summary>
|
---|
262 | Optimal,
|
---|
263 | /// <summary>
|
---|
264 | /// more pixel exact positioning, strictly only the place really needed for labels is used (slower)
|
---|
265 | /// </summary>
|
---|
266 | StrictOptimal,
|
---|
267 | /// <summary>
|
---|
268 | /// No automatic resizing for the cube projection size, values from PlotCubeScreenRect are taken
|
---|
269 | /// </summary>
|
---|
270 | Manual
|
---|
271 | }
|
---|
272 | /// <summary>
|
---|
273 | /// possible states/reasons/sources for rendering the scene
|
---|
274 | /// </summary>
|
---|
275 | internal enum RenderReason {
|
---|
276 | /// <summary>
|
---|
277 | /// normal source, the scene is to be rendered the common way
|
---|
278 | /// </summary>
|
---|
279 | PaintEvent,
|
---|
280 | /// <summary>
|
---|
281 | /// the rendering was re-initialized because the matrices need to be recalculated for laying out labels correctly
|
---|
282 | /// </summary>
|
---|
283 | RecalcLabels
|
---|
284 | }
|
---|
285 | /// <summary>
|
---|
286 | /// Alignments for labels
|
---|
287 | /// </summary>
|
---|
288 | public enum LabelAlign {
|
---|
289 | /// <summary>
|
---|
290 | /// align the label near the lower range limit
|
---|
291 | /// </summary>
|
---|
292 | Lower,
|
---|
293 | /// <summary>
|
---|
294 | /// align the label in the center
|
---|
295 | /// </summary>
|
---|
296 | Center,
|
---|
297 | /// <summary>
|
---|
298 | /// align the label near the upper range limit
|
---|
299 | /// </summary>
|
---|
300 | Upper
|
---|
301 | }
|
---|
302 | /// <summary>
|
---|
303 | /// Possible alignments for tick labels
|
---|
304 | /// </summary>
|
---|
305 | /// <remarks>member of this enum can get bitwise combined. Default is: Top,Left</remarks>
|
---|
306 | [FlagsAttribute]
|
---|
307 | public enum TickLabelAlign {
|
---|
308 | /// <summary>
|
---|
309 | /// align the label to the left side
|
---|
310 | /// </summary>
|
---|
311 | left = 0,
|
---|
312 | /// <summary>
|
---|
313 | /// align the labels to the center
|
---|
314 | /// </summary>
|
---|
315 | center = 1,
|
---|
316 | /// <summary>
|
---|
317 | /// align the label to the right side
|
---|
318 | /// </summary>
|
---|
319 | right = 2,
|
---|
320 | /// <summary>
|
---|
321 | /// align the label to top
|
---|
322 | /// </summary>
|
---|
323 | top = 0,
|
---|
324 | /// <summary>
|
---|
325 | /// align the label to center vertically
|
---|
326 | /// </summary>
|
---|
327 | vertCenter = 4,
|
---|
328 | /// <summary>
|
---|
329 | /// align the label to bottom
|
---|
330 | /// </summary>
|
---|
331 | bottom = 16
|
---|
332 | }
|
---|
333 |
|
---|
334 | /// <summary>
|
---|
335 | /// projection types
|
---|
336 | /// </summary>
|
---|
337 | public enum Projection {
|
---|
338 | /// <summary>
|
---|
339 | /// 3D graphs will be distorted for opotimized 3D impression
|
---|
340 | /// </summary>
|
---|
341 | Perspective,
|
---|
342 | /// <summary>
|
---|
343 | /// graphs will not be distorted. objects in the front will get the same size as objects in the back
|
---|
344 | /// </summary>
|
---|
345 | Orthographic
|
---|
346 | }
|
---|
347 |
|
---|
348 | /// <summary>
|
---|
349 | /// valid marker styles (partially supported)
|
---|
350 | /// </summary>
|
---|
351 | public enum MarkerStyle {
|
---|
352 | /// <summary>
|
---|
353 | /// draw markers as dots
|
---|
354 | /// </summary>
|
---|
355 | Dot,
|
---|
356 | /// <summary>
|
---|
357 | /// draw markers as circle
|
---|
358 | /// </summary>
|
---|
359 | Circle,
|
---|
360 | /// <summary>
|
---|
361 | /// draw markers as diamonds
|
---|
362 | /// </summary>
|
---|
363 | Diamond,
|
---|
364 | /// <summary>
|
---|
365 | /// draw markers as square
|
---|
366 | /// </summary>
|
---|
367 | Square,
|
---|
368 | /// <summary>
|
---|
369 | /// draw markers as up pointing triangles
|
---|
370 | /// </summary>
|
---|
371 | TriangleUp,
|
---|
372 | /// <summary>
|
---|
373 | /// draw markers as up pointing triangles
|
---|
374 | /// </summary>
|
---|
375 | TriangleDown,
|
---|
376 | /// <summary>
|
---|
377 | /// draw markers as up pointing triangles
|
---|
378 | /// </summary>
|
---|
379 | TriangleLeft,
|
---|
380 | /// <summary>
|
---|
381 | /// draw markers as up pointing triangles
|
---|
382 | /// </summary>
|
---|
383 | TriangleRight,
|
---|
384 | /// <summary>
|
---|
385 | /// draw markers as plus
|
---|
386 | /// </summary>
|
---|
387 | Plus,
|
---|
388 | /// <summary>
|
---|
389 | /// draw markers as cross
|
---|
390 | /// </summary>
|
---|
391 | Cross,
|
---|
392 | /// <summary>
|
---|
393 | /// do not draw markers
|
---|
394 | /// </summary>
|
---|
395 | None,
|
---|
396 | }
|
---|
397 | /// <summary>
|
---|
398 | /// Possible positions of the camera
|
---|
399 | /// </summary>
|
---|
400 | public enum CameraQuadrant {
|
---|
401 | TopLeftFront,
|
---|
402 | TopLeftBack,
|
---|
403 | TopRightBack,
|
---|
404 | TopRightFront,
|
---|
405 | BottomLeftFront,
|
---|
406 | BottomLeftBack,
|
---|
407 | BottomRightBack,
|
---|
408 | BottomRightFront
|
---|
409 | }
|
---|
410 | /// <summary>
|
---|
411 | /// Shading styles for surface graphs
|
---|
412 | /// </summary>
|
---|
413 | public enum ShadingStyles {
|
---|
414 | /// <summary>
|
---|
415 | /// color will be interpolated between all corners
|
---|
416 | /// </summary>
|
---|
417 | Interpolate,
|
---|
418 | /// <summary>
|
---|
419 | /// same color for whole tile area
|
---|
420 | /// </summary>
|
---|
421 | /// <remarks>The resulting color will
|
---|
422 | /// reflect the average over all corner values for a rectangle</remarks>
|
---|
423 | Flat
|
---|
424 | }
|
---|
425 |
|
---|
426 | /// <summary>
|
---|
427 | /// line style
|
---|
428 | /// </summary>
|
---|
429 | public enum LineStyle {
|
---|
430 | /// <summary>
|
---|
431 | /// solid line
|
---|
432 | /// </summary>
|
---|
433 | Solid = Int32.MaxValue,
|
---|
434 | /// <summary>
|
---|
435 | /// dashed line
|
---|
436 | /// </summary>
|
---|
437 | Dashed = Int16.MaxValue,
|
---|
438 | /// <summary>
|
---|
439 | /// point dashed line
|
---|
440 | /// </summary>
|
---|
441 | PointDash = unchecked((int)4294837760),
|
---|
442 | /// <summary>
|
---|
443 | /// dotted line
|
---|
444 | /// </summary>
|
---|
445 | Dotted = unchecked((int)3435973836),
|
---|
446 | /// <summary>
|
---|
447 | /// use user stipple pattern
|
---|
448 | /// </summary>
|
---|
449 | UserPattern = -1,
|
---|
450 | /// <summary>
|
---|
451 | /// no line at all
|
---|
452 | /// </summary>
|
---|
453 | None = 0
|
---|
454 | }
|
---|
455 | /// <summary>
|
---|
456 | /// modes of mouse interaction with ILPanel
|
---|
457 | /// </summary>
|
---|
458 | public enum InteractiveModes {
|
---|
459 | ZoomRectangle,
|
---|
460 | Rotating,
|
---|
461 | Selecting,
|
---|
462 | Translating,
|
---|
463 | None
|
---|
464 | }
|
---|
465 | /// <summary>
|
---|
466 | /// single precision 3D point structure
|
---|
467 | /// </summary>
|
---|
468 | [StructLayout(LayoutKind.Sequential)]
|
---|
469 | public struct ILPoint3Df {
|
---|
470 | /// <summary>
|
---|
471 | /// X coordinate
|
---|
472 | /// </summary>
|
---|
473 | public float X;
|
---|
474 | /// <summary>
|
---|
475 | /// Y coordinate
|
---|
476 | /// </summary>
|
---|
477 | public float Y;
|
---|
478 | /// <summary>
|
---|
479 | /// Z coordinate
|
---|
480 | /// </summary>
|
---|
481 | public float Z;
|
---|
482 | /// <summary>
|
---|
483 | /// create point in single precision
|
---|
484 | /// </summary>
|
---|
485 | /// <param name="x">X coord</param>
|
---|
486 | /// <param name="y">Y coord</param>
|
---|
487 | /// <param name="z">Z coord</param>
|
---|
488 | public ILPoint3Df (float x, float y, float z) {
|
---|
489 | X = x;
|
---|
490 | Y = y;
|
---|
491 | Z = z;
|
---|
492 | }
|
---|
493 | /// <summary>
|
---|
494 | /// create new ILPoint3Df by double values (for convenience, internally casted to float)
|
---|
495 | /// </summary>
|
---|
496 | /// <param name="x">X coord</param>
|
---|
497 | /// <param name="y">Y coord</param>
|
---|
498 | /// <param name="z">Z coors</param>
|
---|
499 | public ILPoint3Df (double x, double y, double z) {
|
---|
500 | X = (float)x;
|
---|
501 | Y = (float)y;
|
---|
502 | Z = (float)z;
|
---|
503 | }
|
---|
504 | /// <summary>
|
---|
505 | /// convert this point to string representation
|
---|
506 | /// </summary>
|
---|
507 | /// <returns></returns>
|
---|
508 | public override string ToString() {
|
---|
509 | return "X:" + X.ToString() + " Y:" + Y.ToString() + " Z:" + Z.ToString();
|
---|
510 | }
|
---|
511 | /// <summary>
|
---|
512 | /// Access to coords by index
|
---|
513 | /// </summary>
|
---|
514 | /// <param name="index">index number: 0=x, 1=y, 2=z</param>
|
---|
515 | /// <returns>float value of coord specified</returns>
|
---|
516 | public float this[int index] {
|
---|
517 | get {
|
---|
518 | switch (index) {
|
---|
519 | case 0:
|
---|
520 | return X;
|
---|
521 | case 1:
|
---|
522 | return Y;
|
---|
523 | default:
|
---|
524 | return Z;
|
---|
525 | }
|
---|
526 | }
|
---|
527 | }
|
---|
528 | public static bool operator == (ILPoint3Df p1, ILPoint3Df p2) {
|
---|
529 | return (p1.X == p2.X &&
|
---|
530 | p1.Y == p2.Y &&
|
---|
531 | p1.Z == p2.Z);
|
---|
532 | }
|
---|
533 | public static bool operator != (ILPoint3Df p1, ILPoint3Df p2) {
|
---|
534 | return (p1.X != p2.X ||
|
---|
535 | p1.Y != p2.Y ||
|
---|
536 | p1.Z != p2.Z);
|
---|
537 | }
|
---|
538 | public static ILPoint3Df operator + (ILPoint3Df p1, ILPoint3Df p2) {
|
---|
539 | ILPoint3Df ret = new ILPoint3Df();
|
---|
540 | ret.X = p1.X + p2.X;
|
---|
541 | ret.Y = p1.Y + p2.Y;
|
---|
542 | ret.Z = p1.Z + p2.Z;
|
---|
543 | return ret;
|
---|
544 | }
|
---|
545 | public static ILPoint3Df operator - (ILPoint3Df p1, ILPoint3Df p2) {
|
---|
546 | ILPoint3Df ret = new ILPoint3Df();
|
---|
547 | ret.X = p1.X - p2.X;
|
---|
548 | ret.Y = p1.Y - p2.Y;
|
---|
549 | ret.Z = p1.Z - p2.Z;
|
---|
550 | return ret;
|
---|
551 | }
|
---|
552 | public static ILPoint3Df operator * (ILPoint3Df p1, float factor) {
|
---|
553 | ILPoint3Df ret = new ILPoint3Df();
|
---|
554 | ret.X = p1.X * factor;
|
---|
555 | ret.Y = p1.Y * factor;
|
---|
556 | ret.Z = p1.Z * factor;
|
---|
557 | return ret;
|
---|
558 | }
|
---|
559 | public static ILPoint3Df operator *(OpenTK.Math.Matrix4 mat, ILPoint3Df vec) {
|
---|
560 | return new ILPoint3Df(
|
---|
561 | mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z + mat.Row0.W,
|
---|
562 | mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z + mat.Row1.W,
|
---|
563 | mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z + mat.Row2.W);
|
---|
564 | }
|
---|
565 | public static ILPoint3Df operator / (ILPoint3Df p1, float factor) {
|
---|
566 | ILPoint3Df ret = new ILPoint3Df();
|
---|
567 | ret.X = p1.X / factor;
|
---|
568 | ret.Y = p1.Y / factor;
|
---|
569 | ret.Z = p1.Z / factor;
|
---|
570 | return ret;
|
---|
571 | }
|
---|
572 | public static readonly ILPoint3Df Empty = new ILPoint3Df(float.NaN,float.NaN,float.NaN);
|
---|
573 | public bool IsEmtpy () {
|
---|
574 | return float.IsNaN(X) || float.IsNaN(Y) || float.IsNaN(Z);
|
---|
575 | }
|
---|
576 |
|
---|
577 | /// <summary>
|
---|
578 | /// cross product
|
---|
579 | /// </summary>
|
---|
580 | /// <param name="a">vector 1</param>
|
---|
581 | /// <param name="b">vector 2</param>
|
---|
582 | /// <returns>normalized cross product between a x b</returns>
|
---|
583 | public static ILPoint3Df cross(ILPoint3Df a, ILPoint3Df b) {
|
---|
584 | return new ILPoint3Df(
|
---|
585 | a.Y * b.Z - a.Z * b.Y,
|
---|
586 | a.Z * b.X - a.X * b.Z,
|
---|
587 | a.X * b.Y - a.Y * b.X);
|
---|
588 | }
|
---|
589 | /// <summary>
|
---|
590 | /// normalized cross product
|
---|
591 | /// </summary>
|
---|
592 | /// <param name="a">vector 1</param>
|
---|
593 | /// <param name="b">vector 2</param>
|
---|
594 | /// <returns>normalized cross product: a x b</returns>
|
---|
595 | public static ILPoint3Df crossN(ILPoint3Df a, ILPoint3Df b) {
|
---|
596 | ILPoint3Df ret = new ILPoint3Df(
|
---|
597 | a.Y * b.Z - a.Z * b.Y,
|
---|
598 | a.Z * b.X - a.X * b.Z,
|
---|
599 | a.X * b.Y - a.Y * b.X);
|
---|
600 | float len = (float)Math.Sqrt(ret.X * ret.X + ret.Z * ret.Z + ret.Y * ret.Y);
|
---|
601 | if (len != 0)
|
---|
602 | return (ret / len);
|
---|
603 | return ret;
|
---|
604 | }
|
---|
605 | public float GetLength() {
|
---|
606 | return (float)Math.Sqrt(X * X + Y * Y + Z * Z);
|
---|
607 | }
|
---|
608 | public static ILPoint3Df MaxValue {
|
---|
609 | get { return new ILPoint3Df(float.MaxValue,float.MaxValue,float.MaxValue); }
|
---|
610 | }
|
---|
611 | public static ILPoint3Df MinValue {
|
---|
612 | get { return new ILPoint3Df(float.MinValue,float.MinValue,float.MinValue); }
|
---|
613 | }
|
---|
614 | public static ILPoint3Df Min(ILPoint3Df val1, ILPoint3Df val2) {
|
---|
615 | ILPoint3Df ret = val1;
|
---|
616 | if (val2.X < val1.X) ret.X = val2.X;
|
---|
617 | if (val2.Y < val1.Y) ret.Y = val2.Y;
|
---|
618 | if (val2.Z < val1.Z) ret.Z = val2.Z;
|
---|
619 | return ret;
|
---|
620 | }
|
---|
621 | public static ILPoint3Df Min(ILPoint3Df val1, ILPoint3Df val2, ref bool changed) {
|
---|
622 | ILPoint3Df ret = val1;
|
---|
623 | if (val2.X < val1.X) {
|
---|
624 | ret.X = val2.X;
|
---|
625 | changed = true;
|
---|
626 | }
|
---|
627 | if (val2.Y < val1.Y) {
|
---|
628 | ret.Y = val2.Y;
|
---|
629 | changed = true;
|
---|
630 | }
|
---|
631 | if (val2.Z < val1.Z) {
|
---|
632 | ret.Z = val2.Z;
|
---|
633 | changed = true;
|
---|
634 | }
|
---|
635 | return ret;
|
---|
636 | }
|
---|
637 | public static ILPoint3Df Max(ILPoint3Df val1, ILPoint3Df val2) {
|
---|
638 | ILPoint3Df ret = val1;
|
---|
639 | if (val2.X > val1.X) ret.X = val2.X;
|
---|
640 | if (val2.Y > val1.Y) ret.Y = val2.Y;
|
---|
641 | if (val2.Z > val1.Z) ret.Z = val2.Z;
|
---|
642 | return ret;
|
---|
643 | }
|
---|
644 | public static ILPoint3Df Max(ILPoint3Df val1, ILPoint3Df val2, ref bool changed) {
|
---|
645 | ILPoint3Df ret = val1;
|
---|
646 | if (val2.X > val1.X) {
|
---|
647 | ret.X = val2.X;
|
---|
648 | changed = true;
|
---|
649 | }
|
---|
650 | if (val2.Y > val1.Y) {
|
---|
651 | ret.Y = val2.Y;
|
---|
652 | changed = true;
|
---|
653 | }
|
---|
654 | if (val2.Z > val1.Z) {
|
---|
655 | ret.Z = val2.Z;
|
---|
656 | changed = true;
|
---|
657 | }
|
---|
658 | return ret;
|
---|
659 | }
|
---|
660 |
|
---|
661 |
|
---|
662 | public static ILPoint3Df normalize(ILPoint3Df p) {
|
---|
663 | float length = (float)Math.Sqrt(p.X * p.X + p.Y * p.Y + p.Z * p.Z);
|
---|
664 | return p / length;
|
---|
665 | }
|
---|
666 |
|
---|
667 | public static ILPoint3Df normalize(float x, float y, float z) {
|
---|
668 | float length = (float)Math.Sqrt(x * x + y * y + z * z);
|
---|
669 | return new ILPoint3Df(x,y,z) / length;
|
---|
670 | }
|
---|
671 |
|
---|
672 | public void ToPolar(out float len, out float phi, out float rho) {
|
---|
673 | len = (float)Math.Sqrt(X * X + Y * Y + Z * Z);
|
---|
674 | phi = (float)Math.Atan2(Y, X);
|
---|
675 | rho = (float)Math.Atan2(Math.Sqrt(X * X + Y * Y), Z);
|
---|
676 | }
|
---|
677 |
|
---|
678 | /// <summary>
|
---|
679 | /// rotate the vector, keep length
|
---|
680 | /// </summary>
|
---|
681 | /// <param name="normal">axis as rotation normal</param>
|
---|
682 | /// <param name="angleDeg">angle to move (radian)</param>
|
---|
683 | /// <returns>rotated version of this vector, does not change original vector</returns>
|
---|
684 | public ILPoint3Df Spin(ILPoint3Df normal, float angleDeg) {
|
---|
685 | float a = angleDeg * (float)Math.PI / 180f;
|
---|
686 | float cosa = (float)Math.Cos(a);
|
---|
687 | float sina = (float)Math.Sin(a);
|
---|
688 | normal = ILPoint3Df.normalize(normal);
|
---|
689 | float omincosa = 1 - cosa;
|
---|
690 | ILPoint3Df ret = new ILPoint3Df(
|
---|
691 | (cosa + X * X * omincosa) * normal.X
|
---|
692 | + (X * Y * omincosa - Z * sina) * normal.Y
|
---|
693 | + (X * Z * omincosa + Y * sina) * normal.Z,
|
---|
694 |
|
---|
695 | (Y * X * omincosa + Z * sina) * normal.X
|
---|
696 | + (cosa + Y * Y * omincosa) * normal.Y
|
---|
697 | + (Y * Z * omincosa - X * sina) * normal.Z,
|
---|
698 |
|
---|
699 | (Z * X * omincosa - Y * sina) * normal.X
|
---|
700 | + (Z * Y * omincosa + X * sina) * normal.Y
|
---|
701 | + (cosa + Z * Z * omincosa) * normal.Z);
|
---|
702 | return ret;
|
---|
703 | }
|
---|
704 | /// <summary>
|
---|
705 | /// Compares obj's coordinate values to those of this class instance
|
---|
706 | /// </summary>
|
---|
707 | /// <param name="obj">ILPoint3Df to compare</param>
|
---|
708 | /// <returns>true, if X,Y and Z coordinates are equal</returns>
|
---|
709 | public override bool Equals(object obj) {
|
---|
710 | return ((ILPoint3Df)obj) == this;
|
---|
711 | }
|
---|
712 | /// <summary>
|
---|
713 | /// get a hash code for this ILPoint3Df object
|
---|
714 | /// </summary>
|
---|
715 | /// <returns>hash code</returns>
|
---|
716 | public override int GetHashCode() {
|
---|
717 | return base.GetHashCode();
|
---|
718 | }
|
---|
719 | }
|
---|
720 | /// <summary>
|
---|
721 | /// double precision 3D point definition
|
---|
722 | /// </summary>
|
---|
723 | [StructLayout(LayoutKind.Sequential)]
|
---|
724 | public struct ILPoint3Dd {
|
---|
725 | /// <summary>
|
---|
726 | /// X coord
|
---|
727 | /// </summary>
|
---|
728 | public double X;
|
---|
729 | /// <summary>
|
---|
730 | /// Y coord
|
---|
731 | /// </summary>
|
---|
732 | public double Y;
|
---|
733 | /// <summary>
|
---|
734 | /// Z coord
|
---|
735 | /// </summary>
|
---|
736 | public double Z;
|
---|
737 | }
|
---|
738 | /// <summary>
|
---|
739 | /// supported graphics devices
|
---|
740 | /// </summary>
|
---|
741 | public enum GraphicDeviceType {
|
---|
742 | /// <summary>
|
---|
743 | /// DirectX based
|
---|
744 | /// </summary>
|
---|
745 | Direct3D,
|
---|
746 | /// <summary>
|
---|
747 | /// OpenGL based (not supported yet)
|
---|
748 | /// </summary>
|
---|
749 | OpenGL,
|
---|
750 | /// <summary>
|
---|
751 | /// Windows native graphics device (not implemented)
|
---|
752 | /// </summary>
|
---|
753 | GDI,
|
---|
754 | /// <summary>
|
---|
755 | /// unknown graphics device (not used, errror)
|
---|
756 | /// </summary>
|
---|
757 | Unknown
|
---|
758 | }
|
---|
759 | /// <summary>
|
---|
760 | /// valid types for plotting graphs
|
---|
761 | /// </summary>
|
---|
762 | public enum GraphType {
|
---|
763 | Axis,
|
---|
764 | Plot2D,
|
---|
765 | Plot3D,
|
---|
766 | Surf,
|
---|
767 | Mesh,
|
---|
768 | Waterfall,
|
---|
769 | Ribbon,
|
---|
770 | Image,
|
---|
771 | Imagesc,
|
---|
772 | PColor,
|
---|
773 | Contour,
|
---|
774 | CountourFilled,
|
---|
775 | ContourSlice,
|
---|
776 | Scatter,
|
---|
777 | Scatter3,
|
---|
778 | SceneGraph,
|
---|
779 | Errorbar,
|
---|
780 | Stem,
|
---|
781 | Stairs,
|
---|
782 | Stem3,
|
---|
783 | Bar,
|
---|
784 | BarHorizontal,
|
---|
785 | Auto
|
---|
786 | }
|
---|
787 | /// <summary>
|
---|
788 | /// Coordinate systems for TextRenderer
|
---|
789 | /// </summary>
|
---|
790 | public enum CoordSystem {
|
---|
791 | /// <summary>
|
---|
792 | /// the location is expected to be specified into screen coords
|
---|
793 | /// </summary>
|
---|
794 | Screen,
|
---|
795 | /// <summary>
|
---|
796 | /// the location is expected to be specified into world (3D) coords
|
---|
797 | /// </summary>
|
---|
798 | World3D
|
---|
799 | }
|
---|
800 | /// <summary>
|
---|
801 | /// possible types of renderable items
|
---|
802 | /// </summary>
|
---|
803 | public enum RenderItemType {
|
---|
804 | /// <summary>
|
---|
805 | /// the item defines a character
|
---|
806 | /// </summary>
|
---|
807 | Character,
|
---|
808 | /// <summary>
|
---|
809 | /// the item defines a bitmap
|
---|
810 | /// </summary>
|
---|
811 | Bitmap
|
---|
812 | }
|
---|
813 | /// <summary>
|
---|
814 | /// possible reason for an ILGraphCollectionChangedEvent to occur
|
---|
815 | /// </summary>
|
---|
816 | public enum GraphCollectionChangeReason {
|
---|
817 | Added,
|
---|
818 | Deleted,
|
---|
819 | Changed
|
---|
820 | }
|
---|
821 | public class ILLayoutData {
|
---|
822 | public ILLayoutData(ILCamera camera) {
|
---|
823 | CameraPosition = camera;
|
---|
824 | }
|
---|
825 | public ILCamera CameraPosition;
|
---|
826 | public ILLayoutData() {
|
---|
827 | }
|
---|
828 | }
|
---|
829 | }
|
---|
830 |
|
---|
831 | namespace ILNumerics.Drawing.Labeling {
|
---|
832 | /// <summary>
|
---|
833 | /// simple single labeled tick
|
---|
834 | /// </summary>
|
---|
835 | public struct LabeledTick {
|
---|
836 | /// <summary>
|
---|
837 | /// tick label
|
---|
838 | /// </summary>
|
---|
839 | public readonly ILRenderQueue Queue;
|
---|
840 | /// <summary>
|
---|
841 | /// tick position
|
---|
842 | /// </summary>
|
---|
843 | public readonly float Position;
|
---|
844 | /// <summary>
|
---|
845 | /// create single labeled tick
|
---|
846 | /// </summary>
|
---|
847 | /// <param name="position">position</param>
|
---|
848 | /// <param name="queue">render queue used to render the item</param>
|
---|
849 | public LabeledTick(float position, ILRenderQueue queue) {
|
---|
850 | Position = position;
|
---|
851 | Queue = queue;
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 |
|
---|
856 | }
|
---|
857 |
|
---|