zoukankan      html  css  js  c++  java
  • halcon基础数据类型详解

    #if defined(__CHAR_UNSIGNED__) || defined(__sgi) 
    #define  INT1      signed char       /* integer, signed 1 Byte         */
    #define  INT1_MIN  SCHAR_MIN
    #define  INT1_MAX  SCHAR_MAX
    #else
    #define  INT1      char              /* integer, signed 1 Byte         */
    #define  INT1_MIN  CHAR_MIN
    #define  INT1_MAX  CHAR_MAX
    #endif
    #define  UINT1     unsigned char     /* integer, unsigned 1 Byte       */
    #define  UINT1_MIN 0
    #define  UINT1_MAX UCHAR_MAX
    
    #define LONG_FORMAT _INT64_FORMAT
    typedef INT4_8  Hlong;
    typedef UINT4_8 Hulong;
    
    

      看粗体部分,可以看到 Hlong型在32位的机器上其实就是long型 代表4个字节 32位,在64位机器上有另一种定义

      再来看看halcon中最重要的数据类型HTuple,在C++里面,halcon将HTuple类型封装了类,其始祖类HRootObject,这个类相当于MFC里面的CObject,halcon从HRootObject派生了HBaseArray,当然这两个类是虚基类,有一些方法需要我HTuple自己实现,当然也有一些方法可以直接用的。这两个类在HCPPUtil里,可以看看。

      HTuple类就是从HBaseArray派生,元组基类,相当于数组,具有如下的构造函数:

      

      HTuple(int l);
      HTuple(float f);
      HTuple(double d);
      HTuple(const char *s);
      HTuple(const HCtrlVal &c);
      HTuple(const HTuple &in):HBaseArray() {CopyTuple(in);}
      HTuple(Hlong length, const HTuple &value);
      HTuple(const HTuple &length, const HTuple &value);
      HTuple(SpecialTuple d);

      

      HTuple对各种操作符进行了重载:

      operator     HCtrlVal(void) const;
      HTuple       operator () (Hlong min, Hlong max) const;
      HTuple       operator () (const HTuple &min, const HTuple &max) const;
      HCtrlVal    &operator [] (Hlong index);
      HCtrlVal     operator [] (Hlong index) const;
      HCtrlVal    &operator [] (const HTuple &index);
      HCtrlVal     operator [] (const HTuple &index) const;
      HTuple      &operator ++ (void); // nur fuer double und Hlong
      HBool        operator !  (void) const;
      HTuple       operator ~  (void) const;
      HTuple       operator << (const HTuple &val) const;
      HTuple       operator << (Hlong val) const;
      HTuple       operator >> (const HTuple &val) const;
      HTuple       operator >> (Hlong val) const;
      HTuple       operator +  (const HTuple &val) const;
      HTuple       operator +  (double val) const;
      HTuple       operator +  (int val) const;

      在讲解halcon是如何维护这样一个HTuple中各种数据之前 ,先来看看这样一个类:

      

    class LIntExport HCtrlVal  {
      friend class HTuple;
    public:
      HCtrlVal(void)      {val.type  = UndefVal;  val.par.l = 0;}
    #if !defined(_TMS320C6X)
      HCtrlVal(Hlong l)   {val.type  = LongVal;   val.par.l = l;}
    #endif
      HCtrlVal(int l)     {val.type  = LongVal;   val.par.l = l;}
      HCtrlVal(double d)  {val.type  = DoubleVal; val.par.f = d;}
      HCtrlVal(const char *s);
      HCtrlVal(const HCtrlVal &v) {CopyCtrlVal(v);}
      ~HCtrlVal(void)             {ClearCtrlVal();}
      HCtrlVal& operator = (const HCtrlVal &v);
     
      // Type conversion
      int         ValType() const          {return val.type;}
      operator    int(void) const          {return I();}
    #if !defined(_TMS320C6X)
      operator    Hlong(void) const        {return L();}
    #endif
      operator    double(void) const       {return D();}
      operator    const char*(void) const  {return S();}
      operator    const Hcpar&(void)const  {return HCPAR();}
      // Access contents
      double          D() const;
      Hlong           L() const;
      int             I() const;
      const char *    S() const;
      const Hcpar&    HCPAR()const;
      // Arithmetics
      HCtrlVal     operator + (const HCtrlVal &val) const;
      HTuple       operator + (const HTuple &val) const;
      HCtrlVal     operator - (const HCtrlVal &val) const;
      HTuple       operator - (const HTuple &val) const;
      HCtrlVal     operator * (const HCtrlVal &val) const;
      HTuple       operator * (const HTuple &val) const;
      HCtrlVal     operator / (const HCtrlVal &val) const;
      HTuple       operator / (const HTuple &val) const;
      HCtrlVal     operator % (const HCtrlVal &val) const;
      HTuple       operator % (const HTuple &val) const;
      HBool        operator != (const HCtrlVal &val) const;
      HBool        operator != (const HTuple &val) const;
      HBool        operator == (const HCtrlVal &val) const;
      HBool        operator == (const HTuple &val) const;
      HBool        operator >= (const HCtrlVal &val) const;
      HBool        operator >= (const HTuple &val) const;
      HBool        operator <= (const HCtrlVal &val) const;
      HBool        operator <= (const HTuple &val) const;
      HBool        operator > (const HCtrlVal &val) const;
      HBool        operator > (const HTuple &val) const;
      HBool        operator < (const HCtrlVal &val) const;
      HBool        operator < (const HTuple &val) const;
    
      const char *ClassName(void) const { return "HCtrlVal"; }
      int Version(void) const;
      int Revision(void) const;
      const char *Creation(void) const;
      
    private:
      // Data
      Hcpar       val;        // Value: one of the three types and type specifyer
      // Support operationen
      void ClearCtrlVal();
      void CopyCtrlVal(const HCtrlVal& source);
    };
    typedef struct
    {
      Hpar   par;             /* values                                          */
      INT1   type;            /* type flag                                       */
    } Hcpar;                  /* parameter passing for the C interface           */
    typedef union 
    {
      INT4_8  l;              /* 4/8 byte integer                       (input)  */
      double  f;              /* 8 byte real                            (input)  */
      char    *s;             /* pointer to strings                     (input)  */
    } Hpar;                   /* parameter passing for the C interface           */
    typedef union 
    {
      INT4_8  *l;             /* 4/8 byte integer                       (output) */
      double  *f;             /* 8 byte real                            (output) */
      char    *s;             /* pointer to strings                     (output) */
      VOIDP   p;              /* pointer to var. of any type (e.g. tuple)(output)*/
    } Hvar;                   /* parameter passing for the C interface           */

      仔细看我用红色粗体并加大的部分,这四段代码可以说是halcon维护HTuple这种数据类型的精髓了。下面我们来讲解一下:

      首先HTuple类中有私有成员变量:

    private:
      HCtrlVal    *tuple;       // values (array of Hlong/float/string)

      halcon给的注释写的很清楚,tuple是一群值,指向一个数组,数组里面有long型,浮点型及字符串型数据。这是一个指针,这个类就是维护这样一个指针,具体此指针的内容,我们往下看HCtrlVal: (这里说一下这几个单词的意义吧:H->Halcon   Ctrl->Control   Val->Values  表示Halcon的控制变量,当然还有图形变量,以后再讲吧。)

    private:
      // Data
      Hcpar       val;        // Value: one of the three types and type specifyer

      HCtrlVal类就维护了这样一个成员变量,halcon给的注释是说 val 代表数据的三种类型中的一个,并指向一个值。那么HTuple中的tuple指针就是维护了val组成的链表,这样HTuple就可以维护多种不同类型的数据。

      HTuple用起来的确很方便,halcon对其进行了大量的运算符重载包括像强制类型转换,都不需要我们手动去做,只需要在前面加个数据类型就行了。

      好了,由于本人水平有限,文中可能会有纰漏,敬请指出!

      added by xiejl

  • 相关阅读:
    Mac php使用gd库出错 Call to undefined function imagettftext()
    centos 使用 locate
    Mac HomeBrew 安装 mysql
    zsh 命令提示符 PROMPT
    新的开始
    Java 面试题分析
    Java NIO Show All Files
    正确使用 Volatile 变量
    面试题整理 2017
    有10阶梯, 每次走1,2 or 3 阶,有多少种方式???
  • 原文地址:https://www.cnblogs.com/xiejiulong/p/3819608.html
Copyright © 2011-2022 走看看