///
/// This file is part of ILNumerics Community Edition.
///
/// ILNumerics Community Edition - high performance computing for applications.
/// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
///
/// ILNumerics Community Edition is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License version 3 as published by
/// the Free Software Foundation.
///
/// ILNumerics Community Edition is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with ILNumerics Community Edition. See the file License.txt in the root
/// of your distribution package. If not, see .
///
/// In addition this software uses the following components and/or licenses:
///
/// =================================================================================
/// The Open Toolkit Library License
///
/// Copyright (c) 2006 - 2009 the Open Toolkit library.
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights to
/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
/// the Software, and to permit persons to whom the Software is furnished to do
/// so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// =================================================================================
///
#pragma warning disable 1591
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
using ILNumerics.Drawing.Graphs;
namespace ILNumerics.Drawing {
///
/// Options for adapting ILPanel view limits
///
public enum AutoZoomOptions {
///
/// never adapt automatically, the view limits are handled by the user
///
Never,
///
/// Only adapt view limits once at startup, later changes of the data limits will not affect the view limits
///
OnStartup,
///
/// View limits will automatically adapt changes of data limits. (Default)
///
OnDataChanges
}
///
/// modes for projecting the rendering output to the available client area
///
public enum AspectRatioMode {
///
/// plots fill available rendering area of the PlotCubeScreenRectF rectangle
///
StretchToFill,
///
/// plots will be shrinked to fit inside PlotCubeScreeRectF but maintain data aspect ratio
///
MaintainRatios
}
///
/// defines the movement from current to new zoom setting
///
public enum ZoomModes {
///
/// No ramp, jump to new zoom setting
///
Jump,
///
/// morph softly to new zoom setting
///
RollSoft,
///
/// morph faster to new setting
///
RollHard,
///
/// morph to new setting by 'going over the limit'
///
RollOverride
}
///
/// predefined colormaps
///
public enum Colormaps {
Autumn,
Bone,
//Colorcube,
Cool,
Copper,
Flag,
Gray,
Hot,
Hsv,
ILNumerics,
Jet,
Lines,
Pink,
Prism,
Spring,
Summer,
White,
Winter
}
///
/// Orientation for labels and other purposes
///
public enum TextOrientation {
Horizontal,
Vertical
}
///
/// Alignment for
///
public enum VerticalAlignment {
Lower,
Middle,
Upper
}
///
/// Suggest, how label positions for axis ticks are to be choosen
///
public enum TickLabelRenderingHint {
///
/// tick labels will optimally fill the whole axis length
///
Filled,
///
/// multiples of 10^n will be prefered for label steps
///
Multiple1,
///
/// multiples of 2*10^n will be prefered for label steps
///
Multiple2,
///
/// multiples of 5*10^n will be prefered for label steps
///
Multiple5,
///
/// Try to find the optimal division for tick label steps [default]
///
/// This method is the most computational intensive one.
Auto
}
///
/// Names for all 3 axes
///
public enum AxisNames {
XAxis = 0,
YAxis = 1,
ZAxis = 2
}
///
/// simple single unlabled tick
///
public struct UnlabeledTick {
///
/// Position of tick
///
public float Position;
}
///
/// Axis ticks spacing type: linear, logarithmic
///
public enum AxisType {
///
/// linear axis tick spacing
///
Linear,
///
/// logarithmic axis tick spacing
///
Logarithmic
}
///
/// On which sides ticks will be displayed
///
public enum TickDisplay {
///
/// ticks for axis will be displayed on label side only
///
LabelSide,
///
/// ticks for axis will be displayed on label - and the opposite site
///
BothSides
}
///
/// how ticks are displayed (inside/outside)
///
public enum TickDirection {
///
/// Ticks will lay inside the rendering cube
///
Inside,
///
/// Ticks will lay outside the rendering cube
///
Outside
}
///
/// orientation for axis labels (not implemented)
///
public enum ILAxisLabelOrientation {
Normal,
Rotate90,
Rotate180,
Rotate270,
Arbitrary
}
///
/// TickModes - automatic or manual axis tick positioning
///
public enum TickMode {
///
/// find tick positions automatically
///
Auto,
///
/// manually create ticks
///
Manual
}
///
/// options for the sizing of the projection of the plot cube onto the 2D screen client area of the control
///
public enum PlotBoxScreenSizeMode {
///
/// the projection of the plot cube drawing area fills the whole controls space (labels may be hidden)
///
Maximum,
///
/// the size of plot cube projection rectangle is automatically determined, taking labels size into account
///
Optimal,
///
/// more pixel exact positioning, strictly only the place really needed for labels is used (slower)
///
StrictOptimal,
///
/// No automatic resizing for the cube projection size, values from PlotCubeScreenRect are taken
///
Manual
}
///
/// possible states/reasons/sources for rendering the scene
///
internal enum RenderReason {
///
/// normal source, the scene is to be rendered the common way
///
PaintEvent,
///
/// the rendering was re-initialized because the matrices need to be recalculated for laying out labels correctly
///
RecalcLabels
}
///
/// Alignments for labels
///
public enum LabelAlign {
///
/// align the label near the lower range limit
///
Lower,
///
/// align the label in the center
///
Center,
///
/// align the label near the upper range limit
///
Upper
}
///
/// Possible alignments for tick labels
///
/// member of this enum can get bitwise combined. Default is: Top,Left
[FlagsAttribute]
public enum TickLabelAlign {
///
/// align the label to the left side
///
left = 0,
///
/// align the labels to the center
///
center = 1,
///
/// align the label to the right side
///
right = 2,
///
/// align the label to top
///
top = 0,
///
/// align the label to center vertically
///
vertCenter = 4,
///
/// align the label to bottom
///
bottom = 16
}
///
/// projection types
///
public enum Projection {
///
/// 3D graphs will be distorted for opotimized 3D impression
///
Perspective,
///
/// graphs will not be distorted. objects in the front will get the same size as objects in the back
///
Orthographic
}
///
/// valid marker styles (partially supported)
///
public enum MarkerStyle {
///
/// draw markers as dots
///
Dot,
///
/// draw markers as circle
///
Circle,
///
/// draw markers as diamonds
///
Diamond,
///
/// draw markers as square
///
Square,
///
/// draw markers as up pointing triangles
///
TriangleUp,
///
/// draw markers as up pointing triangles
///
TriangleDown,
///
/// draw markers as up pointing triangles
///
TriangleLeft,
///
/// draw markers as up pointing triangles
///
TriangleRight,
///
/// draw markers as plus
///
Plus,
///
/// draw markers as cross
///
Cross,
///
/// do not draw markers
///
None,
}
///
/// Possible positions of the camera
///
public enum CameraQuadrant {
TopLeftFront,
TopLeftBack,
TopRightBack,
TopRightFront,
BottomLeftFront,
BottomLeftBack,
BottomRightBack,
BottomRightFront
}
///
/// Shading styles for surface graphs
///
public enum ShadingStyles {
///
/// color will be interpolated between all corners
///
Interpolate,
///
/// same color for whole tile area
///
/// The resulting color will
/// reflect the average over all corner values for a rectangle
Flat
}
///
/// line style
///
public enum LineStyle {
///
/// solid line
///
Solid = Int32.MaxValue,
///
/// dashed line
///
Dashed = Int16.MaxValue,
///
/// point dashed line
///
PointDash = unchecked((int)4294837760),
///
/// dotted line
///
Dotted = unchecked((int)3435973836),
///
/// use user stipple pattern
///
UserPattern = -1,
///
/// no line at all
///
None = 0
}
///
/// modes of mouse interaction with ILPanel
///
public enum InteractiveModes {
ZoomRectangle,
Rotating,
Selecting,
Translating,
None
}
///
/// single precision 3D point structure
///
[StructLayout(LayoutKind.Sequential)]
public struct ILPoint3Df {
///
/// X coordinate
///
public float X;
///
/// Y coordinate
///
public float Y;
///
/// Z coordinate
///
public float Z;
///
/// create point in single precision
///
/// X coord
/// Y coord
/// Z coord
public ILPoint3Df (float x, float y, float z) {
X = x;
Y = y;
Z = z;
}
///
/// create new ILPoint3Df by double values (for convenience, internally casted to float)
///
/// X coord
/// Y coord
/// Z coors
public ILPoint3Df (double x, double y, double z) {
X = (float)x;
Y = (float)y;
Z = (float)z;
}
///
/// convert this point to string representation
///
///
public override string ToString() {
return "X:" + X.ToString() + " Y:" + Y.ToString() + " Z:" + Z.ToString();
}
///
/// Access to coords by index
///
/// index number: 0=x, 1=y, 2=z
/// float value of coord specified
public float this[int index] {
get {
switch (index) {
case 0:
return X;
case 1:
return Y;
default:
return Z;
}
}
}
public static bool operator == (ILPoint3Df p1, ILPoint3Df p2) {
return (p1.X == p2.X &&
p1.Y == p2.Y &&
p1.Z == p2.Z);
}
public static bool operator != (ILPoint3Df p1, ILPoint3Df p2) {
return (p1.X != p2.X ||
p1.Y != p2.Y ||
p1.Z != p2.Z);
}
public static ILPoint3Df operator + (ILPoint3Df p1, ILPoint3Df p2) {
ILPoint3Df ret = new ILPoint3Df();
ret.X = p1.X + p2.X;
ret.Y = p1.Y + p2.Y;
ret.Z = p1.Z + p2.Z;
return ret;
}
public static ILPoint3Df operator - (ILPoint3Df p1, ILPoint3Df p2) {
ILPoint3Df ret = new ILPoint3Df();
ret.X = p1.X - p2.X;
ret.Y = p1.Y - p2.Y;
ret.Z = p1.Z - p2.Z;
return ret;
}
public static ILPoint3Df operator * (ILPoint3Df p1, float factor) {
ILPoint3Df ret = new ILPoint3Df();
ret.X = p1.X * factor;
ret.Y = p1.Y * factor;
ret.Z = p1.Z * factor;
return ret;
}
public static ILPoint3Df operator *(OpenTK.Math.Matrix4 mat, ILPoint3Df vec) {
return new ILPoint3Df(
mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z + mat.Row0.W,
mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z + mat.Row1.W,
mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z + mat.Row2.W);
}
public static ILPoint3Df operator / (ILPoint3Df p1, float factor) {
ILPoint3Df ret = new ILPoint3Df();
ret.X = p1.X / factor;
ret.Y = p1.Y / factor;
ret.Z = p1.Z / factor;
return ret;
}
public static readonly ILPoint3Df Empty = new ILPoint3Df(float.NaN,float.NaN,float.NaN);
public bool IsEmtpy () {
return float.IsNaN(X) || float.IsNaN(Y) || float.IsNaN(Z);
}
///
/// cross product
///
/// vector 1
/// vector 2
/// normalized cross product between a x b
public static ILPoint3Df cross(ILPoint3Df a, ILPoint3Df b) {
return new ILPoint3Df(
a.Y * b.Z - a.Z * b.Y,
a.Z * b.X - a.X * b.Z,
a.X * b.Y - a.Y * b.X);
}
///
/// normalized cross product
///
/// vector 1
/// vector 2
/// normalized cross product: a x b
public static ILPoint3Df crossN(ILPoint3Df a, ILPoint3Df b) {
ILPoint3Df ret = new ILPoint3Df(
a.Y * b.Z - a.Z * b.Y,
a.Z * b.X - a.X * b.Z,
a.X * b.Y - a.Y * b.X);
float len = (float)Math.Sqrt(ret.X * ret.X + ret.Z * ret.Z + ret.Y * ret.Y);
if (len != 0)
return (ret / len);
return ret;
}
public float GetLength() {
return (float)Math.Sqrt(X * X + Y * Y + Z * Z);
}
public static ILPoint3Df MaxValue {
get { return new ILPoint3Df(float.MaxValue,float.MaxValue,float.MaxValue); }
}
public static ILPoint3Df MinValue {
get { return new ILPoint3Df(float.MinValue,float.MinValue,float.MinValue); }
}
public static ILPoint3Df Min(ILPoint3Df val1, ILPoint3Df val2) {
ILPoint3Df ret = val1;
if (val2.X < val1.X) ret.X = val2.X;
if (val2.Y < val1.Y) ret.Y = val2.Y;
if (val2.Z < val1.Z) ret.Z = val2.Z;
return ret;
}
public static ILPoint3Df Min(ILPoint3Df val1, ILPoint3Df val2, ref bool changed) {
ILPoint3Df ret = val1;
if (val2.X < val1.X) {
ret.X = val2.X;
changed = true;
}
if (val2.Y < val1.Y) {
ret.Y = val2.Y;
changed = true;
}
if (val2.Z < val1.Z) {
ret.Z = val2.Z;
changed = true;
}
return ret;
}
public static ILPoint3Df Max(ILPoint3Df val1, ILPoint3Df val2) {
ILPoint3Df ret = val1;
if (val2.X > val1.X) ret.X = val2.X;
if (val2.Y > val1.Y) ret.Y = val2.Y;
if (val2.Z > val1.Z) ret.Z = val2.Z;
return ret;
}
public static ILPoint3Df Max(ILPoint3Df val1, ILPoint3Df val2, ref bool changed) {
ILPoint3Df ret = val1;
if (val2.X > val1.X) {
ret.X = val2.X;
changed = true;
}
if (val2.Y > val1.Y) {
ret.Y = val2.Y;
changed = true;
}
if (val2.Z > val1.Z) {
ret.Z = val2.Z;
changed = true;
}
return ret;
}
public static ILPoint3Df normalize(ILPoint3Df p) {
float length = (float)Math.Sqrt(p.X * p.X + p.Y * p.Y + p.Z * p.Z);
return p / length;
}
public static ILPoint3Df normalize(float x, float y, float z) {
float length = (float)Math.Sqrt(x * x + y * y + z * z);
return new ILPoint3Df(x,y,z) / length;
}
public void ToPolar(out float len, out float phi, out float rho) {
len = (float)Math.Sqrt(X * X + Y * Y + Z * Z);
phi = (float)Math.Atan2(Y, X);
rho = (float)Math.Atan2(Math.Sqrt(X * X + Y * Y), Z);
}
///
/// rotate the vector, keep length
///
/// axis as rotation normal
/// angle to move (radian)
/// rotated version of this vector, does not change original vector
public ILPoint3Df Spin(ILPoint3Df normal, float angleDeg) {
float a = angleDeg * (float)Math.PI / 180f;
float cosa = (float)Math.Cos(a);
float sina = (float)Math.Sin(a);
normal = ILPoint3Df.normalize(normal);
float omincosa = 1 - cosa;
ILPoint3Df ret = new ILPoint3Df(
(cosa + X * X * omincosa) * normal.X
+ (X * Y * omincosa - Z * sina) * normal.Y
+ (X * Z * omincosa + Y * sina) * normal.Z,
(Y * X * omincosa + Z * sina) * normal.X
+ (cosa + Y * Y * omincosa) * normal.Y
+ (Y * Z * omincosa - X * sina) * normal.Z,
(Z * X * omincosa - Y * sina) * normal.X
+ (Z * Y * omincosa + X * sina) * normal.Y
+ (cosa + Z * Z * omincosa) * normal.Z);
return ret;
}
///
/// Compares obj's coordinate values to those of this class instance
///
/// ILPoint3Df to compare
/// true, if X,Y and Z coordinates are equal
public override bool Equals(object obj) {
return ((ILPoint3Df)obj) == this;
}
///
/// get a hash code for this ILPoint3Df object
///
/// hash code
public override int GetHashCode() {
return base.GetHashCode();
}
}
///
/// double precision 3D point definition
///
[StructLayout(LayoutKind.Sequential)]
public struct ILPoint3Dd {
///
/// X coord
///
public double X;
///
/// Y coord
///
public double Y;
///
/// Z coord
///
public double Z;
}
///
/// supported graphics devices
///
public enum GraphicDeviceType {
///
/// DirectX based
///
Direct3D,
///
/// OpenGL based (not supported yet)
///
OpenGL,
///
/// Windows native graphics device (not implemented)
///
GDI,
///
/// unknown graphics device (not used, errror)
///
Unknown
}
///
/// valid types for plotting graphs
///
public enum GraphType {
Axis,
Plot2D,
Plot3D,
Surf,
Mesh,
Waterfall,
Ribbon,
Image,
Imagesc,
PColor,
Contour,
CountourFilled,
ContourSlice,
Scatter,
Scatter3,
SceneGraph,
Errorbar,
Stem,
Stairs,
Stem3,
Bar,
BarHorizontal,
Auto
}
///
/// Coordinate systems for TextRenderer
///
public enum CoordSystem {
///
/// the location is expected to be specified into screen coords
///
Screen,
///
/// the location is expected to be specified into world (3D) coords
///
World3D
}
///
/// possible types of renderable items
///
public enum RenderItemType {
///
/// the item defines a character
///
Character,
///
/// the item defines a bitmap
///
Bitmap
}
///
/// possible reason for an ILGraphCollectionChangedEvent to occur
///
public enum GraphCollectionChangeReason {
Added,
Deleted,
Changed
}
public class ILLayoutData {
public ILLayoutData(ILCamera camera) {
CameraPosition = camera;
}
public ILCamera CameraPosition;
public ILLayoutData() {
}
}
}
namespace ILNumerics.Drawing.Labeling {
///
/// simple single labeled tick
///
public struct LabeledTick {
///
/// tick label
///
public readonly ILRenderQueue Queue;
///
/// tick position
///
public readonly float Position;
///
/// create single labeled tick
///
/// position
/// render queue used to render the item
public LabeledTick(float position, ILRenderQueue queue) {
Position = position;
Queue = queue;
}
}
}