///
/// 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.
///
/// =================================================================================
///
using System;
using System.Collections.Generic;
using System.Text;
using ILNumerics;
using ILNumerics.Drawing;
using ILNumerics.Drawing.Graphs;
using ILNumerics.Drawing.Shapes;
using ILNumerics.Drawing.Labeling;
using System.Drawing;
namespace ILNumerics.Drawing.Plots {
///
/// the plot displays a simple colored lit 3D box
///
public class ILLitBox3D : ILPlot {
#region public enums
///
/// enum for all
///
public static class QuadIndices {
public static readonly int front = 0;
public static readonly int right = 1;
public static readonly int back = 2;
public static readonly int left = 3;
public static readonly int top = 4;
public static readonly int bottom = 5;
}
#endregion
#region attributes
ILLitQuad[] m_quads;
ILLineProperties m_lineProperties;
Color m_gradColor;
Color m_fillColor;
Color m_topColor;
byte m_opacity = 255;
ILWorldLabel m_valLabel;
ILShapeLabel m_topLabel;
#endregion
#region properties
///
/// get the opacity for the box or set it
///
public byte Opacity {
get { return m_opacity; }
set {
foreach (ILLitQuad s in m_quads) {
s.Opacity = value;
for (int i = 0; i < s.Vertices.Length; i++) {
s.Vertices[i].Alpha = value;
}
}
m_opacity = value; }
}
///
/// the color used at one corner for each quad to generate a simple gradient effect
///
public Color GradientColor {
get { return m_gradColor; }
set {
m_gradColor = value;
updateColors();
}
}
///
/// properties of the edge lines
///
public ILLineProperties Edges {
get {
return m_lineProperties;
}
}
///
/// overall fill color (bottom and lower area of color gradient)
///
public Color FillColor {
get { return m_fillColor; }
set {
m_fillColor = value;
updateColors();
}
}
///
/// top color (top and upper area of color gradient)
///
public Color TopColor {
get { return m_topColor; }
set {
m_topColor = value;
updateColors();
}
}
///
/// reference to the label which renders the current z-value onto the top area (world coords)
///
public ILWorldLabel ValueLabel {
get {
return m_valLabel;
}
}
///
/// label drawn in screen coords on top of the lit box
///
public ILShapeLabel TopLabel {
get { return m_topLabel; }
}
///
/// get reference to the quads, the lit box is assembled out of
///
public ILLitQuad[] Quads {
get { return m_quads; }
}
#endregion
#region constructor
///
/// create new lit 3D box
///
/// panel hosting the scene
/// minimum coordinates defining the box' dimensions (x,y,z)
/// minimum coordinates defining the box' dimensions (x,y,z)
/// overall color for the box
/// color used to color the top edges of the box
public ILLitBox3D(ILPanel panel, ILPoint3Df min, ILPoint3Df max, Color fillColor, Color topColor)
: base(panel) {
m_lineProperties = new ILLineProperties();
m_lineProperties.Changed += new EventHandler(m_lineProperties_Changed);
m_valLabel = new ILWorldLabel(panel);
m_valLabel.Text = ""; // (max * 1000).Z.ToString("F3");
ILPoint3Df mi = ILPoint3Df.Min(min, max);
ILPoint3Df ma = ILPoint3Df.Max(min, max);
m_valLabel.PositionMax = new ILPoint3Df(ma.X,mi.Y,ma.Z);
m_valLabel.PositionMin = new ILPoint3Df(mi.X, ma.Y, ma.Z); ;
m_topLabel = new ILShapeLabel(panel);
m_topLabel.Color = Color.Blue;
//m_topLabel.Font = new Font("Arial", 10, FontStyle.Bold);
string tval = max.Z.ToString("F2");
m_topLabel.Text = String.Format("{0}",tval);
m_topLabel.Anchor = new PointF(0.5f, 1);
m_topColor = topColor;
#region setup quads
m_quads = new ILLitQuad[6];
// front
ILLitQuad quad = new ILLitQuad(m_panel);
quad.Vertices[0].Position = new ILPoint3Df(min.X, min.Y, min.Z);
quad.Vertices[1].Position = new ILPoint3Df(min.X, min.Y, max.Z);
quad.Vertices[2].Position = new ILPoint3Df(max.X, min.Y, max.Z);
quad.Vertices[3].Position = new ILPoint3Df(max.X, min.Y, min.Z);
m_quads[QuadIndices.front] = quad;
// right
quad = new ILLitQuad(m_panel);
quad.Vertices[0].Position = new ILPoint3Df(max.X, min.Y, min.Z);
quad.Vertices[1].Position = new ILPoint3Df(max.X, min.Y, max.Z);
quad.Vertices[2].Position = new ILPoint3Df(max.X, max.Y, max.Z);
quad.Vertices[3].Position = new ILPoint3Df(max.X, max.Y, min.Z);
m_quads[QuadIndices.right] = quad;
// back
quad = new ILLitQuad(m_panel);
quad.Vertices[0].Position = new ILPoint3Df(max.X, max.Y, min.Z);
quad.Vertices[1].Position = new ILPoint3Df(max.X, max.Y, max.Z);
quad.Vertices[2].Position = new ILPoint3Df(min.X, max.Y, max.Z);
quad.Vertices[3].Position = new ILPoint3Df(min.X, max.Y, min.Z);
m_quads[QuadIndices.back] = quad;
// left
quad = new ILLitQuad(m_panel);
quad.Vertices[0].Position = new ILPoint3Df(min.X, max.Y, min.Z);
quad.Vertices[1].Position = new ILPoint3Df(min.X, max.Y, max.Z);
quad.Vertices[2].Position = new ILPoint3Df(min.X, min.Y, max.Z);
quad.Vertices[3].Position = new ILPoint3Df(min.X, min.Y, min.Z);
m_quads[QuadIndices.left] = quad;
// top
quad = new ILLitQuad(m_panel);
quad.Vertices[0].Position = new ILPoint3Df(min.X, min.Y, max.Z);
quad.Vertices[1].Position = new ILPoint3Df(max.X, min.Y, max.Z);
quad.Vertices[2].Position = new ILPoint3Df(max.X, max.Y, max.Z);
quad.Vertices[3].Position = new ILPoint3Df(min.X, max.Y, max.Z);
m_quads[QuadIndices.top] = quad;
// bottom
quad = new ILLitQuad(m_panel);
quad.Vertices[0].Position = new ILPoint3Df(min.X, min.Y, min.Z);
quad.Vertices[1].Position = new ILPoint3Df(max.X, min.Y, min.Z);
quad.Vertices[2].Position = new ILPoint3Df(max.X, max.Y, min.Z);
quad.Vertices[3].Position = new ILPoint3Df(min.X, max.Y, min.Z);
m_quads[QuadIndices.bottom] = quad;
#endregion
EventingSuspend();
foreach (ILLitQuad s in m_quads) {
s.Label.Text = "";
s.Shading = ShadingStyles.Interpolate;
s.Opacity = m_opacity;
s.Border.Color = Color.Gray;
s.Border.Width = 1;
s.Border.Visible = true;
s.Border.Antialiasing = false;
Add(s);
}
EventingResume();
m_fillColor = fillColor;
updateColors();
}
#endregion
#region public interface
///
/// (internally used) draws the plot
///
///
internal override void Draw(ILRenderProperties props) {
base.Draw(props);
m_valLabel.Draw(props);
ILPoint3Df labPos = m_quads[QuadIndices.top].Center;
labPos.Z = Math.Max(m_quads[QuadIndices.top].Center.Z,m_quads[QuadIndices.bottom].Center.Z);
m_topLabel.Draw(props,labPos);
}
#endregion
#region private helpers
///
/// update all quad borders with new settings
///
///
///
void m_lineProperties_Changed(object sender, EventArgs e) {
foreach (ILLitQuad quad in m_quads) {
quad.Border.CopyFrom(m_lineProperties);
}
}
///
/// distribute changed color settings to all quads
///
private void updateColors() {
SetColorGradient(m_quads[QuadIndices.front], m_fillColor, m_topColor, m_topColor, m_gradColor);
SetColorGradient(m_quads[QuadIndices.right], m_fillColor, m_topColor, m_topColor, m_gradColor);
SetColorGradient(m_quads[QuadIndices.back], m_fillColor, m_topColor, m_topColor, m_gradColor);
SetColorGradient(m_quads[QuadIndices.left], m_fillColor, m_topColor, m_topColor, m_gradColor);
SetColorGradient(m_quads[QuadIndices.top], m_topColor, m_topColor, m_topColor, m_topColor);
SetColorGradient(m_quads[QuadIndices.bottom], m_topColor, m_topColor, m_topColor, m_topColor);
}
///
/// color settings helper
///
/// quad index
/// color 1
/// color 2
/// color 3
/// color 4
private void SetColorGradient(
ILLitQuad quad, Color col0, Color col1, Color col2, Color col3) {
quad.Vertices[0].Color = col0;
quad.Vertices[0].Alpha = m_opacity;
quad.Vertices[1].Color = col1;
quad.Vertices[1].Alpha = m_opacity;
quad.Vertices[2].Color = col2;
quad.Vertices[2].Alpha = m_opacity;
quad.Vertices[3].Color = col3;
quad.Vertices[3].Alpha = m_opacity;
}
#endregion
}
}