Apollo  6.0
Open source self driving car software
object_template_manager.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 #pragma once
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 #include "cyber/common/log.h"
23 #include "cyber/common/macros.h"
24 #include "gflags/gflags.h"
26 #include "modules/perception/camera/common/proto/object_template_meta_schema.pb.h"
28 
29 namespace apollo {
30 namespace perception {
31 namespace camera {
32 
33 enum class TemplateIndex {
38 };
39 
40 typedef std::map<base::ObjectSubType, std::vector<float>> TemplateMap;
41 
43  std::string root_dir;
44  std::string conf_file;
45  int gpu_id = 0;
46  bool use_cyber_work_root = false;
47 };
48 
50  public:
51  bool Init(const ObjectTemplateManagerInitOptions &options);
52  // for general visual obj typed as vehicle
53  float VehObjHwlBySearchTemplates(float *hwl, int *index = nullptr,
54  bool *is_flip = nullptr);
55  const int NrDimPerTmplt() {
56  ACHECK(inited_);
57  return nr_dim_per_tmplt_;
58  }
59  const std::vector<float> &VehHwl() {
60  ACHECK(inited_);
61  return veh_hwl_;
62  }
63  const std::map<TemplateIndex, int> &LookUpTableMinVolumeIndex() {
64  ACHECK(inited_);
65  return look_up_table_min_volume_index_;
66  }
67  const std::map<base::ObjectSubType, float> &TypeSpeedLimit() {
68  ACHECK(inited_);
69  return type_speed_limit_;
70  }
71  const std::vector<base::ObjectSubType> &TypeRefinedByTemplate() {
72  ACHECK(inited_);
73  return type_refined_by_template_;
74  }
75  const std::vector<base::ObjectSubType> &TypeRefinedByRef() {
76  ACHECK(inited_);
77  return type_refined_by_ref_;
78  }
79  const std::vector<base::ObjectSubType> &TypeCanBeRef() {
80  ACHECK(inited_);
81  return type_can_be_ref_;
82  }
83  const TemplateMap &MinTemplateHWL() {
84  ACHECK(inited_);
85  return min_template_hwl_;
86  }
87  const TemplateMap &MidTemplateHWL() {
88  ACHECK(inited_);
89  return mid_template_hwl_;
90  }
91  const TemplateMap &MaxTemplateHWL() {
92  ACHECK(inited_);
93  return max_template_hwl_;
94  }
95  const std::vector<TemplateMap> &TemplateHWL() {
96  ACHECK(inited_);
97  return template_hwl_;
98  }
99 
100  private:
101  void LoadVehTemplates(const ObjectTemplate &tmplt);
102  void LoadVehMinMidMaxTemplates(const base::ObjectSubType &type,
103  const ObjectTemplate &tmplt);
104 
105  // util for tmplt search
106  float Get3dDimensionSimilarity(const float *hwl1, const float *hwl2);
107 
108  private:
109  bool inited_ = false;
110  lib::Mutex mutex_;
111 
112  int nr_dim_per_tmplt_ = 0;
113  int total_nr_tmplts_veh_ = 0;
114  float max_dim_change_ratio_ = 0.0f;
115  // tmplt
116  std::vector<float> veh_hwl_;
117  // index for min vol in veh class
118  std::map<TemplateIndex, int> look_up_table_min_volume_index_;
119 
120  std::map<base::ObjectSubType, float> type_speed_limit_;
121 
122  std::vector<base::ObjectSubType> type_refined_by_template_;
123  std::vector<base::ObjectSubType> type_refined_by_ref_;
124  std::vector<base::ObjectSubType> type_can_be_ref_;
125 
126  TemplateMap min_template_hwl_;
127  TemplateMap mid_template_hwl_;
128  TemplateMap max_template_hwl_;
129  std::vector<TemplateMap> template_hwl_;
130 
132 };
133 
134 } // namespace camera
135 } // namespace perception
136 } // namespace apollo
const std::vector< base::ObjectSubType > & TypeRefinedByTemplate()
Definition: object_template_manager.h:71
const std::map< base::ObjectSubType, float > & TypeSpeedLimit()
Definition: object_template_manager.h:67
#define ACHECK(cond)
Definition: log.h:80
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: mutex.h:24
const TemplateMap & MidTemplateHWL()
Definition: object_template_manager.h:87
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
Definition: object_template_manager.h:49
const std::vector< TemplateMap > & TemplateHWL()
Definition: object_template_manager.h:95
const TemplateMap & MinTemplateHWL()
Definition: object_template_manager.h:83
TemplateIndex
Definition: object_template_manager.h:33
const std::vector< base::ObjectSubType > & TypeRefinedByRef()
Definition: object_template_manager.h:75
std::string root_dir
Definition: object_template_manager.h:43
bool Init(const char *binary_name)
const std::vector< float > & VehHwl()
Definition: object_template_manager.h:59
const std::vector< base::ObjectSubType > & TypeCanBeRef()
Definition: object_template_manager.h:79
std::map< base::ObjectSubType, std::vector< float > > TemplateMap
Definition: object_template_manager.h:40
const std::map< TemplateIndex, int > & LookUpTableMinVolumeIndex()
Definition: object_template_manager.h:63
const int NrDimPerTmplt()
Definition: object_template_manager.h:55
const TemplateMap & MaxTemplateHWL()
Definition: object_template_manager.h:91
std::string conf_file
Definition: object_template_manager.h:44
ObjectSubType
Definition: object_types.h:63
Definition: object_template_manager.h:42