summaryrefslogtreecommitdiffstats
path: root/tksao/frame/context.h
blob: 9a717c8918cc3fbb0b683e1b7ca65006ddd04420 (plain)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#ifndef __context_h__
#define __context_h__

#include <pthread.h>

#include "base.h"
#include "colorscale.h"
#include "coord.h"
#include "frscale.h"
#include "list.h"
#include "fitsimage.h"
#include "head.h"

class FVContour;

class FitsZBound { 
 public:
  int zmin;
  int zmax;

 public:
  FitsZBound() {zmin= zmax=0;}
  FitsZBound(int z0, int z1) {zmin=z0; zmax=z1;}
  FitsZBound(const FitsZBound &bb) {zmin=bb.zmin; zmax=bb.zmax;}
  void set(int z0, int z1) {zmin=z0; zmax=z1;}
};
ostream& operator<<(ostream&, const FitsZBound&);

class Context {
  friend class FitsImage;
  
 public:
  enum SmoothFunction {BOXCAR, TOPHAT, GAUSSIAN, ELLIPTIC};

 protected:
  Base* parent_;

  FrScale frScale;

  int shareWCS_;

  int manageAxes_;
  int axesOrder_;

  int baxis_[FTY_MAXAXES]; // the first two are ignored
  int* naxis_; // the first two are ignored
  int slice_[FTY_MAXAXES]; // the first two are ignored

  int mosaicCount_;
  Base::MosaicType mosaicType;
  Coord::CoordSystem mosaicSystem;

  FitsHist::Function binFunction_;
  Vector binFactor_;
  int binBufferSize_;
  int binDepth_;

  Vector blockFactor_;

  int doSmooth_;
  SmoothFunction smoothFunction_;
  int smoothRadius_;
  int smoothRadiusMinor_;
  double smoothSigma_;
  double smoothSigmaMinor_;
  double smoothAngle_;

  // params in DATA coords 0-n
  FitsZBound iparams; // image bbox
  FitsZBound cparams; // crop bbox

  FVContour fvcontour_;
  List<ContourLevel> auxcontours_;
  int hasContour_;
  int hasAuxContour_;

 protected:
  void binFinish();
  // waj
  //  int blockMask();
  //  void loadFinishMask();
  //  int loadFinishMosaicMask();
  int nhdu();
  void loadFinishMosaic(FitsImage*);
  int processMosaicKeywords(FitsImage*);
  void updateClip(FrScale*);
  void updateClipGlobal(FrScale*);
  void updateClipLocal(FrScale*);

  void contourList(ostream&, Coord::CoordSystem, Coord::SkyFrame, 
		   List<ContourLevel>&);

  void reorderAxis(char*, char**, int, int, int, size_t);
  void reorderThread(void*, char*, void* (void*), int*);

  pthread_t* thread_;

 public:
  FitsImage* bfits_;
  FitsImage* fits;
  FitsImage* cfits;

 public:
  Context();
  ~Context();

  FVContour& fvcontour() {return fvcontour_;}
  List<ContourLevel>& auxcontours() {return auxcontours_;}

  void analysis();
  int axesOrder() {return axesOrder_;}

  Matrix bin(const Vector&);
  Matrix binCenter();
  Matrix binCursor();

  int block();
  void bltHist(char*, char*, int);

  int calcSlice();
  void contourAppendAux(ContourLevel*);
  void contourCreateFV(const char* color, int width, int dash,
		       FVContour::Method method, int numlevel, 
		       int smooth, 
		       FrScale::ColorScaleType colorScaleType,
		       float expo,
		       FrScale::ClipMode clipMode, float,
		       FrScale::ClipScope clipScope, 
		       double low, double high, const char* level);
  void contourDeleteFV();
  void contourDeleteAux();
  void contourListFV(ostream&, Coord::CoordSystem, Coord::SkyFrame);
  void contourListAux(ostream&, Coord::CoordSystem, Coord::SkyFrame);
  void contourLoadAux(istream&);
  void contourLoadAux(istream&, const char*, int, int);
  void contourLoadAux(istream&, Coord::CoordSystem, Coord::SkyFrame, 
		      const char*, int, int);
  void contourPS(Widget::PSColorSpace cs);
  void contourX11(Pixmap, Coord::InternalSystem, const BBox&);
#ifdef MAC_OSX_TK
  void contourMacOSX();
#endif
#ifdef __WIN32
  void contourWin32();
#endif

  void deleteFits(FitsImage*);

  int fitsCount();

  Vector getClip(FrScale::ClipMode, FrScale::ClipScope, float);
  Vector getClip();
  // params in DATA coords 0-n
  FitsZBound* getDataParams(FrScale::SecMode);
  Vector getMinMax();

  int hasContour() {return hasContour_;}
  int hasContourAux() {return hasAuxContour_;}
  double* histequ() {return frScale.histequ(fits);}

  Coord::Orientation IRAFOrientation(Coord::Orientation oo) 
    {return parent_->IRAFOrientation(oo);}
  int isMosaic() {return mosaicCount_>1 ? 1 : 0;}
  int isCube() {return nhdu()>1 ? 1 : 0;}

  int load(Base::MemType, const char*, FitsImage*);
  int loadExtCube(Base::MemType, const char*, FitsImage*);
  int loadSlice(Base::MemType, const char*, FitsImage*);
  int loadMosaic(Base::MemType, const char*, FitsImage*, 
		 Base::MosaicType, Coord::CoordSystem);
  int loadMosaicImage(Base::MemType, const char*, FitsImage*, 
		      Base::MosaicType, Coord::CoordSystem);
  int loadMosaicWFPC2(Base::MemType, const char*, FitsImage*);
  void loadInit(int, Base::MosaicType, Coord::CoordSystem);
  int loadFinish();

  int naxis(int ii) {return naxis_[ii];}
  int naxes();
  int nthreads() {return parent_->nthreads_;}

  void parent(Base* pp) {parent_ = pp;}

  void reorderAxes();
  void reorderWCSi(FitsHead*, char*, int, char);
  void reorderWCSij(FitsHead*, char*, int, char);
  void resetSecMode();

  int slice(int ii) {return slice_[ii];}

  void setAxesOrder(int);
  void setBinFunction(FitsHist::Function f) {binFunction_ = f;}
  void setBinFactor(const Vector&);
  void setBinToFactor(const Vector&);
  void setBinBufferSize(int s) {binBufferSize_ = s;}
  void setBinDepth(int d) {binDepth_ = d < 1 ? 1 : d;}
  FitsHist::Function binFunction() {return binFunction_;}
  Vector binFactor() {return binFactor_;}
  int binBufferSize() {return binBufferSize_;}
  int binDepth() {return binDepth_;}

  Vector setBlockFactor(const Vector&);
  Vector setBlockToFactor(const Vector&);
  const Vector& blockFactor() {return blockFactor_;}

  // params in DATA coords 0-n
  void setCrop3dParams();
  void setCrop3dParams(int,int);
  void setCrop3dParams(double, double);

  void setIIS();
  void resetIIS();

  void setSmooth(int ss) {doSmooth_ =ss;}
  void setSmooth(int, SmoothFunction, int, int, double, double, double);
  // backward compatibility backup
  void setSmooth(int, SmoothFunction, int);
  int hasSmooth() {return doSmooth_;}
  SmoothFunction smoothFunction() {return smoothFunction_;}
  int smoothRadius() {return smoothRadius_;}
  int smoothRadiusMinor() {return smoothRadiusMinor_;}
  double smoothSigma() {return smoothSigma_;}
  double smoothSigmaMinor() {return smoothSigmaMinor_;}
  double smoothAngle() {return smoothAngle_;}

  int shareWCS() {return shareWCS_;}

  void unload();
  void updateBinFileNames();
  void clearHist();
  void updateClip();
  void updateContours();
  void updateContours(const Matrix&);
  void updateSlice(int, int);

  int updateClipScope(FrScale::ClipScope);
  int updateClipMode(FrScale::ClipMode);
  int updateClipMode(float);
  int updateMinMax(FrScale::MinMaxMode, int);
  // backward compatibility backup
  int updateMinMaxMode(FrScale::MinMaxMode);
  // backward compatibility backup
  int updateMinMaxSample(int);
  int updateUser(float,float);
  int updateZscale(float, int, int);
  // backward compatibility backup
  int updateZscaleContrast(float);
  // backward compatibility backup
  int updateZscaleSample(int);
  // backward compatibility backup
  int updateZscaleLine(int);
  int updateDataSec(int);
  int updateExpo(double);

  FrScale::ColorScaleType colorScaleType() {return frScale.colorScaleType();}
  FrScale::ClipScope clipScope() {return frScale.clipScope();}
  FrScale::ClipMode clipMode() {return frScale.clipMode();}
  int datasec() {return frScale.datasec();}
  float expo() {return frScale.expo();}
  double low() {return frScale.low();}
  double high() {return frScale.high();}
  int minmaxSample() {return frScale.minmaxSample();}
  FrScale::MinMaxMode minmaxMode() {return frScale.minmaxMode();}
  FrScale::SecMode secMode() {return frScale.secMode();}
  float autoCutPer() {return frScale.autoCutPer();}
  float zContrast() {return frScale.zContrast();}
  int zSample() {return frScale.zSample();}
  int zLine() {return frScale.zLine();}
  double ulow() {return frScale.ulow();}
  double uhigh() {return frScale.uhigh();}

  void setClipScope(FrScale::ClipScope ss) {frScale.setClipScope(ss);}
  void setColorScaleType(FrScale::ColorScaleType tt)
  {frScale.setColorScaleType(tt);}
  void setSecMode(FrScale::SecMode);

};

#endif