Line data Source code
1 : //# PlotFactory.cc
2 : //# Copyright (C) 2009
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be addressed as follows:
20 : //# Internet email: aips2-request@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : //# $Id: $
27 : #include <graphics/GenericPlotter/PlotFactory.h>
28 :
29 : using namespace casacore;
30 : namespace casa {
31 :
32 : /////////////////////////////
33 : // PLOTFACTORY DEFINITIONS //
34 : /////////////////////////////
35 :
36 0 : PlotFactory::PlotFactory() { }
37 :
38 0 : PlotFactory::~PlotFactory() { }
39 :
40 :
41 0 : PlotterPtr PlotFactory::plotter(PlotCanvasPtr canvas,const String& windowTitle,
42 : bool showGUI, int logEventFlags, bool smartDelete) {
43 : PlotterPtr p = plotter(windowTitle, false, showGUI, logEventFlags,
44 0 : smartDelete);
45 0 : if(!canvas.null()) p->setCanvasLayout(new PlotLayoutSingle(canvas));
46 0 : return p;
47 : }
48 :
49 :
50 0 : MaskedScatterPlotPtr PlotFactory::maskedPlot(PlotMaskedPointDataPtr data,
51 : const String& title, bool smartDelete) const {
52 0 : return scatterPlot(data, title, smartDelete); }
53 :
54 0 : ErrorPlotPtr PlotFactory::errorPlot(PlotErrorDataPtr data,
55 : const String& title, bool smartDelete) const {
56 0 : return scatterPlot(data, title, smartDelete); }
57 :
58 0 : ColoredPlotPtr PlotFactory::coloredPlot(PlotBinnedDataPtr data,
59 : const String& title, bool smartDelete) const {
60 0 : return scatterPlot(data, title, smartDelete); }
61 :
62 0 : BarPlotPtr PlotFactory::histogramPlot(PlotSingleDataPtr data,
63 : unsigned int numBins, const String& title, bool smartDelete) const {
64 0 : return barPlot(new PlotHistogramData(data, numBins), title, smartDelete); }
65 :
66 0 : RasterPlotPtr PlotFactory::contourPlot(PlotRasterDataPtr data,
67 : const std::vector<double>& contours, const String& title,
68 : PlotRasterData::Format format, bool smartDelete) const {
69 0 : RasterPlotPtr p = rasterPlot(data, title, format, smartDelete);
70 0 : p->setContourLines(contours);
71 0 : return p;
72 : }
73 :
74 0 : RasterPlotPtr PlotFactory::spectrogramPlot(PlotRasterDataPtr data,
75 : const String& title, bool smartDelete) const{
76 0 : return rasterPlot(data, title, PlotRasterData::SPECTROGRAM, smartDelete); }
77 :
78 0 : RasterPlotPtr PlotFactory::contouredSpectrogramPlot(PlotRasterDataPtr data,
79 : const std::vector<double>& cont, const String& title,bool smartDelete)const{
80 : RasterPlotPtr p = rasterPlot(data, title, PlotRasterData::SPECTROGRAM,
81 0 : smartDelete);
82 0 : p->setContourLines(cont);
83 0 : return p;
84 : }
85 :
86 0 : PlotAnnotationPtr PlotFactory::annotation(const String& text, double x,
87 : double y, bool smartDelete) const {
88 0 : return annotation(text, PlotCoordinate(x, y, PlotCoordinate::WORLD),
89 0 : smartDelete);
90 : }
91 :
92 0 : PlotShapeRectanglePtr PlotFactory::shapeRectangle(double left, double top,
93 : double right, double bottom, bool smartDelete) const {
94 0 : return shapeRectangle(PlotCoordinate(left, top, PlotCoordinate::WORLD),
95 0 : PlotCoordinate(right, bottom, PlotCoordinate::WORLD),
96 0 : smartDelete);
97 : }
98 :
99 0 : PlotShapeEllipsePtr PlotFactory::shapeEllipse(double x, double y,
100 : double xRadius, double yRadius, bool smartDelete) const {
101 0 : return shapeEllipse(PlotCoordinate(x, y, PlotCoordinate::WORLD),
102 0 : PlotCoordinate(xRadius, yRadius, PlotCoordinate::WORLD),
103 0 : smartDelete);
104 : }
105 :
106 0 : PlotShapePolygonPtr PlotFactory::shapePolygon(const std::vector<double>& x,
107 : const std::vector<double>& y, bool smartDelete) const {
108 0 : std::vector<PlotCoordinate> c(min((uInt)x.size(), (uInt)y.size()));
109 0 : for(unsigned int i = 0; i < c.size(); i++)
110 0 : c[i] = PlotCoordinate(x[i], y[i], PlotCoordinate::WORLD);
111 0 : return shapePolygon(c, smartDelete);
112 : }
113 :
114 0 : PlotShapeArrowPtr PlotFactory::shapeArrow(double fromX, double fromY,
115 : double toX, double toY, PlotShapeArrow::Style fromArrow,
116 : PlotShapeArrow::Style toArrow, bool smartDelete) const {
117 0 : return shapeArrow(PlotCoordinate(fromX, fromY, PlotCoordinate::WORLD),
118 0 : PlotCoordinate(toX, toY, PlotCoordinate::WORLD),
119 0 : fromArrow, toArrow, smartDelete);
120 : }
121 :
122 0 : PlotShapeArrowPtr PlotFactory::shapeLineSegment(const PlotCoordinate& from,
123 : const PlotCoordinate& to, bool smartDelete) const {
124 : return shapeArrow(from, to, PlotShapeArrow::NOARROW,
125 0 : PlotShapeArrow::NOARROW, smartDelete);
126 : }
127 :
128 0 : PlotShapeArrowPtr PlotFactory::shapeLineSegment(double fromX, double fromY,
129 : double toX, double toY, bool smartDelete) const {
130 0 : return shapeArrow(PlotCoordinate(fromX, fromY, PlotCoordinate::WORLD),
131 0 : PlotCoordinate(toX, toY, PlotCoordinate::WORLD),
132 : PlotShapeArrow::NOARROW, PlotShapeArrow::NOARROW,
133 0 : smartDelete);
134 : }
135 :
136 0 : PlotShapePathPtr PlotFactory::shapePath(const std::vector<double>& x,
137 : const std::vector<double>& y, bool smartDelete) const {
138 0 : std::vector<PlotCoordinate> c(min((uInt)x.size(), (uInt)y.size()));
139 0 : for(unsigned int i = 0; i < c.size(); i++)
140 0 : c[i] = PlotCoordinate(x[i], y[i], PlotCoordinate::WORLD);
141 0 : return shapePath(c, smartDelete);
142 : }
143 :
144 0 : PlotPointPtr PlotFactory::point(double x, double y, bool smartDelete) const {
145 0 : return point(PlotCoordinate(x, y, PlotCoordinate::WORLD),smartDelete); }
146 :
147 0 : PlotPointPtr PlotFactory::point(float x, float y, bool smartDelete) const {
148 0 : return point(PlotCoordinate(x, y, PlotCoordinate::WORLD),smartDelete); }
149 :
150 0 : PlotPointPtr PlotFactory::point(int x, int y, bool smartDelete) const {
151 0 : return point(PlotCoordinate(x, y, PlotCoordinate::WORLD),smartDelete); }
152 :
153 0 : PlotPointPtr PlotFactory::point(unsigned int x, unsigned int y,
154 : bool smartDelete) const {
155 0 : return point(PlotCoordinate(x, y, PlotCoordinate::WORLD),smartDelete); }
156 :
157 :
158 0 : PlotColorPtr PlotFactory::color(const PlotColorPtr copy,
159 : bool smartDelete) const {
160 0 : if(!copy.null()) return color(*copy, smartDelete);
161 0 : else return copy;
162 : }
163 :
164 0 : PlotFontPtr PlotFactory::font(const PlotFontPtr copy, bool smartDelete) const {
165 0 : if(!copy.null()) return font(*copy, smartDelete);
166 0 : else return copy;
167 : }
168 :
169 0 : PlotAreaFillPtr PlotFactory::areaFill(const PlotAreaFillPtr copy,
170 : bool smartDelete) const {
171 0 : if(!copy.null()) return areaFill(*copy, smartDelete);
172 0 : else return copy;
173 : }
174 :
175 0 : PlotLinePtr PlotFactory::line(const PlotLinePtr copy, bool smartDelete) const {
176 0 : if(!copy.null()) return line(*copy, smartDelete);
177 0 : else return copy;
178 : }
179 :
180 0 : PlotSymbolPtr PlotFactory::symbol(char sym, bool smartDelete) const {
181 0 : PlotSymbolPtr s = symbol(PlotSymbol::CHARACTER, smartDelete);
182 0 : s->setSymbol(sym);
183 0 : return s;
184 : }
185 :
186 0 : PlotSymbolPtr PlotFactory::createSymbol (const String& descriptor,
187 : Int size, const String& color,
188 : const String& fillPattern, bool outline ){
189 0 : PlotSymbolPtr ps = symbol(PlotSymbol::NOSYMBOL);
190 0 : ps->setSymbol( descriptor );
191 0 : ps->setSize( size, size );
192 0 : ps->setColor( color );
193 0 : PlotAreaFillPtr paf = areaFill(color, PlotAreaFill::NOFILL);
194 0 : paf ->setPattern( fillPattern );
195 0 : ps->setAreaFill( paf );
196 0 : if(outline) {
197 0 : ps->setLine("black");
198 : }
199 0 : return ps;
200 : }
201 :
202 0 : PlotSymbolPtr PlotFactory::uSymbol(unsigned short unicode,
203 : bool smartDelete) const {
204 0 : PlotSymbolPtr s = symbol(PlotSymbol::CHARACTER, smartDelete);
205 0 : s->setUSymbol(unicode);
206 0 : return s;
207 : }
208 :
209 0 : PlotSymbolPtr PlotFactory::symbol(const PlotSymbolPtr copy,
210 : bool smartDelete) const {
211 0 : if(!copy.null()) return symbol(*copy, smartDelete);
212 0 : else return copy;
213 : }
214 :
215 :
216 :
217 0 : PlotStandardMouseToolGroupPtr PlotFactory::standardMouseTools(
218 : ToolCode activeTool,
219 : bool smartDelete) const {
220 :
221 0 : PlotSelectToolPtr sel = selectTool();
222 0 : sel->setSelectLine(line("black", PlotLine::SOLID, 1.0));
223 0 : sel->setRectLine(line("black", PlotLine::SOLID, 1.0));
224 0 : sel->setRectFill(areaFill("black", PlotAreaFill::MESH3));
225 : return PlotStandardMouseToolGroupPtr(new PlotStandardMouseToolGroup(
226 0 : sel, zoomTool(), panTool(), flagAllTool(), trackerTool(), activeTool),
227 0 : smartDelete);
228 : }
229 :
230 :
231 :
232 :
233 0 : PlotStandardMouseToolGroupPtr PlotFactory::standardMouseTools(
234 : PlotAxis xAxis,
235 : PlotAxis yAxis,
236 : PlotCoordinate::System sys,
237 : ToolCode activeTool,
238 : bool smartDelete) const {
239 :
240 0 : PlotSelectToolPtr sel = selectTool(xAxis, yAxis, sys);
241 0 : sel->setSelectLine(line("black", PlotLine::SOLID, 1.0));
242 0 : sel->setSubtractLine(line("violet", PlotLine::DASHED, 2.0)); //DSW: if compiles ok, change to #9020C8
243 0 : sel->setRectLine(line("black", PlotLine::SOLID, 1.0));
244 0 : sel->setRectFill(areaFill("black", PlotAreaFill::MESH3));
245 : return PlotStandardMouseToolGroupPtr(new PlotStandardMouseToolGroup(
246 0 : sel, zoomTool(xAxis, yAxis, sys), panTool(xAxis, yAxis, sys),
247 0 : flagAllTool(xAxis, yAxis, sys),
248 0 : trackerTool(xAxis, yAxis, sys), activeTool), smartDelete);
249 : }
250 :
251 0 : PlotSelectToolPtr PlotFactory::selectTool(bool smartDelete) const {
252 0 : return PlotSelectToolPtr(new PlotSelectTool(), smartDelete); }
253 :
254 0 : PlotZoomToolPtr PlotFactory::zoomTool(bool smartDelete) const {
255 0 : return PlotZoomToolPtr(new PlotZoomTool(), smartDelete); }
256 :
257 0 : PlotPanToolPtr PlotFactory::panTool(bool smartDelete) const {
258 0 : return PlotPanToolPtr(new PlotPanTool(), smartDelete); }
259 :
260 0 : PlotFlagAllToolPtr PlotFactory::flagAllTool(bool smartDelete) const {
261 0 : return PlotFlagAllToolPtr(new PlotFlagAllTool(), smartDelete); }
262 :
263 0 : PlotTrackerToolPtr PlotFactory::trackerTool(bool smartDelete) const {
264 0 : return PlotTrackerToolPtr(new PlotTrackerTool(), smartDelete); }
265 :
266 0 : PlotSelectToolPtr PlotFactory::selectTool(PlotAxis xAxis, PlotAxis yAxis,
267 : PlotCoordinate::System system, bool smartDelete) const {
268 0 : return PlotSelectToolPtr(new PlotSelectTool(xAxis, yAxis, system),
269 0 : smartDelete);
270 : }
271 :
272 0 : PlotZoomToolPtr PlotFactory::zoomTool(PlotAxis xAxis, PlotAxis yAxis,
273 : PlotCoordinate::System system, bool smartDelete) const {
274 0 : return PlotZoomToolPtr(new PlotZoomTool(xAxis, yAxis, system),
275 0 : smartDelete);
276 : }
277 :
278 0 : PlotPanToolPtr PlotFactory::panTool(PlotAxis xAxis, PlotAxis yAxis,
279 : PlotCoordinate::System system, bool smartDelete) const {
280 :
281 : (void)smartDelete;
282 0 : return PlotPanToolPtr(new PlotPanTool(xAxis, yAxis, system), false); }
283 :
284 0 : PlotFlagAllToolPtr PlotFactory::flagAllTool(PlotAxis xAxis, PlotAxis yAxis,
285 : PlotCoordinate::System system, bool smartDelete) const {
286 0 : return PlotFlagAllToolPtr(new PlotFlagAllTool(xAxis, yAxis, system),
287 0 : smartDelete);
288 : }
289 :
290 0 : PlotTrackerToolPtr PlotFactory::trackerTool(PlotAxis xAxis, PlotAxis yAxis,
291 : PlotCoordinate::System system, bool smartDelete) const {
292 0 : return PlotTrackerToolPtr(new PlotTrackerTool(xAxis, yAxis, system),
293 0 : smartDelete);
294 : }
295 :
296 :
297 : // Macro for method definitions for PF_DATA_DEC declarations.
298 : #define PF_DATA_DEF(TYPE) \
299 : PlotPointDataPtr PlotFactory::data(TYPE *& y, unsigned int n, \
300 : bool shouldDelete) const { \
301 : return new PlotPointDataImpl< TYPE >(y, n, shouldDelete); } \
302 : \
303 : PlotPointDataPtr PlotFactory::data(Vector< TYPE >& y, \
304 : bool shouldDelete) const { \
305 : return new PlotPointDataImpl< TYPE >(y, shouldDelete); } \
306 : \
307 : PlotPointDataPtr PlotFactory::data(std::vector< TYPE >& y, \
308 : bool shouldDelete) const { \
309 : return new PlotPointDataImpl< TYPE >(y, shouldDelete); } \
310 : \
311 : PlotPointDataPtr PlotFactory::data(TYPE *& x, TYPE *& y, unsigned int n, \
312 : bool shouldDelete) const { \
313 : return new PlotPointDataImpl< TYPE >(x, y, n, shouldDelete); } \
314 : \
315 : PlotPointDataPtr PlotFactory::data(Vector< TYPE >& x, Vector< TYPE >& y, \
316 : bool shouldDelete) const { \
317 : return new PlotPointDataImpl< TYPE >(x, y, shouldDelete); } \
318 : \
319 : PlotPointDataPtr PlotFactory::data(std::vector< TYPE >& x, std::vector< TYPE >& y, \
320 : bool shouldDelete) const { \
321 : return new PlotPointDataImpl< TYPE >(x, y, shouldDelete); } \
322 : \
323 : PlotSingleDataPtr PlotFactory::singleData(TYPE *& data, unsigned int n, \
324 : bool shouldDelete) const { \
325 : return new PlotSingleDataImpl< TYPE >(data, n, shouldDelete); } \
326 : \
327 : PlotSingleDataPtr PlotFactory::singleData(Vector< TYPE >& data, \
328 : bool shouldDelete) const { \
329 : return new PlotSingleDataImpl< TYPE >(data, shouldDelete); } \
330 : \
331 : PlotSingleDataPtr PlotFactory::singleData(std::vector< TYPE >& data, \
332 : bool shouldDelete) const { \
333 : return new PlotSingleDataImpl< TYPE >(data, shouldDelete); } \
334 : \
335 : PlotPointDataPtr PlotFactory::histogramData(TYPE *& data, unsigned int n, \
336 : unsigned int numBins, bool shouldDel) const { \
337 : return new PlotHistogramData(singleData(data, n, shouldDel), numBins); } \
338 : \
339 : PlotPointDataPtr PlotFactory::histogramData(Vector< TYPE >& data, \
340 : unsigned int numBins, bool shouldDel) const { \
341 : return new PlotHistogramData(singleData(data, shouldDel), numBins); } \
342 : \
343 : PlotPointDataPtr PlotFactory::histogramData(std::vector< TYPE >& data, \
344 : unsigned int numBins, bool shouldDel) const { \
345 : return new PlotHistogramData(singleData(data, shouldDel), numBins); } \
346 : \
347 : PlotMaskedPointDataPtr PlotFactory::data(TYPE *& x, TYPE*& y, bool*& mask, \
348 : unsigned int n, bool shouldDelete) const { \
349 : return new PlotMaskedPointDataImpl< TYPE >(x, y, mask, n, shouldDelete); }\
350 : \
351 : PlotMaskedPointDataPtr PlotFactory::data(Vector< TYPE >& x, Vector< TYPE >& y,\
352 : Vector<bool>& mask, bool shouldDelete) const { \
353 : return new PlotMaskedPointDataImpl< TYPE >(x, y, mask, shouldDelete); } \
354 : \
355 : PlotMaskedPointDataPtr PlotFactory::data(std::vector< TYPE >& x, std::vector< TYPE >& y,\
356 : std::vector<bool>& mask, bool shouldDelete) const { \
357 : return new PlotMaskedPointDataImpl< TYPE >(x, y, mask, shouldDelete); } \
358 : \
359 : PlotErrorDataPtr PlotFactory::data(TYPE *& x, TYPE *& y, unsigned int n, \
360 : TYPE xLeftError, TYPE xRightError, TYPE yBottomError, TYPE yTopError, \
361 : bool shouldDelete) const { \
362 : return new PlotScalarErrorDataImpl< TYPE >(x, y, n, xLeftError, \
363 : xRightError, yBottomError, yTopError, shouldDelete); } \
364 : \
365 : PlotErrorDataPtr PlotFactory::data(Vector< TYPE >& x, Vector< TYPE >& y, \
366 : TYPE xLeftError, TYPE xRightError, TYPE yBottomError, TYPE yTopError, \
367 : bool shouldDelete) const { \
368 : return new PlotScalarErrorDataImpl< TYPE >(x, y, xLeftError, \
369 : xRightError, yBottomError, yTopError, shouldDelete); } \
370 : \
371 : PlotErrorDataPtr PlotFactory::data(std::vector< TYPE >& x, std::vector< TYPE >& y, \
372 : TYPE xLeftError, TYPE xRightError, TYPE yBottomError, TYPE yTopError, \
373 : bool shouldDelete) const { \
374 : return new PlotScalarErrorDataImpl< TYPE >(x, y, xLeftError, \
375 : xRightError, yBottomError, yTopError, shouldDelete); } \
376 : \
377 : PlotErrorDataPtr PlotFactory::data(TYPE *& x, TYPE *& y, TYPE *& xLeftError, \
378 : TYPE *& xRightError, TYPE *& yBottomError, TYPE *& yTopError, \
379 : unsigned int n, bool shouldDelete) const { \
380 : return new PlotErrorDataImpl< TYPE >(x, y, xLeftError, xRightError, \
381 : yBottomError, yTopError, n, shouldDelete); } \
382 : \
383 : PlotErrorDataPtr PlotFactory::data(Vector< TYPE >& x, Vector< TYPE >& y, \
384 : Vector< TYPE >& xLeftError, Vector< TYPE >& xRightError, \
385 : Vector< TYPE >& yBottomError, Vector< TYPE >& yTopError, \
386 : bool shouldDelete) const { \
387 : return new PlotErrorDataImpl< TYPE >(x, y, xLeftError, xRightError, \
388 : yBottomError, yTopError, shouldDelete); } \
389 : \
390 : PlotErrorDataPtr PlotFactory::data(std::vector< TYPE >& x, std::vector< TYPE >& y, \
391 : std::vector< TYPE >& xLeftError, std::vector< TYPE >& xRightError, \
392 : std::vector< TYPE >& yBottomError, std::vector< TYPE >& yTopError, \
393 : bool shouldDelete) const { \
394 : return new PlotErrorDataImpl< TYPE >(x, y, xLeftError, xRightError, \
395 : yBottomError, yTopError, shouldDelete); } \
396 : \
397 : PlotRasterDataPtr PlotFactory::data(Matrix< TYPE >& data, \
398 : bool shouldDelete) const { \
399 : return new PlotRasterMatrixData< TYPE >(data, shouldDelete); } \
400 : \
401 : PlotRasterDataPtr PlotFactory::data(Matrix< TYPE >& data, double fromX, \
402 : double toX, double fromY, double toY, bool shouldDelete) const { \
403 : PlotRasterMatrixData< TYPE >* d = new PlotRasterMatrixData< TYPE > ( \
404 : data, shouldDelete); \
405 : d->setXRange(fromX, toX); \
406 : d->setYRange(fromY, toY); \
407 : return d; \
408 : }
409 :
410 0 : PF_DATA_DEF(double)
411 :
412 0 : PF_DATA_DEF(float)
413 :
414 0 : PF_DATA_DEF(int)
415 :
416 0 : PF_DATA_DEF(unsigned int)
417 :
418 0 : PlotPointDataPtr PlotFactory::histogramData(PlotSingleDataPtr data,
419 : unsigned int numBins) const {
420 0 : return new PlotHistogramData(data, numBins); }
421 :
422 : }
|