GPU-Accelerated Coverage  0.1.0
Compute coverage tours for known environment with articulated objects on GPU
Config.h
1 /*
2  * Copyright (c) 2018, Stefan Osswald
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef INCLUDE_ARTICULATION_CONFIG_H_
32 #define INCLUDE_ARTICULATION_CONFIG_H_
33 
34 #include <string>
35 #include <iostream>
36 #include <stdexcept>
37 #include <map>
38 #include <vector>
39 #if __ANDROID__
40 #include <android/asset_manager.h>
41 #include <android/asset_manager_jni.h>
42 #endif
43 
44 namespace gpu_coverage {
45 
49 class Config {
50 public:
57  CUBE,
60  };
61 
62 protected:
67  Config(const std::string& filename);
71  virtual ~Config();
72 
73  const std::string filename;
74 
78  struct AbstractParam {
79  const std::string name;
80  const std::string description;
81 
88  friend std::ostream& operator<<(std::ostream& os, AbstractParam& param);
89 
96  friend std::istream& operator>>(std::istream& is, AbstractParam& param);
97 
102  virtual void write(std::ostream& os) const = 0;
103 
108  virtual void read(std::istream& is) = 0;
114  AbstractParam(const std::string& name, const std::string& description)
115  : name(name), description(description) {
116  }
120  virtual ~AbstractParam() {
121  }
122  };
123  friend std::ostream& operator<<(std::ostream& os, AbstractParam& param);
124  friend std::istream& operator>>(std::istream& is, AbstractParam& param);
125 
130  template<class T>
131  struct Param: public AbstractParam {
132  T dflt;
133  T value;
134 
140  Param(const std::string& name, const std::string& description, const T& dflt)
141  : AbstractParam(name, description), dflt(dflt), value(dflt) {
142  }
143 
147  virtual ~Param() {
148  }
149 
154  virtual void write(std::ostream& os) const;
155 
160  virtual void read(std::istream& is) throw (std::invalid_argument);
161  };
162 
163  typedef std::map<std::string, AbstractParam *> Params;
164  Params params;
165  static Config *instance;
166 
167 #if __ANDROID__
168  static AAssetManager *apkAssetManager;
169 #endif
170 
171 public:
172 #if __ANDROID__
173 
177  static void setAssetManager(AAssetManager *manager) {
178  apkAssetManager = manager;
179  }
184  static AAssetManager * getAssetManager() {
185  return apkAssetManager;
186  }
187 #endif
188 
196  static inline Config &getInstance() {
197  return *instance;
198  }
199 
205  static void init(const int argc, const char * const argv[]);
206 
210  void save() const;
211 
215  void load();
216 
225  template<class T>
226  T getParam(const std::string& name) const {
227  Params::const_iterator paramIt = params.find(name);
228  if (paramIt == params.end()) {
229  throw std::invalid_argument(std::string("Parameter ") + name + " not found");
230  }
231  const Param<T> * const bp = dynamic_cast<Param<T>*>(paramIt->second);
232  if (!bp) {
233  throw std::invalid_argument(std::string("Parameter ") + name + " is not of requested type");
234  }
235  return bp->value;
236  }
237 };
238 
239 } /* namespace gpu_coverage */
240 
241 #endif /* INCLUDE_ARTICULATION_CONFIG_H_ */
std::map< std::string, AbstractParam * > Params
Parameter map type, maps names to parameter structure.
Definition: Config.h:163
T getParam(const std::string &name) const
Get a configuration parameter.
Definition: Config.h:226
AbstractParam(const std::string &name, const std::string &description)
Constructor.
Definition: Config.h:114
Configuration parameter.
Definition: Config.h:131
static Config & getInstance()
Definition: Config.h:196
Cube sides folded onto a 4x3 grid.
Definition: Config.h:57
Equirectangular projection image with aspect ratio 2:1.
Definition: Config.h:58
virtual void read(std::istream &is)=0
Read this parameter from a configuration file input stream.
PanoOutputValue
Possible values for the panoOutputFormat parameter.
Definition: Config.h:54
void load()
Load the configuration from disk.
virtual ~Param()
Destructor.
Definition: Config.h:147
const std::string filename
The file name for loading and storing the configuration data.
Definition: Config.h:73
virtual ~Config()
Destructor.
const std::string description
A human-readable description of the parameter.
Definition: Config.h:80
void save() const
Save the configuration to disk.
virtual void write(std::ostream &os) const =0
Write this parameter to a configuration file output stream.
Config(const std::string &filename)
Protected constructor, loads configuration from file.
friend std::ostream & operator<<(std::ostream &os, AbstractParam &param)
Stream operator for writing this parameter to a config data stream.
Abstract class representing a configuration parameter.
Definition: Config.h:78
Cylindrical projection image with aspect ratio 2:1.
Definition: Config.h:59
static Config * instance
The singleton instance.
Definition: Config.h:165
virtual ~AbstractParam()
Destructor.
Definition: Config.h:120
T value
Current value of the parameter.
Definition: Config.h:133
Six cube map sides aligned vertically (right-left-top-bottom-back-front)
Definition: Config.h:56
Definition: AbstractCamera.h:41
Singleton class for storing configuration.
Definition: Config.h:49
friend std::istream & operator>>(std::istream &is, AbstractParam &param)
Stream operator for reading this parameter from a config data stream.
static void init(const int argc, const char *const argv[])
T dflt
Default value of the parameter.
Definition: Config.h:132
Params params
The parameters.
Definition: Config.h:164
const std::string name
The name of the descriptor.
Definition: Config.h:79
Six cube map sides aligned horizontally (right-left-top-bottom-back-front)
Definition: Config.h:55
Param(const std::string &name, const std::string &description, const T &dflt)
Constructor.
Definition: Config.h:140