Elbeem: fix memory leak and add guarded allocator directives
[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 #ifdef WITH_CXX_GUARDEDALLOC
38 #  include "MEM_guardedalloc.h"
39 #endif
40
41 // weight and triangle index
42 class mvmIndexWeight {
43         public:
44
45                 mvmIndexWeight() : weight(0.0) {}
46
47                 mvmIndexWeight(int const& i, mvmFloat const& w) :
48                         weight(w), index(i) {}
49
50                 // for sorting
51                 bool operator> (mvmIndexWeight const& w) const { return this->weight > w.weight; } 
52                 bool operator< (mvmIndexWeight const& w) const { return this->weight < w.weight; }
53
54                 mvmFloat weight;
55                 int index;
56
57 private:
58 #ifdef WITH_CXX_GUARDEDALLOC
59         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:mvmIndexWeight")
60 #endif
61 };
62
63 // transfer point with weights
64 class mvmTransferPoint {
65         public:
66                 //! position of transfer point
67                 ntlVec3Gfx lastpos;
68                 //! triangle weights
69                 std::vector<mvmIndexWeight> weights;
70
71 private:
72 #ifdef WITH_CXX_GUARDEDALLOC
73         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:mvmTransferPoint")
74 #endif
75 };
76
77
78 //! compute mvmcs
79 class MeanValueMeshCoords {
80
81         public:
82
83     MeanValueMeshCoords() {}
84     ~MeanValueMeshCoords() {
85         clear();
86     }
87
88     void clear();
89
90     void calculateMVMCs(std::vector<ntlVec3Gfx> &reference_vertices, 
91                                 std::vector<ntlTriangle> &tris, std::vector<ntlVec3Gfx> &points, gfxReal numweights);
92     
93     void transfer(std::vector<ntlVec3Gfx> &vertices, std::vector<ntlVec3Gfx>& displacements);
94
95         protected:
96
97     void computeWeights(std::vector<ntlVec3Gfx> &reference_vertices, 
98                                 std::vector<ntlTriangle> &tris, mvmTransferPoint& tds, gfxReal numweights);
99
100     std::vector<mvmTransferPoint> mVertices;
101     int mNumVerts;
102
103 private:
104 #ifdef WITH_CXX_GUARDEDALLOC
105         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:MeanValueMeshCoords")
106 #endif
107 };
108
109 #endif
110