howieliang_NFCMatrix/Processing/NFCMat_v3/Init.pde
void initNFCMat() {
  for (int i = 0; i < sheetID.length; i++) {
    sheetID[i] = new ArrayList<Integer>();
    sheetCell[i] = new ArrayList<Integer>();
    sheetLocA[i] = new PVector();
    sheetCoilID[i] = new int[coilNum];
    for (int a = 0; a < A; a++) {
      sheetPiVec[i][a] = new ArrayList<Integer>();
      sheetPjVec[i][a] = new ArrayList<Integer>();
      sheetPiCell[i][a] = new ArrayList<Integer>();
      sheetPjCell[i][a] = new ArrayList<Integer>();
    }
    for (int w=0; w<W; w++) {
      for (int h=0; h<H; h++) {
        ttlTimer[i][w][h]=0;
      }
    }
  }
}

void resetNFCMat() {
  for (int i = 0; i < sheetID.length; i++) {
    sheetID[i].clear();
    sheetCell[i].clear();
    sheetLocA[i] = new PVector();
    for (int n=0; n<coilNum; n++) {
      sheetCoilID[i][n] = -1;
    }
    for (int a = 0; a < A; a++) {
      sheetPiVec[i][a].clear();
      sheetPjVec[i][a].clear();
      sheetPiCell[i][a].clear();
      sheetPjCell[i][a].clear();
    }
  }
}

void updateTTLTimer() {
  for (int i = 0; i < sheetID.length; i++) {
    for (int w=0; w<W; w++) {
      for (int h=0; h<H; h++) {
        ttlTimer[i][w][h]= (ttlTimer[i][w][h]>0 ? ttlTimer[i][w][h]-=0.1 : 0);
      }
    }
  }
}

void updateNFCMat() {
  for (int n=0; n<coilNum; n++) {
    int id = nfcs.searchID(nfcs.id_db, nfcs.IDtoLong(coilUID[n]));   
    int s = id / (W*H); 
    if (id>=0) { 
      int x = (id%(W*H)) %W;
      int y = (id%(W*H)) /W;
      sheetID[s].add(id);
      sheetCell[s].add(n);
      sheetCoilID[s][n] = id % (W*H);
      ttlTimer[s][x][y] = 1;
    }
  }
}

void featureExtration() {
  float tagNum = 0;
  int[][] a0 = {{0, 1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {3, 4, 5, 6}, {4, 5, 6}, {5, 6}, {6}, {7, 8, 9, 10, 11, 12, 13}, {8, 9, 10, 11, 12, 13}, {9, 10, 11, 12, 13}, {10, 11, 12, 13}, {11, 12, 13}, {12, 13}, {13}, {14, 15, 16, 17, 18, 19, 20}, {15, 16, 17, 18, 19, 20}, {16, 17, 18, 19, 20}, {17, 18, 19, 20}, {18, 19, 20}, {19, 20}, {20}, {21, 22, 23, 24, 25, 26, 27}, {22, 23, 24, 25, 26, 27}, {23, 24, 25, 26, 27}, {24, 25, 26, 27}, {25, 26, 27}, {26, 27}, {27}, {28, 29, 30, 31, 32, 33, 34}, {29, 30, 31, 32, 33, 34}, {30, 31, 32, 33, 34}, {31, 32, 33, 34}, {32, 33, 34}, {33, 34}, {34}, {35, 36, 37, 38, 39, 40, 41}, {36, 37, 38, 39, 40, 41}, {37, 38, 39, 40, 41}, {38, 39, 40, 41}, {39, 40, 41}, {40, 41}, {41}, {42, 43, 44, 45, 46, 47, 48}, {43, 44, 45, 46, 47, 48}, {44, 45, 46, 47, 48}, {45, 46, 47, 48}, {46, 47, 48}, {47, 48}, {48}, {49, 50, 51, 52, 53, 54, 55}, {50, 51, 52, 53, 54, 55}, {51, 52, 53, 54, 55}, {52, 53, 54, 55}, {53, 54, 55}, {54, 55}, {55}};
  int[][] a30 = {{0, 8, 17, 25, 34}, {1, 9, 18, 26}, {2, 10, 19, 27}, {3, 11, 20}, {4, 12}, {5, 13}, {6}, {7, 16, 24, 33, 41}, {8, 17, 25, 34}, {9, 18, 26}, {10, 19, 27}, {11, 20}, {12}, {13}, {14, 22, 31, 39, 48}, {15, 23, 32, 40}, {16, 24, 33, 41}, {17, 25, 34}, {18, 26}, {19, 27}, {20}, {21, 30, 38, 47, 55}, {22, 31, 39, 48}, {23, 32, 40}, {24, 33, 41}, {25, 34}, {26}, {27}, {28, 36, 45, 53}, {29, 37, 46, 54}, {30, 38, 47, 55}, {31, 39, 48}, {32, 40}, {33, 41}, {34}, {35, 44, 52}, {36, 45, 53}, {37, 46, 54}, {38, 47, 55}, {39, 48}, {40}, {41}, {42, 50}, {43, 51}, {44, 52}, {45, 53}, {46, 54}, {47, 55}, {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}};
  int[][] a60 = {{0, 7, 15, 22, 30, 37, 45}, {1, 8, 16, 23, 31, 38, 46}, {2, 9, 17, 24, 32, 39, 47}, {3, 10, 18, 25, 33, 40, 48}, {4, 11, 19, 26, 34, 41}, {5, 12, 20, 27}, {6, 13}, {7, 15, 22, 30, 37, 45, 52}, {8, 16, 23, 31, 38, 46, 53}, {9, 17, 24, 32, 39, 47, 54}, {10, 18, 25, 33, 40, 48, 55}, {11, 19, 26, 34, 41}, {12, 20, 27}, {13}, {14, 21, 29, 36, 44, 51}, {15, 22, 30, 37, 45, 52}, {16, 23, 31, 38, 46, 53}, {17, 24, 32, 39, 47, 54}, {18, 25, 33, 40, 48, 55}, {19, 26, 34, 41}, {20, 27}, {21, 29, 36, 44, 51}, {22, 30, 37, 45, 52}, {23, 31, 38, 46, 53}, {24, 32, 39, 47, 54}, {25, 33, 40, 48, 55}, {26, 34, 41}, {27}, {28, 35, 43, 50}, {29, 36, 44, 51}, {30, 37, 45, 52}, {31, 38, 46, 53}, {32, 39, 47, 54}, {33, 40, 48, 55}, {34, 41}, {35, 43, 50}, {36, 44, 51}, {37, 45, 52}, {38, 46, 53}, {39, 47, 54}, {40, 48, 55}, {41}, {42}, {43, 50}, {44, 51}, {45, 52}, {46, 53}, {47, 54}, {48, 55}, {49}, {50}, {51}, {52}, {53}, {54}, {55}};
  int[][] a90 = {{0, 14, 28, 42}, {1, 15, 29, 43}, {2, 16, 30, 44}, {3, 17, 31, 45}, {4, 18, 32, 46}, {5, 19, 33, 47}, {6, 20, 34, 48}, {7, 21, 35, 49}, {8, 22, 36, 50}, {9, 23, 37, 51}, {10, 24, 38, 52}, {11, 25, 39, 53}, {12, 26, 40, 54}, {13, 27, 41, 55}, {14, 28, 42}, {15, 29, 43}, {16, 30, 44}, {17, 31, 45}, {18, 32, 46}, {19, 33, 47}, {20, 34, 48}, {21, 35, 49}, {22, 36, 50}, {23, 37, 51}, {24, 38, 52}, {25, 39, 53}, {26, 40, 54}, {27, 41, 55}, {28, 42}, {29, 43}, {30, 44}, {31, 45}, {32, 46}, {33, 47}, {34, 48}, {35, 49}, {36, 50}, {37, 51}, {38, 52}, {39, 53}, {40, 54}, {41, 55}, {42}, {43}, {44}, {45}, {46}, {47}, {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}};
  int[][] a120 = {{0}, {1, 7, 14}, {2, 8, 15, 21, 28}, {3, 9, 16, 22, 29, 35, 42}, {4, 10, 17, 23, 30, 36, 43}, {5, 11, 18, 24, 31, 37, 44}, {6, 12, 19, 25, 32, 38, 45}, {7, 14}, {8, 15, 21, 28}, {9, 16, 22, 29, 35, 42}, {10, 17, 23, 30, 36, 43, 49}, {11, 18, 24, 31, 37, 44, 50}, {12, 19, 25, 32, 38, 45, 51}, {13, 20, 26, 33, 39, 46, 52}, {14}, {15, 21, 28}, {16, 22, 29, 35, 42}, {17, 23, 30, 36, 43, 49}, {18, 24, 31, 37, 44, 50}, {19, 25, 32, 38, 45, 51}, {20, 26, 33, 39, 46, 52}, {21, 28}, {22, 29, 35, 42}, {23, 30, 36, 43, 49}, {24, 31, 37, 44, 50}, {25, 32, 38, 45, 51}, {26, 33, 39, 46, 52}, {27, 34, 40, 47, 53}, {28}, {29, 35, 42}, {30, 36, 43, 49}, {31, 37, 44, 50}, {32, 38, 45, 51}, {33, 39, 46, 52}, {34, 40, 47, 53}, {35, 42}, {36, 43, 49}, {37, 44, 50}, {38, 45, 51}, {39, 46, 52}, {40, 47, 53}, {41, 48, 54}, {42}, {43, 49}, {44, 50}, {45, 51}, {46, 52}, {47, 53}, {48, 54}, {49}, {50}, {51}, {52}, {53}, {54}, {55}};
  int[][] a150 = {{0}, {1}, {2, 7}, {3, 8, 14}, {4, 9, 15}, {5, 10, 16, 21}, {6, 11, 17, 22, 28}, {7}, {8, 14}, {9, 15}, {10, 16, 21}, {11, 17, 22, 28}, {12, 18, 23, 29}, {13, 19, 24, 30, 35}, {14}, {15}, {16, 21}, {17, 22, 28}, {18, 23, 29}, {19, 24, 30, 35}, {20, 25, 31, 36, 42}, {21}, {22, 28}, {23, 29}, {24, 30, 35}, {25, 31, 36, 42}, {26, 32, 37, 43}, {27, 33, 38, 44, 49}, {28}, {29}, {30, 35}, {31, 36, 42}, {32, 37, 43}, {33, 38, 44, 49}, {34, 39, 45, 50}, {35}, {36, 42}, {37, 43}, {38, 44, 49}, {39, 45, 50}, {40, 46, 51}, {41, 47, 52}, {42}, {43}, {44, 49}, {45, 50}, {46, 51}, {47, 52}, {48, 53}, {49}, {50}, {51}, {52}, {53}, {54}, {55}};
  for (int i = 0; i < sheetID.length; i++) {
    tagNum = sheetID[i].size();
    if (tagNum>1) {
      for (int n=0; n<tagNum; n++) {
        for (int m=0; m<tagNum; m++) {
          if (n!=m) {
            int idN = (int)sheetID[i].get(n);
            int idM = (int)sheetID[i].get(m);
            int cellN = (int)sheetCell[i].get(n);
            int cellM = (int)sheetCell[i].get(m);
            if (idN < idM) {
              for (int j = 1; j<a0[idN%(W*H)].length; j++) {
                if (a0[idN%(W*H)][j] == idM%(W*H)) {
                  sheetPiVec[i][0].add(idN);
                  sheetPjVec[i][0].add(idM);
                  sheetPiCell[i][0].add(cellN);
                  sheetPjCell[i][0].add(cellM);
                }
              }
              for (int j = 1; j<a30[idN%(W*H)].length; j++) {
                if (a30[idN%(W*H)][j] == idM%(W*H)) {
                  sheetPiVec[i][1].add(idN);
                  sheetPjVec[i][1].add(idM);
                  sheetPiCell[i][1].add(cellN);
                  sheetPjCell[i][1].add(cellM);
                }
              }
              for (int j = 1; j<a60[idN%(W*H)].length; j++) {
                if (a60[idN%(W*H)][j] == idM%(W*H)) {
                  sheetPiVec[i][2].add(idN);
                  sheetPjVec[i][2].add(idM);
                  sheetPiCell[i][2].add(cellN);
                  sheetPjCell[i][2].add(cellM);
                }
              }
              for (int j = 1; j<a90[idN%(W*H)].length; j++) {
                if (a90[idN%(W*H)][j] == idM%(W*H)) {
                  sheetPiVec[i][3].add(idN);
                  sheetPjVec[i][3].add(idM);
                  sheetPiCell[i][3].add(cellN);
                  sheetPjCell[i][3].add(cellM);
                }
              }
              for (int j = 1; j<a120[idN%(W*H)].length; j++) {
                if (a120[idN%(W*H)][j] == idM%(W*H)) {
                  sheetPiVec[i][4].add(idN);
                  sheetPjVec[i][4].add(idM);
                  sheetPiCell[i][4].add(cellN);
                  sheetPjCell[i][4].add(cellM);
                }
              }
              for (int j = 1; j<a150[idN%(W*H)].length; j++) {
                if (a150[idN%(W*H)][j] == idM%(W*H)) {
                  sheetPiVec[i][5].add(idN);
                  sheetPjVec[i][5].add(idM);
                  sheetPiCell[i][5].add(cellN);
                  sheetPjCell[i][5].add(cellM);
                }
              }
            }
          }
        }
      }
    }
  }
}
