Zivid  1.0.1+3607.8a7510c4
Zivid API
Point.h
Go to the documentation of this file.
1 /*[
2  * This file is part of the Zivid 3D Camera API
3  *
4  * Copyright 2015-2018 (C) Zivid Labs. All rights reserved.
5  * Contact info@zividlabs.com or see http://www.zividlabs.com
6  *
7  * This code is proprietary and confidential.
8  * Unauthorized copying of this file, via any medium is strictly prohibited.
9 ]*/
10 
11 #pragma once
12 
15 
16 #include <cstdint>
17 #include <numeric>
18 #include <limits>
19 #include <cstring>
20 #include <cmath>
21 
22 #ifdef _MSC_VER
23 #pragma warning(push)
24 #pragma warning(disable:4251)
25 #endif
26 
27 namespace Zivid
28 {
30  class Point
31  {
32  public:
33  float x;
34  float y;
35  float z;
36  float contrast;
37  uint32_t rgba;
38 
40  Point() :
41  x{ 0.0f },
42  y{ 0.0f },
43  z{ 0.0f },
44  contrast{ 0.0f },
45  rgba{ 0xff000000 }
46  {}
47 
49  void setNaN()
50  {
51  x = y = z = std::numeric_limits<float>::quiet_NaN();
52  }
53 
55  bool isNaN() const
56  {
57  return std::isnan(z);
58  }
59 
61  inline void setRgba(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
62  {
63  this->rgba = static_cast<uint32_t>((a << 24) | (r << 16) | (g << 8) | b);
64  }
65 
67  inline void setRgb(unsigned char r, unsigned char g, unsigned char b)
68  {
69  setRgba(r,g,b,255);
70  }
71 
73  inline void setIntensity(unsigned char val)
74  {
75  setRgb(val,val,val);
76  }
77 
79  inline void setContrast(float value)
80  {
81  this->contrast = value;
82  }
83 
85  inline unsigned char alpha()
86  {
87  return (this->rgba >> 24) & 0xff;
88  }
89 
91  inline unsigned char red() const
92  {
93  return (this->rgba >> 16) & 0xff;
94  }
95 
97  inline unsigned char green() const
98  {
99  return (this->rgba >> 8) & 0xff;
100  }
101 
103  inline unsigned char blue() const
104  {
105  return (this->rgba & 0xff);
106  }
107 
109  inline unsigned char intensity()
110  {
111  unsigned short r = red();
112  unsigned short g = green();
113  unsigned short b = blue();
114  return static_cast<unsigned char>((r+g+b)/3);
115  }
116  };
117 }
118 
119 #ifdef _MSC_VER
120 #pragma warning(pop)
121 #endif
uint32_t rgba
Color (red,green,blue,alpha)
Definition: Point.h:37
unsigned char intensity()
Get the intensity of the point.
Definition: Point.h:109
unsigned char green() const
Get the green color value for the point.
Definition: Point.h:97
void setRgb(unsigned char r, unsigned char g, unsigned char b)
Set the r,g,b color value for the point.
Definition: Point.h:67
float z
Z coordinate.
Definition: Point.h:35
float y
Y coordinate.
Definition: Point.h:34
float x
X coordinate.
Definition: Point.h:33
unsigned char red() const
Get the red color value for the point.
Definition: Point.h:91
Definition: Application.h:19
bool isNaN() const
Check whether the point is valid (Not-a-Number)
Definition: Point.h:55
void setRgba(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Set the r,g,b and alpha color value for the point.
Definition: Point.h:61
void setNaN()
Invalidate the point (set it to Not-a-Number)
Definition: Point.h:49
unsigned char blue() const
Get the blue color value for the point.
Definition: Point.h:103
void setContrast(float value)
Set the contrast for the point.
Definition: Point.h:79
void setIntensity(unsigned char val)
Set the intensity for the point (sets r,g and b to identical values)
Definition: Point.h:73
A 3D point with contrast and RGBA values.
Definition: Point.h:30
float contrast
Contrast.
Definition: Point.h:36
unsigned char alpha()
Get the alpha value for the point.
Definition: Point.h:85
Point()
Construct a 3D point at (0,0,0) with contrast 0 and color values (r,g,b,a) = (0,0,0,255)
Definition: Point.h:40