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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
|
/*
* fractal_addend_function.h -- part of FractalNow
*
* Copyright (c) 2012 Marc Pegon <pe.marc@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* \file fractal_addend_function.h
* \brief Header file related to fractal addend functions.
* \author Marc Pegon
*/
#ifndef __FRACTAL_ADDEND_FUNCTION_H__
#define __FRACTAL_ADDEND_FUNCTION_H__
#include "float_precision.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* \enum e_AddendFunction
* \brief Fractal addend function.
*
* Addend functions are used to compute values of fractal
* in case of average coloring (CM_AVERAGECOLORING).
*
* Addend functions are described by a sequence of instructions
* at the initialization of the fractal loop, for each iteration,
* and at the end of the fractal loop.\n
* They take for parameter 'size' the number of average sums to
* be computed. Those sums SN[0], SN[1], ..., SN[size-1] *must*
* be computed (at least initialized) by the addend function,
* since they will be used by the interpolation method.
*
* Remark : in the fractal "literature", addend functions
* are not exactly the functions *that compute* the average
* sums, but functions *used* when computing those sums.\n
* Remark 2 : some sums might not be computable if the number of
* iterations (in orbit) is too small (N must be >= size).
*/
/**
* \typedef AddendFunction
* \brief Convenient typedef for enum AddendFunction.
*/
typedef enum e_AddendFunction {
AF_TRIANGLEINEQUALITY = 0,
AF_CURVATURE,
AF_STRIPE
} AddendFunction;
/**
* \var nbAddendFunctions
* \brief Number of addend functions.
*/
extern const uint_fast32_t nbAddendFunctions;
/**
* \var addendFunctionStr
* \brief Strings of addend function enum values.
*/
extern const char *addendFunctionStr[];
/**
* \var addendFunctionDescStr
* \brief More descriptive strings for addend functions.
*/
extern const char *addendFunctionDescStr[];
/**
* \fn int GetAddendFunction(AddendFunction *addendFunction, const char *str)
* \brief Get addend function from string.
*
* Function is case insensitive.
* Possible strings are :
* - "triangleinequality" for triangle inequality
* - "curvature" for curvature
* - "stripe" for stripe
*
* \param addendFunction AddendFunction destination.
* \param str String specifying addend function.
* \return 0 in case of success, 1 in case of failure.
*/
int GetAddendFunction(AddendFunction *addendFunction, const char *str);
/******************AF_TRIANGLEINEQUALITY******************/
#define ENGINE_DECL_VAR_AF_TRIANGLEINEQUALITY(size,fprec) \
FLOATTYPE(fprec) shiftSN_AF[size];\
uint_fast32_t zeros_AF[size];\
uint_fast32_t shiftZeros_AF[size];\
COMPLEX_FLOATTYPE(fprec) prevZP_AF;\
FLOATTYPE(fprec) nPrevZP_AF;\
FLOATTYPE(fprec) mn_AF;\
FLOATTYPE(fprec) Mn_AF;\
FLOATTYPE(fprec) rn_AF;\
FLOATTYPE(fprec) diff_AF;\
FLOATTYPE(fprec) absC_AF;\
FLOATTYPE(fprec) tmp_AF;\
uint_fast32_t currentIndex_AF;\
uint_fast32_t previousIndex_AF;
#define ENGINE_INIT_VAR_AF_TRIANGLEINEQUALITY(size,fprec) \
for (uint_fast32_t i = 0; i < size; ++i) {\
initF(fprec,data->shiftSN_AF[i]);\
}\
cinitF(fprec,data->prevZP_AF);\
initF(fprec,data->nPrevZP_AF);\
initF(fprec,data->mn_AF);\
initF(fprec,data->Mn_AF);\
initF(fprec,data->rn_AF);\
initF(fprec,data->diff_AF);\
initF(fprec,data->absC_AF);\
initF(fprec,data->tmp_AF);
#define ENGINE_CLEAR_VAR_AF_TRIANGLEINEQUALITY(size,fprec) \
for (uint_fast32_t i = 0; i < size; ++i) {\
clearF(fprec,data->shiftSN_AF[i]);\
}\
cclearF(fprec,data->prevZP_AF);\
clearF(fprec,data->nPrevZP_AF);\
clearF(fprec,data->mn_AF);\
clearF(fprec,data->Mn_AF);\
clearF(fprec,data->rn_AF);\
clearF(fprec,data->diff_AF);\
clearF(fprec,data->absC_AF);\
clearF(fprec,data->tmp_AF);
#define LOOP_INIT_AF_TRIANGLEINEQUALITY(size,fprec) \
cfromUiF(fprec, data->prevZP_AF, 0);\
fromUiF(fprec, data->nPrevZP_AF, 0);\
fromUiF(fprec, data->mn_AF, 0);\
fromUiF(fprec, data->Mn_AF, 0);\
fromUiF(fprec, data->rn_AF, 0);\
fromUiF(fprec, data->diff_AF, 0);\
cabsF(fprec,data->absC_AF,data->c);\
data->currentIndex_AF = 0;\
data->previousIndex_AF = size-1;\
for (uint_fast32_t i = 0; i < size; ++i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
data->zeros_AF[i] = 0;\
}
#define LOOP_ITERATION_AF_TRIANGLEINEQUALITY(size,fprec) \
{\
uint_fast32_t m = 1;\
if (data->n >= m) {\
csubF(fprec,data->prevZP_AF,data->z,data->c);\
cabsF(fprec,data->nPrevZP_AF,data->prevZP_AF);\
subF(fprec,data->mn_AF,data->nPrevZP_AF,data->absC_AF);\
fabsF(fprec,data->mn_AF,data->mn_AF);\
addF(fprec,data->Mn_AF,data->nPrevZP_AF,data->absC_AF);\
sqrtF(fprec,data->rn_AF,data->normZ);\
subF(fprec,data->diff_AF,data->Mn_AF,data->mn_AF);\
data->zeros_AF[data->currentIndex_AF] = data->zeros_AF[data->previousIndex_AF];\
if (!eq_uiF(fprec,data->diff_AF,0)) {\
/* Avoid division by zero. */\
subF(fprec,data->tmp_AF,data->rn_AF,data->mn_AF);\
divF(fprec,data->tmp_AF,data->tmp_AF,data->diff_AF);\
addF(fprec,data->SN_IM[data->currentIndex_AF],data->SN_IM[data->previousIndex_AF],data->tmp_AF);\
} else {\
assignF(fprec, data->SN_IM[data->currentIndex_AF], data->SN_IM[data->previousIndex_AF]);\
/* Counting zeros in order to divide by*/\
/* the exact number of terms added to SN.*/\
++data->zeros_AF[data->currentIndex_AF];\
}\
data->previousIndex_AF = data->currentIndex_AF;\
data->currentIndex_AF = (data->currentIndex_AF + 1) % size;\
}\
}
#define LOOP_END_AF_TRIANGLEINEQUALITY(size,fprec) \
{\
uint_fast32_t m = 1;\
if (data->n >= m+size-1) {\
for (uint_fast32_t i = 0; i < size; ++i) {\
assignF(fprec, data->shiftSN_AF[i], data->SN_IM[i]);\
data->shiftZeros_AF[i] = data->zeros_AF[i];\
}\
for (uint_fast32_t i = 0; i < size; ++i) {\
data->zeros_AF[i] = data->shiftZeros_AF[(data->previousIndex_AF+size-i) % size];\
if (data->zeros_AF[i] == data->n+1-m-i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
} else {\
div_uiF(fprec, data->SN_IM[i], data->shiftSN_AF[(data->previousIndex_AF+size-i) %\
size], data->n+1-m-i-data->zeros_AF[i]);\
}\
}\
} else {\
/* Result undefined. 0 chosen. */\
for (uint_fast32_t i = 0; i < size; ++i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
}\
}\
}
/*********************************************************/
/***********************AF_CURVATURE**********************/
#define ENGINE_DECL_VAR_AF_CURVATURE(size,fprec) \
FLOATTYPE(fprec) shiftSN_AF[size];\
uint_fast32_t zeros_AF[size];\
uint_fast32_t shiftZeros_AF[size];\
COMPLEX_FLOATTYPE(fprec) znm1_AF;\
COMPLEX_FLOATTYPE(fprec) znm2_AF;\
COMPLEX_FLOATTYPE(fprec) diff_AF;\
COMPLEX_FLOATTYPE(fprec) ctmp_AF;\
FLOATTYPE(fprec) tmp_AF;\
uint_fast32_t currentIndex_AF;\
uint_fast32_t previousIndex_AF;
#define ENGINE_INIT_VAR_AF_CURVATURE(size,fprec) \
for (uint_fast32_t i = 0; i < size; ++i) {\
initF(fprec, data->shiftSN_AF[i]);\
}\
cinitF(fprec, data->znm1_AF);\
cinitF(fprec, data->znm2_AF);\
cinitF(fprec, data->diff_AF);\
cinitF(fprec, data->ctmp_AF);\
initF(fprec, data->tmp_AF);
#define ENGINE_CLEAR_VAR_AF_CURVATURE(size,fprec) \
cclearF(fprec, data->znm1_AF);\
cclearF(fprec, data->znm2_AF);\
cclearF(fprec, data->diff_AF);\
cclearF(fprec, data->ctmp_AF);\
clearF(fprec, data->tmp_AF);\
for (uint_fast32_t i = 0; i < size; ++i) {\
clearF(fprec, data->shiftSN_AF[i]);\
}
#define LOOP_INIT_AF_CURVATURE(size,fprec) \
cfromUiF(fprec, data->znm1_AF, 0);\
cfromUiF(fprec, data->znm2_AF, 0);\
cfromUiF(fprec, data->diff_AF, 0);\
data->currentIndex_AF = 0;\
data->previousIndex_AF = size-1;\
for (uint_fast32_t i = 0; i < size; ++i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
data->zeros_AF[i] = 0;\
}
#define LOOP_ITERATION_AF_CURVATURE(size,fprec) \
{\
uint_fast32_t m = 1;\
if (data->n >= m+1) {\
csubF(fprec,data->diff_AF,data->znm1_AF,data->znm2_AF);\
data->zeros_AF[data->currentIndex_AF] = data->zeros_AF[data->previousIndex_AF];\
if (!ceq_siF(fprec,data->diff_AF,0)) {\
/* Avoid division by zero. */\
csubF(fprec,data->ctmp_AF,data->z,data->znm1_AF);\
cdivF(fprec,data->ctmp_AF,data->ctmp_AF,data->diff_AF);\
cargF(fprec,data->tmp_AF,data->ctmp_AF);\
fabsF(fprec,data->tmp_AF,data->tmp_AF);\
addF(fprec,data->SN_IM[data->currentIndex_AF],data->SN_IM[data->previousIndex_AF],data->tmp_AF);\
} else {\
assignF(fprec,data->SN_IM[data->currentIndex_AF],data->SN_IM[data->previousIndex_AF]);\
/* Counting zeros in order to divide by*/\
/* the exact number of terms added to SN.*/\
++data->zeros_AF[data->currentIndex_AF];\
}\
data->previousIndex_AF = data->currentIndex_AF;\
data->currentIndex_AF = (data->currentIndex_AF + 1) % size;\
}\
cassignF(fprec, data->znm2_AF, data->znm1_AF);\
cassignF(fprec, data->znm1_AF, data->z);\
}
#define LOOP_END_AF_CURVATURE(size,fprec) \
{\
uint_fast32_t m = 1;\
if (data->n >= m+size) {\
for (uint_fast32_t i = 0; i < size; ++i) {\
assignF(fprec, data->shiftSN_AF[i], data->SN_IM[i]);\
data->shiftZeros_AF[i] = data->zeros_AF[i];\
}\
for (uint_fast32_t i = 0; i < size; ++i) {\
data->zeros_AF[i] = data->shiftZeros_AF[(data->previousIndex_AF+size-i) % size];\
if (data->zeros_AF[i] == data->n-m-i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
} else {\
div_uiF(fprec, data->SN_IM[i], data->shiftSN_AF[(data->previousIndex_AF+size-i) %\
size], data->n-m-i-data->zeros_AF[i]);\
}\
}\
} else {\
/* Result undefined. 0 chosen. */\
for (uint_fast32_t i = 0; i < size; ++i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
}\
}\
}
/*********************************************************/
/************************AF_STRIPE************************/
#define ENGINE_DECL_VAR_AF_STRIPE(size,fprec) \
uint_fast32_t currentIndex_AF ;\
uint_fast32_t previousIndex_AF;\
FLOATTYPE(fprec) tmp_AF ;\
FLOATTYPE(fprec) shiftSN_AF[size];
#define ENGINE_INIT_VAR_AF_STRIPE(size,fprec) \
initF(fprec, data->tmp_AF);\
for (uint_fast32_t i = 0; i < size; ++i) {\
initF(fprec, data->shiftSN_AF[i]);\
}
#define ENGINE_CLEAR_VAR_AF_STRIPE(size,fprec) \
clearF(fprec,data->tmp_AF);\
for (uint_fast32_t i = 0; i < size; ++i) {\
clearF(fprec, data->shiftSN_AF[i]);\
}
#define LOOP_INIT_AF_STRIPE(size,fprec) \
data->currentIndex_AF = 0;\
data->previousIndex_AF = size-1;\
for (uint_fast32_t i = 0; i < size; ++i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
}
#define LOOP_ITERATION_AF_STRIPE(size,fprec) \
{\
uint_fast32_t m = 1;\
if (data->n >= m) {\
cargF(fprec,data->tmp_AF,data->z);\
mul_dF(fprec,data->tmp_AF,data->tmp_AF,render->stripeDensity);\
sinF(fprec,data->tmp_AF,data->tmp_AF);\
add_uiF(fprec,data->tmp_AF,data->tmp_AF,1);\
addF(fprec,data->SN_IM[data->currentIndex_AF],data->SN_IM[data->previousIndex_AF],data->tmp_AF);\
data->previousIndex_AF = data->currentIndex_AF;\
data->currentIndex_AF = (data->currentIndex_AF + 1) % size;\
}\
}
#define LOOP_END_AF_STRIPE(size,fprec) \
{\
uint_fast32_t m = 1;\
if (data->n >= m+size-1) {\
for (uint_fast32_t i = 0; i < size; ++i) {\
assignF(fprec, data->shiftSN_AF[i], data->SN_IM[i]);\
}\
for (uint_fast32_t i = 0; i < size; ++i) {\
div_uiF(fprec, data->SN_IM[i], data->shiftSN_AF[(data->previousIndex_AF+size-i) %\
size], 2*(data->n+1-m-i));\
}\
} else {\
/* Result undefined. 0 chosen. */\
for (uint_fast32_t i = 0; i < size; ++i) {\
fromUiF(fprec, data->SN_IM[i], 0);\
}\
}\
}
/*********************************************************/
#ifdef __cplusplus
}
#endif
#endif
|