///
/// 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.Collections.Generic;
using System.Drawing;
using ILNumerics.Drawing.Interfaces;
using ILNumerics.Drawing.Misc;
using ILNumerics.Exceptions;
namespace ILNumerics.Drawing.Plots {
///
/// Simple 3D Bar Graph - plot
///
public sealed class ILBarGraph3D : ILPlot, IILPanelConfigurator {
#region attributes
ILLitBox3D[,] m_boxes;
float m_barLengthX = 1.0f;
float m_barLengthY = 1.0f;
float m_paddingX = 0.3f;
float m_paddingY = 0.4f;
Color m_barColor = Color.FromArgb(170, 210, 210, 255);
Color m_barColorGradient = Color.FromArgb(170, 180, 180, 255);
#endregion
///
/// create a new 3D Bar Graph plot, provide data matrix
///
/// panel hosting the scene
/// data matrix, at least 2x2 entries
public ILBarGraph3D(ILPanel panel, ILInArray data)
: base(panel) {
using (ILScope.Enter(data)) {
if (data == null)
throw new ILArgumentException("data argument must not be null!");
create(data, Colormaps.ILNumerics);
}
}
///
/// get/set opacity of the bars
///
public byte Opacity {
set {
foreach (ILLitBox3D box in m_boxes) {
box.Opacity = value;
}
}
}
///
/// individual access to each bar (ILLitBox)
///
/// row index, 0 based
/// column index, 0 based
/// lit box shape at specified position
public ILLitBox3D this[int row, int col] {
get {
return m_boxes[row,col];
}
}
#region public interface
///
/// set axes labels and tick labels at once
///
/// panel hosting the plot
/// label text for x axis
/// label text for y axis
/// label text for z axis
/// collection of strings for columns labels (x-direction)
/// collection of strings for row labels (x-direction)
public void SetLabels(ILPanel panel
, string xlabel, string ylabel, string zlabel
, ICollection xtickLabels
, ICollection ytickLabels
) {
panel.Axes[0].LabeledTicks.Clear();
int counter = 0;
if (xtickLabels != null)
foreach (string s in xtickLabels) {
panel.Axes[0].LabeledTicks.Add(m_boxes[0, counter].Center.X, s);
counter++;
}
panel.Axes[1].LabeledTicks.Clear();
counter = 0;
if (ytickLabels != null)
foreach (string s in ytickLabels) {
panel.Axes[1].LabeledTicks.Add(m_boxes[counter, 0].Center.Y, s);
counter++;
}
panel.Axes[0].Label.Text = xlabel;
panel.Axes[1].Label.Text = ylabel;
panel.Axes[2].Label.Text = zlabel;
}
#endregion
#region private helper
private void create(ILInArray data, Colormaps colormap) {
using (ILScope.Enter(data)) {
ILArray dataF = ILMath.check(data);
m_boxes = new ILLitBox3D[data.Size[0], data.Size[1]];
float maxY = data.Size[0] * (m_barLengthY + m_paddingY);
// prepare coloring for top quads
ILColormap cmap = new ILColormap(colormap);
float minV, maxV, mult;
dataF.GetLimits(out minV, out maxV);
if (maxV > minV) {
mult = (cmap.Length - 1) / (maxV - minV);
} else {
minV = 0;
mult = 0;
}
for (int r = 0; r < data.Size[0]; r++) {
for (int c = 0; c < data.Size[1]; c++) {
float val = dataF.GetValue(r, c);
ILPoint3Df max = new ILPoint3Df(
(float)(c * (m_paddingX + m_barLengthX) + m_barLengthX)
, (float)(maxY - r * (m_paddingY + m_barLengthY))
, val);
ILPoint3Df min = new ILPoint3Df(
max.X - m_barLengthX
, max.Y - m_barLengthY
, 0);
Color topColor = cmap.Map((double)(val - minV) * mult);
ILLitBox3D box = new ILLitBox3D(m_panel, min, max, m_barColor, topColor);
box.GradientColor = m_barColorGradient;
box.TopLabel.Color = topColor;
box.TopLabel.Text = "";
m_boxes[r, c] = box;
Add(box);
}
}
}
}
#endregion
#region IILPanelConfigurator Members
///
/// configure default view of panel, called when adding the plot to the panel
///
/// panel hosting the plot
public void ConfigurePanel(ILPanel panel) {
panel.BackgroundFilled = false;
panel.ClipViewData = false;
panel.Axes.LinesVisible = false;
panel.Projection = Projection.Perspective;
panel.DefaultView.SetDeg(-35, 55, 250);
// configure light
panel.Lights[0].Enabled = true;
panel.Lights[0].Position = new ILPoint3Df(0, 0, 250);
panel.BackgroundFilled = false;
panel.BackColor = Color.White;
panel.Axes.GridVisible = false;
panel.Axes.LinesVisible = false;
// configure X axis
panel.Axes[0].LabeledTicks.Mode = TickMode.Manual;
panel.Axes[0].LabeledTicks.Color = Color.Black;
panel.Axes[0].LabeledTicks.Clear();
panel.Axes[1].NearLines.Visible = false;
panel.Axes[1].FarLines.Visible = false;
panel.Axes[1].Label.Color = Color.Black;
panel.Axes[2].NearLines.Visible = false;
panel.Axes[2].FarLines.Visible = false;
panel.Axes[2].Grid.Visible = true;
panel.Axes[2].Grid.Color = Color.DarkGray;
panel.Axes[2].Grid.Antialiasing = true;
panel.Axes[2].Label.Color = Color.Black;
panel.Axes[2].LabeledTicks.Color = Color.Black;
panel.Axes[0].NearLines.Visible = false;
panel.Axes[0].FarLines.Visible = false;
panel.Axes[0].Label.Color = Color.Black;
// configure Y axis
panel.Axes[1].LabeledTicks.Mode = TickMode.Manual;
panel.Axes[1].LabeledTicks.Color = Color.Black;
}
#endregion
}
}