// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2018/01/30 // filename: Matrix_impl.cpp // // author: Guillaume Sanahuja // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: classe definissant le type de données Matrix // /*********************************************************************/ #include "Matrix.h" #include "Matrix_impl.h" #include #include using std::string; using namespace flair::core; Matrix_impl::Matrix_impl(Matrix *self, int rows, int cols, flair::core::ScalarType const &_elementDataType, int n) : elementDataType(_elementDataType) { descriptor = new cvmatrix_descriptor(rows, cols); Init(self, n); } Matrix_impl::Matrix_impl(Matrix *self, const cvmatrix_descriptor *inDescriptor, flair::core::ScalarType const &_elementDataType, int n) : elementDataType(_elementDataType) { descriptor = new cvmatrix_descriptor(inDescriptor->Rows(), inDescriptor->Cols()); for (uint32_t i = 0; i < descriptor->Rows(); i++) { for (uint32_t j = 0; j < descriptor->Cols(); j++) { descriptor->SetElementName(i, j, inDescriptor->ElementName(i, j)); } } Init(self, n); } void Matrix_impl::Init(Matrix *self, int n) { this->self = self; datas = nullptr; try { ScalarType const &scalarType = dynamic_cast(elementDataType); if (typeid(scalarType) == typeid(FloatType)) { datas = (float **)malloc(descriptor->Rows() * sizeof(float*)); if(datas==NULL) { self->Err("error allocating matrix\n"); return; } for(uint32_t i=0 ; i < descriptor->Rows() ; i++){ datas[i] = (float*)malloc(descriptor->Cols() * sizeof(float) ); if(datas[i]==NULL) { self->Err("error allocating matrix\n"); for(uint32_t j = i-1 ; j >= 0 ; j--) free(datas[j]); free(datas); return; } } /* } else if (typeid(scalarType) == typeid(SignedIntegerType)) { switch (elementDataType.GetSize()) { case 1: mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_8SC1); break; case 2: mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_16SC1); break; default: self->Err("unsupported integer scalar type\n"); }*/ } else { self->Err("unsupported scalar type\n"); } } catch (std::bad_cast e) { self->Err("type is not a scalar\n"); } if (datas == nullptr) self->Err("allocating matrix failed\n"); if (n > 1) self->Warn("n>1 not supported\n"); } Matrix_impl::~Matrix_impl() { for (uint32_t i = 0; i < descriptor->Rows();i++) { free(datas[i]); } free(datas); delete descriptor; }