Skip to content

Instantly share code, notes, and snippets.

@meiqua
Created May 8, 2019 13:26
Show Gist options
  • Save meiqua/7568d7ef004038f44d33a11a1c81f4b5 to your computer and use it in GitHub Desktop.
Save meiqua/7568d7ef004038f44d33a11a1c81f4b5 to your computer and use it in GitHub Desktop.
// https://github.com/meiqua/shape_based_matching/issues/10#issuecomment-490470602
// two mistakes:
// index of LUT, line 45
// movement of high parts, line 51
#include <iostream>
#include <vector>
#include <assert.h>
using namespace std;
const int ORI=8; //8个方向
const int SEG=2; //2个分割
const int INDEX=16; //16索引
struct Node {
int value;
int prev;
int next;
};
int main()
{
vector<Node> nodes(ORI);
for(int i=0; i<ORI; i++){
nodes[i].value = (1 << i);
nodes[i].prev = i-1;
nodes[i].next = i+1;
}
nodes[0].prev = ORI-1;
nodes[ORI-1].next = 0;
uint8_t LUT[ORI*SEG*INDEX] = {0};
uint8_t LUT_RIGHT[] = {0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
0, 3, 4, 4, 3, 3, 4, 4, 2, 3, 4, 4, 3, 3, 4, 4, 0, 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
0, 2, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 0, 2, 1, 2, 0, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2,
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 0, 3, 2, 3, 1, 3, 2, 3, 0, 3, 2, 3, 1, 3, 2, 3,
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4,
0, 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 3, 4, 4, 3, 3, 4, 4, 2, 3, 4, 4, 3, 3, 4, 4,
0, 2, 1, 2, 0, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0, 2, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4,
0, 3, 2, 3, 1, 3, 2, 3, 0, 3, 2, 3, 1, 3, 2, 3, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
for(int i=0; i<ORI; i++){ // 8 ori
for(int m=0; m<SEG; m++){ // 2 seg
for(int n=0; n<INDEX; n++){ // 16 index
int index = n+m*INDEX+i*INDEX*SEG;
if(n==0){ // no ori
LUT[index] = 0;
continue;
}
int res = (n << (m*4)); // 4 here comes from 2^4 = 16(INDEX)
Node current_node_go_forward = nodes[i];
Node current_node_go_back = nodes[i];
int angle_diff = 0;
while(1){
if((current_node_go_forward.value & res) > 0 ||
(current_node_go_back.value & res) > 0){
break;
}else{
current_node_go_back = nodes[current_node_go_back.prev];
current_node_go_forward = nodes[current_node_go_forward.next];
angle_diff ++;
}
}
LUT[index] = 4 - angle_diff;
assert(LUT[index] == LUT_RIGHT[index]);
}
}
}
for(int i=0; i<ORI; i++){
for(int m=0; m<SEG*INDEX; m++){
cout << int(LUT[i*SEG*INDEX + m]) << ", ";
}
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment