/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// Intel License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, all rights reserved.13// Third party copyrights are property of their respective icvers.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of Intel Corporation may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "opencv2/core/base.hpp"4243#ifndef __OPENCV_DENOISING_ARRAYS_HPP__44#define __OPENCV_DENOISING_ARRAYS_HPP__4546namespace cv47{4849template <class T>50struct Array2d51{52T* a;53int n1,n2;54bool needToDeallocArray;5556Array2d(const Array2d& array2d):57a(array2d.a), n1(array2d.n1), n2(array2d.n2), needToDeallocArray(false)58{59if (array2d.needToDeallocArray)60{61CV_Error(Error::BadDataPtr, "Copy constructor for self allocating arrays not supported");62}63}6465Array2d(T* _a, int _n1, int _n2):66a(_a), n1(_n1), n2(_n2), needToDeallocArray(false)67{68}6970Array2d(int _n1, int _n2):71n1(_n1), n2(_n2), needToDeallocArray(true)72{73a = new T[n1*n2];74}7576~Array2d()77{78if (needToDeallocArray)79delete[] a;80}8182T* operator [] (int i)83{84return a + i*n2;85}8687inline T* row_ptr(int i)88{89return (*this)[i];90}91};9293template <class T>94struct Array3d95{96T* a;97int n1,n2,n3;98bool needToDeallocArray;99100Array3d(T* _a, int _n1, int _n2, int _n3):101a(_a), n1(_n1), n2(_n2), n3(_n3), needToDeallocArray(false)102{103}104105Array3d(int _n1, int _n2, int _n3):106n1(_n1), n2(_n2), n3(_n3), needToDeallocArray(true)107{108a = new T[n1*n2*n3];109}110111~Array3d()112{113if (needToDeallocArray)114delete[] a;115}116117Array2d<T> operator [] (int i)118{119Array2d<T> array2d(a + i*n2*n3, n2, n3);120return array2d;121}122123inline T* row_ptr(int i1, int i2)124{125return a + i1*n2*n3 + i2*n3;126}127};128129template <class T>130struct Array4d131{132T* a;133int n1,n2,n3,n4;134bool needToDeallocArray;135int steps[4];136137void init_steps()138{139steps[0] = n2*n3*n4;140steps[1] = n3*n4;141steps[2] = n4;142steps[3] = 1;143}144145Array4d(T* _a, int _n1, int _n2, int _n3, int _n4) :146a(_a), n1(_n1), n2(_n2), n3(_n3), n4(_n4), needToDeallocArray(false)147{148init_steps();149}150151Array4d(int _n1, int _n2, int _n3, int _n4) :152n1(_n1), n2(_n2), n3(_n3), n4(_n4), needToDeallocArray(true)153{154a = new T[n1*n2*n3*n4];155init_steps();156}157158~Array4d()159{160if (needToDeallocArray)161delete[] a;162}163164Array3d<T> operator [] (int i)165{166Array3d<T> array3d(a + i*n2*n3*n4, n2, n3, n4);167return array3d;168}169170inline T* row_ptr(int i1, int i2, int i3)171{172return a + i1*n2*n3*n4 + i2*n3*n4 + i3*n4;173}174175inline int step_size(int dimension)176{177return steps[dimension];178}179};180181}182183#endif184185186