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

Last change on this file since 2 was 2, checked in by Sanahuja Guillaume, 7 years ago

flaircore

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,flair::core::ScalarType const &_elementDataType,int n):elementDataType(_elementDataType) {
27 descriptor=new cvmatrix_descriptor(rows,cols);
28 Init(self,n);
29}
30
31cvmatrix_impl::cvmatrix_impl(cvmatrix* self,const cvmatrix_descriptor *descriptor,flair::core::ScalarType const &_elementDataType,int n):elementDataType(_elementDataType) {
32 this->descriptor=descriptor;
33 Init(self,n);
34}
35
36void cvmatrix_impl::Init(cvmatrix* self,int n) {
37 this->self=self;
38
39 mat=nullptr;
40 try {
41 ScalarType const &scalarType=dynamic_cast<ScalarType const &>(elementDataType);
42 if (typeid(scalarType)==typeid(FloatType)) {
43 mat=cvCreateMat(descriptor->Rows(),descriptor->Cols(),CV_32FC1);
44 } else if (typeid(scalarType)==typeid(SignedIntegerType)) {
45 switch(elementDataType.GetSize()) {
46 case 1:
47 mat=cvCreateMat(descriptor->Rows(),descriptor->Cols(),CV_8SC1);
48 break;
49 case 2:
50 mat=cvCreateMat(descriptor->Rows(),descriptor->Cols(),CV_16SC1);
51 break;
52 default:
53 self->Err("unsupported integer scalar type\n");
54 }
55 } else {
56 self->Err("unsupported scalar type\n");
57 }
58 } catch(std::bad_cast e) {
59 self->Err("type is not a scalar\n");
60 }
61
62 if(mat==nullptr) self->Err("allocating matrix failed\n");
63 if(n>1) self->Warn("n>1 not supported\n");
64}
65
66cvmatrix_impl::~cvmatrix_impl() {
67 cvReleaseMat(&mat);
68 delete descriptor;
69}
Note: See TracBrowser for help on using the repository browser.