#include <OSGNormalQuantifier.h>
Public Member Functions | |
Constructors | |
| * | NormalQuantifier (UInt32 numberSubdivisions=0) |
Destructor | |
| *virtual | ~NormalQuantifier (void) |
Get | |
| *UInt32 | getIndex (Vec3f &normal, UInt32 numberSubdivisions=0) const |
| const Vec3f & | getNormal (UInt32 index) const |
| UInt32 | getNormalCount (void) const |
Init | |
| *void | build (UInt32 numberSubdivisions=4) |
Protected Member Functions | |
Helper | |
| *void | subdivide (Vec3f point1, Vec3f point2, Vec3f point3, UInt32 number, UInt32 &index) |
| bool | rayTriangle (const Vec3f &dir, const Vec3f &vert0, const Vec3f &vert1, const Vec3f &vert2) const |
| UInt32 | getSubIndex (Vec3f point, Vec3f point1, Vec3f point2, Vec3f point3, UInt32 number) const |
Protected Attributes | |
Member | |
| *UInt32 | _numberSubdivisions |
| std::vector< Vec3f > | _normalTable |
Private Member Functions | |
| NormalQuantifier (const NormalQuantifier &source) | |
| prohibit default function (move to 'public' if needed) | |
| NormalQuantifier & | operator= (const NormalQuantifier &source) |
| prohibit default function (move to 'public' if needed) | |
Definition at line 55 of file OSGNormalQuantifier.h.
|
|
Definition at line 58 of file OSGNormalQuantifier.cpp. References build(). 00059 { 00060 build(numberSubdivisions); 00061 }
|
|
|
Definition at line 65 of file OSGNormalQuantifier.cpp.
|
|
|
|
|
||||||||||||
|
get a index for the given normal Definition at line 74 of file OSGNormalQuantifier.cpp. References _numberSubdivisions, getSubIndex(), osg::VecStorage3< ValueTypeT >::setValues(), osg::VecStorage3< ValueTypeT >::x(), osg::VecStorage3< ValueTypeT >::y(), and osg::VecStorage3< ValueTypeT >::z(). 00076 { 00077 UInt32 index; 00078 UInt32 nS; 00079 UInt32 octant; 00080 Int32 xoctant; 00081 Int32 yoctant; 00082 Int32 zoctant; 00083 00084 Vec3f point1; 00085 Vec3f point2; 00086 Vec3f point3; 00087 00088 if(numberSubdivisions == 0) 00089 { 00090 nS = _numberSubdivisions; 00091 } 00092 else if(numberSubdivisions > _numberSubdivisions) 00093 { 00094 nS = _numberSubdivisions; 00095 } 00096 else 00097 { 00098 nS = numberSubdivisions; 00099 } 00100 00101 octant = 00102 (((normal.x() >= 0) ? 0 : 1) << 2) | 00103 (((normal.y() >= 0) ? 0 : 1) << 1) | 00104 ( (normal.z() >= 0) ? 0 : 1); 00105 00106 xoctant = (octant & 4) ? -1 : 1; 00107 yoctant = (octant & 2) ? -1 : 1; 00108 zoctant = (octant & 1) ? -1 : 1; 00109 00110 point1.setValues(0.f * xoctant, 0.f * yoctant, 1.f * zoctant); 00111 point2.setValues(1.f * xoctant, 0.f * yoctant, 0.f * zoctant); 00112 point3.setValues(0.f * xoctant, 1.f * yoctant, 0.f * zoctant); 00113 00114 index = getSubIndex(normal, point1, point2, point3, nS); 00115 00116 index = (octant << (2 * nS)) + index; 00117 00118 return index; 00119 }
|
|
|
get a single normal by index Definition at line 46 of file OSGNormalQuantifier.inl. References _normalTable. 00047 { 00048 return _normalTable[index]; 00049 }
|
|
|
get the Size of a normals table (number of indices) Definition at line 55 of file OSGNormalQuantifier.inl. References _normalTable. 00056 { 00057 //return ((1<<(2*_numberSubdivisions))*8); 00058 return _normalTable.size(); 00059 }
|
|
|
fills the normal table with 8*(2^(2*numberSubdivisions)) Definition at line 126 of file OSGNormalQuantifier.cpp. References _normalTable, _numberSubdivisions, FFATAL, FLOG, and subdivide(). Referenced by NormalQuantifier(). 00127 { 00128 UInt32 index = 0; 00129 UInt32 nN = ((1 << (2 * numberSubdivisions)) * 8); 00130 00131 _numberSubdivisions = numberSubdivisions; 00132 00133 _normalTable.resize(nN); 00134 00135 if(_numberSubdivisions != 0) 00136 { 00137 for(UInt32 octant = 0; octant < 8; octant++) 00138 { 00139 Int32 xoctant = (octant & 4)>0?-1:1; 00140 Int32 yoctant = (octant & 2)>0?-1:1; 00141 Int32 zoctant = (octant & 1)>0?-1:1; 00142 00143 Vec3f point1(0.f * xoctant, 0.f * yoctant, 1.f * zoctant); 00144 Vec3f point2(1.f * xoctant, 0.f * yoctant, 0.f * zoctant); 00145 Vec3f point3(0.f * xoctant, 1.f * yoctant, 0.f * zoctant); 00146 00147 subdivide(point1, point2, point3, _numberSubdivisions+1, index); 00148 } 00149 00150 if(index != nN) 00151 { 00152 FFATAL(("NormalQuantifier::build() index missmatch!\n")); 00153 } 00154 else 00155 { 00156 FLOG(("NormalQuantifier init: %d subdivision, %d normal\n", 00157 _numberSubdivisions, _normalTable.size())); 00158 } 00159 } 00160 }
|
|
||||||||||||||||||||||||
|
recursive function to fill the NormalsTable Definition at line 224 of file OSGNormalQuantifier.cpp. References _normalTable, and osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(). Referenced by build(). 00229 { 00230 number--; 00231 00232 if(number == 0) 00233 { 00234 Vec3f newPoint = point1; 00235 00236 newPoint += point2; 00237 newPoint += point3; 00238 newPoint /= 3; 00239 00240 newPoint.normalize(); 00241 00242 _normalTable[index] = newPoint; 00243 ++index; 00244 } 00245 else 00246 { 00247 Vec3f newPoint1 = point1; 00248 00249 newPoint1 += point2; 00250 newPoint1 /= 2; 00251 newPoint1.normalize(); 00252 00253 Vec3f newPoint2 = point1; 00254 00255 newPoint2 += point3; 00256 newPoint2 /= 2; 00257 newPoint2.normalize(); 00258 00259 Vec3f newPoint3 = point2; 00260 00261 newPoint3 += point3; 00262 newPoint3 /= 2; 00263 newPoint3.normalize(); 00264 00265 subdivide(point1 , newPoint1, newPoint2, number, index); 00266 subdivide(newPoint1, point2 , newPoint3, number, index); 00267 subdivide(newPoint1, newPoint2, newPoint3, number, index); 00268 subdivide(newPoint2, newPoint3, point3 , number, index); 00269 } 00270 }
|
|
||||||||||||||||||||
|
recursive function to fill the NormalsTable Definition at line 170 of file OSGNormalQuantifier.cpp. References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(), and EPSILON. Referenced by getSubIndex(). 00174 { 00175 Vec3f edge1, edge2, tvec, pvec, qvec; 00176 float det,inv_det; 00177 float u,v; 00178 Vec3f orig(0,0,0); 00179 00180 /* find vectors for two edges sharing vert0 */ 00181 edge1 = vert1 - vert0; 00182 edge2 = vert2 - vert0; 00183 00184 /* begin calculating determinant - also used to calculate U parameter */ 00185 pvec = dir.cross(edge2); 00186 00187 /* if determinant is near zero, ray lies in plane of triangle */ 00188 det = edge1.dot(pvec); 00189 00190 /* the non-culling branch */ 00191 if (det > -EPSILON && det < EPSILON) 00192 return false; 00193 00194 inv_det = 1.0f / det; 00195 00196 /* calculate distance from vert0 to ray origin */ 00197 tvec = orig - vert0; 00198 00199 /* calculate U parameter and test bounds */ 00200 u = tvec.dot(pvec) *inv_det; 00201 00202 if (u < 0.0 || u > 1.0) 00203 return false; 00204 00205 /* prepare to test V parameter */ 00206 qvec = tvec.cross(edge1); 00207 00208 /* calculate V parameter and test bounds */ 00209 v = dir.dot(qvec) * inv_det; 00210 00211 if (v < 0.0 || u + v > 1.0) 00212 return false; 00213 00214 /* calculate t, ray intersects triangle */ 00215 //t = edge2.dot(qvec) * inv_det; 00216 00217 return true; 00218 };
|
|
||||||||||||||||||||||||
|
recursive function to get an index Definition at line 275 of file OSGNormalQuantifier.cpp. References FFATAL, osg::intersect(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), and rayTriangle(). Referenced by getIndex(). 00280 { 00281 int intersect = -1, index = 0; 00282 Vec3f newPoint1(point1); 00283 Vec3f newPoint2(point1); 00284 Vec3f newPoint3(point2); 00285 00286 //newPoint1 = (point1+point2)/2; newPoint1.normalize(); 00287 //newPoint2 = (point1+point3)/2; newPoint2.normalize(); 00288 //newPoint3 = (point2+point3)/2; newPoint3.normalize(); 00289 00290 newPoint1 += point2; 00291 newPoint1 /= 2; 00292 newPoint1.normalize(); 00293 00294 newPoint2 += point3; 00295 newPoint2 /=2; 00296 newPoint2.normalize(); 00297 00298 newPoint3 += point3; 00299 newPoint3 /= 2; 00300 newPoint3.normalize(); 00301 00302 number--; 00303 00304 if (rayTriangle(point, point1, newPoint1, newPoint2)) 00305 intersect = 0; 00306 else 00307 if (rayTriangle(point, newPoint1, point2, newPoint3)) 00308 intersect = 1; 00309 else 00310 if ( rayTriangle(point, newPoint1, newPoint2, newPoint3)) 00311 intersect = 2; 00312 else 00313 if ( rayTriangle(point, newPoint2, newPoint3, point3)) 00314 intersect = 3; 00315 00316 if ( intersect >= 0 ) { 00317 00318 index = intersect; 00319 00320 if (number != 0) { 00321 00322 index = index << (number*2); 00323 00324 switch (intersect) { 00325 case 0: 00326 index += getSubIndex(point, point1, newPoint1, newPoint2, number); 00327 break; 00328 case 1: 00329 index += getSubIndex(point, newPoint1, point2, newPoint3, number); 00330 break; 00331 case 2: 00332 index += getSubIndex(point, newPoint1, newPoint2, newPoint3, number); 00333 break; 00334 case 3: 00335 index += getSubIndex(point, newPoint2, newPoint3, point3, number); 00336 break; 00337 } 00338 } 00339 } 00340 else { 00341 FFATAL (( "Intersect < 0 in NormalQuantifier::getSubIndex()\n")); 00342 } 00343 00344 return index; 00345 }
|
|
|
|
|
|
Definition at line 102 of file OSGNormalQuantifier.h. Referenced by build(), and getIndex(). |
|
|
Definition at line 104 of file OSGNormalQuantifier.h. Referenced by build(), getNormal(), getNormalCount(), and subdivide(). |
1.4.3