Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Marker/ILTexMarkerShape.cs @ 11826

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

#1967: ILNumerics source for experimentation

File size: 8.8 KB
RevLine 
[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
40using System;
41using System.Collections.Generic;
42using System.Text;
43using System.Drawing;
44using ILNumerics.Drawing;
45using ILNumerics.Drawing.Interfaces;
46using ILNumerics.Drawing.Labeling;
47using ILNumerics.Drawing.Shapes;
48
49namespace ILNumerics.Drawing.Marker {
50    public class ILTexMarkerShape : ILMarkerShape {
51
52        #region attributes
53        protected string m_expression;
54        protected IILTextInterpreter m_interpreter;
55        protected Font m_font;
56        protected int m_maxLabelsDrawn;
57        protected string m_valueFormat;
58        protected IILTextRenderer m_renderer;
59        #endregion
60
61        #region constructors
62        internal ILTexMarkerShape (ILPanel panel, string expression)
63            :base (panel) {
64            m_expression = expression;
65            m_interpreter = new ILSimpleTexInterpreter();
66            m_font = new Font(FontFamily.GenericSansSerif,10.0f);
67            m_maxLabelsDrawn = 50;
68            m_valueFormat = "f";
69            m_renderer = panel.TextRendererManager.GetDefault(CoordSystem.World3D);
70        }
71        #endregion
72
73        #region properties
74        /// <summary>
75        /// Interpreter instance usedt to convert expression into visual output
76        /// </summary>
77        public IILTextInterpreter Interpreter {
78            get {
79                return m_interpreter;
80            }
81            set {
82                m_interpreter = value;
83            }
84        }
85        /// <summary>
86        /// maximum number of labels to be drawn
87        /// </summary>
88        /// <remarks>If the graph contains more datapoints, only <i>MaxLabelsDrawn</i> markers
89        /// will be shown. This is for performance reasons only. Default is 50.</remarks>
90        public int MaxLabelsDrawn {
91            get { return m_maxLabelsDrawn; }
92            set {
93                if (value >= 0)
94                    m_maxLabelsDrawn = value;
95            }
96        }
97        /// <summary>
98        /// Format string used to convert value numbers into string
99        /// </summary>
100        /// <remarks>Default: 'f'</remarks>
101        public string ValueFormat {
102            get { return m_valueFormat; }
103            set {
104                if (!String.IsNullOrEmpty(value)) {
105                    m_valueFormat = value;
106                }
107            }
108        }
109        /// <summary>
110        /// Expression defining the marker tex shape
111        /// </summary>
112        /// <remarks>The expression may uses markups interpretable by the current interpreter. This is - by default - an simple Tex interpreter.
113        /// In addition to all partial tex commands, one may uses placeholders '\\index', '\\xvalue' and/or '\\yvalue'. Those placeholders will be
114        /// replaces for every marker individually with its real values at runtime.
115        /// <para>This property is readonly. In order to change the expression, assign the new expression string to the Shape property of the
116        /// containing ILMarker class.</para></remarks>
117        public string Expression {
118            get {
119                return m_expression;
120            }
121        }
122        #endregion
123
124        #region public interface
125        public string Hash() {
126            return String.Format("M:{0}",m_expression);
127        }
128
129        /// <summary>
130        /// draw all markers (graph / legend)
131        /// </summary>
132        /// <param name="marker">the marker object (for properties)</param>
133        /// <param name="vertices">coords, interleaved</param>
134        /// <param name="vertcount">number of coords, special: -1 for legend rendering</param>
135        /// <remarks>This function is reused for both: drawing in world coords (graph) and drawing in
136        /// screen coords (legend). Latter case requires vertcount to be -1, vertices must contain
137        /// at least 2 float values than!</remarks>
138        internal override void Draw(ILRenderProperties p, ILMarker marker, C4bV3f[] vertices, int startID, int vertcount) {
139            if (vertcount > 0) {
140                int inc = Math.Max(1,(vertcount/m_maxLabelsDrawn));
141                m_renderer.Begin(p);
142                for (int i = 0; i < vertcount; i += inc) {
143                    #region draw textured points (slow version: textured quads)
144                    string expr = m_expression.Replace("\\index",i.ToString());
145                    expr = expr.Replace("\\xvalue",vertices[i].XPosition.ToString(m_valueFormat));
146                    expr = expr.Replace("\\yvalue",vertices[i].YPosition.ToString(m_valueFormat));
147                    ILRenderQueue queue = m_interpreter.Transform(expr,m_font,marker.Color,m_renderer);
148                    #region determine size for markers in world coords (graph limits)
149                        float w,h;
150                        ILClippingData clip = m_panel.Limits;
151                        float s05x;
152                        float s05y;
153                        s05x = Math.Abs(queue.Size.Width * clip.WidthF / 2 / (m_panel.ClientSize.Width));
154                        s05y = Math.Abs(queue.Size.Height * clip.HeightF / 2 / (m_panel.ClientSize.Height));
155                    #endregion
156                    // this is slow! Todo: replace by point sprites!
157                    w = vertices[i].XPosition;
158                    h = vertices[i].YPosition;           
159                    if (m_panel.ClipViewData && (w < clip.XMin || w > clip.XMax || h < clip.YMin || h > clip.YMax)) {
160                        continue;
161                    }
162                    m_renderer.Draw(queue,w-s05x,h+s05y,vertices[i].ZPosition,
163                                    w + s05x,h-s05y,vertices[i].ZPosition,marker.Color);
164                    #endregion
165                }
166                m_renderer.End(p);
167            } else if (vertcount == -1) {
168                #region render for legend
169                m_renderer.Begin(p);
170                string expr = m_expression.Replace("\\index","0");
171                expr = expr.Replace("\\xvalue","0.2");
172                expr = expr.Replace("\\yvalue","0.4");
173                ILRenderQueue queue = m_interpreter.Transform(expr,m_font,marker.Color,m_renderer);
174                #region determine size for markers in SCREEN COORDS
175                float w,h;
176                ILClippingData clip = m_panel.Limits;
177                float s05x;
178                float s05y;
179                s05x = Math.Abs(queue.Size.Width / 2 );
180                s05y = Math.Abs(queue.Size.Height / 2);
181
182                #endregion
183                // this is slow! Todo: replace by point sprites!
184                w = vertices[0].XPosition;
185                h = vertices[0].YPosition;
186               
187                m_renderer.Draw(queue,w-s05x,h-s05y,0,w + s05x,h+s05y,0,marker.Color);
188                m_renderer.End(p);
189                #endregion
190            }
191
192        }
193        #endregion
194
195    }
196}
Note: See TracBrowser for help on using the repository browser.