/// /// 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.Marker; using ILNumerics.Drawing; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using OpenTK.Platform; using OpenTK.Graphics.OpenGL.Enums; using ILNumerics.Drawing.Labeling; using ILNumerics.Drawing.Shapes; namespace ILNumerics.Drawing.Platform.OpenGL { public class ILOGLStyledMarkerShape : ILStyledMarkerShape { #region constructors internal ILOGLStyledMarkerShape (ILPanel panel, MarkerStyle style) : base (panel,style) { } #endregion #region public interface internal override void Draw(ILRenderProperties p, ILMarker marker, C4bV3f[] vertices, int startID, int vertCount) { // some implementations need to know we are drawing in // screen coords, vertcount give the signal: -1 if (vertCount == 0 || vertCount < -1) return; if (m_style != MarkerStyle.None) { if (m_style == MarkerStyle.Dot || m_style == MarkerStyle.Square) { SetupMarkerStyle(marker); unsafe { fixed(C4bV3f* pVertArr = vertices) { //GL.TexCoord2(0.5,0.5); GL.InterleavedArrays(InterleavedArrayFormat.V2f,0,(IntPtr)pVertArr); GL.DrawArrays(BeginMode.Points,0,Math.Abs(vertCount)); } } } else { #region draw textured points (slow version: textured quads) string markerTexKey = Hash(); ILTextureData texData; if (!m_panel.TextureManager.Exists(markerTexKey)) { CacheMarkerBitmap(); } texData = m_panel.TextureManager.GetTextureItem(markerTexKey,true); System.Diagnostics.Debug.Assert(texData != null,"The texture for marker was expected to exist in texture storage, but it was not found!"); // prepare for plotting GL.Color3(marker.Color); GL.PushAttrib(AttribMask.AllAttribBits); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Disable(EnableCap.DepthTest); RectangleF rectF = texData.TextureRectangle; float w,h; ILClippingData clip = m_panel.Limits; float s05x; float s05y; //if (m_marker.) s05x = Math.Abs(marker.Size * clip.WidthF / (m_panel.ClientSize.Width)); s05y = Math.Abs(marker.Size * clip.HeightF / (m_panel.ClientSize.Height)); if (vertCount > 0) { #region determine size for markers in world coords (graph limits) #endregion // draw all markers using quads. // this is slow! Todo: replace by point sprites! GL.Begin(BeginMode.Quads); for (int i = 0; i < vertCount; i++) { w = vertices[i].XPosition; h = vertices[i].YPosition; if (m_panel.ClipViewData && (w < clip.XMin || w > clip.XMax || h < clip.YMin || h > clip.YMax)) continue; w -= s05x; h -= s05y; GL.TexCoord2(rectF.Left,rectF.Bottom); GL.Vertex2(w,h); // ul GL.TexCoord2(rectF.Left,rectF.Top); GL.Vertex2(w,h + 2 * s05y); // bl w += 2 * s05x; GL.TexCoord2(rectF.Right,rectF.Top); GL.Vertex2(w,h + 2 * s05y); // br GL.TexCoord2(rectF.Right,rectF.Bottom); GL.Vertex2(w,h); // tr } GL.End(); } else if (vertCount == -1) { GL.Begin(BeginMode.Quads); w = vertices[0].XPosition - marker.Size; h = vertices[0].YPosition - marker.Size; GL.TexCoord2(rectF.Left,rectF.Top); GL.Vertex2(w,h); // ul GL.TexCoord2(rectF.Left,rectF.Bottom); GL.Vertex2(w,h + marker.Size * 2); // bl w += marker.Size; GL.TexCoord2(rectF.Right,rectF.Bottom); GL.Vertex2(w,h + marker.Size * 2); // br GL.TexCoord2(rectF.Right,rectF.Top); GL.Vertex2(w,h); // tr GL.End(); } GL.PopAttrib(); #endregion } } } #endregion #region private helper private void SetupMarkerStyle(ILMarker marker) { GL.PointSize(marker.Size); GL.Color3(marker.Color); GL.Disable(EnableCap.DepthTest); switch (m_style) { case MarkerStyle.Dot: GL.Enable(EnableCap.PointSmooth); break; case MarkerStyle.Square: GL.Disable(EnableCap.PointSmooth); break; case MarkerStyle.None: GL.PointSize(0.0f); break; default: throw new NotImplementedException(); } } #endregion } }