source: flair-src/trunk/lib/FlairCore/src/cvmatrix_impl.cpp @ 67

Last change on this file since 67 was 15, checked in by Bayard Gildas, 6 years ago

sources reformatted with flair-format-dir script

File size: 2.2 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5//  created:    2012/03/21
6//  filename:   cvmatrix_impl.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    classe definissant le type de données "CvMat"
14//
15/*********************************************************************/
16
17#include "cvmatrix.h"
18#include "cvmatrix_impl.h"
19#include <cxcore.h>
20#include <typeinfo>
21#include <sstream>
22
23using std::string;
24using namespace flair::core;
25
26cvmatrix_impl::cvmatrix_impl(cvmatrix *self, int rows, int cols,
27                             flair::core::ScalarType const &_elementDataType,
28                             int n)
29    : elementDataType(_elementDataType) {
30  descriptor = new cvmatrix_descriptor(rows, cols);
31  Init(self, n);
32}
33
34cvmatrix_impl::cvmatrix_impl(cvmatrix *self,
35                             const cvmatrix_descriptor *descriptor,
36                             flair::core::ScalarType const &_elementDataType,
37                             int n)
38    : elementDataType(_elementDataType) {
39  this->descriptor = descriptor;
40  Init(self, n);
41}
42
43void cvmatrix_impl::Init(cvmatrix *self, int n) {
44  this->self = self;
45
46  mat = nullptr;
47  try {
48    ScalarType const &scalarType =
49        dynamic_cast<ScalarType const &>(elementDataType);
50    if (typeid(scalarType) == typeid(FloatType)) {
51      mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_32FC1);
52    } else if (typeid(scalarType) == typeid(SignedIntegerType)) {
53      switch (elementDataType.GetSize()) {
54      case 1:
55        mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_8SC1);
56        break;
57      case 2:
58        mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_16SC1);
59        break;
60      default:
61        self->Err("unsupported integer scalar type\n");
62      }
63    } else {
64      self->Err("unsupported scalar type\n");
65    }
66  } catch (std::bad_cast e) {
67    self->Err("type is not a scalar\n");
68  }
69
70  if (mat == nullptr)
71    self->Err("allocating matrix failed\n");
72  if (n > 1)
73    self->Warn("n>1 not supported\n");
74}
75
76cvmatrix_impl::~cvmatrix_impl() {
77  cvReleaseMat(&mat);
78  delete descriptor;
79}
Note: See TracBrowser for help on using the repository browser.