///
/// 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 System.Drawing;
using ILNumerics.Drawing;
using ILNumerics.Drawing.Interfaces;
namespace ILNumerics.Drawing.Graphs {
///
/// Surface graph
///
public abstract class ILSurfaceGraph : ILFilledGraph, IILLegendRenderer, IILPanelConfigurator {
#region attributes
protected ShadingStyles m_shading;
#endregion
#region properties
///
/// determine, how the color for surface tiles will be drawn
///
/// Interpolated will interpolate the color for the
/// tiles between all corner data points. Flat will draw the area of the
/// tile in a single color. The color than reflects the average value of
/// all corner data points.
public ShadingStyles Shading {
get {
return m_shading;
}
set {
m_shading = value;
OnChanged("Shading");
}
}
#endregion
#region constructor
///
/// construct new surface graph, provide all 3 coordinates
///
/// panel this graph is to be hosted in
/// X coordinates
/// Y coordinates
/// Z coordinates
/// Color values
///
public ILSurfaceGraph(ILPanel panel, ILArray X, ILArray Y,
ILArray Z, ILArray C, ILClippingData clippingContainer)
: base(panel, X, Y, Z, C, clippingContainer) {
using (ILScope.Enter(X, Y, Z, C)) {
m_graphType = GraphType.Surf;
m_wireLines.Width = 1;
m_wireLines.Antialiasing = false;
m_wireLines.Color = System.Drawing.Color.Blue;
m_opacity = 0.84f;
}
}
#endregion
#region ILFilledGraph overloads
///
/// create indices for ILSurfaceGraph triangles
///
/// If possible, the indices will assemble triangle strips. If not -
/// the base implementation will be used to create individual triangles.
protected override void CreateIndices() {
if (m_opacity == 1.0f && m_shading == ShadingStyles.Interpolate) {
#region no transparency
// simple case: DepthTest on, we can do fast drawing
// with low number on indices needed (triangle strips)
checkVertexIndicesLength(m_cols * 2,m_rows-1);
int pos1 = 0, pos2 = m_cols, posI = 0;
while (posI < m_indicesCount) {
m_indices[posI++] = (uint)pos2++;
m_indices[posI++] = (uint)pos1++;
}
#endregion
if (m_wireLines.Visible) {
#region looking from front
posI = 0;
System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi > 0 (grid front)");
checkGridIndicesLength((m_cols-1) * 4 + 2,m_rows-1);
pos1 = m_Vertcount-m_cols;
pos2 = m_Vertcount-m_cols;
// first row is special:
for (int c = m_cols-1; c-->0;) {
m_gridIndices[posI++] = (uint)pos1++;
m_gridIndices[posI++] = (uint)pos1;
}
pos1 -= 2*m_cols-1;
for (int r = m_rows-1; r-->0;) {
// first column is special:
m_gridIndices[posI++] = (uint)pos2;
m_gridIndices[posI++] = (uint)pos1;
for (int c = m_cols-1; c-->0;) {
m_gridIndices[posI++] = (uint)pos1++;
m_gridIndices[posI++] = (uint)pos1;
m_gridIndices[posI++] = (uint)++pos2;
m_gridIndices[posI++] = (uint)pos1;
}
pos1 -= (m_cols * 2 - 1);
pos2 -= (m_cols * 2 - 1);
}
#endregion
}
} else {
// create regular individual triangles
base.CreateIndices();
}
}
public override bool Is3DGraph() {
return true;
}
#endregion
#region IILLegendRenderer
public abstract void DrawToLegend(ILRenderProperties p, Rectangle sampleRect, Rectangle labelRect);
public Size LabelSize { get { return m_label.Size; } }
#endregion
#region IILPanelConfigurator
public void ConfigurePanel(ILPanel panel) {
panel.InteractiveMode = InteractiveModes.Rotating;
panel.DefaultView.Set(5.8f, 1.17f, panel.DefaultView.Distance);
}
#endregion
}
}