Edited Comments and GPL license
This commit is contained in:
parent
dd6fcedec8
commit
c6f15ed3ad
|
@ -0,0 +1,249 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VCGLIB_COLOR4
|
||||
#define __VCGLIB_COLOR4
|
||||
|
||||
#include <vcg/space/point4.h>
|
||||
|
||||
namespace vcg {
|
||||
template <class T>
|
||||
class Color4 : public Point4<T>
|
||||
{
|
||||
public:
|
||||
/// Constant for storing standard colors.
|
||||
/// Each color is stored in a simple in so that the bit pattern match with the one of Color4b.
|
||||
enum ColorConstant {
|
||||
Black =0xff000000,
|
||||
Gray =0xff808080,
|
||||
White =0xffffffff,
|
||||
|
||||
Red =0xff0000ff,
|
||||
Green =0xff00ff00,
|
||||
Blue =0xffff0000,
|
||||
|
||||
Cyan =0xffffff00,
|
||||
Yellow =0xff00ffff,
|
||||
Magenta=0xffff00ff,
|
||||
|
||||
LightGray =0xffc0c0c0,
|
||||
LightRed =0xff8080ff,
|
||||
LightGreen =0xff80ff80,
|
||||
LightBlue =0xffff8080,
|
||||
|
||||
DarkGray =0xff404040,
|
||||
DarkRed =0xff000040,
|
||||
DarkGreen =0xff004000,
|
||||
DarkBlue =0xff400000,
|
||||
};
|
||||
|
||||
inline Color4 ( const T nx, const T ny, const T nz , const T nw ) :Point4<T>(nx,ny,nz,nw) {};
|
||||
inline Color4 ( Color4 &c) :Point4<T>(c) {};
|
||||
inline Color4 (){};
|
||||
inline Color4 (ColorConstant cc);
|
||||
|
||||
template <class Q>
|
||||
inline void Import(const Color4<Q> & b )
|
||||
{
|
||||
_v[0] = T(b[0]);
|
||||
_v[1] = T(b[1]);
|
||||
_v[2] = T(b[2]);
|
||||
_v[3] = T(b[3]);
|
||||
}
|
||||
|
||||
inline void Import(const Color4<float> &b);
|
||||
inline void Import(const Color4<unsigned char> &b);
|
||||
|
||||
inline void lerp(const Color4 &c0, const Color4 &c1, const float x);
|
||||
inline void lerp(const Color4 &c0, const Color4 &c1, const Color4 &c2, const Point3f &ip);
|
||||
inline void ColorRamp(const float &minf,const float &maxf ,float v );
|
||||
|
||||
inline void SetRGB( unsigned char r, unsigned char g, unsigned char b )
|
||||
{
|
||||
_v[0] = r;
|
||||
_v[1] = g;
|
||||
_v[2] = b;
|
||||
_v[3] = 0;
|
||||
}
|
||||
|
||||
void SetHSVColor( float h, float s, float v){
|
||||
float r,g,b;
|
||||
if(s==0.0){ // gray color
|
||||
r = g = b = v;
|
||||
_v[0]=(unsigned char)(255*r);_v[1]=(unsigned char)(255*g);_v[2]=(unsigned char)(255*b);
|
||||
_v[3]=255;
|
||||
return;
|
||||
}
|
||||
if(h==1.0) h = 0.0;
|
||||
|
||||
int i = int( floor(h*6.0) );
|
||||
float f = float(h*6.0f - floor(h*6.0f));
|
||||
|
||||
float p = v*(1.0f-s);
|
||||
float q = v*(1.0f-s*f);
|
||||
float t = v*(1.0f-s*(1.0f-f));
|
||||
|
||||
switch(i){
|
||||
case 0: r=v; g=t; b=p; break;
|
||||
case 1: r=q; g=v; b=p; break;
|
||||
case 2: r=p; g=v; b=t; break;
|
||||
case 3: r=p; g=q; b=v; break;
|
||||
case 4: r=t; g=p; b=v; break;
|
||||
case 5: r=v; g=p; b=q; break;
|
||||
}
|
||||
_v[0]=(unsigned char)(255*r);_v[1]=(unsigned char)(255*g);_v[2]=(unsigned char)(255*b);
|
||||
_v[3]=255;
|
||||
// _v[0]=r*256;_v[1]=g*256;_v[2]=b*256;
|
||||
}
|
||||
|
||||
inline static Color4 GrayShade(float f)
|
||||
{
|
||||
return ColorF(f,f,f,1);
|
||||
}
|
||||
|
||||
inline void SetGrayShade(float f)
|
||||
{
|
||||
*this = ColorF(f,f,f,1);
|
||||
}
|
||||
|
||||
|
||||
// Given an integer returns a well ordering of colors
|
||||
// so that every color differs as much as possible form the previous one
|
||||
// params:
|
||||
// n is the maximum expected value (max of the range)
|
||||
// v is the requested position
|
||||
|
||||
inline static Color4 Scatter(int n, int a,float Sat=.3f,float Val=.9f)
|
||||
{
|
||||
int b, k, m=n;
|
||||
int r =n;
|
||||
|
||||
for (b=0, k=1; k<n; k<<=1)
|
||||
if (a<<1>=m) {
|
||||
if (b==0) r = k;
|
||||
b += k;
|
||||
a -= (m+1)>>1;
|
||||
m >>= 1;
|
||||
}
|
||||
else m = (m+1)>>1;
|
||||
if (r>n-b) r = n-b;
|
||||
|
||||
//TRACE("Scatter range 0..%i, in %i out %i\n",n,a,b);
|
||||
Color4 rc;
|
||||
rc.SetHSVColor(float(b)/float(n),Sat,Val);
|
||||
return rc;
|
||||
}
|
||||
|
||||
};
|
||||
template <class T>
|
||||
inline void Color4<T>::lerp(const Color4<T> &c0, const Color4<T> &c1, const float x)
|
||||
{
|
||||
assert(x>=0);
|
||||
assert(x<=1);
|
||||
|
||||
_v[0]=(T)(c1._v[0]*x + c0._v[0]*(1.0f-x));
|
||||
_v[1]=(T)(c1._v[1]*x + c0._v[1]*(1.0f-x));
|
||||
_v[2]=(T)(c1._v[2]*x + c0._v[2]*(1.0f-x));
|
||||
_v[3]=(T)(c1._v[3]*x + c0._v[3]*(1.0f-x));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void Color4<T>::lerp(const Color4<T> &c0, const Color4<T> &c1, const Color4<T> &c2, const Point3f &ip)
|
||||
{
|
||||
assert(fabs(ip[0]+ip[1]+ip[2]-1)<0.00001);
|
||||
|
||||
c[0]=(T)(c0.c[0]*ip[0] + c1.c[0]*ip[1]+ c2.c[0]*ip[2]);
|
||||
c[1]=(T)(c0.c[1]*ip[0] + c1.c[1]*ip[1]+ c2.c[1]*ip[2]);
|
||||
c[2]=(T)(c0.c[2]*ip[0] + c1.c[2]*ip[1]+ c2.c[2]*ip[2]);
|
||||
c[3]=(T)(c0.c[3]*ip[0] + c1.c[3]*ip[1]+ c2.c[3]*ip[2]);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline void Color4<T>::ColorRamp(const float &minf,const float &maxf ,float v )
|
||||
{
|
||||
if(v < minf ) { *this=Color4(Color4::Red); return; }
|
||||
|
||||
float step=(maxf-minf)/4;
|
||||
v-=minf;
|
||||
if(v<step) {lerp(Color4(Color4::Red), Color4(Color4::Yellow),v/step); return;}
|
||||
v-=step;
|
||||
if(v<step) {lerp(Color4(Color4::Yellow),Color4(Color4::Green),v/step);return;}
|
||||
v-=step;
|
||||
if(v<step) {lerp(Color4(Color4::Green),Color4(Color4::Cyan),v/step); return;}
|
||||
v-=step;
|
||||
if(v<step) {lerp(Color4(Color4::Cyan),Color4(Color4::Blue),v/step); return;}
|
||||
|
||||
*this= Color4(Color4::Blue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void Color4<float>::Import(const Color4<unsigned char> &b)
|
||||
{
|
||||
_v[0]=b[0]/255.0f;
|
||||
_v[1]=b[1]/255.0f;
|
||||
_v[2]=b[2]/255.0f;
|
||||
_v[3]=b[3]/255.0f;
|
||||
}
|
||||
|
||||
inline void Color4<unsigned char>::Import(const Color4<float> &b)
|
||||
{
|
||||
_v[0]=(unsigned char)(b[0]*255.0f);
|
||||
_v[1]=(unsigned char)(b[1]*255.0f);
|
||||
_v[2]=(unsigned char)(b[2]*255.0f);
|
||||
_v[3]=(unsigned char)(b[3]*255.0f);
|
||||
}
|
||||
|
||||
|
||||
//template <class T,class S>
|
||||
//inline void Color4<T>::Import(const Color4<S> &b)
|
||||
//{
|
||||
// _v[0] = T(b[0]);
|
||||
// _v[1] = T(b[1]);
|
||||
// _v[2] = T(b[2]);
|
||||
// _v[3] = T(b[3]);
|
||||
//}
|
||||
//
|
||||
inline Color4<unsigned char>::Color4<unsigned char>(Color4<unsigned char>::ColorConstant cc)
|
||||
{
|
||||
*((int *)this )= cc;
|
||||
}
|
||||
|
||||
inline Color4<float>::Color4<float>(Color4<float>::ColorConstant cc)
|
||||
{
|
||||
Import(Color4<unsigned char>((Color4<unsigned char>::ColorConstant)cc));
|
||||
}
|
||||
|
||||
|
||||
typedef Color4<unsigned char> Color4b;
|
||||
typedef Color4<float> Color4f;
|
||||
|
||||
} // end of NameSpace
|
||||
|
||||
#endif
|
|
@ -1,25 +1,32 @@
|
|||
/*#***************************************************************************
|
||||
* VCGLib *
|
||||
* *
|
||||
* Visual Computing Group o> *
|
||||
* IEI Institute, CNUCE Institute, CNR Pisa <| *
|
||||
* / \ *
|
||||
* Copyright(C) 1999 by Paolo Cignoni, Claudio Rocchini *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* Permission to use, copy, modify, distribute and sell this software and *
|
||||
* its documentation for any purpose is hereby granted without fee, provided *
|
||||
* that the above copyright notice appear in all copies and that both that *
|
||||
* copyright notice and this permission notice appear in supporting *
|
||||
* documentation. the author makes no representations about the suitability *
|
||||
* of this software for any purpose. It is provided "as is" without express *
|
||||
* or implied warranty. *
|
||||
* *
|
||||
*****************************************************************************/
|
||||
/*#**************************************************************************
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
$Id: point3.h,v 1.4 2004-02-09 13:48:02 cignoni Exp $
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.4 2004/02/09 13:48:02 cignoni
|
||||
Edited doxygen comments
|
||||
|
||||
Revision 1.3 2004/02/06 02:25:54 cignoni
|
||||
First working release.
|
||||
|
||||
|
@ -32,7 +39,6 @@ First commit...
|
|||
#ifndef __VCGLIB_POINT3
|
||||
#define __VCGLIB_POINT3
|
||||
|
||||
//#include <limits>
|
||||
#include <assert.h>
|
||||
#include <vcg/math/base.h>
|
||||
|
||||
|
@ -55,7 +61,7 @@ public:
|
|||
|
||||
//@{
|
||||
|
||||
/** @name Standard Constructors and Initializer.
|
||||
/** @name Standard Constructors and Initializers
|
||||
No casting operators have been introduced to avoid automatic unattended (and costly) conversion between different point types
|
||||
**/
|
||||
|
||||
|
@ -112,15 +118,13 @@ public:
|
|||
return Point3(T(b[0]),T(b[1]),T(b[2]));
|
||||
}
|
||||
|
||||
//@}
|
||||
//@}
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Data Access.
|
||||
access to data is done by overloading of [] or explicit naming of coords (x,y,z)**/
|
||||
|
||||
// Accesso alle componenti
|
||||
inline const T &x() const { return _v[0]; }
|
||||
inline const T &y() const { return _v[1]; }
|
||||
inline const T &z() const { return _v[2]; }
|
||||
inline T &x() { return _v[0]; }
|
||||
inline T &y() { return _v[1]; }
|
||||
inline T &z() { return _v[2]; }
|
||||
inline T & operator [] ( const int i )
|
||||
{
|
||||
assert(i>=0 && i<3);
|
||||
|
@ -131,6 +135,12 @@ public:
|
|||
assert(i>=0 && i<3);
|
||||
return _v[i];
|
||||
}
|
||||
inline const T &X() const { return _v[0]; }
|
||||
inline const T &Y() const { return _v[1]; }
|
||||
inline const T &Z() const { return _v[2]; }
|
||||
inline T &X() { return _v[0]; }
|
||||
inline T &Y() { return _v[1]; }
|
||||
inline T &Z() { return _v[2]; }
|
||||
inline const T * V() const
|
||||
{
|
||||
return _v;
|
||||
|
@ -145,7 +155,13 @@ public:
|
|||
assert(i>=0 && i<3);
|
||||
return _v[i];
|
||||
}
|
||||
// Operatori matematici di base
|
||||
//@}
|
||||
//@{
|
||||
|
||||
/** @name Classical overloading of operators
|
||||
Note
|
||||
**/
|
||||
|
||||
inline Point3 operator + ( Point3 const & p) const
|
||||
{
|
||||
return Point3<T>( _v[0]+p._v[0], _v[1]+p._v[1], _v[2]+p._v[2] );
|
||||
|
@ -162,12 +178,12 @@ public:
|
|||
{
|
||||
return Point3<T>( _v[0]/s, _v[1]/s, _v[2]/s );
|
||||
}
|
||||
// dot product
|
||||
/// Dot product
|
||||
inline T operator * ( Point3 const & p ) const
|
||||
{
|
||||
return ( _v[0]*p._v[0] + _v[1]*p._v[1] + _v[2]*p._v[2] );
|
||||
}
|
||||
// Cross product
|
||||
/// Cross product
|
||||
inline Point3 operator ^ ( Point3 const & p ) const
|
||||
{
|
||||
return Point3 <T>
|
||||
|
@ -246,8 +262,14 @@ public:
|
|||
fi = (T)acos( _v[2]/ro );
|
||||
}
|
||||
|
||||
// Operatori di confronto (ordinamento lessicografico)
|
||||
inline bool operator == ( Point3 const & p ) const
|
||||
//@}
|
||||
//@{
|
||||
|
||||
/** @name Comparison Operators.
|
||||
Note that the reverse z prioritized ordering, useful in many situations.
|
||||
**/
|
||||
|
||||
inline bool operator == ( Point3 const & p ) const
|
||||
{
|
||||
return _v[0]==p._v[0] && _v[1]==p._v[1] && _v[2]==p._v[2];
|
||||
}
|
||||
|
@ -285,7 +307,7 @@ public:
|
|||
{
|
||||
return Point3<T> ( -_v[0], -_v[1], -_v[2] );
|
||||
}
|
||||
|
||||
//@}
|
||||
// Casts
|
||||
#ifdef __VCG_USE_CAST
|
||||
inline operator Point3<int> (){ return Point3<int> (_v[0],_v[1],_v[2]); }
|
||||
|
|
|
@ -0,0 +1,288 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VCGLIB_POINT4
|
||||
#define __VCGLIB_POINT4
|
||||
|
||||
#include <vcg/space/point3.h>
|
||||
|
||||
namespace vcg {
|
||||
|
||||
|
||||
|
||||
template <class T> class Point4
|
||||
{
|
||||
protected:
|
||||
T _v[4];
|
||||
|
||||
public:
|
||||
typedef T scalar;
|
||||
|
||||
|
||||
inline Point4 () { }
|
||||
inline Point4 ( const T nx, const T ny, const T nz , const T nw )
|
||||
{
|
||||
_v[0] = nx; _v[1] = ny; _v[2] = nz; _v[3] = nw;
|
||||
}
|
||||
inline Point4 ( const T p[4] )
|
||||
{
|
||||
_v[0] = p[0]; _v[1]= p[1]; _v[2] = p[2]; _v[3]= p[3];
|
||||
}
|
||||
inline Point4 ( const Point4 & p )
|
||||
{
|
||||
_v[0]= p._v[0]; _v[1]= p._v[1]; _v[2]= p._v[2]; _v[3]= p._v[3];
|
||||
}
|
||||
inline Point4 ( const Point3<T> & p )
|
||||
{
|
||||
_v[0] = p.V(0);
|
||||
_v[1] = p.V(1);
|
||||
_v[2] = p.V(2);
|
||||
_v[3] = 1.0;
|
||||
}
|
||||
inline Point4 & operator = ( const Point4 & p )
|
||||
{
|
||||
_v[0]= p._v[0]; _v[1]= p._v[1]; _v[2]= p._v[2]; _v[3]= p._v[3];
|
||||
return *this;
|
||||
}
|
||||
inline T &x() {return _v[0];}
|
||||
inline T &y() {return _v[1];}
|
||||
inline T &z() {return _v[2];}
|
||||
inline T &w() {return _v[3];}
|
||||
inline const T & operator [] ( const int i ) const
|
||||
{
|
||||
assert(i>=0 && i<4);
|
||||
return _v[i];
|
||||
}
|
||||
inline T & operator [] ( const int i )
|
||||
{
|
||||
assert(i>=0 && i<4);
|
||||
return _v[i];
|
||||
}
|
||||
inline T const * V() const
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
inline const T & V ( const int i ) const
|
||||
{
|
||||
assert(i>=0 && i<4);
|
||||
return _v[i];
|
||||
}
|
||||
inline T & V ( const int i )
|
||||
{
|
||||
assert(i>=0 && i<4);
|
||||
return _v[i];
|
||||
}
|
||||
|
||||
inline Point4 operator + ( const Point4 & p) const
|
||||
{
|
||||
return Point4( _v[0]+p._v[0], _v[1]+p._v[1], _v[2]+p._v[2], _v[3]+p._v[3] );
|
||||
}
|
||||
inline Point4 operator - ( const Point4 & p) const
|
||||
{
|
||||
return Point4( _v[0]-p._v[0], _v[1]-p._v[1], _v[2]-p._v[2], _v[3]-p._v[3] );
|
||||
}
|
||||
inline Point4 operator * ( const T s ) const
|
||||
{
|
||||
return Point4( _v[0]*s, _v[1]*s, _v[2]*s, _v[3]*s );
|
||||
}
|
||||
inline Point4 operator / ( const T s ) const
|
||||
{
|
||||
return Point4( _v[0]/s, _v[1]/s, _v[2]/s, _v[3]/s );
|
||||
}
|
||||
inline T operator * ( const Point4 & p ) const
|
||||
{
|
||||
return _v[0]*p._v[0] + _v[1]*p._v[1] + _v[2]*p._v[2] + _v[3]*p._v[3];
|
||||
}
|
||||
inline Point4 & operator += ( const Point4 & p)
|
||||
{
|
||||
_v[0] += p._v[0]; _v[1] += p._v[1]; _v[2] += p._v[2]; _v[3] += p._v[3];
|
||||
return *this;
|
||||
}
|
||||
inline Point4 & operator -= ( const Point4 & p )
|
||||
{
|
||||
_v[0] -= p._v[0]; _v[1] -= p._v[1]; _v[2] -= p._v[2]; _v[3] -= p._v[3];
|
||||
return *this;
|
||||
}
|
||||
inline Point4 & operator *= ( const T s )
|
||||
{
|
||||
_v[0] *= s; _v[1] *= s; _v[2] *= s; _v[3] *= s;
|
||||
return *this;
|
||||
}
|
||||
inline Point4 & operator /= ( const T s )
|
||||
{
|
||||
_v[0] /= s; _v[1] /= s; _v[2] /= s; _v[3] /= s;
|
||||
return *this;
|
||||
}
|
||||
inline T Norm() const
|
||||
{
|
||||
return Sqrt( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3] );
|
||||
}
|
||||
inline T SquaredNorm() const
|
||||
{
|
||||
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
|
||||
}
|
||||
|
||||
inline Point4 & Normalize()
|
||||
{
|
||||
T n = Sqrt(_v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3] );
|
||||
if(n>0.0) { _v[0] /= n; _v[1] /= n; _v[2] /= n; _v[3] /= n; }
|
||||
return *this;
|
||||
}
|
||||
inline Point4 operator - () const
|
||||
{
|
||||
return Point4( -_v[0], -_v[1], -_v[2], -_v[3] );
|
||||
}
|
||||
inline bool operator == ( const Point4& p ) const
|
||||
{
|
||||
return _v[0]==p._v[0] && _v[1]==p._v[1] && _v[2]==p._v[2] && _v[3]==p._v[3];
|
||||
}
|
||||
inline bool operator != ( const Point4 & p ) const
|
||||
{
|
||||
return _v[0]!=p._v[0] || _v[1]!=p._v[1] || _v[2]!=p._v[2] || _v[3]!=p._v[3];
|
||||
}
|
||||
inline bool operator < ( Point4 const & p ) const
|
||||
{
|
||||
return (_v[3]!=p._v[3])?(_v[3]<p._v[3]):
|
||||
(_v[2]!=p._v[2])?(_v[2]<p._v[2]):
|
||||
(_v[1]!=p._v[1])?(_v[1]<p._v[1]):
|
||||
(_v[0]<p._v[0]);
|
||||
}
|
||||
inline bool operator > ( const Point4 & p ) const
|
||||
{
|
||||
return (_v[3]!=p._v[3])?(_v[3]>p._v[3]):
|
||||
(_v[2]!=p._v[2])?(_v[2]>p._v[2]):
|
||||
(_v[1]!=p._v[1])?(_v[1]>p._v[1]):
|
||||
(_v[0]>p._v[0]);
|
||||
}
|
||||
inline bool operator <= ( const Point4 & p ) const
|
||||
{
|
||||
return (_v[3]!=p._v[3])?(_v[3]< p._v[3]):
|
||||
(_v[2]!=p._v[2])?(_v[2]< p._v[2]):
|
||||
(_v[1]!=p._v[1])?(_v[1]< p._v[1]):
|
||||
(_v[0]<=p._v[0]);
|
||||
}
|
||||
inline bool operator >= ( const Point4 & p ) const
|
||||
{
|
||||
return (_v[3]!=p._v[3])?(_v[3]> p._v[3]):
|
||||
(_v[2]!=p._v[2])?(_v[2]> p._v[2]):
|
||||
(_v[1]!=p._v[1])?(_v[1]> p._v[1]):
|
||||
(_v[0]>=p._v[0]);
|
||||
}
|
||||
/// Questa funzione estende il vettore ad un qualsiasi numero di dimensioni
|
||||
/// paddando gli elementi estesi con zeri
|
||||
inline T Ext( const int i ) const
|
||||
{
|
||||
if(i>=0 && i<=3) return _v[i];
|
||||
else return 0;
|
||||
}
|
||||
|
||||
T stable_dot ( const Point4<T> & p ) const
|
||||
{
|
||||
T k[4];
|
||||
|
||||
k[0] = _v[0]*p._v[0];
|
||||
k[1] = _v[1]*p._v[1];
|
||||
k[2] = _v[2]*p._v[2];
|
||||
k[3] = _v[3]*p._v[3];
|
||||
sort(k+0,k+4, MagnitudoComparer<T>() );
|
||||
T q = k[0];
|
||||
q += k[1];
|
||||
q += k[2];
|
||||
q += k[3];
|
||||
return q;
|
||||
}
|
||||
|
||||
template <class Q>
|
||||
inline void Import( const Point4<Q> & b )
|
||||
{
|
||||
_v[0] = T(b[0]);
|
||||
_v[1] = T(b[1]);
|
||||
_v[2] = T(b[2]);
|
||||
_v[3] = T(b[3]);
|
||||
}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
#ifdef __VCG_USE_P4_INTRINSIC__
|
||||
#include <vcg/p4/point4p4.h>
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
T Angle( const Point4<T>& p1, const Point4<T> & p2 )
|
||||
{
|
||||
T w = p1.Norm()*p2.Norm();
|
||||
if(w==0) return -1;
|
||||
T t = (p1*p2)/w;
|
||||
if(t>1) t=1;
|
||||
return T( acos(t) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T Norm( const Point4<T> & p )
|
||||
{
|
||||
return p.Norm();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T SquaredNorm( const Point4<T> & p )
|
||||
{
|
||||
return p.SquaredNorm();
|
||||
}
|
||||
|
||||
/* Deprecato
|
||||
template <class T>
|
||||
inline Point4<T> & Normalize( Point4<T> & p ){
|
||||
T n = Sqrt( p._v[0]*p._v[0] + p._v[1]*p._v[1] + p._v[2]*p._v[2] + p._v[3]*p._v[3] );
|
||||
if(n>0.0) p/=n;
|
||||
return p;
|
||||
}
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
inline T Distance( const Point4<T> & p1, const Point4<T> & p2 )
|
||||
{
|
||||
return Norm(p1-p2);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T SquaredDistance( const Point4<T> & p1, const Point4<T> & p2 )
|
||||
{
|
||||
return SquaredNorm(p1-p2);
|
||||
}
|
||||
|
||||
|
||||
typedef Point4<short> Point4s;
|
||||
typedef Point4<int> Point4i;
|
||||
typedef Point4<float> Point4f;
|
||||
typedef Point4<double> Point4d;
|
||||
|
||||
|
||||
} // end namespace
|
||||
#endif
|
Loading…
Reference in New Issue