⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edgelattice.hh

📁 用于计算矩阵的特征值,及矩阵的其他运算.可以用与稀疏矩阵
💻 HH
字号:

#ifndef __EdgeLattice_hh__
#define __EdgeLattice_hh__

#include <math.h>
#include <assert.h>

// Pixel edge lattice template class.
// Pixel centers are at (0,0)..(w-1,h-1).
// Horizontal edges are at (0,.5)..(w-1,h-1-.5).
// Vertical edges are at (.5,0)..(w-1-.5,h-1).

template<class T>
class EdgeLattice
{
public:
    EdgeLattice () 
        : h(0,0), v(0,0), width(0), height(0)
        {}
    EdgeLattice (int _width, int _height) 
        : h(_width,_height-1),
          v(_width-1,_height),
          width(_width),
          height(_height)
        {}
    int getWidth () const { return width; }
    int getHeight () const { return height; }
    bool issize (const int _width, const int _height) const {
        return (width == _width) && (height == _height);
    }
    void init (T x) {
        h.init(x); v.init(x);
    }
    void resize (const int _width, const int _height) {
        h.resize(_width,_height-1);
        v.resize(_width-1,_height);
        width = _width;
        height = _height;
    }
    // Is (x,y) a valid pixel edge coordinate?
    bool valid (const double x, const double y) const { 
        return x >= 0 && x <= width-1
            && y >= 0 && y <= height-1
            && (isH(x,y) || isV(x,y));
    }
    // Does (x,y) denote a horizontal pixel edge?
    static bool isH (const double x, const double y) {
        return (x - floor(x) == 0) && (y - floor(y) == 0.5);
    }
    // Does (x,y) denote a vertical pixel edge?
    static bool isV (const double x, const double y) {
        return (x - floor(x) == 0.5) && (y - floor(y) == 0);
    }
    // Read-only accessor.
    const T& operator() (const double x, const double y) const {
        assert(valid(x,y));
        const int i = (int) floor (x);
        const int j = (int) floor (y);
        return isH(x,y) ? h(i,j) : v(i,j);
    }
    // Read-write accessor.
    T& operator() (const double x, const double y) {
        assert(valid(x,y));
        const int i = (int) floor (x);
        const int j = (int) floor (y);
        return isH(x,y) ? h(i,j) : v(i,j);
    }
private:
    Util::Array2D<T> h,v;
    int width, height;
};

#endif // __EdgeLattice_hh__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -