|
40 | 40 | #include "IECore/MurmurHash.h"
|
41 | 41 | #include "IECore/SimpleTypedData.h"
|
42 | 42 |
|
| 43 | +#include <tbb/parallel_reduce.h> |
| 44 | +#include <tbb/blocked_range.h> |
| 45 | + |
43 | 46 | using namespace std;
|
44 | 47 | using namespace Imath;
|
45 | 48 | using namespace IECore;
|
@@ -193,26 +196,45 @@ Imath::Box3f PointsPrimitive::bound() const
|
193 | 196 | // Compute the bounding box from the gathered data.
|
194 | 197 |
|
195 | 198 | Box3f result;
|
196 |
| - for( size_t i = 0; i < count; ++i ) |
197 |
| - { |
198 |
| - float r = constantWidth * *width / 2.0f; |
199 |
| - width += widthStep; |
200 |
| - if( aspectRatio ) |
201 |
| - { |
202 |
| - // Type is patch - the diagonal will be |
203 |
| - // longer than either the width or the |
204 |
| - // height, so derive a new radius from that. |
205 |
| - float hh = r; // half the height |
206 |
| - if( *aspectRatio != 0.0f ) |
| 199 | + using RangeType = tbb::blocked_range< const V3f* >; |
| 200 | + tbb::this_task_arena::isolate( [ =, & result ]{ |
| 201 | + tbb::task_group_context taskGroupContext( tbb::task_group_context::isolated ); |
| 202 | + result = tbb::parallel_reduce( RangeType( p, p + count, 1000 ), Imath::Box3f(), |
| 203 | + [ = ]( const RangeType& range, const Imath::Box3f& value ) -> Imath::Box3f |
207 | 204 | {
|
208 |
| - hh /= *aspectRatio; |
209 |
| - } |
210 |
| - r = sqrtf( r * r + hh * hh ); |
211 |
| - aspectRatio += aspectRatioStep; |
212 |
| - } |
213 |
| - result.extendBy( Box3f( *p - V3f( r ), *p + V3f( r ) ) ); |
214 |
| - p++; |
215 |
| - } |
| 205 | + Imath::Box3f b( value ); |
| 206 | + const size_t offset = range.begin() - p; |
| 207 | + const float* wIt = offset * widthStep + width; |
| 208 | + const float* aIt = offset * aspectRatioStep + aspectRatio; |
| 209 | + for( const V3f& pos : range ) |
| 210 | + { |
| 211 | + float r = constantWidth * ( *wIt ) / 2.0f; |
| 212 | + wIt += widthStep; |
| 213 | + if( aspectRatio ) |
| 214 | + { |
| 215 | + // Type is patch - the diagonal will be |
| 216 | + // longer than either the width or the |
| 217 | + // height, so derive a new radius from that. |
| 218 | + float hh = r; // half the height |
| 219 | + if( ( *aIt ) != 0.0f ) |
| 220 | + { |
| 221 | + hh /= ( *aIt ); |
| 222 | + } |
| 223 | + r = sqrtf( r * r + hh * hh ); |
| 224 | + aIt += aspectRatioStep; |
| 225 | + } |
| 226 | + b.extendBy( Box3f( pos - V3f( r ), pos + V3f( r ) ) ); |
| 227 | + } |
| 228 | + return b; |
| 229 | + }, |
| 230 | + []( const Imath::Box3f& lhs, const Imath::Box3f& rhs ) -> Imath::Box3f |
| 231 | + { |
| 232 | + Imath::Box3f b( lhs ); |
| 233 | + b.extendBy( rhs ); |
| 234 | + return b; |
| 235 | + }, |
| 236 | + taskGroupContext ); |
| 237 | + } ); |
216 | 238 |
|
217 | 239 | return result;
|
218 | 240 | }
|
|
0 commit comments