// geometry_global.h
#ifndef _GEOMETRY_GLOBAL_H_
#define _GEOMETRY_GLOBAL_H_


/********************************************************************
	created:	 2009/07/23
	created:	 23:7:2009   19:18
	file base:	 geometry_global.h
	author:		 Liangliang Nan
    contact:     liangliang.nan@gmail.com
    affiliation: Shenzhen Institute of Advanced Technology
	
	purpose:	 
*********************************************************************/


#include "geometry_common.h"
#include "geometry_types.h"
#include "color.h"


class Vertex;

namespace Global {

	//////////////////////////////////////////////////////////////////////////
	//-----------------------   global variables

	extern  GEOMETRY_API    float	   light_position[4];
	extern  GEOMETRY_API    float      light_specular;
	extern  GEOMETRY_API    float      light_diffuse; 

	// colors for selected and highlighted objects
	extern  GEOMETRY_API 	Colorf	   color_selected;   
	extern  GEOMETRY_API 	Colorf	   color_highlighted;    

	extern  GEOMETRY_API 	Colorf	   wire_frame_color; 
	extern  GEOMETRY_API 	float	   facet_transparency;
	extern  GEOMETRY_API 	Colorf	   facet_color; 

	extern  GEOMETRY_API 	float      line_width;
	extern  GEOMETRY_API 	float      highlighted_line_width;

	extern  GEOMETRY_API  	float      point_size;
	extern  GEOMETRY_API 	float      highlighted_point_size;

	//////////////////////////////////////////////////////////////////////////

	GEOMETRY_API    Bbox2f	bbox_of(const std::vector<Point2f>& points);
	GEOMETRY_API    Bbox3f	bbox_of(const std::vector<Point3f>& points);
	GEOMETRY_API    Bbox3f	bbox_of(const std::vector<Vertex*> pts) ;

	//////////////////////////////////////////////////////////////////////////

	GEOMETRY_API    float	normalize(Vector2f& v) ; 
	GEOMETRY_API    float	length_of(const Vector2f& v);

	GEOMETRY_API    float	normalize(Vector3f& v) ; 
	GEOMETRY_API    float	length_of(const Vector3f& v);

	GEOMETRY_API    Vector3f	normal_of(const Plane3f& plane) ; 

	// fitting a plane to given points
	// q denotes a fitting quality (1 - lambda_min/lambda_max):
	//  1 is best (zero variance orthogonally to the fitting line)
	//  0 is worst (isotropic case, returns a plane with default direction)
	GEOMETRY_API	float	fit_plane(const std::vector<Point3f>& vertices, Plane3f& plane);		
	GEOMETRY_API	float	fit_plane(const std::vector<Vertex*>& vertices, Plane3f& plane);	

	GEOMETRY_API	float	radian_to_degree(float rad) ;
	GEOMETRY_API	float	degree_to_radian(float deg) ;
	GEOMETRY_API	Point3f rotate_in_radian(const Point3f& p, const Point3f& axis_pos, const Vector3f& axis_dir, float angle) ;
	GEOMETRY_API	Point3f rotate_in_degree(const Point3f& p, const Point3f& axis_pos, const Vector3f& axis_dir, float angle) ;

	GEOMETRY_API    bool	is_point_in_polygon(const Point2f& p, const std::vector<Point2f>& polygon) ; 
} ;


#endif



