MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / PickTriangles

Method PickTriangles

GTE/Graphics/Picker.cpp:254–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252
253
254void Picker::PickTriangles(std::shared_ptr<Visual> const& visual, char const* positions,
255 uint32_t vstride, IndexBuffer* ibuffer, Line3<float> const& line)
256{
257 // Partition the items for multiple threads.
258 auto const firstTriangle = ibuffer->GetFirstPrimitive();
259 auto const numTriangles = ibuffer->GetNumActivePrimitives();
260 auto const numThreads = std::min(numTriangles, mNumThreads);
261
262 if (numThreads > 1)
263 {
264 auto const numPerThread = numTriangles / numThreads;
265 std::vector<int32_t> imin(numThreads), imax(numThreads);
266 for (uint32_t t = 0; t < numThreads; ++t)
267 {
268 imin[t] = firstTriangle + t * numPerThread;
269 imax[t] = imin[t] + numPerThread - 1;
270 }
271 imax[static_cast<size_t>(numThreads) - 1] = firstTriangle + numTriangles - 1;
272
273 // Process blocks of items in multiple threads.
274 std::vector<std::thread> process(numThreads);
275 std::vector<std::vector<PickRecord>> threadOutputs(numThreads);
276 for (uint32_t t = 0; t < numThreads; ++t)
277 {
278 auto const i0 = imin[t];
279 auto const i1 = imax[t];
280 process[t] = std::thread(
281 [this, t, visual, positions, vstride, ibuffer, line, i0, i1, &threadOutputs]()
282 {
283 PickTriangles(visual, positions, vstride, ibuffer, line,
284 i0, i1, threadOutputs[t]);
285 });
286 }
287
288 // Wait for all threads to finish.
289 for (uint32_t t = 0; t < numThreads; ++t)
290 {
291 process[t].join();
292 std::copy(threadOutputs[t].begin(), threadOutputs[t].end(), std::back_inserter(records));
293 }
294 }
295 else
296 {
297 PickTriangles(visual, positions, vstride, ibuffer, line,
298 firstTriangle, firstTriangle + numTriangles - 1, records);
299 }
300}
301
302void Picker::PickTriangles(std::shared_ptr<Visual> const& visual, char const* positions,
303 uint32_t vstride, IndexBuffer* ibuffer, Line3<float> const& line,

Callers

nothing calls this directly

Calls 9

GetFirstPrimitiveMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
IsIndexedMethod · 0.80
GetPrimitiveTypeMethod · 0.80
HLiftFunction · 0.50
LengthFunction · 0.50
GetTriangleMethod · 0.45

Tested by

no test coverage detected