Krita Source Code Documentation
Loading...
Searching...
No Matches
nugrid.h File Reference

Go to the source code of this file.

Classes

struct  center_grid
 
struct  log_grid
 
struct  NUgrid
 

Enumerations

enum  grid_type { LINEAR , GENERAL , CENTER , LOG }
 

Functions

NUgridcreate_center_grid (double start, double end, double ratio, int num_points)
 
NUgridcreate_general_grid (double *points, int num_points)
 
NUgridcreate_log_grid (double start, double end, int num_points)
 
void destroy_grid (NUgrid *grid)
 

Enumeration Type Documentation

◆ grid_type

enum grid_type
Enumerator
LINEAR 
GENERAL 
CENTER 
LOG 

Definition at line 26 of file nugrid.h.

grid_type
Definition nugrid.h:26
@ CENTER
Definition nugrid.h:26
@ GENERAL
Definition nugrid.h:26
@ LOG
Definition nugrid.h:26
@ LINEAR
Definition nugrid.h:26

Function Documentation

◆ create_center_grid()

NUgrid * create_center_grid ( double start,
double end,
double ratio,
int num_points )

Definition at line 83 of file nugrid.cpp.

85{
86 center_grid *grid = new center_grid;
87 if (grid != NULL) {
88 assert (ratio > 1.0);
89 grid->start = start;
90 grid->end = end;
91 grid->center = 0.5*(start + end);
92 grid->num_points = num_points;
93 grid->half_points = num_points/2;
94 grid->odd = ((num_points % 2) == 1);
95 grid->b = log(ratio) / (double)(grid->half_points-1);
96 grid->bInv = 1.0/grid->b;
97 grid->points = new double[num_points];
98 if (grid->odd) {
99 grid->even_half = 0.0;
100 grid->odd_one = 1;
101 grid->a = 0.5*(end-start)/expm1(grid->b*grid->half_points);
102 grid->aInv = 1.0/grid->a;
103 for (int i=-grid->half_points; i<=grid->half_points; i++) {
104 double sign;
105 if (i<0)
106 sign = -1.0;
107 else
108 sign = 1.0;
109 grid->points[i+grid->half_points] =
110 sign * grid->a*expm1(grid->b*abs(i))+grid->center;
111 }
112 }
113 else {
114 grid->even_half = 0.5;
115 grid->odd_one = 0;
116 grid->a =
117 0.5*(end-start)/expm1(grid->b*(-0.5+grid->half_points));
118 grid->aInv = 1.0/grid->a;
119 for (int i=-grid->half_points; i<grid->half_points; i++) {
120 double sign;
121 if (i<0) sign = -1.0;
122 else sign = 1.0;
123 grid->points[i+grid->half_points] =
124 sign * grid->a*expm1(grid->b*fabs(0.5+i)) + grid->center;
125 }
126 }
128 grid->code = CENTER;
129 }
130 return (NUgrid*) grid;
131}
Point abs(const Point &pt)
int center_grid_reverse_map(void *gridptr, double x)
Definition nugrid.cpp:32
int odd_one
Definition nugrid.h:55
double end
Definition nugrid.h:48
grid_type code
Definition nugrid.h:47
int(* reverse_map)(void *grid, double x)
Definition nugrid.h:51
double a
Definition nugrid.h:54
double *restrict points
Definition nugrid.h:49
int num_points
Definition nugrid.h:50
int half_points
Definition nugrid.h:55
double even_half
Definition nugrid.h:54
double b
Definition nugrid.h:54
double center
Definition nugrid.h:54
double aInv
Definition nugrid.h:54
bool odd
Definition nugrid.h:56
double bInv
Definition nugrid.h:54
double start
Definition nugrid.h:48

◆ create_general_grid()

NUgrid * create_general_grid ( double * points,
int num_points )

Definition at line 155 of file nugrid.cpp.

156{
157 NUgrid* grid = new NUgrid;
158 if (grid != NULL) {
160 grid->code = GENERAL;
161 grid->points = new double[num_points];
162 grid->start = points[0];
163 grid->end = points[num_points-1];
164 grid->num_points = num_points;
165 for (int i=0; i<num_points; i++)
166 grid->points[i] = points[i];
167 grid->code = GENERAL;
168 }
169 return grid;
170}
int general_grid_reverse_map(void *gridptr, double x)
Definition nugrid.cpp:57
int(* reverse_map)(void *grid, double x)
Definition nugrid.h:36
int num_points
Definition nugrid.h:35
double end
Definition nugrid.h:33
double start
Definition nugrid.h:33
grid_type code
Definition nugrid.h:32
double *restrict points
Definition nugrid.h:34

◆ create_log_grid()

NUgrid * create_log_grid ( double start,
double end,
int num_points )

Definition at line 135 of file nugrid.cpp.

137{
138 log_grid *grid = new log_grid;
139 grid->code = LOG;
140 grid->start = start;
141 grid->end = end;
142 grid->num_points = num_points;
143 grid->points = new double[num_points];
144 grid->a = 1.0/(double)(num_points-1)*log(end/start);
145 grid->ainv = 1.0/grid->a;
146 grid->startinv = 1.0/start;
147 for (int i=0; i<num_points; i++)
148 grid->points[i] = start*exp(grid->a*(double)i);
150 return (NUgrid*) grid;
151}
int log_grid_reverse_map(void *gridptr, double x)
Definition nugrid.cpp:43
double startinv
Definition nugrid.h:70
double a
Definition nugrid.h:70
int(* reverse_map)(void *grid, double x)
Definition nugrid.h:67
double start
Definition nugrid.h:64
grid_type code
Definition nugrid.h:63
int num_points
Definition nugrid.h:66
double ainv
Definition nugrid.h:70
double *restrict points
Definition nugrid.h:65
double end
Definition nugrid.h:64

References log_grid::a, log_grid::ainv, log_grid::code, log_grid::end, LOG, log_grid_reverse_map(), log_grid::num_points, log_grid::points, log_grid::reverse_map, log_grid::start, and log_grid::startinv.

◆ destroy_grid()

void destroy_grid ( NUgrid * grid)

Definition at line 173 of file nugrid.cpp.

174{
175 delete[] grid->points;
176 delete grid;
177}

References NUgrid::points.