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