00001
00014 #include <assert.h>
00015
00016 #include "MarchingCubesBase.h"
00017
00018
00019 #define DEBUG_MODE 99
00020
00021 #include "General/vuMarchingCubes/debug.h"
00022
00023
00024 const GLfloat MarchingCubesBase::_vertOffset[8][3] = {
00025 {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
00026 {0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}
00027 };
00028
00029
00030 const int MarchingCubesBase::_marchingCubesTable[256][16] = {
00031 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00032 {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00033 {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00034 {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00035 {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00036 {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00037 {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00038 {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1},
00039 {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00040 {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00041 {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00042 {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1},
00043 {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00044 {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1},
00045 {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1},
00046 {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00047 {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00048 {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00049 {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00050 {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1},
00051 {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00052 {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1},
00053 {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
00054 {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1},
00055 {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00056 {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1},
00057 {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
00058 {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1},
00059 {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1},
00060 {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1},
00061 {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1},
00062 {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1},
00063 {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00064 {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00065 {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00066 {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1},
00067 {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00068 {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
00069 {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1},
00070 {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1},
00071 {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00072 {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
00073 {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
00074 {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1},
00075 {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1},
00076 {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1},
00077 {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1},
00078 {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1},
00079 {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00080 {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1},
00081 {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1},
00082 {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00083 {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1},
00084 {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1},
00085 {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1},
00086 {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
00087 {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1},
00088 {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1},
00089 {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1},
00090 {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1},
00091 {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1},
00092 {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1},
00093 {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1},
00094 {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00095 {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00096 {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00097 {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00098 {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
00099 {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00100 {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1},
00101 {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1},
00102 {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1},
00103 {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00104 {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
00105 {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
00106 {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1},
00107 {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1},
00108 {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1},
00109 {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1},
00110 {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1},
00111 {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00112 {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1},
00113 {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
00114 {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1},
00115 {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1},
00116 {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1},
00117 {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1},
00118 {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1},
00119 {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
00120 {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1},
00121 {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1},
00122 {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1},
00123 {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1},
00124 {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1},
00125 {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1},
00126 {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1},
00127 {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00128 {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1},
00129 {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1},
00130 {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1},
00131 {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1},
00132 {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1},
00133 {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00134 {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1},
00135 {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1},
00136 {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1},
00137 {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1},
00138 {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1},
00139 {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1},
00140 {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1},
00141 {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1},
00142 {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00143 {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1},
00144 {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1},
00145 {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1},
00146 {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1},
00147 {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1},
00148 {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1},
00149 {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1},
00150 {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00151 {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1},
00152 {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1},
00153 {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1},
00154 {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1},
00155 {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1},
00156 {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00157 {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1},
00158 {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00159 {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00160 {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00161 {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00162 {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
00163 {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00164 {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
00165 {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
00166 {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1},
00167 {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00168 {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1},
00169 {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1},
00170 {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1},
00171 {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1},
00172 {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1},
00173 {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1},
00174 {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1},
00175 {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00176 {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1},
00177 {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1},
00178 {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1},
00179 {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1},
00180 {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1},
00181 {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1},
00182 {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1},
00183 {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1},
00184 {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00185 {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1},
00186 {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
00187 {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1},
00188 {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1},
00189 {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1},
00190 {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00191 {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00192 {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
00193 {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
00194 {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1},
00195 {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
00196 {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1},
00197 {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1},
00198 {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1},
00199 {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
00200 {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1},
00201 {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1},
00202 {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1},
00203 {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1},
00204 {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1},
00205 {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1},
00206 {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1},
00207 {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1},
00208 {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1},
00209 {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1},
00210 {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1},
00211 {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1},
00212 {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1},
00213 {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1},
00214 {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1},
00215 {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1},
00216 {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1},
00217 {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1},
00218 {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00219 {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1},
00220 {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1},
00221 {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00222 {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00223 {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00224 {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1},
00225 {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
00226 {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1},
00227 {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1},
00228 {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1},
00229 {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1},
00230 {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1},
00231 {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1},
00232 {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1},
00233 {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1},
00234 {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1},
00235 {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00236 {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1},
00237 {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
00238 {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00239 {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1},
00240 {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1},
00241 {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1},
00242 {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1},
00243 {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1},
00244 {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1},
00245 {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1},
00246 {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00247 {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1},
00248 {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1},
00249 {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1},
00250 {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1},
00251 {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
00252 {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00253 {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1},
00254 {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00255 {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1},
00256 {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1},
00257 {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1},
00258 {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1},
00259 {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1},
00260 {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1},
00261 {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1},
00262 {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1},
00263 {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1},
00264 {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1},
00265 {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1},
00266 {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00267 {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1},
00268 {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1},
00269 {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00270 {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00271 {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00272 {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1},
00273 {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1},
00274 {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00275 {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1},
00276 {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1},
00277 {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00278 {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00279 {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1},
00280 {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00281 {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1},
00282 {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00283 {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00284 {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00285 {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
00286 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
00287 };
00288
00289
00290 const int MarchingCubesBase::_edgeConnect[12][2] = {
00291 {0,1}, {1,2}, {2,3}, {3,0},
00292 {4,5}, {5,6}, {6,7}, {7,4},
00293 {0,4}, {1,5}, {2,6}, {3,7}
00294 };
00295
00296
00297 const int MarchingCubesBase::_edgeSizeConnect[12] = {
00298 0, 1, 0, 1,
00299 0, 1, 0, 1,
00300 2, 2, 2, 2
00301 };
00302
00303
00304 const int MarchingCubesBase::_edgeMapping[12][3][3][3] = {
00305 {
00306 {
00307
00308 { -1, -1, -1 },
00309 { -1, -1, -1 },
00310 { -1, -1, -1 }
00311 },
00312 {
00313
00314 { -1, -1, -1 },
00315 { -1, -1, -1 },
00316 { -1, -1, -1 }
00317 },
00318 {
00319
00320 { 6, -1, 2 },
00321 { -1, -1, -1 },
00322 { 4, -1, -1 }
00323 }
00324 },
00325 {
00326 {
00327
00328 { -1, -1, -1 },
00329 { -1, -1, -1 },
00330 { -1, -1, -1 }
00331 },
00332 {
00333
00334 { -1, -1, -1 },
00335 { 5, -1, -1 },
00336 { -1, -1, -1 }
00337 },
00338 {
00339
00340 { -1, -1, -1 },
00341 { 7, 3, -1 },
00342 { -1, -1, -1 }
00343 }
00344 },
00345 {
00346 {
00347
00348 { -1, -1, -1 },
00349 { -1, -1, -1 },
00350 { -1, -1, -1 }
00351 },
00352 {
00353
00354 { -1, -1, -1 },
00355 { 6, -1, -1 },
00356 { 4, 0, -1 }
00357 },
00358 {
00359
00360 { -1, -1, -1 },
00361 { -1, -1, -1 },
00362 { -1, -1, -1 }
00363 }
00364 },
00365 {
00366 {
00367
00368 { -1, -1, -1 },
00369 { 5, 1, -1 },
00370 { -1, -1, -1 }
00371 },
00372 {
00373
00374 { -1, -1, -1 },
00375 { 7, -1, -1 },
00376 { -1, -1, -1 }
00377 },
00378 {
00379
00380 { -1, -1, -1 },
00381 { -1, -1, -1 },
00382 { -1, -1, -1 }
00383 }
00384 },
00385 {
00386 {
00387
00388 { -1, -1, -1 },
00389 { -1, -1, -1 },
00390 { -1, -1, -1 }
00391 },
00392 {
00393
00394 { -1, 6, 2 },
00395 { -1, -1, 0 },
00396 { -1, -1, -1 }
00397 },
00398 {
00399
00400 { -1, -1, -1 },
00401 { -1, -1, -1 },
00402 { -1, -1, -1 }
00403 }
00404 },
00405 {
00406 {
00407
00408 { -1, -1, -1 },
00409 { -1, -1, -1 },
00410 { -1, -1, -1 }
00411 },
00412 {
00413
00414 { -1, -1, -1 },
00415 { -1, -1, 1 },
00416 { -1, -1, -1 }
00417 },
00418 {
00419
00420 { -1, -1, -1 },
00421 { -1, 7, 3 },
00422 { -1, -1, -1 }
00423 }
00424 },
00425 {
00426 {
00427
00428 { -1, -1, -1 },
00429 { -1, -1, -1 },
00430 { -1, -1, -1 }
00431 },
00432 {
00433
00434 { -1, -1, -1 },
00435 { -1, -1, 2 },
00436 { -1, 4, 0 }
00437 },
00438 {
00439
00440 { -1, -1, -1 },
00441 { -1, -1, -1 },
00442 { -1, -1, -1 }
00443 }
00444 },
00445 {
00446 {
00447
00448 { -1, -1, -1 },
00449 { -1, 5, 1 },
00450 { -1, -1, -1 }
00451 },
00452 {
00453
00454 { -1, -1, -1 },
00455 { -1, -1, 3 },
00456 { -1, -1, -1 }
00457 },
00458 {
00459
00460 { -1, -1, -1 },
00461 { -1, -1, -1 },
00462 { -1, -1, -1 }
00463 }
00464 },
00465 {
00466 {
00467
00468 { -1, 10, -1 },
00469 { -1, 9, -1 },
00470 { -1, -1, -1 }
00471 },
00472 {
00473
00474 { -1, 11, -1 },
00475 { -1, -1, -1 },
00476 { -1, -1, -1 }
00477 },
00478 {
00479
00480 { -1, -1, -1 },
00481 { -1, -1, -1 },
00482 { -1, -1, -1 }
00483 }
00484 },
00485 {
00486 {
00487
00488 { -1, -1, -1 },
00489 { -1, -1, -1 },
00490 { -1, -1, -1 }
00491 },
00492 {
00493
00494 { -1, 10, -1 },
00495 { -1, -1, -1 },
00496 { -1, -1, -1 }
00497 },
00498 {
00499
00500 { -1, 11, -1 },
00501 { -1, 8, -1 },
00502 { -1, -1, -1 }
00503 }
00504 },
00505 {
00506 {
00507
00508 { -1, -1, -1 },
00509 { -1, -1, -1 },
00510 { -1, -1, -1 }
00511 },
00512 {
00513
00514 { -1, -1, -1 },
00515 { -1, -1, -1 },
00516 { -1, 9, -1 }
00517 },
00518 {
00519
00520 { -1, -1, -1 },
00521 { -1, 11, -1 },
00522 { -1, 8, -1 }
00523 }
00524 },
00525 {
00526 {
00527
00528 { -1, -1, -1 },
00529 { -1, 10, -1 },
00530 { -1, 9, -1 }
00531 },
00532 {
00533
00534 { -1, -1, -1 },
00535 { -1, -1, -1 },
00536 { -1, 8, -1 }
00537 },
00538 {
00539
00540 { -1, -1, -1 },
00541 { -1, -1, -1 },
00542 { -1, -1, -1 }
00543 }
00544 }
00545 };
00546
00547
00548 const GLfloat MarchingCubesBase::_edgeDir[12][3] = {
00549 {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0},
00550 {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0},
00551 {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, { 0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}
00552 };
00553
00554
00555 const int MarchingCubesBase::_edgeFlags[256] = {
00556 0x000, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
00557 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
00558 0x190, 0x099, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
00559 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
00560 0x230, 0x339, 0x033, 0x13a, 0x636, 0x73f, 0x435, 0x53c,
00561 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
00562 0x3a0, 0x2a9, 0x1a3, 0x0aa, 0x7a6, 0x6af, 0x5a5, 0x4ac,
00563 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
00564 0x460, 0x569, 0x663, 0x76a, 0x066, 0x16f, 0x265, 0x36c,
00565 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
00566 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0x0ff, 0x3f5, 0x2fc,
00567 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
00568 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x055, 0x15c,
00569 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
00570 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0x0cc,
00571 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
00572 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
00573 0x0cc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
00574 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
00575 0x15c, 0x055, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
00576 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
00577 0x2fc, 0x3f5, 0x0ff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
00578 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
00579 0x36c, 0x265, 0x16f, 0x066, 0x76a, 0x663, 0x569, 0x460,
00580 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
00581 0x4ac, 0x5a5, 0x6af, 0x7a6, 0x0aa, 0x1a3, 0x2a9, 0x3a0,
00582 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
00583 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x033, 0x339, 0x230,
00584 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
00585 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x099, 0x190,
00586 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
00587 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x000
00588 };
00589
00590
00591 MarchingCubesBase::MarchingCubesBase()
00592 : _origin1(1.0), _origin2(1.0), _origin3(1.0),
00593 _data(0),
00594 _gd(NULL),
00595 _valueRangeAdjusted(false),
00596 _progCB(0),
00597 _histoCB(0),
00598 _mesh(0),
00599 _theCube(0),
00600 _cube(0)
00601 {
00602 DEBUG0("MarchingCubesBase::MarchingCubesBase(MCGlobalData *gd)\n");
00603 }
00604
00605
00606 MarchingCubesBase::~MarchingCubesBase()
00607 {
00608 DEBUGD("virtual MarchingCubesBase::~MarchingCubesBase()\n");
00609 if (_data) delete _data;
00610 if (_progCB) delete _progCB;
00611 if (_histoCB) delete _histoCB;
00612 if (_mesh) delete _mesh;
00613 }
00614
00615
00617 void MarchingCubesBase::glRenderFrame()
00618 {
00619 DEBUG0("void MarchingCubesBase::glRenderFrame()\n");
00620 assert(_gd != NULL);
00621 glPushMatrix();
00622 glTranslatef(_origin1, _origin2, _origin3);
00623 drawHorCylinder(1, 0.0, _gd->frameRadius, (float)_size[2]*_gd->cubeSize[2]);
00624 drawHorCylinder(0, 90.0, _gd->frameRadius, (float)_size[0]*_gd->cubeSize[0]);
00625 drawHorCylinder(4, 180.0, _gd->frameRadius, (float)_size[2]*_gd->cubeSize[2]);
00626 drawHorCylinder(5, 270.0, _gd->frameRadius, (float)_size[0]*_gd->cubeSize[0]);
00627 drawHorCylinder(2, 0.0, _gd->frameRadius, (float)_size[2]*_gd->cubeSize[2]);
00628 drawHorCylinder(3, 90.0, _gd->frameRadius, (float)_size[0]*_gd->cubeSize[0]);
00629 drawHorCylinder(7, 180.0, _gd->frameRadius, (float)_size[2]*_gd->cubeSize[2]);
00630 drawHorCylinder(6, 270.0, _gd->frameRadius, (float)_size[0]*_gd->cubeSize[0]);
00631 drawVertCylinder(0, _gd->frameRadius, (float)_size[1]*_gd->cubeSize[1]);
00632 drawVertCylinder(1, _gd->frameRadius, (float)_size[1]*_gd->cubeSize[1]);
00633 drawVertCylinder(4, _gd->frameRadius, (float)_size[1]*_gd->cubeSize[1]);
00634 drawVertCylinder(5, _gd->frameRadius, (float)_size[1]*_gd->cubeSize[1]);
00635 for(int i = 0; i < 8; ++i) {
00636 drawCorner(i, _gd->frameRadius);
00637 }
00638 glPopMatrix();
00639 }
00640
00641
00643 void MarchingCubesBase::glRender()
00644 {
00645 DEBUG0("void MarchingCubesBase::glRender()\n");
00646 if (_gd->cullMode) {
00647 glEnable(GL_CULL_FACE);
00648 glCullFace(_gd->cullMode);
00649 } else {
00650 glDisable(GL_CULL_FACE);
00651 }
00652
00653 if (_gd->cubeBrowser) {
00654 glPushMatrix();
00655 glTranslatef(_origin1, _origin2, _origin3);
00656
00657 for(int i = 0; i < 8; ++i) {
00658 if (!(_gd->cube&(1<<i))) drawSpot(i);
00659
00660 }
00661 bool tp = _gd->termProgress;
00662 _gd->termProgress = false;
00663 drawTriangles();
00664 _gd->termProgress = tp;
00665 glPopMatrix();
00666 } else {
00667 glPushMatrix();
00668 glTranslatef(_origin1, _origin2, _origin3);
00669
00670 if (_gd->drawObject) _mesh->render();
00671 glPopMatrix();
00672 if (!_gd->drawObject) {
00673 GLUquadric* quad = gluNewQuadric();
00674 glPushMatrix();
00675 gluCylinder(quad, (float)_size[1]/50.0, (float)_size[1]/50.0, (float)_size[2]/5.0, 36, 10);
00676 glTranslatef(0.0, 0.0, (float)_size[2]/5.0);
00677 gluCylinder(quad, (float)_size[1]/20.0, 0.0, _size[2]/10.0, 36, 10);
00678 gluDisk(quad, (float)_size[1]/50.0, (float)_size[1]/20.05, 36, 2);
00679 glPopMatrix();
00680 glPushMatrix();
00681 glRotatef(-90.0, 1.0, 0.0, 0.0);
00682 gluCylinder(quad, (float)_size[1]/50.0, (float)_size[1]/50.0, (float)_size[2]/5.0, 36, 10);
00683 glTranslatef(0.0, 0.0, (float)_size[2]/5.0);
00684 gluCylinder(quad, (float)_size[1]/20.0, 0.0, _size[2]/10.0, 36, 10);
00685 gluDisk(quad, (float)_size[1]/50.0, (float)_size[1]/20.05, 36, 2);
00686 glPopMatrix();
00687 glPushMatrix();
00688 glRotatef(90.0, 0.0, 1.0, 0.0);
00689 gluCylinder(quad, (float)_size[1]/50.0, (float)_size[1]/50.0, (float)_size[2]/5.0, 36, 10);
00690 glTranslatef(0.0, 0.0, (float)_size[2]/5.0);
00691 gluCylinder(quad, (float)_size[1]/20.0, 0.0, _size[2]/10.0, 36, 10);
00692 gluDisk(quad, (float)_size[1]/50.0, (float)_size[1]/20.05, 36, 2);
00693 glPopMatrix();
00694 glutSolidSphere((float)_size[1]/50.0, 36, 36);
00695 }
00696 }
00697
00698 glCullFace(GL_BACK);
00699 glEnable(GL_CULL_FACE);
00700 }
00701
00702
00703 void MarchingCubesBase::Size(int sz1, int sz2, int sz3)
00704 {
00705 DEBUG0("void MarchingCubesBase::Size("<<sz1<<", "<<sz2<<", "<<sz3<<")\n");
00706 assert(_gd);
00708 _size[0] = sz1;
00709 _size[1] = sz2;
00710 _size[2] = sz3;
00711 Origin((float)-_size[0]/2.0, (float)-_size[1]/2.0, (float)-_size[2]/2.0);
00712 _gd->normalsLength = (float)this->maxSize()/10.0;
00714 if (_data) { delete [] _data; _data = 0; }
00715 _data = new int[sz1*sz2*sz3];
00716 _gd->termProgress = (maxSize()>=128);
00717 }
00718
00719
00720 int MarchingCubesBase::maxSize()
00721 {
00722 DEBUG0("int MarchingCubesBase::maxSize()\n");
00723 int max = (_size[0] > _size[1]) ? _size[0] : _size[1];
00724 return (max > _size[2]) ? max : _size[2];
00725 }
00726
00727
00728 long long MarchingCubesBase::numVertices()
00729 {
00730 DEBUG0("long long MarchingCubesBase::numVertices()\n");
00731 if (_mesh) return _mesh->numVertices();
00732 return 0;
00733 }
00734
00735
00736 long long MarchingCubesBase::numTriangles()
00737 {
00738 DEBUG0("long long MarchingCubesBase::numTriangles()\n");
00739 if (_mesh) return _mesh->numTriangles();
00740 return 0;
00741 }
00742
00743
00744 long long MarchingCubesBase::numIndices()
00745 {
00746 DEBUG0("long long MarchingCubesBase::numIndices()\n");
00747 if (_mesh) return _mesh->numIndices();
00748 return 0;
00749 }
00750
00751
00752 void MarchingCubesBase::Origin(float or1, float or2, float or3)
00753 {
00754 DEBUG0("void MarchingCubesBase::Origin("<<or1<<", "<<or2<<", "<<or3<<")\n");
00755 _origin1 = or1;
00756 _origin2 = or2;
00757 _origin3 = or3;
00758 }
00759
00760
00761 void MarchingCubesBase::drawHorCylinder(int pos, float angle, float r, float l)
00762 {
00763 DEBUG0("void MarchingCubesBase::void drawHorCylinder(int pos, float angle, float r, float l)\n");
00764 assert(_gd);
00765 GLUquadric* quad = gluNewQuadric();
00766 glPushMatrix();
00767 glTranslated((float)_size[0]*_vertOffset[pos][0]*_gd->cubeSize[0],
00768 (float)_size[1]*_vertOffset[pos][1]*_gd->cubeSize[1],
00769 (float)_size[2]*_vertOffset[pos][2]*_gd->cubeSize[2]);
00770 glRotated(angle, 0.0, 1.0, 0.0);
00771 gluCylinder(quad, r, r, l, 36, 10);
00772 glPopMatrix();
00773 }
00774
00775
00776 void MarchingCubesBase::drawVertCylinder(int pos, float r, float l)
00777 {
00778 GLUquadric* quad = gluNewQuadric();
00779 glPushMatrix();
00780 glTranslated((float)_size[0]*_vertOffset[pos][0]*_gd->cubeSize[0],
00781 (float)_size[1]*_vertOffset[pos][1]*_gd->cubeSize[1],
00782 (float)_size[2]*_vertOffset[pos][2]*_gd->cubeSize[2]);
00783 glRotated(-90.0, 1.0, 0.0, 0.0);
00784 gluCylinder(quad, r, r, l, 36, 10);
00785 glPopMatrix();
00786 }
00787
00788
00789 void MarchingCubesBase::drawCorner(int pos, float r)
00790 {
00791 glPushMatrix();
00792 glTranslated((float)_size[0]*_vertOffset[pos][0]*_gd->cubeSize[0],
00793 (float)_size[1]*_vertOffset[pos][1]*_gd->cubeSize[1],
00794 (float)_size[2]*_vertOffset[pos][2]*_gd->cubeSize[2]);
00795 glutSolidSphere(r, 36, 36);
00796 glPopMatrix();
00797 }
00798
00799
00800 void MarchingCubesBase::drawSpot(int pos)
00801 {
00802 float r = maxSize()/20.0;
00803 glPushMatrix();
00804 glTranslatef((float)_size[0]*_vertOffset[pos][0]*_gd->cubeSize[0],
00805 (float)_size[1]*_vertOffset[pos][1]*_gd->cubeSize[1],
00806 (float)_size[2]*_vertOffset[pos][2]*_gd->cubeSize[2]);
00807 glutSolidSphere(r, 36, 36);
00808 glPopMatrix();
00809 }
00810
00811
00812 void MarchingCubesBase::drawTriangles()
00813 {
00814 int n = 0;
00815
00816 if (_theCube != _gd->cube) {
00817 if (_cube) delete _cube;
00818 _cube = new MCMesh(_gd);
00819 DEBUG7("_gd->cube = "<<_gd->cube<<"\n");
00820 int triangle = -1;
00821 while((_marchingCubesTable[_gd->cube][n] != -1) && (n < 16)) {
00822 if (!(n%3)) {
00823 DEBUG7("adding a triangle ...\n");
00824 triangle = _cube->AddTriangle(_gd->cube);
00825 }
00826 int edge = _marchingCubesTable[_gd->cube][n];
00827 int vertex;
00828 if ((vertex = _cube->GetVertex(0, 0, 0, edge)) != -1) {
00829 DEBUG7("adding existing vertex "<<vertex
00830 <<" to triangle "<<triangle<<"\n");
00831 _cube->AddVertex(vertex, triangle);
00832 } else {
00833 DEBUG7("adding new vertex to triangle "<<triangle<<"\n");
00834 int start = _edgeConnect[edge][0];
00835 vuVector vert((float)_size[0]*_vertOffset[start][0],
00836 (float)_size[1]*_vertOffset[start][1],
00837 (float)_size[2]*_vertOffset[start][2]);
00838 DEBUG7("vert = ("<<vert[0]<<", "<<vert[1]<<", "<<vert[2]<<")\n");
00839 vuVector dir(_edgeDir[edge][0],
00840 _edgeDir[edge][1],
00841 _edgeDir[edge][2]);
00842 DEBUG7("dir = ("<<dir[0]<<", "<<dir[1]<<", "<<dir[2]<<")\n");
00843 vert += dir*(_size[_edgeSizeConnect[edge]]*0.5);
00844 DEBUG7("vert = ("<<vert[0]<<", "<<vert[1]<<", "<<vert[2]<<")\n");
00845 _cube->AddVertex(0, 0, 0, edge, triangle, vert);
00846 }
00847 ++n;
00848 }
00849 _theCube = _gd->cube;
00850 }
00851
00852 _cube->render();
00853 }
00854
00855
00856 int MarchingCubesBase::getCubeType(int x, int y, int z)
00857 {
00858 DEBUG0("int MarchingCubesBase::getCubeType(int x="<<x<<", int y="<<y<<", int z="<<z<<")\n");
00859 DEBUG4("x = "<<x<<", y = "<<y<<", z = "<<z<<"\n");
00860 assert(x<(int)_size[0] && y<(int)_size[1] && z<(int)_size[2]);
00861 int result = 0;
00862 for(int i = 0; i < 8; ++i) {
00863 int idx = MCB_IDX(x+(int)_vertOffset[i][0],
00864 y+(int)_vertOffset[i][1],
00865 z+(int)_vertOffset[i][2]);
00866 DEBUG4("_data["<<idx<<"]="<<_data[idx]<<", thres="<<_gd->thres<<"\n");
00867
00868 int val = ((float)_data[idx]>=_gd->thres) ? 0 : 1;
00869 DEBUG4("val = "<<val<<", i = "<<i<<", (val<<i)="<<(val<<i)<<"\n");
00870 result += (val<<i);
00871 if (!_valueRangeAdjusted) {
00872 _gd->valueMin = (_data[idx]<_gd->valueMin) ? _data[idx] : _gd->valueMin;
00873 _gd->valueMax = (_data[idx]>_gd->valueMax) ? _data[idx] : _gd->valueMax;
00874 }
00875 }
00876 return result;
00877 }
00878
00879
00880 float MarchingCubesBase::valueAt(float px, float py, float pz)
00881 {
00882 DEBUG0("float MarchingCubesBase::valueAt(float x, float y, float z)\n");
00883 DEBUG8("position: "<<px<<", "<<py<<", "<<pz<<"\n");
00884 int ix = (int)px;
00885 int iy = (int)py;
00886 int iz = (int)pz;
00887 DEBUG8("cube position: "<<ix<<", "<<iy<<", "<<iz<<"\n");
00888 float x = px - (float)ix;
00889 float y = py - (float)iy;
00890 float z = pz - (float)iz;
00891 DEBUG8("delta position: "<<x<<", "<<y<<", "<<z<<"\n");
00892 return _data[MCB_IDX(ix , iy , iz )] * (1-x) * (1-y) * (1-z) +
00893 _data[MCB_IDX(ix+1, iy , iz )] * ( x) * (1-y) * (1-z) +
00894 _data[MCB_IDX(ix , iy+1, iz )] * (1-x) * ( y) * (1-z) +
00895 _data[MCB_IDX(ix , iy , iz+1)] * (1-x) * (1-y) * ( z) +
00896 _data[MCB_IDX(ix+1, iy , iz+1)] * ( x) * (1-y) * ( z) +
00897 _data[MCB_IDX(ix , iy+1, iz+1)] * (1-x) * ( y) * ( z) +
00898 _data[MCB_IDX(ix+1, iy+1, iz )] * ( x) * ( y) * (1-z) +
00899 _data[MCB_IDX(ix+1, iy+1, iz+1)] * ( x) * ( y) * ( z);
00900 }
00901
00902
00903 inline vuVector MarchingCubesBase::calcVertex(int x, int y, int z, int edge)
00904 {
00905 DEBUG0("vuVector MarchingCubesBase::calcVertex(int x, int y, int z, int edge)\n");
00906
00907 DEBUG5("x = "<<x<<", y = "<<y<<", z = "<<z<<", edge = "<<edge
00908 <<", c0 = "<<_edgeConnect[edge][0]<<", c1 = "<<_edgeConnect[edge][1]
00909 <<", idx0 = "<<MCB_IDX(x+(int)_vertOffset[_edgeConnect[edge][0]][0],
00910 y+(int)_vertOffset[_edgeConnect[edge][0]][1],
00911 z+(int)_vertOffset[_edgeConnect[edge][0]][2])
00912 <<", idx1 = "<<MCB_IDX(x+(int)_vertOffset[_edgeConnect[edge][1]][0],
00913 y+(int)_vertOffset[_edgeConnect[edge][1]][1],
00914 z+(int)_vertOffset[_edgeConnect[edge][1]][2])<<"\n");
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924 vuVector v0(((float)x+_vertOffset[_edgeConnect[edge][0]][0]),
00925 ((float)y+_vertOffset[_edgeConnect[edge][0]][1]),
00926 ((float)z+_vertOffset[_edgeConnect[edge][0]][2]));
00927 vuVector v1(((float)x+_vertOffset[_edgeConnect[edge][1]][0]),
00928 ((float)y+_vertOffset[_edgeConnect[edge][1]][1]),
00929 ((float)z+_vertOffset[_edgeConnect[edge][1]][2]));
00930 float val0 = _data[MCB_IDX(x+(int)_vertOffset[_edgeConnect[edge][0]][0],
00931 y+(int)_vertOffset[_edgeConnect[edge][0]][1],
00932 z+(int)_vertOffset[_edgeConnect[edge][0]][2])];
00933 float val1 = _data[MCB_IDX(x+(int)_vertOffset[_edgeConnect[edge][1]][0],
00934 y+(int)_vertOffset[_edgeConnect[edge][1]][1],
00935 z+(int)_vertOffset[_edgeConnect[edge][1]][2])];
00936 vuVector e = v1 - v0;
00937 float eLen = e.norm(), dist = 0;
00938 DEBUG5("val0 = "<<val0<<", val1 = "<<val1<<", _gd->thres = "<<_gd->thres<<", eLen = "<<eLen<<"\n");
00939 if (val0 == val1) {
00940 dist = eLen / 2.0;
00941 } else if (val0 < val1) {
00942 assert(val0<=_gd->thres && _gd->thres<=val1);
00943 dist = (_gd->thres-val0)/(val1-val0)*eLen;
00944 } else {
00945 assert(val1<=_gd->thres && _gd->thres<=val0);
00946 dist = eLen-((_gd->thres-val1)/(val0-val1)*eLen);
00947 }
00948 DEBUG5("dist = "<<dist<<"\n");
00949 vuVector result = v0 + e.makeUnit()*dist;
00950 return result;
00951 }
00952
00953
00954 void MarchingCubesBase::marchCubes()
00955 {
00956 DEBUG0("void MarchingCubesBase::marchCubes()\n");
00957 assert(_gd != NULL);
00958 if (_histoCB) _histoCB->Clear();
00959 StartProgress();
00960 SetProgressText("Calculating mesh (i.e. marching cubes):");
00962 int type0 = 0;
00963 int type255 = 0;
00964 int x = 0, y = 0, z = 0;
00965 if (!_valueRangeAdjusted) {
00966 _gd->valueMin = 0xfffffff;
00967 _gd->valueMax = 0;
00968 }
00969 try {
00970 if (_mesh) delete _mesh;
00971 _mesh = new MCMesh(_gd, _progCB);
00972 for(z = 0; z < _size[2]-1; ++z) {
00973 for(y = 0; y < _size[1]-1; ++y)
00974 for(x = 0; x < _size[0]-1; ++x) {
00976 int type = getCubeType(x, y, z);
00977 DEBUG5("type = "<<type<<"\n");
00978 if (_histoCB && type!=0 && type!=255) _histoCB->Inc(type);
00979 if (type==0) ++type0;
00980 if (type==255) ++type255;
00981 if (type != 0 && type != 255) {
00982 int triangle = -1;
00984 int vertNr = 0;
00985 while (vertNr<16 && _marchingCubesTable[type][vertNr]!=-1) {
00986 int edgeNr = _marchingCubesTable[type][vertNr];
00987 DEBUG5("vertNr = "<<vertNr<<", edgeNr = "<<edgeNr<<"\n");
00988 int vertex;
00990 if ((vertNr%3) == 0)
00991 triangle = _mesh->AddTriangle(type);
00992 DEBUG5("triangle = "<<triangle<<"\n");
00994 if ((vertex=_mesh->GetVertex(x,y,z,edgeNr)) != -1) {
00996 _mesh->AddVertex(vertex, triangle);
00997 } else {
01000 vuVector v = calcVertex(x, y, z, edgeNr);
01001 DEBUG6("Adding vector ("<<v[0]<<", "
01002 <<v[1]<<", "<<v[2]<<")\n");
01003 _mesh->AddVertex(x,y,z,edgeNr,triangle,v);
01004 }
01005 ++vertNr;
01006 }
01007 }
01008 }
01009 if (_gd->termProgress)
01010 std::cerr << ((float)z/(float)_size[2]*100.0) << "% marched.\n";
01011 if (_histoCB) {
01012 _histoCB->Inc(0, type0); type0 = 0;
01013 _histoCB->Inc(255, type255); type255 = 0;
01014 }
01015 UpdateProgress(int((float)z/(float)_size[2]*100.0));
01016 }
01017 _valueRangeAdjusted = true;
01018 if (_histoCB) _histoCB->Flush();
01019 EndProgress();
01020 _mesh->prepare();
01021 } catch (...) {
01022 MC_FAIL_EXIT( "Error while marching through the cubes.\n"
01023 <<"Actual mesh memory usage is: "<<_gd->meshSize<<".\n"
01024 <<"Actual index in the data is: "<<x<<", "<<y<<", "<<z<<".\n", -1);
01025 }
01026 }
01027
01028
01029 void MarchingCubesBase::SetProgressCallback(MCBProgressCallback* cb)
01030 {
01031 DEBUG0("void MarchingCubesBase::SetProgressCallback(MCBProgressCallback* cb)\n");
01032 _progCB = cb;
01033 }
01034
01035
01036 void MarchingCubesBase::SetHistoCallback(MCBHistoCallback* cb)
01037 {
01038 DEBUG0("void MarchingCubesBase::SetHistoCallback(MCBHistoCallback* cb)\n");
01039 _histoCB = cb;
01040 }
01041
01042
01043 void MarchingCubesBase::SetProgressText(const char* txt)
01044 {
01045 DEBUG0("void MarchingCubesBase::SetProgressText(const char* txt="<<txt<<")\n");
01046 if (_progCB) _progCB->SetText(txt);
01047 }
01048
01049
01050 void MarchingCubesBase::StartProgress()
01051 {
01052 DEBUG0("void MarchingCubesBase::StartProgress()\n");
01053 if (_progCB) _progCB->Start();
01054 }
01055
01056
01057 void MarchingCubesBase::UpdateProgress(int v)
01058 {
01059 DEBUG0("void MarchingCubesBase::UpdateProgress(int v="<<v<<")\n");
01060 if (_progCB) _progCB->Update(v);
01061 }
01062
01063
01064 void MarchingCubesBase::EndProgress()
01065 {
01066 DEBUG0("void MarchingCubesBase::EndProgress()\n");
01067 if (_progCB) _progCB->End();
01068 }
01069
01070
01071