1 /*
2  * Copyright (C) 2017 The Android Open Source Project
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 #ifndef CONFIG_MANAGER_H
17 #define CONFIG_MANAGER_H
18 
19 #include <string>
20 #include <vector>
21 
22 namespace android {
23 namespace automotive {
24 namespace evs {
25 namespace support {
26 
27 class ConfigManager {
28 public:
29     struct CameraInfo {
30         std::string cameraId = "";  // The name of the camera from the point of view of the HAL
31         std::string function = "";  // The expected use for this camera ("reverse", "left", "right")
32         float position[3] = {0};    // x, y, z -> right, fwd, up in the units of car space
33         float yaw = 0;    // radians positive to the left (right hand rule about global z axis)
34         float pitch = 0;  // positive upward (ie: right hand rule about local x axis)
35         float hfov = 0;   // radians
36         float vfov = 0;   // radians
37     };
38 
39     bool initialize(const char* configFileName);
40 
41     // World space dimensions of the car
getCarWidth()42     float getCarWidth() const { return mCarWidth; };
getCarLength()43     float getCarLength() const { return mWheelBase + mFrontExtent + mRearExtent; };
getWheelBase()44     float getWheelBase() const { return mWheelBase; };
45 
46     // Car space (world space centered on the rear axel) edges of the car
getFrontLocation()47     float getFrontLocation() const { return mWheelBase + mFrontExtent; };
getRearLocation()48     float getRearLocation() const { return -mRearExtent; };
getRightLocation()49     float getRightLocation() const { return mCarWidth * 0.5f; };
getLeftLocation()50     float getLeftLocation() const { return -mCarWidth * 0.5f; };
51 
52     // Where are the edges of the top down display in car space?
getDisplayTopLocation()53     float getDisplayTopLocation() const {
54         // From the rear axel (origin) to the front bumper, and then beyond by the front range
55         return mWheelBase + mFrontExtent + mFrontRangeInCarSpace;
56     };
getDisplayBottomLocation()57     float getDisplayBottomLocation() const {
58         // From the rear axel (origin) to the back bumper, and then beyond by the back range
59         return -mRearExtent - mRearRangeInCarSpace;
60     };
getDisplayRightLocation(float aspectRatio)61     float getDisplayRightLocation(float aspectRatio) const {
62         // Given the display aspect ratio (width over height), how far can we see to the right?
63         return (getDisplayTopLocation() - getDisplayBottomLocation()) * 0.5f * aspectRatio;
64     };
getDisplayLeftLocation(float aspectRatio)65     float getDisplayLeftLocation(float aspectRatio) const {
66         // Given the display aspect ratio (width over height), how far can we see to the left?
67         return -getDisplayRightLocation(aspectRatio);
68     };
69 
70     // At which texel (vertically in the image) are the front and rear bumpers of the car?
carGraphicFrontPixel()71     float carGraphicFrontPixel() const { return mCarGraphicFrontPixel; };
carGraphicRearPixel()72     float carGraphicRearPixel() const { return mCarGraphicRearPixel; };
73 
getCameras()74     const std::vector<CameraInfo>& getCameras() const { return mCameras; };
75 
76 private:
77     // Camera information
78     std::vector<CameraInfo> mCameras;
79 
80     // Car body information (assumes front wheel steering and origin at center of rear axel)
81     // Note that units aren't specified and don't matter as long as all length units are consistent
82     // within the JSON file from which we parse.  That is, if everything is in meters, that's fine.
83     // Everything in mm?  That's fine too.
84     float mCarWidth;
85     float mWheelBase;
86     float mFrontExtent;
87     float mRearExtent;
88 
89     // Display information
90     float mFrontRangeInCarSpace;  // How far the display extends in front of the car
91     float mRearRangeInCarSpace;   // How far the display extends behind the car
92 
93     // Top view car image information
94     float mCarGraphicFrontPixel;  // How many pixels from the top of the image does the car start
95     float mCarGraphicRearPixel;   // How many pixels from the top of the image does the car end
96 };
97 
98 }  // namespace support
99 }  // namespace evs
100 }  // namespace automotive
101 }  // namespace android
102 
103 #endif  // CONFIG_MANAGER_H
104