# Path: Settings/Exceptions.py
# class DroneVisionError(Exception):
# 	def __init__(self, error_key=None):
# 		'''CONSTRUCTOR'''
# 
# 		self.__error_messages = {	'no_blobs_error_msg'								: 'No blobs detected!', \
# 									'blob_distance_is_not_calibrated_error_msg'			: 'Blob distance is not calibrated!', \
# 									'feature_descriptor_not_available_error_msg'		: 'Feature descriptor not avaiable - Use block matching!', \
# 									'find_line_limits_unexpected_angle'					: 'Unexpected angle: provide vertical or horizontal hough lines only',  \
# 									'error_msg_no_heading_angle_detected' 				: 'No heading angles detected', \
# 									'error_msg_no_backup_heading_available'				: 'No edge heading detected, and no backup heading available.', \
# 									'find_line_limits_no_hor_or_vert_found' 			: 'Only vertical or horizontal lines found - need both horizontal and vertical lines to process.', \
# 									'detect_boundary_edge_not_found_all_edge_lines'		: 'Could not compute all edges lines - need all boundary edge lines to process', \
# 									'no_3D_point_matches'								: 'Could not compute 3D points - no matching points.', \
# 									'could_not_get_point_list_from_slave'				: 'Timeout thread - could not get right point list from slave within timeout!', \
# 									'triangulation_error_msg'							: 'Triangulation failed!', \
# 									'3D_point_filtration_failed'						: 'Filtration of 3D points failed!'}
# 
# 		self.msg = None
# 		if error_key != None:
# 			self.msg = self.__error_messages[error_key]
# 
# 	def __str__(self):
# 		return repr(self.msg)
# 
# 	def GetErrorMessage(self, error_key):
# 		'''
# 		 @brief Return all possible error messages
# 		'''
# 		return self.__error_messages[error_key]
# 
# Path: src/DroneVision/DroneVision_src/imgProcessing/frameTools/frameTools.py
# def GetShape(frame):
# 	'''
# 	 @brief Get shape of frame, regardless of depth dimension.
# 
# 	 @param frame 
# 	 
# 	 return (height, width)
# 	'''
# 	return frame.shape[:2]
# 
# def CheckColor(frame):
# 	'''
# 	 @brief Check wether the frame is of grayscale or color.
# 	 	converts the frame to color if necessary.
# 
# 	 @param frame
# 	 
# 	 @return color frame.
# 	'''
# 	shape = frame.shape
# 	if len(shape) == 2:
# 		cl_frame = ToColor(frame)
# 	else:
# 		cl_frame = frame
# 	return cl_frame


import cv2, math
import numpy as np
from Settings.Exceptions import DroneVisionError
from src.DroneVision.DroneVision_src.imgProcessing.frameTools.frameTools import GetShape, CheckColor
		 	(Return
		 		selected_hor_edge_heading 	= closest horizontal edge heading to previous horizontal edge heading ((None, None, None, None), if there were no detected horizontal edges)
		 		selected_vert_edge_heading 	= closest vertical edge heading to previous vertical edge heading ((None, None, None, None), if there were no detected vertical edges)
		 		possible_hor_edge_headings 	= [(rho, theta, max/min, hor/vert),..] in horizontal direction
		 		possible_vert_edge_headings = [(rho, theta, max/min, hor/vert),..] in vertical direction
		 		(rho = distance to edge, theta = heading direction in radian degrees., max/min = True/False according to if it is the max or min boundary line, hor/vert = True/False - True for horizontal, False for vertical)
		'''
		possible_hor_edge_headings 	= []
		possible_vert_edge_headings = []

		# for drawing: max_hor = DARK BLUE, min_hor = LIGHT BLUE, max_vert = PURPLE, min_vert = GREEN
		colors = [(0,0,255), (0,255,255), (204,0,204), (0,255,0)]
		n_boundary_hough_lines = len(boundary_hough_lines)
		for i in range(n_boundary_hough_lines):
			if i % 2 == 0:
				max_line = True
			else:
				max_line = False

			proc_returns = self.ProcessBoundaryHoughLine(frame, boundary_hough_lines[i], draw=draw, color=colors[i])
			edge_line, rho, theta = proc_returns[:3]
			if draw:
				frame = proc_returns[3]
			if edge_line:
				if i < n_boundary_hough_lines/2: # horizontal lines
					possible_hor_edge_headings.append((rho, theta, max_line, True))
				else: # vertical lines
					possible_vert_edge_headings.append((rho, theta, max_line, False))

		if (len(possible_hor_edge_headings) + len(possible_vert_edge_headings)) == 0:

# Path: Settings/Exceptions.py
# class DroneVisionError(Exception):
# 	def __init__(self, error_key=None):
# 		'''CONSTRUCTOR'''
# 
# 		self.__error_messages = {	'no_blobs_error_msg'								: 'No blobs detected!', \
# 									'blob_distance_is_not_calibrated_error_msg'			: 'Blob distance is not calibrated!', \
# 									'feature_descriptor_not_available_error_msg'		: 'Feature descriptor not avaiable - Use block matching!', \
# 									'find_line_limits_unexpected_angle'					: 'Unexpected angle: provide vertical or horizontal hough lines only',  \
# 									'error_msg_no_heading_angle_detected' 				: 'No heading angles detected', \
# 									'error_msg_no_backup_heading_available'				: 'No edge heading detected, and no backup heading available.', \
# 									'find_line_limits_no_hor_or_vert_found' 			: 'Only vertical or horizontal lines found - need both horizontal and vertical lines to process.', \
# 									'detect_boundary_edge_not_found_all_edge_lines'		: 'Could not compute all edges lines - need all boundary edge lines to process', \
# 									'no_3D_point_matches'								: 'Could not compute 3D points - no matching points.', \
# 									'could_not_get_point_list_from_slave'				: 'Timeout thread - could not get right point list from slave within timeout!', \
# 									'triangulation_error_msg'							: 'Triangulation failed!', \
# 									'3D_point_filtration_failed'						: 'Filtration of 3D points failed!'}
# 
# 		self.msg = None
# 		if error_key != None:
# 			self.msg = self.__error_messages[error_key]
# 
# 	def __str__(self):
# 		return repr(self.msg)
# 
# 	def GetErrorMessage(self, error_key):
# 		'''
# 		 @brief Return all possible error messages
# 		'''
# 		return self.__error_messages[error_key]
# 
# Path: src/DroneVision/DroneVision_src/imgProcessing/frameTools/frameTools.py
# def GetShape(frame):
# 	'''
# 	 @brief Get shape of frame, regardless of depth dimension.
# 
# 	 @param frame 
# 	 
# 	 return (height, width)
# 	'''
# 	return frame.shape[:2]
# 
# def CheckColor(frame):
# 	'''
# 	 @brief Check wether the frame is of grayscale or color.
# 	 	converts the frame to color if necessary.
# 
# 	 @param frame
# 	 
# 	 @return color frame.
# 	'''
# 	shape = frame.shape
# 	if len(shape) == 2:
# 		cl_frame = ToColor(frame)
# 	else:
# 		cl_frame = frame
# 	return cl_frame


# Path: src/DroneVision/DroneVision_src/imgProcessing/Heading/EdgeHeading.py
import cv2, math
import numpy as np
from Settings.Exceptions import DroneVisionError
from src.DroneVision.DroneVision_src.imgProcessing.frameTools.frameTools import GetShape, CheckColor

		 	(Return
		 		selected_hor_edge_heading 	= closest horizontal edge heading to previous horizontal edge heading ((None, None, None, None), if there were no detected horizontal edges)
		 		selected_vert_edge_heading 	= closest vertical edge heading to previous vertical edge heading ((None, None, None, None), if there were no detected vertical edges)
		 		possible_hor_edge_headings 	= [(rho, theta, max/min, hor/vert),..] in horizontal direction
		 		possible_vert_edge_headings = [(rho, theta, max/min, hor/vert),..] in vertical direction
		 		(rho = distance to edge, theta = heading direction in radian degrees., max/min = True/False according to if it is the max or min boundary line, hor/vert = True/False - True for horizontal, False for vertical)
		'''
		possible_hor_edge_headings 	= []
		possible_vert_edge_headings = []

		# for drawing: max_hor = DARK BLUE, min_hor = LIGHT BLUE, max_vert = PURPLE, min_vert = GREEN
		colors = [(0,0,255), (0,255,255), (204,0,204), (0,255,0)]
		n_boundary_hough_lines = len(boundary_hough_lines)
		for i in range(n_boundary_hough_lines):
			if i % 2 == 0:
				max_line = True
			else:
				max_line = False

			proc_returns = self.ProcessBoundaryHoughLine(frame, boundary_hough_lines[i], draw=draw, color=colors[i])
			edge_line, rho, theta = proc_returns[:3]
			if draw:
				frame = proc_returns[3]
			if edge_line:
				if i < n_boundary_hough_lines/2: # horizontal lines
					possible_hor_edge_headings.append((rho, theta, max_line, True))
				else: # vertical lines
					possible_vert_edge_headings.append((rho, theta, max_line, False))

		if (len(possible_hor_edge_headings) + len(possible_vert_edge_headings)) == 0:

			raise DroneVisionError('error_msg_no_heading_angle_detected')