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

#include "inversescale.h"
#include "framebase.h"
#include "colorscale.h"

InverseScale::InverseScale(int ss) : size_(ss)
{
  level_ = new double[size_];

  for (int ii=0; ii<size_; ii++)
    level_[ii] = 0;
}

InverseScale::InverseScale(int ss, double* ll) : size_(ss)
{
  level_ = new double[size_];

  for (int ii=0; ii<size_; ii++)
    level_[ii] = ll[ii];
}

InverseScale::~InverseScale()
{
  if (level_)
    delete [] level_;
}

ostream& operator<<(ostream& s, const InverseScale& c)
{
  for (int ii=0; ii<c.size_; ii++)
    if (isfinite(c.level_[ii]))
      s << c.level_[ii] << ' ';
    else
      s << 0 << ' ';
  return s;
}

// Note: this an inverse algorithm. We have y, we need x

LinearInverseScale::LinearInverseScale(int ss, double low, double high) 
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = double(ii)/(size_-1);
    level_[ii] = aa*dd +low;
  }
}

LogInverseScale::LogInverseScale(int ss, double low, double high, double exp) 
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = (::pow(exp,double(ii)/(size_-1)) -1) / exp;
    level_[ii] =  aa*dd  +low;
  }
}

PowInverseScale::PowInverseScale(int ss, double low, double high, double exp) 
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = log10(exp*double(ii)/(size_-1) +1) / log10(exp);
    level_[ii] =  aa*dd  +low;
  }
}

SqrtInverseScale::SqrtInverseScale(int ss, double low, double high) 
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = double(ii)/(size_-1);
    level_[ii] = (aa*aa)*dd +low;
  }
}

SquaredInverseScale::SquaredInverseScale(int ss, double low, double high)
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = sqrt(double(ii)/(size_-1));
    level_[ii] = aa*dd +low;
  }
}

AsinhInverseScale::AsinhInverseScale(int ss, double low, double high)
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = sinh(3*double(ii)/(size_-1))/10;
    level_[ii] = aa*dd +low;
  }
}

SinhInverseScale::SinhInverseScale(int ss, double low, double high)
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = asinh(10*double(ii)/(size_-1))/3;
    level_[ii] = aa*dd +low;
  }
}

HistEquInverseScale::HistEquInverseScale(int ss, double low, double high, 
					 double* hist, int histsize) 
  : InverseScale(ss)
{
  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  if (!hist) {
    for (int ii=0; ii<size_; ii++) {
      double aa = double(ii)/(size_-1);
      level_[ii] = aa*dd +low;
    }
  }
  else {
    for (int ii=0; ii<size_; ii++) {
      double vv = double(ii)/(size_-1);
      int jj=0;
      while (jj<histsize-1) {
	if (hist[jj]>vv)
	  break;
	jj++;
      }
      double aa = double(jj)/histsize;
      level_[ii] = aa*dd +low;
    }
  }
}

IISInverseScale::IISInverseScale(int ss, double low, double high, Vector& iisz) 
  : InverseScale(ss)
{
  low = IISMIN;
  high = IISMAX;

  if (size_==1) {
    level_[0] = high;
    return;
  }

  double dd = high-low;
  for (int ii=0; ii<size_; ii++) {
    double aa = double(ii)/(size_-1);
    double vv = aa*dd +low;

    if (vv == 0)
      level_[ii] = iisz[0];
    else if (vv == IISMIN)
      level_[ii] = iisz[0];
    else if (vv == IISMAX)
      level_[ii] = iisz[1];
    else if (vv > IISMAX)
      level_[ii] = iisz[1];
    else
      level_[ii] = ((vv-IISMIN) * (iisz[1]-iisz[0]))/(IISMAX-IISMIN) + iisz[0];
  }
}