#ifndef _VERTEX_H_
#define _VERTEX_H_


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

purpose:	 
*********************************************************************/



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

#include <gl/gl.h>




enum VertexType {
 	VT_Surface,
 	VT_Surface_Boundary,
 	VT_Unknown
 };



class VertexGroup;

class Vertex : public SelectableItem
{
public:
	Vertex(const Point3f& p)
		: point_(p)
		, normal_(0.0f, 0.0f, 0.0f)
		, index_(0)
		, vertex_group_(nil)
		, type_(VT_Unknown)
	{
	}

	Vertex(float x, float y , float z)
		: point_(x, y, z)
		, normal_(0.0f, 0.0f, 0.0f)
		, index_(0)
		, vertex_group_(nil)
		, type_(VT_Unknown)
	{
	}

	Vertex(float x, float y , float z, float nx, float ny , float nz)
		: point_(x, y, z)
		, normal_(nx, ny, nz)
		, index_(0)
		, vertex_group_(nil)
		, type_(VT_Unknown)
	{
	}

	const Point3f& point() const     { return point_ ; }
	Point3f& point()                 { return point_ ; }
	void set_point(const Point3f& p) { point_ = p ;    }
	void set_point(float x, float y, float z) { point_ = Point3f(x, y, z); }

	const Vector3f& normal() const		{ return normal_; }
	Vector3f& normal()					{ return normal_; }
	void set_normal(const Vector3f& n)	{ normal_ = n;    }

	VertexGroup* vertex_group() { return vertex_group_; }
	void set_vertex_group(VertexGroup* g) { vertex_group_ = g; }

	unsigned int index() const { return index_; }
	void set_index(unsigned int idx) { index_ = idx; }

	inline VertexType type() const { return type_; }
	inline void set_type(VertexType t) { type_ = t; }

	const float& point_size() const {	return Global::point_size; }

	inline void draw() const ;
	inline void draw_with_name(unsigned int i) const ;

private:
	Point3f		 point_ ;
	Vector3f     normal_;

	VertexGroup* vertex_group_;

	unsigned int index_;

	VertexType	 type_;
} ;



void Vertex::draw() const {
	glColor4fv(color().data());
	glNormal3f(normal_.x(), normal_.y(), normal_.z());
	glVertex3f(point_.x(), point_.y(), point_.z());
}


void Vertex::draw_with_name(unsigned int i) const {
	glPushName(i);
	glRasterPos3f(point_.x(), point_.y(), point_.z());
	glPopName();
}




#endif