Changeset 214 in flair-src for trunk/lib/FlairCore/src/Matrix_impl.cpp


Ignore:
Timestamp:
02/07/18 17:49:27 (6 years ago)
Author:
Sanahuja Guillaume
Message:

matrix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Matrix_impl.cpp

    r213 r214  
    5454        dynamic_cast<ScalarType const &>(elementDataType);
    5555    if (typeid(scalarType) == typeid(FloatType)) {
    56       datas = (float **)malloc(descriptor->Rows() * sizeof(float*));
    57       if(datas==NULL) {
    58         self->Err("error allocating matrix\n");
    59         return;
    60       }
    61       for(uint32_t i=0 ; i < descriptor->Rows() ; i++){
    62         datas[i] = (float*)malloc(descriptor->Cols() * sizeof(float) );
    63         if(datas[i]==NULL) {
    64           self->Err("error allocating matrix\n");
    65           for(uint32_t j = i-1 ; j >= 0 ; j--) free(datas[j]);
    66           free(datas);
    67           return;
    68         }
    69       }
    70       /*
    71     } else if (typeid(scalarType) == typeid(SignedIntegerType)) {
     56      datas =malloc(descriptor->Rows() * descriptor->Cols() * sizeof(float));
     57    } else if (typeid(scalarType) == typeid(SignedIntegerType) || typeid(scalarType) == typeid(UnsignedIntegerType) ) {
    7258      switch (elementDataType.GetSize()) {
    7359      case 1:
    74         mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_8SC1);
     60        datas=malloc(descriptor->Rows() * descriptor->Cols() * sizeof(uint8_t));
    7561        break;
    7662      case 2:
    77         mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_16SC1);
     63        datas=malloc(descriptor->Rows() * descriptor->Cols() * sizeof(uint16_t));
    7864        break;
    7965      default:
    8066        self->Err("unsupported integer scalar type\n");
    81       }*/
     67      }
    8268    } else {
    8369      self->Err("unsupported scalar type\n");
     
    9480
    9581Matrix_impl::~Matrix_impl() {
    96   for (uint32_t i = 0; i < descriptor->Rows();i++) {
    97     free(datas[i]);
    98   }
    9982  free(datas);
    10083  delete descriptor;
    10184}
     85
     86float Matrix_impl::ValueNoMutex(uint32_t row, uint32_t col) const {
     87  ScalarType const &scalarType =
     88        dynamic_cast<ScalarType const &>(elementDataType);
     89  if (typeid(scalarType) == typeid(FloatType)) {
     90    return ((float*)datas)[row*descriptor->Cols()+col];
     91  } else if (typeid(scalarType) == typeid(SignedIntegerType)) {
     92    switch (elementDataType.GetSize()) {
     93    case 1:
     94      return ((int8_t*)datas)[row*descriptor->Cols()+col];
     95      break;
     96    case 2:
     97      return ((int16_t*)datas)[row*descriptor->Cols()+col];
     98      break;
     99    default:
     100      self->Err("unsupported signed integer scalar type\n");
     101    }
     102  } else if (typeid(scalarType) == typeid(UnsignedIntegerType)) {
     103    switch (elementDataType.GetSize()) {
     104    case 1:
     105      return ((uint8_t*)datas)[row*descriptor->Cols()+col];
     106      break;
     107    case 2:
     108      return ((uint16_t*)datas)[row*descriptor->Cols()+col];
     109      break;
     110    default:
     111      self->Err("unsupported unsigned integer scalar type\n");
     112    }
     113  } else {
     114    self->Err("unsupported scalar type\n");
     115  }
     116  return 0;
     117}
     118
     119void Matrix_impl::SetValueNoMutex(uint32_t row, uint32_t col, float value) {
     120 ScalarType const &scalarType =
     121        dynamic_cast<ScalarType const &>(elementDataType);
     122  if (typeid(scalarType) == typeid(FloatType)) {
     123    ((float*)datas)[row*descriptor->Cols()+col]=value;
     124  } else if (typeid(scalarType) == typeid(SignedIntegerType)) {
     125    switch (elementDataType.GetSize()) {
     126    case 1:
     127      ((int8_t*)datas)[row*descriptor->Cols()+col]=value;
     128      break;
     129    case 2:
     130      ((int16_t*)datas)[row*descriptor->Cols()+col]=value;
     131      break;
     132    default:
     133      self->Err("unsupported signed integer scalar type\n");
     134    }
     135  } else if (typeid(scalarType) == typeid(UnsignedIntegerType)) {
     136    switch (elementDataType.GetSize()) {
     137    case 1:
     138      ((uint8_t*)datas)[row*descriptor->Cols()+col]=value;
     139      break;
     140    case 2:
     141      ((uint16_t*)datas)[row*descriptor->Cols()+col]=value;
     142      break;
     143    default:
     144      self->Err("unsupported unsigned integer scalar type\n");
     145    }
     146  } else {
     147    self->Err("unsupported scalar type\n");
     148  }
     149}
Note: See TracChangeset for help on using the changeset viewer.