[Bf-blender-cvs] [461d1ed] fluid-mantaflow: added helper classes that were used in intern/smoke too

Sebastián Barschkis noreply at git.blender.org
Thu Mar 17 19:10:51 CET 2016


Commit: 461d1ed860a8ccd20ab29ecec86e87c20aee474b
Author: Sebastián Barschkis
Date:   Wed Mar 9 16:14:20 2016 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rB461d1ed860a8ccd20ab29ecec86e87c20aee474b

added helper classes that were used in intern/smoke too

===================================================================

A	intern/mantaflow/intern/VEC3.h
A	intern/mantaflow/intern/spectrum.cpp
A	intern/mantaflow/intern/spectrum.h

===================================================================

diff --git a/intern/mantaflow/intern/VEC3.h b/intern/mantaflow/intern/VEC3.h
new file mode 100644
index 0000000..dafe5e5
--- /dev/null
+++ b/intern/mantaflow/intern/VEC3.h
@@ -0,0 +1,989 @@
+/** \file smoke/intern/VEC3.h
+ *  \ingroup smoke
+ */
+/******************************************************************************
+ * Copyright 2007 Nils Thuerey
+ * Basic vector class 
+ *****************************************************************************/
+#ifndef BASICVECTOR_H
+#define BASICVECTOR_H
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <iostream>
+#include <sstream>
+
+// use which fp-precision? 1=float, 2=double
+#ifndef FLOATINGPOINT_PRECISION
+#if DDF_DEBUG==1
+#define FLOATINGPOINT_PRECISION 2
+#else // DDF_DEBUG==1
+#define FLOATINGPOINT_PRECISION 1
+#endif // DDF_DEBUG==1
+#endif
+
+// VECTOR_EPSILON is the minimal vector length
+// In order to be able to discriminate floating point values near zero, and
+// to be sure not to fail a comparison because of roundoff errors, use this
+// value as a threshold.  
+
+#if FLOATINGPOINT_PRECISION==1
+typedef float Real;
+#define FP_REAL_MAX __FLT_MAX__
+#define VECTOR_EPSILON (1e-5f)
+#else
+typedef double Real;
+#define FP_REAL_MAX __DBL_MAX__
+#define VECTOR_EPSILON (1e-10)
+#endif
+
+
+// hardcoded limits for now...
+// for e.g. MSVC compiler...
+// some of these defines can be needed
+// for linux systems as well (e.g. FLT_MAX)
+#ifndef __FLT_MAX__
+#	ifdef FLT_MAX  // try to use it instead
+#		define __FLT_MAX__ FLT_MAX
+#	else // FLT_MAX
+#		define __FLT_MAX__ 3.402823466e+38f
+#	endif // FLT_MAX
+#endif // __FLT_MAX__
+#ifndef __DBL_MAX__
+#	ifdef DBL_MAX // try to use it instead
+#		define __DBL_MAX__ DBL_MAX
+#	else // DBL_MAX
+#		define __DBL_MAX__ 1.7976931348623158e+308
+#	endif // DBL_MAX
+#endif // __DBL_MAX__
+
+#ifndef FLT_MAX
+#define FLT_MAX __FLT_MAX__
+#endif
+
+#ifndef DBL_MAX
+#define DBL_MAX __DBL_MAX__
+#endif
+
+#ifndef M_PI
+#	define M_PI 3.1415926536
+#	define M_E  2.7182818284
+#endif
+
+
+
+namespace BasicVector {
+
+
+// basic inlined vector class
+template<class Scalar>
+class Vector3Dim
+{
+public:
+  // Constructor
+  inline Vector3Dim();
+  // Copy-Constructor
+  inline Vector3Dim(const Vector3Dim<Scalar> &v );
+  inline Vector3Dim(const float *);
+  inline Vector3Dim(const double *);
+  // construct a vector from one Scalar
+  inline Vector3Dim(Scalar);
+  // construct a vector from three Scalars
+  inline Vector3Dim(Scalar, Scalar, Scalar);
+
+	// get address of array for OpenGL
+	Scalar *getAddress() { return value; }
+
+  // Assignment operator
+  inline const Vector3Dim<Scalar>& operator=  (const Vector3Dim<Scalar>& v);
+  // Assignment operator
+  inline const Vector3Dim<Scalar>& operator=  (Scalar s);
+  // Assign and add operator
+  inline const Vector3Dim<Scalar>& operator+= (const Vector3Dim<Scalar>& v);
+  // Assign and add operator
+  inline const Vector3Dim<Scalar>& operator+= (Scalar s);
+  // Assign and sub operator
+  inline const Vector3Dim<Scalar>& operator-= (const Vector3Dim<Scalar>& v);
+  // Assign and sub operator
+  inline const Vector3Dim<Scalar>& operator-= (Scalar s);
+  // Assign and mult operator
+  inline const Vector3Dim<Scalar>& operator*= (const Vector3Dim<Scalar>& v);
+  // Assign and mult operator
+  inline const Vector3Dim<Scalar>& operator*= (Scalar s);
+  // Assign and div operator
+  inline const Vector3Dim<Scalar>& operator/= (const Vector3Dim<Scalar>& v);
+  // Assign and div operator
+  inline const Vector3Dim<Scalar>& operator/= (Scalar s);
+
+
+  // unary operator
+  inline Vector3Dim<Scalar> operator- () const;
+
+  // binary operator add
+  inline Vector3Dim<Scalar> operator+ (const Vector3Dim<Scalar>&) const;
+  // binary operator add
+  inline Vector3Dim<Scalar> operator+ (Scalar) const;
+  // binary operator sub
+  inline Vector3Dim<Scalar> operator- (const Vector3Dim<Scalar>&) const;
+  // binary operator sub
+  inline Vector3Dim<Scalar> operator- (Scalar) const;
+  // binary operator mult
+  inline Vector3Dim<Scalar> operator* (const Vector3Dim<Scalar>&) const;
+  // binary operator mult
+  inline Vector3Dim<Scalar> operator* (Scalar) const;
+  // binary operator div
+  inline Vector3Dim<Scalar> operator/ (const Vector3Dim<Scalar>&) const;
+  // binary operator div
+  inline Vector3Dim<Scalar> operator/ (Scalar) const;
+
+  // Projection normal to a vector
+  inline Vector3Dim<Scalar>	  getOrthogonalntlVector3Dim() const;
+  // Project into a plane
+  inline const Vector3Dim<Scalar>& projectNormalTo(const Vector3Dim<Scalar> &v);
+  
+  // minimize
+  inline const Vector3Dim<Scalar> &minimize(const Vector3Dim<Scalar> &);
+  // maximize
+  inline const Vector3Dim<Scalar> &maximize(const Vector3Dim<Scalar> &);
+  
+  // access operator
+  inline Scalar& operator[](unsigned int i);
+  // access operator
+  inline const Scalar& operator[](unsigned int i) const;
+
+	//! actual values
+	union {
+		struct {
+  		Scalar value[3];  
+		};
+		struct {
+  		Scalar x;
+  		Scalar y;
+  		Scalar z;
+		};
+		struct {
+  		Scalar X;
+  		Scalar Y;
+  		Scalar Z;
+		};
+	};
+protected:
+  
+};
+
+
+
+
+
+//------------------------------------------------------------------------------
+// VECTOR inline FUNCTIONS
+//------------------------------------------------------------------------------
+
+
+
+/*************************************************************************
+  Constructor.
+  */
+template<class Scalar>
+inline Vector3Dim<Scalar>::Vector3Dim( void )
+{
+  value[0] = value[1] = value[2] = 0;
+}
+
+
+
+/*************************************************************************
+  Copy-Constructor.
+  */
+template<class Scalar>
+inline Vector3Dim<Scalar>::Vector3Dim( const Vector3Dim<Scalar> &v )
+{
+  value[0] = v.value[0];
+  value[1] = v.value[1];
+  value[2] = v.value[2];
+}
+template<class Scalar>
+inline Vector3Dim<Scalar>::Vector3Dim( const float *fvalue)
+{
+  value[0] = (Scalar)fvalue[0];
+  value[1] = (Scalar)fvalue[1];
+  value[2] = (Scalar)fvalue[2];
+}
+template<class Scalar>
+inline Vector3Dim<Scalar>::Vector3Dim( const double *fvalue)
+{
+  value[0] = (Scalar)fvalue[0];
+  value[1] = (Scalar)fvalue[1];
+  value[2] = (Scalar)fvalue[2];
+}
+
+
+
+/*************************************************************************
+  Constructor for a vector from a single Scalar. All components of
+  the vector get the same value.
+  \param s The value to set
+  \return The new vector
+  */
+template<class Scalar>
+inline Vector3Dim<Scalar>::Vector3Dim(Scalar s )
+{
+  value[0]= s;
+  value[1]= s;
+  value[2]= s;
+}
+
+
+/*************************************************************************
+  Constructor for a vector from three Scalars.
+  \param s1 The value for the first vector component
+  \param s2 The value for the second vector component
+  \param s3 The value for the third vector component
+  \return The new vector
+  */
+template<class Scalar>
+inline Vector3Dim<Scalar>::Vector3Dim(Scalar s1, Scalar s2, Scalar s3)
+{
+  value[0]= s1;
+  value[1]= s2;
+  value[2]= s3;
+}
+
+
+
+/*************************************************************************
+  Copy a Vector3Dim componentwise.
+  \param v vector with values to be copied
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator=( const Vector3Dim<Scalar> &v )
+{
+  value[0] = v.value[0];
+  value[1] = v.value[1];
+  value[2] = v.value[2];  
+  return *this;
+}
+
+
+/*************************************************************************
+  Copy a Scalar to each component.
+  \param s The value to copy
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator=(Scalar s)
+{
+  value[0] = s;
+  value[1] = s;
+  value[2] = s;  
+  return *this;
+}
+
+
+/*************************************************************************
+  Add another Vector3Dim componentwise.
+  \param v vector with values to be added
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator+=( const Vector3Dim<Scalar> &v )
+{
+  value[0] += v.value[0];
+  value[1] += v.value[1];
+  value[2] += v.value[2];  
+  return *this;
+}
+
+
+/*************************************************************************
+  Add a Scalar value to each component.
+  \param s Value to add
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator+=(Scalar s)
+{
+  value[0] += s;
+  value[1] += s;
+  value[2] += s;  
+  return *this;
+}
+
+
+/*************************************************************************
+  Subtract another vector componentwise.
+  \param v vector of values to subtract
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator-=( const Vector3Dim<Scalar> &v )
+{
+  value[0] -= v.value[0];
+  value[1] -= v.value[1];
+  value[2] -= v.value[2];  
+  return *this;
+}
+
+
+/*************************************************************************
+  Subtract a Scalar value from each component.
+  \param s Value to subtract
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator-=(Scalar s)
+{
+  value[0]-= s;
+  value[1]-= s;
+  value[2]-= s;  
+  return *this;
+}
+
+
+/*************************************************************************
+  Multiply with another vector componentwise.
+  \param v vector of values to multiply with
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator*=( const Vector3Dim<Scalar> &v )
+{
+  value[0] *= v.value[0];
+  value[1] *= v.value[1];
+  value[2] *= v.value[2];  
+  return *this;
+}
+
+
+/*************************************************************************
+  Multiply each component with a Scalar value.
+  \param s Value to multiply with
+  \return Reference to self
+  */
+template<class Scalar>
+inline const Vector3Dim<Scalar>&
+Vector3Dim<Scalar>::operator*=(Scalar s)
+{
+  value[0] *= s;
+  value[1] *= s;
+  value[2] *= s;  
+  return 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list