MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / calcBox_

Method calcBox_

source/MRViewer/MRViewportCamera.cpp:552–843  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550}
551
552Box3f Viewport::calcBox_( const std::vector<std::shared_ptr<VisualObject>>& objs, Space space, bool selectedPrimitives /*= false*/ ) const
553{
554 Box3f box;
555
556 // object space to camera space
557 const auto makeObj2Cam = [space, xfV = getViewXf_()] ( const AffineXf3f& xfObj ) -> ObjectToCameraFunc
558 {
559 switch ( space )
560 {
561 case Space::World:
562 return [xf = xfObj] ( Vector3f& p )
563 {
564 p = xf( p );
565 return true;
566 };
567 case Space::CameraOrthographic:
568 return [xf = xfV * xfObj] ( Vector3f& p )
569 {
570 p = xf( p );
571 return true;
572 };
573 case Space::CameraPerspective:
574 return [xf = xfV * xfObj] ( Vector3f& p )
575 {
576 auto v = xf( p );
577 if ( v.z == 0 )
578 return false;
579 p = Vector3f( v.x / v.z, v.y / v.z, v.z );
580 return true;
581 };
582 }
583 MR_UNREACHABLE
584 };
585
586 const auto expandBox = [&box] ( const VertCoords& coords, const VertBitSet& region, const ObjectToCameraFunc& obj2cam )
587 {
588 LimitCalc calc( coords, region, obj2cam );
589 parallel_reduce( tbb::blocked_range( region.find_first(), region.find_last() + 1 ), calc );
590 box.include( calc.box() );
591 };
592
593 for ( const auto& obj : objs )
594 {
595 if ( !obj->globalVisibility( id ) )
596 continue;
597
598 const auto xf = obj->worldXf( id );
599 const auto obj2cam = makeObj2Cam( xf );
600
601 if ( selectedPrimitives )
602 {
603 if ( auto* objMesh = obj->asType<ObjectMeshHolder>() )
604 {
605 if ( !objMesh->mesh() )
606 continue;
607
608 const auto& mesh = *objMesh->mesh();
609 const auto region =

Callers

nothing calls this directly

Calls 10

getIncidentVertsFunction · 0.85
getCornersFunction · 0.85
worldXfMethod · 0.80
multFunction · 0.50
find_firstMethod · 0.45
find_lastMethod · 0.45
includeMethod · 0.45
anyMethod · 0.45
getBoundingBoxMethod · 0.45
validMethod · 0.45

Tested by

no test coverage detected