# 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]


import cv2
import numpy as np
from Settings.Exceptions import DroneVisionError
from detectLines import HoughLineEdgePoints, DrawHoughLine
from src.DroneVision.DroneVision_src.imgProcessing.frameTools.frameTools import GetShape

	max_vert_line_edge_points	= [[],[]] # [x],[y]
	max_vert_hough_line 		= (None, None)
	average_line_y_pos			= max_vert_line[0][0] + (max_vert_line[1][0] - max_vert_line[0][0])/2
	if average_line_y_pos < vert_edge_region_threshold: # Edge detected to the right
		for hor_line in bounded_lines[0]: # Check all horizontal lines (max points)
			len_line 	= int(round((hor_line[1][0] - hor_line[0][0])*line_perc))
			max_point 	= hor_line[1]
			x_edge_ind 	= DetectLineEdge(edgel_frame, True, max_point[1], max_point[0], height-1)
			max_vert_line_edge_points[0].append(x_edge_ind)
			max_vert_line_edge_points[1].append(max_point[1])
		if filtrate_edge_points:
			max_vert_line_edge_points[1], max_vert_line_edge_points[0] = FiltrateEdgePoints(max_vert_line_edge_points[1], max_vert_line_edge_points[0])
		max_vert_hough_line = HoughLineEdgePoints(edgel_frame, max_vert_line_edge_points, True)

	min_vert_line_edge_points 	= [[],[]] # [x],[y]
	min_vert_hough_line 		= (None, None)
	average_line_y_pos 			= min_vert_line[0][0] + (min_vert_line[1][0] - min_vert_line[0][0])/2
	if average_line_y_pos > height - vert_edge_region_threshold: # Edge detected to the left
		for hor_line in bounded_lines[0]: # Check all horizontal lines (min points)
			len_line 	= int(round((hor_line[1][0] - hor_line[0][0])*line_perc))
			min_point 	= hor_line[0]
			x_edge_ind 	= DetectLineEdge(edgel_frame, True, min_point[1], min_point[0], 0)
			min_vert_line_edge_points[0].append(x_edge_ind)
			min_vert_line_edge_points[1].append(min_point[1])
		if filtrate_edge_points:
			min_vert_line_edge_points[1], min_vert_line_edge_points[0] = FiltrateEdgePoints(min_vert_line_edge_points[1], min_vert_line_edge_points[0])
		min_vert_hough_line = HoughLineEdgePoints(edgel_frame, min_vert_line_edge_points, True)

	if max_hor_hough_line[0] == None or min_hor_hough_line[0] == None or max_vert_hough_line[0] == None or min_vert_hough_line[0] == None:

# 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]


# Path: src/DroneVision/DroneVision_src/imgProcessing/featureDetection/generalDetectors/detectEdges.py
import cv2
import numpy as np
from Settings.Exceptions import DroneVisionError
from detectLines import HoughLineEdgePoints, DrawHoughLine
from src.DroneVision.DroneVision_src.imgProcessing.frameTools.frameTools import GetShape


	max_vert_line_edge_points	= [[],[]] # [x],[y]
	max_vert_hough_line 		= (None, None)
	average_line_y_pos			= max_vert_line[0][0] + (max_vert_line[1][0] - max_vert_line[0][0])/2
	if average_line_y_pos < vert_edge_region_threshold: # Edge detected to the right
		for hor_line in bounded_lines[0]: # Check all horizontal lines (max points)
			len_line 	= int(round((hor_line[1][0] - hor_line[0][0])*line_perc))
			max_point 	= hor_line[1]
			x_edge_ind 	= DetectLineEdge(edgel_frame, True, max_point[1], max_point[0], height-1)
			max_vert_line_edge_points[0].append(x_edge_ind)
			max_vert_line_edge_points[1].append(max_point[1])
		if filtrate_edge_points:
			max_vert_line_edge_points[1], max_vert_line_edge_points[0] = FiltrateEdgePoints(max_vert_line_edge_points[1], max_vert_line_edge_points[0])
		max_vert_hough_line = HoughLineEdgePoints(edgel_frame, max_vert_line_edge_points, True)

	min_vert_line_edge_points 	= [[],[]] # [x],[y]
	min_vert_hough_line 		= (None, None)
	average_line_y_pos 			= min_vert_line[0][0] + (min_vert_line[1][0] - min_vert_line[0][0])/2
	if average_line_y_pos > height - vert_edge_region_threshold: # Edge detected to the left
		for hor_line in bounded_lines[0]: # Check all horizontal lines (min points)
			len_line 	= int(round((hor_line[1][0] - hor_line[0][0])*line_perc))
			min_point 	= hor_line[0]
			x_edge_ind 	= DetectLineEdge(edgel_frame, True, min_point[1], min_point[0], 0)
			min_vert_line_edge_points[0].append(x_edge_ind)
			min_vert_line_edge_points[1].append(min_point[1])
		if filtrate_edge_points:
			min_vert_line_edge_points[1], min_vert_line_edge_points[0] = FiltrateEdgePoints(min_vert_line_edge_points[1], min_vert_line_edge_points[0])
		min_vert_hough_line = HoughLineEdgePoints(edgel_frame, min_vert_line_edge_points, True)

	if max_hor_hough_line[0] == None or min_hor_hough_line[0] == None or max_vert_hough_line[0] == None or min_vert_hough_line[0] == None:

		raise DroneVisionError('detect_boundary_edge_not_found_all_edge_lines')