util Namespace Reference

Various utility classes for generic programming. More...

Namespaces

namespace  Shapes
 

This namespace contains various shapes.


Classes

class  Buffer
 A ranged checked array. More...
class  CircIterator
 Creates a circular iterator from a range of forward iterators. More...
class  Color
 A utility class to encapsulate color data. More...
class  Contour
 Contour utility class. More...
struct  CrossProductType< 2, T >
 For 2d -> a scalar. More...
struct  CrossProductType< 3, T >
 For 3d -> a vector. More...
class  FileObject
 This class is the base class for any object that might be watched by the WatchDog. More...
class  Function
 A utility class for functions. More...
class  GraphInset
 Class used to draw a graph of time stamped data in the model window. More...
class  KeyFramer
 Class describing the evolution of a bspline surface through time. More...
class  Materials
 A utility class for materials. More...
class  Matrix
 Class representing a fixed-size matrix. More...
class  Palette
 A utility class for palettes. More...
class  Parms
 A utility class to parse L-Studio like parameter files. More...
class  Point
 A 3D point/vector class. More...
class  range
 Class representing a range of values from two iterators. More...
class  refpair
 Class used to hold references for the util::tie() function. More...
class  SelectMemberIterator
 Iterate over a container of structure, dereferencing only a member of it. More...
struct  set_vector
 Define a class using (small) vectors as unordered sets. More...
class  Tensor
 A growth tensor class. More...
class  Texture1D
 A utility class for one-dimensional textures. More...
class  Texture2D
 A utility class for two-dimensional textures. More...
class  Vector
 Vector class supporting all classic classic vector operations. More...
class  WatchDog
 Watch the modifications of file objects for you. More...

Typedefs

typedef Color< double > Colord
typedef Color< float > Colorf

Functions

void __assert_fail (const QString &assertion, const char *file, unsigned int line, const char *function)
void __assert_fail_txt (const QString &assertion, const char *file, unsigned int line, const char *function)
std::string absoluteDir (std::string filename, std::string current_dir=std::string())
 Returns the absolute path of filename.
bool approx (double v1, double v2, double abs_epsilon=VVE_EPSILON, double rel_epsilon=VVE_REL_EPSILON)
 Test if v1 == v2, with floating point error.
template<class T >
clamp (const T &val, const T &min, const T &max)
 A function to clamp a value to a range.
void convertFromQColor (Color< long long > &c, const QColor &col)
void convertFromQColor (Color< long > &c, const QColor &col)
void convertFromQColor (Color< int > &c, const QColor &col)
void convertFromQColor (Color< short > &c, const QColor &col)
void convertFromQColor (Color< char > &c, const QColor &col)
void convertFromQColor (Color< unsigned long long > &c, const QColor &col)
void convertFromQColor (Color< unsigned long > &c, const QColor &col)
void convertFromQColor (Color< unsigned int > &c, const QColor &col)
void convertFromQColor (Color< unsigned short > &c, const QColor &col)
void convertFromQColor (Color< unsigned char > &c, const QColor &col)
void convertFromQColor (Color< long double > &c, const QColor &col)
void convertFromQColor (Color< double > &c, const QColor &col)
void convertFromQColor (Color< float > &c, const QColor &col)
template<class T >
Color< T > convertHSVtoRGB (T h, T s, T v)
 Return a color based on HSV values.
QColor convertToQColor (const Color< long long > &c)
QColor convertToQColor (const Color< long > &c)
QColor convertToQColor (const Color< int > &c)
QColor convertToQColor (const Color< short > &c)
QColor convertToQColor (const Color< char > &c)
QColor convertToQColor (const Color< unsigned long long > &c)
QColor convertToQColor (const Color< unsigned long > &c)
QColor convertToQColor (const Color< unsigned int > &c)
QColor convertToQColor (const Color< unsigned short > &c)
QColor convertToQColor (const Color< unsigned char > &c)
QColor convertToQColor (const Color< long double > &c)
QColor convertToQColor (const Color< double > &c)
QColor convertToQColor (const Color< float > &c)
std::string demangle (std::string s)
 Demangle all the words in the string.
template<size_t dim>
Vector< dim, double > gaussRan (const Vector< dim, double > &mean, const Vector< dim, double > &sigma)
 Generate a random vector with gaussian distribution.
double gaussRan (double mean, double sigma)
 Generate a random number with gaussian distribution.
bool greater (double v1, double v2, double abs_epsilon=VVE_EPSILON, double rel_epsilon=VVE_REL_EPSILON)
 Test if v1 > v2, with floating point error.
bool less (double v1, double v2, double abs_epsilon=VVE_EPSILON, double rel_epsilon=VVE_REL_EPSILON)
 Test if v1 < v2, with floating point error.
template<typename Iterator >
range< Iterator > make_range (const std::pair< Iterator, Iterator > &p)
 Function to create a range from a pair of iterators.
template<typename Iterator >
range< Iterator > make_range (const Iterator &first, const Iterator &last)
 Function to create a range from two iterators.
template<size_t dim, typename T , typename T1 >
Vector< dim, T > map (T(*fct)(const T1 &), const Vector< dim, T1 > &v)
template<size_t dim, typename T , typename T1 >
Vector< dim, T > map (const T &(*fct)(const T1 &), const Vector< dim, T1 > &v)
template<size_t dim, typename T >
Vector< dim, T > map (T(*fct)(T), const Vector< dim, T > &v)
template<size_t dim, typename T >
Vector< dim, T > map (T(*fct)(const T &), const Vector< dim, T > &v)
template<size_t dim, typename T >
Vector< dim, T > map (const T &(*fct)(const T &), const Vector< dim, T > &v)
template<size_t nRows, typename T >
matrix_minor (const Matrix< nRows, nRows, T > &mat, size_t i, size_t j)
template<typename T >
maximum (const T &a, const T &b)
 Return the maximum of two values.
template<typename T >
minimum (const T &a, const T &b)
 Return the minimum of two values.
bool notequal (double v1, double v2, double abs_epsilon=VVE_EPSILON, double rel_epsilon=VVE_REL_EPSILON)
 Test if v1 != v2, with floating point error.
template<class T >
Point< T > operator* (const T &s, const Point< T > &p)
 Scalar multiplication operator.
template<class T >
Point< T > operator* (const Point< T > &p, const T &s)
 Scalar multiplication operator.
template<class T >
std::ostream & operator<< (std::ostream &os, Tensor< T > &tensor)
template<class T , unsigned int size>
std::ostream & operator<< (std::ostream &os, Buffer< T, size > &b)
 Stream output to the array.
template<class T >
std::istream & operator>> (std::istream &is, Tensor< T > &tensor)
QTextStreamoperator>> (QTextStream &ss, bool b)
template<class T , unsigned int size>
std::istream & operator>> (std::istream &is, Buffer< T, size > &b)
 Stream input to the array.
QString qdemangle (std::string s)
 Demangle all the words in the string.
template<size_t dim>
Vector< dim, double > ran (const Vector< dim, double > &V)
 Generate a random vector uniformely distributed between Vector(0) and V.
double ran (double M)
 Generate a random number uniformely distributed between 0 and M.
template<size_t dim>
Vector< dim, long int > random (const Vector< dim, long int > &n)
 Returns a vector of random numbers.
long int random (long int n)
 Returns a random number between 0 and n (excluded), for n <= RAND_MAX.
long int random ()
 Returns a random number between 0 and RAND_MAX.
template<typename T >
bool range_c (const T &min, const T &max, const T &val)
 Check if a value is in a C-style range (closed on lower bound and open on the upper).
template<typename T >
bool range_closed (const T &min, const T &max, const T &val)
 Check if a value is in an closed range.
template<typename T >
bool range_open (const T &min, const T &max, const T &val)
 Check if a value is in an open range.
template<size_t dim, class T >
bool serialization (storage::VVEStorage &store, Vector< dim, T > &vec)
template<size_t nRows, size_t nCols, typename T >
bool serialization (storage::VVEStorage &store, Matrix< nRows, nCols, T > &mat)
void sran (unsigned int seed)
 Initialize the random number generator.
unsigned int sran_time ()
 Initialize the random number with the current time of the day (in microsecond).
template<typename T , typename U >
refpair< T, U > tie (T &x, U &y)
 Tie two variables to the values of a pair.

Variables

QTextStream err (stderr)
QTextStream out (stdout)

Detailed Description

Various utility classes for generic programming.

Namespace containing all the utility classes.


Function Documentation

std::string util::absoluteDir ( std::string  filename,
std::string  current_dir = std::string() 
)

Returns the absolute path of filename.

If filename is not already absolute, it is considered relative to current_dir.

bool util::approx ( double  v1,
double  v2,
double  abs_epsilon = VVE_EPSILON,
double  rel_epsilon = VVE_REL_EPSILON 
) [inline]

Test if v1 == v2, with floating point error.

Definition at line 45 of file floats.h.

Referenced by notequal().

00046   {
00047     double diff = fabs(v1-v2);
00048     if(diff < abs_epsilon) return true;
00049     double tot = fabs(v1)+fabs(v2);
00050     return (diff/tot) < rel_epsilon;
00051   }

template<class T >
T util::clamp ( const T &  val,
const T &  min,
const T &  max 
) [inline]

A function to clamp a value to a range.

Parameters:
val The start value.
min The minimum value of the range.
max The maximum value of the range.

If min is more than max, the function returns max.

Definition at line 19 of file clamp.h.

00019                                                                        {
00020     if (min >= max) return max;
00021     else if (val < min) return min;
00022     else if (val > max) return max;
00023     else return val;
00024   }

template<class T >
Color<T> util::convertHSVtoRGB ( h,
s,
v 
) [inline]

Return a color based on HSV values.

Definition at line 194 of file color.h.

References util::Color< T >::a(), util::Color< T >::b(), util::Color< T >::g(), and util::Color< T >::r().

00194                                           {
00195     // based on Jo's code in medit
00196 
00197     Color<T> rgb;
00198     rgb.a(1.0);
00199 
00200     while (h > 360.0) h -= 360.0;
00201     while (h < 0.0) h += 360.0;
00202 
00203     h /= 60.0;
00204 
00205     int i = int(h);
00206 
00207     double f = h - i;
00208     double p = v * (1 - s);
00209     double q = v * (1 - (s * f));
00210     double t = v * (1 - (s * (1 - f)));
00211 
00212     switch (i) {
00213     case 0: rgb.r(v); rgb.g(t); rgb.b(p); break;
00214     case 1: rgb.r(q); rgb.g(v); rgb.b(p); break;
00215     case 2: rgb.r(p); rgb.g(v); rgb.b(t); break;
00216     case 3: rgb.r(p); rgb.g(q); rgb.b(v); break;
00217     case 4: rgb.r(t); rgb.g(p); rgb.b(v); break;
00218     case 5: rgb.r(v); rgb.g(p); rgb.b(q); break;
00219     }
00220 
00221     return rgb;
00222   }

std::string util::demangle ( std::string  s  ) 

Demangle all the words in the string.

Returns:
The string with all symbols demangled.
template<size_t dim>
Vector<dim,double> util::gaussRan ( const Vector< dim, double > &  mean,
const Vector< dim, double > &  sigma 
) [inline]

Generate a random vector with gaussian distribution.

Parameters:
mean Vector with mean of the gaussian distribution for each dimension
sigma Vector with standard deviation of the gaussian distribution for each dimension

Definition at line 61 of file random.h.

References gaussRan().

00062   {
00063     Vector<dim,double> result;
00064     for(size_t i = 0 ; i < dim ; ++i)
00065       result[i] = gaussRan(mean[i], sigma[i]);
00066     return result;
00067   }

double util::gaussRan ( double  mean,
double  sigma 
)

Generate a random number with gaussian distribution.

Parameters:
mean Mean of the gaussian distribution
sigma Standard deviation of the gaussian distribution

Referenced by gaussRan().

bool util::greater ( double  v1,
double  v2,
double  abs_epsilon = VVE_EPSILON,
double  rel_epsilon = VVE_REL_EPSILON 
) [inline]

Test if v1 > v2, with floating point error.

Definition at line 29 of file floats.h.

Referenced by less().

00030   {
00031     return (v1*(1+rel_epsilon/2) + abs_epsilon/2) > (v2*(1-rel_epsilon/2) - abs_epsilon/2);
00032   }

bool util::less ( double  v1,
double  v2,
double  abs_epsilon = VVE_EPSILON,
double  rel_epsilon = VVE_REL_EPSILON 
) [inline]

Test if v1 < v2, with floating point error.

Definition at line 37 of file floats.h.

References greater().

00038   {
00039     return greater(v2, v1, abs_epsilon, rel_epsilon);
00040   }

template<typename Iterator >
range<Iterator> util::make_range ( const std::pair< Iterator, Iterator > &  p  )  [inline]

Function to create a range from a pair of iterators.

Definition at line 179 of file range.h.

00180   {
00181     return range<Iterator>(p);
00182   }

template<typename Iterator >
range<Iterator> util::make_range ( const Iterator &  first,
const Iterator &  last 
) [inline]
template<typename T >
T util::maximum ( const T &  a,
const T &  b 
) [inline]

Return the maximum of two values.

Parameters:
a The first value.
b The second value.

Definition at line 13 of file minmax.h.

00013                                                           {
00014     return (a > b) ? a : b;
00015   }

template<typename T >
T util::minimum ( const T &  a,
const T &  b 
) [inline]

Return the minimum of two values.

Parameters:
a The first value.
b The second value.

Definition at line 22 of file minmax.h.

00022                                                           {
00023     return (a < b) ? a : b;
00024   }

bool util::notequal ( double  v1,
double  v2,
double  abs_epsilon = VVE_EPSILON,
double  rel_epsilon = VVE_REL_EPSILON 
) [inline]

Test if v1 != v2, with floating point error.

Definition at line 56 of file floats.h.

References approx().

00057   {
00058     return !approx(v1, v2, abs_epsilon, rel_epsilon);
00059   }

template<class T >
Point<T> util::operator* ( const T &  s,
const Point< T > &  p 
) [inline]

Scalar multiplication operator.

Parameters:
p The point to scale.
s The scaling value.

Definition at line 73 of file point.h.

00073                                                       {
00074     return p * s;
00075   }

template<class T >
Point<T> util::operator* ( const Point< T > &  p,
const T &  s 
) [inline]

Scalar multiplication operator.

Parameters:
p The point to scale.
s The scaling value.

Definition at line 62 of file point.h.

References util::Vector< 3, T >::Vector().

00062                                                      {
00063     Point<T> r( p.Vector<3,T>::operator*( s ) );
00064     return r;
00065   }

template<class T , unsigned int size>
std::ostream& util::operator<< ( std::ostream &  os,
Buffer< T, size > &  b 
) [inline]

Stream output to the array.

Parameters:
os The output stream.
b The Buffer object to read from.

The following stream output writes 'size' elements, assuming that elements are seperated by a single space. For this to work, T must have an implemented output stream operator.

Definition at line 58 of file buffer.h.

00058                                                              {
00059     for (unsigned int i = 0; i < size; ++i) {
00060       if (i) os << " ";
00061       os << b[i];
00062     }
00063     return os;
00064   }

template<class T , unsigned int size>
std::istream& util::operator>> ( std::istream &  is,
Buffer< T, size > &  b 
) [inline]

Stream input to the array.

Parameters:
is The input stream.
b The Buffer object to write into.

The following stream input reads 'size' elements, assuming that elements are seperated by whitespace as defined by std::ws. For this to work, T must have an implemented input stream operator.

Definition at line 42 of file buffer.h.

00042                                                              {
00043     for (unsigned int i = 0; i < size; ++i)
00044       is >> std::ws >> b[i];
00045     return is;
00046   }

QString util::qdemangle ( std::string  s  ) 

Demangle all the words in the string.

Returns:
The string with all symbols demangled.
template<size_t dim>
Vector<dim,double> util::ran ( const Vector< dim, double > &  V  )  [inline]

Generate a random vector uniformely distributed between Vector(0) and V.

Definition at line 36 of file random.h.

References ran().

00037   {
00038     Vector<dim,double> result;
00039     for(size_t i = 0 ; i < dim ; ++i)
00040       result[i] = ran(V[i]);
00041     return result;
00042   }

double util::ran ( double  M  ) 

Generate a random number uniformely distributed between 0 and M.

Referenced by ran().

template<size_t dim>
Vector<dim,long int> util::random ( const Vector< dim, long int > &  n  )  [inline]

Returns a vector of random numbers.

Parameters:
n Vector with the maximum number for each dimension

Definition at line 96 of file random.h.

References random().

00097   {
00098     Vector<dim,double> result;
00099     for(size_t i = 0 ; i < dim ; ++i)
00100       result[i] = random(n[i]);
00101     return result;
00102   }

long int util::random ( long int  n  ) 

Returns a random number between 0 and n (excluded), for n <= RAND_MAX.

Vector< dim, long int > util::random (  )  [inline]

Returns a random number between 0 and RAND_MAX.

Returns a vector of random numbers between 0 and RAND_MAX.

Definition at line 78 of file random.h.

Referenced by random().

00079   {
00080     Vector<dim,double> result;
00081     for(size_t i = 0 ; i < dim ; ++i)
00082       result[i] = random();
00083     return result;
00084   }

template<typename T >
bool util::range_c ( const T &  min,
const T &  max,
const T &  val 
) [inline]

Check if a value is in a C-style range (closed on lower bound and open on the upper).

Parameters:
min The minimum range value.
max The maximum range value.
val The value to check.

Definition at line 211 of file range.h.

00211                                                                                {
00212     return (val >= min && val < max);
00213   }

template<typename T >
bool util::range_closed ( const T &  min,
const T &  max,
const T &  val 
) [inline]

Check if a value is in an closed range.

Parameters:
min The minimum range value.
max The maximum range value.
val The value to check.

Definition at line 190 of file range.h.

00190                                                                                     {
00191     return (val >= min && val <= max);
00192   }

template<typename T >
bool util::range_open ( const T &  min,
const T &  max,
const T &  val 
) [inline]

Check if a value is in an open range.

Parameters:
min The minimum range value.
max The maximum range value.
val The value to check.

Definition at line 200 of file range.h.

00200                                                                                   {
00201     return (val > min && val < max);
00202   }

void util::sran ( unsigned int  seed  ) 

Initialize the random number generator.

unsigned int util::sran_time (  ) 

Initialize the random number with the current time of the day (in microsecond).

Returns:
the seed used.
template<typename T , typename U >
refpair<T, U> util::tie ( T &  x,
U &  y 
) [inline]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:25 2013 for VVE by  doxygen 1.6.3