CParam.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2015, IAV Automotive Engineering
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without 
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice, 
00011  *    this list of conditions and the following disclaimer.
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00014  *    this list of conditions and the following disclaimer in the documentation 
00015  *    and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00019  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00027  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  */
00030 /*
00031  *  IAV Team
00032  *  http://www.iav.com
00033  *
00034  */
00035 
00036 
00037 #include "../include/CParam.h"
00038 
00039 using namespace iav_depthimage_to_laserscan;
00040 
00041 CParam::CParam() {
00042 }
00043 
00044 CParam::~CParam() {
00045 }
00046 
00047 /*
00048 * Init a TF and set names
00049 *
00050 * @param header header.frame_id
00051 * @param child child_frame_id
00052 */
00053 
00054 void CParam::createTF(std::string header, std::string child) {
00055     // Create new TF
00056     geometry_msgs::TransformStamped* tf = new geometry_msgs::TransformStamped();
00057     
00058     // Set header and child frame id
00059     tf->header.frame_id = header;
00060     tf->child_frame_id = child;
00061 
00062     // Set Transform Translations of the camera (x y z)
00063     // apply translation from Laserscan's coordinates
00064     tf->transform.translation.x = cam_offset*cos(cam_yaw);  // cam_offset*cos(cam_yaw)
00065     tf->transform.translation.y = cam_offset*sin(cam_yaw);  // cam_offset*sin(cam_yaw)
00066     tf->transform.translation.z = 0.0;  // 0.0
00067 
00068     // Set Transform Rotations of the camera (roll pitch yaw)
00069     // apply rotation from Laserscan's angles
00070     tf->transform.rotation = tf::createQuaternionMsgFromRollPitchYaw(0.0, cam_pitch, cam_yaw);
00071 
00072     // Add a TF to m_tf
00073     m_tf = tf;
00074 }
00075 
00076 /*
00077 * This function is used to stablish the geometrical limits of the image. It is used just once.
00078 * @param Param Parameters of the camera
00079 * @param laserParam Parameters of the laser
00080 * @param height_max value > 0 (considering 0 the laser_height), wich limits the height above the laser scan
00081 * @param height_min value < 0 (considering 0 the laser_height), wich limits the height below the laser scan
00082 */
00083 void CParam::init_parameter(CParam& Param, LSParam& laserParam, float height_max, float height_min) {
00084   
00085   // Allocate memory for the auxiliaries
00086   Param.cam_max_distances = (float*) malloc (Param.cam_image_height*sizeof(float));
00087   Param.cam_min_distances = (float*) malloc (Param.cam_image_height*sizeof(float));
00088 
00089   Param.cam_sin_v = (float*) malloc (Param.cam_image_height*sizeof(float)); 
00090   Param.cam_cos_v = (float*) malloc (Param.cam_image_height*sizeof(float)); 
00091   Param.cam_cos_h = (float*) malloc (Param.cam_image_width*sizeof(float));
00092   Param.cam_index = (int*) malloc (Param.cam_image_width*sizeof(int)); 
00093 
00094   // Auxiliares for the calculation of the distances limits
00095   float increment_v = Param.cam_AOV_v / Param.cam_image_height;
00096   float distance_a; 
00097   float distance_b;
00098   float longer;
00099   float shorter; 
00100   float angle;
00101 
00102   // Define the laser angle CParam 
00103   double th;
00104   double angle_min = laserParam.laser_min_angle;
00105   double angle_increment = (laserParam.laser_max_angle - laserParam.laser_min_angle)/(laserParam.laser_rays - 1);
00106 
00107   // Use correct principal point from calibration
00108   float center_x = Param.cam_image_width/2;
00109   float center_y = Param.cam_image_height/2;
00110 
00111   // Combine unit conversion (if necessary) with scaling by focal length for computing (X,Y)
00112   double unit_scaling = 0.001f;
00113   float constant_x = unit_scaling / Param.cam_focal_length_x;
00114   float constant_y = unit_scaling / Param.cam_focal_length_y;
00115 
00116   // Pre calculation of the index for the correct depth points
00117   for(int u = 0; u <  Param.cam_image_width; u++) {
00118     th = atan2((double)(center_x - u) * constant_x, unit_scaling); // Atan2(x, z), but depth divides out
00119 
00120     if((th - angle_min + cam_yaw) / angle_increment > laserParam.laser_rays - 1) cam_index[u] = laserParam.laser_rays - 1;
00121     else if((th - angle_min + cam_yaw) / angle_increment < 0) cam_index[u] = 0;
00122     else cam_index[u] = (th - angle_min + cam_yaw) / angle_increment;
00123         
00124     Param.cam_cos_h[u] =  cos (th);
00125   }
00126 
00127   // Calculate the distances limits based on height_max and height_min args
00128   for (int j = 0; j < Param.cam_image_height; j++) {    
00129     angle = atan2((double)(center_y - j) * constant_y, unit_scaling) - Param.cam_pitch;
00130    
00131     Param.cam_sin_v[j] =  sin (angle);
00132     Param.cam_cos_v[j] =  cos (angle);
00133     
00134             
00135     if (Param.cam_sin_v [j] != 0.0) {
00136        distance_a = (height_max) / Param.cam_sin_v[j]; 
00137        distance_b = (height_min) / Param.cam_sin_v[j]; 
00138                  
00139        if (distance_a < 0.0) {
00140           distance_a =  laserParam.laser_min_range;
00141        }
00142 
00143        if (distance_b < 0.0){
00144           distance_b = laserParam.laser_min_range; 
00145        }                             
00146     
00147        longer  = std::max ( distance_a, distance_b );
00148        shorter = std::min ( distance_a, distance_b );
00149 
00150        Param.cam_max_distances[j] = std::min(longer,(float) laserParam.laser_max_range);
00151        Param.cam_min_distances[j] = std::max(shorter,(float) laserParam.laser_min_range);
00152     }
00153                        
00154     else
00155     {
00156        Param.cam_max_distances[j] = laserParam.laser_max_range;
00157        Param.cam_min_distances[j] = laserParam.laser_min_range;
00158     }                                                    
00159   } 
00160 } 


iav_depthimage_to_laserscan
Author(s): Jan Obermueller
autogenerated on Thu Jun 6 2019 20:28:38