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