utils.py
Go to the documentation of this file.
00001 #!/bin/env python
00002 
00003 from python_qt_binding.QtCore import QPoint, QPointF, QSize
00004 from python_qt_binding.QtGui import QLabel, QPolygon
00005 
00006 def clearLayoutAndFixHeight(layout):
00007     # Clear all subfunction buttons.
00008     while layout.count():
00009         item = layout.takeAt(0)
00010         if item.widget() is not None:
00011             item.widget().deleteLater()
00012     height_label = QLabel()
00013     height_label.setFixedHeight(30)
00014     layout.addWidget(height_label)
00015     
00016 def determineScale(orig_size, new_size):
00017     if orig_size.width() > orig_size.height():
00018         scale = float(new_size.width()) / float(orig_size.width())
00019     else:
00020         scale = float(new_size.height()) / float(orig_size.height())
00021     return scale
00022 
00023 def scalePoint(pt, orig_size, new_size):
00024     scale = determineScale(orig_size, new_size)
00025     return scale * pt
00026 
00027 def scalePolygon(polygon, orig_size, new_size):
00028     ret_poly = QPolygon()
00029     for point_idx in range(polygon.size()):
00030         point = polygon.point(point_idx)
00031         scaled_point = scalePoint(point, orig_size, new_size)
00032         ret_poly.append(scaled_point)
00033     return ret_poly
00034 
00035 def transformPointToPixelCoordinates(pt, map, image_size):
00036     map_point_f = (pt - QPointF(map.map.info.origin.position.x, map.map.info.origin.position.y)) * (1.0 / map.map.info.resolution)
00037     map_point = QPoint(int(map_point_f.x()), int(map_point_f.y()))
00038     map_size = QSize(map.map.info.width, map.map.info.height)
00039     scaled_point = scalePoint(map_point, map_size, image_size) 
00040     return QPoint(scaled_point.x(), image_size.height() - scaled_point.y() - 1)
00041 
00042 def transformPointToRealWorldCoordinates(pt, map, image_size):
00043     map_size = QSize(map.map.info.width, map.map.info.height)
00044     vertically_flipped_point = QPoint(pt.x(), image_size.height() - pt.y() - 1)
00045     map_point = scalePoint(vertically_flipped_point, image_size, map_size)
00046     return QPointF(map.map.info.origin.position.x, map.map.info.origin.position.y) + \
00047             QPointF(map_point) * map.map.info.resolution 
00048 
00049 def getDoorsFileLocationFromDataDirectory(data_directory):
00050     return data_directory + "/doors.yaml"
00051 
00052 def getDoorsMapLocationFromDataDirectory(data_directory):
00053     return data_directory + "/doors_map.yaml"
00054 
00055 def getDoorsMapImageLocationFromDataDirectory(data_directory):
00056     return data_directory + "/doors_map.pgm"
00057 
00058 def getLocationsFileLocationFromDataDirectory(data_directory):
00059     return data_directory + "/locations.yaml"
00060 
00061 def getObjectsFileLocationFromDataDirectory(data_directory):
00062     return data_directory + "/objects.yaml"
00063 
00064 def getLocationsImageFileLocationFromDataDirectory(data_directory):
00065     return data_directory + "/locations.pgm"


bwi_planning_common
Author(s): Piyush Khandelwal
autogenerated on Fri Aug 28 2015 10:14:40