Argus Camera Sample
Argus Camera Sample
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AppModuleMultiExposure.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "AppModuleMultiExposure.h"
30 #include "Options.h"
31 #include "Error.h"
32 
33 namespace ArgusSamples
34 {
35 
36 /* static */ bool AppModuleMultiExposure::exposureRange(void *userPtr, const char *optArg)
37 {
38  AppModuleMultiExposure *module = reinterpret_cast<AppModuleMultiExposure*>(userPtr);
39  PROPAGATE_ERROR(module->m_multiExposure.m_exposureRange.setFromString(optArg));
40  return true;
41 }
42 
43 /* static */ bool AppModuleMultiExposure::exposureSteps(void *userPtr, const char *optArg)
44 {
45  AppModuleMultiExposure *module = reinterpret_cast<AppModuleMultiExposure*>(userPtr);
46  PROPAGATE_ERROR(module->m_multiExposure.m_exposureSteps.setFromString(optArg));
47  return true;
48 }
49 
51  : m_initialized(false)
52  , m_running(false)
53  , m_guiContainerConfig(NULL)
54  , m_guiConfig(NULL)
55 {
56 }
57 
59 {
60  shutdown();
61 }
62 
64 {
65  if (m_initialized)
66  return true;
67 
68  PROPAGATE_ERROR(m_multiExposure.initialize());
69 
70  PROPAGATE_ERROR(options.addOption(
71  Options::Option("exposurerange", 0, "RANGE", m_multiExposure.m_exposureRange,
72  "set the exposure range to RANGE.", exposureRange, this)));
73  PROPAGATE_ERROR(options.addOption(
74  Options::Option("exposuresteps", 0, "COUNT", m_multiExposure.m_exposureSteps,
75  "sample the exposure range at COUNT steps.",
76  exposureSteps, this)));
77 
78  m_initialized = true;
79 
80  return true;
81 }
82 
84 {
85  if (!m_initialized)
86  return true;
87 
88  PROPAGATE_ERROR_CONTINUE(stop());
89 
90  PROPAGATE_ERROR_CONTINUE(m_multiExposure.shutdown());
91 
92  delete m_guiConfig;
93  m_guiConfig = NULL;
94 
95  m_guiContainerConfig = NULL;
96 
97  m_initialized = false;
98 
99  return true;
100 }
101 
102 bool AppModuleMultiExposure::start(Window::IGuiMenuBar *iGuiMenuBar,
103  Window::IGuiContainer *iGuiContainerConfig)
104 {
105  if (m_running)
106  return true;
107 
108  // initialize the GUI
109  if (iGuiContainerConfig && !m_guiConfig)
110  {
111  // initialize the GUI
112 
113  // create a grid container
114  PROPAGATE_ERROR(Window::IGuiContainerGrid::create(&m_guiConfig));
115 
116  // create the elements
117  UniquePointer<Window::IGuiElement> element;
118 
119  Window::IGuiContainerGrid::BuildHelper buildHelper(m_guiConfig);
120 
121 #define CREATE_GUI_ELEMENT(_NAME, _VALUE) \
122  PROPAGATE_ERROR(Window::IGuiElement::createValue(&_VALUE, &element)); \
123  PROPAGATE_ERROR(buildHelper.append(_NAME, element.get())); \
124  element.release();
125 
128 
129 #undef CREATE_GUI_ELEMENT
130 
131  m_guiContainerConfig = iGuiContainerConfig;
132  }
133 
135  PROPAGATE_ERROR(m_guiContainerConfig->add(m_guiConfig));
136 
137  PROPAGATE_ERROR(m_multiExposure.start());
138 
139  m_running = true;
140 
141  return true;
142 }
143 
145 {
146  if (!m_running)
147  return true;
148 
149  PROPAGATE_ERROR(m_multiExposure.stop());
150 
152  PROPAGATE_ERROR(m_guiContainerConfig->remove(m_guiConfig));
153 
154  m_running = false;
155 
156  return true;
157 }
158 
159 }; // namespace ArgusSamples