Changeset 214 in flair-src for trunk/lib/FlairCore


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

matrix

Location:
trunk/lib/FlairCore/src
Files:
10 edited

Legend:

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

    r213 r214  
    211211  }
    212212                                                                                                                                                                                       
    213         UDT::startup();
     213        UDT::startup(1024*256,1024*256,1024*256);
    214214  this->rcv_buf_size = rcv_buf_size;
    215215
  • trunk/lib/FlairCore/src/Matrix.cpp

    r213 r214  
    1919#include <typeinfo>
    2020#include <string.h>
    21 
    22 //#include <iostream>
    2321
    2422using std::string;
     
    3735    this->col = col;
    3836    if (row >= matrix->Rows() || col >= matrix->Cols()) {
    39       matrix->Err("index (%i,%i) out of bound (%i,%i)\n", row, col,
     37      matrix->Err("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    4038                  matrix->Rows() - 1, matrix->Cols() - 1);
    4139      size = 0;
     
    7169      } break;
    7270      }
     71    } else if (typeid(matrix->GetDataType().GetElementDataType()) ==
     72               typeid(UnsignedIntegerType)) {
     73      switch (matrix->GetDataType().GetElementDataType().GetSize()) {
     74      case 1: {
     75        uint8_t uint8Value = matrix->Value(row, col);
     76        memcpy(dst, &uint8Value, 1);
     77      } break;
     78      case 2: {
     79        uint16_t uint16Value = matrix->Value(row, col);
     80        memcpy(dst, &uint16Value, 2);
     81      } break;
     82      }
    7383    }
    7484  }
     
    133143  if (row >= (uint32_t)pimpl_->descriptor->Rows() ||
    134144      col >= (uint32_t)pimpl_->descriptor->Cols()) {
    135     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     145    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    136146         pimpl_->descriptor->Rows() - 1, pimpl_->descriptor->Cols() - 1);
    137147    return 0;
     
    139149
    140150  GetMutex();
    141   value = pimpl_->datas[row][col];
     151  value = pimpl_->ValueNoMutex(row, col);
    142152  ReleaseMutex();
    143153
     
    148158  if (row >= (uint32_t)pimpl_->descriptor->Rows() ||
    149159      col >= (uint32_t)pimpl_->descriptor->Cols()) {
    150     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     160    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    151161         pimpl_->descriptor->Rows() - 1, pimpl_->descriptor->Cols() - 1);
    152162    return 0;
    153163  }
    154164
    155   return pimpl_->datas[row][col];
     165  return pimpl_->ValueNoMutex(row, col);
    156166}
    157167
     
    159169  if (row >= (uint32_t)pimpl_->descriptor->Rows() ||
    160170      col >= (uint32_t)pimpl_->descriptor->Cols()) {
    161     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     171    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    162172         pimpl_->descriptor->Rows() - 1, pimpl_->descriptor->Cols() - 1);
    163173  } else {
    164174    GetMutex();
    165     pimpl_->datas[row][col]=value;
     175    pimpl_->SetValueNoMutex(row, col,value);
    166176    ReleaseMutex();
    167177  }
     
    171181  if (row >= (uint32_t)pimpl_->descriptor->Rows() ||
    172182      col >= (uint32_t)pimpl_->descriptor->Cols()) {
    173     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     183    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    174184         pimpl_->descriptor->Rows() - 1, pimpl_->descriptor->Cols() - 1);
    175185  } else {
    176     pimpl_->datas[row][col]=value;
     186    pimpl_->SetValueNoMutex(row, col,value);
    177187  }
    178188}
     
    180190void Matrix::CopyDatas(char *dst) const {
    181191  GetMutex();
    182   // printf("%f %x %i\n",cvGetReal2D(pimpl_->mat,0,0),dst,Size());
    183192  memcpy(dst, pimpl_->datas, dataType.GetSize());
    184193  ReleaseMutex();
  • trunk/lib/FlairCore/src/Matrix.h

    r213 r214  
    2727* \brief Class defining a matrix
    2828*
    29 * Only supports float for the moment
    30 * TODO: write a template
    3129*
    3230*/
     
    196194
    197195  Type const &GetDataType() const { return dataType; };
    198 
     196void CopyDatas(char *dst) const;
    199197private:
    200198  /*!
     
    206204  * \param dst destination buffer
    207205  */
    208   void CopyDatas(char *dst) const;
     206  //void CopyDatas(char *dst) const;
    209207
    210208  class Matrix_impl *pimpl_;
  • 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}
  • trunk/lib/FlairCore/src/RangeFinderPlot.cpp

    r137 r214  
    1818
    1919#include "RangeFinderPlot.h"
    20 #include "cvmatrix.h"
    21 #include "Layout.h"
     20#include "Matrix.h"
    2221#include "LayoutPosition.h"
    2322#include <cxcore.h>
     
    3231                                 string x_name, float xmin, float xmax,
    3332                                 string y_name, float ymin, float ymax,
    34                                  const cvmatrix *datas, float start_angle,
     33                                 const Matrix *datas, float start_angle,
    3534                                 float end_angle, uint32_t nb_samples)
    3635    : SendData(position, name, "RangeFinderPlot", 200) {
    3736  this->datas = datas;
    38 
     37Warn("RangeFinderPlot::CopyDatas needs to be written\n");
    3938  SetSendSize(datas->GetDataType().GetSize());
    4039
     
    5958
    6059void RangeFinderPlot::CopyDatas(char *buf) const {
    61   datas->GetMutex();
    62   memcpy(buf, datas->getCvMat()->data.ptr, datas->GetDataType().GetSize());
    63   datas->ReleaseMutex();
     60  //datas->CopyDatas(buf);
    6461}
    6562
  • trunk/lib/FlairCore/src/RangeFinderPlot.h

    r15 r214  
    2020namespace flair {
    2121namespace core {
    22 class cvmatrix;
     22class Matrix;
    2323}
    2424}
     
    6161                  std::string x_name, float xmin, float xmax,
    6262                  std::string y_name, float ymin, float ymax,
    63                   const core::cvmatrix *datas, float start_angle,
     63                  const core::Matrix *datas, float start_angle,
    6464                  float end_angle, uint32_t nb_samples);
    6565
     
    8787  void ExtraXmlEvent(void){};
    8888
    89   const core::cvmatrix *datas;
     89  const core::Matrix *datas;
    9090};
    9191
  • trunk/lib/FlairCore/src/cvmatrix.cpp

    r15 r214  
    3737    this->col = col;
    3838    if (row >= matrix->Rows() || col >= matrix->Cols()) {
    39       matrix->Err("index (%i,%i) out of bound (%i,%i)\n", row, col,
     39      matrix->Err("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    4040                  matrix->Rows() - 1, matrix->Cols() - 1);
    4141      size = 0;
     
    133133  if (row >= (uint32_t)pimpl_->mat->rows ||
    134134      col >= (uint32_t)pimpl_->mat->cols) {
    135     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     135    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    136136         pimpl_->mat->rows - 1, pimpl_->mat->cols - 1);
    137137    return 0;
     
    148148  if (row >= (uint32_t)pimpl_->mat->rows ||
    149149      col >= (uint32_t)pimpl_->mat->cols) {
    150     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     150    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    151151         pimpl_->mat->rows - 1, pimpl_->mat->cols - 1);
    152152    return 0;
     
    159159  if (row >= (uint32_t)pimpl_->mat->rows ||
    160160      col >= (uint32_t)pimpl_->mat->cols) {
    161     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     161    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    162162         pimpl_->mat->rows - 1, pimpl_->mat->cols - 1);
    163163  } else {
     
    171171  if (row >= (uint32_t)pimpl_->mat->rows ||
    172172      col >= (uint32_t)pimpl_->mat->cols) {
    173     Warn("index (%i,%i) out of bound (%i,%i)\n", row, col,
     173    Warn("index (%i,%i) out of bound, max (%i,%i)\n", row, col,
    174174         pimpl_->mat->rows - 1, pimpl_->mat->cols - 1);
    175175  } else {
  • trunk/lib/FlairCore/src/cvmatrix_descriptor.cpp

    r15 r214  
    4646                                         string name) {
    4747  if (row >= rows || col >= cols) {
    48     getFrameworkManager()->Err("index out of bound %s (%i,%i), range (%i,%i)\n",
     48    getFrameworkManager()->Err("index out of bound %s (%i,%i), max (%i,%i)\n",
    4949                               name.c_str(), row, col, rows - 1, cols - 1);
    5050    return;
     
    5555string cvmatrix_descriptor::ElementName(uint32_t row, uint32_t col) const {
    5656  if (row >= rows || col >= cols) {
    57     getFrameworkManager()->Err("index out of bound (%i,%i), range (%i,%i)\n",
     57    getFrameworkManager()->Err("index out of bound (%i,%i), max (%i,%i)\n",
    5858                               row, col, rows - 1, cols - 1);
    5959    return *element_names[0]; // safe value...
  • trunk/lib/FlairCore/src/unexported/Matrix_impl.h

    r213 r214  
    3333  flair::core::ScalarType const &elementDataType;
    3434  flair::core::cvmatrix_descriptor *descriptor;
    35   float **datas;
     35  void *datas;
     36  void SetValueNoMutex(uint32_t row, uint32_t col, float value);
     37  float ValueNoMutex(uint32_t row, uint32_t col) const;
    3638
    3739private:
  • trunk/lib/FlairCore/src/unexported/config.h

    r213 r214  
    2727
    2828// nrt pipe size
    29 #define NRT_PIPE_SIZE 1024 * 100
     29#define NRT_PIPE_SIZE 1024 * 100*10
    3030
    3131// rt log heap size
Note: See TracChangeset for help on using the changeset viewer.