File: HandleLineSeries.cpp

package info (click to toggle)
freemat 4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 174,736 kB
  • ctags: 67,053
  • sloc: cpp: 351,060; ansic: 255,892; sh: 40,590; makefile: 4,323; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (206 lines) | stat: -rw-r--r-- 8,201 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * Copyright (c) 2002-2006 Samit Basu
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include "HandleLineSeries.hpp"
#include "HandleList.hpp"
#include "HandleObject.hpp"
#include "HandleAxis.hpp"
#include "IEEEFP.hpp"

HandleLineSeries::HandleLineSeries() {
  ConstructProperties();
  SetupDefaults();
}

HandleLineSeries::~HandleLineSeries() {
}

// Calculate the limits - should return a vector of the
// form...
// [xmin, xmax, ymin, ymax, zmin, zmax, cmin, cmax, amin, amax]
QVector<double> HandleLineSeries::GetLimits() {
  QVector<double> xs(VectorPropertyLookup("xdata"));
  QVector<double> ys(VectorPropertyLookup("ydata"));
  QVector<double> zs(VectorPropertyLookup("zdata"));
  QVector<double> limits;
  limits.push_back(VecMin(xs));
  limits.push_back(VecMax(xs));
  limits.push_back(VecMin(ys));
  limits.push_back(VecMax(ys));
  limits.push_back(VecMin(zs));
  limits.push_back(VecMax(zs));
  limits.push_back(0);
  limits.push_back(0);
  limits.push_back(0);
  limits.push_back(0);    
  return limits;
}

void HandleLineSeries::UpdateState() {
  // Check that x, y and z data are the same size
  // Generate the x coordinates if necessary
  QVector<double> xs(VectorPropertyLookup("xdata"));
  QVector<double> ys(VectorPropertyLookup("ydata"));
  QVector<double> zs(VectorPropertyLookup("zdata"));
  if (IsAuto("xdatamode")) {
    xs.clear();
    for (int i=0;i<ys.size();i++)
      xs.push_back(i+1.0);
  }
  if (zs.size() == 0)
    for (int i=0;i<ys.size();i++)
      zs.push_back(0.0);
  HPVector *sp;
  sp = (HPVector*) LookupProperty("xdata");
  sp->Data(xs);
  sp = (HPVector*) LookupProperty("zdata");
  sp->Data(zs);
}

void HandleLineSeries::PaintMe(RenderEngine& gc) {
  if (StringCheck("visible","off"))
    return;
  // Draw the line...
  double width(ScalarPropertyLookup("linewidth"));
  gc.lineWidth(width);
  HPColor *lc = (HPColor*) LookupProperty("color");
  // remap...
  QVector<double> xs(VectorPropertyLookup("xdata"));
  QVector<double> ys(VectorPropertyLookup("ydata"));
  QVector<double> zs(VectorPropertyLookup("zdata"));
  if (!((xs.size() == ys.size()) && (ys.size() == zs.size())))
    return;
  QVector<double> mxs, mys, mzs;
  HandleAxis *parent = (HandleAxis*) GetParentAxis();
  parent->ReMap(xs,ys,zs,mxs,mys,mzs);
  if (!lc->IsNone()) {
    gc.color(lc->Data());
    gc.setLineStyle(StringPropertyLookup("linestyle"));
    // Partition it into segments of finite entries..
    int n = 0;
    while (n < mxs.size()) {
      QVector<double> local_mxs, local_mys, local_mzs;
      while ((n < mxs.size()) && IsFinite(mxs[n]) && IsFinite(mys[n]) && (IsFinite(mzs[n]))) {
	local_mxs.push_back(mxs[n]);
	local_mys.push_back(mys[n]);
	local_mzs.push_back(mzs[n]);
	n++;
      }
      gc.lineSeries(local_mxs,local_mys,local_mzs);
      while ((n < mxs.size()) && !(IsFinite(mxs[n]) && IsFinite(mys[n]) && (IsFinite(mzs[n])))) n++;
    }
  }
  // Draw the symbols
  HPColor *ec = (HPColor*) LookupProperty("markeredgecolor");
  HPColor *fc = (HPColor*) LookupProperty("markerfacecolor");
  RenderEngine::SymbolType typ = StringToSymbol(StringPropertyLookup("marker"));
  double sze = ScalarPropertyLookup("markersize")/2.0;
  // Make sure there's something to draw...
  if ((typ != RenderEngine::None) || ec->IsNone() || fc->IsNone()) {
    // Calculate the u/v coordinates (pixels)
    QVector<double> uc;
    QVector<double> vc;
    for (int i=0;i<mxs.size();i++) {
      double u, v;
      bool clipped;
      gc.toPixels(mxs[i],mys[i],mzs[i],u,v,clipped);
      if (!clipped) {
	uc.push_back(u); vc.push_back(v);
      }
    }
    gc.setupDirectDraw();
    for (int i=0;i<uc.size();i++) 
      DrawSymbol(gc,typ,uc[i],vc[i],0,sze,ec->Data(),fc->Data(),width);
    gc.releaseDirectDraw();
  }
}

void HandleLineSeries::SetupDefaults() {
  SetThreeVectorDefault("color",0,0,0);
  SetConstrainedStringDefault("linestyle","-");
  SetScalarDefault("linewidth",1.0);
  SetConstrainedStringDefault("marker","none");
  SetThreeVectorDefault("markeredgecolor",0,0,0);
  SetThreeVectorDefault("markerfacecolor",0,0,0);
  SetScalarDefault("markersize",6);
  SetStringDefault("type","line");
  SetConstrainedStringDefault("visible","on");
  SetConstrainedStringDefault("xdatamode","manual");
}
  
void HandleLineSeries::ConstructProperties() {
  //!
  //@Module LINEPROPERTIES Line Series Object Properties
  //@@Section HANDLE
  //@@Usage
  //Below is a summary of the properties for a line series.
  //\begin{itemize}
  //  \item @|color| - @|colorspec| - The color that is used to 
  // draw the line.
  //  \item @|children| - Not used.
  //  \item @|displayname| - The name of this line series as it
  // appears in a legend.
  //  \item @|linestyle| - @|{'-','--',':','-.','none'}| - The style of the line.
  //  \item @|linewidth| - @|scalar| - The width of the line.
  //  \item @|marker| - @|{'+','o','*','.','x','square','s','diamond','d','^','v','>','<'}| - 
  // The marker for data points on the line.  Some of these are redundant, as @|'square'| 
  // @|'s'| are synonyms, and @|'diamond'| and @|'d'| are also synonyms.
  //  \item @|markeredgecolor| - @|colorspec| - The color used to draw the marker.  For some
  // of the markers (circle, square, etc.) there are two colors used to draw the marker.
  // This property controls the edge color (which for unfilled markers) is the primary
  // color of the marker.
  //  \item @|markerfacecolor| - @|colorspec| - The color used to fill the marker.  For some
  // of the markers (circle, square, etc.) there are two colors used to fill the marker.
  //  \item @|markersize| - @|scalar| - Control the size of the marker.  Defaults to 6, which
  // is effectively the radius (in pixels) of the markers.
  //  \item @|parent| - @|handle| - The axis that contains this object.
  //  \item @|tag| - @|string| - A string that can be used to tag the object.
  //  \item @|type| - @|string| - Returns the string @|'line'|.
  //  \item @|visible| - @|{'on','off'}| - Controls visibility of the the line.
  //  \item @|xdata| - @|vector| - Vector of x coordinates of points on the line.  Must be
  // the same size as the @|ydata| and @|zdata| vectors.
  //  \item @|ydata| - @|vector| - Vector of y coordinates of points on the line.  Must be
  // the same size as the @|xdata| and @|zdata| vectors.
  //  \item @|zdata| - @|vector| - Vector of z coordinates of points on the line.  Must be
  // the same size as the @|xdata| and @|ydata| vectors.
  //  \item @|xdatamode| - @|{'auto','manual'}| - When set to @|'auto'| FreeMat will autogenerate
  // the x coordinates for the points on the line.  These values will be @|1,..,N| where
  // @|N| is the number of points in the line.
  //  \item @|userdata| - @|array| - Available to store any variable you
  // want in the handle object.
  //\end{itemize}
  //!
  AddProperty(new HPColor,"color");
  AddProperty(new HPHandles,"children");
  AddProperty(new HPString,"displayname");
  AddProperty(new HPLineStyle,"linestyle");
  AddProperty(new HPScalar,"linewidth");
  AddProperty(new HPSymbol,"marker");
  AddProperty(new HPColor,"markeredgecolor");
  AddProperty(new HPColor,"markerfacecolor");
  AddProperty(new HPScalar,"markersize");
  AddProperty(new HPHandles,"parent");
  AddProperty(new HPString,"tag");
  AddProperty(new HPString,"type");
  AddProperty(new HPOnOff,"visible");
  AddProperty(new HPVector,"xdata");
  AddProperty(new HPAutoManual,"xdatamode");
  AddProperty(new HPArray,"userdata");
  AddProperty(new HPVector,"ydata");
  AddProperty(new HPVector,"zdata");
}