OSVR-Core
Imaging.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_Imaging_h_GUID_5473F500_E901_419D_46D2_62ED5CB57412
26 #define INCLUDED_Imaging_h_GUID_5473F500_E901_419D_46D2_62ED5CB57412
27 
28 // Internal Includes
33 #include <osvr/Util/TimeValue.h>
34 #include <osvr/Util/Deletable.h>
35 
36 // Library/third-party includes
37 #include <boost/shared_ptr.hpp>
38 #include <boost/noncopyable.hpp>
39 
40 // Standard includes
41 // - none
42 
43 namespace osvr {
44 
45 namespace clientkit {
50  void registerImagingCallback(Interface &iface, ImagingCallback cb,
51  void *userdata);
52 #ifndef OSVR_DOXYGEN_EXTERNAL
53  namespace detail {
58  boost::noncopyable {
59  public:
60  virtual ~ImagingCallbackRegistration() {}
61 
62  private:
66  ImagingCallback cb,
67  void *userdata)
68  : m_cb(cb), m_userdata(userdata),
69  m_ctx(iface.getContext().get()) {
70  osvrRegisterImagingCallback(
71  iface.get(),
72  &ImagingCallbackRegistration::handleRawImagingCallback,
73  this);
74  }
76  class ImagingDeleter {
77  public:
78  ImagingDeleter(OSVR_ClientContext ctx) : m_ctx(ctx) {}
79  void operator()(OSVR_ImageBufferElement *buf) {
80  osvrClientFreeImage(m_ctx, buf);
81  }
82 
83  private:
84  OSVR_ClientContext m_ctx;
85  };
86 
89  static void
90  handleRawImagingCallback(void *userdata,
91  const struct OSVR_TimeValue *timestamp,
92  const struct OSVR_ImagingReport *report) {
94  static_cast<ImagingCallbackRegistration *>(userdata);
95  ImagingReport newReport;
96  newReport.sensor = report->sensor;
97  newReport.metadata = report->state.metadata;
98  newReport.buffer.reset(report->state.data,
99  ImagingDeleter(self->m_ctx));
100  self->m_cb(self->m_userdata, *timestamp, newReport);
101  }
102 
103  ImagingCallback m_cb;
104  void *m_userdata;
105  OSVR_ClientContext m_ctx;
106  friend void osvr::clientkit::registerImagingCallback(
107  Interface &iface, ImagingCallback cb, void *userdata);
108  };
109  } // namespace detail
110 
111 #endif // OSVR_DOXYGEN_EXTERNAL
112 
113  inline void registerImagingCallback(Interface &iface,
114  ImagingCallback cb,
115  void *userdata) {
117  new detail::ImagingCallbackRegistration(iface, cb, userdata));
118  iface.takeOwnership(ptr);
119  }
120 
122 
123 } // end namespace clientkit
124 
125 } // end namespace osvr
126 
127 #endif // INCLUDED_Imaging_h_GUID_5473F500_E901_419D_46D2_62ED5CB57412
Header.
Interface handle object.
Definition: Interface_decl.h:54
void(* ImagingCallback)(void *userdata, util::time::TimeValue const &timestamp, ImagingReport report)
The user-friendly imaging callback type.
Definition: Imaging_decl.h:65
Base class for objects that just need to be generically deletable.
Definition: Deletable.h:42
::boost::shared_ptr< Deletable > DeletablePtr
Shared-ownership smart pointer to a Deletable, using Boost&#39;s shared pointers.
Definition: BoostDeletable.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
OSVR_ChannelCount sensor
The device sensor number this frame came from.
Definition: Imaging_decl.h:54
The user-friendly imaging report.
Definition: Imaging_decl.h:52
OSVR_EXTERN_C_BEGIN OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientFreeImage(OSVR_ClientContext ctx, OSVR_ImageBufferElement *buf)
Free an image buffer returned from a callback.
Definition: ImagingC.cpp:35
ImageBufferPtr buffer
A shared pointer with custom deleter that owns the underlying image data buffer for the frame...
Definition: Imaging_decl.h:61
OSVR_ClientInterface get()
Get the raw OSVR_ClientInterface from this wrapper.
Definition: Interface.h:55
Definition: newuoa.h:1888
OSVR_ClientContext get()
Gets the bare OSVR_ClientContext.
Definition: Context.h:114
Class serving to maintain the registration of and wrap a friendly imaging callback.
Definition: Imaging.h:57
OSVR_ImagingMetadata metadata
Metadata containing the properties of this frame.
Definition: Imaging_decl.h:57
Header providing a C++ wrapper around TimeValueC.h.
Definition: ClientContext.h:50
Header defining a base class for objects that just need to be generically deletable.
Definition: ImagingReportTypesC.h:82
Header containing the inline implementation of Interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
ClientContext & getContext()
Get the associated ClientContext.
Definition: Interface.h:57
unsigned char OSVR_ImageBufferElement
Type for raw buffer access to image data.
Definition: ImagingReportTypesC.h:53
void takeOwnership(util::boost_util::DeletablePtr const &obj)
Take (shared) ownership of some Deletable object.
Definition: Interface.h:67