[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 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 |
|
---|
| 23 | using std::string;
|
---|
| 24 | using namespace flair::core;
|
---|
| 25 |
|
---|
[15] | 26 | cvmatrix_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);
|
---|
[2] | 32 | }
|
---|
| 33 |
|
---|
[15] | 34 | cvmatrix_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);
|
---|
[2] | 41 | }
|
---|
| 42 |
|
---|
[15] | 43 | void cvmatrix_impl::Init(cvmatrix *self, int n) {
|
---|
| 44 | this->self = self;
|
---|
[2] | 45 |
|
---|
[15] | 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");
|
---|
[2] | 65 | }
|
---|
[15] | 66 | } catch (std::bad_cast e) {
|
---|
| 67 | self->Err("type is not a scalar\n");
|
---|
| 68 | }
|
---|
[2] | 69 |
|
---|
[15] | 70 | if (mat == nullptr)
|
---|
| 71 | self->Err("allocating matrix failed\n");
|
---|
| 72 | if (n > 1)
|
---|
| 73 | self->Warn("n>1 not supported\n");
|
---|
[2] | 74 | }
|
---|
| 75 |
|
---|
| 76 | cvmatrix_impl::~cvmatrix_impl() {
|
---|
[15] | 77 | cvReleaseMat(&mat);
|
---|
| 78 | delete descriptor;
|
---|
[2] | 79 | }
|
---|