TAPs 0.7.7.3
TAPsModelDeformableGLSL_Visualization_RTGenMesh.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsModelDeformableGLSL_Visualization_RTGenMesh.cpp
00003 ******************************************************************************/
00008 /******************************************************************************
00009 SUKITTI PUNAK   (05/28/2007)
00010 UPDATE          (09/29/2007)
00011 ******************************************************************************/
00012 #include "TAPsModelDeformableGLSL_Visualization_RTGenMesh.hpp"
00013 // Using Inclusion Model (i.e. definitions are included in declarations)
00014 //                       (this name.cpp is included in name.hpp)
00015 // Each friend is defined directly inside its declaration.
00016 
00017 // EXPERIMENT 2
00018 
00019 BEGIN_NAMESPACE_TAPs__OpenGL
00020 //=============================================================================
00021 // START: STATIC MEMBER(S) AND FUNCTION(S)
00022 //===============================================================
00023 template <typename T> unsigned short
00024 ModelDeformableGLSL_Visualization_RTGenMesh<T>::g_iNumOfCreatedVisualDefModel = 0;
00025 //---------------------------------------------------------------
00026 // Marching Cube Tables (EdgeTable & TriTable)
00027 //---------------------------------------------------------------
00028 // Adapted from "Polygonising a scalar field" by Paul Bourke (1994)
00029 // http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/
00030 //---------------------------------------------------------------
00031 //-----------------------------------------------------------------------------
00032 // Vertex & Edge Index
00033 //          3------2------2
00034 //         /|            /|
00035 //       11 |          10 |
00036 //       /  3          /  1
00037 //      7------6------6   |
00038 //      |   |         |   |
00039 //      |   0------0--|---1
00040 //      7  /          5  /
00041 //      | 8           | 9 
00042 //      |/            |/
00043 //      4------4------5
00044 //---------------------------------
00045 // Edge Table [256] & Triangle Table [256][16]
00053 // V = V1 + (isovalue - s1) (V2 - V1) / (s2 - s1)
00054 //-----------------------------------------------------------------------------
00055 template <typename T> unsigned short
00056 ModelDeformableGLSL_Visualization_RTGenMesh<T>::EdgeTable[256] = {
00057     // 0-127
00058     0x0  , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
00059     0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
00060     0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
00061     0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
00062     0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c,
00063     0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
00064     0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac,
00065     0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
00066     0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c,
00067     0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
00068     0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc,
00069     0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
00070     0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c,
00071     0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
00072     0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc ,
00073     0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
00074 
00075     // 128-255
00076     0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
00077     0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
00078     0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
00079     0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
00080     0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
00081     0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
00082     0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
00083     0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460,
00084     0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
00085     0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0,
00086     0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
00087     0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230,
00088     0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
00089     0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190,
00090     0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
00091     0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0
00092 };
00093 //-------------------------------------------------------------------
00094 template <typename T> char
00095 ModelDeformableGLSL_Visualization_RTGenMesh<T>::TriTable[256][16] = {
00096     // 0-9
00097     {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00098     {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00099     {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00100     {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00101     {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00102     {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00103     {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00104     {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1},
00105     {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00106     {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00107     // 10-19
00108     {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00109     {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1},
00110     {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00111     {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1},
00112     {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1},
00113     {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00114     {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00115     {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00116     {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00117     {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1},
00118     // 20-29
00119     {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00120     {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1},
00121     {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
00122     {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1},
00123     {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00124     {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1},
00125     {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
00126     {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1},
00127     {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1},
00128     {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1},
00129     // 30-39
00130     {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1},
00131     {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1},
00132     {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00133     {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00134     {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00135     {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1},
00136     {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00137     {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
00138     {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1},
00139     {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1},
00140     // 40-49
00141     {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00142     {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
00143     {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
00144     {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1},
00145     {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1},
00146     {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1},
00147     {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1},
00148     {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1},
00149     {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00150     {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1},
00151     // 50-59
00152     {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1},
00153     {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00154     {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1},
00155     {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1},
00156     {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1},
00157     {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
00158     {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1},
00159     {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1},
00160     {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1},
00161     {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1},
00162     // 60-69
00163     {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1},
00164     {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1},
00165     {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1},
00166     {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00167     {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00168     {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00169     {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00170     {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
00171     {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00172     {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1},
00173     // 70-79
00174     {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1},
00175     {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1},
00176     {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00177     {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
00178     {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
00179     {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1},
00180     {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1},
00181     {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1},
00182     {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1},
00183     {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1},
00184     // 80-89
00185     {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00186     {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1},
00187     {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
00188     {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1},
00189     {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1},
00190     {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1},
00191     {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1},
00192     {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1},
00193     {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
00194     {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1},
00195     // 90-99
00196     {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1},
00197     {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1},
00198     {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1},
00199     {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1},
00200     {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1},
00201     {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1},
00202     {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00203     {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1},
00204     {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1},
00205     {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1},
00206     // 100-109
00207     {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1},
00208     {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1},
00209     {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00210     {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1},
00211     {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1},
00212     {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1},
00213     {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1},
00214     {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1},
00215     {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1},
00216     {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1},
00217     // 110-119
00218     {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1},
00219     {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00220     {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1},
00221     {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1},
00222     {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1},
00223     {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1},
00224     {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1},
00225     {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1},
00226     {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1},
00227     {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00228     // 120-129
00229     {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1},
00230     {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1},
00231     {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1},
00232     {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1},
00233     {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1},
00234     {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00235     {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1},
00236     {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00237     {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00238     {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00239     // 130-139
00240     {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00241     {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
00242     {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00243     {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
00244     {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
00245     {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1},
00246     {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00247     {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1},
00248     {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1},
00249     {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1},
00250     // 140-149
00251     {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1},
00252     {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1},
00253     {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1},
00254     {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1},
00255     {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00256     {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1},
00257     {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1},
00258     {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1},
00259     {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1},
00260     {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1},
00261     // 150-159
00262     {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1},
00263     {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1},
00264     {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1},
00265     {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00266     {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1},
00267     {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
00268     {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1},
00269     {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1},
00270     {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1},
00271     {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00272     // 160-169
00273     {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00274     {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
00275     {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
00276     {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1},
00277     {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
00278     {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1},
00279     {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1},
00280     {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1},
00281     {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
00282     {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1},
00283     // 170-179
00284     {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1},
00285     {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1},
00286     {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1},
00287     {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1},
00288     {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1},
00289     {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1},
00290     {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1},
00291     {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1},
00292     {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1},
00293     {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1},
00294     // 180-189
00295     {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1},
00296     {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1},
00297     {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1},
00298     {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1},
00299     {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1},
00300     {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1},
00301     {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1},
00302     {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00303     {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1},
00304     {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1},
00305     // 190-199
00306     {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00307     {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00308     {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00309     {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1},
00310     {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
00311     {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1},
00312     {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1},
00313     {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1},
00314     {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1},
00315     {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1},
00316     // 200-209
00317     {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1},
00318     {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1},
00319     {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1},
00320     {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1},
00321     {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00322     {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1},
00323     {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
00324     {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00325     {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1},
00326     {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1},
00327     // 210-219
00328     {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1},
00329     {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1},
00330     {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1},
00331     {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1},
00332     {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1},
00333     {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00334     {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1},
00335     {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1},
00336     {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1},
00337     {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1},
00338     // 220-229
00339     {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
00340     {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00341     {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1},
00342     {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00343     {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1},
00344     {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1},
00345     {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1},
00346     {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1},
00347     {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1},
00348     {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1},
00349     // 230-239
00350     {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1},
00351     {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1},
00352     {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1},
00353     {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1},
00354     {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1},
00355     {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00356     {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1},
00357     {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1},
00358     {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00359     {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00360     // 240-249
00361     {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00362     {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1},
00363     {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1},
00364     {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00365     {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1},
00366     {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1},
00367     {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00368     {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00369     {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1},
00370     {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00371     // 250-255
00372     {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1},
00373     {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00374     {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00375     {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00376     {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00377     {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
00378 };
00379 //-------------------------------------------------------------------
00380 template <typename T> GLuint
00381 ModelDeformableGLSL_Visualization_RTGenMesh<T>::EdgeTableTexture = 0;
00382 template <typename T> GLuint
00383 ModelDeformableGLSL_Visualization_RTGenMesh<T>::TriTableTexture = 0;
00384 //template <typename T> GLuint
00385 //ModelDeformableGLSL_Visualization_RTGenMesh<T>::TriAndEdgeTableTexture = 0;
00386 //-------------------------------------------------------------------
00387 //template <typename T>
00388 //bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::SetupEdgeAndTriTablesOnGPUToo ()
00389 //{
00390 //  //-----------------------------------------------------
00391 //  /**
00392 //   * Setup Tri and Edge Tables together on one 2D Texture
00393 //   *
00394 //   * Triangle Table Texture
00395 //   *
00396 //   * The value from the edge table is mapped to the triangle table 
00397 //   * for generating triangles.  Each generated triangle has its vertices 
00398 //   * intersect an edge of the cube.
00399 //   *
00400 //   * Edge Table Texture
00401 //   *
00402 //   * An integer 2D texture of size 16x256 (width and height of GPU texture) 
00403 //   * for TriTable[256][16] -- height and width of CPU memory
00404 //   * This texture stores the 256 configurations of the marching cube.
00405 //   * Its 12-bit are set/unset by the eight cube vertices using a bitfield operation.
00406 //   */
00407 //  // An integer 2D texture of size 16x(256+16)
00408 //  glGenTextures( 1, &TriAndEdgeTableTexture );
00409 //  glEnable( GL_TEXTURE_2D );
00410 //  glBindTexture( GL_TEXTURE_2D, TriAndEdgeTableTexture );
00411 //  // Integer textures must use nearest filter
00412 //  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00413 //  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00414 //  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00415 //  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00416 //  {
00417 //      int idx = 0;
00418 //      GLint TriAndEdgeTableData[(256+16)*16];
00419 //      for ( int i = 0; i < 256; ++i ) {
00420 //          for ( int j = 0; j < 16; ++j ) {
00421 //              TriAndEdgeTableData[idx] = static_cast<GLint>( TriTable[i][j] );
00422 //              ++idx;
00423 //          }
00424 //      }
00425 //      for ( int i = 0; i < 256; ++i ) {
00426 //          TriAndEdgeTableData[idx] = static_cast<GLint>( EdgeTable[i] );
00427 //          ++idx;
00428 //      }
00429 //      glTexImage2D( 
00430 //          GL_TEXTURE_2D, 0, GL_ALPHA16I_EXT, 16, 256+16, 
00431 //          0, GL_ALPHA_INTEGER_EXT, GL_INT, &TriAndEdgeTableData );
00432 //  }
00433 //  //---------------------------------
00434 //  // DEBUG: CHECK THE CREATED TEXTURE
00435 //  //#ifdef TAPs_DEBUG_MODE
00436 //  {
00437 //      GLint data[(256+16)*16];
00438 //      glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00439 //      glBindTexture( GL_TEXTURE_2D, TriAndEdgeTableTexture );
00440 //      glGetTexImage( GL_TEXTURE_2D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, data );
00441 //      TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00442 //
00443 //      std::cout << "---------\n";
00444 //      std::cout << "EdgeTable\n";
00445 //      std::cout << "---------\n";
00446 //      for ( int i = 0; i < 256; ++i ) {
00447 //          std::cout /*<< std::setbase( 16 )*/ << "(" << EdgeTable[i] << ") ";
00448 //          std::cout /*<< std::setbase( 16 )*/ << data[256*16+i] << "\t";
00449 //          if ( (i+1) % 8 == 0 ) {
00450 //              std::cout << "\n";
00451 //          }
00452 //      }
00453 //      std::cout << "---------\n";
00454 //
00455 //      std::cout << "---------\n";
00456 //      std::cout << "TriTable\n";
00457 //      std::cout << "---------\n";
00458 //      int count = 0;
00459 //      for ( int i = 0; i < 256; ++i ) {
00460 //          for ( int j = 0; j < 16; ++j ) {
00461 //              std::cout << "(" << static_cast<GLint>( TriTable[i][j] ) << ") ";
00462 //              std::cout << data[i*16+j] << "\t";
00463 //              if ( ++count % 16 == 0 ) {
00464 //                  std::cout << "\n";
00465 //              }
00466 //          }
00467 //      }
00468 //      std::cout << "---------\n";
00469 //  }
00470 //  //#endif // #ifdef TAPs_DEBUG_MODE
00471 //  //---------------------------------
00472 //  //-----------------------------------------------------
00473 //  glDisable( GL_TEXTURE_2D );
00474 //  glBindTexture( GL_TEXTURE_2D, 0 );
00475 //  //-----------------------------------------------------
00476 //  return true;
00477 //}
00478 //-------------------------------------------------------------------
00479 template <typename T>
00480 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::SetupEdgeAndTriTablesOnGPU ()
00481 {
00482     // if already generated
00483     if ( EdgeTableTexture && TriTableTexture )  return true;
00484     //-----------------------------------------------------
00491     // An integer 2D texture of size 256x1
00492     glGenTextures( 1, &EdgeTableTexture );
00493     glEnable( GL_TEXTURE_2D );
00494     glBindTexture( GL_TEXTURE_2D, EdgeTableTexture );
00495     // Integer textures must use nearest filter
00496     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00497     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00498     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00499     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00500     {
00501         GLint EdgeTableData[256];
00502         for ( int i = 0; i < 256; ++i ) {
00503             EdgeTableData[i] = static_cast<GLint>( EdgeTable[i] );
00504         }
00505         glTexImage2D( 
00506             GL_TEXTURE_2D, 0, GL_ALPHA16I_EXT, 256, 1, 
00507             0, GL_ALPHA_INTEGER_EXT, GL_INT, &EdgeTableData );
00508     }
00509     //---------------------------------
00510     // DEBUG: CHECK THE CREATED TEXTURE
00511     #ifdef TAPs_DEBUG_MODE
00512     {
00513         GLint data[256];
00514         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00515         glBindTexture( GL_TEXTURE_2D, EdgeTableTexture );
00516         glGetTexImage( GL_TEXTURE_2D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, data );
00517 
00518         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00519         std::cout << "---------\n";
00520         std::cout << "EdgeTable\n";
00521         std::cout << "---------\n";
00522         for ( int i = 0; i < 256; ++i ) {
00523             std::cout /*<< std::setbase( 16 )*/ << "(" << EdgeTable[i] << ") ";
00524             std::cout /*<< std::setbase( 16 )*/ << data[i] << "\t";
00525             if ( (i+1) % 8 == 0 ) {
00526                 std::cout << "\n";
00527             }
00528         }
00529         std::cout << "---------\n";
00530     }
00531     #endif // #ifdef TAPs_DEBUG_MODE
00532     //---------------------------------
00533     //-----------------------------------------------------
00541     // An integer 2D texture of size 16x256 (width and height of GPU texture) 
00542     // for TriTable[256][16] -- height and width of CPU memory
00543     glGenTextures( 1, &TriTableTexture );
00544     glEnable( GL_TEXTURE_2D );
00545     glBindTexture( GL_TEXTURE_2D, TriTableTexture );
00546     // Integer textures must use nearest filter
00547     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00548     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00549     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00550     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00551     {
00552         GLint TriTableData[256][16];
00553         for ( int i = 0; i < 256; ++i ) {
00554             for ( int j = 0; j < 16; ++j ) {
00555                 TriTableData[i][j] = static_cast<GLint>( TriTable[i][j] );
00556             }
00557         }
00558         glTexImage2D( 
00559             GL_TEXTURE_2D, 0, GL_ALPHA16I_EXT, 16, 256, 
00560             0, GL_ALPHA_INTEGER_EXT, GL_INT, &TriTableData );
00561     }
00562     //---------------------------------
00563     // DEBUG: CHECK THE CREATED TEXTURE
00564     #ifdef TAPs_DEBUG_MODE
00565     {
00566         GLint data[256][16];
00567         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00568         glBindTexture( GL_TEXTURE_2D, TriTableTexture );
00569         glGetTexImage( GL_TEXTURE_2D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, data );
00570 
00571         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00572         std::cout << "---------\n";
00573         std::cout << "TriTable\n";
00574         std::cout << "---------\n";
00575         int count = 0;
00576         for ( int i = 0; i < 256; ++i ) {
00577             for ( int j = 0; j < 16; ++j ) {
00578                 std::cout << "(" << static_cast<GLint>( TriTable[i][j] ) << ") ";
00579                 std::cout << data[i][j] << "\t";
00580                 if ( ++count % 16 == 0 ) {
00581                     std::cout << "\n";
00582                 }
00583             }
00584         }
00585         std::cout << "---------\n";
00586     }
00587     #endif // #ifdef TAPs_DEBUG_MODE
00588     //---------------------------------
00589     glDisable( GL_TEXTURE_2D );
00590     glBindTexture( GL_TEXTURE_2D, 0 );
00591     //-----------------------------------------------------
00592     return true;
00593 }
00594 
00595 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00596 //-------------------------------------------------------------------
00597 template <typename T>
00598 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
00599 SetupCubeTrackingTexture ( Vector3<int> const & vGridSize )
00600 {
00601     //-----------------------------------------------------
00608     // An integer 3D texture
00609     glGenTextures( 1, &CubeTrackingTexture );
00610     glEnable( GL_TEXTURE_3D );
00611     glBindTexture( GL_TEXTURE_3D, CubeTrackingTexture );
00612     // Integer textures must use nearest filter
00613     glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00614     glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00615     glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00616     glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00617     glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP );
00618     //---------------------------------
00619     Vector3<int> vCubes( vGridSize[0]-1, vGridSize[1]-1, vGridSize[2]-1 );
00620     int iTotalCubes = vCubes[0] * vCubes[1] * vCubes[2];
00621 
00622     // Use GLubyte for GL_ALPHA8UI_EXT gives incorrect result.
00623     // It has to be GLuint applied for either GL_ALPHA8UI_EXT or GL_ALPHA16UI_EXT.
00624     // Also the format has to be GL_ALPHA_INTEGER_EXT.
00625     // But the type has to be GL_UNSIGNED_INT.
00626 
00627     // NOT WORKING!
00628     //GLubyte * pCubeValData = new GLubyte[ iTotalCubes ];
00629 
00630     //GLuint * pCubeValData = new GLuint[ iTotalCubes ];
00631     GLint * pCubeValData = new GLint[ iTotalCubes ];
00632     //GLubyte * pCubeValData = new GLubyte[ iTotalCubes ];
00633     {
00634         int i = 0;
00635         for ( int z = 0; z < vCubes[2]; ++z ) {
00636             for ( int y = 0; y < vCubes[1]; ++y ) {
00637                 for ( int x = 0; x < vCubes[0]; ++x ) {
00638                     pCubeValData[i] = i % 256;
00639                     //if ( x >= vCubes[0]/2 && y >= vCubes[1]/2 && z >= vCubes[1]/2 ) {
00640                     //  pCubeValData[i] = 55;
00641                     //}
00642                     //else {
00643                     //  pCubeValData[i] = 0;
00644                     //}
00645                     ++i;
00646                 }
00647             }
00648         }
00649 
00650         //glTexImage3D( 
00651         //  GL_TEXTURE_3D, 0, GL_ALPHA8UI_EXT,      // This makes its  8-bit unsigned integer
00652         //  //GL_TEXTURE_3D, 0, GL_ALPHA16UI_EXT,   // This makes its 16-bit unsigned integer
00653         //  vCubes[0], vCubes[1], vCubes[2], 
00654         //  //0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_BYTE, pCubeValData );
00655         //  0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT, pCubeValData );
00656         // CURRENTLY
00657         // GL_ALPHA8UI_EXT is not working correctly.
00658         // Due to bugs with unsigned int in geometry shader compiler/driver.
00659         // So GL_ALPHA16I_EXT is used instead!
00660         //glTexImage3D( 
00661         //  GL_TEXTURE_3D, 0, GL_ALPHA16I_EXT,  // This makes its 16-bit integer
00662         //  vCubes[0], vCubes[1], vCubes[2], 
00663         //  0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
00664         // CURRENTLY
00665         // The GLSL's texture3D( isampler3D sampler, vec3 coords ) 
00666         // doesn't return the correct value for integer
00667         // The GLSL's texture3D( usampler3D sampler, vec3 coords ) 
00668         // doesn't return the correct value for unsinged integer
00669         // So GL_ALPHA8 is used instead!
00670         //glTexImage3D( 
00671         //  GL_TEXTURE_3D, 0, GL_ALPHA8,        // This makes its 8-bit unsigned byte
00672         //  vCubes[0], vCubes[1], vCubes[2], 
00673         //  0, GL_ALPHA, GL_UNSIGNED_BYTE, pCubeValData );
00674         // CURRENTLY
00675         // GL_ALPHA8 DOESN'T WORK EITHER SO BACK TO GL_ALPHA16UI_EXT
00676         glTexImage3D( 
00677             GL_TEXTURE_3D, 0, GL_ALPHA16I_EXT,  // This makes its 16-bit integer
00678             vCubes[0], vCubes[1], vCubes[2], 
00679             0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
00680     }
00681 
00682     /*
00683     //---------------------------------
00684     // DEBUG: CHECK THE CREATED TEXTURE
00685     {
00686         std::cout << "-----------------------------------\n";
00687         std::cout << "INIT DATA for Cube Tracking Texture\n";
00688         std::cout << "-----------------------------------\n";
00689         int i = 0;
00690         for ( int z = 0; z < vCubes[2]; ++z ) {
00691             for ( int y = 0; y < vCubes[1]; ++y ) {
00692                 for ( int x = 0; x < vCubes[0]; ++x ) {
00693                     std::cout << "  ";
00694                     if ( pCubeValData[i] < 100 )    std::cout << " ";
00695                     if ( pCubeValData[i] <  10 )    std::cout << " ";
00696                     std::cout << static_cast<int>( pCubeValData[i] );
00697                     ++i;
00698                 }
00699                 std::cout << "\n";
00700             }
00701             std::cout << "\n";
00702         }
00703         std::cout << "---------------------\n";
00704     }
00705     {
00706         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00707         glBindTexture( GL_TEXTURE_3D, CubeTrackingTexture );
00708 
00709         // NOT WORKING!
00710         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_BYTE, pCubeValData );
00711 
00712         // CURRENTLY, GL_ALPHA8UI_EXT is not working correctly.
00713         // Due to bugs with unsigned int in geometry shader compiler/driver.
00714         // So GL_ALPHA16I_EXT is used instead!
00715         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT, pCubeValData );
00716         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
00717         // CURRENTLY
00718         // The GLSL's texture3D( isampler3D sampler, vec3 coords ) 
00719         // doesn't return the correct value for integer
00720         // The GLSL's texture3D( usampler3D sampler, vec3 coords ) 
00721         // doesn't return the correct value for unsinged integer
00722         // So GL_ALPHA8 is used instead!
00723         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
00724         // CURRENTLY
00725         // The GLSL's texture3D( isampler3D sampler, vec3 coords ) 
00726         // doesn't return the correct value for integer
00727         // The GLSL's texture3D( usampler3D sampler, vec3 coords ) 
00728         // doesn't return the correct value for unsinged integer
00729         // So GL_ALPHA8 is used instead!
00730         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pCubeValData );
00731         // CURRENTLY
00732         // GL_ALPHA8 DOESN'T WORK EITHER SO BACK TO GL_ALPHA16UI_EXT
00733         glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
00734 
00735 
00736 
00737         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00738         std::cout << "---------------------\n";
00739         std::cout << "Cube Tracking Texture\n";
00740         std::cout << "---------------------\n";
00741         int i = 0;
00742         for ( int z = 0; z < vCubes[2]; ++z ) {
00743             for ( int y = 0; y < vCubes[1]; ++y ) {
00744                 for ( int x = 0; x < vCubes[0]; ++x ) {
00745                     std::cout << "  ";
00746                     if ( pCubeValData[i] < 100 )    std::cout << " ";
00747                     if ( pCubeValData[i] <  10 )    std::cout << " ";
00748                     std::cout << static_cast<int>( pCubeValData[i] );
00749                     ++i;
00750                 }
00751                 std::cout << "\n";
00752             }
00753             std::cout << "\n";
00754         }
00755         std::cout << "-----------------------------------\n";
00756     }
00757     //*/
00758 
00759     //---------------------------------
00760     glDisable( GL_TEXTURE_3D );
00761     glBindTexture( GL_TEXTURE_3D, 0 );
00762     //-----------------------------------------------------
00763     delete [] pCubeValData;
00764     return true;
00765 }
00766 //-------------------------------------------------------------------
00767 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00768 
00769 //-----------------------------------------------------------------------------
00770 // END: STATIC MEMBER(S) AND FUNCTION(S)
00771 //=============================================================================
00772 //=============================================================================
00773 //-----------------------------------------------------------------------------
00774 // Nondefault Constructor
00775 template <typename T>
00776 ModelDeformableGLSL_Visualization_RTGenMesh<T>::
00777 ModelDeformableGLSL_Visualization_RTGenMesh ( 
00778     ModelDeformableGLSL<T> * simDomain
00779 )
00780 {
00781     m_SimDomain = simDomain;
00782     //---------------------------------------------------------------
00783     // Since Microsoft gl.h is version 1.1,
00784     // So this fn calls glewInit() for latest OpenGL version 
00785     // and initialize GLSL.
00786     GFnInitGLSL();
00787 
00788     ++g_iNumOfCreatedVisualDefModel;
00789 
00790     Default();
00791     //---------------------------------------------------------------
00792 #ifdef  TAPs_DEBUG_MODE
00793     std::cout << "ModelDeformableGLSL_Visualization_RTGenMesh<" 
00794                 << typeid(T).name() << "> Constructor\n";
00795 #endif//TAPs_DEBUG_MODE
00796 }
00797 //-----------------------------------------------------------------------------
00798 // Destructor
00799 template <typename T>
00800 ModelDeformableGLSL_Visualization_RTGenMesh<T>::
00801 ~ModelDeformableGLSL_Visualization_RTGenMesh ()
00802 {
00803     Clear();
00804     //---------------------------------------------------------------
00805     // Static Data
00806     --g_iNumOfCreatedVisualDefModel;
00807     if ( g_iNumOfCreatedVisualDefModel == 0 ) {
00808         if ( EdgeTableTexture > 0 ) {
00809             glDeleteTextures( 1, &EdgeTableTexture );
00810             EdgeTableTexture = 0;
00811         }
00812         if ( TriTableTexture > 0 ) {
00813             glDeleteTextures( 1, &TriTableTexture );
00814             TriTableTexture = 0;
00815         }
00816         //if ( TriAndEdgeTableTexture > 0 ) {
00817         //  glDeleteTextures( 1, &TriAndEdgeTableTexture );
00818         //  TriAndEdgeTableTexture = 0;
00819         //}
00820     }
00821     //---------------------------------------------------------------
00822 #ifdef  TAPs_DEBUG_MODE
00823     std::cout << "ModelDeformableGLSL_Visualization_RTGenMesh<" 
00824                 << typeid(T).name() << "> Destructor\n";
00825 #endif//TAPs_DEBUG_MODE
00826 }
00827 //-----------------------------------------------------------------------------
00828 // Default
00829 template <typename T>
00830 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::Default ()
00831 {
00832 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00833     //-------------------------------------------
00834     // For Rendering
00835     m_uiTotalCubes = 0;
00836     m_vboVerticesAsTexCoords = 0;
00837 
00838     //-------------------------------------------
00839     // For Cube Tracking
00840     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00841     m_vboTexCoordForCubeTracking = 0;
00842     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00843 
00844 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00845 
00846     //-------------------------------------------
00847     // For GLSL shaders
00848 
00849     // Selectable Gradient Computations
00850     //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
00851     m_bComputeGradientFaces     = true;
00852     m_bComputeGradientVertices  = true;
00853     m_bComputeGradientEdges     = true;
00854     //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
00855 
00856     // Interpolation Parameters
00857     m_glslProgramObjectWithGlobalIntpValue  = NULL;
00858     m_glslProgramObjectWithTextureIntpValue = NULL;
00859 
00860     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
00861     m_glslProgramObjectForShaderSurfaceFromSW = NULL;
00862     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
00863 
00864     // Cube Tracking
00865     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00866     m_glslFBO_CubeTracking = 0;
00867     m_glslProgramObjectUpdateCubeTracking = NULL;
00868     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00869 
00870     //-------------------------------------------
00871     // For Textures
00872     m_3DTexture = 0;
00873     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00874     CubeTrackingTexture = 0;
00875     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00876     //-------------------------------------------
00877     // Adjustable Parameters
00878     m_bUseGlobalInterpolationVal    =   false;
00879     m_tGlobalInterpolationVal       =   0.1;
00880     m_bDrawPNTriangle               =   false;
00881     m_PNTriangleSmoothness          =   4;
00882     //-------------------------------------------
00883 }
00884 //-----------------------------------------------------------------------------
00885 // Clear
00886 template <typename T>
00887 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::Clear ()
00888 {
00889 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00890     //---------------------------------------------------------------
00891     // Clear Vertex Buffer for Rendering
00892     if ( m_vboVerticesAsTexCoords > 0 ) {
00893         glDeleteBuffers( 1, &m_vboVerticesAsTexCoords );
00894     }
00895 
00896     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00897     //---------------------------------------------------------------
00898     // Clear Vertex Buffer for Cube Tracking
00899     if ( m_vboTexCoordForCubeTracking > 0 ) {
00900         glDeleteBuffers( 1, &m_vboTexCoordForCubeTracking );
00901     }
00902     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00903 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00904     //---------------------------------------------------------------
00905     // Clear GLSL Shaders
00906     if ( m_glslProgramObjectWithGlobalIntpValue ) {
00907         m_glslShaderManager.Delete( m_glslProgramObjectWithGlobalIntpValue );
00908     }
00909     if ( m_glslProgramObjectWithTextureIntpValue ) {
00910         m_glslShaderManager.Delete( m_glslProgramObjectWithTextureIntpValue );
00911     }
00912 
00913     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
00914     if ( m_glslProgramObjectForShaderSurfaceFromSW ) {
00915         m_glslShaderManager.Delete( m_glslProgramObjectForShaderSurfaceFromSW );
00916     }
00917     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
00918 
00919     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00920     // Delete Frame Buffer Object(s)
00921     if ( m_glslFBO_CubeTracking > 0 ) {
00922         glDeleteFramebuffersEXT( 1, &m_glslFBO_CubeTracking );
00923     }
00924     if ( m_glslProgramObjectUpdateCubeTracking ) {
00925         m_glslShaderManager.Delete( m_glslProgramObjectUpdateCubeTracking );
00926     }
00927     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00928     //---------------------------------------------------------------
00929     // Clear Textures
00930     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00931     if ( CubeTrackingTexture > 0 ) {
00932         glDeleteTextures( 1, &CubeTrackingTexture );
00933     }
00934     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00935     //---------------------------------------------------------------
00936     Default();
00937 }
00938 //-----------------------------------------------------------------------------
00939 //=============================================================================
00940 
00941 
00942 //=============================================================================
00943 // SetupVisualization
00944 //-----------------------------------------------------------------------------
00945 template <typename T>
00946 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
00947 SetupVisualization ( 
00948     int resolutionX, int resolutionY, int resolutionZ, 
00949     enum GridGenerator<T>::VertexFlag *** pFlagDataForXYZVoxels 
00950 )
00951 {
00952     //---------------------------------------------------------------
00953     // Setup (static) Edge and Triangle Tables
00954     if ( !SetupEdgeAndTriTablesOnGPU() ) {
00955         std::cout << "SetupEdgeAndTriTablesOnGPU returns false!\n";
00956         return false;
00957     }
00958     //---------------------------------------------------------------
00959 
00960     //---------------------------------------------------------------
00961     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00962     if ( !GenerateTheVBOForTextureCoordinates( 
00963             Vector3<int>( resolutionX, resolutionY, resolutionZ ) ) 
00964     ) {
00965         std::cout << "GenerateTheVBOForTextureCoordinates(...) returns false!\n";
00966         return false;
00967     }
00968     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00969     //---------------------------------------------------------------
00970 
00971     //---------------------------------------------------------------
00972     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00973     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00974     if ( !GenerateTheVBOForTexCoordForCubeTracking( 
00975             Vector3<int>( resolutionX, resolutionY, resolutionZ ) ) 
00976     ) {
00977         std::cout << "GenerateTheVBOForTexCoordForCubeTracking(...) returns false!\n";
00978         return false;
00979     }
00980     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00981     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
00982     //---------------------------------------------------------------
00983 
00984     //---------------------------------------------------------------
00985     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
00986     if ( !SetupShadersForDrawing() ) {
00987         std::cout << "SetupShadersForDrawing() returns false!\n";
00988         return false;
00989     }
00990     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
00991     //---------------------------------------------------------------
00992 
00993     //---------------------------------------------------------------
00994     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
00995     //-----------------------
00996     if ( !GenerateBufferObjects() ) {
00997         std::cout << "GenerateBufferObjects() returns false!\n";
00998         return false;
00999     }
01000     //-----------------------
01001     if ( !SetupCubeTrackingTexture( 
01002             Vector3<int>( resolutionX, resolutionY, resolutionZ ) ) 
01003     ) {
01004         std::cout << "SetupCubeTrackingTexture(...) returns false!\n";
01005         return false;
01006     }
01007     //-----------------------
01008     if ( !SetupShadersForUpdateCubeTrackingTexture() ) {
01009         std::cout << "SetupShadersForUpdateCubeTrackingTexture() returns false!\n";
01010         return false;
01011     }
01012     //-----------------------
01013     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01014     //---------------------------------------------------------------
01015 
01016     return true;
01017 }
01018 //-----------------------------------------------------------------------------
01019 // END: SetupVisualization
01020 //=============================================================================
01021 
01022 
01023 //=============================================================================
01024 // Setup a 3D Texture for Visualization
01025 //-----------------------------------------------------------------------------
01026 /*
01027 template <typename T>
01028 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
01029 Setup3DTexture ( 
01030 //  int resolutionX, int resolutionY, int resolutionZ, 
01031 //  enum GridGenerator<T>::VertexFlag *** pFlagDataForXYZVoxels
01032 )
01033 {
01034     //---------------------------------------------------------------
01035     return true;
01036 }
01037 //*/
01038 //-----------------------------------------------------------------------------
01039 // END: Setup3DTexture
01040 //=============================================================================
01041 
01042 
01043 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
01044 //=============================================================================
01045 // Setup Shaders for Drawing by Marching Cubes Algorithm
01046 //-----------------------------------------------------------------------------
01047 template <typename T>
01048 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::SetupShadersForDrawing ()
01049 {
01050     //*
01051     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
01052     if ( !m_glslShaderManager.CreateGLSLProgramObject( m_glslProgramObjectForShaderSurfaceFromSW ) ) {
01053         std::cout << "Cannot Create Program Object: m_glslProgramObjectForShaderSurfaceFromSW" << std::endl;
01054         Clear();
01055         return false;
01056     }
01057     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectForShaderSurfaceFromSW, 
01058         "Resource/Shader/DefModelShaderForDrawBySW.vert", GL_VERTEX_SHADER ) ) {
01059         std::cout << "Cannot Load Shader: m_glslProgramObjectForShaderSurfaceFromSW --- Resource/Shader/DefModelShaderForDrawBySW.vert" << std::endl;
01060         Clear();
01061         return false;
01062     }
01063     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectForShaderSurfaceFromSW, 
01064         "Resource/Shader/DefModelShaderForDrawBySW.frag", GL_FRAGMENT_SHADER ) ) {
01065         std::cout << "Cannot Load Shader: m_glslProgramObjectForShaderSurfaceFromSW --- Resource/Shader/DefModelShaderForDrawBySW.frag" << std::endl;
01066         Clear();
01067         return false;
01068     }
01069     if ( !m_glslShaderManager.Link( m_glslProgramObjectForShaderSurfaceFromSW ) ) {
01070         Clear();
01071         return false;
01072     }
01073     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
01074     //*/
01075 
01076     //===============================================================
01077     // START: m_glslProgramObjectWithGlobalIntpValue
01078     //---------------------------------------------------------------
01079     if ( !m_glslShaderManager.CreateGLSLProgramObject( m_glslProgramObjectWithGlobalIntpValue ) ) {
01080         Clear();
01081         return false;
01082     }
01083     //---------------------------------------------------------------
01084     // Vertex Shader
01085     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectWithGlobalIntpValue, 
01086         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01087 
01088             // WITH 1X1X1 CUBE
01089             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01090                 // WITH CUBE TRACKING
01091                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01092                     // WITH GRADIENT TEXTURE
01093                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01094                         //"Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01095                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_RdCubeVerticesOnVertShader.vert", GL_VERTEX_SHADER ) ) {
01096                     #endif
01097                     // WITHOUT GRADIENT TEXTURE
01098                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01099                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01100                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01101                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01102                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01103                         #else
01104                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01105                         #endif
01106                     #endif
01107                 #endif
01108                 // WITHOUT CUBE TRACKING
01109                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES
01110                     // WITH GRADIENT TEXTURE
01111                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01112                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01113                     #endif
01114                     // WITHOUT GRADIENT TEXTURE
01115                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01116                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01117                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01118                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01119                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01120                         #else
01121                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01122                         #endif
01123                     #endif
01124                 #endif
01125             #endif
01126 
01127             // WITH 2X2X2 CUBE
01128             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01129                 "Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.vert", GL_VERTEX_SHADER ) ) {
01130             #endif
01131 
01132             // WITH 4X4X4 CUBE
01133             //#ifdef    TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_4X4X4_CUBES
01134             //  "Resource/Shader/DefModelDrawByGenMesh_4x4x4cubes.vert", GL_VERTEX_SHADER ) ) {
01135             //#endif
01136         #endif
01137         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01138             "Resource/Shader/DefModelDrawByGenMeshWithPNTri.vert", GL_VERTEX_SHADER ) ) {
01139         #endif
01140         Clear();
01141         return false;
01142     }
01143 
01144     //*
01146     // DEBUG
01147     {
01148         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01149             // WITH 1X1X1 CUBE
01150             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01151                 // WITH CUBE TRACKING
01152                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01153                     #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01154                     // WITH GRADIENT TEXTURE
01155                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01156                             //std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking_wGradTex.geom" << std::endl;
01157                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking_wGradTex_RdCubeVerticesOnVertShader.geom" << std::endl;
01158                     #endif
01159                     // WITHOUT GRADIENT TEXTURE
01160                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01161                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01162                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01163                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking_wSelectableGradients.geom" << std::endl;
01164                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01165                         #else
01166                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking.geom" << std::endl;
01167                         #endif
01168                     #endif
01169                     #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01170                 #endif
01171                 // WITHOUT CUBE TRACKING
01172                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES
01173                     // WITH GRADIENT TEXTURE
01174                     #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01175                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01176                         std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wGradTex.geom" << std::endl;
01177                     #endif
01178                     // WITHOUT GRADIENT TEXTURE
01179                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01180                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01181                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01182                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wSelectableGradients.geom" << std::endl;
01183                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01184                         #else
01185                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp.geom" << std::endl;
01186                         #endif
01187                     #endif
01188                     #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01189                 #endif
01190             #endif
01191             // WITH 2X2X2 CUBES
01192             #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01193             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01194                 std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.geom" << std::endl;
01195             #endif
01196             #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01197         #endif
01198         // WITH PN-TRIANGLES
01199         #ifdef TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01200         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01201             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMeshWithPNTri.geom" << std::endl;
01202         #endif
01203         #endif // TAPs_DEFMODEL_DEBUG_LOADING_SHADERS
01204     }
01206     //*/
01207 
01208     //---------------------------------------------------------------
01209     // Geometry Shader -- WITH GLOBAL INTERPOLATION VALUE
01210     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectWithGlobalIntpValue, 
01211         // WITHOUT PN-TRIANGLES
01212         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01213             // WITH 1X1X1 CUBE
01214             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01215                 // WITH CUBE TRACKING
01216                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01217                     // WITH GRADIENT TEXTURE
01218                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01219                         //"Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking_wGradTex.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01220                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking_wGradTex_RdCubeVerticesOnVertShader.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01221                     #endif
01222                     // WITHOUT GRADIENT TEXTURE
01223                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01224                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01225                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01226                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking_wSelectableGradients.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01227                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01228                         #else
01229                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wCubeTracking.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01230                         #endif
01231                     #endif
01232                 #endif
01233                 // WITHOUT CUBE TRACKING
01234                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES
01235                     // WITH GRADIENT TEXTURE
01236                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01237                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wGradTex.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01238                     #endif
01239                     // WITHOUT GRADIENT TEXTURE
01240                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01241                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01242                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01243                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp_wSelectableGradients.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01244                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01245                         #else
01246                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wGlobalIntp.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01247                         #endif
01248                     #endif
01249                 #endif
01250             #endif
01251             // WITH 2X2X2 CUBES
01252             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01253                 "Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01254             #endif
01255         #endif
01256         // WITH PN-TRIANGLES
01257         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01258             "Resource/Shader/DefModelDrawByGenMeshWithPNTri.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01259         #endif
01260         Clear();
01261         return false;
01262     }
01263     //---------------------------------------------------------------
01264     // Fragment Shader
01265     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectWithGlobalIntpValue, 
01266         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01267             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01268                 "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.frag", GL_FRAGMENT_SHADER ) ) {
01269             #endif
01270             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01271                 "Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.frag", GL_FRAGMENT_SHADER ) ) {
01272             #endif
01273         #endif
01274         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01275             "Resource/Shader/DefModelDrawByGenMeshWithPNTri.frag", GL_FRAGMENT_SHADER ) ) {
01276         #endif
01277         Clear();
01278         return false;
01279     }
01280     //---------------------------------------------------------------
01281     // Setup Geometry Shader for Marching Cube
01282     // Since Geometry Shader needs to specify input and output types 
01283     // and the number of maximum out/emitted vertices.
01284     {
01285         GLuint progObj = m_glslProgramObjectWithGlobalIntpValue->GetProgramObject();
01286         glProgramParameteriEXT( progObj, GL_GEOMETRY_INPUT_TYPE_EXT,    GL_POINTS );
01287         glProgramParameteriEXT( progObj, GL_GEOMETRY_OUTPUT_TYPE_EXT,   GL_TRIANGLE_STRIP );
01288         // (At most 5 triangles from Marching Cube) * (PNTriangle Smoothness)
01289         //                                       5  *  10 (smoothness of 4 = 10 vertices per triangle)
01290         // Setting the smoothness to five (# out vertices = 5*15 = 75) seems to be too much 
01291         //   for 320MB 8800 GTS to handle -- i.e. too slow.
01292         // In addition, the rendered surface contains several holes.
01293         // Also setting the # out vertices to 50 (or 55 or 60), 
01294         //   the GLSL shader doesn't render the correct surface.
01295         // It renders a surface with several holes.
01296         // Due to this weird logic error from geometry shader, the # out vertices is set to 64.
01297 
01298         // Check max number of vertices that the geometry shader can output
01299 
01300         #ifdef TAPs_DEBUG_MODE
01301         GLint maxOutNumVertices;
01302         glGetIntegerv( GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &maxOutNumVertices );
01303         std::cout << "The maximum number of output vertices that the graphics card's geometry shader can output is " << maxOutNumVertices << ".\n";
01304         // GeForce 8800 GTS's GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT is 1024.
01305         #endif // #ifdef TAPs_DEBUG_MODE
01306 
01307 
01308         // Without PNTriangles
01309         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01310             #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01311             glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 16*2 /*15*/ );
01312             #endif
01313             #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01314             glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 16*4 /*15x8*/ );
01315             //glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 256 /*15x8*/ );
01316             #endif
01317             //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_4X4X4_CUBES
01318             //glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 16 /*15x64*/ );
01319             //#endif
01320         #endif
01321 
01322         // With PNTriangles
01323         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01324         glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT,  64 /*(15/3)x10*/ );
01325         #endif
01326     }
01327     //---------------------------------------------------------------
01328     if ( !m_glslShaderManager.Link( m_glslProgramObjectWithGlobalIntpValue ) ) {
01329         Clear();
01330         return false;
01331     }
01332     //---------------------------------------------------------------
01333     // END: m_glslProgramObjectWithGlobalIntpValue
01334     //===============================================================
01335 
01336 
01337     //===============================================================
01338     // START: m_glslProgramObjectWithTextureIntpValue
01339     //---------------------------------------------------------------
01340     if ( !m_glslShaderManager.CreateGLSLProgramObject( m_glslProgramObjectWithTextureIntpValue ) ) {
01341         Clear();
01342         return false;
01343     }
01344     //---------------------------------------------------------------
01345     // Vertex Shader
01346     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectWithTextureIntpValue, 
01347         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01348             // WITH 1X1X1 CUBE
01349             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01350                 // WITH CUBE TRACKING
01351                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01352                     // WITH GRADIENT TEXTURE
01353                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01354                         //"Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01355                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_RdCubeVerticesOnVertShader.vert", GL_VERTEX_SHADER ) ) {
01356                     #endif
01357                     // WITHOUT GRADIENT TEXTURE
01358                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01359                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01360                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01361                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01362                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01363                         #else
01364                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01365                         #endif
01366                     #endif
01367                 #endif
01368                 // WITHOUT CUBE TRACKING
01369                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES
01370                     // WITH GRADIENT TEXTURE
01371                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01372                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01373                     #endif
01374                     // WITHOUT GRADIENT TEXTURE
01375                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01376                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01377                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01378                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01379                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01380                         #else
01381                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.vert", GL_VERTEX_SHADER ) ) {
01382                         #endif
01383                     #endif
01384                 #endif
01385             #endif
01386 
01387             // WITH 2X2X2 CUBE
01388             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01389                 "Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.vert", GL_VERTEX_SHADER ) ) {
01390             #endif
01391 
01392             // WITH 4X4X4 CUBE
01393             //#ifdef    TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_4X4X4_CUBES
01394             //  "Resource/Shader/DefModelDrawByGenMesh_4x4x4cubes.vert", GL_VERTEX_SHADER ) ) {
01395             //#endif
01396         #endif
01397         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01398             "Resource/Shader/DefModelDrawByGenMeshWithPNTri.vert", GL_VERTEX_SHADER ) ) {
01399         #endif
01400         Clear();
01401         return false;
01402     }
01403 
01404     //*
01406     // DEBUG
01407     {
01408         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01409             // WITH 1X1X1 CUBE
01410             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01411                 // WITH CUBE TRACKING
01412                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01413                     // WITH GRADIENT TEXTURE
01414                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01415                             //std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking_wGradTex.geom" << std::endl;
01416                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking_wGradTex_RdCubeVerticesOnVertShader.geom" << std::endl;
01417                     #endif
01418                     // WITHOUT GRADIENT TEXTURE
01419                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01420                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01421                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01422                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking_wSelectableGradients.geom" << std::endl;
01423                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01424                         #else
01425                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking.geom" << std::endl;
01426                         #endif
01427                     #endif
01428                 #endif
01429                 // WITHOUT CUBE TRACKING
01430                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES
01431                     // WITH GRADIENT TEXTURE
01432                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01433                         std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wGradTex.geom" << std::endl;
01434                     #endif
01435                     // WITHOUT GRADIENT TEXTURE
01436                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01437                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01438                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01439                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wSelectableGradients.geom" << std::endl;
01440                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01441                         #else
01442                             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp.geom" << std::endl;
01443                         #endif
01444                     #endif
01445                 #endif
01446             #endif
01447             // WITH 2X2X2 CUBES
01448             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01449                 std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.geom" << std::endl;
01450             #endif
01451         #endif
01452         // WITH PN-TRIANGLES
01453         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01454             std::cout << "LOAD: Resource/Shader/DefModelDrawByGenMeshWithPNTri.geom" << std::endl;
01455         #endif
01456     }
01458     //*/
01459 
01460     //---------------------------------------------------------------
01461     // Geometry Shader -- WITH INTERPOLATION VALUE TEXTURE
01462     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectWithTextureIntpValue, 
01463         // WITHOUT PN-TRIANGLES
01464         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01465             // 1X1X1 CUBE
01466             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01467                 // WITH CUBE TRACKING OPTION
01468                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01469                     // WITH GRADIENT TEXTURE
01470                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01471                         //"Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking_wGradTex.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01472                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking_wGradTex_RdCubeVerticesOnVertShader.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01473                     #endif
01474                     // WITHOUT GRADIENT TEXTURE
01475                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01476                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01477                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01478                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking_wSelectableGradients.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01479                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01480                         #else
01481                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wCubeTracking.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01482                         #endif
01483                     #endif
01484                 #endif
01485                 // WITHOUT CUBE TRACKING OPTION
01486                 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_TRACKING_CUBES
01487                     // WITH GRADIENT TEXTURE
01488                     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
01489                         "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wGradTex.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01490                     #endif
01491                     // WITHOUT GRADIENT TEXTURE
01492                     #ifdef TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE
01493                         // WITH SELECTABLE GRADIENT COMPUTATION OPTION
01494                         #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
01495                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp_wSelectableGradients.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01496                         // WITHOUT SELECTABLE GRADIENT COMPUTATION OPTION
01497                         #else
01498                             "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes_wTextureIntp.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01499                         #endif
01500                     #endif
01501                 #endif
01502             #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01503             // 2X2X2 CUBES
01504             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01505                 "Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01506             #endif
01507         #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01508         // WITH PN-TRIANGLES
01509         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01510             "Resource/Shader/DefModelDrawByGenMeshWithPNTri.geom", GL_GEOMETRY_SHADER_EXT ) ) {
01511         #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01512         Clear();
01513         return false;
01514     }
01515     //---------------------------------------------------------------
01516     // Fragment Shader
01517     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectWithTextureIntpValue, 
01518         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01519             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01520                 "Resource/Shader/DefModelDrawByGenMesh_1x1x1cubes.frag", GL_FRAGMENT_SHADER ) ) {
01521             #endif
01522             #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01523                 "Resource/Shader/DefModelDrawByGenMesh_2x2x2cubes.frag", GL_FRAGMENT_SHADER ) ) {
01524             #endif
01525             //#ifdef    TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_4X4X4_CUBES
01526             //  "Resource/Shader/DefModelDrawByGenMesh_4x4x4cubes.frag", GL_FRAGMENT_SHADER ) ) {
01527             //#endif
01528         #endif
01529         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01530             "Resource/Shader/DefModelDrawByGenMeshWithPNTri.frag", GL_FRAGMENT_SHADER ) ) {
01531         #endif
01532         Clear();
01533         return false;
01534     }
01535     //---------------------------------------------------------------
01536     // Setup Geometry Shader for Marching Cube
01537     // Since Geometry Shader needs to specify input and output types 
01538     // and the number of maximum out/emitted vertices.
01539     {
01540         GLuint progObj = m_glslProgramObjectWithTextureIntpValue->GetProgramObject();
01541         glProgramParameteriEXT( progObj, GL_GEOMETRY_INPUT_TYPE_EXT,    GL_POINTS );
01542         glProgramParameteriEXT( progObj, GL_GEOMETRY_OUTPUT_TYPE_EXT,   GL_TRIANGLE_STRIP );
01543         // (At most 5 triangles from Marching Cube) * (PNTriangle Smoothness)
01544         //                                       5  *  10 (smoothness of 4 = 10 vertices per triangle)
01545         // Setting the smoothness to five (# out vertices = 5*15 = 75) seems to be too much 
01546         //   for 320MB 8800 GTS to handle -- i.e. too slow.
01547         // In addition, the rendered surface contains several holes.
01548         // Also setting the # out vertices to 50 (or 55 or 60), 
01549         //   the GLSL shader doesn't render the correct surface.
01550         // It renders a surface with several holes.
01551         // Due to this weird logic error from geometry shader, the # out vertices is set to 64.
01552 
01553         // Check max number of vertices that the geometry shader can output
01554 
01555         #ifdef TAPs_DEBUG_MODE
01556         GLint maxOutNumVertices;
01557         glGetIntegerv( GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &maxOutNumVertices );
01558         std::cout << "The maximum number of output vertices that the graphics card's geometry shader can output is " << maxOutNumVertices << ".\n";
01559         // GeForce 8800 GTS's GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT is 1024.
01560         #endif // #ifdef TAPs_DEBUG_MODE
01561 
01562 
01563         // Without PNTriangles
01564         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITHOUT_PNTRI
01565             #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01566             glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 16 /*15*/ );
01567             #endif
01568             #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01569             glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 16*4 /*15x8*/ );
01570             //glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 256 /*15x8*/ );
01571             #endif
01572             //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_4X4X4_CUBES
01573             //glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT, 16 /*15x64*/ );
01574             //#endif
01575         #endif
01576 
01577         // With PNTriangles
01578         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
01579         glProgramParameteriEXT( progObj, GL_GEOMETRY_VERTICES_OUT_EXT,  64 /*(15/3)x10*/ );
01580         #endif
01581     }
01582     //---------------------------------------------------------------
01583     if ( !m_glslShaderManager.Link( m_glslProgramObjectWithTextureIntpValue ) ) {
01584         Clear();
01585         return false;
01586     }
01587     //---------------------------------------------------------------
01588     // END: m_glslProgramObjectWithTextureIntpValue
01589     //===============================================================
01590 
01591     return true;
01592 }
01593 //-----------------------------------------------------------------------------
01594 // END: SetupShadersForDrawing
01595 //=============================================================================
01596 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
01597 
01598 
01599 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01600 //=============================================================================
01601 // Setup Shaders for Update Cube Tracking Texture
01602 //-----------------------------------------------------------------------------
01603 template <typename T>
01604 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
01605 SetupShadersForUpdateCubeTrackingTexture ()
01606 {
01607     //---------------------------------------------------------------
01608     if ( !m_glslShaderManager.CreateGLSLProgramObject( m_glslProgramObjectUpdateCubeTracking ) ) {
01609         Clear();
01610         return false;
01611     }
01612     //---------------------------------------------------------------
01613     // Fragment Shader
01614     if ( !m_glslShaderManager.AttachShaderFromFile( m_glslProgramObjectUpdateCubeTracking, 
01615         #ifdef  TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01616             "Resource/Shader/DefModelDrawByGenMesh_UpdateCubeTracking_1x1x1cubes.frag", GL_FRAGMENT_SHADER ) ) {
01617         #endif
01618         Clear();
01619         return false;
01620     }
01621     //---------------------------------------------------------------
01622     if ( !m_glslShaderManager.Link( m_glslProgramObjectUpdateCubeTracking ) ) {
01623         Clear();
01624         return false;
01625     }
01626     //---------------------------------------------------------------
01627     return true;
01628 }
01629 //-----------------------------------------------------------------------------
01630 // END: SetupShadersForUpdateCubeTrackingTexture
01631 //=============================================================================
01632 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01633 
01634 
01635 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
01636 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01637 #ifdef TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO
01638 //=============================================================================
01639 // Vertex Buffer for Rendering
01640 //-----------------------------------------------------------------------------
01641 template <typename T>
01642 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
01643 GenerateTheVBOForTextureCoordinates ( Vector3<int> const & vGridSize )
01644 {
01645     std::cout << "TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO" << std::endl;
01646 
01647     assert( m_vboVerticesAsTexCoords == 0 );
01648     //-------------------------------------------
01649     // Reduce the grid size by one, 
01650     // since needed only the # of cubes for marching cube.
01651     //-------------------------------------------
01652     // Process 1x1x1 Cubes as a group
01653     Vector3<int> newGridSize( vGridSize[0]*2, vGridSize[1]*2, vGridSize[2]*2 );
01654     Vector3<int> v1x1x1NumBlocks( newGridSize[0]*2 - 1, newGridSize[1]*2 - 1, newGridSize[2]*2 - 1 );
01655     m_uiTotalCubes = v1x1x1NumBlocks[0] * v1x1x1NumBlocks[1] * v1x1x1NumBlocks[2];
01656     glGenBuffers( 1, &m_vboVerticesAsTexCoords );
01657     if ( m_vboVerticesAsTexCoords == 0 ) return false;
01658     //-----------------------------------------------------
01659     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
01660     glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat)*m_uiTotalCubes*3, NULL, GL_STATIC_DRAW );
01661     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
01662     float * vertices = static_cast<float *>( glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY ) );
01663     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
01664     //-----------------------------------------------------
01665     // Grid size is #ofBlocks + 1
01666     // Divided by vGridSize so that the texture coordinates is of 
01667     // the first vertex (#0) of the cube
01668     Vector3<float> texCoordStep( 
01669         1.0 / newGridSize[0], 1.0 / newGridSize[1], 1.0 / newGridSize[2] );
01670     Vector3<float> minTexCoord( 
01671         texCoordStep[0] / 2.0, texCoordStep[1] / 2.0, texCoordStep[2] / 2.0 );
01672     int idx = 0;
01673     float Z = minTexCoord[2];
01674 
01675     //*
01676     //-------------------------------------------
01677     for ( int z = 0; z < v1x1x1NumBlocks[2]; ++z ) {
01678         float Y = minTexCoord[1];
01679         for ( int y = 0; y < v1x1x1NumBlocks[1]; ++y ) {
01680             float X = minTexCoord[0];
01681             for ( int x = 0; x < v1x1x1NumBlocks[0]; ++x ) {
01682                 vertices[ idx++ ] = X;
01683                 vertices[ idx++ ] = Y;
01684                 vertices[ idx++ ] = Z;
01685                 //std::cout << "VBO for Rendering: " 
01686                 //  << X << ", " 
01687                 //  << Y << ", " 
01688                 //  << Z << "\n";
01689                 X += texCoordStep[0];
01690             }
01691             Y += texCoordStep[1];
01692         }
01693         Z += texCoordStep[2];
01694     }
01695     //-----------------------------------------------------
01696     //*/
01697 
01698     /*
01699     //-----------------------------------------------------
01700     // Swizzled Walk
01701     //
01702     //    +---+---+---+---+---+
01703     //    | 0 | 0 | 0 | 0 | 0 |
01704     //  --+---+---+---+---+---+
01705     //    | 1 | 2 | 1 | 2 | 0 |
01706     //    +---+---+---+---+---+
01707     //    | 0 | 3 | 0 | 3 | 0 |
01708     //  --+---+---+---+---+---+
01709     //    | 1 | 2 | 1 | 2 | 0 |
01710     //    +---+---+---+---+---+
01711     //    | 0 | 3 | 0 | 3 | 0 |
01712     //  --+---+---+---+---+---+
01713     //    |       |       |
01714     //
01715     for ( int z = 0; z < v1x1x1NumBlocks[2]; ++z ) {
01716         float Y = minTexCoord[1];
01717         for ( int y = 0; y < v1x1x1NumBlocks[1]; y+=2 ) {
01718             float X = minTexCoord[0];
01719             for ( int x = 0; x < v1x1x1NumBlocks[0]; x+=2 ) {
01720                 if ( x < v1x1x1NumBlocks[0]-1 && y < v1x1x1NumBlocks[1]-1 )
01721                 {
01722                     T X1 = X + texCoordStep[0];
01723                     T Y1 = Y + texCoordStep[1];
01724                     // 0
01725                     vertices[ idx++ ] = X;
01726                     vertices[ idx++ ] = Y;
01727                     vertices[ idx++ ] = Z;
01728                     // 1
01729                     vertices[ idx++ ] = X;
01730                     vertices[ idx++ ] = Y1;
01731                     vertices[ idx++ ] = Z;
01732                     // 2
01733                     vertices[ idx++ ] = X1;
01734                     vertices[ idx++ ] = Y1;
01735                     vertices[ idx++ ] = Z;
01736                     // 3
01737                     vertices[ idx++ ] = X1;
01738                     vertices[ idx++ ] = Y;
01739                     vertices[ idx++ ] = Z;
01740                 }
01741                 else {
01742                     vertices[ idx++ ] = X;
01743                     vertices[ idx++ ] = Y;
01744                     vertices[ idx++ ] = Z;
01745                 }
01746                 X += texCoordStep[0] + texCoordStep[0];
01747             }
01748             Y += texCoordStep[1] * texCoordStep[1];
01749         }
01750         Z += texCoordStep[2];
01751     }
01752     //-----------------------------------------------------
01753     //*/
01754 
01755     //-----------------------------------------------------
01756     glUnmapBuffer( GL_ARRAY_BUFFER );
01757     glBindBuffer( GL_ARRAY_BUFFER, 0 );
01758     //-----------------------------------------------------
01759     return true;
01760 }
01761 //-----------------------------------------------------------------------------
01762 // END: GenerateTheVBOForTextureCoordinates
01763 //=============================================================================
01764 
01765 #else // TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO is not defined
01766 
01767 //=============================================================================
01768 // Vertex Buffer for Rendering
01769 //-----------------------------------------------------------------------------
01770 template <typename T>
01771 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
01772 GenerateTheVBOForTextureCoordinates ( Vector3<int> const & vGridSize )
01773 {
01774     assert( m_vboVerticesAsTexCoords == 0 );
01775 
01776     const int iNumComps = 4;
01777     //-------------------------------------------
01778     // Reduce the grid size by one, 
01779     // since needed only the # of cubes for marching cube.
01780     //-------------------------------------------
01781     // Process 1x1x1 Cubes as a group
01782     Vector3<int> v1x1x1NumBlocks( 
01783         vGridSize[0]-1, 
01784         vGridSize[1]-1, 
01785         vGridSize[2]-1 
01786     );
01787     m_uiTotalCubes = v1x1x1NumBlocks[0] * v1x1x1NumBlocks[1] * v1x1x1NumBlocks[2];
01788     glGenBuffers( 1, &m_vboVerticesAsTexCoords );
01789     if ( m_vboVerticesAsTexCoords == 0 ) return false;
01790     //-----------------------------------------------------
01791     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
01792     glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat)*m_uiTotalCubes*iNumComps, NULL, GL_STATIC_DRAW );
01793     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
01794     float * vertices = static_cast<float *>( glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY ) );
01795     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
01796     //-----------------------------------------------------
01797     // Grid size is #ofBlocks + 1
01798     // Divided by vGridSize so that the texture coordinates is of 
01799     // the first vertex (#0) of the cube
01800     Vector3<float> texCoordStep( 
01801         1.0 / vGridSize[0], 1.0 / vGridSize[1], 1.0 / vGridSize[2] );
01802     Vector3<float> minTexCoord( 
01803         texCoordStep[0] / 2.0, texCoordStep[1] / 2.0, texCoordStep[2] / 2.0 );
01804     int idx = 0;
01805     float Z = minTexCoord[2];
01806 
01807     //*
01808     //-------------------------------------------
01809     for ( int z = 0; z < v1x1x1NumBlocks[2]; ++z ) {
01810         float Y = minTexCoord[1];
01811         for ( int y = 0; y < v1x1x1NumBlocks[1]; ++y ) {
01812             float X = minTexCoord[0];
01813             for ( int x = 0; x < v1x1x1NumBlocks[0]; ++x ) {
01814                 vertices[ idx++ ] = X;
01815                 vertices[ idx++ ] = Y;
01816                 vertices[ idx++ ] = Z;
01817                 if ( iNumComps == 4 ) {
01818                     if ( z > v1x1x1NumBlocks[2] / 2 ) {
01819                         vertices[ idx++ ] = 0.0;
01820                     }
01821                     else {
01822                         vertices[ idx++ ] = 1.0;
01823                     }
01824                 }
01825                 //std::cout << "VBO for Rendering: " 
01826                 //  << X << ", " 
01827                 //  << Y << ", " 
01828                 //  << Z << "\n";
01829                 X += texCoordStep[0];
01830             }
01831             Y += texCoordStep[1];
01832         }
01833         Z += texCoordStep[2];
01834     }
01835     //-----------------------------------------------------
01836     //*/
01837 
01838     /*
01839     //-----------------------------------------------------
01840     // Swizzled Walk
01841     //
01842     //    +---+---+---+---+---+
01843     //    | 0 | 0 | 0 | 0 | 0 |
01844     //  --+---+---+---+---+---+
01845     //    | 1 | 2 | 1 | 2 | 0 |
01846     //    +---+---+---+---+---+
01847     //    | 0 | 3 | 0 | 3 | 0 |
01848     //  --+---+---+---+---+---+
01849     //    | 1 | 2 | 1 | 2 | 0 |
01850     //    +---+---+---+---+---+
01851     //    | 0 | 3 | 0 | 3 | 0 |
01852     //  --+---+---+---+---+---+
01853     //    |       |       |
01854     //
01855     for ( int z = 0; z < v1x1x1NumBlocks[2]; ++z ) {
01856         float Y = minTexCoord[1];
01857         for ( int y = 0; y < v1x1x1NumBlocks[1]; y+=2 ) {
01858             float X = minTexCoord[0];
01859             for ( int x = 0; x < v1x1x1NumBlocks[0]; x+=2 ) {
01860                 if ( x < v1x1x1NumBlocks[0]-1 && y < v1x1x1NumBlocks[1]-1 )
01861                 {
01862                     T X1 = X + texCoordStep[0];
01863                     T Y1 = Y + texCoordStep[1];
01864                     // 0
01865                     vertices[ idx++ ] = X;
01866                     vertices[ idx++ ] = Y;
01867                     vertices[ idx++ ] = Z;
01868                     // 1
01869                     vertices[ idx++ ] = X;
01870                     vertices[ idx++ ] = Y1;
01871                     vertices[ idx++ ] = Z;
01872                     // 2
01873                     vertices[ idx++ ] = X1;
01874                     vertices[ idx++ ] = Y1;
01875                     vertices[ idx++ ] = Z;
01876                     // 3
01877                     vertices[ idx++ ] = X1;
01878                     vertices[ idx++ ] = Y;
01879                     vertices[ idx++ ] = Z;
01880                 }
01881                 else {
01882                     vertices[ idx++ ] = X;
01883                     vertices[ idx++ ] = Y;
01884                     vertices[ idx++ ] = Z;
01885                 }
01886                 X += texCoordStep[0] * texCoordStep[0];
01887             }
01888             Y += texCoordStep[1] * texCoordStep[1];
01889         }
01890         Z += texCoordStep[2];
01891     }
01892     //-----------------------------------------------------
01893     //*/
01894 
01895     glUnmapBuffer( GL_ARRAY_BUFFER );
01896     glBindBuffer( GL_ARRAY_BUFFER, 0 );
01897     //-----------------------------------------------------
01898     return true;
01899 }
01900 //-----------------------------------------------------------------------------
01901 // END: GenerateTheVBOForTextureCoordinates
01902 //=============================================================================
01903 #endif // TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO
01904 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01905 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
01906 
01907 
01908 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
01909 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01910 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01911 //=============================================================================
01912 // Vertex Buffer for Cube Tracking
01913 //-----------------------------------------------------------------------------
01914 template <typename T>
01915 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
01916 GenerateTheVBOForTexCoordForCubeTracking ( Vector3<int> const & vGridSize )
01917 {
01918     assert( m_vboTexCoordForCubeTracking == 0 );
01919     //-------------------------------------------
01920     // Reduce the grid size by one, 
01921     // since needed only the # of cubes for marching cube.
01922     //-------------------------------------------
01923     // Process 1x1x1 Cubes as a group
01924     Vector3<int> v1x1x1NumBlocks( 
01925         vGridSize[0]-1, 
01926         vGridSize[1]-1, 
01927         vGridSize[2]-1 
01928     );
01929     m_uiTotalCubes = v1x1x1NumBlocks[0] * v1x1x1NumBlocks[1] * v1x1x1NumBlocks[2];
01930     glGenBuffers( 1, &m_vboTexCoordForCubeTracking );
01931     if ( m_vboTexCoordForCubeTracking == 0 ) return false;
01932     //-----------------------------------------------------
01933     glBindBuffer( GL_ARRAY_BUFFER, m_vboTexCoordForCubeTracking );
01934     glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat)*m_uiTotalCubes*3, NULL, GL_STATIC_DRAW );
01935     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
01936     float * vertices = static_cast<float *>( glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY ) );
01937     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
01938     //-----------------------------------------------------
01939     // Grid size is #ofBlocks + 1
01940     // Divided by vGridSize so that the texture coordinates is of 
01941     // the first vertex (#0) of the cube
01942     Vector3<float> texCoordStep( 
01943         1.0 / v1x1x1NumBlocks[0], 1.0 / v1x1x1NumBlocks[1], 1.0 / v1x1x1NumBlocks[2] );
01944     Vector3<float> minTexCoord( 
01945         texCoordStep[0] / 2.0, texCoordStep[1] / 2.0, texCoordStep[2] / 2.0 );
01946     int idx = 0;
01947     float Z = minTexCoord[2];
01948     //-------------------------------------------
01949     for ( int z = 0; z < v1x1x1NumBlocks[2]; ++z ) {
01950         float Y = minTexCoord[1];
01951         for ( int y = 0; y < v1x1x1NumBlocks[1]; ++y ) {
01952             float X = minTexCoord[0];
01953             for ( int x = 0; x < v1x1x1NumBlocks[0]; ++x ) {
01954                 vertices[ idx++ ] = X;
01955                 vertices[ idx++ ] = Y;
01956                 vertices[ idx++ ] = Z;
01957                 /*/
01958                 std::cout << "VBO for Rendering: " 
01959                     << X << ", " 
01960                     << Y << ", " 
01961                     << Z << "\n";
01962                 //*/
01963                 X += texCoordStep[0];
01964             }
01965             Y += texCoordStep[1];
01966         }
01967         Z += texCoordStep[2];
01968     }
01969     //-----------------------------------------------------
01970     glUnmapBuffer( GL_ARRAY_BUFFER );
01971     glBindBuffer( GL_ARRAY_BUFFER, 0 );
01972     //-----------------------------------------------------
01973     return true;
01974 }
01975 //-----------------------------------------------------------------------------
01976 // END: GenerateTheVBOForTexCoordForCubeTracking
01977 //=============================================================================
01978 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
01979 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
01980 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
01981 
01982 
01983 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
01984 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
01985 //=============================================================================
01986 // Vertex Buffer for Rendering
01987 //-----------------------------------------------------------------------------
01988 template <typename T>
01989 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::
01990 GenerateTheVBOForTextureCoordinates ( Vector3<int> const & vGridSize )
01991 {
01992     assert( m_vboVerticesAsTexCoords == 0 );
01993     //-------------------------------------------
01994     // Reduce the grid size by one, 
01995     // since needed only the # of cubes for marching cube.
01996     // Process 2x2x2 Cubes as a group
01997     Vector3<int> v2x2x2NumBlocks( 
01998         ceil( (vGridSize[0]-1)/2.0 ), 
01999         ceil( (vGridSize[1]-1)/2.0 ), 
02000         ceil( (vGridSize[2]-1)/2.0 ) 
02001     );
02002 
02003     //wxLogError( wxT("#Blocks: %i %i %i"), v2x2x2NumBlocks[0], v2x2x2NumBlocks[1], v2x2x2NumBlocks[2] );
02004 
02005     m_uiTotalCubes = v2x2x2NumBlocks[0] * v2x2x2NumBlocks[1] * v2x2x2NumBlocks[2];
02006     glGenBuffers( 1, &m_vboVerticesAsTexCoords );
02007     if ( m_vboVerticesAsTexCoords == 0 ) return false;
02008     //-----------------------------------------------------
02009     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02010     glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat)*m_uiTotalCubes*3, NULL, GL_STATIC_DRAW );
02011     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02012     float * vertices = static_cast<float *>( glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY ) );
02013     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02014     //-----------------------------------------------------
02015     // Grid size is #ofBlocks + 1
02016     // Divided by (v2x2x2NumBlocks[0]+1) so that the texture coordinates is of 
02017     // the first vertex (#0) of the cube
02018 
02019     // The texture is from 0 to 1 (0 - gridsize)
02020     Vector3<float> texCoordStep( 
02021         2.0 / vGridSize[0], 2.0 / vGridSize[1], 2.0 / vGridSize[2] );
02022     Vector3<float> minTexCoord( 
02023         0.5 / vGridSize[0], 0.5 / vGridSize[1], 0.5 / vGridSize[2] );
02024     int idx = 0;
02025     float Z = minTexCoord[2];
02026     //-------------------------------------------
02027     // Reduce the grid size by one, 
02028     // since needed only the # of cubes for marching cube.
02029     for ( int z = 0; z < v2x2x2NumBlocks[2]; ++z ) {
02030         float Y = minTexCoord[1];
02031         for ( int y = 0; y < v2x2x2NumBlocks[1]; ++y ) {
02032             float X = minTexCoord[0];
02033             for ( int x = 0; x < v2x2x2NumBlocks[0]; ++x ) {
02034                 vertices[ idx++ ] = X;
02035                 vertices[ idx++ ] = Y;
02036                 vertices[ idx++ ] = Z;
02037                 /*/
02038                 std::cout << "VBO for Rendering: " 
02039                     << X << ", " 
02040                     << Y << ", " 
02041                     << Z << "\n";
02042                 //*/
02043                 X += texCoordStep[0];
02044             }
02045             Y += texCoordStep[1];
02046         }
02047         Z += texCoordStep[2];
02048     }
02049     //-----------------------------------------------------
02050     glUnmapBuffer( GL_ARRAY_BUFFER );
02051     glBindBuffer( GL_ARRAY_BUFFER, 0 );
02052     //-----------------------------------------------------
02053     return true;
02054 }
02055 //-----------------------------------------------------------------------------
02056 // END: GenerateTheVBOForTextureCoordinates
02057 //=============================================================================
02058 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
02059 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
02060 
02061 
02062 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02063 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02064 //*****************************************************************************
02065 // BEGIN: GenerateBufferObjects
02066 //-----------------------------------------------------------------------------
02067 template <typename T>
02068 bool ModelDeformableGLSL_Visualization_RTGenMesh<T>::GenerateBufferObjects ()
02069 {
02070     //===============================================================
02071     // Framebuffer Object(s)
02072     //---------------------------------------------------------------
02073     //-----------------------
02074     // For Cube Tracking
02075     //-----------------------
02076     glGenFramebuffersEXT( 1, &m_glslFBO_CubeTracking );
02077     glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_CubeTracking );
02078     glFramebufferTexture3DEXT(
02079         GL_FRAMEBUFFER_EXT,         // target
02080         GL_COLOR_ATTACHMENT0_EXT,   // attached frame
02081         GL_TEXTURE_3D,              // texture target
02082         CubeTrackingTexture,        // texture id
02083         0,                          // level
02084         0                           // zoffset (for 3D texture)
02085     );
02086     //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );
02087     TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS();
02088     glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
02089     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02090     //-----------------------
02091     //---------------------------------------------------------------
02092     //===============================================================
02093     return true;
02094 }
02095 //-----------------------------------------------------------------------------
02096 // END: GenerateBufferObjects
02097 //*****************************************************************************
02098 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02099 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02100 
02101 
02102 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02103 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
02104 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02105 //*****************************************************************************
02106 // BEGIN: UpdateCubeTrackingTexture
02107 //-----------------------------------------------------------------------------
02108 template <typename T>
02109 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::UpdateCubeTrackingTexture ()
02110 {
02116     //---------------------------------------------------------------
02117 #ifdef TAPs_DEBUG_MODE
02118     if ( !m_SimDomain ) return;
02119     //---------------------------------------------------------------
02120     if ( !m_SimDomain->RetObject3DTexturePosition() )   return;
02121     //---------------------------------------------------------------
02122 #endif
02123 
02124     //UpdateCollisionDetectionParameters();
02125     //---------------------------------------------------------------
02126     //===============================================================
02127     // Get 3D texture for positions
02128     //---------------------------------------------------------------
02129     Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
02130     //---------------------------------------------------------------
02131     //===============================================================
02132     texture3DPosition->EnableTextureTarget();
02133     m_glslProgramObjectUpdateCubeTracking->BeginGLSL();
02134     glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_CubeTracking );
02135     TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS();
02136     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02137     glPushAttrib( GL_ALL_ATTRIB_BITS );
02138     {
02139         //-------------------------------------------------
02140         // Send Stream of Data (one 2D texture at a time in a for loop)
02141         glMatrixMode( GL_PROJECTION );
02142         glPushMatrix();
02143         glLoadIdentity();
02144         //
02145         Vector3<T> offsetCoords = m_SimDomain->GetTexCoordOffsetForPosition();
02146         T offsetRCoord = offsetCoords[2] / 2.0;
02147         T maxCoordS = 1.0 - offsetCoords[0];
02148         T maxCoordT = 1.0 - offsetCoords[1];
02149         //
02150         // Set texture coordinates -- xMin, xMax, yMin and yMax
02151         // In this case, they are      0,    1,    0,  and  1.
02152         //gluOrtho2D( 0, texture3DPosition->GetMaxCoordS(), 
02153         //          0, texture3DPosition->GetMaxCoordT() );
02154         gluOrtho2D( 0, maxCoordS, 0, maxCoordT );
02155         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02156         //
02157         glMatrixMode( GL_MODELVIEW );
02158         glPushMatrix();
02159         glLoadIdentity();
02160         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02161         //
02162         // Generate pixels -- xMin, xMax, yMin, and yMax
02163         // One less due to the cube size.
02164         glViewport( 0, 0, texture3DPosition->GetWidth()-1, 
02165                           texture3DPosition->GetHeight()-1 );
02166         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02167         //
02168         //=================================================
02169         //-------------------------------------------------
02170         // Uniform Variables
02171         //-------------------------------------------------
02172         // Threshold
02173         m_glslProgramObjectUpdateCubeTracking->SetUniform1f( "threshold", m_SimDomain->IC_Thresholds::ON_BOUNDARY );
02174         //---------------------------------
02175         // Coordinate Offsets
02176         m_glslProgramObjectUpdateCubeTracking->SetUniform3f( 
02177             "offsetCoordsPosition", 
02178             offsetCoords[0], offsetCoords[1], offsetCoords[2] 
02179         );
02180         //-------------------------------------------------
02181         texture3DPosition->EnableTextureTarget();
02182         //-------------------------------------------------
02183         // Set PositionTexture to Texture Unit 0
02184         glActiveTexture( GL_TEXTURE0 );
02185         texture3DPosition->BindTexture(0);
02186         m_glslProgramObjectUpdateCubeTracking->SetUniform1i( "PositionTexture", 0 );
02187         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02188         //-------------------------------------------------
02189         //=================================================
02190         // The size is m_vGridResolution[2]-1, due to the cube size is one less.
02191         for ( int i = 0; i < texture3DPosition->GetDepth()-1; ++i ) {
02192             //-------------------------------------------------
02193             glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_glslFBO_CubeTracking );
02194             glFramebufferTexture3DEXT(
02195                 GL_FRAMEBUFFER_EXT,         // target
02196                 GL_COLOR_ATTACHMENT0_EXT,   // attached frame
02197                 GL_TEXTURE_3D,              // texture target
02198                 CubeTrackingTexture,        // texture id -- next position
02199                 0,                          // level
02200                 i                           // zoffset
02201             );
02202             glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );
02203 
02204             // CURRENTLY
02205             // The GLSL's texture3D( isampler3D sampler, vec3 coords ) 
02206             // doesn't return the correct value for integer
02207             // The GLSL's texture3D( usampler3D sampler, vec3 coords ) 
02208             // doesn't return the correct value for unsinged integer
02209             // So GL_ALPHA8 is used instead!
02210             // So glBindFragDataLocationEXT is not used!
02211             // CURRENTLY
02212             // GL_ALPHA8 DOESN'T WORK EITHER SO BACK TO GL_ALPHA16UI_EXT
02213             // So use the below statement for writing to integer texture
02214 
02215             // New fn for writing unsigned int from fragment shader to GL_COLOR_ATTACHMENT location
02216             //void BindFragDataLocationEXT(uint program, uint colorNumber, const char *name);
02217             glBindFragDataLocationEXT( m_glslProgramObjectUpdateCubeTracking->GetProgramObject(), 0, "fragData0" );
02218 
02219             TAPs::OpenGL::Fn::CHECK_FRAMEBUFFER_STATUS();
02220             //-------------------------------------------------
02221             // Send data stream to GPU
02222             TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02223             //
02224             glClearColor( 0, 0, 0, 0 );
02225             //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
02226             glClear( GL_COLOR_BUFFER_BIT );
02227             //
02228             T coordR = offsetCoords[2]*i + offsetRCoord;
02229             glPolygonMode( GL_FRONT, GL_FILL );
02230             glBegin( GL_QUADS );
02231                 glTexCoord3f( 0,            0,          coordR );
02232                 glVertex3f  ( 0,            0,          0 );
02233                 glTexCoord3f( maxCoordS,    0,          coordR );
02234                 glVertex3f  ( maxCoordS,    0,          0 );
02235                 glTexCoord3f( maxCoordS,    maxCoordT,  coordR );
02236                 glVertex3f  ( maxCoordS,    maxCoordT,  0 );
02237                 glTexCoord3f( 0,            maxCoordT,  coordR );
02238                 glVertex3f  ( 0,            maxCoordT,  0 );
02239             glEnd();
02240         }
02241         glPopMatrix();
02242         glMatrixMode( GL_PROJECTION );
02243         glPopMatrix();
02244         glMatrixMode( GL_MODELVIEW );
02245     }
02246     glPopAttrib();
02247     texture3DPosition->DisableTextureTarget();
02248     texture3DPosition->UnbindTexture();
02249     glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
02250     //
02251     m_glslProgramObjectUpdateCubeTracking->EndGLSL();
02252     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02253     //---------------------------------------------------------------
02254 
02255 
02256     /*
02257     // DEBUG
02258     {
02259         Vector3<int> vCubes( 
02260             texture3DPosition->GetWidth()-1, 
02261             texture3DPosition->GetHeight()-1, 
02262             texture3DPosition->GetDepth()-1 
02263         );
02264         int iTotalCubes = vCubes[0] * vCubes[1] * vCubes[2];
02265         //GLubyte * pCubeValData = new GLubyte[ iTotalCubes * 2 ];  // there's one more read element per row!  Why? How to fix it?
02266         GLint * pCubeValData = new GLint[ iTotalCubes ];
02267         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
02268         glBindTexture( GL_TEXTURE_3D, CubeTrackingTexture );
02269 
02270         // CURRENTLY, GL_ALPHA8UI_EXT is not working correctly.
02271         // Due to bugs with unsigned int in geometry shader compiler/driver.
02272         // So GL_ALPHA16I_EXT is used instead!
02273         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT, pCubeValData );
02274         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
02275         // CURRENTLY
02276         // The GLSL's texture3D( isampler3D sampler, vec3 coords ) 
02277         // doesn't return the correct value for integer
02278         // The GLSL's texture3D( usampler3D sampler, vec3 coords ) 
02279         // doesn't return the correct value for unsinged integer
02280         // So GL_ALPHA8 is used instead!
02281         //glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pCubeValData );
02282         // CURRENTLY
02283         // GL_ALPHA8 DOESN'T WORK EITHER SO BACK TO GL_ALPHA16UI_EXT
02284         glGetTexImage( GL_TEXTURE_3D, 0, GL_ALPHA_INTEGER_EXT, GL_INT, pCubeValData );
02285 
02286         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02287         std::cout << "-------------------------------\n";
02288         std::cout << "Cube Tracking Texture -- UPDATE\n";
02289         std::cout << "-------------------------------\n";
02290         int i = 0;
02291         for ( int z = 0; z < vCubes[2]; ++z ) {
02292             for ( int y = 0; y < vCubes[1]; ++y ) {
02293                 for ( int x = 0; x < vCubes[0]; ++x ) {
02294                     std::cout << "  ";
02295                     if ( pCubeValData[i] < 100 )    std::cout << " ";
02296                     if ( pCubeValData[i] <  10 )    std::cout << " ";
02297                     std::cout << static_cast<int>( pCubeValData[i] );
02298                     ++i;
02299                 }
02300                 std::cout << "\n";
02301             }
02302             std::cout << "\n";
02303         }
02304         std::cout << "---------------------\n";
02305         //---------------------------------
02306         glDisable( GL_TEXTURE_3D );
02307         glBindTexture( GL_TEXTURE_3D, 0 );
02308         //-----------------------------------------------------
02309         delete [] pCubeValData;
02310     }
02311     //*/
02312 
02313 
02314     /*
02315     //===============================================================
02316     // Get 3D texture for positions
02317     //---------------------------------------------------------------
02318     Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
02319     //---------------------------------------------------------------
02320     //===============================================================
02321     // 
02322     //---------------------------------------------------------------
02323     glPushAttrib( GL_ALL_ATTRIB_BITS );
02324     //-----------------------------------------------------
02325     //-----------------------------------------------------
02326     m_glslProgramObjectUpdateCubeTracking->BeginGLSL();
02327     //-----------------------------------------------------
02328 
02329     //+++++++++++++++++++++++++++++++++++++++++++
02330     //===========================================
02331     // START: Parameter Setup
02332     //-------------------------------------------
02333     // Texture Parameter Setup
02334     //---------------------------------
02335     // Set PositionTexture to Texture Unit 0
02336     texture3DPosition->EnableTextureTarget();
02337     glActiveTexture( GL_TEXTURE0 );
02338     texture3DPosition->BindTexture(0);
02339     m_glslProgramObjectUpdateCubeTracking->SetUniform1i( "PositionTexture", 0 );
02340     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02341     //---------------------------------
02342     // Threshold Value
02343     m_glslProgramObjectUpdateCubeTracking->SetUniform1f( "threshold", m_SimDomain->IC_Thresholds::ON_BOUNDARY );
02344     //---------------------------------
02345     // Coordinate Offsets
02346     Vector3<T> coordOffsets = m_SimDomain->GetTexCoordOffsetForPosition();
02347     m_glslProgramObjectUpdateCubeTracking->SetUniform3f( 
02348         "offsetCoordsPosition", 
02349         coordOffsets[0], coordOffsets[1], coordOffsets[2] 
02350     );
02351     //-------------------------------------------
02352     // END: Parameter Setup
02353     //===========================================
02354     //+++++++++++++++++++++++++++++++++++++++++++
02355 
02356     //-----------------------------------------------------
02357     // Bind the buffer and then draw
02358     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02359     glVertexPointer( 3, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02360     glEnableClientState( GL_VERTEX_ARRAY );
02361     glDrawArrays( GL_POINTS, 0, m_uiTotalCubes );
02362     glDisableClientState( GL_VERTEX_ARRAY );
02363     glBindBuffer( GL_ARRAY_BUFFER, 0 );
02364     //-----------------------------------------------------
02365     m_glslProgramObjectUpdateCubeTracking->EndGLSL();
02366     //-----------------------------------------------------
02367     texture3DPosition->DisableTextureTarget();
02368     texture3DPosition->UnbindTexture();
02369     //-----------------------------------------------------
02370     glPopAttrib();
02371     //---------------------------------------------------------------
02372     //===============================================================
02373     //*/
02374 }
02375 //-----------------------------------------------------------------------------
02376 // END: UpdateCubeTrackingTexture
02377 //*****************************************************************************
02378 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02379 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
02380 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02381 
02382 
02383 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02384 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
02385 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
02386 //*****************************************************************************
02387 // BEGIN: DrawByGLSL
02388 //-----------------------------------------------------------------------------
02389 template <typename T>
02390 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::DrawByGLSL ()
02391 {
02402     //---------------------------------------------------------------
02403 #ifdef TAPs_DEBUG_MODE
02404     if ( !m_SimDomain ) return;
02405     //---------------------------------------------------------------
02406     if ( !m_SimDomain->RetObject3DTexturePosition() )   return;
02407     //---------------------------------------------------------------
02408 #endif
02409     //*
02410     //===============================================================
02411     // Get 3D texture for positions
02412     //---------------------------------------------------------------
02413     Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
02414     //GLfloat modelviewMatrix[16];
02415     //glGetFloatv( GL_MODELVIEW_MATRIX, modelviewMatrix );
02416     //---------------------------------------------------------------
02417     //===============================================================
02418     // Draw the deformable model
02419     //---------------------------------------------------------------
02420     glPushAttrib( GL_ALL_ATTRIB_BITS );
02421     //-----------------------------------------------------
02422     glColor3ub( 80, 80, 80 );
02423     //glEnable( GL_COLOR_MATERIAL );
02424     glEnable( GL_LIGHTING );
02425     glEnable( GL_BLEND );
02426     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
02427     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );
02428     glEnable( GL_TEXTURE_3D );
02429     //glEnable( GL_CULL_FACE ); // Doesn't really make the drawing run faster!
02430     //glShadeModel( GL_SMOOTH );
02431     //glShadeModel( GL_FLAT );
02432     //-----------------------------------------------------
02433     //texture3DPosition->EnableTextureTarget();
02434     //glActiveTexture( GL_TEXTURE0 );
02435     //texture3DPosition->BindTexture(0);
02436     //-----------------------------------------------------
02437     GLSLProgramObject * pShader = NULL;
02438     if ( m_bUseGlobalInterpolationVal ) {
02439         pShader = m_glslProgramObjectWithGlobalIntpValue;
02440     }
02441     else {
02442         pShader = m_glslProgramObjectWithTextureIntpValue;
02443     }
02444     pShader->BeginGLSL();
02445     //-----------------------------------------------------
02446 
02447     //+++++++++++++++++++++++++++++++++++++++++++
02448     //===========================================
02449     // START: Parameter Setup
02450     //-------------------------------------------
02451     // Texture Parameter Setup
02452     // Set Surface 3D Texture to Texture Unit 0
02453     //glEnable( GL_BLEND );
02454     if ( m_3DTexture ) {
02455         glActiveTexture( GL_TEXTURE0 );
02456         glBindTexture( GL_TEXTURE_3D, m_3DTexture );
02457         pShader->SetUniform1i( "SurfaceTexture", 0 );
02458         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02459     }
02460     //---------------------------------
02461     // Set PositionTexture to Texture Unit 1
02462     texture3DPosition->EnableTextureTarget();
02463     glActiveTexture( GL_TEXTURE1 );
02464     texture3DPosition->BindTexture(0);
02465     pShader->SetUniform1i( "PositionTexture", 1 );
02466     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02467     //---------------------------------
02468     // Set Edge Table to Texture Unit 2
02469     glEnable( GL_TEXTURE_2D );
02470     glActiveTexture( GL_TEXTURE2 );
02471     glBindTexture( GL_TEXTURE_2D, EdgeTableTexture );
02472     pShader->SetUniform1i( "EdgeTableTexture", 2 );
02473     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02474     //---------------------------------
02475     // Set Triangle Table to Texture Unit 3
02476     //glEnable( GL_TEXTURE_2D );
02477     glActiveTexture( GL_TEXTURE3 );
02478     glBindTexture( GL_TEXTURE_2D, TriTableTexture );
02479     pShader->SetUniform1i( "TriTableTexture", 3 );
02480     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02481     //---------------------------------
02482     // A Combined Texture for Triangle and Edge Tables
02483     // Set Triangle and Edge Tables to Texture Unit 2
02484     //glEnable( GL_TEXTURE_2D );
02485     //glActiveTexture( GL_TEXTURE2 );
02486     //glBindTexture( GL_TEXTURE_2D, TriAndEdgeTableTexture );
02487     //m_glslProgramObject->SetUniform1i( "TriAndEdgeTableTexture", 2 );
02488     //TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02489     //-------------------------------------------------------------------------
02490 
02491     // WITH GRADIENT TEXTURE
02492     #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
02493     //---------------------------------
02494     // Set Gradient to Texture Unit 6
02495     glActiveTexture( GL_TEXTURE6 );
02496     glBindTexture( GL_TEXTURE_3D, m_SimDomain->Get3DTextureGradient() );
02497     pShader->SetUniform1i( "Gradient", 6 );
02498     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02499     //---------------------------------
02500     #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE
02501 
02502     //int maximum;
02503     //glGetIntegerv( GL_MAX_TEXTURE_COORDS, &maximum );
02504     //std::cout << "GL_MAX_TEXTURE_COORDS: " << maximum << "\n";
02505     //glGetIntegerv( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maximum );
02506     //std::cout << "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: " << maximum << "\n";
02507 
02508     //=========================================================================
02509     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02510     //-------------------------------------------------------------------------
02511     // Can't set to Texture Unit 0, 1, 2, or 3 -- they are in used
02512     // If set to Texture Unit 0 (1, 2, or 3), the surface will not be drawn.
02513     // Set Cube Tracking Texture to Texture Unit 4
02514     //glEnable( GL_TEXTURE_3D );
02515     glActiveTexture( GL_TEXTURE4 );
02516     glBindTexture( GL_TEXTURE_3D, CubeTrackingTexture );
02517 
02518     //m_glslProgramObject->SetUniform1ui( "CubeTrackingTexture", 4 );
02519     // CURRENTLY, GL_ALPHA8UI_EXT is not working correctly.
02520     // Due to bugs with unsigned int in geometry shader compiler/driver.
02521     // So GL_ALPHA16I_EXT is used instead!
02522     //m_glslProgramObject->SetUniform1i( "CubeTrackingTexture", 4 );
02523     // CURRENTLY
02524     // The GLSL's texture3D( isampler3D sampler, vec3 coords ) 
02525     // doesn't return the correct value for integer
02526     // The GLSL's texture3D( usampler3D sampler, vec3 coords ) 
02527     // doesn't return the correct value for unsinged integer
02528     // So GL_ALPHA8 is used instead!
02529     pShader->SetUniform1i( "CubeTrackingTexture", 4 );
02530     //-------------------------------------------------------------------------
02531     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02532     //=========================================================================
02533     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02534 
02535     //---------------------------------
02536     // Selectable Gradient Computations
02537     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
02538     pShader->SetUniform1i( "bGradFaces",    m_bComputeGradientFaces );
02539     pShader->SetUniform1i( "bGradVertices", m_bComputeGradientVertices );
02540     pShader->SetUniform1i( "bGradEdges",    m_bComputeGradientEdges );
02541     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_GRADIENT_SELECTABLE
02542 
02543     //---------------------------------
02544     // Interpolation Value
02545     //   use global value
02546     if ( m_bUseGlobalInterpolationVal ) {
02547         pShader->SetUniform1f( "interpolationValue", m_tGlobalInterpolationVal );
02548     }
02549     //   use values store in texture
02550     else {
02551         glActiveTexture( GL_TEXTURE5 );
02552         glBindTexture( GL_TEXTURE_3D, m_SimDomain->Get3DTextureEllipsoidInfluence() );
02553         pShader->SetUniform1i( "IntpValTexture", 5 );
02554         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02555     }
02556 
02557     /*
02558     //---------------------------------
02559     // Threshold Value --> moved to UpdateShaderParametersForVisualization Fn
02560     pShader->SetUniform1f( "threshold", m_SimDomain->IC_Thresholds::ON_BOUNDARY );
02561     //---------------------------------
02562     // Coordinate Offsets --> moved to UpdateShaderParametersForVisualization Fn
02563     Vector3<T> coordOffsets = m_SimDomain->GetTexCoordOffsetForPosition();
02564     pShader->SetUniform3f( 
02565         "offsetCoordsPosition", 
02566 #ifdef TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO
02567         coordOffsets[0]*0.5, coordOffsets[1]*0.5, coordOffsets[2]*0.5 
02568 #else
02569         coordOffsets[0], coordOffsets[1], coordOffsets[2] 
02570 #endif // TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO
02571     );
02572     //---------------------------------
02573     //*/
02574     UpdateShaderParametersForVisualization( pShader );
02575 
02576     //---------------------------------
02577     // Threshold Value
02578     // For NVIDIA 320MB 8800 GTS, the smoothness should be at most 4.
02579     // The smotthness cannot be less than 2, due to the essential nature of PNTriangle algorithm.
02580     // Therefore, the smoothness must be between 2 (no PNTriangle, i.e. original triangle) to 4.
02581     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
02582         int Smoothness = static_cast<int>( m_PNTriangleSmoothness );
02583         if      ( Smoothness < 2 ) Smoothness = 2;
02584         else if ( Smoothness > 4 ) Smoothness = 4;
02585         //std::cout << "Smoothness: " << Smoothness << std::endl;
02586         m_glslProgramObject->SetUniform1i( "Smoothness", Smoothness );
02587     #endif // #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
02588     //---------------------------------
02589 
02590     //-------------------------------------------
02591     // END: Parameter Setup
02592     //===========================================
02593     //+++++++++++++++++++++++++++++++++++++++++++
02594 
02595     glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
02596     //-----------------------------------------------------
02597 
02598     glEnableClientState( GL_VERTEX_ARRAY );
02599 
02600     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02601     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
02602     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02603 
02604     //-------------------------------------------
02605     // Bind the buffer for vertices as texture coordinate for vertex positions
02606     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02607     //glVertexPointer( 3, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02608     glVertexPointer( 4, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02609 
02610     //-------------------------------------------
02611     // Bind the buffer for vertices as texture coordinate for vertex positions
02612     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02613     glBindBuffer( GL_ARRAY_BUFFER, m_vboTexCoordForCubeTracking );
02614     glTexCoordPointer( 3, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02615     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
02616 
02617     //-------------------------------------------
02618     // Draw
02619     //glBeginTransformFeedbackNV( GL_TRIANGLES );
02620     glDrawArrays( GL_POINTS, 0, m_uiTotalCubes );
02621     //glEndTransformFeedbackNV();
02622 
02623     glBindBuffer( GL_ARRAY_BUFFER, 0 );
02624     glDisableClientState( GL_VERTEX_ARRAY );
02625     //-----------------------------------------------------
02626     glPopClientAttrib();
02627 
02628     //-----------------------------------------------------
02629     pShader->EndGLSL();
02630     //-----------------------------------------------------
02631     texture3DPosition->DisableTextureTarget();
02632     texture3DPosition->UnbindTexture();
02633     //-----------------------------------------------------
02634     glPopAttrib();
02635     //---------------------------------------------------------------
02636     //===============================================================
02637     //*/
02638 
02639     /*
02640     //=========================================================================
02641     // TEST DRAWING
02642     glPushAttrib( GL_ALL_ATTRIB_BITS );
02643     glColor3ub( 175, 80, 80 );
02644     glEnable( GL_COLOR_MATERIAL );
02645     glDisable( GL_LIGHTING );
02646     glPointSize( 5 );
02647     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02648     glVertexPointer( 3, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02649     glEnableClientState( GL_VERTEX_ARRAY );
02650     //glDrawArrays( GL_POINTS, 0, m_SimDomain->GetTotalGridElements() );
02651 
02652     //glBeginTransformFeedbackNV( GL_TRIANGLES );
02653     glDrawArrays( GL_POINTS, 0, m_uiTotalCubes );
02654     //glEndTransformFeedbackNV();
02655 
02656     glDisableClientState( GL_VERTEX_ARRAY );
02657     glBindBuffer( GL_ARRAY_BUFFER, 0 );
02658     glPopAttrib();
02659     //=========================================================================
02660     //*/
02661 }
02662 //-----------------------------------------------------------------------------
02663 // END: DrawByGLSL
02664 //*****************************************************************************
02665 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_1X1X1_CUBES
02666 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
02667 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02668 
02669 
02670 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02671 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
02672 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
02673 //*****************************************************************************
02674 // BEGIN: DrawByGLSL
02675 //-----------------------------------------------------------------------------
02676 template <typename T>
02677 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::DrawByGLSL ()
02678 {
02689     //---------------------------------------------------------------
02690 #ifdef TAPs_DEBUG_MODE
02691     if ( !m_SimDomain ) return;
02692     //---------------------------------------------------------------
02693     if ( !m_SimDomain->RetObject3DTexturePosition() )   return;
02694     //---------------------------------------------------------------
02695 #endif
02696     //*
02697     //===============================================================
02698     // Get 3D texture for positions
02699     //---------------------------------------------------------------
02700     Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
02701     //GLfloat modelviewMatrix[16];
02702     //glGetFloatv( GL_MODELVIEW_MATRIX, modelviewMatrix );
02703     //---------------------------------------------------------------
02704     //===============================================================
02705     // Draw the deformable model
02706     //---------------------------------------------------------------
02707     glPushAttrib( GL_ALL_ATTRIB_BITS );
02708     //-----------------------------------------------------
02709     glColor3ub( 80, 80, 80 );
02710     glEnable( GL_COLOR_MATERIAL );
02711     glEnable( GL_LIGHTING );
02712     glEnable( GL_BLEND );
02713     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
02714     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );
02715     //glShadeModel( GL_SMOOTH );
02716     //glShadeModel( GL_FLAT );
02717     //-----------------------------------------------------
02718     //texture3DPosition->EnableTextureTarget();
02719     //glActiveTexture( GL_TEXTURE0 );
02720     //texture3DPosition->BindTexture(0);
02721     //-----------------------------------------------------
02722     GLSLProgramObject * pShader = NULL;
02723     if ( m_bUseGlobalInterpolationVal ) {
02724         pShader = m_glslProgramObjectWithGlobalIntpValue;
02725     }
02726     else {
02727         pShader = m_glslProgramObjectWithTextureIntpValue;
02728     }
02729     pShader->BeginGLSL();
02730     //-----------------------------------------------------
02731 
02732     //+++++++++++++++++++++++++++++++++++++++++++
02733     //===========================================
02734     // START: Parameter Setup
02735     //-------------------------------------------
02736     // Texture Parameter Setup
02737     // Set Surface 3D Texture to Texture Unit 0
02738     //glEnable( GL_BLEND );
02739     glEnable( GL_TEXTURE_3D );
02740     glActiveTexture( GL_TEXTURE0 );
02741     glBindTexture( GL_TEXTURE_3D, m_3DTexture );
02742     pShader->SetUniform1i( "SurfaceTexture", 0 );
02743     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02744     //---------------------------------
02745     // Set PositionTexture to Texture Unit 1
02746     texture3DPosition->EnableTextureTarget();
02747     glActiveTexture( GL_TEXTURE1 );
02748     texture3DPosition->BindTexture(0);
02749     pShader->SetUniform1i( "PositionTexture", 1 );
02750     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02751     //---------------------------------
02752     // Set Edge Table to Texture Unit 2
02753     glEnable( GL_TEXTURE_2D );
02754     glActiveTexture( GL_TEXTURE2 );
02755     glBindTexture( GL_TEXTURE_2D, EdgeTableTexture );
02756     pShader->SetUniform1i( "EdgeTableTexture", 2 );
02757     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02758     //---------------------------------
02759     // Set Triangle Table to Texture Unit 3
02760     //glEnable( GL_TEXTURE_2D );
02761     glActiveTexture( GL_TEXTURE3 );
02762     glBindTexture( GL_TEXTURE_2D, TriTableTexture );
02763     pShader->SetUniform1i( "TriTableTexture", 3 );
02764     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02765     //---------------------------------
02766     // Set Triangle and Edge Tables to Texture Unit 2
02767     //glEnable( GL_TEXTURE_2D );
02768     //glActiveTexture( GL_TEXTURE2 );
02769     //glBindTexture( GL_TEXTURE_2D, TriAndEdgeTableTexture );
02770     //pShader->SetUniform1i( "TriAndEdgeTableTexture", 2 );
02771     //TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02772     //---------------------------------
02773     // Threshold Value
02774     pShader->SetUniform1f( "threshold", m_SimDomain->IC_Thresholds::ON_BOUNDARY );
02775     //---------------------------------
02776     // Interpolation Value
02777     pShader->SetUniform1f( "interpolationValue", m_tGlobalInterpolationVal );
02778     //---------------------------------
02779     // Threshold Value
02780     // For NVIDIA 320MB 8800 GTS, the smoothness should be at most 4.
02781     // The smotthness cannot be less than 2, due to the essential nature of PNTriangle algorithm.
02782     // Therefore, the smoothness must be between 2 (no PNTriangle, i.e. original triangle) to 4.
02783     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
02784         int Smoothness = static_cast<int>( m_PNTriangleSmoothness );
02785         if      ( Smoothness < 2 ) Smoothness = 2;
02786         else if ( Smoothness > 4 ) Smoothness = 4;
02787         //std::cout << "Smoothness: " << Smoothness << std::endl;
02788         pShader->SetUniform1i( "Smoothness", Smoothness );
02789     #endif // #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_PNTRI
02790     //---------------------------------
02791     // Coordinate Offsets
02792     Vector3<T> coordOffsets = m_SimDomain->GetTexCoordOffsetForPosition();
02793     pShader->SetUniform3f( 
02794         "offsetCoordsPosition", 
02795         coordOffsets[0], coordOffsets[1], coordOffsets[2] 
02796     );
02797     //-------------------------------------------
02798     // END: Parameter Setup
02799     //===========================================
02800     //+++++++++++++++++++++++++++++++++++++++++++
02801 
02802     //-----------------------------------------------------
02803     // Bind the buffer and then draw
02804     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02805     glVertexPointer( 3, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02806     glEnableClientState( GL_VERTEX_ARRAY );
02807     //glDrawArrays( GL_POINTS, 0, m_SimDomain->GetTotalGridElements() );
02808 
02809     //glBeginTransformFeedbackNV( GL_TRIANGLES );
02810     glDrawArrays( GL_POINTS, 0, m_uiTotalCubes );
02811     //glEndTransformFeedbackNV();
02812 
02813     glDisableClientState( GL_VERTEX_ARRAY );
02814     glBindBuffer( GL_ARRAY_BUFFER, 0 );
02815     //-----------------------------------------------------
02816     pShader->EndGLSL();
02817     //-----------------------------------------------------
02818     texture3DPosition->DisableTextureTarget();
02819     texture3DPosition->UnbindTexture();
02820     //-----------------------------------------------------
02821     glPopAttrib();
02822     //---------------------------------------------------------------
02823     //===============================================================
02824     //*/
02825 
02826     /*
02827     //=========================================================================
02828     // TEST DRAWING
02829     glPushAttrib( GL_ALL_ATTRIB_BITS );
02830     glColor3ub( 175, 80, 80 );
02831     glEnable( GL_COLOR_MATERIAL );
02832     glDisable( GL_LIGHTING );
02833     glPointSize( 5 );
02834     glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02835     glVertexPointer( 3, GL_FLOAT, 0, (GLubyte *)((char *)NULL + (0)) );
02836     glEnableClientState( GL_VERTEX_ARRAY );
02837     //glDrawArrays( GL_POINTS, 0, m_SimDomain->GetTotalGridElements() );
02838 
02839     //glBeginTransformFeedbackNV( GL_TRIANGLES );
02840     glDrawArrays( GL_POINTS, 0, m_uiTotalCubes );
02841     //glEndTransformFeedbackNV();
02842 
02843     glDisableClientState( GL_VERTEX_ARRAY );
02844     glBindBuffer( GL_ARRAY_BUFFER, 0 );
02845     glPopAttrib();
02846     //=========================================================================
02847     //*/
02848 }
02849 //-----------------------------------------------------------------------------
02850 // END: DrawByGLSL
02851 //*****************************************************************************
02852 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_2X2X2_CUBES
02853 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_BUFFERS
02854 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02855 
02856 
02857 //*****************************************************************************
02858 // BEGIN: UpdateShaderParametersForVisualization
02859 //-----------------------------------------------------------------------------
02860 template <typename T>
02861 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::
02862 UpdateShaderParametersForVisualization ( GLSLProgramObject * pShader )
02863 {
02864     //-------------------------------------------
02865     //pShader->BeginGLSL();
02866         //-----------------------------
02867         pShader->SetUniform1f( "threshold", m_SimDomain->IC_Thresholds::ON_BOUNDARY );
02868         Vector3<T> vCubeDimension = m_SimDomain->RetGridDimension();
02869         pShader->SetUniform3f( "cubeDimensions", vCubeDimension[0], vCubeDimension[1], vCubeDimension[2] );
02870         //-----------------------------
02871         // Coordinate Offsets
02872         Vector3<T> coordOffsets = m_SimDomain->GetTexCoordOffsetForPosition();
02873         pShader->SetUniform3f( 
02874             "offsetCoordsPosition", 
02875     #ifdef TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO
02876             coordOffsets[0]*0.5, coordOffsets[1]*0.5, coordOffsets[2]*0.5 
02877     #else
02878             coordOffsets[0], coordOffsets[1], coordOffsets[2] 
02879     #endif // TAPs_DEFORMABLE_MODEL_VISUALIZATION_GPU_MARCHING_CUBES_SUBCUBE_BY_TWO
02880         );
02881     //-------------------------------------------
02882     //pShader->EndGLSL();
02883 }
02884 //-------------------------------------------------------------------------
02885 // END: UpdateShaderParametersForVisualization
02886 //*************************************************************************
02887 
02888 
02889 #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_CPU_RENDERING
02890 //*****************************************************************************
02891 // BEGIN: DrawByGLSL
02892 //-----------------------------------------------------------------------------
02893 template <typename T>
02894 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::DrawByGLSL ()
02895 {
02896     DrawByGL();
02897 }
02898 //-----------------------------------------------------------------------------
02899 // END: DrawByGLSL
02900 //*****************************************************************************
02901 #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_CPU_RENDERING
02902 
02903 
02904 //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
02905 //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_NOT_USE_BUFFERS
02909 //template <typename T>
02910 //void ModelDeformableGLSL_Visualization_RTGenMesh<T>::DrawByGLSL ()
02911 //{
02912 //          //*
02913 //          glPushAttrib( GL_ALL_ATTRIB_BITS );
02914 //          glDisable( GL_LIGHTING );
02915 //          glPointSize( 17 );
02916 //          glBegin( GL_POINTS );
02917 //          glColor3f( 1, 1, 1 );
02918 //          glVertex3f( 0, 0, 0 );
02919 //          glEnd();
02920 //          glPopAttrib();
02921 //          //*/
02922 //
02923 //  //---------------------------------------------------------------
02924 //#ifdef TAPs_DEBUG_MODE
02925 //  if ( !m_SimDomain ) return;
02926 //  //---------------------------------------------------------------
02927 //  if ( !m_SimDomain->RetObject3DTexturePosition() )   return;
02928 //  //---------------------------------------------------------------
02929 //#endif
02930 //  //===============================================================
02931 //  // Get 3D texture for positions
02932 //  //---------------------------------------------------------------
02933 //  Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
02934 //  //GLfloat modelviewMatrix[16];
02935 //  //glGetFloatv( GL_MODELVIEW_MATRIX, modelviewMatrix );
02936 //  //---------------------------------------------------------------
02937 //  //===============================================================
02938 //  // Draw the deformable model
02939 //  //---------------------------------------------------------------
02940 //  glPushAttrib( GL_ALL_ATTRIB_BITS );
02941 //  //-----------------------------------------------------
02942 //  texture3DPosition->EnableTextureTarget();
02943 //  //glActiveTexture( GL_TEXTURE0 );
02944 //  texture3DPosition->BindTexture(0);
02945 //  //-----------------------------------------------------
02946 //  m_glslProgramObject->BeginGLSL();
02947 //  //-----------------------------------------------------
02948 //  // Set PositionTexture to Texture Unit 0
02949 //  texture3DPosition->EnableTextureTarget();
02950 //  glActiveTexture( GL_TEXTURE0 );
02951 //  texture3DPosition->BindTexture(0);
02952 //  m_glslProgramObject->SetUniform1i( "PositionTexture", 0 );
02953 //  TAPs::OpenGL::Fn::CHECK_GL_ERROR();
02954 //  //-------------------------------------------
02955 //                                         // location name, count, isTranspose, *data
02956 //  //////m_glslProgramObject->SetUniformMatrix4fv( "ModelviewMatrix", 1, GL_FALSE, modelviewMatrix );
02957 //  //-------------------------------------------
02958 //  Vector3<int>    gridResolution = m_SimDomain->GetGridResolution();
02959 //  Vector3<T>      texCoordOffset = m_SimDomain->GetTexCoordOffsetForPosition();
02960 //  T texCoordStart[3] = { 
02961 //      texCoordOffset[0] / 2.0, 
02962 //      texCoordOffset[1] / 2.0, 
02963 //      texCoordOffset[2] / 2.0 
02964 //  };
02965 //  T texCoord[3] = { texCoordStart[0], texCoordStart[1], texCoordStart[2] };
02966 //  int idx = 0;
02967 //  glPointSize( 11 );
02968 //
02969 //
02970 //  /*/
02971 //  static bool isFirstRun = true;
02972 //  if ( isFirstRun ) {
02973 //      isFirstRun = false;
02974 //      std::cout << "m_SimDomain->GetTotalGridElements(): " << m_SimDomain->GetTotalGridElements() << "\n";
02975 //      glBindBuffer( GL_ARRAY_BUFFER, m_vboVerticesAsTexCoords );
02976 //      float * vertices = static_cast<float *>( glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY ) );
02977 //      int idx = 0;
02978 //      for ( int z = 0; z < gridResolution[2]; ++z ) {
02979 //          for ( int y = 0; y < gridResolution[1]; ++y ) {
02980 //              for ( int x = 0; x < gridResolution[0]; ++x ) {
02981 //                  std::cout << "VBO READ BACK: " 
02982 //                      << x << " " 
02983 //                      << y << " " 
02984 //                      << z << ": "
02985 //                      << vertices[idx++] << " " 
02986 //                      << vertices[idx++] << " " 
02987 //                      << vertices[idx++] << "\n";
02988 //              }
02989 //          }
02990 //      }
02991 //      glUnmapBuffer( GL_ARRAY_BUFFER );
02992 //      glBindBuffer( GL_ARRAY_BUFFER, 0 );
02993 //  }
02994 //  //*/
02995 //
02996 //  //*
02997 //  glBegin( GL_POINTS );
02998 //      //texCoord[2] = texCoordStart[2];
02999 //      for ( int Z = 0; Z < gridResolution[2]; ++Z ) {
03000 //          texCoord[1] = texCoordStart[1];
03001 //          for ( int Y = 0; Y < gridResolution[1]; ++Y ) {
03002 //              texCoord[0] = texCoordStart[0];
03003 //              for ( int X = 0; X < gridResolution[0]; ++X ) {
03004 //                  //glTexCoord3f( texCoord[0], texCoord[1], texCoord[2] );
03005 //                  glVertex3f( texCoord[0], texCoord[1], texCoord[2] );
03006 //                  idx += 4;
03007 //                  texCoord[0] += texCoordOffset[0];
03008 //              }
03009 //              texCoord[1] += texCoordOffset[1];
03010 //          }
03011 //          texCoord[2] += texCoordOffset[2];
03012 //      }
03013 //  glEnd();
03014 //  //*/
03015 //  //-----------------------------------------------------
03016 //  m_glslProgramObject->EndGLSL();
03017 //  //-----------------------------------------------------
03018 //  texture3DPosition->DisableTextureTarget();
03019 //  texture3DPosition->UnbindTexture();
03020 //  //-----------------------------------------------------
03021 //  glPopAttrib();
03022 //  //---------------------------------------------------------------
03023 //  //===============================================================
03024 //}
03028 //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_NOT_USE_BUFFERS
03029 //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_RENDERING
03030 
03031 
03032 //*****************************************************************************
03033 // BEGIN: DrawByGL_StandardMC
03034 //-----------------------------------------------------------------------------
03035 template <typename T>
03036 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::DrawByGL_StandardMC ()
03037 {
03048 //*
03049     //---------------------------------------------------------------
03050 #ifdef TAPs_DEBUG_MODE
03051     if ( !m_SimDomain ) return;
03052     //---------------------------------------------------------------
03053     if ( !m_SimDomain->RetObject3DTexturePosition() )   return;
03054     //---------------------------------------------------------------
03055 #endif
03056     //===============================================================
03057     // Read data from GPU -- Positions
03058     //---------------------------------------------------------------
03059     Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
03060     //---------------------------------------------------------------
03061     glPushAttrib( GL_ALL_ATTRIB_BITS );
03062     //-----------------------------------------------------
03063     GLsizei sizeForPosition = 
03064             texture3DPosition->GetWidth() *
03065             texture3DPosition->GetHeight() *
03066             texture3DPosition->GetDepth() *
03067             texture3DPosition->GetInternalFormatNumberOfComponents();
03068     GLfloat * dataForPosition = new GLfloat[ sizeForPosition ];
03069     {
03070         int i = 0;
03071         //=================================================
03072         // Read data for positions from a texture to memory
03073         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
03074         texture3DPosition->BindTexture(0);
03075         glGetTexImage( 
03076             texture3DPosition->GetTarget(),
03077             texture3DPosition->GetLevel(),
03078             texture3DPosition->GetPixelFormat(),
03079             texture3DPosition->GetDataType(),
03080             dataForPosition
03081         );
03082         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
03083         //=================================================
03084     }
03085     //---------------------------------------------------------------
03086     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
03087     //-----------------------------------------------------
03088     glPopAttrib();
03089     //---------------------------------------------------------------
03090     //===============================================================
03091 
03092     //===============================================================
03093     // Read data from GPU -- Ellipsoid Influence
03094     //---------------------------------------------------------------
03095     Texture * texture3DEllipsoidInfluence = m_SimDomain->RetObject3DTextureEllipsoidInfluence();
03096     //---------------------------------------------------------------
03097     glPushAttrib( GL_ALL_ATTRIB_BITS );
03098     //-----------------------------------------------------
03099     GLsizei sizeForEllipsoidInfluence = 
03100             texture3DEllipsoidInfluence->GetWidth() *
03101             texture3DEllipsoidInfluence->GetHeight() *
03102             texture3DEllipsoidInfluence->GetDepth() *
03103             texture3DEllipsoidInfluence->GetInternalFormatNumberOfComponents();
03104     //std::cout << "sizeForEllipsoidInfluence: " << sizeForEllipsoidInfluence << "\n";
03105     GLfloat * dataForEllipsoidInfluence = new GLfloat[ sizeForEllipsoidInfluence ];
03106     {
03107         int i = 0;
03108         //=================================================
03109         // Read data for ellipsoid influences from a texture to memory
03110         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
03111         texture3DEllipsoidInfluence->BindTexture(0);
03112         glGetTexImage( 
03113             texture3DEllipsoidInfluence->GetTarget(),
03114             texture3DEllipsoidInfluence->GetLevel(),
03115             texture3DEllipsoidInfluence->GetPixelFormat(),
03116             texture3DEllipsoidInfluence->GetDataType(),
03117             dataForEllipsoidInfluence
03118         );
03119         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
03120         //=================================================
03121     }
03122     //---------------------------------------------------------------
03123     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
03124     //-----------------------------------------------------
03125     glPopAttrib();
03126     //---------------------------------------------------------------
03127     //===============================================================
03128 
03129     //---------------------------------
03130     Vector3<int> gridResolution = m_SimDomain->GetGridResolution();
03131     Vector3<T>   gridDimension  = m_SimDomain->GetGridDimension();
03132     //---------------------------------
03133 
03134     //*
03135     //===============================================================
03136     // Draw by Marching Cube
03137     //---------------------------------------------------------------
03138     // Adapted from "Polygonising a scalar field" by Paul Bourke (1994)
03139     // http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/
03140     //---------------------------------------------------------------
03141     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
03142     m_glslProgramObjectForShaderSurfaceFromSW->BeginGLSL();
03143     if ( m_3DTexture ) {
03144         glActiveTexture( GL_TEXTURE0 );
03145         glBindTexture( GL_TEXTURE_3D, m_3DTexture );
03146         m_glslProgramObjectForShaderSurfaceFromSW->SetUniform1i( "SurfaceTexture", 0 );
03147         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
03148     }
03149     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
03150 
03151     glPushAttrib( GL_ALL_ATTRIB_BITS );
03152     //glLineWidth( 2 );
03153     glPointSize( 5 );
03154 
03155     //glColor3ub( 240/2, 220/2, 130/2 );
03156     //glColor3ub( 240/8, 220/8, 130/8 );
03157     //glColor3ub( 65, 65, 65 );
03158 
03159     glColor3ub( 75, 75, 75 );
03160 
03161     //glColor3ub( 150, 150, 150 );
03162     //glColor3ub( 255, 255, 255 );
03163     
03164     //glEnable( GL_COLOR_MATERIAL );
03165 
03166     /*
03167     GLfloat diffuseMaterial[4]  = { 0.5f, 0.5f, 0.5f, 1.0f };
03168     GLfloat specularMaterial[4] = { 0.8f, 0.8f, 0.8f, 1.0f };
03169     GLfloat ambientMaterial[4]  = { 0.1f, 0.1f, 0.1f, 1.0f };
03170     GLfloat shininessMaterial[] = { 128.0 };
03171     glMaterialfv( GL_FRONT, GL_AMBIENT,  ambientMaterial );
03172     glMaterialfv( GL_FRONT, GL_SPECULAR, specularMaterial );
03173     glMaterialfv( GL_FRONT, GL_DIFFUSE,  diffuseMaterial );
03174     glMaterialfv( GL_FRONT, GL_SHININESS,  diffuseMaterial );
03175     //*/
03176 
03177     glEnable( GL_LIGHTING );
03178     //glDisable( GL_LIGHTING );
03179 
03180     // DEBUG for two-sided lighting
03181     glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
03182 
03183     //---------------------------------------------------------------
03184     // Texture Parameter Setup
03185 
03186     /*
03187     // 3D Texture for surface
03188     glEnable( GL_TEXTURE_3D );
03189     glBindTexture( GL_TEXTURE_3D, m_3DTexture );
03190     //*/
03191 
03192     // Composition
03193     glEnable( GL_BLEND );
03194     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
03195     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
03196     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );
03197     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
03198     //glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE, 0.5 );
03199     //glTexEnvf( GL_TEXTURE_ENV, GL_ALPHA_SCALE, 0.5 );
03200     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );
03201 
03202     /*
03203     static GLfloat constColor[4] = { 0.0, 0.0, 0.0, 0.0 };
03204     constColor[3] = 0.2;
03205     glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor );
03206     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
03207     glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
03208     glTexEnvf( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE );
03209     glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
03210     glTexEnvf( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS );
03211     glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
03212     glTexEnvf( GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS );
03213     glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA );
03214     //*/
03215 
03216     //---------------------------------------------------------------
03217     int iOffsetSlice = gridResolution[1] * gridResolution[0] * 4;
03218     int iOffsetRow = gridResolution[0] * 4;
03219     int iOffsetCol = 4;
03220     //---------------------------------
03221     // Vertex & Edge Index
03222     //          3------2------2
03223     //         /|            /|
03224     //       11 |          10 |
03225     //       /  3          /  1
03226     //      7------6------6   |
03227     //      |   |         |   |
03228     //      |   0------0--|---1
03229     //      7  /          5  /
03230     //      | 8           | 9 
03231     //      |/            |/
03232     //      4------4------5
03233     //---------------------------------
03234     // Edge Table [256] & Triangle Table [256][16]
03242     // V = V1 + (isovalue - s1) (V2 - V1) / (s2 - s1)
03243     //---------------------------------
03244     //unsigned char cubeClass = 0;
03245     //if ( grid.val[0] < isolevel ) cubeClass |= 1;
03246     //if ( grid.val[1] < isolevel ) cubeClass |= 2;
03247     //if ( grid.val[2] < isolevel ) cubeClass |= 4;
03248     //if ( grid.val[3] < isolevel ) cubeClass |= 8;
03249     //if ( grid.val[4] < isolevel ) cubeClass |= 16;
03250     //if ( grid.val[5] < isolevel ) cubeClass |= 32;
03251     //if ( grid.val[6] < isolevel ) cubeClass |= 64;
03252     //if ( grid.val[7] < isolevel ) cubeClass |= 128;
03253     //---------------------------------
03254     int numOfTrisPerCell = 0;   // number of triangles in the cell
03255     int triIndices[15];         // at most 5 triangles
03256     Vector3<T>  V[8];           // vertices of the cell
03257     Vector3<T>  VTC[8];         // texture coordinates of the vertices
03258     Vector3<T>  texCoordList[12];   // since 12 edges
03259     Vector3<T>  vertexList[12]; // since 12 edges
03260     int         bV[12];         // >=0 if the vertex is counted (e.g. on boundary, existing, etc.)
03261     Vector3<T>  grad[12];       // gradients of vertices
03262     //Vector3<T> texCoords[12]; // 
03263     Vector3<T> Center, nE, nW, nN, nS, nF, nB;  // center and its neighbors for gradient computation
03264     //---------------------------------
03265     int idx[8], d, i;
03266     unsigned char cubeClass = 0;
03267     T threshold = 250;
03268     //
03269     T tc[3];
03270     T tcStep[3] = {
03271         1.0 / static_cast<T>( gridResolution[0]-1 ), 
03272         1.0 / static_cast<T>( gridResolution[1]-1 ), 
03273         1.0 / static_cast<T>( gridResolution[2]-1 ) 
03274     };
03275     //
03276 
03277     //-----------------------------------------------------
03278     // For Interpolation Data used by Marching Cube
03279     int iOffsetSliceIntp = gridResolution[1] * gridResolution[0] * 3;
03280     int iOffsetRowIntp = gridResolution[0] * 3;
03281     int iOffsetColIntp = 3;
03282     int intpIdx[8];
03283     Vector3<T> VIntp[8];    // Interpolation Data (XYZ)
03284     //-----------------------------------------------------
03285 
03286     //---------------------------------
03287     //for ( int Z = gridResolution[2]*3/4; Z < gridResolution[2]-1; ++Z ) {
03288     for ( int Z = 0; Z < gridResolution[2]-1; ++Z ) {
03289         //
03290         // For Interpolation Data
03291         int offsetZIntp = Z * iOffsetSliceIntp;
03292         //
03293         int offsetZ = Z * iOffsetSlice;
03294         //
03295         // Texture Coordinates -- Z
03296         tc[2] = static_cast<T>( Z ) / static_cast<T>( gridResolution[2]-1 );
03297         VTC[0].SetZ( tc[2] );
03298         VTC[1].SetZ( tc[2] );
03299         VTC[2].SetZ( tc[2] );
03300         VTC[3].SetZ( tc[2] );
03301         tc[2] += tcStep[2];
03302         VTC[4].SetZ( tc[2] );
03303         VTC[5].SetZ( tc[2] );
03304         VTC[6].SetZ( tc[2] );
03305         VTC[7].SetZ( tc[2] );
03306         //
03307         //for ( int Y = gridResolution[1]; Y < gridResolution[1]-1; ++Y ) {
03308         for ( int Y = 0; Y < gridResolution[1]-1; ++Y ) {
03309             //
03310             // Set Indices for Interpolation Data
03311             int offsetYZIntp = Y * iOffsetRowIntp + offsetZIntp;
03312             intpIdx[0] = offsetYZIntp;;
03313             intpIdx[1] = intpIdx[0] + iOffsetColIntp;
03314             intpIdx[2] = intpIdx[1] + iOffsetRowIntp;
03315             intpIdx[3] = intpIdx[0] + iOffsetRowIntp;
03316             intpIdx[4] = intpIdx[0] + iOffsetSliceIntp;
03317             intpIdx[5] = intpIdx[4] + iOffsetColIntp;
03318             intpIdx[6] = intpIdx[5] + iOffsetRowIntp;
03319             intpIdx[7] = intpIdx[4] + iOffsetRowIntp;
03320             //
03321             // Set Indices for Cube Vertices
03322             int offsetYZ = Y * iOffsetRow + offsetZ;
03323             idx[0] = offsetYZ;
03324             idx[1] = idx[0] + iOffsetCol;
03325             idx[2] = idx[1] + iOffsetRow;
03326             idx[3] = idx[0] + iOffsetRow;
03327             idx[4] = idx[0] + iOffsetSlice;
03328             idx[5] = idx[4] + iOffsetCol;
03329             idx[6] = idx[5] + iOffsetRow;
03330             idx[7] = idx[4] + iOffsetRow;
03331             //
03332             // Texture Coordinates -- Y
03333             tc[1] = static_cast<T>( Y ) / static_cast<T>( gridResolution[1]-1 );
03334             VTC[0].SetY( tc[1] );
03335             VTC[1].SetY( tc[1] );
03336             VTC[4].SetY( tc[1] );
03337             VTC[5].SetY( tc[1] );
03338             tc[1] += tcStep[1];
03339             VTC[2].SetY( tc[1] );
03340             VTC[3].SetY( tc[1] );
03341             VTC[6].SetY( tc[1] );
03342             VTC[7].SetY( tc[1] );
03343             //
03344             for ( int X = 0; X < gridResolution[0]-1; ++X ) {
03345                 //
03346                 // Texture Coordinates -- X
03347                 tc[0] = static_cast<T>( X ) / static_cast<T>( gridResolution[0]-1 );
03348                 VTC[0].SetX( tc[0] );
03349                 VTC[3].SetX( tc[0] );
03350                 VTC[4].SetX( tc[0] );
03351                 VTC[7].SetX( tc[0] );
03352                 tc[0] += tcStep[0];
03353                 VTC[1].SetX( tc[0] );
03354                 VTC[2].SetX( tc[0] );
03355                 VTC[5].SetX( tc[0] );
03356                 VTC[6].SetX( tc[0] );
03357                 //
03358 
03359 
03360                 bool bLeftPresent  = false;
03361                 bool bRightPresent = false;
03362                 {
03363                     for ( int i = 0; i < 8; ++i ) {
03364                         int flagVal = static_cast<int>( dataForPosition[idx[i] + 3] );
03365                         if ( flagVal > threshold ) {
03366                             flagVal %= int( m_SimDomain->IC_Thresholds::FLAG_STEP );
03367                             if      ( 1 < flagVal && flagVal < m_SimDomain->IC_Thresholds::MC_LEFT_ADD+1 ) {
03368                                 bLeftPresent = true;
03369                             }
03370                             else if ( flagVal > m_SimDomain->IC_Thresholds::MC_LEFT_ADD+1 ) {
03371                                 bRightPresent = true;
03372                             }
03373                         }
03374                     }
03375                 }
03376 
03377                 // STANDARD CUBE CONFIGURATION
03378                 //-------------------------------
03379                 // Determine the threshold of each vertex of the cube
03380                 cubeClass = 0;
03381                 if ( dataForPosition[idx[0] + 3] > threshold )  cubeClass |= 1;
03382                 if ( dataForPosition[idx[1] + 3] > threshold )  cubeClass |= 2;
03383                 if ( dataForPosition[idx[2] + 3] > threshold )  cubeClass |= 4;
03384                 if ( dataForPosition[idx[3] + 3] > threshold )  cubeClass |= 8;
03385                 if ( dataForPosition[idx[4] + 3] > threshold )  cubeClass |= 16;
03386                 if ( dataForPosition[idx[5] + 3] > threshold )  cubeClass |= 32;
03387                 if ( dataForPosition[idx[6] + 3] > threshold )  cubeClass |= 64;
03388                 if ( dataForPosition[idx[7] + 3] > threshold )  cubeClass |= 128;
03389                 //-------------------------------
03390 
03391 
03392                 // ONE ITERATION FOR EACH CUBE
03393                 {
03394                     //-------------------------------
03395                     // Cell is entirely in/out of the surface
03396                     if ( EdgeTable[cubeClass] == 0 ) {
03397                         numOfTrisPerCell = 0;
03398                     }
03399                     else {
03400                     //-------------------------------
03401                     // Cell contains part of the surface
03402                         //-----------------
03403                         for ( i = 0; i < 8; ++i ) {
03404                             V[i].SetXYZ( 
03405                                 dataForPosition[idx[i]    ], 
03406                                 dataForPosition[idx[i] + 1], 
03407                                 dataForPosition[idx[i] + 2] 
03408                             );
03409                         }
03410                         //-----------------
03411                         // Reset list of existing vertices
03412                         for ( i = 0; i < 12; ++i ) {
03413                             bV[i] = -1;
03414                         }
03415 
03416                         //-----------------
03417                         // Interpolation Data
03418                         for ( i = 0; i < 8; ++i ) {
03419                             VIntp[i].SetXYZ( 
03420                                 dataForEllipsoidInfluence[intpIdx[i]    ], 
03421                                 dataForEllipsoidInfluence[intpIdx[i] + 1], 
03422                                 dataForEllipsoidInfluence[intpIdx[i] + 2] 
03423                             );
03424                         }
03425 
03426                         //===============================================
03427                         // Calculate Gradients
03428                         //-----------------------------------------------
03429                         Vector3<T> G[8];
03430                         int index;
03431                         for ( int vID = 0; vID < 8; ++vID ) {
03432                             Center.SetXYZ(  dataForPosition[idx[vID]  ], 
03433                                             dataForPosition[idx[vID]+1], 
03434                                             dataForPosition[idx[vID]+2] );
03435                             G[vID].SetXYZ( 0, 0, 0 );
03436 
03437                             //*
03438                             //=================================
03439                             // START: 6 Face Gradients
03440                             //---------------------------------
03441                             if ( GetGradientComputationByFacesStatus() ) {
03442                             //--- East --------------
03443                             if ( X < gridResolution[0]-2 ) {
03444                                 index = idx[vID] + iOffsetCol;
03445                                 if ( dataForPosition[index+3] > threshold ) {
03446                                     nE.SetXYZ( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03447                                     G[vID] += Center - nE;
03448                                 }
03449                             }
03450                             //--- West --------------
03451                             if ( X > 0 ) {
03452                                 index = idx[vID] - iOffsetCol;
03453                                 if ( dataForPosition[index+3] > threshold ) {
03454                                     nW.SetXYZ( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03455                                     G[vID] += Center - nW;
03456                                 }
03457                             }
03458                             //--- North -------------
03459                             if ( Y < gridResolution[1]-2 ) {
03460                                 index = idx[vID] + iOffsetRow;
03461                                 if ( dataForPosition[index+3] > threshold ) {
03462                                     nN.SetXYZ( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03463                                     G[vID] += Center - nN;
03464                                 }
03465                             }
03466                             //--- South -------------
03467                             if ( Y > 0 ) {
03468                                 index = idx[vID] - iOffsetRow;
03469                                 if ( dataForPosition[index+3] > threshold ) {
03470                                     nS.SetXYZ( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03471                                     G[vID] += Center - nS;
03472                                 }
03473                             }
03474                             //--- Front -------------
03475                             if ( Z < gridResolution[2]-2 ) {
03476                                 index = idx[vID] + iOffsetSlice;
03477                                 if ( dataForPosition[index+3] > threshold ) {
03478                                     nF.SetXYZ( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03479                                     G[vID] += Center - nF;
03480                                 }
03481                             }
03482                             //--- Back --------------
03483                             if ( Z > 0 ) {
03484                                 index = idx[vID] - iOffsetSlice;
03485                                 if ( dataForPosition[index+3] > threshold ) {
03486                                     nB.SetXYZ( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03487                                     G[vID] += Center - nB;
03488                                 }
03489                             }
03490                             //-----------------------
03491                             } // END: if ( GetGradientComputationByFacesStatus() ) {
03492                             //---------------------------------
03493                             // END: 6 Face Gradients
03494                             //=================================
03495                             //*/
03496 
03497                             //*
03498                             //=================================
03499                             // START: 8 Vertex Gradients
03500                             //---------------------------------
03501                             if ( GetGradientComputationByVerticesStatus() ) {
03502                             //--- Front -------------
03503                             if ( Z < gridResolution[2]-2 ) {
03504                                 int idxF = idx[vID] + iOffsetSlice;
03505                                 //-- North -----
03506                                 if ( Y < gridResolution[1]-2 ) {
03507                                     int idxFN = idxF + iOffsetRow;
03508                                     //- West
03509                                     if ( X > 0 ) {
03510                                         index = idxFN - iOffsetCol;
03511                                         if ( dataForPosition[index+3] > threshold ) {
03512                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03513                                             G[vID] += Center - vGrad;
03514                                         }
03515                                     }
03516                                     //- East
03517                                     if ( X < gridResolution[0]-2 ) {
03518                                         index = idxFN + iOffsetCol;
03519                                         if ( dataForPosition[index+3] > threshold ) {
03520                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03521                                             G[vID] += Center - vGrad;
03522                                         }
03523                                     }
03524                                 }
03525                                 //-- South -----
03526                                 if ( Y > 0 ) {
03527                                     int idxFS = idxF - iOffsetRow;
03528                                     //- West
03529                                     if ( X > 0 ) {
03530                                         index = idxFS - iOffsetCol;
03531                                         if ( dataForPosition[index+3] > threshold ) {
03532                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03533                                             G[vID] += Center - vGrad;
03534                                         }
03535                                     }
03536                                     //- East
03537                                     if ( X < gridResolution[0]-2 ) {
03538                                         index = idxFS + iOffsetCol;
03539                                         if ( dataForPosition[index+3] > threshold ) {
03540                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03541                                             G[vID] += Center - vGrad;
03542                                         }
03543                                     }
03544                                 }
03545                             }
03546                             //--- Back --------------
03547                             if ( Z > 0 ) {
03548                                 int idxF = idx[vID] - iOffsetSlice;
03549                                 //-- North -----
03550                                 if ( Y < gridResolution[1]-2 ) {
03551                                     int idxFN = idxF + iOffsetRow;
03552                                     //- West
03553                                     if ( X > 0 ) {
03554                                         index = idxFN - iOffsetCol;
03555                                         if ( dataForPosition[index+3] > threshold ) {
03556                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03557                                             G[vID] += Center - vGrad;
03558                                         }
03559                                     }
03560                                     //- East
03561                                     if ( X < gridResolution[0]-2 ) {
03562                                         index = idxFN + iOffsetCol;
03563                                         if ( dataForPosition[index+3] > threshold ) {
03564                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03565                                             G[vID] += Center - vGrad;
03566                                         }
03567                                     }
03568                                 }
03569                                 //-- South -----
03570                                 if ( Y > 0 ) {
03571                                     int idxFS = idxF - iOffsetRow;
03572                                     //- West
03573                                     if ( X > 0 ) {
03574                                         index = idxFS - iOffsetCol;
03575                                         if ( dataForPosition[index+3] > threshold ) {
03576                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03577                                             G[vID] += Center - vGrad;
03578                                         }
03579                                     }
03580                                     //- East
03581                                     if ( X < gridResolution[0]-2 ) {
03582                                         index = idxFS + iOffsetCol;
03583                                         if ( dataForPosition[index+3] > threshold ) {
03584                                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03585                                             G[vID] += Center - vGrad;
03586                                         }
03587                                     }
03588                                 }
03589                             }
03590                             //-----------------------
03591                             } // END: if ( GetGradientComputationByVerticesStatus() ) {
03592                             //---------------------------------
03593                             // END: 8 Vertex Gradients
03594                             //=================================
03595                             //*/
03596 
03597                             //*
03598                             //=================================
03599                             // START: 12 Edge Gradients
03600                             //---------------------------------
03601                             if ( GetGradientComputationByEdgesStatus() ) {
03602                             //--- Front -------------
03603                             if ( Z < gridResolution[2]-2 ) {
03604                                 int idxF = idx[vID] + iOffsetSlice;
03605                                 //-- East ------
03606                                 if ( X < gridResolution[0]-2 ) {
03607                                     index = idxF + iOffsetCol;
03608                                     if ( dataForPosition[index+3] > threshold ) {
03609                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03610                                         G[vID] += Center - vGrad;
03611                                     }
03612                                 }
03613                                 //-- West ------
03614                                 if ( X > 0 ) {
03615                                     index = idxF - iOffsetCol;
03616                                     if ( dataForPosition[index+3] > threshold ) {
03617                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03618                                         G[vID] += Center - vGrad;
03619                                     }
03620                                 }
03621                                 //-- North -----
03622                                 if ( Y < gridResolution[1]-2 ) {
03623                                     index = idxF + iOffsetRow;
03624                                     if ( dataForPosition[index+3] > threshold ) {
03625                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03626                                         G[vID] += Center - vGrad;
03627                                     }
03628                                 }
03629                                 //-- South -----
03630                                 if ( Y > 0 ) {
03631                                     index = idxF - iOffsetRow;
03632                                     if ( dataForPosition[index+3] > threshold ) {
03633                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03634                                         G[vID] += Center - vGrad;
03635                                     }
03636                                 }
03637                             }
03638                             //--- Center ------------
03639                             if ( true ) {
03640                                 int idxC = idx[vID];
03641                                 //-- East ------
03642                                 if ( X < gridResolution[0]-2 ) {
03643                                     index = idxC + iOffsetCol;
03644                                     if ( dataForPosition[index+3] > threshold ) {
03645                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03646                                         G[vID] += Center - vGrad;
03647                                     }
03648                                 }
03649                                 //-- West ------
03650                                 if ( X > 0 ) {
03651                                     index = idxC - iOffsetCol;
03652                                     if ( dataForPosition[index+3] > threshold ) {
03653                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03654                                         G[vID] += Center - vGrad;
03655                                     }
03656                                 }
03657                                 //-- North -----
03658                                 if ( Y < gridResolution[1]-2 ) {
03659                                     index = idxC + iOffsetRow;
03660                                     if ( dataForPosition[index+3] > threshold ) {
03661                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03662                                         G[vID] += Center - vGrad;
03663                                     }
03664                                 }
03665                                 //-- South -----
03666                                 if ( Y > 0 ) {
03667                                     index = idxC - iOffsetRow;
03668                                     if ( dataForPosition[index+3] > threshold ) {
03669                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03670                                         G[vID] += Center - vGrad;
03671                                     }
03672                                 }
03673                             }
03674                             //--- Back --------------
03675                             if ( Z > 0 ) {
03676                                 int idxB = idx[vID] - iOffsetSlice;
03677                                 //-- East ------
03678                                 if ( X < gridResolution[0]-2 ) {
03679                                     index = idxB + iOffsetCol;
03680                                     if ( dataForPosition[index+3] > threshold ) {
03681                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03682                                         G[vID] += Center - vGrad;
03683                                     }
03684                                 }
03685                                 //-- West ------
03686                                 if ( X > 0 ) {
03687                                     index = idxB - iOffsetCol;
03688                                     if ( dataForPosition[index+3] > threshold ) {
03689                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03690                                         G[vID] += Center - vGrad;
03691                                     }
03692                                 }
03693                                 //-- North -----
03694                                 if ( Y < gridResolution[1]-2 ) {
03695                                     index = idxB + iOffsetRow;
03696                                     if ( dataForPosition[index+3] > threshold ) {
03697                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03698                                         G[vID] += Center - vGrad;
03699                                     }
03700                                 }
03701                                 //-- South -----
03702                                 if ( Y > 0 ) {
03703                                     index = idxB - iOffsetRow;
03704                                     if ( dataForPosition[index+3] > threshold ) {
03705                                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
03706                                         G[vID] += Center - vGrad;
03707                                     }
03708                                 }
03709                             }
03710                             //-----------------------
03711                             } // END: if ( GetGradientComputationByEdgesStatus() ) {
03712                             //---------------------------------
03713                             // END: 12 Edge Gradients
03714                             //=================================
03715                             //*/
03716                         }
03717                         //-----------------------------------------------
03718                         // END: Calculate Gradients
03719                         //===============================================
03720 
03721 
03722                         //===============================================
03723                         // Marching Cube Interpolation
03724                         // V = V1 + (isovalue - s1) (V2 - V1) / (s2 - s1)
03725                         //-----------------------------------------------
03726                         // RUNTIME ERROR CAN OCCURS -- DEPENDING ON THE DATA
03727                         // SINCE IT DOES NOT HAVE BOUNDARY PROTECTION -- ARRAY INDEX OUT OF BOUND ERROR
03728                         //-----------------------------------------------
03729                         // Not Use Global Interpolation Value -- each element has its own xyz interpolation values
03730                         if ( !m_bUseGlobalInterpolationVal ) {
03731                             //-------------------------------------
03732                             // Marching Cube Interpolation
03733                             T interpolationValPlus;// = m_tGlobalInterpolationVal;
03734                             T interpolationValNeg;//  = 1.0 - m_tGlobalInterpolationVal;
03735                             //-------------------------------------
03736                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
03737                             if ( EdgeTable[cubeClass] & 1 ) {
03738                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
03739                                     //
03740                                     // Interpotation Data
03741                                     interpolationValPlus = VIntp[0].GetX();
03742                                     //
03743                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]);
03744                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]);
03745                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]);
03746                                 }
03747                                 else {
03748                                     //
03749                                     // Interpotation Data
03750                                     interpolationValNeg = 1.0 - VIntp[1].GetX();
03751                                     //
03752                                     vertexList[ 0] = V[0] + interpolationValNeg*(V[1] - V[0]);
03753                                     grad[0]        = G[0] + interpolationValNeg*(G[1] - G[0]);
03754                                     texCoordList[0] = VTC[0] + interpolationValNeg*(VTC[1] - VTC[0]);
03755                                     //grad[0] *= -1.0;
03756                                 }
03757                                 grad[0].Normalized();
03758                             }
03759                             if ( EdgeTable[cubeClass] & 2 ) {
03760                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
03761                                     //
03762                                     // Interpotation Data
03763                                     interpolationValPlus = VIntp[1].GetY();
03764                                     //
03765                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]);
03766                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]);
03767                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]);
03768                                 }
03769                                 else {
03770                                     //
03771                                     // Interpotation Data
03772                                     interpolationValNeg = 1.0 - VIntp[2].GetY();
03773                                     //
03774                                     vertexList[ 1] = V[1] + interpolationValNeg*(V[2] - V[1]);
03775                                     grad[1]        = G[1] + interpolationValNeg*(G[2] - G[1]);
03776                                     texCoordList[1] = VTC[1] + interpolationValNeg*(VTC[2] - VTC[1]);
03777                                     //grad[1] *= -1.0;
03778                                 }
03779                                 grad[1].Normalized();
03780                             }
03781                             if ( EdgeTable[cubeClass] & 4 ) {
03782                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
03783                                     //
03784                                     // Interpotation Data
03785                                     interpolationValPlus = VIntp[2].GetX();
03786                                     //
03787                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]);
03788                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]);
03789                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]);
03790                                     //grad[2] *= -1.0;
03791                                 }
03792                                 else {
03793                                     //
03794                                     // Interpotation Data
03795                                     interpolationValNeg = 1.0 - VIntp[3].GetX();
03796                                     //
03797                                     vertexList[ 2] = V[2] + interpolationValNeg*(V[3] - V[2]);
03798                                     grad[2]        = G[2] + interpolationValNeg*(G[3] - G[2]);
03799                                     texCoordList[2] = VTC[2] + interpolationValNeg*(VTC[3] - VTC[2]);
03800                                 }
03801                                 grad[2].Normalized();
03802                             }
03803                             if ( EdgeTable[cubeClass] & 8 ) {
03804                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
03805                                     //
03806                                     // Interpotation Data
03807                                     interpolationValPlus = VIntp[0].GetY();
03808                                     //
03809                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]);
03810                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]);
03811                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]);
03812                                     //grad[3][1] *= -1.0;
03813                                 }
03814                                 else {
03815                                     //
03816                                     // Interpotation Data
03817                                     interpolationValNeg = 1.0 - VIntp[3].GetY();
03818                                     //
03819                                     vertexList[ 3] = V[0] + interpolationValNeg*(V[3] - V[0]);
03820                                     grad[3]        = G[0] + interpolationValNeg*(G[3] - G[0]);
03821                                     texCoordList[3] = VTC[0] + interpolationValNeg*(VTC[3] - VTC[0]);
03822                                 }
03823                                 grad[3].Normalized();
03824                             }
03825                             if ( EdgeTable[cubeClass] & 16 ) {
03826                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
03827                                     //
03828                                     // Interpotation Data
03829                                     interpolationValPlus = VIntp[4].GetX();
03830                                     //
03831                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]);
03832                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]);
03833                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]);
03834                                 }
03835                                 else {
03836                                     //
03837                                     // Interpotation Data
03838                                     interpolationValNeg = 1.0 - VIntp[5].GetX();
03839                                     //
03840                                     vertexList[ 4] = V[4] + interpolationValNeg*(V[5] - V[4]);
03841                                     grad[4]        = G[4] + interpolationValNeg*(G[5] - G[4]);
03842                                     texCoordList[4] = VTC[4] + interpolationValNeg*(VTC[5] - VTC[4]);
03843                                     //grad[4] *= -1.0;
03844                                 }
03845                                 grad[4].Normalized();
03846                             }
03847                             if ( EdgeTable[cubeClass] & 32 ) {
03848                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
03849                                     //
03850                                     // Interpotation Data
03851                                     interpolationValPlus = VIntp[5].GetY();
03852                                     //
03853                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]);
03854                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]);
03855                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]);
03856                                 }
03857                                 else {
03858                                     //
03859                                     // Interpotation Data
03860                                     interpolationValNeg = 1.0 - VIntp[6].GetY();
03861                                     //
03862                                     vertexList[ 5] = V[5] + interpolationValNeg*(V[6] - V[5]);
03863                                     grad[5]        = G[5] + interpolationValNeg*(G[6] - G[5]);
03864                                     texCoordList[5] = VTC[5] + interpolationValNeg*(VTC[6] - VTC[5]);
03865                                     //grad[5][1] *= -1.0;
03866                                 }
03867                                 grad[5].Normalized();
03868                             }
03869                             if ( EdgeTable[cubeClass] & 64 ) {
03870                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
03871                                     //
03872                                     // Interpotation Data
03873                                     interpolationValPlus = VIntp[6].GetX();
03874                                     //
03875                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]);
03876                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]);
03877                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]);
03878                                 }
03879                                 else {
03880                                     //
03881                                     // Interpotation Data
03882                                     interpolationValNeg = 1.0 - VIntp[7].GetX();
03883                                     //
03884                                     vertexList[ 6] = V[6] + interpolationValNeg*(V[7] - V[6]);
03885                                     grad[6]        = G[6] + interpolationValNeg*(G[7] - G[6]);
03886                                     texCoordList[6] = VTC[6] + interpolationValNeg*(VTC[7] - VTC[6]);
03887                                     //grad[6] *= -1.0;
03888                                 }
03889                                 grad[6].Normalized();
03890                             }
03891                             if ( EdgeTable[cubeClass] & 128 ) {
03892                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
03893                                     //
03894                                     // Interpotation Data
03895                                     interpolationValPlus = VIntp[4].GetY();
03896                                     //
03897                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]);
03898                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]);
03899                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]);
03900                                     //grad[7][1] *= -1.0;
03901                                 }
03902                                 else {
03903                                     //
03904                                     // Interpotation Data
03905                                     interpolationValNeg = 1.0 - VIntp[7].GetY();
03906                                     //
03907                                     vertexList[ 7] = V[4] + interpolationValNeg*(V[7] - V[4]);
03908                                     grad[7]        = G[4] + interpolationValNeg*(G[7] - G[4]);
03909                                     texCoordList[7] = VTC[4] + interpolationValNeg*(VTC[7] - VTC[4]);
03910                                 }
03911                                 grad[7].Normalized();
03912                             }
03913                             if ( EdgeTable[cubeClass] & 256 ) {
03914                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
03915                                     //
03916                                     // Interpotation Data
03917                                     interpolationValPlus = VIntp[0].GetZ();
03918                                     //
03919                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]);
03920                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]);
03921                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]);
03922                                 }
03923                                 else {
03924                                     //
03925                                     // Interpotation Data
03926                                     interpolationValNeg = 1.0 - VIntp[4].GetZ();
03927                                     //
03928                                     vertexList[ 8] = V[0] + interpolationValNeg*(V[4] - V[0]);
03929                                     grad[8]        = G[0] + interpolationValNeg*(G[4] - G[0]);
03930                                     texCoordList[8] = VTC[0] + interpolationValNeg*(VTC[4] - VTC[0]);
03931                                     //grad[8][2] *= -1.0;
03932                                 }
03933                                 grad[8].Normalized();
03934                             }
03935                             if ( EdgeTable[cubeClass] & 512 ) {
03936                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
03937                                     //
03938                                     // Interpotation Data
03939                                     interpolationValPlus = VIntp[1].GetZ();
03940                                     //
03941                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]);
03942                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]);
03943                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]);
03944                                 }
03945                                 else {
03946                                     //
03947                                     // Interpotation Data
03948                                     interpolationValNeg = 1.0 - VIntp[5].GetZ();
03949                                     //
03950                                     vertexList[ 9] = V[1] + interpolationValNeg*(V[5] - V[1]);
03951                                     grad[9]        = G[1] + interpolationValNeg*(G[5] - G[1]);
03952                                     texCoordList[9] = VTC[1] + interpolationValNeg*(VTC[5] - VTC[1]);
03953                                     //grad[9][2] *= -1.0;
03954                                 }
03955                                 grad[9].Normalized();
03956                             }
03957                             if ( EdgeTable[cubeClass] & 1024 ) {
03958                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
03959                                     //
03960                                     // Interpotation Data
03961                                     interpolationValPlus = VIntp[2].GetZ();
03962                                     //
03963                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]);
03964                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]);
03965                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]);
03966                                 }
03967                                 else {
03968                                     //
03969                                     // Interpotation Data
03970                                     interpolationValNeg = 1.0 - VIntp[6].GetZ();
03971                                     //
03972                                     vertexList[10] = V[2] + interpolationValNeg*(V[6] - V[2]);
03973                                     grad[10]       = G[2] + interpolationValNeg*(G[6] - G[2]);
03974                                     texCoordList[10] = VTC[2] + interpolationValNeg*(VTC[6] - VTC[2]);
03975                                     //grad[10][2] *= -1.0;
03976                                 }
03977                                 grad[10].Normalized();
03978                             }
03979                             if ( EdgeTable[cubeClass] & 2048 ) {
03980                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
03981                                     //
03982                                     // Interpotation Data
03983                                     interpolationValPlus = VIntp[3].GetZ();
03984                                     //
03985                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]);
03986                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]);
03987                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]);
03988                                 }
03989                                 else {
03990                                     //
03991                                     // Interpotation Data
03992                                     interpolationValNeg = 1.0 - VIntp[7].GetZ();
03993                                     //
03994                                     vertexList[11] = V[3] + interpolationValNeg*(V[7] - V[3]);
03995                                     grad[11]       = G[3] + interpolationValNeg*(G[7] - G[3]);
03996                                     texCoordList[11] = VTC[3] + interpolationValNeg*(VTC[7] - VTC[3]);
03997                                     //grad[11][2] *= -1.0;
03998                                 }
03999                                 grad[11].Normalized();
04000                             }
04001                         } // END: Not Use Global Interpolation Value
04002                         //-----------------------------------------------
04003                         // Use Global Interpolation Value -- all elements have the same interpolation value
04004                         else {
04005                             //-------------------------------------
04006                             // Marching Cube Interpolation
04007                             T interpolationValPlus = m_tGlobalInterpolationVal;
04008                             T interpolationValNeg  = 1.0 - m_tGlobalInterpolationVal;
04009                             //-------------------------------------
04010                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
04011                             if ( EdgeTable[cubeClass] & 1 ) {
04012                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
04013                                     //
04014                                     // Interpotation Data
04015                                     //interpolationValPlus = VIntp[0].GetX();
04016                                     //
04017                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]);
04018                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]);
04019                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]);
04020                                 }
04021                                 else {
04022                                     //
04023                                     // Interpotation Data
04024                                     //interpolationValNeg = 1.0 - VIntp[1].GetX();
04025                                     //
04026                                     vertexList[ 0] = V[0] + interpolationValNeg*(V[1] - V[0]);
04027                                     grad[0]        = G[0] + interpolationValNeg*(G[1] - G[0]);
04028                                     texCoordList[0] = VTC[0] + interpolationValNeg*(VTC[1] - VTC[0]);
04029                                     //grad[0] *= -1.0;
04030                                 }
04031                                 grad[0].Normalized();
04032                             }
04033                             if ( EdgeTable[cubeClass] & 2 ) {
04034                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
04035                                     //
04036                                     // Interpotation Data
04037                                     //interpolationValPlus = VIntp[1].GetY();
04038                                     //
04039                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]);
04040                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]);
04041                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]);
04042                                 }
04043                                 else {
04044                                     //
04045                                     // Interpotation Data
04046                                     //interpolationValNeg = 1.0 - VIntp[2].GetY();
04047                                     //
04048                                     vertexList[ 1] = V[1] + interpolationValNeg*(V[2] - V[1]);
04049                                     grad[1]        = G[1] + interpolationValNeg*(G[2] - G[1]);
04050                                     texCoordList[1] = VTC[1] + interpolationValNeg*(VTC[2] - VTC[1]);
04051                                     //grad[1] *= -1.0;
04052                                 }
04053                                 grad[1].Normalized();
04054                             }
04055                             if ( EdgeTable[cubeClass] & 4 ) {
04056                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
04057                                     //
04058                                     // Interpotation Data
04059                                     //interpolationValPlus = VIntp[2].GetX();
04060                                     //
04061                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]);
04062                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]);
04063                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]);
04064                                     //grad[2] *= -1.0;
04065                                 }
04066                                 else {
04067                                     //
04068                                     // Interpotation Data
04069                                     //interpolationValNeg = 1.0 - VIntp[3].GetX();
04070                                     //
04071                                     vertexList[ 2] = V[2] + interpolationValNeg*(V[3] - V[2]);
04072                                     grad[2]        = G[2] + interpolationValNeg*(G[3] - G[2]);
04073                                     texCoordList[2] = VTC[2] + interpolationValNeg*(VTC[3] - VTC[2]);
04074                                 }
04075                                 grad[2].Normalized();
04076                             }
04077                             if ( EdgeTable[cubeClass] & 8 ) {
04078                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
04079                                     //
04080                                     // Interpotation Data
04081                                     //interpolationValPlus = VIntp[0].GetY();
04082                                     //
04083                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]);
04084                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]);
04085                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]);
04086                                     //grad[3][1] *= -1.0;
04087                                 }
04088                                 else {
04089                                     //
04090                                     // Interpotation Data
04091                                     //interpolationValNeg = 1.0 - VIntp[3].GetY();
04092                                     //
04093                                     vertexList[ 3] = V[0] + interpolationValNeg*(V[3] - V[0]);
04094                                     grad[3]        = G[0] + interpolationValNeg*(G[3] - G[0]);
04095                                     texCoordList[3] = VTC[0] + interpolationValNeg*(VTC[3] - VTC[0]);
04096                                 }
04097                                 grad[3].Normalized();
04098                             }
04099                             if ( EdgeTable[cubeClass] & 16 ) {
04100                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
04101                                     //
04102                                     // Interpotation Data
04103                                     //interpolationValPlus = VIntp[4].GetX();
04104                                     //
04105                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]);
04106                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]);
04107                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]);
04108                                 }
04109                                 else {
04110                                     //
04111                                     // Interpotation Data
04112                                     //interpolationValNeg = 1.0 - VIntp[5].GetX();
04113                                     //
04114                                     vertexList[ 4] = V[4] + interpolationValNeg*(V[5] - V[4]);
04115                                     grad[4]        = G[4] + interpolationValNeg*(G[5] - G[4]);
04116                                     texCoordList[4] = VTC[4] + interpolationValNeg*(VTC[5] - VTC[4]);
04117                                     //grad[4] *= -1.0;
04118                                 }
04119                                 grad[4].Normalized();
04120                             }
04121                             if ( EdgeTable[cubeClass] & 32 ) {
04122                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
04123                                     //
04124                                     // Interpotation Data
04125                                     //interpolationValPlus = VIntp[5].GetY();
04126                                     //
04127                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]);
04128                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]);
04129                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]);
04130                                 }
04131                                 else {
04132                                     //
04133                                     // Interpotation Data
04134                                     //interpolationValNeg = 1.0 - VIntp[6].GetY();
04135                                     //
04136                                     vertexList[ 5] = V[5] + interpolationValNeg*(V[6] - V[5]);
04137                                     grad[5]        = G[5] + interpolationValNeg*(G[6] - G[5]);
04138                                     texCoordList[5] = VTC[5] + interpolationValNeg*(VTC[6] - VTC[5]);
04139                                     //grad[5][1] *= -1.0;
04140                                 }
04141                                 grad[5].Normalized();
04142                             }
04143                             if ( EdgeTable[cubeClass] & 64 ) {
04144                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
04145                                     //
04146                                     // Interpotation Data
04147                                     //interpolationValPlus = VIntp[6].GetX();
04148                                     //
04149                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]);
04150                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]);
04151                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]);
04152                                 }
04153                                 else {
04154                                     //
04155                                     // Interpotation Data
04156                                     //interpolationValNeg = 1.0 - VIntp[7].GetX();
04157                                     //
04158                                     vertexList[ 6] = V[6] + interpolationValNeg*(V[7] - V[6]);
04159                                     grad[6]        = G[6] + interpolationValNeg*(G[7] - G[6]);
04160                                     texCoordList[6] = VTC[6] + interpolationValNeg*(VTC[7] - VTC[6]);
04161                                     //grad[6] *= -1.0;
04162                                 }
04163                                 grad[6].Normalized();
04164                             }
04165                             if ( EdgeTable[cubeClass] & 128 ) {
04166                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
04167                                     //
04168                                     // Interpotation Data
04169                                     //interpolationValPlus = VIntp[4].GetY();
04170                                     //
04171                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]);
04172                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]);
04173                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]);
04174                                     //grad[7][1] *= -1.0;
04175                                 }
04176                                 else {
04177                                     //
04178                                     // Interpotation Data
04179                                     //interpolationValNeg = 1.0 - VIntp[7].GetY();
04180                                     //
04181                                     vertexList[ 7] = V[4] + interpolationValNeg*(V[7] - V[4]);
04182                                     grad[7]        = G[4] + interpolationValNeg*(G[7] - G[4]);
04183                                     texCoordList[7] = VTC[4] + interpolationValNeg*(VTC[7] - VTC[4]);
04184                                 }
04185                                 grad[7].Normalized();
04186                             }
04187                             if ( EdgeTable[cubeClass] & 256 ) {
04188                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
04189                                     //
04190                                     // Interpotation Data
04191                                     //interpolationValPlus = VIntp[0].GetZ();
04192                                     //
04193                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]);
04194                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]);
04195                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]);
04196                                 }
04197                                 else {
04198                                     //
04199                                     // Interpotation Data
04200                                     //interpolationValNeg = 1.0 - VIntp[4].GetZ();
04201                                     //
04202                                     vertexList[ 8] = V[0] + interpolationValNeg*(V[4] - V[0]);
04203                                     grad[8]        = G[0] + interpolationValNeg*(G[4] - G[0]);
04204                                     texCoordList[8] = VTC[0] + interpolationValNeg*(VTC[4] - VTC[0]);
04205                                     //grad[8][2] *= -1.0;
04206                                 }
04207                                 grad[8].Normalized();
04208                             }
04209                             if ( EdgeTable[cubeClass] & 512 ) {
04210                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
04211                                     //
04212                                     // Interpotation Data
04213                                     //interpolationValPlus = VIntp[1].GetZ();
04214                                     //
04215                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]);
04216                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]);
04217                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]);
04218                                 }
04219                                 else {
04220                                     //
04221                                     // Interpotation Data
04222                                     //interpolationValNeg = 1.0 - VIntp[5].GetZ();
04223                                     //
04224                                     vertexList[ 9] = V[1] + interpolationValNeg*(V[5] - V[1]);
04225                                     grad[9]        = G[1] + interpolationValNeg*(G[5] - G[1]);
04226                                     texCoordList[9] = VTC[1] + interpolationValNeg*(VTC[5] - VTC[1]);
04227                                     //grad[9][2] *= -1.0;
04228                                 }
04229                                 grad[9].Normalized();
04230                             }
04231                             if ( EdgeTable[cubeClass] & 1024 ) {
04232                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
04233                                     //
04234                                     // Interpotation Data
04235                                     //interpolationValPlus = VIntp[2].GetZ();
04236                                     //
04237                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]);
04238                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]);
04239                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]);
04240                                 }
04241                                 else {
04242                                     //
04243                                     // Interpotation Data
04244                                     //interpolationValNeg = 1.0 - VIntp[6].GetZ();
04245                                     //
04246                                     vertexList[10] = V[2] + interpolationValNeg*(V[6] - V[2]);
04247                                     grad[10]       = G[2] + interpolationValNeg*(G[6] - G[2]);
04248                                     texCoordList[10] = VTC[2] + interpolationValNeg*(VTC[6] - VTC[2]);
04249                                     //grad[10][2] *= -1.0;
04250                                 }
04251                                 grad[10].Normalized();
04252                             }
04253                             if ( EdgeTable[cubeClass] & 2048 ) {
04254                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
04255                                     //
04256                                     // Interpotation Data
04257                                     //interpolationValPlus = VIntp[3].GetZ();
04258                                     //
04259                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]);
04260                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]);
04261                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]);
04262                                 }
04263                                 else {
04264                                     //
04265                                     // Interpotation Data
04266                                     //interpolationValNeg = 1.0 - VIntp[7].GetZ();
04267                                     //
04268                                     vertexList[11] = V[3] + interpolationValNeg*(V[7] - V[3]);
04269                                     grad[11]       = G[3] + interpolationValNeg*(G[7] - G[3]);
04270                                     texCoordList[11] = VTC[3] + interpolationValNeg*(VTC[7] - VTC[3]);
04271                                     //grad[11][2] *= -1.0;
04272                                 }
04273                                 grad[11].Normalized();
04274                             }
04275                         } // END: Use Global Interpolation Value
04276                         //-----------------------------------------------
04277                         // END: if/else statement for MC Interpolation
04278                         //===============================================
04279 
04280                         //===============================================
04281                         //-----------------------------------------------
04282                         // Generate Triangle Index
04283                         numOfTrisPerCell = 0;
04284                         for ( d = 0; TriTable[cubeClass][d] != -1; ++d ) {
04285                             triIndices[d] = TriTable[cubeClass][d];
04286                         }
04287                         numOfTrisPerCell = d / 3;
04288                         //-----------------------------------------------
04289                         //===============================================
04290                     }
04291 
04292                     /*
04293                     //-------------------------------
04294                     // Draw (Gradient) Normals
04295                     {
04296                         glPushAttrib( GL_ALL_ATTRIB_BITS );
04297                         glBegin( GL_LINES );
04298                         glDisable( GL_TEXTURE_3D );
04299                         glDisable( GL_BLEND );
04300                         glDisable( GL_LIGHTING );
04301                         for ( int i = 0; i < numOfTrisPerCell*3; i+=3 ) {
04302                             glColor3f( 1, 0, 0 );
04303                             glVertex3fv( vertexList[triIndices[i+2]].GetDataFloat() );
04304                             glVertex3fv( ( vertexList[triIndices[i+2]] + grad[triIndices[i+2]]*0.15 ).GetDataFloat() );
04305                             glColor3f( 0, 1, 0 );
04306                             glVertex3fv( vertexList[triIndices[i+1]].GetDataFloat() );
04307                             glVertex3fv( ( vertexList[triIndices[i+1]] + grad[triIndices[i+1]]*0.15 ).GetDataFloat() );
04308                             glColor3f( 0, 0, 1 );
04309                             glVertex3fv( vertexList[triIndices[i+0]].GetDataFloat() );
04310                             glVertex3fv( ( vertexList[triIndices[i+0]] + grad[triIndices[i+0]]*0.15 ).GetDataFloat() );
04311                         }
04312                         glEnd();
04313                         glPopAttrib();
04314                     }
04315                     //-------------------------------
04316                     //*/
04317 
04318                     //-------------------------------
04319                     // Draw PN-Triangles generated 
04320                     // from Marching Cube Triangles
04321                     if ( m_bDrawPNTriangle ) {
04322                         int i = 0;
04323                         while ( numOfTrisPerCell > 0 ) {
04324                             PNTriangle<T>::DrawByOpenGL( 
04325                                 vertexList[triIndices[i+2]], 
04326                                 vertexList[triIndices[i+1]], 
04327                                 vertexList[triIndices[i+0]], 
04328                                 grad[triIndices[i+2]], 
04329                                 grad[triIndices[i+1]], 
04330                                 grad[triIndices[i+0]], 
04331                                 texCoordList[triIndices[i+2]], 
04332                                 texCoordList[triIndices[i+1]], 
04333                                 texCoordList[triIndices[i+0]], 
04334                                 m_PNTriangleSmoothness 
04335                             );
04336                             --numOfTrisPerCell;
04337                             i += 3;
04338                         }
04339                     }
04340                     // DEBUG for PNTri Drawing
04341                     //glUseProgramObjectARB( g_PNTriProg );
04342                     //
04343                     // DEBUG for PNTri Drawing
04344                     //glUseProgramObjectARB( NULL );
04345 
04346                     //-------------------------------
04347                     // Draw Marching Cube Triangles
04348                     else {
04349 
04350                         /*
04351                         //*************************************
04352                         // DEBUG
04353                         {
04354                             glPushAttrib( GL_ALL_ATTRIB_BITS );
04355                             glDisable( GL_LIGHTING );
04356                             glDisable( GL_BLEND );
04357                             glDisable( GL_TEXTURE_3D );
04358                             glColor3ub( 200, 50, 100 );
04359                             //glColor3f( 0.0, 0.0, 1.0 );
04360                             glBegin( GL_POINTS );
04361                             int count = numOfTrisPerCell;
04362                             int i = 0;
04363                             while ( count > 0 ) {
04364                                 //glTexCoord3fv( texCoordList[triIndices[i+2]].GetDataFloat() );
04365                                 glColor3f( 1, 0, 0 );
04366                                 glNormal3fv( grad[triIndices[i+2]].GetDataFloat() );
04367                                 glVertex3fv( vertexList[triIndices[i+2]].GetDataFloat() );
04368                                 //
04369                                 //glTexCoord3fv( texCoordList[triIndices[i+1]].GetDataFloat() );
04370                                 glColor3f( 0, 1, 0 );
04371                                 glNormal3fv( grad[triIndices[i+1]].GetDataFloat() );
04372                                 glVertex3fv( vertexList[triIndices[i+1]].GetDataFloat() );
04373                                 //
04374                                 //glTexCoord3fv( texCoordList[triIndices[i+0]].GetDataFloat() );
04375                                 glColor3f( 0, 0, 1 );
04376                                 glNormal3fv( grad[triIndices[i+0]].GetDataFloat() );
04377                                 glVertex3fv( vertexList[triIndices[i+0]].GetDataFloat() );
04378                                 //
04379                                 --count;
04380                                 i += 3;
04381                             }
04382                             glEnd();
04383                             glPopAttrib();
04384                         }
04385                         //*************************************
04386                         //*/
04387 
04388                         //glBegin( GL_LINE_LOOP );
04389                         glBegin( GL_TRIANGLES );
04390                         int i = 0;
04391                         while ( numOfTrisPerCell > 0 ) {
04392                             glTexCoord3fv( texCoordList[triIndices[i+2]].GetDataFloat() );
04393                             glNormal3fv( grad[triIndices[i+2]].GetDataFloat() );
04394                             glVertex3fv( vertexList[triIndices[i+2]].GetDataFloat() );
04395                             //
04396                             glTexCoord3fv( texCoordList[triIndices[i+1]].GetDataFloat() );
04397                             glNormal3fv( grad[triIndices[i+1]].GetDataFloat() );
04398                             glVertex3fv( vertexList[triIndices[i+1]].GetDataFloat() );
04399                             //
04400                             glTexCoord3fv( texCoordList[triIndices[i+0]].GetDataFloat() );
04401                             glNormal3fv( grad[triIndices[i+0]].GetDataFloat() );
04402                             glVertex3fv( vertexList[triIndices[i+0]].GetDataFloat() );
04403                             //
04404                             --numOfTrisPerCell;
04405                             i += 3;
04406                         }
04407                         glEnd();
04408                     }
04409 
04410                     //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04412                     //if ( isFirstRun ) {
04413                     //  if ( cubeClass < 100 )  std::cout << " ";
04414                     //  if ( cubeClass < 10 )   std::cout << " ";
04415                     //  std::cout << "  " << static_cast<int>( cubeClass );
04416                     //}
04417                     //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04418 
04419                 } // END: // TWO ITERATIONS FOR LEFT AND RIGHT CUBE CONFIGURATIONS
04420 
04421                 //-------------------------------
04422                 // Next Cell
04423                 for ( i = 0; i < 8; ++i ) {
04424                     idx[i] += 4;
04425                     //
04426                     intpIdx[i] += 3;
04427                 }
04428                 //-------------------------------
04429 
04430             } // END: for loop for X
04431 
04432             //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04434             //if ( isFirstRun ) std::cout << "\n";
04435             //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04436 
04437         } // END: for loop for Y
04438 
04439         //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04441         //if ( isFirstRun ) std::cout << "\n";
04442         //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04443 
04444     } // END: for loop for Z
04445 
04446     //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04448     //if ( isFirstRun ) {
04449     //  std::cout << "-------------------------\n";
04450     //}
04452     //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
04453 
04454     glPopAttrib();
04455 
04456     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
04457     m_glslProgramObjectForShaderSurfaceFromSW->EndGLSL();
04458     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
04459     //---------------------------------------------------------------
04460     //===============================================================
04461     //*/
04462 
04463     //---------------------------------------------------------------
04464     //===============================================================
04465     delete [] dataForPosition;
04466     delete [] dataForEllipsoidInfluence;
04467 }
04468 //-----------------------------------------------------------------------------
04469 // END: DrawByGL_StandardMC
04470 //*****************************************************************************
04471 
04472 
04476 //*****************************************************************************
04477 // BEGIN: DrawByGL
04478 //-----------------------------------------------------------------------------
04479 template <typename T>
04480 void ModelDeformableGLSL_Visualization_RTGenMesh<T>::DrawByGL ()
04481 {
04493     //---------------------------------------------------------------
04494     // For fixed length (by interpolation) after cutting
04495     const Vector3<T> CUBE_DIMENSIONS = m_SimDomain->RetGridDimension();
04496     //---------------------------------------------------------------
04497 
04498 //*
04499     //---------------------------------------------------------------
04500 #ifdef TAPs_DEBUG_MODE
04501     if ( !m_SimDomain ) return;
04502     //---------------------------------------------------------------
04503     if ( !m_SimDomain->RetObject3DTexturePosition() )   return;
04504     //---------------------------------------------------------------
04505 #endif
04506     //===============================================================
04507     // Read data from GPU -- Positions
04508     //---------------------------------------------------------------
04509     Texture * texture3DPosition = m_SimDomain->RetObject3DTexturePosition();
04510     //---------------------------------------------------------------
04511     glPushAttrib( GL_ALL_ATTRIB_BITS );
04512     //-----------------------------------------------------
04513     GLsizei sizeForPosition = 
04514             texture3DPosition->GetWidth() *
04515             texture3DPosition->GetHeight() *
04516             texture3DPosition->GetDepth() *
04517             texture3DPosition->GetInternalFormatNumberOfComponents();
04518     GLfloat * dataForPosition = new GLfloat[ sizeForPosition ];
04519     {
04520         int i = 0;
04521         //=================================================
04522         // Read data for positions from a texture to memory
04523         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
04524         texture3DPosition->BindTexture(0);
04525         glGetTexImage( 
04526             texture3DPosition->GetTarget(),
04527             texture3DPosition->GetLevel(),
04528             texture3DPosition->GetPixelFormat(),
04529             texture3DPosition->GetDataType(),
04530             dataForPosition
04531         );
04532         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
04533         //=================================================
04534     }
04535     //---------------------------------------------------------------
04536     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
04537     //-----------------------------------------------------
04538     glPopAttrib();
04539     //---------------------------------------------------------------
04540     //===============================================================
04541 
04542     //===============================================================
04543     // Read data from GPU -- Ellipsoid Influence
04544     //---------------------------------------------------------------
04545     Texture * texture3DEllipsoidInfluence = m_SimDomain->RetObject3DTextureEllipsoidInfluence();
04546     //---------------------------------------------------------------
04547     glPushAttrib( GL_ALL_ATTRIB_BITS );
04548     //-----------------------------------------------------
04549     GLsizei sizeForEllipsoidInfluence = 
04550             texture3DEllipsoidInfluence->GetWidth() *
04551             texture3DEllipsoidInfluence->GetHeight() *
04552             texture3DEllipsoidInfluence->GetDepth() *
04553             texture3DEllipsoidInfluence->GetInternalFormatNumberOfComponents();
04554     //std::cout << "sizeForEllipsoidInfluence: " << sizeForEllipsoidInfluence << "\n";
04555     GLfloat * dataForEllipsoidInfluence = new GLfloat[ sizeForEllipsoidInfluence ];
04556     {
04557         int i = 0;
04558         //=================================================
04559         // Read data for ellipsoid influences from a texture to memory
04560         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
04561         texture3DEllipsoidInfluence->BindTexture(0);
04562         glGetTexImage( 
04563             texture3DEllipsoidInfluence->GetTarget(),
04564             texture3DEllipsoidInfluence->GetLevel(),
04565             texture3DEllipsoidInfluence->GetPixelFormat(),
04566             texture3DEllipsoidInfluence->GetDataType(),
04567             dataForEllipsoidInfluence
04568         );
04569         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
04570         //=================================================
04571     }
04572     //---------------------------------------------------------------
04573     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
04574     //-----------------------------------------------------
04575     glPopAttrib();
04576     //---------------------------------------------------------------
04577     //===============================================================
04578 
04579     //---------------------------------
04580     Vector3<int> gridResolution = m_SimDomain->GetGridResolution();
04581     Vector3<T>   gridDimension  = m_SimDomain->GetGridDimension();
04582     //---------------------------------
04583 
04584     //*
04585     //===============================================================
04586     // Draw by Marching Cube
04587     //---------------------------------------------------------------
04588     // Adapted from "Polygonising a scalar field" by Paul Bourke (1994)
04589     // http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/
04590     //---------------------------------------------------------------
04591     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
04592     m_glslProgramObjectForShaderSurfaceFromSW->BeginGLSL();
04593     if ( m_3DTexture ) {
04594         glActiveTexture( GL_TEXTURE0 );
04595         glBindTexture( GL_TEXTURE_3D, m_3DTexture );
04596         m_glslProgramObjectForShaderSurfaceFromSW->SetUniform1i( "SurfaceTexture", 0 );
04597         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
04598     }
04599     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
04600 
04601     glPushAttrib( GL_ALL_ATTRIB_BITS );
04602     //glLineWidth( 2 );
04603     glPointSize( 5 );
04604 
04605     //glColor3ub( 240/2, 220/2, 130/2 );
04606     //glColor3ub( 240/8, 220/8, 130/8 );
04607     //glColor3ub( 65, 65, 65 );
04608 
04609     glColor3ub( 75, 75, 75 );
04610 
04611     //glColor3ub( 150, 150, 150 );
04612     //glColor3ub( 255, 255, 255 );
04613     
04614     //glEnable( GL_COLOR_MATERIAL );
04615 
04616     /*
04617     GLfloat diffuseMaterial[4]  = { 0.5f, 0.5f, 0.5f, 1.0f };
04618     GLfloat specularMaterial[4] = { 0.8f, 0.8f, 0.8f, 1.0f };
04619     GLfloat ambientMaterial[4]  = { 0.1f, 0.1f, 0.1f, 1.0f };
04620     GLfloat shininessMaterial[] = { 128.0 };
04621     glMaterialfv( GL_FRONT, GL_AMBIENT,  ambientMaterial );
04622     glMaterialfv( GL_FRONT, GL_SPECULAR, specularMaterial );
04623     glMaterialfv( GL_FRONT, GL_DIFFUSE,  diffuseMaterial );
04624     glMaterialfv( GL_FRONT, GL_SHININESS,  diffuseMaterial );
04625     //*/
04626 
04627     glEnable( GL_LIGHTING );
04628     //glDisable( GL_LIGHTING );
04629 
04630     // DEBUG for two-sided lighting
04631     glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
04632 
04633     //---------------------------------------------------------------
04634     // Texture Parameter Setup
04635 
04636     /*
04637     // 3D Texture for surface
04638     glEnable( GL_TEXTURE_3D );
04639     glBindTexture( GL_TEXTURE_3D, m_3DTexture );
04640     //*/
04641 
04642     // Composition
04643     glEnable( GL_BLEND );
04644     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
04645     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
04646     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );
04647     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
04648     //glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE, 0.5 );
04649     //glTexEnvf( GL_TEXTURE_ENV, GL_ALPHA_SCALE, 0.5 );
04650     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );
04651 
04652     /*
04653     static GLfloat constColor[4] = { 0.0, 0.0, 0.0, 0.0 };
04654     constColor[3] = 0.2;
04655     glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor );
04656     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
04657     glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
04658     glTexEnvf( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE );
04659     glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
04660     glTexEnvf( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS );
04661     glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
04662     glTexEnvf( GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS );
04663     glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA );
04664     //*/
04665 
04666     //---------------------------------------------------------------
04667     int iOffsetSlice = gridResolution[1] * gridResolution[0] * 4;
04668     int iOffsetRow = gridResolution[0] * 4;
04669     int iOffsetCol = 4;
04670     //---------------------------------
04671     // Vertex & Edge Index
04672     //          3------2------2
04673     //         /|            /|
04674     //       11 |          10 |
04675     //       /  3          /  1
04676     //      7------6------6   |
04677     //      |   |         |   |
04678     //      |   0------0--|---1
04679     //      7  /          5  /
04680     //      | 8           | 9 
04681     //      |/            |/
04682     //      4------4------5
04683     //---------------------------------
04684     // Edge Table [256] & Triangle Table [256][16]
04692     // V = V1 + (isovalue - s1) (V2 - V1) / (s2 - s1)
04693     //---------------------------------
04694     //unsigned char cubeClass = 0;
04695     //if ( grid.val[0] < isolevel ) cubeClass |= 1;
04696     //if ( grid.val[1] < isolevel ) cubeClass |= 2;
04697     //if ( grid.val[2] < isolevel ) cubeClass |= 4;
04698     //if ( grid.val[3] < isolevel ) cubeClass |= 8;
04699     //if ( grid.val[4] < isolevel ) cubeClass |= 16;
04700     //if ( grid.val[5] < isolevel ) cubeClass |= 32;
04701     //if ( grid.val[6] < isolevel ) cubeClass |= 64;
04702     //if ( grid.val[7] < isolevel ) cubeClass |= 128;
04703     //---------------------------------
04704     int numOfTrisPerCell = 0;   // number of triangles in the cell
04705     int triIndices[15];         // at most 5 triangles
04706     Vector3<T>  V[8];           // vertices of the cell
04707     Vector3<T>  VTC[8];         // texture coordinates of the vertices
04708     Vector3<T>  texCoordList[12];   // since 12 edges
04709     Vector3<T>  vertexList[12]; // since 12 edges
04710     int         bV[12];         // >=0 if the vertex is counted (e.g. on boundary, existing, etc.)
04711     Vector3<T>  grad[12];       // gradients of vertices
04712     //Vector3<T> texCoords[12]; // 
04713     Vector3<T> Center;//, nE, nW, nN, nS, nF, nB;   // center and its neighbors for gradient computation
04714     //---------------------------------
04715     int idx[8], d, i;
04716     unsigned char cubeClass = 0;
04717     T threshold  = 250;
04718     //
04719     T tc[3];
04720     T tcStep[3] = {
04721         1.0 / static_cast<T>( gridResolution[0]-1 ), 
04722         1.0 / static_cast<T>( gridResolution[1]-1 ), 
04723         1.0 / static_cast<T>( gridResolution[2]-1 ) 
04724     };
04725     //
04726 
04727     //-----------------------------------------------------
04728     // For Interpolation Data used by Marching Cube
04729     int iOffsetSliceIntp = gridResolution[1] * gridResolution[0] * 3;
04730     int iOffsetRowIntp = gridResolution[0] * 3;
04731     int iOffsetColIntp = 3;
04732     int intpIdx[8];
04733     Vector3<T> VIntp[8];    // Interpolation Data (XYZ)
04734     //-----------------------------------------------------
04735 
04736     //---------------------------------
04737     //for ( int Z = gridResolution[2]*3/4; Z < gridResolution[2]-1; ++Z ) {
04738     for ( int Z = 0; Z < gridResolution[2]-1; ++Z ) {
04739         //
04740         // For Interpolation Data
04741         int offsetZIntp = Z * iOffsetSliceIntp;
04742         //
04743         int offsetZ = Z * iOffsetSlice;
04744         //
04745         // Texture Coordinates -- Z
04746         tc[2] = static_cast<T>( Z ) / static_cast<T>( gridResolution[2]-1 );
04747         VTC[0].SetZ( tc[2] );
04748         VTC[1].SetZ( tc[2] );
04749         VTC[2].SetZ( tc[2] );
04750         VTC[3].SetZ( tc[2] );
04751         tc[2] += tcStep[2];
04752         VTC[4].SetZ( tc[2] );
04753         VTC[5].SetZ( tc[2] );
04754         VTC[6].SetZ( tc[2] );
04755         VTC[7].SetZ( tc[2] );
04756         //
04757         //for ( int Y = gridResolution[1]; Y < gridResolution[1]-1; ++Y ) {
04758         for ( int Y = 0; Y < gridResolution[1]-1; ++Y ) {
04759             //
04760             // Set Indices for Interpolation Data
04761             int offsetYZIntp = Y * iOffsetRowIntp + offsetZIntp;
04762             intpIdx[0] = offsetYZIntp;;
04763             intpIdx[1] = intpIdx[0] + iOffsetColIntp;
04764             intpIdx[2] = intpIdx[1] + iOffsetRowIntp;
04765             intpIdx[3] = intpIdx[0] + iOffsetRowIntp;
04766             intpIdx[4] = intpIdx[0] + iOffsetSliceIntp;
04767             intpIdx[5] = intpIdx[4] + iOffsetColIntp;
04768             intpIdx[6] = intpIdx[5] + iOffsetRowIntp;
04769             intpIdx[7] = intpIdx[4] + iOffsetRowIntp;
04770             //
04771             // Set Indices for Cube Vertices
04772             int offsetYZ = Y * iOffsetRow + offsetZ;
04773             idx[0] = offsetYZ;
04774             idx[1] = idx[0] + iOffsetCol;
04775             idx[2] = idx[1] + iOffsetRow;
04776             idx[3] = idx[0] + iOffsetRow;
04777             idx[4] = idx[0] + iOffsetSlice;
04778             idx[5] = idx[4] + iOffsetCol;
04779             idx[6] = idx[5] + iOffsetRow;
04780             idx[7] = idx[4] + iOffsetRow;
04781             //
04782             // Texture Coordinates -- Y
04783             tc[1] = static_cast<T>( Y ) / static_cast<T>( gridResolution[1]-1 );
04784             VTC[0].SetY( tc[1] );
04785             VTC[1].SetY( tc[1] );
04786             VTC[4].SetY( tc[1] );
04787             VTC[5].SetY( tc[1] );
04788             tc[1] += tcStep[1];
04789             VTC[2].SetY( tc[1] );
04790             VTC[3].SetY( tc[1] );
04791             VTC[6].SetY( tc[1] );
04792             VTC[7].SetY( tc[1] );
04793             //
04794             for ( int X = 0; X < gridResolution[0]-1; ++X ) {
04795                 //
04796                 // Texture Coordinates -- X
04797                 tc[0] = static_cast<T>( X ) / static_cast<T>( gridResolution[0]-1 );
04798                 VTC[0].SetX( tc[0] );
04799                 VTC[3].SetX( tc[0] );
04800                 VTC[4].SetX( tc[0] );
04801                 VTC[7].SetX( tc[0] );
04802                 tc[0] += tcStep[0];
04803                 VTC[1].SetX( tc[0] );
04804                 VTC[2].SetX( tc[0] );
04805                 VTC[5].SetX( tc[0] );
04806                 VTC[6].SetX( tc[0] );
04807                 //
04808 
04809 
04810                 bool bLeftPresent  = false;
04811                 bool bRightPresent = false;
04812                 {
04813                     for ( int i = 0; i < 8; ++i ) {
04814                         int flagVal = static_cast<int>( dataForPosition[idx[i] + 3] );
04815                         if ( flagVal > threshold ) {
04816                             flagVal %= int( m_SimDomain->IC_Thresholds::FLAG_STEP );
04817                             if      ( 1 < flagVal && flagVal < m_SimDomain->IC_Thresholds::MC_LEFT_ADD+1 ) {
04818                                 bLeftPresent = true;
04819                             }
04820                             else if ( flagVal > m_SimDomain->IC_Thresholds::MC_LEFT_ADD+1 ) {
04821                                 bRightPresent = true;
04822                             }
04823                         }
04824                     }
04825                 }
04826 
04827                 //*
04828                 // STANDARD CUBE CONFIGURATION
04829                 //-------------------------------
04830                 // Determine the threshold of each vertex of the cube
04831                 cubeClass = 0;
04832                 if ( dataForPosition[idx[0] + 3] > threshold )  cubeClass |= 1;
04833                 if ( dataForPosition[idx[1] + 3] > threshold )  cubeClass |= 2;
04834                 if ( dataForPosition[idx[2] + 3] > threshold )  cubeClass |= 4;
04835                 if ( dataForPosition[idx[3] + 3] > threshold )  cubeClass |= 8;
04836                 if ( dataForPosition[idx[4] + 3] > threshold )  cubeClass |= 16;
04837                 if ( dataForPosition[idx[5] + 3] > threshold )  cubeClass |= 32;
04838                 if ( dataForPosition[idx[6] + 3] > threshold )  cubeClass |= 64;
04839                 if ( dataForPosition[idx[7] + 3] > threshold )  cubeClass |= 128;
04840                 //-------------------------------
04841                 //*/
04842 
04843                 //===============================================
04844                 // Calculate Gradients
04845                 //-----------------------------------------------
04846                 Vector3<T> G[8];
04847                 int index;
04848                 for ( int vID = 0; vID < 8; ++vID ) {
04849                     Center.SetXYZ(  dataForPosition[idx[vID]  ], 
04850                                     dataForPosition[idx[vID]+1], 
04851                                     dataForPosition[idx[vID]+2] );
04852                     G[vID].SetXYZ( 0, 0, 0 );
04853 
04854                 //*
04855                 //=================================
04856                 // START: 6 Face Gradients
04857                 //---------------------------------
04858                 if ( GetGradientComputationByFacesStatus() ) {
04859                 //--- East --------------
04860                 if ( X < gridResolution[0]-2 ) {
04861                     index = idx[vID] + iOffsetCol;
04862                     if ( dataForPosition[index+3] > threshold ) {
04863                         int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04864                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04865                         G[vID] += Center - vGrad;
04866                     }
04867                 }
04868                 //--- West --------------
04869                 if ( X > 0 ) {
04870                     index = idx[vID] - iOffsetCol;
04871                     if ( dataForPosition[index+3] > threshold ) {
04872                         int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04873                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04874                         G[vID] += Center - vGrad;
04875                     }
04876                 }
04877                 //--- North -------------
04878                 if ( Y < gridResolution[1]-2 ) {
04879                     index = idx[vID] + iOffsetRow;
04880                     if ( dataForPosition[index+3] > threshold ) {
04881                         int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04882                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04883                         G[vID] += Center - vGrad;
04884                     }
04885                 }
04886                 //--- South -------------
04887                 if ( Y > 0 ) {
04888                     index = idx[vID] - iOffsetRow;
04889                     if ( dataForPosition[index+3] > threshold ) {
04890                         int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04891                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04892                         G[vID] += Center - vGrad;
04893                     }
04894                 }
04895                 //--- Front -------------
04896                 if ( Z < gridResolution[2]-2 ) {
04897                     index = idx[vID] + iOffsetSlice;
04898                     if ( dataForPosition[index+3] > threshold ) {
04899                         int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04900                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04901                         G[vID] += Center - vGrad;
04902                     }
04903                 }
04904                 //--- Back --------------
04905                 if ( Z > 0 ) {
04906                     index = idx[vID] - iOffsetSlice;
04907                     if ( dataForPosition[index+3] > threshold ) {
04908                         int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04909                         Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04910                         G[vID] += Center - vGrad;
04911                     }
04912                 }
04913                 //-----------------------
04914                 } // END: if ( GetGradientComputationByFacesStatus() ) {
04915                 //---------------------------------
04916                 // END: 6 Face Gradients
04917                 //=================================
04918                 //*/
04919 
04920                 //*
04921                 //=================================
04922                 // START: 8 Vertex Gradients
04923                 //---------------------------------
04924                 if ( GetGradientComputationByVerticesStatus() ) {
04925                 //--- Front -------------
04926                 if ( Z < gridResolution[2]-2 ) {
04927                     int idxF = idx[vID] + iOffsetSlice;
04928                     //-- North -----
04929                     if ( Y < gridResolution[1]-2 ) {
04930                         int idxFN = idxF + iOffsetRow;
04931                         //- West
04932                         if ( X > 0 ) {
04933                             index = idxFN - iOffsetCol;
04934                             if ( dataForPosition[index+3] > threshold ) {
04935                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04936                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04937                                 G[vID] += Center - vGrad;
04938                             }
04939                         }
04940                         //- East
04941                         if ( X < gridResolution[0]-2 ) {
04942                             index = idxFN + iOffsetCol;
04943                             if ( dataForPosition[index+3] > threshold ) {
04944                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04945                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04946                                 G[vID] += Center - vGrad;
04947                             }
04948                         }
04949                     }
04950                     //-- South -----
04951                     if ( Y > 0 ) {
04952                         int idxFS = idxF - iOffsetRow;
04953                         //- West
04954                         if ( X > 0 ) {
04955                             index = idxFS - iOffsetCol;
04956                             if ( dataForPosition[index+3] > threshold ) {
04957                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04958                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04959                                 G[vID] += Center - vGrad;
04960                             }
04961                         }
04962                         //- East
04963                         if ( X < gridResolution[0]-2 ) {
04964                             index = idxFS + iOffsetCol;
04965                             if ( dataForPosition[index+3] > threshold ) {
04966                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04967                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04968                                 G[vID] += Center - vGrad;
04969                             }
04970                         }
04971                     }
04972                 }
04973                 //--- Back --------------
04974                 if ( Z > 0 ) {
04975                     int idxF = idx[vID] - iOffsetSlice;
04976                     //-- North -----
04977                     if ( Y < gridResolution[1]-2 ) {
04978                         int idxFN = idxF + iOffsetRow;
04979                         //- West
04980                         if ( X > 0 ) {
04981                             index = idxFN - iOffsetCol;
04982                             if ( dataForPosition[index+3] > threshold ) {
04983                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04984                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04985                                 G[vID] += Center - vGrad;
04986                             }
04987                         }
04988                         //- East
04989                         if ( X < gridResolution[0]-2 ) {
04990                             index = idxFN + iOffsetCol;
04991                             if ( dataForPosition[index+3] > threshold ) {
04992                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
04993                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
04994                                 G[vID] += Center - vGrad;
04995                             }
04996                         }
04997                     }
04998                     //-- South -----
04999                     if ( Y > 0 ) {
05000                         int idxFS = idxF - iOffsetRow;
05001                         //- West
05002                         if ( X > 0 ) {
05003                             index = idxFS - iOffsetCol;
05004                             if ( dataForPosition[index+3] > threshold ) {
05005                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05006                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05007                                 G[vID] += Center - vGrad;
05008                             }
05009                         }
05010                         //- East
05011                         if ( X < gridResolution[0]-2 ) {
05012                             index = idxFS + iOffsetCol;
05013                             if ( dataForPosition[index+3] > threshold ) {
05014                                 int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05015                                 Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05016                                 G[vID] += Center - vGrad;
05017                             }
05018                         }
05019                     }
05020                 }
05021                 //-----------------------
05022                 } // END: if ( GetGradientComputationByVerticesStatus() ) {
05023                 //---------------------------------
05024                 // END: 8 Vertex Gradients
05025                 //=================================
05026                 //*/
05027 
05028                 //*
05029                 //=================================
05030                 // START: 12 Edge Gradients
05031                 //---------------------------------
05032                 if ( GetGradientComputationByEdgesStatus() ) {
05033                 //--- Front -------------
05034                 if ( Z < gridResolution[2]-2 ) {
05035                     int idxF = idx[vID] + iOffsetSlice;
05036                     //-- East ------
05037                     if ( X < gridResolution[0]-2 ) {
05038                         index = idxF + iOffsetCol;
05039                         if ( dataForPosition[index+3] > threshold ) {
05040                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05041                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05042                             G[vID] += Center - vGrad;
05043                         }
05044                     }
05045                     //-- West ------
05046                     if ( X > 0 ) {
05047                         index = idxF - iOffsetCol;
05048                         if ( dataForPosition[index+3] > threshold ) {
05049                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05050                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05051                             G[vID] += Center - vGrad;
05052                         }
05053                     }
05054                     //-- North -----
05055                     if ( Y < gridResolution[1]-2 ) {
05056                         index = idxF + iOffsetRow;
05057                         if ( dataForPosition[index+3] > threshold ) {
05058                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05059                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05060                             G[vID] += Center - vGrad;
05061                         }
05062                     }
05063                     //-- South -----
05064                     if ( Y > 0 ) {
05065                         index = idxF - iOffsetRow;
05066                         if ( dataForPosition[index+3] > threshold ) {
05067                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05068                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05069                             G[vID] += Center - vGrad;
05070                         }
05071                     }
05072                 }
05073                 //--- Center ------------
05074                 if ( true ) {
05075                     int idxC = idx[vID];
05076                     //-- East ------
05077                     if ( X < gridResolution[0]-2 ) {
05078                         index = idxC + iOffsetCol;
05079                         if ( dataForPosition[index+3] > threshold ) {
05080                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05081                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05082                             G[vID] += Center - vGrad;
05083                         }
05084                     }
05085                     //-- West ------
05086                     if ( X > 0 ) {
05087                         index = idxC - iOffsetCol;
05088                         if ( dataForPosition[index+3] > threshold ) {
05089                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05090                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05091                             G[vID] += Center - vGrad;
05092                         }
05093                     }
05094                     //-- North -----
05095                     if ( Y < gridResolution[1]-2 ) {
05096                         index = idxC + iOffsetRow;
05097                         if ( dataForPosition[index+3] > threshold ) {
05098                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05099                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05100                             G[vID] += Center - vGrad;
05101                         }
05102                     }
05103                     //-- South -----
05104                     if ( Y > 0 ) {
05105                         index = idxC - iOffsetRow;
05106                         if ( dataForPosition[index+3] > threshold ) {
05107                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05108                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05109                             G[vID] += Center - vGrad;
05110                         }
05111                     }
05112                 }
05113                 //--- Back --------------
05114                 if ( Z > 0 ) {
05115                     int idxB = idx[vID] - iOffsetSlice;
05116                     //-- East ------
05117                     if ( X < gridResolution[0]-2 ) {
05118                         index = idxB + iOffsetCol;
05119                         if ( dataForPosition[index+3] > threshold ) {
05120                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05121                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05122                             G[vID] += Center - vGrad;
05123                         }
05124                     }
05125                     //-- West ------
05126                     if ( X > 0 ) {
05127                         index = idxB - iOffsetCol;
05128                         if ( dataForPosition[index+3] > threshold ) {
05129                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05130                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05131                             G[vID] += Center - vGrad;
05132                         }
05133                     }
05134                     //-- North -----
05135                     if ( Y < gridResolution[1]-2 ) {
05136                         index = idxB + iOffsetRow;
05137                         if ( dataForPosition[index+3] > threshold ) {
05138                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05139                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05140                             G[vID] += Center - vGrad;
05141                         }
05142                     }
05143                     //-- South -----
05144                     if ( Y > 0 ) {
05145                         index = idxB - iOffsetRow;
05146                         if ( dataForPosition[index+3] > threshold ) {
05147                             int iFlag = static_cast<int>( dataForPosition[index+3] ) % m_SimDomain->IC_Thresholds::FLAG_STEP;
05148                             Vector3<T> vGrad( dataForPosition[index], dataForPosition[index+1], dataForPosition[index+2] );
05149                             G[vID] += Center - vGrad;
05150                         }
05151                     }
05152                 }
05153                 //-----------------------
05154                 } // END: if ( GetGradientComputationByEdgesStatus() ) {
05155                 //---------------------------------
05156                 // END: 12 Edge Gradients
05157                 //=================================
05158                 //*/
05159             }
05160             //-----------------------------------------------
05161             // END: Calculate Gradients
05162             //===============================================
05163                 
05164 {
05165                         //*
05166                         //-----------------
05167                         for ( i = 0; i < 8; ++i ) {
05168                             V[i].SetXYZ( 
05169                                 dataForPosition[idx[i]    ], 
05170                                 dataForPosition[idx[i] + 1], 
05171                                 dataForPosition[idx[i] + 2] 
05172                             );
05173                         }
05174                         //-----------------
05175                         // Reset list of existing vertices
05176                         for ( i = 0; i < 12; ++i ) {
05177                             bV[i] = -1;
05178                         }
05179 
05180                         //-----------------
05181                         // Interpolation Data
05182                         for ( i = 0; i < 8; ++i ) {
05183                             VIntp[i].SetXYZ( 
05184                                 dataForEllipsoidInfluence[intpIdx[i]    ], 
05185                                 dataForEllipsoidInfluence[intpIdx[i] + 1], 
05186                                 dataForEllipsoidInfluence[intpIdx[i] + 2] 
05187                             );
05188                         }
05189                         //*/
05190 
05191                             T interpolationValPlus;
05192                             T interpolationValNeg;
05193                             if ( EdgeTable[cubeClass] & 1 ) {
05194                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05195                                     //
05196                                     // Interpotation Data
05197                                     interpolationValPlus = VIntp[0].GetX();
05198                                     //
05199                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]).Normalized()*CUBE_DIMENSIONS[0];
05200                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05201                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05202                                 }
05203                                 else {
05204                                     //
05205                                     // Interpotation Data
05206                                     interpolationValNeg = -VIntp[1].GetX();
05207                                     //
05208                                     vertexList[ 0] = V[1] + interpolationValNeg*(V[1] - V[0]).Normalized()*CUBE_DIMENSIONS[0];
05209                                     grad[0]        = G[1] + interpolationValNeg*(G[1] - G[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05210                                     texCoordList[0] = VTC[1] + interpolationValNeg*(VTC[1] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05211                                 }
05212                                 grad[0].Normalized();
05213                             }
05214                             if ( EdgeTable[cubeClass] & 2 ) {
05215                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
05216                                     //
05217                                     // Interpotation Data
05218                                     interpolationValPlus = VIntp[1].GetY();
05219                                     //
05220                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]).Normalized()*CUBE_DIMENSIONS[1];
05221                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05222                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05223                                 }
05224                                 else {
05225                                     //
05226                                     // Interpotation Data
05227                                     interpolationValNeg = -VIntp[2].GetY();
05228                                     //
05229                                     vertexList[ 1] = V[2] + interpolationValNeg*(V[2] - V[1]).Normalized()*CUBE_DIMENSIONS[1];
05230                                     grad[1]        = G[2] + interpolationValNeg*(G[2] - G[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05231                                     texCoordList[1] = VTC[2] + interpolationValNeg*(VTC[2] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05232                                 }
05233                                 grad[1].Normalized();
05234                             }
05235                             if ( EdgeTable[cubeClass] & 4 ) {
05236                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
05237                                     //
05238                                     // Interpotation Data
05239                                     interpolationValPlus = VIntp[2].GetX();
05240                                     //
05241                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]).Normalized()*CUBE_DIMENSIONS[0];
05242                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05243                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05244                                 }
05245                                 else {
05246                                     //
05247                                     // Interpotation Data
05248                                     interpolationValNeg = -VIntp[3].GetX();
05249                                     //
05250                                     vertexList[ 2] = V[3] + interpolationValNeg*(V[3] - V[2]).Normalized()*CUBE_DIMENSIONS[0];
05251                                     grad[2]        = G[3] + interpolationValNeg*(G[3] - G[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05252                                     texCoordList[2] = VTC[3] + interpolationValNeg*(VTC[3] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05253                                 }
05254                                 grad[2].Normalized();
05255                             }
05256                             if ( EdgeTable[cubeClass] & 8 ) {
05257                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05258                                     //
05259                                     // Interpotation Data
05260                                     interpolationValPlus = VIntp[0].GetY();
05261                                     //
05262                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]).Normalized()*CUBE_DIMENSIONS[1];
05263                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05264                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05265                                 }
05266                                 else {
05267                                     //
05268                                     // Interpotation Data
05269                                     interpolationValNeg = -VIntp[3].GetY();
05270                                     //
05271                                     vertexList[ 3] = V[3] + interpolationValNeg*(V[3] - V[0]).Normalized()*CUBE_DIMENSIONS[1];
05272                                     grad[3]        = G[3] + interpolationValNeg*(G[3] - G[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05273                                     texCoordList[3] = VTC[3] + interpolationValNeg*(VTC[3] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05274                                 }
05275                                 grad[3].Normalized();
05276                             }
05277                             if ( EdgeTable[cubeClass] & 16 ) {
05278                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
05279                                     //
05280                                     // Interpotation Data
05281                                     interpolationValPlus = VIntp[4].GetX();
05282                                     //
05283                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]).Normalized()*CUBE_DIMENSIONS[0];
05284                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05285                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05286                                 }
05287                                 else {
05288                                     //
05289                                     // Interpotation Data
05290                                     interpolationValNeg = -VIntp[5].GetX();
05291                                     //
05292                                     vertexList[ 4] = V[5] + interpolationValNeg*(V[5] - V[4]).Normalized()*CUBE_DIMENSIONS[0];
05293                                     grad[4]        = G[5] + interpolationValNeg*(G[5] - G[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05294                                     texCoordList[4] = VTC[5] + interpolationValNeg*(VTC[5] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05295                                 }
05296                                 grad[4].Normalized();
05297                             }
05298                             if ( EdgeTable[cubeClass] & 32 ) {
05299                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
05300                                     //
05301                                     // Interpotation Data
05302                                     interpolationValPlus = VIntp[5].GetY();
05303                                     //
05304                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]).Normalized()*CUBE_DIMENSIONS[1];
05305                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05306                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05307                                 }
05308                                 else {
05309                                     //
05310                                     // Interpotation Data
05311                                     interpolationValNeg = -VIntp[6].GetY();
05312                                     //
05313                                     vertexList[ 5] = V[6] + interpolationValNeg*(V[6] - V[5]).Normalized()*CUBE_DIMENSIONS[1];
05314                                     grad[5]        = G[6] + interpolationValNeg*(G[6] - G[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05315                                     texCoordList[5] = VTC[6] + interpolationValNeg*(VTC[6] - VTC[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05316                                 }
05317                                 grad[5].Normalized();
05318                             }
05319                             if ( EdgeTable[cubeClass] & 64 ) {
05320                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
05321                                     //
05322                                     // Interpotation Data
05323                                     interpolationValPlus = VIntp[6].GetX();
05324                                     //
05325                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]).Normalized()*CUBE_DIMENSIONS[0];
05326                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05327                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05328                                 }
05329                                 else {
05330                                     //
05331                                     // Interpotation Data
05332                                     interpolationValNeg = -VIntp[7].GetX();
05333                                     //
05334                                     vertexList[ 6] = V[7] + interpolationValNeg*(V[7] - V[6]).Normalized()*CUBE_DIMENSIONS[0];
05335                                     grad[6]        = G[7] + interpolationValNeg*(G[7] - G[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05336                                     texCoordList[6] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05337                                 }
05338                                 grad[6].Normalized();
05339                             }
05340                             if ( EdgeTable[cubeClass] & 128 ) {
05341                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
05342                                     //
05343                                     // Interpotation Data
05344                                     interpolationValPlus = VIntp[4].GetY();
05345                                     //
05346                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]).Normalized()*CUBE_DIMENSIONS[1];
05347                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]);//.Normalized()*CUBE_DIMENSIONS[1];
05348                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[1];
05349                                 }
05350                                 else {
05351                                     //
05352                                     // Interpotation Data
05353                                     interpolationValNeg = -VIntp[7].GetY();
05354                                     //
05355                                     vertexList[ 7] = V[7] + interpolationValNeg*(V[7] - V[4]).Normalized()*CUBE_DIMENSIONS[1];
05356                                     grad[7]        = G[7] + interpolationValNeg*(G[7] - G[4]);//.Normalized()*CUBE_DIMENSIONS[1];
05357                                     texCoordList[7] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[1];
05358                                 }
05359                                 grad[7].Normalized();
05360                             }
05361                             if ( EdgeTable[cubeClass] & 256 ) {
05362                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05363                                     //
05364                                     // Interpotation Data
05365                                     interpolationValPlus = VIntp[0].GetZ();
05366                                     //
05367                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]).Normalized()*CUBE_DIMENSIONS[2];
05368                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]);//.Normalized()*CUBE_DIMENSIONS[2];
05369                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[2];
05370                                 }
05371                                 else {
05372                                     //
05373                                     // Interpotation Data
05374                                     interpolationValNeg = -VIntp[4].GetZ();
05375                                     //
05376                                     vertexList[ 8] = V[4] + interpolationValNeg*(V[4] - V[0]).Normalized()*CUBE_DIMENSIONS[2];
05377                                     grad[8]        = G[4] + interpolationValNeg*(G[4] - G[0]);//.Normalized()*CUBE_DIMENSIONS[2];
05378                                     texCoordList[8] = VTC[4] + interpolationValNeg*(VTC[4] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[2];
05379                                 }
05380                                 grad[8].Normalized();
05381                             }
05382                             if ( EdgeTable[cubeClass] & 512 ) {
05383                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
05384                                     //
05385                                     // Interpotation Data
05386                                     interpolationValPlus = VIntp[1].GetZ();
05387                                     //
05388                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]).Normalized()*CUBE_DIMENSIONS[2];
05389                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]);//.Normalized()*CUBE_DIMENSIONS[2];
05390                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[2];
05391                                 }
05392                                 else {
05393                                     //
05394                                     // Interpotation Data
05395                                     interpolationValNeg = -VIntp[5].GetZ();
05396                                     //
05397                                     vertexList[ 9] = V[5] + interpolationValNeg*(V[5] - V[1]).Normalized()*CUBE_DIMENSIONS[2];
05398                                     grad[9]        = G[5] + interpolationValNeg*(G[5] - G[1]);//.Normalized()*CUBE_DIMENSIONS[2];
05399                                     texCoordList[9] = VTC[5] + interpolationValNeg*(VTC[5] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[2];
05400                                 }
05401                                 grad[9].Normalized();
05402                             }
05403                             if ( EdgeTable[cubeClass] & 1024 ) {
05404                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
05405                                     //
05406                                     // Interpotation Data
05407                                     interpolationValPlus = VIntp[2].GetZ();
05408                                     //
05409                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]).Normalized()*CUBE_DIMENSIONS[2];
05410                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]);//.Normalized()*CUBE_DIMENSIONS[2];
05411                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[2];
05412                                 }
05413                                 else {
05414                                     //
05415                                     // Interpotation Data
05416                                     interpolationValNeg = -VIntp[6].GetZ();
05417                                     //
05418                                     vertexList[10] = V[6] + interpolationValNeg*(V[6] - V[2]).Normalized()*CUBE_DIMENSIONS[2];
05419                                     grad[10]       = G[6] + interpolationValNeg*(G[6] - G[2]);//.Normalized()*CUBE_DIMENSIONS[2];
05420                                     texCoordList[10] = VTC[6] + interpolationValNeg*(VTC[6] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[2];
05421                                 }
05422                                 grad[10].Normalized();
05423                             }
05424                             if ( EdgeTable[cubeClass] & 2048 ) {
05425                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
05426                                     //
05427                                     // Interpotation Data
05428                                     interpolationValPlus = VIntp[3].GetZ();
05429                                     //
05430                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]).Normalized()*CUBE_DIMENSIONS[2];
05431                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]);//.Normalized()*CUBE_DIMENSIONS[2];
05432                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]);//.Normalized()*CUBE_DIMENSIONS[2];
05433                                 }
05434                                 else {
05435                                     //
05436                                     // Interpotation Data
05437                                     interpolationValNeg = -VIntp[7].GetZ();
05438                                     //
05439                                     vertexList[11] = V[7] + interpolationValNeg*(V[7] - V[3]).Normalized()*CUBE_DIMENSIONS[2];
05440                                     grad[11]       = G[7] + interpolationValNeg*(G[7] - G[3]);//.Normalized()*CUBE_DIMENSIONS[2];
05441                                     texCoordList[11] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[3]);//.Normalized()*CUBE_DIMENSIONS[2];
05442                                 }
05443                                 grad[11].Normalized();
05444                             }
05445 } // End processing normal cube
05446 
05447                 // TWO ITERATIONS FOR LEFT AND RIGHT CUBE CONFIGURATIONS
05448                 for ( int iIterate = 0; iIterate < 2; ++iIterate )
05449                 {
05450                     // Store Reloaded Threshold Values
05451                     GLfloat reloadedThresholdValues[8];
05452                     for ( int R = 0; R < 8; ++R ) {
05453                         reloadedThresholdValues[R] = dataForPosition[idx[R] + 3];
05454                     }
05455 
05456                     // STANDARD CUBE CONFIGURATION
05457                     //-------------------------------
05458                     if ( !bLeftPresent || !bRightPresent ) {
05459                         iIterate = 2;
05460                     }
05461                     else {
05462 
05463                         //-------------------------------
05464                         if ( iIterate == 0 )
05465                         // LEFT CUBE CONFIGURATION
05466                         //-------------------------------
05467                         // Determine the threshold of each vertex of the cube
05468                         {
05469                             float flagVal;
05470                             int factor = 1;
05471                             cubeClass = 0;
05472                             for ( int i = 0; i < 8; ++i ) {
05473                                 flagVal = dataForPosition[idx[i] + 3];
05474                                 if ( flagVal > threshold ) {
05475                                     int iFlag = int( flagVal ) % int( m_SimDomain->IC_Thresholds::FLAG_STEP );
05476                                     if ( iFlag < m_SimDomain->IC_Thresholds::MC_LEFT_ADD+1 ) {
05477                                         cubeClass |= factor;
05478                                     }
05479                                     else {
05480                                         dataForPosition[idx[i] + 3] = m_SimDomain->IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY;
05481                                     }
05482                                 }
05483                                 factor *= 2;
05484                             }
05485                         }
05486 
05487                         //-------------------------------
05488                         else
05489                         // RIGHT CUBE CONFIGURATION
05490                         //-------------------------------
05491                         // Determine the threshold of each vertex of the cube
05492                         {
05493                             float flagVal;
05494                             int factor = 1;
05495                             cubeClass = 0;
05496                             for ( int i = 0; i < 8; ++i ) {
05497                                 flagVal = dataForPosition[idx[i] + 3];
05498                                 if ( flagVal > threshold ) {
05499                                     int iFlag = int( flagVal ) % int( m_SimDomain->IC_Thresholds::FLAG_STEP );
05500                                     if ( iFlag < m_SimDomain->IC_Thresholds::MC_LEFT_ADD-1 
05501                                     || iFlag > m_SimDomain->IC_Thresholds::MC_LEFT_ADD+1 ) {
05502                                         cubeClass |= factor;
05503                                     }
05504                                     else {
05505                                         dataForPosition[idx[i] + 3] = m_SimDomain->IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY;
05506                                     }
05507                                 }
05508                                 factor *= 2;
05509                             }
05510                         }
05511                         //-------------------------------
05512                     }
05513 
05514 
05515                     //-------------------------------
05516                     // Cell is entirely in/out of the surface
05517                     if ( EdgeTable[cubeClass] == 0 ) {
05518                         numOfTrisPerCell = 0;
05519                     }
05520                     else {
05521                     //-------------------------------
05522                     // Cell contains part of the surface
05523 
05524 
05525                         //*
05526                         //-----------------
05527                         for ( i = 0; i < 8; ++i ) {
05528                             V[i].SetXYZ( 
05529                                 dataForPosition[idx[i]    ], 
05530                                 dataForPosition[idx[i] + 1], 
05531                                 dataForPosition[idx[i] + 2] 
05532                             );
05533                         }
05534                         //-----------------
05535                         // Reset list of existing vertices
05536                         for ( i = 0; i < 12; ++i ) {
05537                             bV[i] = -1;
05538                         }
05539 
05540                         //-----------------
05541                         // Interpolation Data
05542                         for ( i = 0; i < 8; ++i ) {
05543                             VIntp[i].SetXYZ( 
05544                                 dataForEllipsoidInfluence[intpIdx[i]    ], 
05545                                 dataForEllipsoidInfluence[intpIdx[i] + 1], 
05546                                 dataForEllipsoidInfluence[intpIdx[i] + 2] 
05547                             );
05548                         }
05549                         //*/
05550 
05551 
05552 
05553                         //===============================================
05554                         // Marching Cube Interpolation
05555                         // V = V1 + (isovalue - s1) (V2 - V1) / (s2 - s1)
05556                         //-----------------------------------------------
05557                         // RUNTIME ERROR CAN OCCURS -- DEPENDING ON THE DATA
05558                         // SINCE IT DOES NOT HAVE BOUNDARY PROTECTION -- ARRAY INDEX OUT OF BOUND ERROR
05559                         //-----------------------------------------------
05560                         // Not Use Global Interpolation Value -- each element has its own xyz interpolation values
05561                         if ( !m_bUseGlobalInterpolationVal ) {
05562                             //-------------------------------------
05563                             // Marching Cube Interpolation
05564                             T interpolationValPlus;// = m_tGlobalInterpolationVal;
05565                             T interpolationValNeg;//  = 1.0 - m_tGlobalInterpolationVal;
05566 
05567 
05568 
05569                             /*
05570                             //***************************************
05571                             // Normal Interpolation
05572                             //=======================================
05573                             //-------------------------------------
05574                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
05575                             if ( EdgeTable[cubeClass] & 1 ) {
05576                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05577                                     //
05578                                     // Interpotation Data
05579                                     interpolationValPlus = VIntp[0].GetX();
05580                                     //
05581                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]);
05582                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]);
05583                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]);
05584                                 }
05585                                 else {
05586                                     //
05587                                     // Interpotation Data
05588                                     interpolationValNeg = 1.0 - VIntp[1].GetX();
05589                                     //
05590                                     vertexList[ 0] = V[0] + interpolationValNeg*(V[1] - V[0]);
05591                                     grad[0]        = G[0] + interpolationValNeg*(G[1] - G[0]);
05592                                     texCoordList[0] = VTC[0] + interpolationValNeg*(VTC[1] - VTC[0]);
05593                                     //grad[0] *= -1.0;
05594                                 }
05595                                 grad[0].Normalized();
05596                             }
05597                             if ( EdgeTable[cubeClass] & 2 ) {
05598                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
05599                                     //
05600                                     // Interpotation Data
05601                                     interpolationValPlus = VIntp[1].GetY();
05602                                     //
05603                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]);
05604                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]);
05605                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]);
05606                                 }
05607                                 else {
05608                                     //
05609                                     // Interpotation Data
05610                                     interpolationValNeg = 1.0 - VIntp[2].GetY();
05611                                     //
05612                                     vertexList[ 1] = V[1] + interpolationValNeg*(V[2] - V[1]);
05613                                     grad[1]        = G[1] + interpolationValNeg*(G[2] - G[1]);
05614                                     texCoordList[1] = VTC[1] + interpolationValNeg*(VTC[2] - VTC[1]);
05615                                     //grad[1] *= -1.0;
05616                                 }
05617                                 grad[1].Normalized();
05618                             }
05619                             if ( EdgeTable[cubeClass] & 4 ) {
05620                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
05621                                     //
05622                                     // Interpotation Data
05623                                     interpolationValPlus = VIntp[2].GetX();
05624                                     //
05625                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]);
05626                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]);
05627                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]);
05628                                     //grad[2] *= -1.0;
05629                                 }
05630                                 else {
05631                                     //
05632                                     // Interpotation Data
05633                                     interpolationValNeg = 1.0 - VIntp[3].GetX();
05634                                     //
05635                                     vertexList[ 2] = V[2] + interpolationValNeg*(V[3] - V[2]);
05636                                     grad[2]        = G[2] + interpolationValNeg*(G[3] - G[2]);
05637                                     texCoordList[2] = VTC[2] + interpolationValNeg*(VTC[3] - VTC[2]);
05638                                 }
05639                                 grad[2].Normalized();
05640                             }
05641                             if ( EdgeTable[cubeClass] & 8 ) {
05642                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05643                                     //
05644                                     // Interpotation Data
05645                                     interpolationValPlus = VIntp[0].GetY();
05646                                     //
05647                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]);
05648                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]);
05649                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]);
05650                                     //grad[3][1] *= -1.0;
05651                                 }
05652                                 else {
05653                                     //
05654                                     // Interpotation Data
05655                                     interpolationValNeg = 1.0 - VIntp[3].GetY();
05656                                     //
05657                                     vertexList[ 3] = V[0] + interpolationValNeg*(V[3] - V[0]);
05658                                     grad[3]        = G[0] + interpolationValNeg*(G[3] - G[0]);
05659                                     texCoordList[3] = VTC[0] + interpolationValNeg*(VTC[3] - VTC[0]);
05660                                 }
05661                                 grad[3].Normalized();
05662                             }
05663                             if ( EdgeTable[cubeClass] & 16 ) {
05664                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
05665                                     //
05666                                     // Interpotation Data
05667                                     interpolationValPlus = VIntp[4].GetX();
05668                                     //
05669                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]);
05670                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]);
05671                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]);
05672                                 }
05673                                 else {
05674                                     //
05675                                     // Interpotation Data
05676                                     interpolationValNeg = 1.0 - VIntp[5].GetX();
05677                                     //
05678                                     vertexList[ 4] = V[4] + interpolationValNeg*(V[5] - V[4]);
05679                                     grad[4]        = G[4] + interpolationValNeg*(G[5] - G[4]);
05680                                     texCoordList[4] = VTC[4] + interpolationValNeg*(VTC[5] - VTC[4]);
05681                                     //grad[4] *= -1.0;
05682                                 }
05683                                 grad[4].Normalized();
05684                             }
05685                             if ( EdgeTable[cubeClass] & 32 ) {
05686                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
05687                                     //
05688                                     // Interpotation Data
05689                                     interpolationValPlus = VIntp[5].GetY();
05690                                     //
05691                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]);
05692                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]);
05693                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]);
05694                                 }
05695                                 else {
05696                                     //
05697                                     // Interpotation Data
05698                                     interpolationValNeg = 1.0 - VIntp[6].GetY();
05699                                     //
05700                                     vertexList[ 5] = V[5] + interpolationValNeg*(V[6] - V[5]);
05701                                     grad[5]        = G[5] + interpolationValNeg*(G[6] - G[5]);
05702                                     texCoordList[5] = VTC[5] + interpolationValNeg*(VTC[6] - VTC[5]);
05703                                     //grad[5][1] *= -1.0;
05704                                 }
05705                                 grad[5].Normalized();
05706                             }
05707                             if ( EdgeTable[cubeClass] & 64 ) {
05708                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
05709                                     //
05710                                     // Interpotation Data
05711                                     interpolationValPlus = VIntp[6].GetX();
05712                                     //
05713                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]);
05714                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]);
05715                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]);
05716                                 }
05717                                 else {
05718                                     //
05719                                     // Interpotation Data
05720                                     interpolationValNeg = 1.0 - VIntp[7].GetX();
05721                                     //
05722                                     vertexList[ 6] = V[6] + interpolationValNeg*(V[7] - V[6]);
05723                                     grad[6]        = G[6] + interpolationValNeg*(G[7] - G[6]);
05724                                     texCoordList[6] = VTC[6] + interpolationValNeg*(VTC[7] - VTC[6]);
05725                                     //grad[6] *= -1.0;
05726                                 }
05727                                 grad[6].Normalized();
05728                             }
05729                             if ( EdgeTable[cubeClass] & 128 ) {
05730                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
05731                                     //
05732                                     // Interpotation Data
05733                                     interpolationValPlus = VIntp[4].GetY();
05734                                     //
05735                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]);
05736                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]);
05737                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]);
05738                                     //grad[7][1] *= -1.0;
05739                                 }
05740                                 else {
05741                                     //
05742                                     // Interpotation Data
05743                                     interpolationValNeg = 1.0 - VIntp[7].GetY();
05744                                     //
05745                                     vertexList[ 7] = V[4] + interpolationValNeg*(V[7] - V[4]);
05746                                     grad[7]        = G[4] + interpolationValNeg*(G[7] - G[4]);
05747                                     texCoordList[7] = VTC[4] + interpolationValNeg*(VTC[7] - VTC[4]);
05748                                 }
05749                                 grad[7].Normalized();
05750                             }
05751                             if ( EdgeTable[cubeClass] & 256 ) {
05752                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05753                                     //
05754                                     // Interpotation Data
05755                                     interpolationValPlus = VIntp[0].GetZ();
05756                                     //
05757                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]);
05758                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]);
05759                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]);
05760                                 }
05761                                 else {
05762                                     //
05763                                     // Interpotation Data
05764                                     interpolationValNeg = 1.0 - VIntp[4].GetZ();
05765                                     //
05766                                     vertexList[ 8] = V[0] + interpolationValNeg*(V[4] - V[0]);
05767                                     grad[8]        = G[0] + interpolationValNeg*(G[4] - G[0]);
05768                                     texCoordList[8] = VTC[0] + interpolationValNeg*(VTC[4] - VTC[0]);
05769                                     //grad[8][2] *= -1.0;
05770                                 }
05771                                 grad[8].Normalized();
05772                             }
05773                             if ( EdgeTable[cubeClass] & 512 ) {
05774                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
05775                                     //
05776                                     // Interpotation Data
05777                                     interpolationValPlus = VIntp[1].GetZ();
05778                                     //
05779                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]);
05780                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]);
05781                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]);
05782                                 }
05783                                 else {
05784                                     //
05785                                     // Interpotation Data
05786                                     interpolationValNeg = 1.0 - VIntp[5].GetZ();
05787                                     //
05788                                     vertexList[ 9] = V[1] + interpolationValNeg*(V[5] - V[1]);
05789                                     grad[9]        = G[1] + interpolationValNeg*(G[5] - G[1]);
05790                                     texCoordList[9] = VTC[1] + interpolationValNeg*(VTC[5] - VTC[1]);
05791                                     //grad[9][2] *= -1.0;
05792                                 }
05793                                 grad[9].Normalized();
05794                             }
05795                             if ( EdgeTable[cubeClass] & 1024 ) {
05796                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
05797                                     //
05798                                     // Interpotation Data
05799                                     interpolationValPlus = VIntp[2].GetZ();
05800                                     //
05801                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]);
05802                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]);
05803                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]);
05804                                 }
05805                                 else {
05806                                     //
05807                                     // Interpotation Data
05808                                     interpolationValNeg = 1.0 - VIntp[6].GetZ();
05809                                     //
05810                                     vertexList[10] = V[2] + interpolationValNeg*(V[6] - V[2]);
05811                                     grad[10]       = G[2] + interpolationValNeg*(G[6] - G[2]);
05812                                     texCoordList[10] = VTC[2] + interpolationValNeg*(VTC[6] - VTC[2]);
05813                                     //grad[10][2] *= -1.0;
05814                                 }
05815                                 grad[10].Normalized();
05816                             }
05817                             if ( EdgeTable[cubeClass] & 2048 ) {
05818                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
05819                                     //
05820                                     // Interpotation Data
05821                                     interpolationValPlus = VIntp[3].GetZ();
05822                                     //
05823                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]);
05824                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]);
05825                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]);
05826                                 }
05827                                 else {
05828                                     //
05829                                     // Interpotation Data
05830                                     interpolationValNeg = 1.0 - VIntp[7].GetZ();
05831                                     //
05832                                     vertexList[11] = V[3] + interpolationValNeg*(V[7] - V[3]);
05833                                     grad[11]       = G[3] + interpolationValNeg*(G[7] - G[3]);
05834                                     texCoordList[11] = VTC[3] + interpolationValNeg*(VTC[7] - VTC[3]);
05835                                     //grad[11][2] *= -1.0;
05836                                 }
05837                                 grad[11].Normalized();
05838                             }
05839                             //---------------------------------------
05840                             //=======================================
05841                             //***************************************
05842                             //*/
05843 
05844 
05845 
05846 // START DEBUGGING
05848                             /*
05849                             //***************************************
05850                             // Fixed Distance Interpolation
05851                             //=======================================
05852                             //---------------------------------------
05853                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
05854 //if ( iIterate >= 2 ) 
05855 {
05856                             if ( EdgeTable[cubeClass] & 1 ) {
05857                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05858                                     //
05859                                     // Interpotation Data
05860                                     interpolationValPlus = VIntp[0].GetX();
05861                                     //
05862                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05863                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05864                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05865                                 }
05866                                 else {
05867                                     //
05868                                     // Interpotation Data
05869                                     interpolationValNeg = -VIntp[1].GetX();
05870                                     //
05871                                     vertexList[ 0] = V[1] + interpolationValNeg*(V[1] - V[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05872                                     grad[0]        = G[1] + interpolationValNeg*(G[1] - G[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05873                                     texCoordList[0] = VTC[1] + interpolationValNeg*(VTC[1] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[0];
05874                                 }
05875                                 grad[0].Normalized();
05876                             }
05877                             if ( EdgeTable[cubeClass] & 2 ) {
05878                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
05879                                     //
05880                                     // Interpotation Data
05881                                     interpolationValPlus = VIntp[1].GetY();
05882                                     //
05883                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05884                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05885                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05886                                 }
05887                                 else {
05888                                     //
05889                                     // Interpotation Data
05890                                     interpolationValNeg = -VIntp[2].GetY();
05891                                     //
05892                                     vertexList[ 1] = V[2] + interpolationValNeg*(V[2] - V[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05893                                     grad[1]        = G[2] + interpolationValNeg*(G[2] - G[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05894                                     texCoordList[1] = VTC[2] + interpolationValNeg*(VTC[2] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[1];
05895                                 }
05896                                 grad[1].Normalized();
05897                             }
05898                             if ( EdgeTable[cubeClass] & 4 ) {
05899                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
05900                                     //
05901                                     // Interpotation Data
05902                                     interpolationValPlus = VIntp[2].GetX();
05903                                     //
05904                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05905                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05906                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05907                                 }
05908                                 else {
05909                                     //
05910                                     // Interpotation Data
05911                                     interpolationValNeg = -VIntp[3].GetX();
05912                                     //
05913                                     vertexList[ 2] = V[3] + interpolationValNeg*(V[3] - V[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05914                                     grad[2]        = G[3] + interpolationValNeg*(G[3] - G[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05915                                     texCoordList[2] = VTC[3] + interpolationValNeg*(VTC[3] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[0];
05916                                 }
05917                                 grad[2].Normalized();
05918                             }
05919                             if ( EdgeTable[cubeClass] & 8 ) {
05920                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
05921                                     //
05922                                     // Interpotation Data
05923                                     interpolationValPlus = VIntp[0].GetY();
05924                                     //
05925                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05926                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05927                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05928                                 }
05929                                 else {
05930                                     //
05931                                     // Interpotation Data
05932                                     interpolationValNeg = -VIntp[3].GetY();
05933                                     //
05934                                     vertexList[ 3] = V[3] + interpolationValNeg*(V[3] - V[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05935                                     grad[3]        = G[3] + interpolationValNeg*(G[3] - G[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05936                                     texCoordList[3] = VTC[3] + interpolationValNeg*(VTC[3] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[1];
05937                                 }
05938                                 grad[3].Normalized();
05939                             }
05940                             if ( EdgeTable[cubeClass] & 16 ) {
05941                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
05942                                     //
05943                                     // Interpotation Data
05944                                     interpolationValPlus = VIntp[4].GetX();
05945                                     //
05946                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05947                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05948                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05949                                 }
05950                                 else {
05951                                     //
05952                                     // Interpotation Data
05953                                     interpolationValNeg = -VIntp[5].GetX();
05954                                     //
05955                                     vertexList[ 4] = V[5] + interpolationValNeg*(V[5] - V[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05956                                     grad[4]        = G[5] + interpolationValNeg*(G[5] - G[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05957                                     texCoordList[4] = VTC[5] + interpolationValNeg*(VTC[5] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[0];
05958                                 }
05959                                 grad[4].Normalized();
05960                             }
05961                             if ( EdgeTable[cubeClass] & 32 ) {
05962                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
05963                                     //
05964                                     // Interpotation Data
05965                                     interpolationValPlus = VIntp[5].GetY();
05966                                     //
05967                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05968                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05969                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05970                                 }
05971                                 else {
05972                                     //
05973                                     // Interpotation Data
05974                                     interpolationValNeg = -VIntp[6].GetY();
05975                                     //
05976                                     vertexList[ 5] = V[6] + interpolationValNeg*(V[6] - V[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05977                                     grad[5]        = G[6] + interpolationValNeg*(G[6] - G[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05978                                     texCoordList[5] = VTC[6] + interpolationValNeg*(VTC[6] - VTC[5]);//.Normalized()*CUBE_DIMENSIONS[1];
05979                                 }
05980                                 grad[5].Normalized();
05981                             }
05982                             if ( EdgeTable[cubeClass] & 64 ) {
05983                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
05984                                     //
05985                                     // Interpotation Data
05986                                     interpolationValPlus = VIntp[6].GetX();
05987                                     //
05988                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05989                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05990                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05991                                 }
05992                                 else {
05993                                     //
05994                                     // Interpotation Data
05995                                     interpolationValNeg = -VIntp[7].GetX();
05996                                     //
05997                                     vertexList[ 6] = V[7] + interpolationValNeg*(V[7] - V[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05998                                     grad[6]        = G[7] + interpolationValNeg*(G[7] - G[6]);//.Normalized()*CUBE_DIMENSIONS[0];
05999                                     texCoordList[6] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[6]);//.Normalized()*CUBE_DIMENSIONS[0];
06000                                 }
06001                                 grad[6].Normalized();
06002                             }
06003                             if ( EdgeTable[cubeClass] & 128 ) {
06004                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06005                                     //
06006                                     // Interpotation Data
06007                                     interpolationValPlus = VIntp[4].GetY();
06008                                     //
06009                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]);//.Normalized()*CUBE_DIMENSIONS[1];
06010                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]);//.Normalized()*CUBE_DIMENSIONS[1];
06011                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[1];
06012                                 }
06013                                 else {
06014                                     //
06015                                     // Interpotation Data
06016                                     interpolationValNeg = -VIntp[7].GetY();
06017                                     //
06018                                     vertexList[ 7] = V[7] + interpolationValNeg*(V[7] - V[4]);//.Normalized()*CUBE_DIMENSIONS[1];
06019                                     grad[7]        = G[7] + interpolationValNeg*(G[7] - G[4]);//.Normalized()*CUBE_DIMENSIONS[1];
06020                                     texCoordList[7] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[4]);//.Normalized()*CUBE_DIMENSIONS[1];
06021                                 }
06022                                 grad[7].Normalized();
06023                             }
06024                             if ( EdgeTable[cubeClass] & 256 ) {
06025                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06026                                     //
06027                                     // Interpotation Data
06028                                     interpolationValPlus = VIntp[0].GetZ();
06029                                     //
06030                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]);//.Normalized()*CUBE_DIMENSIONS[2];
06031                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]);//.Normalized()*CUBE_DIMENSIONS[2];
06032                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[2];
06033                                 }
06034                                 else {
06035                                     //
06036                                     // Interpotation Data
06037                                     interpolationValNeg = -VIntp[4].GetZ();
06038                                     //
06039                                     vertexList[ 8] = V[4] + interpolationValNeg*(V[4] - V[0]);//.Normalized()*CUBE_DIMENSIONS[2];
06040                                     grad[8]        = G[4] + interpolationValNeg*(G[4] - G[0]);//.Normalized()*CUBE_DIMENSIONS[2];
06041                                     texCoordList[8] = VTC[4] + interpolationValNeg*(VTC[4] - VTC[0]);//.Normalized()*CUBE_DIMENSIONS[2];
06042                                 }
06043                                 grad[8].Normalized();
06044                             }
06045                             if ( EdgeTable[cubeClass] & 512 ) {
06046                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06047                                     //
06048                                     // Interpotation Data
06049                                     interpolationValPlus = VIntp[1].GetZ();
06050                                     //
06051                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]);//.Normalized()*CUBE_DIMENSIONS[2];
06052                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]);//.Normalized()*CUBE_DIMENSIONS[2];
06053                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[2];
06054                                 }
06055                                 else {
06056                                     //
06057                                     // Interpotation Data
06058                                     interpolationValNeg = -VIntp[5].GetZ();
06059                                     //
06060                                     vertexList[ 9] = V[5] + interpolationValNeg*(V[5] - V[1]);//.Normalized()*CUBE_DIMENSIONS[2];
06061                                     grad[9]        = G[5] + interpolationValNeg*(G[5] - G[1]);//.Normalized()*CUBE_DIMENSIONS[2];
06062                                     texCoordList[9] = VTC[5] + interpolationValNeg*(VTC[5] - VTC[1]);//.Normalized()*CUBE_DIMENSIONS[2];
06063                                 }
06064                                 grad[9].Normalized();
06065                             }
06066                             if ( EdgeTable[cubeClass] & 1024 ) {
06067                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06068                                     //
06069                                     // Interpotation Data
06070                                     interpolationValPlus = VIntp[2].GetZ();
06071                                     //
06072                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]);//.Normalized()*CUBE_DIMENSIONS[2];
06073                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]);//.Normalized()*CUBE_DIMENSIONS[2];
06074                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[2];
06075                                 }
06076                                 else {
06077                                     //
06078                                     // Interpotation Data
06079                                     interpolationValNeg = -VIntp[6].GetZ();
06080                                     //
06081                                     vertexList[10] = V[6] + interpolationValNeg*(V[6] - V[2]);//.Normalized()*CUBE_DIMENSIONS[2];
06082                                     grad[10]       = G[6] + interpolationValNeg*(G[6] - G[2]);//.Normalized()*CUBE_DIMENSIONS[2];
06083                                     texCoordList[10] = VTC[6] + interpolationValNeg*(VTC[6] - VTC[2]);//.Normalized()*CUBE_DIMENSIONS[2];
06084                                 }
06085                                 grad[10].Normalized();
06086                             }
06087                             if ( EdgeTable[cubeClass] & 2048 ) {
06088                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
06089                                     //
06090                                     // Interpotation Data
06091                                     interpolationValPlus = VIntp[3].GetZ();
06092                                     //
06093                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]);//.Normalized()*CUBE_DIMENSIONS[2];
06094                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]);//.Normalized()*CUBE_DIMENSIONS[2];
06095                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]);//.Normalized()*CUBE_DIMENSIONS[2];
06096                                 }
06097                                 else {
06098                                     //
06099                                     // Interpotation Data
06100                                     interpolationValNeg = -VIntp[7].GetZ();
06101                                     //
06102                                     vertexList[11] = V[7] + interpolationValNeg*(V[7] - V[3]);//.Normalized()*CUBE_DIMENSIONS[2];
06103                                     grad[11]       = G[7] + interpolationValNeg*(G[7] - G[3]);//.Normalized()*CUBE_DIMENSIONS[2];
06104                                     texCoordList[11] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[3]);//.Normalized()*CUBE_DIMENSIONS[2];
06105                                 }
06106                                 grad[11].Normalized();
06107                             }
06108 } // End processing normal cube
06109                             //---------------------------------------
06110                             //=======================================
06111                             //***************************************
06112                             //*/
06114 // END DEBUGGING
06115 
06116 
06117 //std::cout << "(V[1] - V[0]).Normalized(): " << (V[1] - V[0]).Normalized() << std::endl;
06118 //std::cout << "(V[1] - V[0]).Normalized().Length(): " << (V[1] - V[0]).Normalized().Length() << std::endl;;
06119 
06120                             //*
06121                             //***************************************
06122                             // Fixed Distance Interpolation
06123                             //=======================================
06124                             //---------------------------------------
06125                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
06126 //else {
06127 if ( iIterate < 2 ) {
06128                             //interpolationValPlus = m_tGlobalInterpolationVal;
06129                             //interpolationValNeg  = m_tGlobalInterpolationVal - 1.0;
06130 
06131                             if ( EdgeTable[cubeClass] & 1 ) {
06132                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06133                                     //
06134                                     // Interpotation Data
06135                                     interpolationValPlus = VIntp[0].GetX();
06136                                     //
06137                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]).Normalized()*CUBE_DIMENSIONS[0];
06138                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]).Normalized()*CUBE_DIMENSIONS[0];
06139                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]).Normalized()*CUBE_DIMENSIONS[0];
06140                                 }
06141                                 else {
06142                                     //
06143                                     // Interpotation Data
06144                                     interpolationValNeg = -VIntp[1].GetX();
06145                                     //
06146                                     vertexList[ 0] = V[1] + interpolationValNeg*(V[1] - V[0]).Normalized()*CUBE_DIMENSIONS[0];
06147                                     grad[0]        = G[1] + interpolationValNeg*(G[1] - G[0]).Normalized()*CUBE_DIMENSIONS[0];
06148                                     texCoordList[0] = VTC[1] + interpolationValNeg*(VTC[1] - VTC[0]).Normalized()*CUBE_DIMENSIONS[0];
06149                                 }
06150                                 grad[0].Normalized();
06151                             }
06152                             if ( EdgeTable[cubeClass] & 2 ) {
06153                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06154                                     //
06155                                     // Interpotation Data
06156                                     interpolationValPlus = VIntp[1].GetY();
06157                                     //
06158                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]).Normalized()*CUBE_DIMENSIONS[1];
06159                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]).Normalized()*CUBE_DIMENSIONS[1];
06160                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]).Normalized()*CUBE_DIMENSIONS[1];
06161                                 }
06162                                 else {
06163                                     //
06164                                     // Interpotation Data
06165                                     interpolationValNeg = -VIntp[2].GetY();
06166                                     //
06167                                     vertexList[ 1] = V[2] + interpolationValNeg*(V[2] - V[1]).Normalized()*CUBE_DIMENSIONS[1];
06168                                     grad[1]        = G[2] + interpolationValNeg*(G[2] - G[1]).Normalized()*CUBE_DIMENSIONS[1];
06169                                     texCoordList[1] = VTC[2] + interpolationValNeg*(VTC[2] - VTC[1]).Normalized()*CUBE_DIMENSIONS[1];
06170                                 }
06171                                 grad[1].Normalized();
06172                             }
06173                             if ( EdgeTable[cubeClass] & 4 ) {
06174                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06175                                     //
06176                                     // Interpotation Data
06177                                     interpolationValPlus = VIntp[2].GetX();
06178                                     //
06179                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]).Normalized()*CUBE_DIMENSIONS[0];
06180                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]).Normalized()*CUBE_DIMENSIONS[0];
06181                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]).Normalized()*CUBE_DIMENSIONS[0];
06182                                 }
06183                                 else {
06184                                     //
06185                                     // Interpotation Data
06186                                     interpolationValNeg = -VIntp[3].GetX();
06187                                     //
06188                                     vertexList[ 2] = V[3] + interpolationValNeg*(V[3] - V[2]).Normalized()*CUBE_DIMENSIONS[0];
06189                                     grad[2]        = G[3] + interpolationValNeg*(G[3] - G[2]).Normalized()*CUBE_DIMENSIONS[0];
06190                                     texCoordList[2] = VTC[3] + interpolationValNeg*(VTC[3] - VTC[2]).Normalized()*CUBE_DIMENSIONS[0];
06191                                 }
06192                                 grad[2].Normalized();
06193                             }
06194                             if ( EdgeTable[cubeClass] & 8 ) {
06195                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06196                                     //
06197                                     // Interpotation Data
06198                                     interpolationValPlus = VIntp[0].GetY();
06199                                     //
06200                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]).Normalized()*CUBE_DIMENSIONS[1];
06201                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]).Normalized()*CUBE_DIMENSIONS[1];
06202                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]).Normalized()*CUBE_DIMENSIONS[1];
06203                                 }
06204                                 else {
06205                                     //
06206                                     // Interpotation Data
06207                                     interpolationValNeg = -VIntp[3].GetY();
06208                                     //
06209                                     vertexList[ 3] = V[3] + interpolationValNeg*(V[3] - V[0]).Normalized()*CUBE_DIMENSIONS[1];
06210                                     grad[3]        = G[3] + interpolationValNeg*(G[3] - G[0]).Normalized()*CUBE_DIMENSIONS[1];
06211                                     texCoordList[3] = VTC[3] + interpolationValNeg*(VTC[3] - VTC[0]).Normalized()*CUBE_DIMENSIONS[1];
06212                                 }
06213                                 grad[3].Normalized();
06214                             }
06215                             if ( EdgeTable[cubeClass] & 16 ) {
06216                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06217                                     //
06218                                     // Interpotation Data
06219                                     interpolationValPlus = VIntp[4].GetX();
06220                                     //
06221                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]).Normalized()*CUBE_DIMENSIONS[0];
06222                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]).Normalized()*CUBE_DIMENSIONS[0];
06223                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]).Normalized()*CUBE_DIMENSIONS[0];
06224                                 }
06225                                 else {
06226                                     //
06227                                     // Interpotation Data
06228                                     interpolationValNeg = -VIntp[5].GetX();
06229                                     //
06230                                     vertexList[ 4] = V[5] + interpolationValNeg*(V[5] - V[4]).Normalized()*CUBE_DIMENSIONS[0];
06231                                     grad[4]        = G[5] + interpolationValNeg*(G[5] - G[4]).Normalized()*CUBE_DIMENSIONS[0];
06232                                     texCoordList[4] = VTC[5] + interpolationValNeg*(VTC[5] - VTC[4]).Normalized()*CUBE_DIMENSIONS[0];
06233                                 }
06234                                 grad[4].Normalized();
06235                             }
06236                             if ( EdgeTable[cubeClass] & 32 ) {
06237                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
06238                                     //
06239                                     // Interpotation Data
06240                                     interpolationValPlus = VIntp[5].GetY();
06241                                     //
06242                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]).Normalized()*CUBE_DIMENSIONS[1];
06243                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]).Normalized()*CUBE_DIMENSIONS[1];
06244                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]).Normalized()*CUBE_DIMENSIONS[1];
06245                                 }
06246                                 else {
06247                                     //
06248                                     // Interpotation Data
06249                                     interpolationValNeg = -VIntp[6].GetY();
06250                                     //
06251                                     vertexList[ 5] = V[6] + interpolationValNeg*(V[6] - V[5]).Normalized()*CUBE_DIMENSIONS[1];
06252                                     grad[5]        = G[6] + interpolationValNeg*(G[6] - G[5]).Normalized()*CUBE_DIMENSIONS[1];
06253                                     texCoordList[5] = VTC[6] + interpolationValNeg*(VTC[6] - VTC[5]).Normalized()*CUBE_DIMENSIONS[1];
06254                                 }
06255                                 grad[5].Normalized();
06256                             }
06257                             if ( EdgeTable[cubeClass] & 64 ) {
06258                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
06259                                     //
06260                                     // Interpotation Data
06261                                     interpolationValPlus = VIntp[6].GetX();
06262                                     //
06263                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]).Normalized()*CUBE_DIMENSIONS[0];
06264                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]).Normalized()*CUBE_DIMENSIONS[0];
06265                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]).Normalized()*CUBE_DIMENSIONS[0];
06266                                 }
06267                                 else {
06268                                     //
06269                                     // Interpotation Data
06270                                     interpolationValNeg = -VIntp[7].GetX();
06271                                     //
06272                                     vertexList[ 6] = V[7] + interpolationValNeg*(V[7] - V[6]).Normalized()*CUBE_DIMENSIONS[0];
06273                                     grad[6]        = G[7] + interpolationValNeg*(G[7] - G[6]).Normalized()*CUBE_DIMENSIONS[0];
06274                                     texCoordList[6] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[6]).Normalized()*CUBE_DIMENSIONS[0];
06275                                 }
06276                                 grad[6].Normalized();
06277                             }
06278                             if ( EdgeTable[cubeClass] & 128 ) {
06279                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06280                                     //
06281                                     // Interpotation Data
06282                                     interpolationValPlus = VIntp[4].GetY();
06283                                     //
06284                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]).Normalized()*CUBE_DIMENSIONS[1];
06285                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]).Normalized()*CUBE_DIMENSIONS[1];
06286                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]).Normalized()*CUBE_DIMENSIONS[1];
06287                                 }
06288                                 else {
06289                                     //
06290                                     // Interpotation Data
06291                                     interpolationValNeg = -VIntp[7].GetY();
06292                                     //
06293                                     vertexList[ 7] = V[7] + interpolationValNeg*(V[7] - V[4]).Normalized()*CUBE_DIMENSIONS[1];
06294                                     grad[7]        = G[7] + interpolationValNeg*(G[7] - G[4]).Normalized()*CUBE_DIMENSIONS[1];
06295                                     texCoordList[7] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[4]).Normalized()*CUBE_DIMENSIONS[1];
06296                                 }
06297                                 grad[7].Normalized();
06298                             }
06299                             if ( EdgeTable[cubeClass] & 256 ) {
06300                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06301                                     //
06302                                     // Interpotation Data
06303                                     interpolationValPlus = VIntp[0].GetZ();
06304                                     //
06305                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]).Normalized()*CUBE_DIMENSIONS[2];
06306                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]).Normalized()*CUBE_DIMENSIONS[2];
06307                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]).Normalized()*CUBE_DIMENSIONS[2];
06308                                 }
06309                                 else {
06310                                     //
06311                                     // Interpotation Data
06312                                     interpolationValNeg = -VIntp[4].GetZ();
06313                                     //
06314                                     vertexList[ 8] = V[4] + interpolationValNeg*(V[4] - V[0]).Normalized()*CUBE_DIMENSIONS[2];
06315                                     grad[8]        = G[4] + interpolationValNeg*(G[4] - G[0]).Normalized()*CUBE_DIMENSIONS[2];
06316                                     texCoordList[8] = VTC[4] + interpolationValNeg*(VTC[4] - VTC[0]).Normalized()*CUBE_DIMENSIONS[2];
06317                                 }
06318                                 grad[8].Normalized();
06319                             }
06320                             if ( EdgeTable[cubeClass] & 512 ) {
06321                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06322                                     //
06323                                     // Interpotation Data
06324                                     interpolationValPlus = VIntp[1].GetZ();
06325                                     //
06326                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]).Normalized()*CUBE_DIMENSIONS[2];
06327                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]).Normalized()*CUBE_DIMENSIONS[2];
06328                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]).Normalized()*CUBE_DIMENSIONS[2];
06329                                 }
06330                                 else {
06331                                     //
06332                                     // Interpotation Data
06333                                     interpolationValNeg = -VIntp[5].GetZ();
06334                                     //
06335                                     vertexList[ 9] = V[5] + interpolationValNeg*(V[5] - V[1]).Normalized()*CUBE_DIMENSIONS[2];
06336                                     grad[9]        = G[5] + interpolationValNeg*(G[5] - G[1]).Normalized()*CUBE_DIMENSIONS[2];
06337                                     texCoordList[9] = VTC[5] + interpolationValNeg*(VTC[5] - VTC[1]).Normalized()*CUBE_DIMENSIONS[2];
06338                                 }
06339                                 grad[9].Normalized();
06340                             }
06341                             if ( EdgeTable[cubeClass] & 1024 ) {
06342                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06343                                     //
06344                                     // Interpotation Data
06345                                     interpolationValPlus = VIntp[2].GetZ();
06346                                     //
06347                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]).Normalized()*CUBE_DIMENSIONS[2];
06348                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]).Normalized()*CUBE_DIMENSIONS[2];
06349                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]).Normalized()*CUBE_DIMENSIONS[2];
06350                                 }
06351                                 else {
06352                                     //
06353                                     // Interpotation Data
06354                                     interpolationValNeg = -VIntp[6].GetZ();
06355                                     //
06356                                     vertexList[10] = V[6] + interpolationValNeg*(V[6] - V[2]).Normalized()*CUBE_DIMENSIONS[2];
06357                                     grad[10]       = G[6] + interpolationValNeg*(G[6] - G[2]).Normalized()*CUBE_DIMENSIONS[2];
06358                                     texCoordList[10] = VTC[6] + interpolationValNeg*(VTC[6] - VTC[2]).Normalized()*CUBE_DIMENSIONS[2];
06359                                 }
06360                                 grad[10].Normalized();
06361                             }
06362                             if ( EdgeTable[cubeClass] & 2048 ) {
06363                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
06364                                     //
06365                                     // Interpotation Data
06366                                     interpolationValPlus = VIntp[3].GetZ();
06367                                     //
06368                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]).Normalized()*CUBE_DIMENSIONS[2];
06369                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]).Normalized()*CUBE_DIMENSIONS[2];
06370                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]).Normalized()*CUBE_DIMENSIONS[2];
06371                                 }
06372                                 else {
06373                                     //
06374                                     // Interpotation Data
06375                                     interpolationValNeg = -VIntp[7].GetZ();
06376                                     //
06377                                     vertexList[11] = V[7] + interpolationValNeg*(V[7] - V[3]).Normalized()*CUBE_DIMENSIONS[2];
06378                                     grad[11]       = G[7] + interpolationValNeg*(G[7] - G[3]).Normalized()*CUBE_DIMENSIONS[2];
06379                                     texCoordList[11] = VTC[7] + interpolationValNeg*(VTC[7] - VTC[3]).Normalized()*CUBE_DIMENSIONS[2];
06380                                 }
06381                                 grad[11].Normalized();
06382                             }
06383 } // End processing `left' or `right' cube
06384                             //---------------------------------------
06385                             //=======================================
06386                             //***************************************
06387                             //*/
06388 
06389                         } // END: Not Use Global Interpolation Value
06390 
06391 
06392                         //-----------------------------------------------
06393                         // Use Global Interpolation Value -- all elements have the same interpolation value
06394                         else {
06395                             //-------------------------------------
06396                             // Marching Cube Interpolation
06397                             T interpolationValPlus = m_tGlobalInterpolationVal;
06398                             T interpolationValNeg  = 1.0 - m_tGlobalInterpolationVal;
06399                             //T interpolationValPlus = 0.3;
06400                             //T interpolationValNeg  = 1.0 - 0.3;
06401 
06402 
06403                             /*
06404                             //***************************************
06405                             // Normal Interpolation
06406                             //=======================================
06407                             //---------------------------------------
06408                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
06409                             if ( EdgeTable[cubeClass] & 1 ) {
06410                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06411                                     //
06412                                     // Interpotation Data
06413                                     //interpolationValPlus = VIntp[0].GetX();
06414                                     //
06415                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]);
06416                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]);
06417                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]);
06418                                 }
06419                                 else {
06420                                     //
06421                                     // Interpotation Data
06422                                     //interpolationValNeg = 1.0 - VIntp[1].GetX();
06423                                     //
06424                                     vertexList[ 0] = V[0] + interpolationValNeg*(V[1] - V[0]);
06425                                     grad[0]        = G[0] + interpolationValNeg*(G[1] - G[0]);
06426                                     texCoordList[0] = VTC[0] + interpolationValNeg*(VTC[1] - VTC[0]);
06427                                 }
06428                                 grad[0].Normalized();
06429                             }
06430                             if ( EdgeTable[cubeClass] & 2 ) {
06431                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06432                                     //
06433                                     // Interpotation Data
06434                                     //interpolationValPlus = VIntp[1].GetY();
06435                                     //
06436                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]);
06437                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]);
06438                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]);
06439                                 }
06440                                 else {
06441                                     //
06442                                     // Interpotation Data
06443                                     //interpolationValNeg = 1.0 - VIntp[2].GetY();
06444                                     //
06445                                     vertexList[ 1] = V[1] + interpolationValNeg*(V[2] - V[1]);
06446                                     grad[1]        = G[1] + interpolationValNeg*(G[2] - G[1]);
06447                                     texCoordList[1] = VTC[1] + interpolationValNeg*(VTC[2] - VTC[1]);
06448                                 }
06449                                 grad[1].Normalized();
06450                             }
06451                             if ( EdgeTable[cubeClass] & 4 ) {
06452                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06453                                     //
06454                                     // Interpotation Data
06455                                     //interpolationValPlus = VIntp[2].GetX();
06456                                     //
06457                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]);
06458                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]);
06459                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]);
06460                                 }
06461                                 else {
06462                                     //
06463                                     // Interpotation Data
06464                                     //interpolationValNeg = 1.0 - VIntp[3].GetX();
06465                                     //
06466                                     vertexList[ 2] = V[2] + interpolationValNeg*(V[3] - V[2]);
06467                                     grad[2]        = G[2] + interpolationValNeg*(G[3] - G[2]);
06468                                     texCoordList[2] = VTC[2] + interpolationValNeg*(VTC[3] - VTC[2]);
06469                                 }
06470                                 grad[2].Normalized();
06471                             }
06472                             if ( EdgeTable[cubeClass] & 8 ) {
06473                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06474                                     //
06475                                     // Interpotation Data
06476                                     //interpolationValPlus = VIntp[0].GetY();
06477                                     //
06478                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]);
06479                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]);
06480                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]);
06481                                 }
06482                                 else {
06483                                     //
06484                                     // Interpotation Data
06485                                     //interpolationValNeg = 1.0 - VIntp[3].GetY();
06486                                     //
06487                                     vertexList[ 3] = V[0] + interpolationValNeg*(V[3] - V[0]);
06488                                     grad[3]        = G[0] + interpolationValNeg*(G[3] - G[0]);
06489                                     texCoordList[3] = VTC[0] + interpolationValNeg*(VTC[3] - VTC[0]);
06490                                 }
06491                                 grad[3].Normalized();
06492                             }
06493                             if ( EdgeTable[cubeClass] & 16 ) {
06494                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06495                                     //
06496                                     // Interpotation Data
06497                                     //interpolationValPlus = VIntp[4].GetX();
06498                                     //
06499                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]);
06500                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]);
06501                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]);
06502                                 }
06503                                 else {
06504                                     //
06505                                     // Interpotation Data
06506                                     //interpolationValNeg = 1.0 - VIntp[5].GetX();
06507                                     //
06508                                     vertexList[ 4] = V[4] + interpolationValNeg*(V[5] - V[4]);
06509                                     grad[4]        = G[4] + interpolationValNeg*(G[5] - G[4]);
06510                                     texCoordList[4] = VTC[4] + interpolationValNeg*(VTC[5] - VTC[4]);
06511                                 }
06512                                 grad[4].Normalized();
06513                             }
06514                             if ( EdgeTable[cubeClass] & 32 ) {
06515                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
06516                                     //
06517                                     // Interpotation Data
06518                                     //interpolationValPlus = VIntp[5].GetY();
06519                                     //
06520                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]);
06521                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]);
06522                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]);
06523                                 }
06524                                 else {
06525                                     //
06526                                     // Interpotation Data
06527                                     //interpolationValNeg = 1.0 - VIntp[6].GetY();
06528                                     //
06529                                     vertexList[ 5] = V[5] + interpolationValNeg*(V[6] - V[5]);
06530                                     grad[5]        = G[5] + interpolationValNeg*(G[6] - G[5]);
06531                                     texCoordList[5] = VTC[5] + interpolationValNeg*(VTC[6] - VTC[5]);
06532                                 }
06533                                 grad[5].Normalized();
06534                             }
06535                             if ( EdgeTable[cubeClass] & 64 ) {
06536                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
06537                                     //
06538                                     // Interpotation Data
06539                                     //interpolationValPlus = VIntp[6].GetX();
06540                                     //
06541                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]);
06542                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]);
06543                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]);
06544                                 }
06545                                 else {
06546                                     //
06547                                     // Interpotation Data
06548                                     //interpolationValNeg = 1.0 - VIntp[7].GetX();
06549                                     //
06550                                     vertexList[ 6] = V[6] + interpolationValNeg*(V[7] - V[6]);
06551                                     grad[6]        = G[6] + interpolationValNeg*(G[7] - G[6]);
06552                                     texCoordList[6] = VTC[6] + interpolationValNeg*(VTC[7] - VTC[6]);
06553                                 }
06554                                 grad[6].Normalized();
06555                             }
06556                             if ( EdgeTable[cubeClass] & 128 ) {
06557                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06558                                     //
06559                                     // Interpotation Data
06560                                     //interpolationValPlus = VIntp[4].GetY();
06561                                     //
06562                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]);
06563                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]);
06564                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]);
06565                                 }
06566                                 else {
06567                                     //
06568                                     // Interpotation Data
06569                                     //interpolationValNeg = 1.0 - VIntp[7].GetY();
06570                                     //
06571                                     vertexList[ 7] = V[4] + interpolationValNeg*(V[7] - V[4]);
06572                                     grad[7]        = G[4] + interpolationValNeg*(G[7] - G[4]);
06573                                     texCoordList[7] = VTC[4] + interpolationValNeg*(VTC[7] - VTC[4]);
06574                                 }
06575                                 grad[7].Normalized();
06576                             }
06577                             if ( EdgeTable[cubeClass] & 256 ) {
06578                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06579                                     //
06580                                     // Interpotation Data
06581                                     //interpolationValPlus = VIntp[0].GetZ();
06582                                     //
06583                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]);
06584                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]);
06585                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]);
06586                                 }
06587                                 else {
06588                                     //
06589                                     // Interpotation Data
06590                                     //interpolationValNeg = 1.0 - VIntp[4].GetZ();
06591                                     //
06592                                     vertexList[ 8] = V[0] + interpolationValNeg*(V[4] - V[0]);
06593                                     grad[8]        = G[0] + interpolationValNeg*(G[4] - G[0]);
06594                                     texCoordList[8] = VTC[0] + interpolationValNeg*(VTC[4] - VTC[0]);
06595                                 }
06596                                 grad[8].Normalized();
06597                             }
06598                             if ( EdgeTable[cubeClass] & 512 ) {
06599                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06600                                     //
06601                                     // Interpotation Data
06602                                     //interpolationValPlus = VIntp[1].GetZ();
06603                                     //
06604                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]);
06605                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]);
06606                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]);
06607                                 }
06608                                 else {
06609                                     //
06610                                     // Interpotation Data
06611                                     //interpolationValNeg = 1.0 - VIntp[5].GetZ();
06612                                     //
06613                                     vertexList[ 9] = V[1] + interpolationValNeg*(V[5] - V[1]);
06614                                     grad[9]        = G[1] + interpolationValNeg*(G[5] - G[1]);
06615                                     texCoordList[9] = VTC[1] + interpolationValNeg*(VTC[5] - VTC[1]);
06616                                 }
06617                                 grad[9].Normalized();
06618                             }
06619                             if ( EdgeTable[cubeClass] & 1024 ) {
06620                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06621                                     //
06622                                     // Interpotation Data
06623                                     //interpolationValPlus = VIntp[2].GetZ();
06624                                     //
06625                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]);
06626                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]);
06627                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]);
06628                                 }
06629                                 else {
06630                                     //
06631                                     // Interpotation Data
06632                                     //interpolationValNeg = 1.0 - VIntp[6].GetZ();
06633                                     //
06634                                     vertexList[10] = V[2] + interpolationValNeg*(V[6] - V[2]);
06635                                     grad[10]       = G[2] + interpolationValNeg*(G[6] - G[2]);
06636                                     texCoordList[10] = VTC[2] + interpolationValNeg*(VTC[6] - VTC[2]);
06637                                 }
06638                                 grad[10].Normalized();
06639                             }
06640                             if ( EdgeTable[cubeClass] & 2048 ) {
06641                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
06642                                     //
06643                                     // Interpotation Data
06644                                     //interpolationValPlus = VIntp[3].GetZ();
06645                                     //
06646                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]);
06647                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]);
06648                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]);
06649                                 }
06650                                 else {
06651                                     //
06652                                     // Interpotation Data
06653                                     //interpolationValNeg = 1.0 - VIntp[7].GetZ();
06654                                     //
06655                                     vertexList[11] = V[3] + interpolationValNeg*(V[7] - V[3]);
06656                                     grad[11]       = G[3] + interpolationValNeg*(G[7] - G[3]);
06657                                     texCoordList[11] = VTC[3] + interpolationValNeg*(VTC[7] - VTC[3]);
06658                                 }
06659                                 grad[11].Normalized();
06660                             }
06661                             //---------------------------------------
06662                             //=======================================
06663                             //***************************************
06664                             //*/
06665 
06666 
06667 
06668                             //*
06669                             //***************************************
06670                             // Fixed Distance Interpolation
06671                             //=======================================
06672                             //---------------------------------------
06673                             // Edge# 0 to 11 <==> [ 1, 2, 4, ... , 2048 ]
06674                             if ( EdgeTable[cubeClass] & 1 ) {
06675                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06676                                     //
06677                                     // Interpotation Data
06678                                     //interpolationValPlus = VIntp[0].GetX();
06679                                     //
06680                                     vertexList[ 0] = V[0] + interpolationValPlus*(V[1] - V[0]).Normalized()*CUBE_DIMENSIONS[0];
06681                                     grad[0]        = G[0] + interpolationValPlus*(G[1] - G[0]).Normalized()*CUBE_DIMENSIONS[0];
06682                                     texCoordList[0] = VTC[0] + interpolationValPlus*(VTC[1] - VTC[0]).Normalized()*CUBE_DIMENSIONS[0];
06683                                 }
06684                                 else {
06685                                     //
06686                                     // Interpotation Data
06687                                     //interpolationValPlus = 1.0 - VIntp[1].GetX();
06688                                     //
06689                                     vertexList[ 0] = V[1] - interpolationValPlus*(V[1] - V[0]).Normalized()*CUBE_DIMENSIONS[0];
06690                                     grad[0]        = G[1] - interpolationValPlus*(G[1] - G[0]).Normalized()*CUBE_DIMENSIONS[0];
06691                                     texCoordList[0] = VTC[1] - interpolationValPlus*(VTC[1] - VTC[0]).Normalized()*CUBE_DIMENSIONS[0];
06692                                 }
06693                                 grad[0].Normalized();
06694                             }
06695                             if ( EdgeTable[cubeClass] & 2 ) {
06696                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06697                                     //
06698                                     // Interpotation Data
06699                                     //interpolationValPlus = VIntp[1].GetY();
06700                                     //
06701                                     vertexList[ 1] = V[1] + interpolationValPlus*(V[2] - V[1]).Normalized()*CUBE_DIMENSIONS[1];
06702                                     grad[1]        = G[1] + interpolationValPlus*(G[2] - G[1]).Normalized()*CUBE_DIMENSIONS[1];
06703                                     texCoordList[1] = VTC[1] + interpolationValPlus*(VTC[2] - VTC[1]).Normalized()*CUBE_DIMENSIONS[1];
06704                                 }
06705                                 else {
06706                                     //
06707                                     // Interpotation Data
06708                                     //interpolationValPlus = 1.0 - VIntp[2].GetY();
06709                                     //
06710                                     vertexList[ 1] = V[2] - interpolationValPlus*(V[2] - V[1]).Normalized()*CUBE_DIMENSIONS[1];
06711                                     grad[1]        = G[2] - interpolationValPlus*(G[2] - G[1]).Normalized()*CUBE_DIMENSIONS[1];
06712                                     texCoordList[1] = VTC[2] - interpolationValPlus*(VTC[2] - VTC[1]).Normalized()*CUBE_DIMENSIONS[1];
06713                                 }
06714                                 grad[1].Normalized();
06715                             }
06716                             if ( EdgeTable[cubeClass] & 4 ) {
06717                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06718                                     //
06719                                     // Interpotation Data
06720                                     //interpolationValPlus = VIntp[2].GetX();
06721                                     //
06722                                     vertexList[ 2] = V[2] + interpolationValPlus*(V[3] - V[2]).Normalized()*CUBE_DIMENSIONS[0];
06723                                     grad[2]        = G[2] + interpolationValPlus*(G[3] - G[2]).Normalized()*CUBE_DIMENSIONS[0];
06724                                     texCoordList[2] = VTC[2] + interpolationValPlus*(VTC[3] - VTC[2]).Normalized()*CUBE_DIMENSIONS[0];
06725                                 }
06726                                 else {
06727                                     //
06728                                     // Interpotation Data
06729                                     //interpolationValPlus = 1.0 - VIntp[3].GetX();
06730                                     //
06731                                     vertexList[ 2] = V[3] - interpolationValPlus*(V[3] - V[2]).Normalized()*CUBE_DIMENSIONS[0];
06732                                     grad[2]        = G[3] - interpolationValPlus*(G[3] - G[2]).Normalized()*CUBE_DIMENSIONS[0];
06733                                     texCoordList[2] = VTC[3] - interpolationValPlus*(VTC[3] - VTC[2]).Normalized()*CUBE_DIMENSIONS[0];
06734                                 }
06735                                 grad[2].Normalized();
06736                             }
06737                             if ( EdgeTable[cubeClass] & 8 ) {
06738                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06739                                     //
06740                                     // Interpotation Data
06741                                     //interpolationValPlus = VIntp[0].GetY();
06742                                     //
06743                                     vertexList[ 3] = V[0] + interpolationValPlus*(V[3] - V[0]).Normalized()*CUBE_DIMENSIONS[1];
06744                                     grad[3]        = G[0] + interpolationValPlus*(G[3] - G[0]).Normalized()*CUBE_DIMENSIONS[1];
06745                                     texCoordList[3] = VTC[0] + interpolationValPlus*(VTC[3] - VTC[0]).Normalized()*CUBE_DIMENSIONS[1];
06746                                 }
06747                                 else {
06748                                     //
06749                                     // Interpotation Data
06750                                     //interpolationValPlus = 1.0 - VIntp[3].GetY();
06751                                     //
06752                                     vertexList[ 3] = V[3] - interpolationValPlus*(V[3] - V[0]).Normalized()*CUBE_DIMENSIONS[1];
06753                                     grad[3]        = G[3] - interpolationValPlus*(G[3] - G[0]).Normalized()*CUBE_DIMENSIONS[1];
06754                                     texCoordList[3] = VTC[3] - interpolationValPlus*(VTC[3] - VTC[0]).Normalized()*CUBE_DIMENSIONS[1];
06755                                 }
06756                                 grad[3].Normalized();
06757                             }
06758                             if ( EdgeTable[cubeClass] & 16 ) {
06759                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06760                                     //
06761                                     // Interpotation Data
06762                                     //interpolationValPlus = VIntp[4].GetX();
06763                                     //
06764                                     vertexList[ 4] = V[4] + interpolationValPlus*(V[5] - V[4]).Normalized()*CUBE_DIMENSIONS[0];
06765                                     grad[4]        = G[4] + interpolationValPlus*(G[5] - G[4]).Normalized()*CUBE_DIMENSIONS[0];
06766                                     texCoordList[4] = VTC[4] + interpolationValPlus*(VTC[5] - VTC[4]).Normalized()*CUBE_DIMENSIONS[0];
06767                                 }
06768                                 else {
06769                                     //
06770                                     // Interpotation Data
06771                                     //interpolationValPlus = 1.0 - VIntp[5].GetX();
06772                                     //
06773                                     vertexList[ 4] = V[5] - interpolationValPlus*(V[5] - V[4]).Normalized()*CUBE_DIMENSIONS[0];
06774                                     grad[4]        = G[5] - interpolationValPlus*(G[5] - G[4]).Normalized()*CUBE_DIMENSIONS[0];
06775                                     texCoordList[4] = VTC[5] - interpolationValPlus*(VTC[5] - VTC[4]).Normalized()*CUBE_DIMENSIONS[0];
06776                                 }
06777                                 grad[4].Normalized();
06778                             }
06779                             if ( EdgeTable[cubeClass] & 32 ) {
06780                                 if ( dataForPosition[idx[5] + 3] > threshold ) {
06781                                     //
06782                                     // Interpotation Data
06783                                     //interpolationValPlus = VIntp[5].GetY();
06784                                     //
06785                                     vertexList[ 5] = V[5] + interpolationValPlus*(V[6] - V[5]).Normalized()*CUBE_DIMENSIONS[1];
06786                                     grad[5]        = G[5] + interpolationValPlus*(G[6] - G[5]).Normalized()*CUBE_DIMENSIONS[1];
06787                                     texCoordList[5] = VTC[5] + interpolationValPlus*(VTC[6] - VTC[5]).Normalized()*CUBE_DIMENSIONS[1];
06788                                 }
06789                                 else {
06790                                     //
06791                                     // Interpotation Data
06792                                     //interpolationValPlus = 1.0 - VIntp[6].GetY();
06793                                     //
06794                                     vertexList[ 5] = V[6] - interpolationValPlus*(V[6] - V[5]).Normalized()*CUBE_DIMENSIONS[1];
06795                                     grad[5]        = G[6] - interpolationValPlus*(G[6] - G[5]).Normalized()*CUBE_DIMENSIONS[1];
06796                                     texCoordList[5] = VTC[6] - interpolationValPlus*(VTC[6] - VTC[5]).Normalized()*CUBE_DIMENSIONS[1];
06797                                 }
06798                                 grad[5].Normalized();
06799                             }
06800                             if ( EdgeTable[cubeClass] & 64 ) {
06801                                 if ( dataForPosition[idx[6] + 3] > threshold ) {
06802                                     //
06803                                     // Interpotation Data
06804                                     //interpolationValPlus = VIntp[6].GetX();
06805                                     //
06806                                     vertexList[ 6] = V[6] + interpolationValPlus*(V[7] - V[6]).Normalized()*CUBE_DIMENSIONS[0];
06807                                     grad[6]        = G[6] + interpolationValPlus*(G[7] - G[6]).Normalized()*CUBE_DIMENSIONS[0];
06808                                     texCoordList[6] = VTC[6] + interpolationValPlus*(VTC[7] - VTC[6]).Normalized()*CUBE_DIMENSIONS[0];
06809                                 }
06810                                 else {
06811                                     //
06812                                     // Interpotation Data
06813                                     //interpolationValPlus = 1.0 - VIntp[7].GetX();
06814                                     //
06815                                     vertexList[ 6] = V[7] - interpolationValPlus*(V[7] - V[6]).Normalized()*CUBE_DIMENSIONS[0];
06816                                     grad[6]        = G[7] - interpolationValPlus*(G[7] - G[6]).Normalized()*CUBE_DIMENSIONS[0];
06817                                     texCoordList[6] = VTC[7] - interpolationValPlus*(VTC[7] - VTC[6]).Normalized()*CUBE_DIMENSIONS[0];
06818                                 }
06819                                 grad[6].Normalized();
06820                             }
06821                             if ( EdgeTable[cubeClass] & 128 ) {
06822                                 if ( dataForPosition[idx[4] + 3] > threshold ) {
06823                                     //
06824                                     // Interpotation Data
06825                                     //interpolationValPlus = VIntp[4].GetY();
06826                                     //
06827                                     vertexList[ 7] = V[4] + interpolationValPlus*(V[7] - V[4]).Normalized()*CUBE_DIMENSIONS[1];
06828                                     grad[7]        = G[4] + interpolationValPlus*(G[7] - G[4]).Normalized()*CUBE_DIMENSIONS[1];
06829                                     texCoordList[7] = VTC[4] + interpolationValPlus*(VTC[7] - VTC[4]).Normalized()*CUBE_DIMENSIONS[1];
06830                                 }
06831                                 else {
06832                                     //
06833                                     // Interpotation Data
06834                                     //interpolationValPlus = 1.0 - VIntp[7].GetY();
06835                                     //
06836                                     vertexList[ 7] = V[7] - interpolationValPlus*(V[7] - V[4]).Normalized()*CUBE_DIMENSIONS[1];
06837                                     grad[7]        = G[7] - interpolationValPlus*(G[7] - G[4]).Normalized()*CUBE_DIMENSIONS[1];
06838                                     texCoordList[7] = VTC[7] - interpolationValPlus*(VTC[7] - VTC[4]).Normalized()*CUBE_DIMENSIONS[1];
06839                                 }
06840                                 grad[7].Normalized();
06841                             }
06842                             if ( EdgeTable[cubeClass] & 256 ) {
06843                                 if ( dataForPosition[idx[0] + 3] > threshold ) {
06844                                     //
06845                                     // Interpotation Data
06846                                     //interpolationValPlus = VIntp[0].GetZ();
06847                                     //
06848                                     vertexList[ 8] = V[0] + interpolationValPlus*(V[4] - V[0]).Normalized()*CUBE_DIMENSIONS[2];
06849                                     grad[8]        = G[0] + interpolationValPlus*(G[4] - G[0]).Normalized()*CUBE_DIMENSIONS[2];
06850                                     texCoordList[8] = VTC[0] + interpolationValPlus*(VTC[4] - VTC[0]).Normalized()*CUBE_DIMENSIONS[2];
06851                                 }
06852                                 else {
06853                                     //
06854                                     // Interpotation Data
06855                                     //interpolationValPlus = 1.0 - VIntp[4].GetZ();
06856                                     //
06857                                     vertexList[ 8] = V[4] - interpolationValPlus*(V[4] - V[0]).Normalized()*CUBE_DIMENSIONS[2];
06858                                     grad[8]        = G[4] - interpolationValPlus*(G[4] - G[0]).Normalized()*CUBE_DIMENSIONS[2];
06859                                     texCoordList[8] = VTC[4] - interpolationValPlus*(VTC[4] - VTC[0]).Normalized()*CUBE_DIMENSIONS[2];
06860                                 }
06861                                 grad[8].Normalized();
06862                             }
06863                             if ( EdgeTable[cubeClass] & 512 ) {
06864                                 if ( dataForPosition[idx[1] + 3] > threshold ) {
06865                                     //
06866                                     // Interpotation Data
06867                                     //interpolationValPlus = VIntp[1].GetZ();
06868                                     //
06869                                     vertexList[ 9] = V[1] + interpolationValPlus*(V[5] - V[1]).Normalized()*CUBE_DIMENSIONS[2];
06870                                     grad[9]        = G[1] + interpolationValPlus*(G[5] - G[1]).Normalized()*CUBE_DIMENSIONS[2];
06871                                     texCoordList[9] = VTC[1] + interpolationValPlus*(VTC[5] - VTC[1]).Normalized()*CUBE_DIMENSIONS[2];
06872                                 }
06873                                 else {
06874                                     //
06875                                     // Interpotation Data
06876                                     //interpolationValPlus = 1.0 - VIntp[5].GetZ();
06877                                     //
06878                                     vertexList[ 9] = V[5] - interpolationValPlus*(V[5] - V[1]).Normalized()*CUBE_DIMENSIONS[2];
06879                                     grad[9]        = G[5] - interpolationValPlus*(G[5] - G[1]).Normalized()*CUBE_DIMENSIONS[2];
06880                                     texCoordList[9] = VTC[5] - interpolationValPlus*(VTC[5] - VTC[1]).Normalized()*CUBE_DIMENSIONS[2];
06881                                 }
06882                                 grad[9].Normalized();
06883                             }
06884                             if ( EdgeTable[cubeClass] & 1024 ) {
06885                                 if ( dataForPosition[idx[2] + 3] > threshold ) {
06886                                     //
06887                                     // Interpotation Data
06888                                     //interpolationValPlus = VIntp[2].GetZ();
06889                                     //
06890                                     vertexList[10] = V[2] + interpolationValPlus*(V[6] - V[2]).Normalized()*CUBE_DIMENSIONS[2];
06891                                     grad[10]       = G[2] + interpolationValPlus*(G[6] - G[2]).Normalized()*CUBE_DIMENSIONS[2];
06892                                     texCoordList[10] = VTC[2] + interpolationValPlus*(VTC[6] - VTC[2]).Normalized()*CUBE_DIMENSIONS[2];
06893                                 }
06894                                 else {
06895                                     //
06896                                     // Interpotation Data
06897                                     //interpolationValPlus = 1.0 - VIntp[6].GetZ();
06898                                     //
06899                                     vertexList[10] = V[6] - interpolationValPlus*(V[6] - V[2]).Normalized()*CUBE_DIMENSIONS[2];
06900                                     grad[10]       = G[6] - interpolationValPlus*(G[6] - G[2]).Normalized()*CUBE_DIMENSIONS[2];
06901                                     texCoordList[10] = VTC[6] - interpolationValPlus*(VTC[6] - VTC[2]).Normalized()*CUBE_DIMENSIONS[2];
06902                                 }
06903                                 grad[10].Normalized();
06904                             }
06905                             if ( EdgeTable[cubeClass] & 2048 ) {
06906                                 if ( dataForPosition[idx[3] + 3] > threshold ) {
06907                                     //
06908                                     // Interpotation Data
06909                                     //interpolationValPlus = VIntp[3].GetZ();
06910                                     //
06911                                     vertexList[11] = V[3] + interpolationValPlus*(V[7] - V[3]).Normalized()*CUBE_DIMENSIONS[2];
06912                                     grad[11]       = G[3] + interpolationValPlus*(G[7] - G[3]).Normalized()*CUBE_DIMENSIONS[2];
06913                                     texCoordList[11] = VTC[3] + interpolationValPlus*(VTC[7] - VTC[3]).Normalized()*CUBE_DIMENSIONS[2];
06914                                 }
06915                                 else {
06916                                     //
06917                                     // Interpotation Data
06918                                     //interpolationValPlus = 1.0 - VIntp[7].GetZ();
06919                                     //
06920                                     vertexList[11] = V[7] - interpolationValPlus*(V[7] - V[3]).Normalized()*CUBE_DIMENSIONS[2];
06921                                     grad[11]       = G[7] - interpolationValPlus*(G[7] - G[3]).Normalized()*CUBE_DIMENSIONS[2];
06922                                     texCoordList[11] = VTC[7] - interpolationValPlus*(VTC[7] - VTC[3]).Normalized()*CUBE_DIMENSIONS[2];
06923                                 }
06924                                 grad[11].Normalized();
06925                             }
06926                             //---------------------------------------
06927                             //=======================================
06928                             //***************************************
06929                             //*/
06930 
06931 
06932 
06933                         } // END: Use Global Interpolation Value
06934                         //-----------------------------------------------
06935                         // END: if/else statement for MC Interpolation
06936                         //===============================================
06937 
06938                         //===============================================
06939                         //-----------------------------------------------
06940                         // Generate Triangle Index
06941                         numOfTrisPerCell = 0;
06942                         for ( d = 0; TriTable[cubeClass][d] != -1; ++d ) {
06943                             triIndices[d] = TriTable[cubeClass][d];
06944                         }
06945                         numOfTrisPerCell = d / 3;
06946                         //-----------------------------------------------
06947                         //===============================================
06948                     }
06949 
06950                     /*
06951                     //-------------------------------
06952                     // Draw (Gradient) Normals
06953                     {
06954                         glPushAttrib( GL_ALL_ATTRIB_BITS );
06955                         glBegin( GL_LINES );
06956                         glDisable( GL_TEXTURE_3D );
06957                         glDisable( GL_BLEND );
06958                         glDisable( GL_LIGHTING );
06959                         for ( int i = 0; i < numOfTrisPerCell*3; i+=3 ) {
06960                             glColor3f( 1, 0, 0 );
06961                             glVertex3fv( vertexList[triIndices[i+2]].GetDataFloat() );
06962                             glVertex3fv( ( vertexList[triIndices[i+2]] + grad[triIndices[i+2]]*0.15 ).GetDataFloat() );
06963                             glColor3f( 0, 1, 0 );
06964                             glVertex3fv( vertexList[triIndices[i+1]].GetDataFloat() );
06965                             glVertex3fv( ( vertexList[triIndices[i+1]] + grad[triIndices[i+1]]*0.15 ).GetDataFloat() );
06966                             glColor3f( 0, 0, 1 );
06967                             glVertex3fv( vertexList[triIndices[i+0]].GetDataFloat() );
06968                             glVertex3fv( ( vertexList[triIndices[i+0]] + grad[triIndices[i+0]]*0.15 ).GetDataFloat() );
06969                         }
06970                         glEnd();
06971                         glPopAttrib();
06972                     }
06973                     //-------------------------------
06974                     //*/
06975 
06976                     /*
06977                     // Left
06978                     glEnable( GL_COLOR_MATERIAL );
06979                     if      ( iIterate == 0 ) {
06980                         glColor3f( 1.0, 0.0, 0.0 );
06981                     }
06982                     else if ( iIterate == 1 ) {
06983                         glColor3f( 0.0, 1.0, 0.0 );
06984                     }
06985                     else {
06986                         glColor3f( 0.0, 0.0, 1.0 );
06987                     }
06988                     //*/
06989 
06990                     //-------------------------------
06991                     // Draw PN-Triangles generated 
06992                     // from Marching Cube Triangles
06993                     if ( m_bDrawPNTriangle ) {
06994                         int i = 0;
06995                         while ( numOfTrisPerCell > 0 ) {
06996                             PNTriangle<T>::DrawByOpenGL( 
06997                                 vertexList[triIndices[i+2]], 
06998                                 vertexList[triIndices[i+1]], 
06999                                 vertexList[triIndices[i+0]], 
07000                                 grad[triIndices[i+2]], 
07001                                 grad[triIndices[i+1]], 
07002                                 grad[triIndices[i+0]], 
07003                                 texCoordList[triIndices[i+2]], 
07004                                 texCoordList[triIndices[i+1]], 
07005                                 texCoordList[triIndices[i+0]], 
07006                                 m_PNTriangleSmoothness 
07007                             );
07008                             --numOfTrisPerCell;
07009                             i += 3;
07010                         }
07011                     }
07012                     // DEBUG for PNTri Drawing
07013                     //glUseProgramObjectARB( g_PNTriProg );
07014                     //
07015                     // DEBUG for PNTri Drawing
07016                     //glUseProgramObjectARB( NULL );
07017 
07018                     //-------------------------------
07019                     // Draw Marching Cube Triangles
07020                     else {
07021 
07022                         /*
07023                         //*************************************
07024                         // DEBUG
07025                         {
07026                             glPushAttrib( GL_ALL_ATTRIB_BITS );
07027                             glDisable( GL_LIGHTING );
07028                             glDisable( GL_BLEND );
07029                             glDisable( GL_TEXTURE_3D );
07030                             glColor3ub( 200, 50, 100 );
07031                             //glColor3f( 0.0, 0.0, 1.0 );
07032                             glBegin( GL_POINTS );
07033                             int count = numOfTrisPerCell;
07034                             int i = 0;
07035                             while ( count > 0 ) {
07036                                 //glTexCoord3fv( texCoordList[triIndices[i+2]].GetDataFloat() );
07037                                 glColor3f( 1, 0, 0 );
07038                                 glNormal3fv( grad[triIndices[i+2]].GetDataFloat() );
07039                                 glVertex3fv( vertexList[triIndices[i+2]].GetDataFloat() );
07040                                 //
07041                                 //glTexCoord3fv( texCoordList[triIndices[i+1]].GetDataFloat() );
07042                                 glColor3f( 0, 1, 0 );
07043                                 glNormal3fv( grad[triIndices[i+1]].GetDataFloat() );
07044                                 glVertex3fv( vertexList[triIndices[i+1]].GetDataFloat() );
07045                                 //
07046                                 //glTexCoord3fv( texCoordList[triIndices[i+0]].GetDataFloat() );
07047                                 glColor3f( 0, 0, 1 );
07048                                 glNormal3fv( grad[triIndices[i+0]].GetDataFloat() );
07049                                 glVertex3fv( vertexList[triIndices[i+0]].GetDataFloat() );
07050                                 //
07051                                 --count;
07052                                 i += 3;
07053                             }
07054                             glEnd();
07055                             glPopAttrib();
07056                         }
07057                         //*************************************
07058                         //*/
07059 
07060                         //glBegin( GL_LINE_LOOP );
07061                         glBegin( GL_TRIANGLES );
07062                         int i = 0;
07063                         while ( numOfTrisPerCell > 0 ) {
07064                             glTexCoord3fv( texCoordList[triIndices[i+2]].GetDataFloat() );
07065                             glNormal3fv( grad[triIndices[i+2]].GetDataFloat() );
07066                             glVertex3fv( vertexList[triIndices[i+2]].GetDataFloat() );
07067                             //
07068                             glTexCoord3fv( texCoordList[triIndices[i+1]].GetDataFloat() );
07069                             glNormal3fv( grad[triIndices[i+1]].GetDataFloat() );
07070                             glVertex3fv( vertexList[triIndices[i+1]].GetDataFloat() );
07071                             //
07072                             glTexCoord3fv( texCoordList[triIndices[i+0]].GetDataFloat() );
07073                             glNormal3fv( grad[triIndices[i+0]].GetDataFloat() );
07074                             glVertex3fv( vertexList[triIndices[i+0]].GetDataFloat() );
07075                             //
07076                             --numOfTrisPerCell;
07077                             i += 3;
07078                         }
07079                         glEnd();
07080                     }
07081 
07082                     //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07084                     //if ( isFirstRun ) {
07085                     //  if ( cubeClass < 100 )  std::cout << " ";
07086                     //  if ( cubeClass < 10 )   std::cout << " ";
07087                     //  std::cout << "  " << static_cast<int>( cubeClass );
07088                     //}
07089                     //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07090 
07091                     // Restore Reloaded Threshold Values
07092                     for ( int R = 0; R < 8; ++R ) {
07093                         dataForPosition[idx[R] + 3] = reloadedThresholdValues[R];
07094                     }
07095 
07096                 } // END: // TWO ITERATIONS FOR LEFT AND RIGHT CUBE CONFIGURATIONS
07097 
07098                 //-------------------------------
07099                 // Next Cell
07100                 for ( i = 0; i < 8; ++i ) {
07101                     idx[i] += 4;
07102                     //
07103                     intpIdx[i] += 3;
07104                 }
07105                 //-------------------------------
07106 
07107             } // END: for loop for X
07108 
07109             //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07111             //if ( isFirstRun ) std::cout << "\n";
07112             //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07113 
07114         } // END: for loop for Y
07115 
07116         //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07118         //if ( isFirstRun ) std::cout << "\n";
07119         //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07120 
07121     } // END: for loop for Z
07122 
07123     //#ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07125     //if ( isFirstRun ) {
07126     //  std::cout << "-------------------------\n";
07127     //}
07129     //#endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_GPU_MC_WITH_TRACKING_CUBES
07130 
07131     glPopAttrib();
07132 
07133     #ifdef TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
07134     m_glslProgramObjectForShaderSurfaceFromSW->EndGLSL();
07135     #endif // TAPs_MODEL_DEFORMABLE_VISUALIZATION_RT_GEN_MESH_USE_SHADER_FOR_SHADING_SURFACE_FROM_SW
07136     //---------------------------------------------------------------
07137     //===============================================================
07138     //*/
07139 
07140     //---------------------------------------------------------------
07141     //===============================================================
07142     delete [] dataForPosition;
07143     delete [] dataForEllipsoidInfluence;
07144 }
07145 //-----------------------------------------------------------------------------
07146 // END: DrawByGL
07147 //*****************************************************************************
07148 
07149 
07150 //-----------------------------------------------------------------------------
07151 //=============================================================================
07152 END_NAMESPACE_TAPs__OpenGL
07153 //-----------------------------------------------------------------------------
07154 //34567890123456789012345678901234567890123456789012345678901234567890123456789
07155 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines