Zivid  1.0.1+3607.8a7510c4
Zivid API
Camera.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 <memory>
17 #include <functional>
18 #include "APIExport.h"
19 #include "Settings.h"
20 #include "ComputeDevice.h"
21 #include "DeviceCloud.h"
22 #include "Frame.h"
23 #include "SerialNumber.h"
24 #include "CameraRevision.h"
25 
26 namespace Zivid
27 {
28  class CloudVisualizer;
29 
38  class Camera
39  {
40  public:
42  using FrameCallback = std::function<void(Frame)>;
43 
45  using StateCallback = std::function<void(CameraState)>;
46 
47  public:
49  ZIVID_API Camera();
51  ZIVID_API ~Camera();
53  ZIVID_API Camera(const Camera &other) noexcept;
55  ZIVID_API Camera &operator=(const Camera &other) noexcept;
57  ZIVID_API Camera(Camera && other) noexcept;
59  ZIVID_API Camera &operator=(Camera && other) noexcept;
60 
62  ZIVID_API Camera &connect();
63 
65  ZIVID_API Camera &connect(const Settings &settings);
66 
68  ZIVID_API void disconnect();
69 
72  ZIVID_API void setSettings(Settings settings);
73 
76  ZIVID_API Settings settings() const;
77 
84  ZIVID_API DeviceCloud allocateDeviceCloud();
85 
88  ZIVID_API CameraState state() const;
89 
98  ZIVID_API void setComputeDevice(ComputeDevice device);
99 
106  ZIVID_API void setFrameCallback(FrameCallback callback);
107 
113  ZIVID_API void startLive();
114 
120  ZIVID_API void stopLive();
121 
124  ZIVID_API Frame capture();
125 
130  ZIVID_API Frame capture(DeviceCloud& deviceCloud);
131 
134  ZIVID_API ComputeDevice computeDevice();
135 
136 #ifndef DOXYGEN_SHOULD_SKIP_THIS
137  ZIVID_API explicit Camera(class CameraImpl && other);
138 #endif
139  ZIVID_API std::string modelName() const;
141 
143  ZIVID_API CameraRevision revision() const;
144 
146  ZIVID_API SerialNumber serialNumber() const;
147 
149  ZIVID_API std::string firmwareVersion() const;
150 
153  ZIVID_API std::string toString() const;
154 
156  ZIVID_API bool operator==(const Camera &other) const;
158  ZIVID_API bool operator!=(const Camera &other) const;
159 
160  private:
161 
162  std::shared_ptr<class CameraImpl> m_impl;
163  };
164 
166  ZIVID_API std::ostream &operator<<(std::ostream &stream, const Camera &camera);
167 
172  {
173  public:
176  explicit SettingsBatch(Camera &camera)
177  : m_settings{ camera.settings() }
178  , m_camera{ camera }
179  {}
180 
181  SettingsBatch(const SettingsBatch &) = delete;
182  SettingsBatch &operator =(const SettingsBatch &) = delete;
183  SettingsBatch &operator =(SettingsBatch &&) = delete;
184 
186  SettingsBatch(SettingsBatch && other) noexcept
187  : m_settings{ std::move(other.m_settings) }
188  , m_camera{ other.m_camera }
189  {
190  other.m_apply = false;
191  }
192 
195  {
196  if (m_apply)
197  {
198  m_camera.setSettings(std::move(m_settings));
199  }
200  }
201 
203  template<typename Setting>
204  SettingsBatch &set(Setting value)
205  {
206  m_settings.set(value.path, value.toString());
207  return *this;
208  }
209 
211  template<typename Setting>
212  friend SettingsBatch operator << (SettingsBatch && setter, Setting value)
213  {
214  setter.set(value);
215  return std::move(setter);
216  }
217 
218  private:
219  bool m_apply{ true };
220  Settings m_settings;
221  Camera &m_camera;
222  };
223 
229  template<typename Setting>
230  SettingsBatch operator << (Camera &camera, Setting value)
231  {
232  return SettingsBatch{ camera } << value;
233  }
234 } // namespace Zivid
Settings for a Zivid camera
SettingsBatch(SettingsBatch &&other) noexcept
Move constructor
Definition: Camera.h:186
ZIVID_API Camera()
Constructor
ZIVID_API CameraState state() const
Get the current camera state
SettingsBatch(Camera &camera)
Construct a SettingsBatch helper class on a camera
Definition: Camera.h:176
ZIVID_API void setFrameCallback(FrameCallback callback)
Set a callback that is executed every time a new frame is ready
ZIVID_API DeviceCloud allocateDeviceCloud()
Allocate a new point cloud on the Compute device
ZIVID_API void stopLive()
Stop live (continuous) capturing of frames
ZIVID_API void disconnect()
Disconnect from the camera and free all resources associated with it
Point cloud on the Compute device
Camera revision
Definition: CameraRevision.h:19
ZIVID_API bool operator!=(const Camera &other) const
check if two camera instances represent the different devices
ZIVID_API std::string modelName() const
Get the model name
ZIVID_API Camera & operator=(const Camera &other) noexcept
Copy assignment
SettingsBatch & set(Setting value)
Cache the setting until object destruction
Definition: Camera.h:204
ZIVID_API bool operator==(const Camera &other) const
check if two camera instances represent the same device
ZIVID_API CameraRevision revision() const
Get the camera revision
ZIVID_API Frame capture()
Capture a single frame
ZIVID_API void setComputeDevice(ComputeDevice device)
Connect the camera to a given Compute device
ZIVID_API Camera & connect()
Connect to the camera
Helper class to a apply a batch of settings changes to a camera
Definition: Camera.h:171
Definition: Application.h:19
Definitions for export of DLL interfaces
A frame captured by a Zivid camera
Definition: Frame.h:36
Point cloud on the Compute device.
Definition: DeviceCloud.h:31
std::function< void(Frame)> FrameCallback
Callback for frames
Definition: Camera.h:42
ZIVID_API std::string firmwareVersion() const
Get the camera&#39;s firmware version
A frame captured by a Zivid camera
ZIVID_API SerialNumber serialNumber() const
Get the serial number of the Zivid camera
ZIVID_API ~Camera()
Destructor
std::function< void(CameraState)> StateCallback
Callback for state
Definition: Camera.h:45
ZIVID_API void setSettings(Settings settings)
Update the camera settings
ZIVID_API Settings settings() const
Get the current camera settings
A Compute device on which to allocate a device point cloud
Settings for a Zivid camera
Definition: Settings.h:50
A Compute device on which to allocate a device point cloud.
Definition: ComputeDevice.h:28
~SettingsBatch()
Apply all cached settings to the camera
Definition: Camera.h:194
ZIVID_API ComputeDevice computeDevice()
Get Compute device
Serial number of a Zivid camera
Serial number of a Zivid camera
Definition: SerialNumber.h:24
ZIVID_API std::string toString() const
Get string representation of the camera info
ZIVID_API void startLive()
Start live (continuous) capturing of frames
Information about camera connection state, live mode, temperatures, etc.
Definition: CameraState.h:38
ZIVID_API std::ostream & operator<<(std::ostream &stream, const Camera &camera)
Serialize the value to a stream
Interface to one Zivid camera
Definition: Camera.h:38