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 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 | using System.Drawing;
|
---|
44 | using ILNumerics.Drawing;
|
---|
45 | using ILNumerics.Drawing.Interfaces;
|
---|
46 |
|
---|
47 | namespace ILNumerics.Drawing.Graphs {
|
---|
48 | /// <summary>
|
---|
49 | /// Surface graph
|
---|
50 | /// </summary>
|
---|
51 | public abstract class ILSurfaceGraph : ILFilledGraph, IILLegendRenderer, IILPanelConfigurator {
|
---|
52 |
|
---|
53 | #region attributes
|
---|
54 | protected ShadingStyles m_shading;
|
---|
55 | #endregion
|
---|
56 |
|
---|
57 | #region properties
|
---|
58 | /// <summary>
|
---|
59 | /// determine, how the color for surface tiles will be drawn
|
---|
60 | /// </summary>
|
---|
61 | /// <remarks>Interpolated will interpolate the color for the
|
---|
62 | /// tiles between all corner data points. Flat will draw the area of the
|
---|
63 | /// tile in a single color. The color than reflects the average value of
|
---|
64 | /// all corner data points.</remarks>
|
---|
65 | public ShadingStyles Shading {
|
---|
66 | get {
|
---|
67 | return m_shading;
|
---|
68 | }
|
---|
69 | set {
|
---|
70 | m_shading = value;
|
---|
71 | OnChanged("Shading");
|
---|
72 | }
|
---|
73 | }
|
---|
74 | #endregion
|
---|
75 |
|
---|
76 | #region constructor
|
---|
77 | /// <summary>
|
---|
78 | /// construct new surface graph, provide all 3 coordinates
|
---|
79 | /// </summary>
|
---|
80 | /// <param name="panel">panel this graph is to be hosted in</param>
|
---|
81 | /// <param name="X">X coordinates</param>
|
---|
82 | /// <param name="Y">Y coordinates</param>
|
---|
83 | /// <param name="Z">Z coordinates</param>
|
---|
84 | /// <param name="C">Color values</param>
|
---|
85 | /// <param name="clippingContainer"></param>
|
---|
86 | public ILSurfaceGraph(ILPanel panel, ILArray<float> X, ILArray<float> Y,
|
---|
87 | ILArray<float> Z, ILArray<float> C, ILClippingData clippingContainer)
|
---|
88 | : base(panel, X, Y, Z, C, clippingContainer) {
|
---|
89 | using (ILScope.Enter(X, Y, Z, C)) {
|
---|
90 | m_graphType = GraphType.Surf;
|
---|
91 | m_wireLines.Width = 1;
|
---|
92 | m_wireLines.Antialiasing = false;
|
---|
93 | m_wireLines.Color = System.Drawing.Color.Blue;
|
---|
94 | m_opacity = 0.84f;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | #endregion
|
---|
98 |
|
---|
99 | #region ILFilledGraph overloads
|
---|
100 | /// <summary>
|
---|
101 | /// create indices for ILSurfaceGraph triangles
|
---|
102 | /// </summary>
|
---|
103 | /// <remarks>If possible, the indices will assemble triangle strips. If not -
|
---|
104 | /// the base implementation will be used to create individual triangles.</remarks>
|
---|
105 | protected override void CreateIndices() {
|
---|
106 | if (m_opacity == 1.0f && m_shading == ShadingStyles.Interpolate) {
|
---|
107 | #region no transparency
|
---|
108 | // simple case: DepthTest on, we can do fast drawing
|
---|
109 | // with low number on indices needed (triangle strips)
|
---|
110 | checkVertexIndicesLength(m_cols * 2,m_rows-1);
|
---|
111 | int pos1 = 0, pos2 = m_cols, posI = 0;
|
---|
112 | while (posI < m_indicesCount) {
|
---|
113 | m_indices[posI++] = (uint)pos2++;
|
---|
114 | m_indices[posI++] = (uint)pos1++;
|
---|
115 | }
|
---|
116 | #endregion
|
---|
117 | if (m_wireLines.Visible) {
|
---|
118 | #region looking from front
|
---|
119 | posI = 0;
|
---|
120 | System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi > 0 (grid front)");
|
---|
121 | checkGridIndicesLength((m_cols-1) * 4 + 2,m_rows-1);
|
---|
122 | pos1 = m_Vertcount-m_cols;
|
---|
123 | pos2 = m_Vertcount-m_cols;
|
---|
124 | // first row is special:
|
---|
125 | for (int c = m_cols-1; c-->0;) {
|
---|
126 | m_gridIndices[posI++] = (uint)pos1++;
|
---|
127 | m_gridIndices[posI++] = (uint)pos1;
|
---|
128 | }
|
---|
129 | pos1 -= 2*m_cols-1;
|
---|
130 | for (int r = m_rows-1; r-->0;) {
|
---|
131 | // first column is special:
|
---|
132 | m_gridIndices[posI++] = (uint)pos2;
|
---|
133 | m_gridIndices[posI++] = (uint)pos1;
|
---|
134 | for (int c = m_cols-1; c-->0;) {
|
---|
135 | m_gridIndices[posI++] = (uint)pos1++;
|
---|
136 | m_gridIndices[posI++] = (uint)pos1;
|
---|
137 | m_gridIndices[posI++] = (uint)++pos2;
|
---|
138 | m_gridIndices[posI++] = (uint)pos1;
|
---|
139 | }
|
---|
140 | pos1 -= (m_cols * 2 - 1);
|
---|
141 | pos2 -= (m_cols * 2 - 1);
|
---|
142 | }
|
---|
143 | #endregion
|
---|
144 | }
|
---|
145 | } else {
|
---|
146 | // create regular individual triangles
|
---|
147 | base.CreateIndices();
|
---|
148 | }
|
---|
149 | }
|
---|
150 | public override bool Is3DGraph() {
|
---|
151 | return true;
|
---|
152 | }
|
---|
153 |
|
---|
154 | #endregion
|
---|
155 |
|
---|
156 | #region IILLegendRenderer
|
---|
157 | public abstract void DrawToLegend(ILRenderProperties p, Rectangle sampleRect, Rectangle labelRect);
|
---|
158 | public Size LabelSize { get { return m_label.Size; } }
|
---|
159 | #endregion
|
---|
160 |
|
---|
161 | #region IILPanelConfigurator
|
---|
162 | public void ConfigurePanel(ILPanel panel) {
|
---|
163 | panel.InteractiveMode = InteractiveModes.Rotating;
|
---|
164 | panel.DefaultView.Set(5.8f, 1.17f, panel.DefaultView.Distance);
|
---|
165 | }
|
---|
166 |
|
---|
167 | #endregion
|
---|
168 | }
|
---|
169 | }
|
---|