00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ANNOTATIONS_ANNOTATIONBASE_H
00029 #define ANNOTATIONS_ANNOTATIONBASE_H
00030
00031 #include <coordinates/Coordinates/CoordinateSystem.h>
00032
00033 #include <measures/Measures/Stokes.h>
00034
00035 #include <list>
00036
00037 namespace casa {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 class AnnotationBase {
00057 public:
00058
00059 using RGB = vector<float>;
00060
00061
00062 using Direction = Vector<std::pair<Quantity,Quantity> >;
00063
00064 enum Type {
00065
00066 LINE,
00067 VECTOR,
00068 TEXT,
00069 SYMBOL,
00070
00071 RECT_BOX,
00072 CENTER_BOX,
00073 ROTATED_BOX,
00074 POLYGON,
00075 POLYLINE,
00076 CIRCLE,
00077 ANNULUS,
00078 ELLIPSE
00079 };
00080
00081 enum Keyword {
00082 COORD,
00083 RANGE,
00084 FRAME,
00085 CORR,
00086 VELTYPE,
00087 RESTFREQ,
00088 LINEWIDTH,
00089 LINESTYLE,
00090 SYMSIZE,
00091 SYMTHICK,
00092 COLOR,
00093 FONT,
00094 FONTSIZE,
00095 FONTSTYLE,
00096 USETEX,
00097 LABEL,
00098 LABELCOLOR,
00099 LABELPOS,
00100 LABELOFF,
00101 UNKNOWN_KEYWORD,
00102 N_KEYS
00103 };
00104
00105 enum LineStyle {
00106 SOLID,
00107 DASHED,
00108 DOT_DASHED,
00109 DOTTED
00110 };
00111
00112 enum FontStyle {
00113 NORMAL,
00114 BOLD,
00115 ITALIC,
00116 ITALIC_BOLD
00117 };
00118
00119 static const RGB BLACK;
00120 static const RGB BLUE;
00121 static const RGB CYAN;
00122 static const RGB GRAY;
00123 static const RGB GREEN;
00124 static const RGB MAGENTA;
00125 static const RGB ORANGE;
00126 static const RGB RED;
00127 static const RGB WHITE;
00128 static const RGB YELLOW;
00129
00130 static const String DEFAULT_LABEL;
00131 static const RGB DEFAULT_COLOR;
00132 static const LineStyle DEFAULT_LINESTYLE;
00133 static const uInt DEFAULT_LINEWIDTH;
00134 static const uInt DEFAULT_SYMBOLSIZE;
00135 static const uInt DEFAULT_SYMBOLTHICKNESS;
00136 static const String DEFAULT_FONT;
00137 static const uInt DEFAULT_FONTSIZE;
00138 static const FontStyle DEFAULT_FONTSTYLE;
00139 static const Bool DEFAULT_USETEX;
00140 static const RGB DEFAULT_LABELCOLOR;
00141 static const String DEFAULT_LABELPOS;
00142 static const vector<Int> DEFAULT_LABELOFF;
00143
00144 static const Regex rgbHexRegex;
00145
00146 virtual ~AnnotationBase();
00147
00148 Type getType() const;
00149
00150 static LineStyle lineStyleFromString(const String& ls);
00151
00152
00153
00154 static Type typeFromString(const String& type);
00155
00156 static String typeToString(const Type type);
00157
00158 static String keywordToString(const Keyword key);
00159
00160 static String lineStyleToString(const LineStyle linestyle);
00161
00162 static FontStyle fontStyleFromString(const String& fs);
00163
00164 static String fontStyleToString(const FontStyle fs);
00165
00166 void setLabel(const String& label);
00167
00168 String getLabel() const;
00169
00170
00171
00172 void setColor(const String& color);
00173
00174
00175
00176 void setColor(const RGB& color);
00177
00178
00179 String getColorString() const;
00180
00181 static String colorToString(const RGB& color);
00182
00183
00184 RGB getColor() const;
00185
00186 void setLineStyle(const LineStyle lineStyle);
00187
00188 LineStyle getLineStyle() const;
00189
00190 void setLineWidth(const uInt linewidth);
00191
00192 uInt getLineWidth() const;
00193
00194 void setSymbolSize(const uInt symbolsize);
00195
00196 uInt getSymbolSize() const;
00197
00198 void setSymbolThickness(const uInt symbolthickness);
00199
00200 uInt getSymbolThickness() const;
00201
00202 void setFont(const String& font);
00203
00204 String getFont() const;
00205
00206 void setFontSize(const uInt fontsize);
00207
00208 uInt getFontSize() const;
00209
00210 void setFontStyle(const FontStyle& fontstyle);
00211
00212 FontStyle getFontStyle() const;
00213
00214 void setUseTex(const Bool usetex);
00215
00216 Bool isUseTex() const;
00217
00218
00219 virtual Bool isRegion() const;
00220
00221
00222
00223 inline virtual Bool isAnnotationOnly() const { return True; }
00224
00225
00226
00227 static void unitInit();
00228
00229
00230
00231 void setLabelColor(const String& color);
00232
00233
00234
00235 void setLabelColor(const RGB& color);
00236
00237
00238
00239 String getLabelColorString() const;
00240
00241
00242 RGB getLabelColor() const;
00243
00244
00245 String getLabelPosition() const;
00246
00247
00248
00249 void setLabelPosition(const String& position);
00250
00251
00252 void setLabelOffset(const vector<Int>& offset);
00253
00254 vector<Int> getLabelOffset() const;
00255
00256 virtual ostream& print(ostream &os) const = 0;
00257
00258
00259
00260
00261
00262 void setGlobals(const Vector<Keyword>& globalKeys);
00263
00264
00265 static ostream& print(
00266 ostream& os, const map<Keyword, String>& params
00267 );
00268
00269
00270 static ostream& print(
00271 ostream& os, const LineStyle ls
00272 );
00273
00274
00275 static ostream& print(
00276 ostream& os, const FontStyle fs
00277 );
00278
00279 static ostream& print(
00280 ostream& os, const Direction d
00281 );
00282
00283
00284 static std::list<std::string> colorChoices();
00285
00286
00287
00288
00289 inline const CoordinateSystem& getCsys() const {
00290 return _csys;
00291 }
00292
00293
00294
00295
00296
00297 Direction getDirections() const;
00298
00299
00300
00301
00302 Vector<MFrequency> getFrequencyLimits() const;
00303
00304
00305
00306 Vector<Stokes::StokesTypes> getStokes() const;
00307
00308
00309
00310
00311
00312
00313 virtual Bool setFrequencyLimits(
00314 const Quantity& beginFreq,
00315 const Quantity& endFreq,
00316 const String& freqRefFrame,
00317 const String& dopplerString,
00318 const Quantity& restfreq
00319 );
00320
00321
00322 inline const Vector<MDirection>& getConvertedDirections() const {
00323 return _convertedDirections;
00324 }
00325
00326 protected:
00327
00328
00329
00330
00331 AnnotationBase(
00332 const Type type, const String& dirRefFrameString,
00333 const CoordinateSystem& csys, const Quantity& beginFreq,
00334 const Quantity& endFreq,
00335 const String& freqRefFrame,
00336 const String& dopplerString,
00337 const Quantity& restfreq,
00338 const Vector<Stokes::StokesTypes>& stokes
00339 );
00340
00341
00342
00343
00344 AnnotationBase(
00345 const Type type, const CoordinateSystem& csys,
00346 const Vector<Stokes::StokesTypes>& stokes
00347 );
00348
00349
00350
00351
00352
00353 AnnotationBase& operator= (const AnnotationBase& other);
00354
00355 static void _checkMixed(
00356 const String& origin,
00357 const Direction& dirs
00358 );
00359
00360 MDirection _directionFromQuantities(
00361 const Quantity& q0, const Quantity& q1
00362 );
00363
00364 void _checkAndConvertDirections(
00365 const String& origin,
00366 const Direction& dirs
00367 );
00368
00369 virtual void _printPairs(ostream& os) const;
00370
00371
00372
00373 inline const IPosition& _getDirectionAxes() const {
00374 return _directionAxes;
00375 }
00376
00377
00378
00379 String _printDirection(
00380 const Quantity& longitude, const Quantity& latitude
00381 ) const;
00382
00383
00384 static String _toArcsec(const Quantity& angle);
00385
00386
00387 static String _toDeg(const Quantity& angle);
00388
00389 inline void _setParam(const Keyword k, const String& s) {
00390 _params[k] = s;
00391 }
00392
00393
00394 static String _printPixel(const Double& d);
00395
00396 MDirection::Types _getDirectionRefFrame() const { return _directionRefFrame; }
00397
00398 private:
00399 Type _type;
00400 MDirection::Types _directionRefFrame;
00401 CoordinateSystem _csys;
00402 IPosition _directionAxes;
00403 String _label, _font, _labelPos;
00404 RGB _color, _labelColor;
00405 FontStyle _fontstyle;
00406 LineStyle _linestyle;
00407 uInt _fontsize, _linewidth, _symbolsize,
00408 _symbolthickness;
00409 Bool _usetex;
00410 Vector<MDirection> _convertedDirections;
00411 Vector<MFrequency> _convertedFreqLimits;
00412 Quantity _beginFreq, _endFreq, _restFreq;
00413 Vector<Stokes::StokesTypes> _stokes;
00414 MFrequency::Types _freqRefFrame;
00415 MDoppler::Types _dopplerType;
00416
00417 map<Keyword, Bool> _globals;
00418 map<Keyword, String> _params;
00419 Bool _printGlobals;
00420 vector<Int> _labelOff;
00421
00422 static Bool _doneUnitInit, _doneColorInit;
00423 static map<String, LineStyle> _lineStyleMap;
00424 static map<String, Type> _typeMap;
00425 static map<string, RGB> _colors;
00426 static map<RGB, string> _rgbNameMap;
00427 static std::list<std::string> _colorNames;
00428
00429 const static String _class;
00430
00431 void _init();
00432 void _initParams();
00433
00434 static void _initColors();
00435
00436 static RGB _colorStringToRGB(const String& s);
00437
00438 static Bool _isRGB(const RGB& rgb);
00439
00440 void _testConvertToPixel() const;
00441
00442 static void _initTypeMap();
00443
00444 void _checkAndConvertFrequencies();
00445
00446 String _printFreqRange() const;
00447
00448 static String _printFreq(const Quantity& freq);
00449
00450 };
00451
00452 inline ostream &operator<<(ostream& os, const AnnotationBase& annotation) {
00453 return annotation.print(os);
00454 };
00455
00456 inline ostream &operator<<(ostream& os, const AnnotationBase::LineStyle& ls) {
00457 return AnnotationBase::print(os, ls);
00458 };
00459
00460 inline ostream &operator<<(ostream& os, const AnnotationBase::FontStyle& fs) {
00461 return AnnotationBase::print(os, fs);
00462 };
00463
00464 inline ostream &operator<<(ostream& os, const map<AnnotationBase::Keyword, String>& x) {
00465 return AnnotationBase::print(os, x);
00466 };
00467
00468 inline ostream &operator<<(ostream& os, const AnnotationBase::Direction x) {
00469 return AnnotationBase::print(os, x);
00470 };
00471
00472
00473 class WorldToPixelConversionError : public AipsError {
00474 public:
00475 WorldToPixelConversionError(String msg) : AipsError(msg) {}
00476 };
00477
00478 }
00479
00480 #endif