Zivid C++ API  1.8.1+6967bc1b-1
Defining the Future of 3D Machine Vision
Camera.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 "Zivid/APIExport.h"
48 #include "Zivid/CameraIntrinsics.h"
49 #include "Zivid/CameraRevision.h"
50 #include "Zivid/CameraState.h"
51 #include "Zivid/ComputeDevice.h"
52 #include "Zivid/DeviceCloud.h"
53 #include "Zivid/Frame.h"
54 #include "Zivid/SerialNumber.h"
55 #include "Zivid/Settings.h"
56 #include "Zivid/Settings2D.h"
57 
58 #include <functional>
59 #include <memory>
60 
61 namespace Zivid
62 {
63  class CloudVisualizer;
64  class Frame2D;
65 
74  class Camera
75  {
76  public:
78  using FrameCallback = std::function<void(Frame)>;
79 
81  using StateCallback [[deprecated("1.2.0: No longer in use elsewhere")]] = std::function<void(CameraState)>;
82 
83  public:
86 
89 
91  ZIVID_API_EXPORT Camera(const Camera &other) noexcept;
92 
94  ZIVID_API_EXPORT Camera &operator=(const Camera &other) noexcept;
95 
97  ZIVID_API_EXPORT Camera(Camera &&other) noexcept;
98 
100  ZIVID_API_EXPORT Camera &operator=(Camera &&other) noexcept;
101 
104 
107  ZIVID_API_EXPORT Camera &connect(const Settings &settings);
108 
111 
114  ZIVID_API_EXPORT void setSettings(Settings settings);
115 
118  ZIVID_API_EXPORT Settings settings() const;
119 
127 
130  ZIVID_API_EXPORT CameraState state() const;
131 
140  ZIVID_API_EXPORT void setComputeDevice(ComputeDevice device);
141 
149 
156 
162  ZIVID_API_EXPORT void stopLive();
163 
166  ZIVID_API_EXPORT Frame capture();
167 
172  ZIVID_API_EXPORT Frame capture(DeviceCloud &deviceCloud);
173 
182  ZIVID_API_EXPORT Frame2D capture2D(const Settings2D &settings);
183 
186  ZIVID_API_EXPORT ComputeDevice computeDevice();
187 
188 #ifndef NO_DOC
189  ZIVID_API_EXPORT explicit Camera(class CameraImpl &&other);
190  ZIVID_API_EXPORT const CameraImpl &getImpl() const;
191  ZIVID_API_EXPORT CameraImpl &getImpl();
192 #endif
193  ZIVID_API_EXPORT std::string modelName() const;
195 
197  ZIVID_API_EXPORT CameraRevision revision() const;
198 
200  ZIVID_API_EXPORT SerialNumber serialNumber() const;
201 
203  ZIVID_API_EXPORT std::string firmwareVersion() const;
204 
206  ZIVID_API_EXPORT size_t userDataMaxSizeBytes() const;
207 
212  ZIVID_API_EXPORT void writeUserData(const std::vector<uint8_t> &data);
213 
215  ZIVID_API_EXPORT std::vector<uint8_t> userData() const;
216 
218  ZIVID_API_EXPORT CameraIntrinsics intrinsics() const;
219 
222  ZIVID_API_EXPORT std::string toString() const;
223 
225  ZIVID_API_EXPORT bool operator==(const Camera &other) const;
227  ZIVID_API_EXPORT bool operator!=(const Camera &other) const;
228 
229  private:
230  std::shared_ptr<class CameraImpl> m_impl;
231  };
232 
234  ZIVID_API_EXPORT std::ostream &operator<<(std::ostream &stream, const Camera &camera);
235 
239  class SettingsBatch
240  {
241  public:
244  explicit SettingsBatch(Camera &camera)
245  : m_settings{ camera.settings() }
246  , m_camera{ camera }
247  {}
248 
249  SettingsBatch(const SettingsBatch &) = delete;
250  SettingsBatch &operator=(const SettingsBatch &) = delete;
251  SettingsBatch &operator=(SettingsBatch &&) = delete;
252 
254  SettingsBatch(SettingsBatch &&other) noexcept
255  : m_settings{ std::move(other.m_settings) }
256  , m_camera{ other.m_camera }
257  {
258  other.m_apply = false;
259  }
260 
262  ~SettingsBatch() noexcept(false)
263  {
264  if(m_apply)
265  {
266  m_camera.setSettings(std::move(m_settings));
267  }
268  }
269 
271  template<typename Setting>
272  SettingsBatch &set(const Setting &value)
273  {
274  m_settings.set(value);
275  return *this;
276  }
277 
279  template<typename Setting>
280  friend SettingsBatch operator<<(SettingsBatch &&setter, Setting value)
281  {
282  setter.set(value);
283  return std::move(setter);
284  }
285 
286  private:
287  bool m_apply{ true };
288  Settings m_settings;
289  Camera &m_camera;
290  };
291 
297  template<typename Setting>
298  SettingsBatch operator<<(Camera &camera, Setting value)
299  {
300  return SettingsBatch{ camera } << value;
301  }
302 } // namespace Zivid
Settings.h
Zivid::Camera::stopLive
ZIVID_API_EXPORT void stopLive()
Stop live (continuous) capturing of frames
Zivid::SettingsBatch::SettingsBatch
SettingsBatch(Camera &camera)
Construct a SettingsBatch helper class on a camera
Definition: Camera.h:283
Zivid::Camera::intrinsics
ZIVID_API_EXPORT CameraIntrinsics intrinsics() const
Get the intrinsic parameters of the camera
Zivid::Camera::operator==
ZIVID_API_EXPORT bool operator==(const Camera &other) const
Check if two camera instances represent the same device
Zivid::SettingsBatch::set
SettingsBatch & set(const Setting &value)
Cache the setting until object destruction
Definition: Camera.h:311
Zivid::Camera::Camera
ZIVID_API_EXPORT Camera()
Constructor
Zivid::SettingsBatch::~SettingsBatch
~SettingsBatch() noexcept(false)
Apply all cached settings to the camera
Definition: Camera.h:301
Zivid::Camera::userData
ZIVID_API_EXPORT std::vector< uint8_t > userData() const
Read user data from camera
Zivid::Camera::startLive
ZIVID_API_EXPORT void startLive()
Start live (continuous) capturing of frames
Zivid::Camera::userDataMaxSizeBytes
ZIVID_API_EXPORT size_t userDataMaxSizeBytes() const
Get the maximum number of bytes of user data that can be stored in the camera
Zivid::Camera::settings
ZIVID_API_EXPORT Settings settings() const
Get the current camera settings
Zivid::Camera::setFrameCallback
ZIVID_API_EXPORT void setFrameCallback(FrameCallback callback)
Set a callback that is executed every time a new frame is ready
Zivid::Camera::FrameCallback
std::function< void(Frame)> FrameCallback
Callback for frames
Definition: Camera.h:117
Zivid::Camera::capture2D
ZIVID_API_EXPORT Frame2D capture2D(const Settings2D &settings)
Capture a single 2D frame
CameraState.h
Zivid::SettingsBatch::operator=
SettingsBatch & operator=(const SettingsBatch &)=delete
Zivid::Camera::setSettings
ZIVID_API_EXPORT void setSettings(Settings settings)
Update the camera settings
Zivid::Camera::toString
ZIVID_API_EXPORT std::string toString() const
Get string representation of the camera info
Zivid::Camera::revision
ZIVID_API_EXPORT CameraRevision revision() const
Get the camera revision
Zivid::Camera::operator=
ZIVID_API_EXPORT Camera & operator=(const Camera &other) noexcept
Copy assignment
Zivid::Camera::operator!=
ZIVID_API_EXPORT bool operator!=(const Camera &other) const
Check if two camera instances represent different devices
ComputeDevice.h
Zivid::Camera::connect
ZIVID_API_EXPORT Camera & connect()
Connect to the camera
Zivid::Camera::modelName
ZIVID_API_EXPORT std::string modelName() const
Get the model name
CameraIntrinsics.h
Zivid::Camera::disconnect
ZIVID_API_EXPORT void disconnect()
Disconnect from the camera and free all resources associated with it
CameraRevision.h
Frame.h
Zivid::Camera::state
ZIVID_API_EXPORT CameraState state() const
Get the current camera state
SerialNumber.h
Zivid::SettingsBatch::operator<<
friend SettingsBatch operator<<(SettingsBatch &&setter, Setting value)
Cache the setting until object destruction
Definition: Camera.h:319
Zivid::Camera::~Camera
ZIVID_API_EXPORT ~Camera()
Destructor
Settings2D.h
APIExport.h
Zivid::Settings::set
void set(const std::string &fullPath, const std::string &value)
Set a value from string by specifying the path
Zivid::Camera::capture
ZIVID_API_EXPORT Frame capture()
Capture a single 3D frame
Zivid::Camera::StateCallback
std::function< void(CameraState)> StateCallback
Callback for state
Definition: Camera.h:120
Zivid::Camera::setComputeDevice
ZIVID_API_EXPORT void setComputeDevice(ComputeDevice device)
Connect the camera to a given Compute device
Zivid
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:52
Zivid::Camera::allocateDeviceCloud
ZIVID_API_EXPORT DeviceCloud allocateDeviceCloud()
Allocate a new point cloud on the Compute device
Zivid::Camera::computeDevice
ZIVID_API_EXPORT ComputeDevice computeDevice()
Get Compute device
ZIVID_API_EXPORT
#define ZIVID_API_EXPORT
Definition: APIExport.h:56
Zivid::Camera::serialNumber
ZIVID_API_EXPORT SerialNumber serialNumber() const
Get the serial number of the Zivid camera
Zivid::Camera::writeUserData
ZIVID_API_EXPORT void writeUserData(const std::vector< uint8_t > &data)
Write user data to camera. The total number of writes supported depends on camera model and size of d...
Zivid::Camera::firmwareVersion
ZIVID_API_EXPORT std::string firmwareVersion() const
Get the camera's firmware version
DeviceCloud.h
Zivid::operator<<
ZIVID_API_EXPORT std::ostream & operator<<(std::ostream &stream, const Camera &camera)
Serialize the value to a stream