1 #ifndef BALLOON_H
2 #define BALLOON_H
3 
4 #include <common/interfaces.h>
5 #include <common/meshmodel.h>   // CMesh0
6 #include <volume.h>             // Volumetric representation for balloon
7 #include "vase_utils.h"         // myscale
8 #include "fieldinterpolator.h"  // Interpolator
9 #include <meshlab/glarea.h>     // Correcting meshlab bug (??)
10 
11 namespace vcg{
12 
13 class Balloon{
14 public:
15     /// Constructor: set default render mode
Balloon(CMeshO & _cloud)16     Balloon( CMeshO& _cloud ) : cloud( _cloud ){}
17 
18     enum RenderMode{
19          DEFAULT            = 0x00000000, // Show the cloud
20 
21          SHOW_CLOUD         = 0x00000001, // Show the cloud
22          SHOW_VOLUME        = 0x00000002, // Show the balloon
23          SHOW_SURF          = 0x00000004, // Show the isosurface
24          // SHOW_ACCEL         = 0x00000008, // Show the accelleration grid
25          SHOW_3DDDR         = 0x00000010, // 3D-DDR voxels
26          SHOW_SURF_TO_VOL   = 0x00000020,
27 
28          SURF_XCOLOR        = 0x00000100, // Show no color
29          SURF_VCOLOR        = 0x00000200, // Show vertex color
30          SURF_FCOLOR        = 0x00000400, // Show face color
31     };
32     Q_DECLARE_FLAGS(RenderModes, RenderMode)
33 
34     /// Interpolation parameter that guides view field interpolation.
35     /// Lower levels of omega might cause overshoothing problems
36     static const float OMEGA_VIEW_FIELD   = 1e8;
37 
38     /// Interpolation parameter which guides weight field
39     /// This can be much smoother
40     static const float OMEGA_WEIGHT_FIELD = 1e-1;
41 
42     /// Pointer to the underlying point cloud
43     CMeshO& cloud;
44 
45     /// Volumetric representation
46     MyVolume vol;
47 
48     /// Surface representation + handles to extra fields
49     CMeshO surf;
50 
51     /// Accellerator for ray-surface intersection
52     GridAccell gridAccell;
53 
54     /// Scalar field interpolator (one constraint per poking ray)
55     FieldInterpolator dinterp;
56 
57     /// Extra field to keep track of init/interpolated distance field
58     /// Refer to "User Defined Attributes" http://vcg.sourceforge.net/index.php/Tutorial
59     CMeshO::PerVertexAttributeHandle<float> surf_df;
60 
61     /// How close am I to the data? (1: close 0: far)
62     FieldInterpolator winterp;
63 
64     /// Extra field to keep track of how geometrically supported a piece of data is
65     CMeshO::PerVertexAttributeHandle<float> surf_wf;
66 
67     /// Defines the rendering style of the ballon
68     RenderModes rm;
69 
70     /// Keeps track of the number of evolution iterations done
71     int numiterscompleted;
72 
73     /// Have these quantities been updated?
74     bool isCurvatureUpdated;
75     bool isDistanceFieldUpdated;
76     bool isWeightFieldUpdated;
77     bool isDistanceFieldInit;
78 
79     /// Creates a new volume of given size and padding
80     void init(int gridsize, int gridpad);
81 
82     /// initializes a distance field according to view-point directions. Constraints are created
83     /// on both sides of the isosurface to cope with noise but especially to guarantee convergence
84     /// of the surface. If we go through a sample, a negative force field will be generated that will
85     /// push the isosurface back close to the sample.bool initializeField();
86     bool init_fields();
87 
88     /// Interpolates the fields defined in "init_fields"
89     bool interp_fields();
90 
91     /// Creates a curvature field defiened on vertices and stored in Kh
92     /// This will be used to create a mean-curvature flow type of evolutoin
93     bool compute_curvature();
94 
95     /// Based on the distance + curvature fields, evolves the surface in an implicit way.
96     /// ASSUMPTION: a correspondence has already been executed once!
97     /// TODO: more documentation
98     bool evolve();
99 
100     //--- Render & debug visualization
101     void render(GLArea* gla);
102 #ifdef DEBUG
103     void KhToVertexColor();
104     void dfieldToVertexColor();
105     void wfieldToVertexColor();
106     void selectedFacesQualityToColor();
107 #endif
108 
109 private:
110     /// Renders sample view directions on the cloud
111     void render_cloud();
112 
113     /// Renders the balloon isosurface with particular RenderMode
114     void render_isosurface(GLArea* gla);
115 
116     /// Renders volume boxes and correspondences to surface
117     void render_surf_to_vol();
118     void render_surf_to_acc();
119 };
120 
121 
122 
123 } //::vcg
124 
125 #endif // BALLOON_H
126