@@ -119,11 +119,34 @@ namespace pov
119
119
* Local preprocessor defines
120
120
******************************************************************************/
121
121
122
- /* Minimal intersection depth for a valid intersection. */
123
- const DBL DEPTH_TOLERANCE = 1.0e-2 ;
122
+ // / @def DEPTH_TOLERANCE
123
+ // / Minimum returned intersection depth for a valid intersection.
124
+ // /
125
+ // / @note
126
+ // / Value for @ref DEPTH_TOLERANCE was since v1.0 set to 1.0e-2. Further the
127
+ // / value was used for both ling used for the minimum returned and as a mindist
128
+ // / in all of the determine_influences()'s intersect_<thing> functions. The
129
+ // / latter probably done initially to help the initial solve_quartic() function
130
+ // / though using such a large value to determine when to add and remove
131
+ // / sub-element influences caused artifacts. In 3.7 when the subsurface (SSLT)
132
+ // / feature was added a special conditional existed which set both values to
133
+ // / 0.0. Currently a 0.0 value is used for all but the returned intersection
134
+ // / where @ref MIN_ISECT_DEPTH is now used. In testing all worked with 0.0, but
135
+ // / there is a performance hit to returning all >0.0 intersections. For example,
136
+ // / internal refelections at distances which must be ignored in downstream code.
137
+ // /
138
+ const DBL DEPTH_TOLERANCE = MIN_ISECT_DEPTH;
124
139
125
- /* Tolerance for inside test. */
126
- const DBL INSIDE_TOLERANCE = 1.0e-6 ;
140
+ // / @def INSIDE_TOLERANCE
141
+ // / Density tolerance for inside test.
142
+ // /
143
+ // / @note
144
+ // / Value for @ref INSIDE_TOLERANCE was since v1.0 set to 1.0e-6 which is a good
145
+ // / value if running single floats. With double floats a value of 1e-15 is better.
146
+ // / This is an offset to the inside of the 0.0 density surface after the blob
147
+ // / threshold is subtracted. Now using std::numeric_limits to set.
148
+ // /
149
+ const DBL INSIDE_TOLERANCE = 1 /std::numeric_limits<DBL>::digits10;
127
150
128
151
/* Ray enters/exits a component. */
129
152
const int ENTERING = 0 ;
@@ -239,7 +262,6 @@ bool Blob::All_Intersections(const Ray& ray, IStack& Depth_Stack, TraceThreadDat
239
262
DBL newcoeffs[5 ], dk[5 ];
240
263
DBL max_bound;
241
264
DBL l, w;
242
- DBL depthTolerance = (ray.IsSubsurfaceRay ()? 0 : DEPTH_TOLERANCE);
243
265
244
266
Thread->Stats ()[Ray_Blob_Tests]++;
245
267
@@ -263,7 +285,7 @@ bool Blob::All_Intersections(const Ray& ray, IStack& Depth_Stack, TraceThreadDat
263
285
264
286
/* Get the intervals along the ray where each component has an effect. */
265
287
Blob_Interval_Struct* intervals = Thread->Blob_Intervals ;
266
- if ((cnt = determine_influences (P, D, depthTolerance, intervals, Thread)) == 0 )
288
+ if ((cnt = determine_influences (P, D, intervals, Thread)) == 0 )
267
289
{
268
290
/* Ray doesn't hit any of the component elements. */
269
291
return (false );
@@ -528,7 +550,7 @@ bool Blob::All_Intersections(const Ray& ray, IStack& Depth_Stack, TraceThreadDat
528
550
529
551
dist = (dist * max_bound + start_dist) / len;
530
552
531
- if ((dist > depthTolerance ) && (dist < MAX_DISTANCE))
553
+ if ((dist > DEPTH_TOLERANCE ) && (dist < MAX_DISTANCE))
532
554
{
533
555
IPoint = ray.Evaluate (dist);
534
556
@@ -600,7 +622,8 @@ bool Blob::All_Intersections(const Ray& ray, IStack& Depth_Stack, TraceThreadDat
600
622
*
601
623
******************************************************************************/
602
624
603
- void Blob::insert_hit (const Blob_Element *Element, DBL t0, DBL t1, Blob_Interval_Struct *intervals, unsigned int *cnt)
625
+ void Blob::insert_hit (const Blob_Element *Element, DBL t0, DBL t1,
626
+ Blob_Interval_Struct *intervals, unsigned int *cnt)
604
627
{
605
628
unsigned int k;
606
629
@@ -678,7 +701,6 @@ void Blob::insert_hit(const Blob_Element *Element, DBL t0, DBL t1, Blob_Interval
678
701
*
679
702
* Element - Pointer to element structure
680
703
* P, D - Ray = P + t * D
681
- * mindist - Min. valid distance
682
704
*
683
705
* OUTPUT
684
706
*
@@ -700,7 +722,8 @@ void Blob::insert_hit(const Blob_Element *Element, DBL t0, DBL t1, Blob_Interval
700
722
*
701
723
******************************************************************************/
702
724
703
- int Blob::intersect_cylinder (const Blob_Element *Element, const Vector3d& P, const Vector3d& D, DBL mindist, DBL *tmin, DBL *tmax)
725
+ int Blob::intersect_cylinder (const Blob_Element *Element, const Vector3d& P,
726
+ const Vector3d& D, DBL *tmin, DBL *tmax)
704
727
{
705
728
DBL a, b, c, d, t, u, v, w, len;
706
729
Vector3d PP, DD;
@@ -786,8 +809,8 @@ int Blob::intersect_cylinder(const Blob_Element *Element, const Vector3d& P, con
786
809
*tmin /= len;
787
810
*tmax /= len;
788
811
789
- if (*tmin < mindist ) { *tmin = 0.0 ; }
790
- if (*tmax < mindist ) { *tmax = 0.0 ; }
812
+ if (*tmin < 0.0 ) { *tmin = 0.0 ; }
813
+ if (*tmax < 0.0 ) { *tmax = 0.0 ; }
791
814
792
815
if (*tmin >= *tmax)
793
816
{
@@ -809,7 +832,6 @@ int Blob::intersect_cylinder(const Blob_Element *Element, const Vector3d& P, con
809
832
*
810
833
* Element - Pointer to element structure
811
834
* P, D - Ray = P + t * D
812
- * mindist - Min. valid distance
813
835
*
814
836
* OUTPUT
815
837
*
@@ -831,7 +853,8 @@ int Blob::intersect_cylinder(const Blob_Element *Element, const Vector3d& P, con
831
853
*
832
854
******************************************************************************/
833
855
834
- int Blob::intersect_ellipsoid (const Blob_Element *Element, const Vector3d& P, const Vector3d& D, DBL mindist, DBL *tmin, DBL *tmax)
856
+ int Blob::intersect_ellipsoid (const Blob_Element *Element, const Vector3d& P,
857
+ const Vector3d& D, DBL *tmin, DBL *tmax)
835
858
{
836
859
DBL b, d, t, len;
837
860
Vector3d V1, PP, DD;
@@ -855,8 +878,8 @@ int Blob::intersect_ellipsoid(const Blob_Element *Element, const Vector3d& P, co
855
878
856
879
d = sqrt (d);
857
880
858
- *tmax = ( - b + d) / len; if (*tmax < mindist ) { *tmax = 0.0 ; }
859
- *tmin = ( - b - d) / len; if (*tmin < mindist ) { *tmin = 0.0 ; }
881
+ *tmax = ( - b + d) / len; if (*tmax < 0.0 ) { *tmax = 0.0 ; }
882
+ *tmin = ( - b - d) / len; if (*tmin < 0.0 ) { *tmin = 0.0 ; }
860
883
861
884
if (*tmax == *tmin)
862
885
{
@@ -885,7 +908,6 @@ int Blob::intersect_ellipsoid(const Blob_Element *Element, const Vector3d& P, co
885
908
*
886
909
* Element - Pointer to element structure
887
910
* P, D - Ray = P + t * D
888
- * mindist - Min. valid distance
889
911
*
890
912
* OUTPUT
891
913
*
@@ -907,7 +929,8 @@ int Blob::intersect_ellipsoid(const Blob_Element *Element, const Vector3d& P, co
907
929
*
908
930
******************************************************************************/
909
931
910
- int Blob::intersect_hemisphere (const Blob_Element *Element, const Vector3d& P, const Vector3d& D, DBL mindist, DBL *tmin, DBL *tmax)
932
+ int Blob::intersect_hemisphere (const Blob_Element *Element, const Vector3d& P,
933
+ const Vector3d& D, DBL *tmin, DBL *tmax)
911
934
{
912
935
DBL b, d, t, z1, z2, len;
913
936
Vector3d PP, DD;
@@ -972,13 +995,13 @@ int Blob::intersect_hemisphere(const Blob_Element *Element, const Vector3d& P, c
972
995
{
973
996
/* Ray is crossing the plane from inside to outside. */
974
997
975
- *tmin = (t < mindist ) ? 0.0 : t;
998
+ *tmin = (t < 0.0 ) ? 0.0 : t;
976
999
}
977
1000
else
978
1001
{
979
1002
/* Ray is crossing the plane from outside to inside. */
980
1003
981
- *tmax = (t < mindist ) ? 0.0 : t;
1004
+ *tmax = (t < 0.0 ) ? 0.0 : t;
982
1005
}
983
1006
984
1007
*tmin /= len;
@@ -1040,13 +1063,13 @@ int Blob::intersect_hemisphere(const Blob_Element *Element, const Vector3d& P, c
1040
1063
{
1041
1064
/* Ray is crossing the plane from inside to outside. */
1042
1065
1043
- *tmin = (t < mindist ) ? 0.0 : t;
1066
+ *tmin = (t < 0.0 ) ? 0.0 : t;
1044
1067
}
1045
1068
else
1046
1069
{
1047
1070
/* Ray is crossing the plane from outside to inside. */
1048
1071
1049
- *tmax = (t < mindist ) ? 0.0 : t;
1072
+ *tmax = (t < 0.0 ) ? 0.0 : t;
1050
1073
}
1051
1074
1052
1075
*tmin /= len;
@@ -1068,7 +1091,6 @@ int Blob::intersect_hemisphere(const Blob_Element *Element, const Vector3d& P, c
1068
1091
*
1069
1092
* Element - Pointer to element structure
1070
1093
* P, D - Ray = P + t * D
1071
- * mindist - Min. valid distance
1072
1094
*
1073
1095
* OUTPUT
1074
1096
*
@@ -1090,7 +1112,8 @@ int Blob::intersect_hemisphere(const Blob_Element *Element, const Vector3d& P, c
1090
1112
*
1091
1113
******************************************************************************/
1092
1114
1093
- int Blob::intersect_sphere (const Blob_Element *Element, const Vector3d& P, const Vector3d& D, DBL mindist, DBL *tmin, DBL *tmax)
1115
+ int Blob::intersect_sphere (const Blob_Element *Element, const Vector3d& P,
1116
+ const Vector3d& D, DBL *tmin, DBL *tmax)
1094
1117
{
1095
1118
DBL b, d, t;
1096
1119
Vector3d V1;
@@ -1108,8 +1131,8 @@ int Blob::intersect_sphere(const Blob_Element *Element, const Vector3d& P, const
1108
1131
1109
1132
d = sqrt (d);
1110
1133
1111
- *tmax = - b + d; if (*tmax < mindist ) { *tmax = 0.0 ; }
1112
- *tmin = - b - d; if (*tmin < mindist ) { *tmin = 0.0 ; }
1134
+ *tmax = - b + d; if (*tmax < 0.0 ) { *tmax = 0.0 ; }
1135
+ *tmin = - b - d; if (*tmin < 0.0 ) { *tmin = 0.0 ; }
1113
1136
1114
1137
if (*tmax == *tmin)
1115
1138
{
@@ -1138,7 +1161,6 @@ int Blob::intersect_sphere(const Blob_Element *Element, const Vector3d& P, const
1138
1161
*
1139
1162
* P, D - Ray = P + t * D
1140
1163
* Element - Pointer to element structure
1141
- * mindist - Min. valid distance
1142
1164
*
1143
1165
* OUTPUT
1144
1166
*
@@ -1160,7 +1182,8 @@ int Blob::intersect_sphere(const Blob_Element *Element, const Vector3d& P, const
1160
1182
*
1161
1183
******************************************************************************/
1162
1184
1163
- int Blob::intersect_element (const Vector3d& P, const Vector3d& D, const Blob_Element *Element, DBL mindist, DBL *tmin, DBL *tmax, TraceThreadData *Thread)
1185
+ int Blob::intersect_element (const Vector3d& P, const Vector3d& D, const Blob_Element *Element,
1186
+ DBL *tmin, DBL *tmax, TraceThreadData *Thread)
1164
1187
{
1165
1188
#ifdef BLOB_EXTRA_STATS
1166
1189
Thread->Stats ()[Blob_Element_Tests]++;
@@ -1173,7 +1196,7 @@ int Blob::intersect_element(const Vector3d& P, const Vector3d& D, const Blob_Ele
1173
1196
{
1174
1197
case BLOB_SPHERE:
1175
1198
1176
- if (!intersect_sphere (Element, P, D, mindist, tmin, tmax))
1199
+ if (!intersect_sphere (Element, P, D, tmin, tmax))
1177
1200
{
1178
1201
return (false );
1179
1202
}
@@ -1182,7 +1205,7 @@ int Blob::intersect_element(const Vector3d& P, const Vector3d& D, const Blob_Ele
1182
1205
1183
1206
case BLOB_ELLIPSOID:
1184
1207
1185
- if (!intersect_ellipsoid (Element, P, D, mindist, tmin, tmax))
1208
+ if (!intersect_ellipsoid (Element, P, D, tmin, tmax))
1186
1209
{
1187
1210
return (false );
1188
1211
}
@@ -1192,7 +1215,7 @@ int Blob::intersect_element(const Vector3d& P, const Vector3d& D, const Blob_Ele
1192
1215
case BLOB_BASE_HEMISPHERE:
1193
1216
case BLOB_APEX_HEMISPHERE:
1194
1217
1195
- if (!intersect_hemisphere (Element, P, D, mindist, tmin, tmax))
1218
+ if (!intersect_hemisphere (Element, P, D, tmin, tmax))
1196
1219
{
1197
1220
return (false );
1198
1221
}
@@ -1201,7 +1224,7 @@ int Blob::intersect_element(const Vector3d& P, const Vector3d& D, const Blob_Ele
1201
1224
1202
1225
case BLOB_CYLINDER:
1203
1226
1204
- if (!intersect_cylinder (Element, P, D, mindist, tmin, tmax))
1227
+ if (!intersect_cylinder (Element, P, D, tmin, tmax))
1205
1228
{
1206
1229
return (false );
1207
1230
}
@@ -1228,7 +1251,6 @@ int Blob::intersect_element(const Vector3d& P, const Vector3d& D, const Blob_Ele
1228
1251
*
1229
1252
* P, D - Ray = P + t * D
1230
1253
* Blob - Pointer to blob structure
1231
- * mindist - Min. valid distance
1232
1254
*
1233
1255
* OUTPUT
1234
1256
*
@@ -1253,7 +1275,8 @@ int Blob::intersect_element(const Vector3d& P, const Vector3d& D, const Blob_Ele
1253
1275
*
1254
1276
******************************************************************************/
1255
1277
1256
- int Blob::determine_influences (const Vector3d& P, const Vector3d& D, DBL mindist, Blob_Interval_Struct *intervals, TraceThreadData *Thread) const
1278
+ int Blob::determine_influences (const Vector3d& P, const Vector3d& D,
1279
+ Blob_Interval_Struct *intervals, TraceThreadData *Thread) const
1257
1280
{
1258
1281
unsigned int cnt, size;
1259
1282
DBL b, t, t0, t1;
@@ -1269,7 +1292,7 @@ int Blob::determine_influences(const Vector3d& P, const Vector3d& D, DBL mindist
1269
1292
1270
1293
for (vector<Blob_Element>::iterator i = Data->Entry .begin (); i != Data->Entry .end (); ++i)
1271
1294
{
1272
- if (intersect_element (P, D, &(*i), mindist, &t0, &t1, Thread))
1295
+ if (intersect_element (P, D, &(*i), &t0, &t1, Thread))
1273
1296
{
1274
1297
insert_hit (&(*i), t0, t1, intervals, &cnt);
1275
1298
}
@@ -1293,7 +1316,7 @@ int Blob::determine_influences(const Vector3d& P, const Vector3d& D, DBL mindist
1293
1316
{
1294
1317
/* Test element. */
1295
1318
1296
- if (intersect_element (P, D, reinterpret_cast <Blob_Element *>(Tree->Node ), mindist, &t0, &t1, Thread))
1319
+ if (intersect_element (P, D, reinterpret_cast <Blob_Element *>(Tree->Node ), &t0, &t1, Thread))
1297
1320
{
1298
1321
insert_hit (reinterpret_cast <Blob_Element *>(Tree->Node ), t0, t1, intervals, &cnt);
1299
1322
}
0 commit comments