1 #ifndef _OCME_QUANTIZED_PLANE_
2 #define _OCME_QUANTIZED_PLANE_
3 
4 #include <vcg/space/plane3.h>
5 #include <vcg/space/box3.h>
6 
7 void ToPolar(vcg::Point3f n, float & alpha, float & beta);
8 vcg::Point3f FromPolar(float   alpha, float   beta);
9 
10 unsigned int SizeCompressedPlane();
11 void CompressPlane(vcg::Plane3f p, vcg::Box3f box, char * buf );
12 void DeCompressPlane(char * buf, vcg::Box3f box , vcg::Plane3f &  p);
13 
14 template <class S>
SizeCompressedPlane()15 unsigned int SizeCompressedPlane(){return 3*sizeof(S);};
16 
17 template <class S>
CompressPlane(vcg::Plane3f p,vcg::Box3f box,S * buf)18 void CompressPlane(vcg::Plane3f p, vcg::Box3f box, S * buf ){
19 
20 	S max_value = std::numeric_limits<S>::max();
21 	float alpha,beta;
22 
23 	float newoffset = -vcg::Distance(box.Center(),p);
24 
25 	buf [0] = (newoffset* max_value) / box.Diag() ; //newoffset in -Diag()/2 +Diag()/2
26 
27 	ToPolar(p.Direction(),alpha,beta);
28 
29 	buf[1] = (alpha* max_value) /(2.f*M_PI);  // alpha in -PI + PI
30 	buf[2] = (beta * max_value) /(    M_PI);	// beta in -PI/2 +PI/2
31 
32 }
33 
34 template <class S>
DeCompressPlane(S * buf,vcg::Box3f box,vcg::Plane3f & p)35 void DeCompressPlane(S * buf, vcg::Box3f box , vcg::Plane3f &  p){
36 	S max_value = std::numeric_limits<S>::max();
37 
38 	float offset = (buf[0] * box.Diag()) / max_value;
39 	float alpha  = (buf[1] * 2.f * M_PI) /max_value;
40 	float beta   = (buf[2] *       M_PI) /max_value;
41 
42 	p.SetDirection(FromPolar(alpha,beta));
43 	p.SetOffset(offset);
44 	p.SetOffset(-vcg::Distance(-box.Center(),p));
45 }
46 
47 template <class S>
48 struct Plane3Comp{
49 	S v[3];
50 
51 	// this is quite correct. the maximum value for the offset corresponds to a plane with
52 	// degenerate intersection with the cube (only one corner) or no intersection at all
SetNullPlane3Comp53 	void SetNull(){v[0] = std::numeric_limits<S>::max();}
IsNullPlane3Comp54 	bool IsNull(){return (v[0] == std::numeric_limits<S>::max());}
55 };
56 
57 #endif