62 Key(
const Key &origin,
int dim,
int direction)
64 for(
int i = 0; i < KD; i++)
key[i] = origin.
key[i] + direction;
65 key[dim] = origin.
key[dim] - direction * KD;
81 for(
int i = 0; i < KD; i++)
92 for(
int i = 0; i < KD; i++)
94 if(
key[i] != other.
key[i])
return false;
111 for(
int i = 0; i < VD; i++)
123 for(
int i = 0; i < VD; i++) val[i] = 0;
138 for(
int i = 0; i < VD; i++)
146 for(
int i = 0; i < VD; i++)
154 for(
int i = 0; i < VD; i++)
162 for(
int i = 0; i < VD; i++)
170 for(
int i = 0; i < VD; i++)
244 if(!create)
return -1;
271 return (offset < 0) ? nullptr :
values + offset;
299 for(
size_t i = 0; i < oldCapacity; i++)
301 if(
entries[i].keyIdx == -1)
continue;
303 while(newEntries[h].keyIdx != -1)
352 float *scaleFactorTmp =
new float[D];
353 int *canonicalTmp =
new int[(D + 1) * (D + 1)];
360 for(
int i = 0; i <= D; i++)
362 for(
int j = 0; j <= D - i; j++) canonicalTmp[i * (D + 1) + j] = i;
363 for(
int j = D - i + 1; j <= D; j++) canonicalTmp[i * (D + 1) + j] = i - (D + 1);
368 for(
int i = 0; i < D; i++)
371 scaleFactorTmp[i] = 1.0f / (sqrtf((
float)(i + 1) * (i + 2)));
385 scaleFactorTmp[i] *= (D + 1) * sqrtf(2.0 / 3);
405 void splat(
float *
position,
float *value,
size_t replay_index,
int thread_index = 0)
const
407 float elevated[D + 1];
410 float barycentric[D + 2];
415 for(
int i = D - 1; i > 0; i--)
421 constexpr float scale = 1.0f / (D + 1);
425 for(
int i = 0; i <= D; i++)
427 float v = elevated[i] * scale;
428 float up = ceilf(v) * (D + 1);
429 float down = floorf(v) * (D + 1);
431 if(up - elevated[i] < elevated[i] - down)
442 memset(rank, 0,
sizeof rank);
443 for(
int i = 0; i < D; i++)
444 for(
int j = i + 1; j <= D; j++)
445 if(elevated[i] - greedy[i] < elevated[j] - greedy[j])
454 for(
int i = 0; i <= D; i++)
456 if(rank[i] >= D + 1 - sum)
459 rank[i] += sum - (D + 1);
469 for(
int i = 0; i <= D; i++)
474 rank[i] += (D + 1) + sum;
482 memset(barycentric, 0,
sizeof barycentric);
483 for(
int i = 0; i <= D; i++)
485 barycentric[D - rank[i]] += (elevated[i] - greedy[i]) * scale;
486 barycentric[D + 1 - rank[i]] -= (elevated[i] - greedy[i]) * scale;
488 barycentric[0] += 1.0f + barycentric[D + 1];
492 for(
int remainder = 0; remainder <= D; remainder++)
496 for(
int i = 0; i < D; i++)
key.key[i] = greedy[i] +
canonical[remainder * (D + 1) + rank[i]];
503 val->
add(value, barycentric[remainder]);
507 replay[replay_index].
weight[remainder] = barycentric[remainder];
524 while(total_entries >
hashTables[0].maxFill())
531 int **offset_remap =
new int *[
nThreads];
537 offset_remap[i] =
new int[filled];
538 for(
int j = 0; j < filled; j++)
541 val->
add(oldVals[j]);
547 for(
int i = 0; i <
nData; i++)
551 for(
int dim = 0; dim <= D; dim++)
556 for(
int i = 1; i <
nThreads; i++)
delete[] offset_remap[i];
557 delete[] offset_remap;
564 void slice(
float *col,
size_t replay_index)
const
569 for(
int i = 0; i <= D; i++)
571 base[r.offset[i]].
addTo(col, r.weight[i]);
581 const Value *hashTableBase = oldValue;
583 const Value zero{ 0 };
586 for(
int j = 0; j <= D; j++)
589#pragma omp parallel for shared(j, oldValue, newValue)
594 const Key &
key = keyBase[i];
596 Key neighbor1(
key, j, +1);
597 Key neighbor2(
key, j, -1);
599 const Value *oldVal = oldValue + i;
602 vm1 = vm1 ? vm1 - hashTableBase + oldValue : &zero;
605 vp1 = vp1 ? vp1 - hashTableBase + oldValue : &zero;
608 newValue[i].
mix(vm1, oldVal, vp1);
610 std::swap(newValue, oldValue);
615 if(oldValue != hashTableBase)
void init(dt_imageio_module_format_t *self)
Definition avif.c:142
int position()
Definition backgroundjobs.c:66
Definition Permutohedral.h:55
HashTablePermutohedral(const HashTablePermutohedral &)=delete
const Key * getKeys() const
Definition Permutohedral.h:218
unsigned long capacity_bits
Definition Permutohedral.h:324
int size() const
Definition Permutohedral.h:207
HashTablePermutohedral & operator=(const HashTablePermutohedral &)=delete
~HashTablePermutohedral()
Definition Permutohedral.h:197
Value * values
Definition Permutohedral.h:321
HashTablePermutohedral()
Definition Permutohedral.h:185
Key * keys
Definition Permutohedral.h:320
size_t capacity
Definition Permutohedral.h:323
Entry * entries
Definition Permutohedral.h:322
size_t filled
Definition Permutohedral.h:323
size_t maxFill() const
Definition Permutohedral.h:212
Value * lookup(const Key &k, bool create=true)
Definition Permutohedral.h:268
void grow(int order=1)
Definition Permutohedral.h:275
Value * getValues() const
Definition Permutohedral.h:224
int lookupOffset(const Key &key, bool create=true)
Definition Permutohedral.h:234
Definition Permutohedral.h:336
void slice(float *col, size_t replay_index) const
Definition Permutohedral.h:564
struct PermutohedralLattice::ReplayEntry * replay
HashTable::Value Value
Definition Permutohedral.h:341
const float * scaleFactor
Definition Permutohedral.h:629
PermutohedralLattice(size_t nData_, int nThreads_=1)
Definition Permutohedral.h:349
int nThreads
Definition Permutohedral.h:628
PermutohedralLattice(const PermutohedralLattice &)=delete
void blur() const
Definition Permutohedral.h:576
~PermutohedralLattice()
Definition Permutohedral.h:394
void merge_splat_threads()
Definition Permutohedral.h:512
PermutohedralLattice & operator=(const PermutohedralLattice &)=delete
int nData
Definition Permutohedral.h:627
HashTable * hashTables
Definition Permutohedral.h:642
HashTablePermutohedral< D, VD > HashTable
Definition Permutohedral.h:339
HashTable::Key Key
Definition Permutohedral.h:340
const int * canonical
Definition Permutohedral.h:630
void splat(float *position, float *value, size_t replay_index, int thread_index=0) const
Definition Permutohedral.h:405
static void weight(const float *c1, const float *c2, const float sharpen, dt_aligned_pixel_t weight)
Definition eaw.c:29
size_t size
Definition mipmap_cache.c:3
Definition Permutohedral.h:316
int keyIdx
Definition Permutohedral.h:317
Definition Permutohedral.h:59
unsigned hash
Definition Permutohedral.h:99
Key & operator=(const Key &)=default
void setHash()
Definition Permutohedral.h:78
Key(const Key &origin, int dim, int direction)
Definition Permutohedral.h:62
bool operator==(const Key &other) const
Definition Permutohedral.h:89
short key[KD]
Definition Permutohedral.h:100
void setKey(int idx, short val)
Definition Permutohedral.h:73
Definition Permutohedral.h:106
void setValue(int idx, short val)
Definition Permutohedral.h:126
Value & operator+=(const Value &other)
Definition Permutohedral.h:168
void add(const Value &other)
Definition Permutohedral.h:136
Value(const Value &)=default
Value & operator=(const Value &)=default
static void clear(float *val)
Definition Permutohedral.h:121
float value[VD]
Definition Permutohedral.h:177
Value(int init)
Definition Permutohedral.h:109
void mix(const Value *left, const Value *center, const Value *right)
Definition Permutohedral.h:160
void addTo(float *dest, float weight) const
Definition Permutohedral.h:152
void addValue(int idx, short val)
Definition Permutohedral.h:131
void add(const float *other, float weight)
Definition Permutohedral.h:144
Definition Permutohedral.h:634
int table
Definition Permutohedral.h:637
float weight[D+1]
Definition Permutohedral.h:639
int offset[D+1]
Definition Permutohedral.h:638