Skip to content

Commit e570ba5

Browse files
committed
Fixed broken iso surface calculation for border regions
1 parent 311ce5b commit e570ba5

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

lib/isaac/isaac_kernel.hpp

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ ISAAC_HOST_DEVICE_INLINE void check_coord( isaac_float3& coord, const TLocalSize
261261
if (coord.z < isaac_float(0))
262262
coord.z = isaac_float(0);
263263
if ( coord.x >= isaac_float(local_size.value.x) )
264-
coord.x = isaac_float(local_size.value.x)-isaac_float(1);
264+
coord.x = isaac_float(local_size.value.x)-isaac_float(1)-FLT_MIN;
265265
if ( coord.y >= isaac_float(local_size.value.y) )
266-
coord.y = isaac_float(local_size.value.y)-isaac_float(1);
266+
coord.y = isaac_float(local_size.value.y)-isaac_float(1)-FLT_MIN;
267267
if ( coord.z >= isaac_float(local_size.value.z) )
268-
coord.z = isaac_float(local_size.value.z)-isaac_float(1);
268+
coord.z = isaac_float(local_size.value.z)-isaac_float(1)-FLT_MIN;
269269
}
270270

271271
template <
@@ -289,7 +289,11 @@ struct merge_source_iterator
289289
typename TFeedback,
290290
typename TStep,
291291
typename TStepLength,
292-
typename TScale
292+
typename TScale,
293+
typename TFirst,
294+
typename TLast,
295+
typename TStartNormal,
296+
typename TEndNormal
293297
>
294298
ISAAC_HOST_DEVICE_INLINE void operator()(
295299
const NR& nr,
@@ -303,7 +307,11 @@ struct merge_source_iterator
303307
TFeedback& feedback,
304308
const TStep& step,
305309
const TStepLength& stepLength,
306-
const TScale& scale
310+
const TScale& scale,
311+
const TFirst& first,
312+
const TLast& last,
313+
const TStartNormal& start_normal,
314+
const TEndNormal& end_normal
307315
) const
308316
{
309317
if ( mpl::at_c< TFilter, NR::value >::type::value )
@@ -370,6 +378,18 @@ struct merge_source_iterator
370378
(get_value< TInterpolation, NR >( source, back, pointerArray, local_size, scale ) -
371379
get_value< TInterpolation, NR >( source, front, pointerArray, local_size, scale )) / d3
372380
};
381+
if (first)
382+
{
383+
gradient.x = start_normal.x;
384+
gradient.y = start_normal.y;
385+
gradient.z = start_normal.z;
386+
}
387+
if (last)
388+
{
389+
gradient.x = end_normal.x;
390+
gradient.y = end_normal.y;
391+
gradient.z = end_normal.z;
392+
}
373393
isaac_float l = sqrt(
374394
gradient.x * gradient.x +
375395
gradient.y * gradient.y +
@@ -522,6 +542,8 @@ template <
522542
isaac_float3 count_start[ISAAC_VECTOR_ELEM];
523543
isaac_float3 local_size_f[ISAAC_VECTOR_ELEM];
524544
isaac_float3 count_end[ISAAC_VECTOR_ELEM];
545+
isaac_float3 start_normal[ISAAC_VECTOR_ELEM];
546+
isaac_float3 end_normal[ISAAC_VECTOR_ELEM];
525547

526548
ISAAC_ELEM_ITERATE(e)
527549
{
@@ -604,8 +626,22 @@ template <
604626
ISAAC_SWITCH_IF_SMALLER( count_end[e].z, count_start[e].z )
605627

606628
//calc intersection of all three super planes and save in [count_start.x ; count_end.x]
607-
count_start[e].x = ISAAC_MAX( ISAAC_MAX( count_start[e].x, count_start[e].y ), count_start[e].z );
608-
count_end[e].x = ISAAC_MIN( ISAAC_MIN( count_end[e].x, count_end[e].y ), count_end[e].z );
629+
float max_start = ISAAC_MAX( ISAAC_MAX( count_start[e].x, count_start[e].y ), count_start[e].z );
630+
if (count_start[e].x == max_start)
631+
start_normal[e] = {-1,0,0};
632+
if (count_start[e].y == max_start)
633+
start_normal[e] = {0,-1,0};
634+
if (count_start[e].z == max_start)
635+
start_normal[e] = {0,0,-1};
636+
count_start[e].x = max_start;
637+
float min_end = ISAAC_MIN( ISAAC_MIN( count_end[e].x, count_end[e].y ), count_end[e].z );
638+
if (count_end[e].x == min_end)
639+
end_normal[e] = {-1,0,0};
640+
if (count_end[e].y == min_end)
641+
end_normal[e] = {0,-1,0};
642+
if (count_end[e].z == min_end)
643+
end_normal[e] = {0,0,-1};
644+
count_end[e].x = min_end;
609645
if ( count_start[e].x > count_end[e].x)
610646
{
611647
if (!finish[e])
@@ -676,7 +712,12 @@ template <
676712
finish[e] = true;
677713
}
678714
if ( first[e] < intersection_step[e] )
715+
{
679716
first[e] = ceil( intersection_step[e] );
717+
start_normal[e].x = clipping[e].elem[i].normal.x;
718+
start_normal[e].y = clipping[e].elem[i].normal.y;
719+
start_normal[e].z = clipping[e].elem[i].normal.z;
720+
}
680721
}
681722
else
682723
{
@@ -687,7 +728,12 @@ template <
687728
finish[e] = true;
688729
}
689730
if ( last[e] > intersection_step[e] )
731+
{
690732
last[e] = floor( intersection_step[e] );
733+
end_normal[e].x = clipping[e].elem[i].normal.x;
734+
end_normal[e].y = clipping[e].elem[i].normal.y;
735+
end_normal[e].z = clipping[e].elem[i].normal.z;
736+
}
691737
}
692738
}
693739
}
@@ -716,6 +762,8 @@ template <
716762
value[e].z = 0;
717763
value[e].w = 0;
718764
result[e] = 0;
765+
bool firstRound = (i == first[e]);
766+
bool lastRound = (i == last[e]);
719767
isaac_for_each_with_mpl_params
720768
(
721769
sources,
@@ -735,7 +783,11 @@ template <
735783
result[e],
736784
step_vec[e],
737785
step,
738-
scale
786+
scale,
787+
firstRound,
788+
lastRound,
789+
start_normal[e],
790+
end_normal[e]
739791
);
740792
/*if ( mpl::size< TSourceList >::type::value > 1)
741793
value = value / isaac_float( mpl::size< TSourceList >::type::value );*/

0 commit comments

Comments
 (0)