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 |
|
---|
23 | using std::string;
|
---|
24 | using namespace flair::core;
|
---|
25 |
|
---|
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);
|
---|
32 | }
|
---|
33 |
|
---|
34 | cvmatrix_impl::cvmatrix_impl(cvmatrix *self,
|
---|
35 | const cvmatrix_descriptor *inDescriptor,
|
---|
36 | flair::core::ScalarType const &_elementDataType,
|
---|
37 | int n)
|
---|
38 | : elementDataType(_elementDataType) {
|
---|
39 | descriptor = new cvmatrix_descriptor(inDescriptor->Rows(), inDescriptor->Cols());
|
---|
40 |
|
---|
41 | for (uint32_t i = 0; i < descriptor->Rows(); i++) {
|
---|
42 | for (uint32_t j = 0; j < descriptor->Cols(); j++) {
|
---|
43 | descriptor->SetElementName(i, j, inDescriptor->ElementName(i, j));
|
---|
44 | }
|
---|
45 | }
|
---|
46 | Init(self, n);
|
---|
47 | }
|
---|
48 |
|
---|
49 | void cvmatrix_impl::Init(cvmatrix *self, int n) {
|
---|
50 | this->self = self;
|
---|
51 |
|
---|
52 | mat = nullptr;
|
---|
53 | try {
|
---|
54 | ScalarType const &scalarType =
|
---|
55 | dynamic_cast<ScalarType const &>(elementDataType);
|
---|
56 | if (typeid(scalarType) == typeid(FloatType)) {
|
---|
57 | mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_32FC1);
|
---|
58 | } else if (typeid(scalarType) == typeid(SignedIntegerType)) {
|
---|
59 | switch (elementDataType.GetSize()) {
|
---|
60 | case 1:
|
---|
61 | mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_8SC1);
|
---|
62 | break;
|
---|
63 | case 2:
|
---|
64 | mat = cvCreateMat(descriptor->Rows(), descriptor->Cols(), CV_16SC1);
|
---|
65 | break;
|
---|
66 | default:
|
---|
67 | self->Err("unsupported integer scalar type\n");
|
---|
68 | }
|
---|
69 | } else {
|
---|
70 | self->Err("unsupported scalar type\n");
|
---|
71 | }
|
---|
72 | } catch (std::bad_cast e) {
|
---|
73 | self->Err("type is not a scalar\n");
|
---|
74 | }
|
---|
75 |
|
---|
76 | if (mat == nullptr)
|
---|
77 | self->Err("allocating matrix failed\n");
|
---|
78 | if (n > 1)
|
---|
79 | self->Warn("n>1 not supported\n");
|
---|
80 | }
|
---|
81 |
|
---|
82 | cvmatrix_impl::~cvmatrix_impl() {
|
---|
83 | cvReleaseMat(&mat);
|
---|
84 | delete descriptor;
|
---|
85 | }
|
---|