87 Key(
const Key &origin,
int dim,
int direction)
89 for(
int i = 0;
i < KD;
i++)
key[
i] = origin.
key[
i] + direction;
90 key[dim] = origin.
key[dim] - direction * KD;
106 for(
int i = 0;
i < KD;
i++)
116 if(
hash != other.
hash)
return false;
117 for(
int i = 0;
i < KD;
i++)
119 if(
key[
i] != other.
key[
i])
return false;
136 for(
int i = 0;
i < VD;
i++)
148 for(
int i = 0;
i < VD;
i++) val[
i] = 0;
163 for(
int i = 0;
i < VD;
i++)
171 for(
int i = 0;
i < VD;
i++)
179 for(
int i = 0;
i < VD;
i++)
187 for(
int i = 0;
i < VD;
i++)
195 for(
int i = 0;
i < VD;
i++)
269 if(!create)
return -1;
296 return (offset < 0) ? nullptr :
values + offset;
324 for(
size_t i = 0;
i < oldCapacity;
i++)
326 if(
entries[
i].keyIdx == -1)
continue;
328 while(newEntries[
h].keyIdx != -1)
377 float *scaleFactorTmp =
new float[D];
378 int *canonicalTmp =
new int[(D + 1) * (D + 1)];
385 for(
int i = 0;
i <= D;
i++)
387 for(
int j = 0; j <= D -
i; j++) canonicalTmp[
i * (D + 1) + j] =
i;
388 for(
int j = D -
i + 1; j <= D; j++) canonicalTmp[
i * (D + 1) + j] =
i - (D + 1);
393 for(
int i = 0;
i < D;
i++)
396 scaleFactorTmp[
i] = 1.0f / (sqrtf((
float)(
i + 1) * (
i + 2)));
410 scaleFactorTmp[
i] *= (D + 1) * sqrtf(2.0 / 3);
432 float elevated[D + 1];
435 float barycentric[D + 2];
440 for(
int i = D - 1;
i > 0;
i--)
446 constexpr float scale = 1.0f / (D + 1);
450 for(
int i = 0;
i <= D;
i++)
452 float v = elevated[
i] * scale;
453 float up = ceilf(
v) * (D + 1);
454 float down = floorf(
v) * (D + 1);
456 if(up - elevated[
i] < elevated[
i] - down)
467 memset(rank, 0,
sizeof rank);
468 for(
int i = 0;
i < D;
i++)
469 for(
int j =
i + 1; j <= D; j++)
470 if(elevated[
i] - greedy[
i] < elevated[j] - greedy[j])
479 for(
int i = 0;
i <= D;
i++)
481 if(rank[
i] >= D + 1 - sum)
484 rank[
i] += sum - (D + 1);
494 for(
int i = 0;
i <= D;
i++)
499 rank[
i] += (D + 1) + sum;
507 memset(barycentric, 0,
sizeof barycentric);
508 for(
int i = 0;
i <= D;
i++)
510 barycentric[D - rank[
i]] += (elevated[
i] - greedy[
i]) * scale;
511 barycentric[D + 1 - rank[
i]] -= (elevated[
i] - greedy[
i]) * scale;
513 barycentric[0] += 1.0f + barycentric[D + 1];
517 for(
int remainder = 0; remainder <= D; remainder++)
521 for(
int i = 0;
i < D;
i++)
key.key[
i] = greedy[
i] +
canonical[remainder * (D + 1) + rank[
i]];
528 val->
add(
value, barycentric[remainder]);
532 replay[replay_index].
weight[remainder] = barycentric[remainder];
549 while(total_entries >
hashTables[0].maxFill())
556 int **offset_remap =
new int *[
nThreads];
562 offset_remap[
i] =
new int[filled];
563 for(
int j = 0; j < filled; j++)
566 val->
add(oldVals[j]);
576 for(
int dim = 0; dim <= D; dim++)
581 for(
int i = 1;
i <
nThreads;
i++)
delete[] offset_remap[
i];
582 delete[] offset_remap;
589 void slice(
float *col,
size_t replay_index)
const
594 for(
int i = 0;
i <= D;
i++)
596 base[
r.offset[
i]].
addTo(col,
r.weight[
i]);
606 const Value *hashTableBase = oldValue;
608 const Value zero{ 0 };
611 for(
int j = 0; j <= D; j++)
614#pragma omp parallel for shared(j, oldValue, newValue)
621 Key neighbor1(
key, j, +1);
622 Key neighbor2(
key, j, -1);
624 const Value *oldVal = oldValue +
i;
627 vm1 = vm1 ? vm1 - hashTableBase + oldValue : &zero;
630 vp1 = vp1 ? vp1 - hashTableBase + oldValue : &zero;
633 newValue[
i].
mix(vm1, oldVal, vp1);
635 std::swap(newValue, oldValue);
640 if(oldValue != hashTableBase)
void init(dt_imageio_module_format_t *self)
Definition avif.c:151
int position()
Definition backgroundjobs.c:82
Definition Permutohedral.h:80
HashTablePermutohedral(const HashTablePermutohedral &)=delete
const Key * getKeys() const
Definition Permutohedral.h:243
unsigned long capacity_bits
Definition Permutohedral.h:349
int size() const
Definition Permutohedral.h:232
HashTablePermutohedral & operator=(const HashTablePermutohedral &)=delete
~HashTablePermutohedral()
Definition Permutohedral.h:222
Value * values
Definition Permutohedral.h:346
HashTablePermutohedral()
Definition Permutohedral.h:210
Key * keys
Definition Permutohedral.h:345
size_t capacity
Definition Permutohedral.h:348
Entry * entries
Definition Permutohedral.h:347
size_t filled
Definition Permutohedral.h:348
size_t maxFill() const
Definition Permutohedral.h:237
Value * lookup(const Key &k, bool create=true)
Definition Permutohedral.h:293
void grow(int order=1)
Definition Permutohedral.h:300
Value * getValues() const
Definition Permutohedral.h:249
int lookupOffset(const Key &key, bool create=true)
Definition Permutohedral.h:259
Definition Permutohedral.h:361
void slice(float *col, size_t replay_index) const
Definition Permutohedral.h:589
struct PermutohedralLattice::ReplayEntry * replay
HashTable::Value Value
Definition Permutohedral.h:366
const float * scaleFactor
Definition Permutohedral.h:654
PermutohedralLattice(size_t nData_, int nThreads_=1)
Definition Permutohedral.h:374
int nThreads
Definition Permutohedral.h:653
PermutohedralLattice(const PermutohedralLattice &)=delete
void blur() const
Definition Permutohedral.h:601
~PermutohedralLattice()
Definition Permutohedral.h:419
void merge_splat_threads()
Definition Permutohedral.h:537
PermutohedralLattice & operator=(const PermutohedralLattice &)=delete
int nData
Definition Permutohedral.h:652
HashTable * hashTables
Definition Permutohedral.h:667
HashTablePermutohedral< D, VD > HashTable
Definition Permutohedral.h:364
HashTable::Key Key
Definition Permutohedral.h:365
const int * canonical
Definition Permutohedral.h:655
void splat(float *position, float *value, size_t replay_index, int thread_index=0) const
Definition Permutohedral.h:430
const float i
Definition colorspaces_inline_conversions.h:669
const float h
Definition colorspaces_inline_conversions.h:1366
const float r
Definition colorspaces_inline_conversions.h:1324
static const dt_aligned_pixel_simd_t value
Definition darktable.h:501
static void weight(const float *c1, const float *c2, const float sharpen, dt_aligned_pixel_t weight)
Definition eaw.c:33
static const float v
Definition iop_profile.h:223
size_t size
Definition mipmap_cache.c:3
Definition Permutohedral.h:341
int keyIdx
Definition Permutohedral.h:342
Definition Permutohedral.h:84
unsigned hash
Definition Permutohedral.h:124
Key & operator=(const Key &)=default
void setHash()
Definition Permutohedral.h:103
Key(const Key &origin, int dim, int direction)
Definition Permutohedral.h:87
bool operator==(const Key &other) const
Definition Permutohedral.h:114
short key[KD]
Definition Permutohedral.h:125
void setKey(int idx, short val)
Definition Permutohedral.h:98
Definition Permutohedral.h:131
void setValue(int idx, short val)
Definition Permutohedral.h:151
Value & operator+=(const Value &other)
Definition Permutohedral.h:193
void add(const Value &other)
Definition Permutohedral.h:161
Value(const Value &)=default
Value & operator=(const Value &)=default
static void clear(float *val)
Definition Permutohedral.h:146
float value[VD]
Definition Permutohedral.h:202
Value(int init)
Definition Permutohedral.h:134
void mix(const Value *left, const Value *center, const Value *right)
Definition Permutohedral.h:185
void addTo(float *dest, float weight) const
Definition Permutohedral.h:177
void addValue(int idx, short val)
Definition Permutohedral.h:156
void add(const float *other, float weight)
Definition Permutohedral.h:169
Definition Permutohedral.h:659
int table
Definition Permutohedral.h:662
float weight[D+1]
Definition Permutohedral.h:664
int offset[D+1]
Definition Permutohedral.h:663