コード例 #1
0
void mexFunction (int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray*prhs[])

{
  if (nrhs != 2) 
    mexErrMsgTxt ("This function requires exactly 2 input arguments");
  
  if (nlhs > 1)
    mexErrMsgTxt ("This function output exactly 1 argument");

  int d = mxGetM (prhs[0]);   /* d is the number of codes, i.e., 8 times the number of bits */
  int na = mxGetN (prhs[0]);
  int nb = mxGetN (prhs[1]);

  if (mxGetM (prhs[1]) != d)
      mexErrMsgTxt("Dimension of binary vectors are not consistent");

  if (mxGetClassID(prhs[0]) != mxUINT8_CLASS)
    mexErrMsgTxt ("first argument should be uint 8 type"); 

  if (mxGetClassID(prhs[1]) != mxUINT8_CLASS)
    mexErrMsgTxt ("second argument should be uint8 type"); 

  uint8 * a = (uint8*) mxGetPr (prhs[0]);
  uint8 * b = (uint8*) mxGetPr (prhs[1]);

  /* ouptut: distances */
  plhs[0] = mxCreateNumericMatrix (na, nb, mxUINT16_CLASS, mxREAL);
  uint16 *dis = (uint16*) mxGetPr (plhs[0]);

  if (BITVECBYTE == d) 
    compute_hamming (dis, a, b, na, nb);
  else
    compute_hamming_generic (dis, a, b, na, nb, d); 
}
コード例 #2
0
ファイル: yael_hamming.c プロジェクト: pombreda/yael
void mexFunction (int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray*prhs[])

{
  int mode_thres = 0;
  if (nrhs != 2 && nrhs != 3) 
    mexErrMsgTxt ("This function requires either 2 input arguments.");
  
  if (nrhs == 3) mode_thres = 1; 
  
  int d = mxGetM (prhs[0]);   /* d is the number of codes, i.e., 8 times the number of bits */
  int na = mxGetN (prhs[0]);
  int nb = mxGetN (prhs[1]);

  if (mxGetM (prhs[1]) != d) 
      usage ("Dimension of binary vectors are not consistent");

  if (mxGetClassID(prhs[0]) != mxUINT8_CLASS)
    	usage ("first argument should be uint 8 type"); 

  if (mxGetClassID(prhs[1]) != mxUINT8_CLASS)
      usage ("second argument should be uint8 type"); 

  uint8 * a = (uint8*) mxGetPr (prhs[0]);
  uint8 * b = (uint8*) mxGetPr (prhs[1]);


  /* Just compute all Hamming distances */
  if (mode_thres == 0) {
    if (nlhs > 1)
      usage ("This syntax expects only exactly one output argument");

    /* ouptut: distances */
    plhs[0] = mxCreateNumericMatrix (na, nb, mxUINT16_CLASS, mxREAL);
    uint16 *dis = (uint16*) mxGetPr (plhs[0]);

    compute_hamming (dis, a, b, na, nb, d);
  }
  
  /* Return only the Hamming distances below a given threshold */
  else {
    if (nlhs != 2)
      usage ("This syntax expects only exactly two output arguments");
    int ht = (int) mxGetScalar (prhs[2]);
    size_t totmatches;
    int * keys;
    uint16 *dis;
    size_t i;
    
/* #ifndef _OPENMP */
    match_hamming_count (a, b, na, nb, ht, d, &totmatches);
    
    plhs[0] = mxCreateNumericMatrix (2, totmatches, mxINT32_CLASS, mxREAL);
    plhs[1] = mxCreateNumericMatrix (1, totmatches, mxUINT16_CLASS, mxREAL);
    
    keys = (int *) mxGetPr(plhs[0]);
    dis = (uint16*) mxGetPr (plhs[1]);
    
    size_t ret = match_hamming_thres_prealloc (a, b, na, nb, ht, d, keys, dis);
 
    assert (ret == totmatches);

    /* Fix Matlab identifiers */
    for (i = 0 ; i < 2 * totmatches ; i++)
      keys[i] = keys[i] + 1;
  }
            
}
コード例 #3
0
ファイル: keyboard.c プロジェクト: stevengos/IN4073
packet_t encapsulate(char command)
{
    packet_t outgoing;

    switch(command)
    {
        case ESC:
            outgoing.header     = STOP;
            outgoing.command    = EMPTY;
            break;

        /* MODES */
        case ZERO:
            outgoing.header     = SET_MODE;
            outgoing.command    = SAFE_MODE;
            break;
        case ONE:
            outgoing.header     = SET_MODE;
            outgoing.command    = PANIC_MODE;
            break;
        case TWO:
            outgoing.header     = SET_MODE;
            outgoing.command    = MANUAL_MODE;
            break;
        case THREE:
            outgoing.header     = SET_MODE;
            outgoing.command    = CALIBRATION_MODE;
            break;
        case FOUR:
            outgoing.header     = SET_MODE;
            outgoing.command    = YAW_MODE;
            break;
        case FIVE:
            outgoing.header     = SET_MODE;
            outgoing.command    = FULL_MODE;
            break;
        case SEVEN:
            outgoing.header     = LOG;
            outgoing.command    = LOG_START;
            break;
        case EIGHT:
            outgoing.header     = LOG;
            outgoing.command    = LOG_STOP;
            break;
        case NINE:
            outgoing.header     = LOG;
            outgoing.command    = LOG_GET;
            break;

        /* MANUAL CONTROL */
        case A:
	    outgoing.header     = D_LIFT;
            outgoing.command    = INCREASE;
            break;
        case Z:
            outgoing.header     = D_LIFT;
            outgoing.command    = DECREASE;
            break;
        
        case Q:
            outgoing.header     = D_YAWRATE;
            outgoing.command    = DECREASE;
            break;
        case W:
            outgoing.header     = D_YAWRATE;
            outgoing.command    = INCREASE;
            break;
        case ARROW_U:
            outgoing.header     = D_PITCH;
            outgoing.command    = DECREASE;
            break;
        case ARROW_D:
            outgoing.header     = D_PITCH;
            outgoing.command    = INCREASE;
            break;
        case ARROW_R:
            outgoing.header     = D_ROLL;
            outgoing.command    = DECREASE;
            break;
        case ARROW_L:
            outgoing.header     = D_ROLL;
            outgoing.command    = INCREASE;
            break;

        /* CONTROLLER SETTINGS */
        case Y:
            outgoing.header     = SET_CONTROLLER_PITCH;
            outgoing.command    = INCREASE;
            break;
        case H:
            outgoing.header     = SET_CONTROLLER_PITCH;
            outgoing.command    = DECREASE;
            break;
        case U:
            outgoing.header     = SET_CONTROLLER_ROLL;
            outgoing.command    = INCREASE;
            break;
        case J:
            outgoing.header     = SET_CONTROLLER_ROLL;
            outgoing.command    = DECREASE;
            break;
        case I:
            outgoing.header     = SET_CONTROLLER_YAW;
            outgoing.command    = INCREASE;
            break;
        case K:
            outgoing.header     = SET_CONTROLLER_YAW;
            outgoing.command    = DECREASE;
            break;
        case O:
            outgoing.header     = SET_SCALE_YAW;
            outgoing.command    = INCREASE;
            break;
        case L:
            outgoing.header     = SET_SCALE_YAW;
            outgoing.command    = DECREASE;
            break;

        case N:
            outgoing.header     = SET_CONTROLLER_YAW;
            outgoing.command    = INCREASE;
            break;

        case M:
            outgoing.header     = SET_CONTROLLER_YAW;
            outgoing.command    = DECREASE;
            break;

        /* NOT RECOGNIZED */
        default:
            outgoing.header     = EMPTY;
            outgoing.command    = EMPTY;
            break;
    };

    compute_hamming(&outgoing);

    return outgoing;
}