Zivid C++ API  1.8.1+6967bc1b-1
Defining the Future of 3D Machine Vision
Point.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * This file is part of the Zivid 3D Camera API
4  *
5  * Copyright 2015-2020 (C) Zivid AS
6  * All rights reserved.
7  *
8  * Zivid Software License, v1.0
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of Zivid AS nor the names of its contributors may be used
21  * to endorse or promote products derived from this software without specific
22  * prior written permission.
23  *
24  * 4. This software, with or without modification, must not be used with any
25  * other 3D camera than from Zivid AS.
26  *
27  * 5. Any software provided in binary form under this license must not be
28  * reverse engineered, decompiled, modified and/or disassembled.
29  *
30  * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
31  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Contact: Zivid Support <support@zivid.com>
42  * Info: http://www.zivid.com
43  ******************************************************************************/
44 
45 #pragma once
46 
47 #include <cmath>
48 #include <cstdint>
49 #include <cstring>
50 #include <limits>
51 #include <numeric>
52 
53 namespace Zivid
54 {
56  class Point
57  {
58  public:
59  float x;
60  float y;
61  float z;
62  float contrast;
63  uint32_t rgba;
64 
66  Point()
67  : x{ 0.0F }
68  , y{ 0.0F }
69  , z{ 0.0F }
70  , contrast{ 0.0F }
71  , rgba{ 0xff000000 }
72  {}
73 
75  void setNaN()
76  {
77  x = y = z = std::numeric_limits<float>::quiet_NaN();
78  }
79 
81  bool isNaN() const
82  {
83  return std::isnan(z);
84  }
85 
87  inline void setRgba(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
88  {
89  rgba = static_cast<uint32_t>((a << 24) | (r << 16) | (g << 8) | b);
90  }
91 
93  inline void setRgb(unsigned char r, unsigned char g, unsigned char b)
94  {
95  setRgba(r, g, b, 255);
96  }
97 
99  inline void setIntensity(unsigned char val)
100  {
101  setRgb(val, val, val);
102  }
103 
105  inline void setContrast(float value)
106  {
107  contrast = value;
108  }
109 
111  inline unsigned char alpha() const
112  {
113  return (rgba >> 24) & 0xff;
114  }
115 
117  inline unsigned char red() const
118  {
119  return (rgba >> 16) & 0xff;
120  }
121 
123  inline unsigned char green() const
124  {
125  return (rgba >> 8) & 0xff;
126  }
127 
129  inline unsigned char blue() const
130  {
131  return (rgba & 0xff);
132  }
133 
135  inline unsigned char intensity() const
136  {
137  unsigned short r = red();
138  unsigned short g = green();
139  unsigned short b = blue();
140  return static_cast<unsigned char>((r + g + b) / 3);
141  }
142  };
143 } // namespace Zivid
Zivid::Point::contrast
float contrast
Contrast.
Definition: Point.h:141
Zivid::Point::rgba
uint32_t rgba
Color (red,green,blue,alpha)
Definition: Point.h:142
Zivid::Point::blue
unsigned char blue() const
Get the blue color value for the point
Definition: Point.h:208
Zivid::Point::red
unsigned char red() const
Get the red color value for the point
Definition: Point.h:196
Zivid::Point::setIntensity
void setIntensity(unsigned char val)
Set the intensity for the point (sets r,g and b to identical values)
Definition: Point.h:178
Zivid::Point::green
unsigned char green() const
Get the green color value for the point
Definition: Point.h:202
Zivid::Point::setNaN
void setNaN()
Invalidate the point (set it to Not-a-Number)
Definition: Point.h:154
Zivid::Point::y
float y
Y coordinate.
Definition: Point.h:139
Zivid::Point::setContrast
void setContrast(float value)
Set the contrast for the point
Definition: Point.h:184
Zivid::Point::Point
Point()
Construct a 3D point at (0,0,0) with contrast 0 and color values (r,g,b,a) = (0,0,...
Definition: Point.h:145
Zivid::Point::alpha
unsigned char alpha() const
Get the alpha value for the point
Definition: Point.h:190
Zivid::Point::x
float x
X coordinate.
Definition: Point.h:138
Zivid::Point::setRgba
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:166
Zivid::Point::intensity
unsigned char intensity() const
Get the intensity of the point
Definition: Point.h:214
Zivid::Point::isNaN
bool isNaN() const
Check whether the point is valid (Not-a-Number)
Definition: Point.h:160
Zivid
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:52
Zivid::Point::setRgb
void setRgb(unsigned char r, unsigned char g, unsigned char b)
Set the r,g,b color value for the point
Definition: Point.h:172
Zivid::Point::z
float z
Z coordinate.
Definition: Point.h:140