summaryrefslogtreecommitdiffstats
path: root/tksao/frame/fitsdata.h
blob: b324e5795f8d94715136096e743521aefbaae2ea (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
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#ifndef __fitsdata_h__
#define __fitsdata_h__

#include "base.h"
#include "file.h"

class ColorScale;
class FitsFile;

class FitsBound { 
 public:
  int xmin;
  int xmax;
  int ymin;
  int ymax;

 public:
  FitsBound() {xmin= xmax= ymin= ymax= 0;}
  FitsBound(int x0, int y0, int x1, int y1) 
    {xmin=x0; xmax=x1; ymin=y0; ymax=y1;}
  FitsBound(const FitsBound &bb)
    {xmin=bb.xmin; xmax=bb.xmax; ymin=bb.ymin; ymax=bb.ymax;}
  void set(int x0, int y0, int x1, int y1) {xmin=x0; xmax=x1; ymin=y0; ymax=y1;}
};
ostream& operator<<(ostream&, const FitsBound&);

class FitsData {
protected:
  Tcl_Interp* interp_;

  long width_;
  long height_;
  char buf_[32];

  int byteswap_;

  double bscale_;
  double bzero_;
  int hasscaling_;

  int blank_;
  int hasblank_;

  double min_;         // bscale applied
  Vector minXY_;
  double max_;         // bscale applied
  Vector maxXY_;

  double high_;        // bscale applied
  double low_;         // bscale applied

  float zHigh_;        // bscale applied
  float zLow_;         // bscale applied
  double aLow_;	       // bscale applied		    
  double aHigh_;       // bscale applied		    
  double ulow_;	       // bscale applied		    
  double uhigh_;       // bscale applied		    

  int scanValid_;
  int minmaxSample_;

  float zContrast_;
  int zSample_;
  int zLine_;
  int zscaleValid_;

  int autoCutValid_;
  float autoCutPer_;

  FrScale::ClipMode clipMode_;
  FrScale::MinMaxMode minmaxMode_;
  FrScale::SecMode secMode_;

  double datamin_;      // bscale applied
  double datamax_;      // bscale applied
  int hasdatamin_;

  double irafmin_;      // bscale applied
  double irafmax_;      // bscale applied
  int hasirafmin_;

  // zscale constants

  enum PixelType {GOOD_PIXEL, BAD_PIXEL, REJECT_PIXEL};

  int zSubSample(float*, float*, int, int);
  int zFitLine(float*, int, float*, float*, float, int, int);
  void zFlattenData (float*, float*, float*, int npix, float, float dz);
  int zComputeSigma (float*, short*, int npix, float*, float*);
  int zRejectPixels (float*, float*, float*, short*, int, double*, 
		     double*, double*, double*, float, int);

 protected:
  void autoCut(FitsBound*);
  int calcIncr();

public:
  FitsData(FitsFile*, Tcl_Interp*);
  virtual ~FitsData();

  virtual void* data() =0;
  virtual const char* getValue(const Vector&) =0;
  virtual float getValueFloat(const Vector&) =0;
  virtual double getValueDouble(const Vector&) =0;

  virtual float getValueFloat(long) =0;
  virtual double getValueDouble(long) =0;

  double min();
  const Vector& minXY() {return minXY_;}
  double max();
  const Vector& maxXY() {return maxXY_;}

  const char* getMin();
  const char* getMinX();
  const char* getMinY();
  const char* getMax();
  const char* getMaxX();
  const char* getMaxY();
  const char* getLow();
  const char* getHigh();

  double low() {return low_;}
  double high() {return high_;}

  void setClip(double ll, double hh) {low_ =ll; high_ =hh;}

  virtual void updateClip(FrScale*, FitsBound*) =0;
  int hasDATAMIN() {return hasdatamin_;}
  int hasIRAFMIN() {return hasirafmin_;}

  virtual void hist(double*,int,double,double,FitsBound*) =0;
};

template<class T>
class FitsDatam : public FitsData {
 private:
  T* data_;

  void scan(FitsBound*);
  void output(ostringstream&, T);
  void zscale(FitsBound*);
  int zSampleImage(float**,FitsBound*);

 public:
  FitsDatam(FitsFile*, Tcl_Interp*);

  T swap(T*);

  void* data() {return data_;}
  const char* getValue(const Vector&);

  float getValueFloat(const Vector&);
  double getValueDouble(const Vector&);

  float getValueFloat(long i);
  double getValueDouble(long i);

  void updateClip(FrScale*, FitsBound*);
  void hist(double*, int, double, double, FitsBound*);
};

#endif