Zivid C++ API  1.4.0+956f554d-12
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-2019 (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 
57 #include <functional>
58 #include <memory>
59 
60 namespace Zivid
61 {
62  class CloudVisualizer;
63 
72  class Camera
73  {
74  public:
76  using FrameCallback = std::function<void(Frame)>;
77 
79  using StateCallback [[deprecated("1.2.0: No longer in use elsewhere")]] = std::function<void(CameraState)>;
80 
81  public:
84 
87 
89  ZIVID_API_EXPORT Camera(const Camera &other) noexcept;
90 
92  ZIVID_API_EXPORT Camera &operator=(const Camera &other) noexcept;
93 
95  ZIVID_API_EXPORT Camera(Camera &&other) noexcept;
96 
98  ZIVID_API_EXPORT Camera &operator=(Camera &&other) noexcept;
99 
102 
105 
108 
112 
116 
124 
128 
138 
146 
153 
159  ZIVID_API_EXPORT void stopLive();
160 
164 
170 
174 
175 #ifndef NO_DOC
176  ZIVID_API_EXPORT explicit Camera(class CameraImpl &&other);
177  ZIVID_API_EXPORT const CameraImpl &getImpl() const;
178  ZIVID_API_EXPORT CameraImpl &getImpl();
179 #endif
180  ZIVID_API_EXPORT std::string modelName() const;
182 
185 
188 
190  ZIVID_API_EXPORT std::string firmwareVersion() const;
191 
193  ZIVID_API_EXPORT size_t userDataMaxSizeBytes() const;
194 
199  ZIVID_API_EXPORT void writeUserData(const std::vector<uint8_t> &data);
200 
202  ZIVID_API_EXPORT std::vector<uint8_t> userData() const;
203 
206 
209  ZIVID_API_EXPORT std::string toString() const;
210 
212  ZIVID_API_EXPORT bool operator==(const Camera &other) const;
214  ZIVID_API_EXPORT bool operator!=(const Camera &other) const;
215 
216  private:
217  std::shared_ptr<class CameraImpl> m_impl;
218  };
219 
221  ZIVID_API_EXPORT std::ostream &operator<<(std::ostream &stream, const Camera &camera);
222 
227  {
228  public:
231  explicit SettingsBatch(Camera &camera)
232  : m_settings{ camera.settings() }
233  , m_camera{ camera }
234  {}
235 
236  SettingsBatch(const SettingsBatch &) = delete;
237  SettingsBatch &operator=(const SettingsBatch &) = delete;
238  SettingsBatch &operator=(SettingsBatch &&) = delete;
239 
241  SettingsBatch(SettingsBatch &&other) noexcept
242  : m_settings{ std::move(other.m_settings) }
243  , m_camera{ other.m_camera }
244  {
245  other.m_apply = false;
246  }
247 
249  ~SettingsBatch() noexcept(false)
250  {
251  if(m_apply)
252  {
253  m_camera.setSettings(std::move(m_settings));
254  }
255  }
256 
258  template<typename Setting>
259  SettingsBatch &set(const Setting &value)
260  {
261  m_settings.set(value);
262  return *this;
263  }
264 
266  template<typename Setting>
267  friend SettingsBatch operator<<(SettingsBatch &&setter, Setting value)
268  {
269  setter.set(value);
270  return std::move(setter);
271  }
272 
273  private:
274  bool m_apply{ true };
275  Settings m_settings;
276  Camera &m_camera;
277  };
278 
284  template<typename Setting>
285  SettingsBatch operator<<(Camera &camera, Setting value)
286  {
287  return SettingsBatch{ camera } << value;
288  }
289 } // namespace Zivid
ZIVID_API_EXPORT void startLive()
Start live (continuous) capturing of frames
ZIVID_API_EXPORT std::string toString() const
Get string representation of the camera info
ZIVID_API_EXPORT void disconnect()
Disconnect from the camera and free all resources associated with it
friend SettingsBatch operator<<(SettingsBatch &&setter, Setting value)
Cache the setting until object destruction
Definition: Camera.h:267
Camera revision
Definition: CameraRevision.h:54
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_API_EXPORT std::string modelName() const
Get the model name
ZIVID_API_EXPORT SerialNumber serialNumber() const
Get the serial number of the Zivid camera
ZIVID_API_EXPORT CameraRevision revision() const
Get the camera revision
ZIVID_API_EXPORT CameraState state() const
Get the current camera state
ZIVID_API_EXPORT std::ostream & operator<<(std::ostream &stream, const Camera &camera)
Serialize the value to a stream
Point cloud on the Compute device
Definition: DeviceCloud.h:62
ZIVID_API_EXPORT bool operator==(const Camera &other) const
check if two camera instances represent the same device
Helper class to a apply a batch of settings changes to a camera
Definition: Camera.h:226
#define ZIVID_API_EXPORT
Definition: APIExport.h:57
std::function< void(Frame)> FrameCallback
Callback for frames
Definition: Camera.h:76
SettingsBatch(Camera &camera)
Construct a SettingsBatch helper class on a camera
Definition: Camera.h:231
ZIVID_API_EXPORT void stopLive()
Stop live (continuous) capturing of frames
ZIVID_API_EXPORT ComputeDevice computeDevice()
Get Compute device
ZIVID_API_EXPORT Settings settings() const
Get the current camera settings
ZIVID_API_EXPORT CameraIntrinsics intrinsics() const
Get the intrinsic parameters of the camera
Settings for a Zivid camera
Definition: Settings.h:68
ZIVID_API_EXPORT void setFrameCallback(FrameCallback callback)
Set a callback that is executed every time a new frame is ready
~SettingsBatch() noexcept(false)
Apply all cached settings to the camera
Definition: Camera.h:249
ZIVID_API_EXPORT bool operator!=(const Camera &other) const
check if two camera instances represent different devices
SettingsBatch & set(const Setting &value)
Cache the setting until object destruction
Definition: Camera.h:259
ZIVID_API_EXPORT DeviceCloud allocateDeviceCloud()
Allocate a new point cloud on the Compute device
ZIVID_API_EXPORT std::string firmwareVersion() const
Get the camera's firmware version
Interface to one Zivid camera
Definition: Camera.h:72
ZIVID_API_EXPORT Frame capture()
Capture a single frame
std::function< void(CameraState)> StateCallback
Callback for state
Definition: Camera.h:79
ZIVID_API_EXPORT Camera & connect()
Connect to the camera
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:53
ZIVID_API_EXPORT size_t userDataMaxSizeBytes() const
The ammount of data that can be stored in the camera
Compute device on which to allocate a device point cloud
Definition: ComputeDevice.h:61
ZIVID_API_EXPORT void setSettings(Settings settings)
Update the camera settings
ZIVID_API_EXPORT void setComputeDevice(ComputeDevice device)
Connect the camera to a given Compute device
Serial number of a Zivid camera
Definition: SerialNumber.h:56
void set(const std::string &fullPath, const std::string &value)
Set a value from string by specifying the path
A frame captured by a Zivid camera
Definition: Frame.h:65
Information about camera connection state, live mode, temperatures, etc.
Definition: CameraState.h:68
ZIVID_API_EXPORT std::vector< uint8_t > userData() const
Read user data from camera
SettingsBatch(SettingsBatch &&other) noexcept
Move constructor
Definition: Camera.h:241
SettingsBatch & operator=(const SettingsBatch &)=delete
Information about the intrinsic parameters of the camera (OpenCV model)
Definition: CameraIntrinsics.h:68
ZIVID_API_EXPORT Camera()
Constructor
ZIVID_API_EXPORT ~Camera()
Destructor
ZIVID_API_EXPORT Camera & operator=(const Camera &other) noexcept
Copy assignment