cb51e91d4671dc27decf4c16552477d29de58a28
[blender.git] / intern / elbeem / intern / mvmcoords.h
1 /** \file elbeem/intern/mvmcoords.h
2  *  \ingroup elbeem
3  */
4 /******************************************************************************
5  *
6 // El'Beem - the visual lattice boltzmann freesurface simulator
7 // All code distributed as part of El'Beem is covered by the version 2 of the 
8 // GNU General Public License. See the file COPYING for details.  
9 //
10 // Copyright 2008 Nils Thuerey , Richard Keiser, Mark Pauly, Ulrich Ruede
11 //
12  *
13  * Mean Value Mesh Coords class
14  *
15  *****************************************************************************/
16
17 #ifndef MVMCOORDS_H
18 #define MVMCOORDS_H
19
20 #include "utilities.h"
21 #include "ntl_ray.h"
22 #include <vector>
23 #define mvmFloat double
24
25 #ifdef WIN32
26 #ifndef FREE_WINDOWS
27 #include "float.h"
28 #define isnan(n) _isnan(n)
29 #define finite _finite
30 #endif
31 #endif
32
33 #ifdef sun
34 #include "ieeefp.h"
35 #endif
36
37 // weight and triangle index
38 class mvmIndexWeight {
39         public:
40
41                 mvmIndexWeight() : weight(0.0) {}
42
43                 mvmIndexWeight(int const& i, mvmFloat const& w) :
44                         weight(w), index(i) {}
45
46                 // for sorting
47                 bool operator> (mvmIndexWeight const& w) const { return this->weight > w.weight; } 
48                 bool operator< (mvmIndexWeight const& w) const { return this->weight < w.weight; }
49
50                 mvmFloat weight;
51                 int index;
52 };
53
54 // transfer point with weights
55 class mvmTransferPoint {
56         public:
57                 //! position of transfer point
58                 ntlVec3Gfx lastpos;
59                 //! triangle weights
60                 std::vector<mvmIndexWeight> weights;
61 };
62
63
64 //! compute mvmcs
65 class MeanValueMeshCoords {
66
67         public:
68
69     MeanValueMeshCoords() {}
70     ~MeanValueMeshCoords() {
71         clear();
72     }
73
74     void clear();
75
76     void calculateMVMCs(std::vector<ntlVec3Gfx> &reference_vertices, 
77                                 std::vector<ntlTriangle> &tris, std::vector<ntlVec3Gfx> &points, gfxReal numweights);
78     
79     void transfer(std::vector<ntlVec3Gfx> &vertices, std::vector<ntlVec3Gfx>& displacements);
80
81         protected:
82
83     void computeWeights(std::vector<ntlVec3Gfx> &reference_vertices, 
84                                 std::vector<ntlTriangle> &tris, mvmTransferPoint& tds, gfxReal numweights);
85
86     std::vector<mvmTransferPoint> mVertices;
87     int mNumVerts;
88
89 };
90
91 #endif
92