Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Platform/OpenGL/ILOGLPlot2DGraph.cs @ 11194

Last change on this file since 11194 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 6.8 KB
Line 
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
40using System;
41using System.Collections.Generic;
42using System.Text;
43using System.Drawing;
44using System.Drawing.Imaging;
45using System.Data;
46using System.Windows.Forms;
47using ILNumerics.Exceptions;
48using System.Resources;
49using OpenTK.Graphics;
50using OpenTK.Graphics.OpenGL;
51using OpenTK.Platform;
52using OpenTK.Graphics.OpenGL.Enums;
53using ILNumerics.Drawing.Graphs;
54using ILNumerics.Drawing;
55using ILNumerics.Drawing.Labeling;
56using ILNumerics.Drawing.Interfaces;
57using ILNumerics.Drawing.Shapes;
58
59namespace ILNumerics.Drawing.Platform.OpenGL
60{
61    /// <summary>
62    /// OpenGL implementation for ILPlot2DGraph
63    /// </summary>
64    public class ILOGLPlot2DGraph : ILPlot2DGraph {
65
66        #region attributes
67
68        protected int m_textureName = 0;
69        protected float[] m_markerQuads;
70
71        #endregion
72
73        #region constructors
74
75        internal ILOGLPlot2DGraph(ILPanel panel, ILArray<float> sourceArray,
76                                  ILClippingData clippingContainer)
77                                : base(panel, sourceArray,clippingContainer) {
78        }
79        internal ILOGLPlot2DGraph(ILPanel panel, ILArray<float> xData, ILArray<float> yData,
80                                  ILClippingData clippingContainer)
81                                : base(panel, xData, yData, clippingContainer) {
82        }
83
84        #endregion
85
86        #region public (& abstract) interface
87
88        public override void Draw(ILRenderProperties p) {
89            //System.Diagnostics.Debug.WriteLine("ILOGLGraphPlot2D_Draw");
90            #region draw line
91            // draw linestrip - simple case - fast vertex rendering
92            if (m_properties.Visible) {
93                GL.Disable(EnableCap.Blend);
94                GL.Disable(EnableCap.Texture2D);
95                ILOGLPanel.SetupLineStyle(m_properties);
96                unsafe {
97                    fixed(C4bV3f* pVertArr = m_vertices) { 
98                        GL.InterleavedArrays(InterleavedArrayFormat.C4ubV3f,0,(IntPtr)pVertArr);
99                        if (m_properties.Color.IsEmpty) {
100                            GL.ShadeModel(ShadingModel.Smooth);
101                        } else {
102                            GL.ShadeModel(ShadingModel.Flat);
103                            GL.DisableClientState(EnableCap.ColorArray);
104                        }
105
106                        if (m_startID < 2) {
107                            GL.DrawArrays(BeginMode.LineStrip, m_startID, m_vertexCount-1);
108                        } else {
109                            GL.DrawArrays(BeginMode.LineStrip, m_startID, m_vertexCount-m_startID);
110                            GL.DrawArrays(BeginMode.LineStrip, 0, m_startID);
111                        }
112                    }
113                }
114            }
115            #endregion
116            #region draw markers
117            if (m_marker.Visible) {
118                m_marker.Shape.Draw(p, m_marker, m_vertices,0, m_vertexCount-1);
119            }
120            #endregion
121        }
122        public override void Dispose() {
123            m_vertices = null;
124        }
125        /// <summary>
126        /// (re)create vertex buffer, line-, texture objects
127        /// </summary>
128        internal override void Configure() {
129        }
130
131        public override void DrawToLegend(ILRenderProperties p, Rectangle sampleArea, Rectangle labelArea) {
132            if (p.Graphics != null) {
133                // bitmap output is handled by base class
134                base.DrawToLegend(p, sampleArea, labelArea);
135                return;
136            }
137            int sampY = (int)(sampleArea.Top + sampleArea.Height / 2.0f);
138            #region draw line
139            if (m_properties.Visible) {
140                ILNumerics.Drawing.Platform.OpenGL.ILOGLPanel.SetupLineStyle(m_properties);
141                GL.Begin(BeginMode.Lines);
142                GL.Vertex2(sampleArea.Left,sampY);
143                GL.Vertex2(sampleArea.Right,sampY);
144                GL.End();
145            }
146            #endregion
147
148            #region draw marker
149            if (m_marker.Visible) {
150                C4bV3f pos = new C4bV3f();
151                pos.XPosition = sampleArea.Left + sampleArea.Width / 2.0f;
152                pos.YPosition = sampY;
153                m_marker.Shape.Draw(p, m_marker,new C4bV3f[] {pos},0,-1);
154            }
155            #endregion
156            //GL.Vertex2(sampleArea.Right,sampleArea.Bottom);
157            //GL.Vertex2(sampleArea.Left,sampleArea.Bottom);
158            m_label.m_position.X = labelArea.X + labelArea.Width / 2;
159            m_label.m_position.Y = labelArea.Y + labelArea.Height / 2;
160            m_label.Anchor = new PointF(.5f, .5f);  //  = TickLabelAlign.center | TickLabelAlign.vertCenter;
161            m_label.Draw(p);
162        }
163        #endregion
164    }
165}
Note: See TracBrowser for help on using the repository browser.