[9102] | 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 | #pragma warning disable 1591
|
---|
| 41 |
|
---|
| 42 | using System;
|
---|
| 43 | using System.Collections.Generic;
|
---|
| 44 | using System.Text;
|
---|
| 45 | using ILNumerics.Exceptions;
|
---|
| 46 | using ILNumerics.Drawing.Misc;
|
---|
| 47 | using ILNumerics.Misc;
|
---|
| 48 |
|
---|
| 49 | namespace ILNumerics.Drawing.Graphs {
|
---|
| 50 | /// <summary>
|
---|
| 51 | /// Class representing abstract implementation of filled graphs
|
---|
| 52 | /// </summary>
|
---|
| 53 | public abstract class ILFilledGraph : ILGraph {
|
---|
| 54 |
|
---|
| 55 | #region attributes / properties
|
---|
| 56 | protected float[] m_xCoords;
|
---|
| 57 | protected float[] m_yCoords;
|
---|
| 58 | protected ILArray<float> m_colors = ILMath.returnType<float>();
|
---|
| 59 | protected ILArray<float> m_sourceArray = ILMath.returnType<float>();
|
---|
| 60 | protected int m_Vertcount;
|
---|
| 61 | protected int m_rows, m_cols;
|
---|
| 62 | protected bool m_vertexReady, m_indexReady;
|
---|
| 63 | protected uint[] m_indices;
|
---|
| 64 | protected uint[] m_gridIndices;
|
---|
| 65 | protected int m_gridIndicesCount;
|
---|
| 66 | protected int m_indicesCount;
|
---|
| 67 | protected int m_oldSubQuadrant;
|
---|
| 68 | protected int m_stripesCount;
|
---|
| 69 | protected int m_stripesLen;
|
---|
| 70 | protected int m_gridStripsLen;
|
---|
| 71 | protected int m_gridStripsLenOnce;
|
---|
| 72 | protected int m_gridStripsCount;
|
---|
| 73 | protected bool m_shadeVertexDirectionLowHigh = false;
|
---|
| 74 | protected static readonly float MAXHUEVALUE = Misc.ILColorProvider.MAXHUEVALUE;
|
---|
| 75 | protected static readonly float CAMERA_ANG_OFFSET = - (float)(Math.PI / 4);
|
---|
| 76 | // visible properties
|
---|
| 77 | protected float m_opacity;
|
---|
| 78 | protected bool m_filled;
|
---|
| 79 | protected ILLineProperties m_wireLines;
|
---|
| 80 | /// <summary>
|
---|
| 81 | /// Wireframe line properties
|
---|
| 82 | /// </summary>
|
---|
| 83 | public ILLineProperties Wireframe {
|
---|
| 84 | get {
|
---|
| 85 | return m_wireLines;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /// <summary>
|
---|
| 90 | /// Get / set the transparency for the graph (percent)
|
---|
| 91 | /// </summary>
|
---|
| 92 | /// <remarks>1.0f (opaque) ... 0.0f (transparent)</remarks>
|
---|
| 93 | public float Opacity {
|
---|
| 94 | get {
|
---|
| 95 | return m_opacity;
|
---|
| 96 | }
|
---|
| 97 | set {
|
---|
| 98 | m_opacity = value;
|
---|
| 99 | Invalidate();
|
---|
| 100 | OnChanged("Opacity");
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | /// <summary>
|
---|
| 104 | /// Determine, if the tiles (rectangle areas between data points)
|
---|
| 105 | /// constructing the surface will be filled or invisible
|
---|
| 106 | /// </summary>
|
---|
| 107 | public bool Filled {
|
---|
| 108 | get {
|
---|
| 109 | return m_filled;
|
---|
| 110 | }
|
---|
| 111 | set {
|
---|
| 112 | m_filled = value;
|
---|
| 113 | OnChanged("Filled");
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | /// <summary>
|
---|
| 117 | /// get a reference to the internal data array
|
---|
| 118 | /// </summary>
|
---|
| 119 | /// <remarks>modifications to the array returned will
|
---|
| 120 | /// <b>not</b> alter the data the graph is based on.</remarks>
|
---|
| 121 | public ILRetArray<float> Data {
|
---|
| 122 | get {
|
---|
| 123 | return m_sourceArray.C;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | #endregion
|
---|
| 127 |
|
---|
| 128 | #region constructor
|
---|
| 129 | /// <summary>
|
---|
| 130 | /// construct new filled graph
|
---|
| 131 | /// </summary>
|
---|
| 132 | /// <param name="panel">panel hosting the graph</param>
|
---|
| 133 | /// <param name="X">X coords, if null, range 0..[cols of Z] will be created</param>
|
---|
| 134 | /// <param name="Y">Y coords, if null, range 0..[rows of Z] will be created</param>
|
---|
| 135 | /// <param name="Z">Z coords (heights)</param>
|
---|
| 136 | /// <param name="C">Colors for Z</param>
|
---|
| 137 | /// <param name="clippingContainer">gloabal limits of panel</param>
|
---|
| 138 | public ILFilledGraph(ILPanel panel, ILArray<float> X, ILArray<float> Y,
|
---|
| 139 | ILArray<float> Z, ILArray<float> C, ILClippingData clippingContainer)
|
---|
| 140 | : base(panel, clippingContainer) {
|
---|
| 141 | using (ILScope.Enter(X, Y, Z, C)) {
|
---|
| 142 | #region argument checking
|
---|
| 143 | m_localClipping.EventingSuspend();
|
---|
| 144 | if (Z == null || !Z.IsMatrix)
|
---|
| 145 | throw new ILArgumentException("ILFilledGraph: Z must be matrix!");
|
---|
| 146 | if (!Z.IsNumeric)
|
---|
| 147 | throw new ILArgumentException("ILFilledGraph: Z must be numeric!");
|
---|
| 148 | m_sourceArray.a = ILMath.tosingle(Z);
|
---|
| 149 | m_rows = m_sourceArray.Size[0];
|
---|
| 150 | m_cols = m_sourceArray.Size[1];
|
---|
| 151 | ILArray<float> tmp;
|
---|
| 152 | if (!object.Equals(X, null) && !X.IsEmpty) {
|
---|
| 153 | if (!X.IsMatrix || !X.IsNumeric) {
|
---|
| 154 | throw new ILArgumentException("ILFilledGraph: X must be numeric matrix!");
|
---|
| 155 | }
|
---|
| 156 | if (X.Size.IsSameSize(Z.Size)) {
|
---|
| 157 | tmp = ILMath.tosingle(X);
|
---|
| 158 | tmp.ExportValues(ref m_xCoords);
|
---|
| 159 | m_localClipping.XMax = tmp.MaxValue;
|
---|
| 160 | m_localClipping.XMin = tmp.MinValue;
|
---|
| 161 | } else {
|
---|
| 162 | throw new ILArgumentException("ILFilledGraph: X must be of same size than Z!");
|
---|
| 163 | }
|
---|
| 164 | } else {
|
---|
| 165 | ILMath.tosingle(ILMath.repmat(ILMath.counter(0.0, 1.0, 1, m_cols), m_rows, 1)).ExportValues(ref m_xCoords);
|
---|
| 166 | m_localClipping.XMin = 0;
|
---|
| 167 | m_localClipping.XMax = m_cols - 1;
|
---|
| 168 | }
|
---|
| 169 | if (!object.Equals(Y, null) && !Y.IsEmpty) {
|
---|
| 170 | if (!Y.IsMatrix || !Y.IsNumeric) {
|
---|
| 171 | throw new ILArgumentException("ILFilledGraph: Y must be numeric matrix!");
|
---|
| 172 | }
|
---|
| 173 | if (Y.Size.IsSameSize(Z.Size)) {
|
---|
| 174 | tmp = ILMath.tosingle(Y);
|
---|
| 175 | tmp.ExportValues(ref m_yCoords);
|
---|
| 176 | m_localClipping.YMax = tmp.MaxValue;
|
---|
| 177 | m_localClipping.YMin = tmp.MinValue;
|
---|
| 178 | } else {
|
---|
| 179 | throw new ILArgumentException("ILFilledGraph: Y must be same size than Z!");
|
---|
| 180 | }
|
---|
| 181 | } else {
|
---|
| 182 | ILMath.tosingle(ILMath.repmat(ILMath.counter(0.0, 1.0, m_rows, 1), 1, m_cols)).ExportValues(ref m_yCoords);
|
---|
| 183 | m_localClipping.YMax = m_rows - 1;
|
---|
| 184 | m_localClipping.YMin = 0;
|
---|
| 185 | }
|
---|
| 186 | if (object.Equals(C, null) || C.IsEmpty) {
|
---|
| 187 | m_colors.a = ILMath.empty<float>();
|
---|
| 188 | } else {
|
---|
| 189 | m_colors.a = ILMath.tosingle(C);
|
---|
| 190 | }
|
---|
| 191 | m_localClipping.ZMax = m_sourceArray.MaxValue;
|
---|
| 192 | m_localClipping.ZMin = m_sourceArray.MinValue;
|
---|
| 193 | #endregion
|
---|
| 194 | m_Vertcount = m_rows * m_cols;
|
---|
| 195 | m_vertexReady = false;
|
---|
| 196 | m_indexReady = false;
|
---|
| 197 | // default view properties
|
---|
| 198 | m_opacity = 1.0f;
|
---|
| 199 | m_wireLines = new ILLineProperties();
|
---|
| 200 | m_wireLines.Changed += new EventHandler(m_wireLines_Changed);
|
---|
| 201 | m_filled = true;
|
---|
| 202 | m_localClipping.EventingResume();
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 | #endregion
|
---|
| 206 |
|
---|
| 207 | #region protected/private helper
|
---|
| 208 |
|
---|
| 209 | protected virtual void CreateVertices() {}
|
---|
| 210 |
|
---|
| 211 | /// <summary>
|
---|
| 212 | /// Create indices for filled graphs
|
---|
| 213 | /// </summary>
|
---|
| 214 | /// <remarks>Indices will be ordered to assemble individual triangles.</remarks>
|
---|
| 215 | protected virtual void CreateIndices() {
|
---|
| 216 | #region interpolate shading faster, less exact (obsolete)
|
---|
| 217 | //if (m_panel.Camera.CosPhiShift > 0) {
|
---|
| 218 | // if (m_panel.Camera.SinPhiShift > 0) {
|
---|
| 219 | // System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi > 0 (front)");
|
---|
| 220 | // // looking from front
|
---|
| 221 | // checkVertexIndicesLength(m_cols * 2, m_rows-1);
|
---|
| 222 | // if (m_panel.Camera.LooksFromLeft) {
|
---|
| 223 | // pos1 = m_Vertcount-1; pos2 = pos1 - m_cols;
|
---|
| 224 | // for (int r = m_rows-1; r --> 0;) {
|
---|
| 225 | // for (int c = m_cols; c--> 0;) {
|
---|
| 226 | // m_indices[posI++] = (uint)pos1--;
|
---|
| 227 | // m_indices[posI++] = (uint)pos2--;
|
---|
| 228 | // }
|
---|
| 229 | // }
|
---|
| 230 | // } else {
|
---|
| 231 | // // looks from right
|
---|
| 232 | // pos1 = m_Vertcount-m_cols; pos2 = pos1 - m_cols;
|
---|
| 233 | // for (int r = m_rows-1; r --> 0;) {
|
---|
| 234 | // for (int c = m_cols; c--> 0;) {
|
---|
| 235 | // m_indices[posI++] = (uint)pos2++;
|
---|
| 236 | // m_indices[posI++] = (uint)pos1++;
|
---|
| 237 | // }
|
---|
| 238 | // pos1 -= (m_cols * 2);
|
---|
| 239 | // pos2 -= (m_cols * 2);
|
---|
| 240 | // }
|
---|
| 241 | // }
|
---|
| 242 | // } else {
|
---|
| 243 | // System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi < 0 (left)");
|
---|
| 244 | // // looking from left
|
---|
| 245 | // checkVertexIndicesLength(m_rows * 2, m_cols-1);
|
---|
| 246 | // pos1 = m_Vertcount-1; pos2 = m_Vertcount-2;
|
---|
| 247 | // for (int c = m_cols-1; c --> 0;) {
|
---|
| 248 | // for (int r = m_rows; r --> 0;) {
|
---|
| 249 | // m_indices[posI++] = (uint)pos1;
|
---|
| 250 | // m_indices[posI++] = (uint)pos2;
|
---|
| 251 | // pos1 -= m_cols;
|
---|
| 252 | // pos2 -= m_cols;
|
---|
| 253 | // }
|
---|
| 254 | // pos1 += (m_Vertcount-1);
|
---|
| 255 | // pos2 = pos1-1;
|
---|
| 256 | // }
|
---|
| 257 | // }
|
---|
| 258 | //} else {
|
---|
| 259 | // if (m_panel.Camera.SinPhiShift > 0) {
|
---|
| 260 | // // looking from right
|
---|
| 261 | // System.Diagnostics.Debug.WriteLine("CosPhi < 0 & SinPhi > 0 (right)");
|
---|
| 262 | // checkVertexIndicesLength(m_rows * 2, m_cols-1);
|
---|
| 263 | // pos1 = m_Vertcount-1; pos2 = m_Vertcount-2;
|
---|
| 264 | // for (int c = m_cols-1; c --> 0;) {
|
---|
| 265 | // for (int r = m_rows-1; r --> 0;) {
|
---|
| 266 | // m_indices[posI++] = (uint)pos1;
|
---|
| 267 | // m_indices[posI++] = (uint)pos2;
|
---|
| 268 | // pos1 -= m_cols;
|
---|
| 269 | // pos2 -= m_cols;
|
---|
| 270 | // }
|
---|
| 271 | // pos1 += m_Vertcount;
|
---|
| 272 | // pos2 += m_Vertcount;
|
---|
| 273 | // }
|
---|
| 274 | // } else {
|
---|
| 275 | // // looking from back
|
---|
| 276 | // System.Diagnostics.Debug.WriteLine("CosPhi < 0 & SinPhi < 0 (back)");
|
---|
| 277 | // checkVertexIndicesLength(m_cols * 2, m_rows-1);
|
---|
| 278 | // pos1 = m_cols-1; pos2 = pos1+m_cols;
|
---|
| 279 | // for (int r = m_rows-1; r-->0;) {
|
---|
| 280 | // for (int c = m_cols; c-->0;) {
|
---|
| 281 | // m_indices[posI++] = (uint)pos2--;
|
---|
| 282 | // m_indices[posI++] = (uint)pos1--;
|
---|
| 283 | // }
|
---|
| 284 | // pos1 += m_cols*2;
|
---|
| 285 | // pos2 += m_cols*2;
|
---|
| 286 | // }
|
---|
| 287 | // }
|
---|
| 288 | //}
|
---|
| 289 | //
|
---|
| 290 | #endregion
|
---|
| 291 | #region both shading modes WITH transparency, draws individual triangles
|
---|
| 292 | // DrawMode "trianglestrips" will not work here! ->
|
---|
| 293 | // We must specify each triangle seperately!
|
---|
| 294 | // Also we must divide the whole camera angle range in 8 (!) areas
|
---|
| 295 | // and handle each individually by different index arrays.
|
---|
| 296 | // This all is more exact but less performant ...
|
---|
| 297 | int pos1,pos2,posI = 0;
|
---|
| 298 | if (m_panel.Camera.CosPhiShift > 0) {
|
---|
| 299 | if (m_panel.Camera.SinPhiShift > 0) {
|
---|
| 300 | #region looking from front
|
---|
| 301 | //System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi > 0 (front)");
|
---|
| 302 | checkVertexIndicesLength((m_cols - 1) * 6,m_rows-1);
|
---|
| 303 | if (m_panel.Camera.LooksFromLeft) {
|
---|
| 304 | m_oldSubQuadrant = 7;
|
---|
| 305 | pos1 = m_Vertcount-1; pos2 = pos1-m_cols;
|
---|
| 306 | for (int r = m_rows-1; r --> 0; ) {
|
---|
| 307 | for (int c = m_cols-1; c-->0;) {
|
---|
| 308 | m_indices[posI++] = (uint)pos1-1;
|
---|
| 309 | m_indices[posI++] = (uint)pos2-1;
|
---|
| 310 | m_indices[posI++] = (uint)pos1;
|
---|
| 311 | m_indices[posI++] = (uint)pos2--;
|
---|
| 312 | m_indices[posI++] = (uint)pos2;
|
---|
| 313 | m_indices[posI++] = (uint)pos1--;
|
---|
| 314 | }
|
---|
| 315 | pos1--;
|
---|
| 316 | pos2--;
|
---|
| 317 | }
|
---|
| 318 | } else {
|
---|
| 319 | m_oldSubQuadrant = 0;
|
---|
| 320 | pos1 = m_Vertcount-2*m_cols; pos2 = m_Vertcount-m_cols;
|
---|
| 321 | for (int r = m_rows-1; r --> 0; ) {
|
---|
| 322 | for (int c = m_cols-1; c-->0;) {
|
---|
| 323 | m_indices[posI++] = (uint)pos2++;
|
---|
| 324 | m_indices[posI++] = (uint)pos1;
|
---|
| 325 | m_indices[posI++] = (uint)pos2;
|
---|
| 326 | m_indices[posI++] = (uint)pos1+1;
|
---|
| 327 | m_indices[posI++] = (uint)pos1++;
|
---|
| 328 | m_indices[posI++] = (uint)pos2;
|
---|
| 329 | }
|
---|
| 330 | pos1 -= (m_cols * 2 - 1);
|
---|
| 331 | pos2 -= (m_cols * 2 - 1);
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 | #endregion
|
---|
| 335 | } else {
|
---|
| 336 | #region looking from left
|
---|
| 337 | //System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi < 0 (left)");
|
---|
| 338 | checkVertexIndicesLength((m_rows - 1) * 6,m_cols-1);
|
---|
| 339 | if (m_panel.Camera.LooksFromFront) {
|
---|
| 340 | m_oldSubQuadrant = 6;
|
---|
| 341 | pos1 = m_Vertcount-2; pos2 = pos1 + 1;
|
---|
| 342 | for (int r = m_cols-1; r --> 0; ) {
|
---|
| 343 | for (int c = m_rows-1; c-->0;) {
|
---|
| 344 | m_indices[posI++] = (uint)(pos2-m_cols);
|
---|
| 345 | m_indices[posI++] = (uint)(pos1-m_cols);
|
---|
| 346 | m_indices[posI++] = (uint)pos2;
|
---|
| 347 | m_indices[posI++] = (uint)pos1; pos1 -= m_cols;
|
---|
| 348 | m_indices[posI++] = (uint)pos1;
|
---|
| 349 | m_indices[posI++] = (uint)pos2; pos2 -= m_cols;
|
---|
| 350 | }
|
---|
| 351 | pos1 += (m_Vertcount - m_cols - 1);
|
---|
| 352 | pos2 += (m_Vertcount - m_cols - 1);
|
---|
| 353 | }
|
---|
| 354 | } else {
|
---|
| 355 | m_oldSubQuadrant = 5;
|
---|
| 356 | pos1 = m_cols-2; pos2 = pos1 + 1;
|
---|
| 357 | for (int r = m_cols-1; r --> 0; ) {
|
---|
| 358 | for (int c = m_rows-1; c-->0;) {
|
---|
| 359 | m_indices[posI++] = (uint)pos1;
|
---|
| 360 | m_indices[posI++] = (uint)pos2; pos2 += m_cols;
|
---|
| 361 | m_indices[posI++] = (uint)pos2;
|
---|
| 362 | m_indices[posI++] = (uint)pos1; pos1 += m_cols;
|
---|
| 363 | m_indices[posI++] = (uint)pos1;
|
---|
| 364 | m_indices[posI++] = (uint)pos2;
|
---|
| 365 | }
|
---|
| 366 | pos1 -= (m_Vertcount - m_cols + 1);
|
---|
| 367 | pos2 -= (m_Vertcount - m_cols + 1);
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 | #endregion
|
---|
| 371 | }
|
---|
| 372 | } else {
|
---|
| 373 | if (m_panel.Camera.SinPhiShift > 0) {
|
---|
| 374 | #region looking from right
|
---|
| 375 | checkVertexIndicesLength((m_rows - 1) * 6,m_cols-1);
|
---|
| 376 | //System.Diagnostics.Debug.WriteLine("CosPhi < 0 & SinPhi > 0 (right)");
|
---|
| 377 | if (m_panel.Camera.LooksFromFront) {
|
---|
| 378 | m_oldSubQuadrant = 1;
|
---|
| 379 | pos1 = m_Vertcount-m_cols; pos2 = pos1+1;
|
---|
| 380 | for (int r = m_cols-1; r --> 0; ) {
|
---|
| 381 | for (int c = m_rows-1; c-->0;) {
|
---|
| 382 | m_indices[posI++] = (uint)pos1; pos1 -= m_cols;
|
---|
| 383 | m_indices[posI++] = (uint)pos1;
|
---|
| 384 | m_indices[posI++] = (uint)pos2;
|
---|
| 385 | m_indices[posI++] = (uint)pos1;
|
---|
| 386 | m_indices[posI++] = (uint)(pos2-m_cols);
|
---|
| 387 | m_indices[posI++] = (uint)pos2; pos2 -= m_cols;
|
---|
| 388 | }
|
---|
| 389 | pos1 += (m_Vertcount - m_cols + 1);
|
---|
| 390 | pos2 += (m_Vertcount - m_cols + 1);
|
---|
| 391 | }
|
---|
| 392 | } else {
|
---|
| 393 | m_oldSubQuadrant = 2;
|
---|
| 394 | pos1 = 0; pos2 = 1;
|
---|
| 395 | for (int r = m_cols-1; r --> 0; ) {
|
---|
| 396 | for (int c = m_rows-1; c-->0;) {
|
---|
| 397 | m_indices[posI++] = (uint)pos1;
|
---|
| 398 | m_indices[posI++] = (uint)(pos1+m_cols);
|
---|
| 399 | m_indices[posI++] = (uint)(pos2+m_cols);
|
---|
| 400 | m_indices[posI++] = (uint)pos1; pos1 += m_cols;
|
---|
| 401 | m_indices[posI++] = (uint)pos2; pos2 += m_cols;
|
---|
| 402 | m_indices[posI++] = (uint)pos2;
|
---|
| 403 | }
|
---|
| 404 | pos1 -= (m_Vertcount - m_cols - 1);
|
---|
| 405 | pos2 -= (m_Vertcount - m_cols - 1);
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 | #endregion
|
---|
| 409 | } else {
|
---|
| 410 | #region looking from back
|
---|
| 411 | //System.Diagnostics.Debug.WriteLine("CosPhi < 0 & SinPhi < 0 (back)");
|
---|
| 412 | checkVertexIndicesLength((m_cols - 1) * 6,m_rows-1);
|
---|
| 413 | if (m_panel.Camera.LooksFromLeft) {
|
---|
| 414 | m_oldSubQuadrant = 4;
|
---|
| 415 | pos1 = m_cols-1; pos2 = pos1+m_cols;
|
---|
| 416 | for (int r = m_rows-1; r --> 0; ) {
|
---|
| 417 | for (int c = m_cols-1; c-->0;) {
|
---|
| 418 | m_indices[posI++] = (uint)pos1--;
|
---|
| 419 | m_indices[posI++] = (uint)pos1;
|
---|
| 420 | m_indices[posI++] = (uint)pos2;
|
---|
| 421 | m_indices[posI++] = (uint)pos2-1;
|
---|
| 422 | m_indices[posI++] = (uint)pos1;
|
---|
| 423 | m_indices[posI++] = (uint)pos2--;
|
---|
| 424 | }
|
---|
| 425 | pos1 += (2*m_cols-1);
|
---|
| 426 | pos2 += (2*m_cols-1);
|
---|
| 427 | }
|
---|
| 428 | } else {
|
---|
| 429 | m_oldSubQuadrant = 3;
|
---|
| 430 | pos1 = 0; pos2 = pos1+m_cols;
|
---|
| 431 | for (int r = m_rows-1; r --> 0; ) {
|
---|
| 432 | for (int c = m_cols-1; c-->0;) {
|
---|
| 433 | m_indices[posI++] = (uint)pos1;
|
---|
| 434 | m_indices[posI++] = (uint)pos1+1;
|
---|
| 435 | m_indices[posI++] = (uint)pos2+1;
|
---|
| 436 | m_indices[posI++] = (uint)pos1++;
|
---|
| 437 | m_indices[posI++] = (uint)pos2++;
|
---|
| 438 | m_indices[posI++] = (uint)pos2;
|
---|
| 439 | }
|
---|
| 440 | pos1 ++;
|
---|
| 441 | pos2 ++;
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 | #endregion
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | #endregion
|
---|
| 448 | if (m_wireLines.Visible) {
|
---|
| 449 | #region create grid line indices
|
---|
| 450 | posI = 0;
|
---|
| 451 | if (m_panel.Camera.CosPhiShift > 0) {
|
---|
| 452 | if (m_panel.Camera.SinPhiShift > 0) {
|
---|
| 453 | #region looking from front
|
---|
| 454 | //System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi > 0 (front)");
|
---|
| 455 | checkGridIndicesLength((m_cols-1) * 4 + 2,m_rows-1);
|
---|
| 456 | pos1 = m_Vertcount-m_cols;
|
---|
| 457 | pos2 = m_Vertcount-m_cols;
|
---|
| 458 | // first row is special:
|
---|
| 459 | for (int c = m_cols-1; c-->0;) {
|
---|
| 460 | m_gridIndices[posI++] = (uint)pos1++;
|
---|
| 461 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 462 | }
|
---|
| 463 | pos1 -= 2*m_cols-1;
|
---|
| 464 | for (int r = m_rows-1; r-->0;) {
|
---|
| 465 | // first column is special:
|
---|
| 466 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 467 | m_gridIndices[posI++] = (uint)pos2;
|
---|
| 468 | for (int c = m_cols-1; c-->0;) {
|
---|
| 469 | m_gridIndices[posI++] = (uint)pos1++;
|
---|
| 470 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 471 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 472 | m_gridIndices[posI++] = (uint)++pos2;
|
---|
| 473 | }
|
---|
| 474 | pos1 -= (m_cols * 2 - 1);
|
---|
| 475 | pos2 -= (m_cols * 2 - 1);
|
---|
| 476 | }
|
---|
| 477 | #endregion
|
---|
| 478 | } else {
|
---|
| 479 | #region looking from left
|
---|
| 480 | //System.Diagnostics.Debug.WriteLine("CosPhi > 0 & SinPhi < 0 (left)");
|
---|
| 481 | checkGridIndicesLength((m_rows-1) * 4 + 2,m_cols-1);
|
---|
| 482 | pos1 = m_Vertcount-1;
|
---|
| 483 | pos2 = m_Vertcount-1-m_cols;
|
---|
| 484 | // first col is special:
|
---|
| 485 | for (int c = m_rows-1; c-->0;) {
|
---|
| 486 | m_gridIndices[posI++] = (uint)pos2; pos2 -= m_cols;
|
---|
| 487 | m_gridIndices[posI++] = (uint)pos1; pos1 -= m_cols;
|
---|
| 488 | }
|
---|
| 489 | pos2 = m_Vertcount - 1 - m_cols;
|
---|
| 490 | pos1 = m_Vertcount - 2;
|
---|
| 491 | for (int r = m_cols-1; r-->0;) {
|
---|
| 492 | // first row is special:
|
---|
| 493 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 494 | m_gridIndices[posI++] = (uint)pos1+1;
|
---|
| 495 | for (int c = m_rows-1; c-->0;) {
|
---|
| 496 | m_gridIndices[posI++] = (uint)(pos1-m_cols);
|
---|
| 497 | m_gridIndices[posI++] = (uint)pos1; pos1 -= m_cols;
|
---|
| 498 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 499 | m_gridIndices[posI++] = (uint)pos2; pos2 -= m_cols;
|
---|
| 500 | }
|
---|
| 501 | pos1 += (m_Vertcount - m_cols -1);
|
---|
| 502 | pos2 += (m_Vertcount - m_cols -1);
|
---|
| 503 | }
|
---|
| 504 | #endregion
|
---|
| 505 | }
|
---|
| 506 | } else {
|
---|
| 507 | if (m_panel.Camera.SinPhiShift > 0) {
|
---|
| 508 | #region looking from right
|
---|
| 509 | //System.Diagnostics.Debug.WriteLine("CosPhi < 0 & SinPhi > 0 (right)");
|
---|
| 510 | checkGridIndicesLength((m_rows-1) * 4 + 2,m_cols-1);
|
---|
| 511 | pos1 = 0;
|
---|
| 512 | pos2 = 1;
|
---|
| 513 | // first col is special:
|
---|
| 514 | for (int c = m_rows-1; c-->0;) {
|
---|
| 515 | m_gridIndices[posI++] = (uint)pos1; pos1 += m_cols;
|
---|
| 516 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 517 | }
|
---|
| 518 | pos1 = m_cols;
|
---|
| 519 | for (int r = m_cols-1; r-->0;) {
|
---|
| 520 | // first row is special:
|
---|
| 521 | m_gridIndices[posI++] = (uint)pos2-1;
|
---|
| 522 | m_gridIndices[posI++] = (uint)pos2;
|
---|
| 523 | for (int c = m_rows-1; c-->0;) {
|
---|
| 524 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 525 | m_gridIndices[posI++] = (uint)pos1+1; pos1 += m_cols;
|
---|
| 526 | m_gridIndices[posI++] = (uint)pos2; pos2 += m_cols;
|
---|
| 527 | m_gridIndices[posI++] = (uint)pos2;
|
---|
| 528 | }
|
---|
| 529 | pos1 -= (m_Vertcount - m_cols -1);
|
---|
| 530 | pos2 -= (m_Vertcount - m_cols -1);
|
---|
| 531 | }
|
---|
| 532 | #endregion
|
---|
| 533 | } else {
|
---|
| 534 | #region looking from back
|
---|
| 535 | //System.Diagnostics.Debug.WriteLine("CosPhi < 0 & SinPhi < 0 (back)");
|
---|
| 536 | checkGridIndicesLength((m_cols-1) * 4 + 2,m_rows-1);
|
---|
| 537 | pos1 = m_cols-1; pos2 = pos1-1;
|
---|
| 538 | for (int c = m_cols-1; c-->0;) {
|
---|
| 539 | m_gridIndices[posI++] = (uint)pos2--;
|
---|
| 540 | m_gridIndices[posI++] = (uint)pos1--;
|
---|
| 541 | }
|
---|
| 542 | pos2 = m_cols*2-1;
|
---|
| 543 | pos1 = m_cols-1;
|
---|
| 544 | for (int r = m_rows-1; r-->0;) {
|
---|
| 545 | // first column is special:
|
---|
| 546 | m_gridIndices[posI++] = (uint)pos1;
|
---|
| 547 | m_gridIndices[posI++] = (uint)pos2;
|
---|
| 548 | for (int c = m_cols-1; c-->0;) {
|
---|
| 549 | m_gridIndices[posI++] = (uint)(pos2-1);
|
---|
| 550 | m_gridIndices[posI++] = (uint)pos2--;
|
---|
| 551 | m_gridIndices[posI++] = (uint)--pos1;
|
---|
| 552 | m_gridIndices[posI++] = (uint)pos2;
|
---|
| 553 | }
|
---|
| 554 | pos1 += (2*m_cols-1);
|
---|
| 555 | pos2 += (2*m_cols-1);
|
---|
| 556 | }
|
---|
| 557 | #endregion
|
---|
| 558 | }
|
---|
| 559 | }
|
---|
| 560 | #endregion
|
---|
| 561 | }
|
---|
| 562 | m_indexReady = true;
|
---|
| 563 | }
|
---|
| 564 | /// <summary>
|
---|
| 565 | /// checks the length of index vector and allocate more memory if needed
|
---|
| 566 | /// </summary>
|
---|
| 567 | /// <param name="vertStrCount">Number of stripes to be drawn</param>
|
---|
| 568 | /// <param name="vertStrLen">Number of indices for each stripe</param>
|
---|
| 569 | protected void checkVertexIndicesLength(int vertStrLen, int vertStrCount) {
|
---|
| 570 | m_indicesCount = vertStrCount * vertStrLen;
|
---|
| 571 | if (m_indices != null && m_indices.Length < m_indicesCount) {
|
---|
| 572 | ILMemoryPool.Pool.Free(m_indices);
|
---|
| 573 | }
|
---|
| 574 | if (m_indices == null || m_indices.Length < m_indicesCount) {
|
---|
| 575 | m_indices = ILMemoryPool.Pool.New<uint>(m_indicesCount);
|
---|
| 576 | }
|
---|
| 577 | m_stripesCount = vertStrCount;
|
---|
| 578 | m_stripesLen = vertStrLen;
|
---|
| 579 | }
|
---|
| 580 | /// <summary>
|
---|
| 581 | /// checks the length of grid index vector and allocate more if needed
|
---|
| 582 | /// </summary>
|
---|
| 583 | /// <param name="gridStrCount">Number of stripes to be drawn</param>
|
---|
| 584 | /// <param name="gridStrLen">Number of indices for each stripe</param>
|
---|
| 585 | protected void checkGridIndicesLength(int gridStrLen, int gridStrCount) {
|
---|
| 586 | m_gridStripsLenOnce = (gridStrLen -2) / 2 + 2;
|
---|
| 587 | m_gridIndicesCount = gridStrLen * gridStrCount + m_gridStripsLenOnce;
|
---|
| 588 | if (m_gridIndices != null && m_gridIndices.Length < m_gridIndicesCount) {
|
---|
| 589 | ILMemoryPool.Pool.Free(m_gridIndices);
|
---|
| 590 | }
|
---|
| 591 | if (m_gridIndices == null || m_gridIndices.Length < m_gridIndicesCount) {
|
---|
| 592 | m_gridIndices = ILMemoryPool.Pool.New<uint>(m_gridIndicesCount);
|
---|
| 593 | }
|
---|
| 594 | m_gridStripsCount = gridStrCount;
|
---|
| 595 | m_gridStripsLen = gridStrLen;
|
---|
| 596 | }
|
---|
| 597 | /// <summary>
|
---|
| 598 | /// Dispose off this filled graph (grid-)indices
|
---|
| 599 | /// </summary>
|
---|
| 600 | public override void Dispose() {
|
---|
| 601 | if (m_indices != null) {
|
---|
| 602 | ILMemoryPool.Pool.Free<uint>(m_indices);
|
---|
| 603 | }
|
---|
| 604 | if (m_gridIndices != null) {
|
---|
| 605 | ILMemoryPool.Pool.Free<uint>(m_gridIndices);
|
---|
| 606 | }
|
---|
| 607 | base.Dispose();
|
---|
| 608 | }
|
---|
| 609 | /// <summary>
|
---|
| 610 | /// checks & if neccessary triggers recreation of all vertices and indices
|
---|
| 611 | /// </summary>
|
---|
| 612 | /// <remarks>This function is called by the enclosing panel, e.g. when rotation
|
---|
| 613 | /// occours, which makes a reconfiguration neccessary. It internally calls CreateVertices()
|
---|
| 614 | /// and CreateIndices().</remarks>
|
---|
| 615 | internal override void Configure() {
|
---|
| 616 | m_isReady = false;
|
---|
| 617 | if (!m_vertexReady) CreateVertices();
|
---|
| 618 | if (!m_indexReady) CreateIndices();
|
---|
| 619 | m_isReady = true;
|
---|
| 620 | }
|
---|
| 621 |
|
---|
| 622 | protected override void OnChanged(string source) {
|
---|
| 623 | base.OnChanged(source);
|
---|
| 624 | m_vertexReady = false;
|
---|
| 625 | }
|
---|
| 626 |
|
---|
| 627 | protected void m_wireLines_Changed(object sender, EventArgs args) {
|
---|
| 628 | OnWireLinesChanged();
|
---|
| 629 | }
|
---|
| 630 | protected virtual void OnWireLinesChanged () {
|
---|
| 631 | m_indexReady = false;
|
---|
| 632 | OnChanged("Wirelines");
|
---|
| 633 | }
|
---|
| 634 | #endregion
|
---|
| 635 |
|
---|
| 636 | }
|
---|
| 637 | }
|
---|