Skip to content

Commit

Permalink
Merge branch 'master' into doc-blog-post
Browse files Browse the repository at this point in the history
  • Loading branch information
omichel committed Jun 23, 2023
2 parents 4841cfd + 8968285 commit 1225560
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
8 changes: 5 additions & 3 deletions resources/web/wwi/nodes/utils/WbBoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export default class WbBoundingSphere {

this.#subBoundingSpheres.add(subBoundingSphere);
subBoundingSphere.parentBoundingSphere = this;
this.boundSpaceDirty = true;
this.parentCoordinatesDirty = true;
this.parentUpdateNotification();
if (!this.boundSpaceDirty) {
this.boundSpaceDirty = true;
this.parentCoordinatesDirty = true;
this.parentUpdateNotification();
}
}

centerInParentCoordinates() {
Expand Down
21 changes: 21 additions & 0 deletions src/webots/nodes/WbCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "WbRobot.hpp"
#include "WbSFNode.hpp"
#include "WbSensor.hpp"
#include "WbSimulationState.hpp"
#include "WbStandardPaths.hpp"
#include "WbUrl.hpp"
#include "WbWorld.hpp"
Expand Down Expand Up @@ -124,6 +125,7 @@ void WbCamera::init() {
mRecognitionRefreshRate = 0;
mRecognizedObjects.clear();
mRecognizedObjectsTexture = NULL;
mIsSubscribedToRayTracing = false;
mSegmentationChanged = false;
mSegmentationCamera = NULL;
mSegmentationEnabled = false;
Expand Down Expand Up @@ -153,6 +155,9 @@ WbCamera::~WbCamera() {

delete mSegmentationCamera;
delete mSegmentationMemoryMappedFile;

if (mIsSubscribedToRayTracing)
WbSimulationState::instance()->unsubscribeToRayTracing();
}

void WbCamera::downloadAssets() {
Expand Down Expand Up @@ -982,6 +987,12 @@ void WbCamera::setup() {
updateAmbientOcclusionRadius();
updateBloomThreshold();
connect(mNoiseMaskUrl, &WbSFString::changed, this, &WbCamera::updateNoiseMaskUrl);

// make sure bounding sphere is updated when object's size and position changes
if (recognition()) {
mIsSubscribedToRayTracing = true;
WbSimulationState::instance()->subscribeToRayTracing();
}
}

bool WbCamera::isEnabled() const {
Expand Down Expand Up @@ -1036,6 +1047,16 @@ void WbCamera::updateRecognition() {
mRecognizedObjectsTexture = NULL;
}

// make sure bounding sphere is updated when object's size and position changes
const bool recognitionEnabled = recognitionNode != NULL;
if (recognitionEnabled != mIsSubscribedToRayTracing) {
mIsSubscribedToRayTracing = recognitionEnabled;
if (recognitionNode)
WbSimulationState::instance()->subscribeToRayTracing();
else
WbSimulationState::instance()->unsubscribeToRayTracing();
}

// clear mRecognizedObjects if Recognition node changed but not if `Recognition.segmentation` changed
qDeleteAll(mRecognizedObjects);
mRecognizedObjects.clear();
Expand Down
1 change: 1 addition & 0 deletions src/webots/nodes/WbCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class WbCamera : public WbAbstractCamera {
QList<WbRecognizedObject *> mRecognizedObjects;
QList<WbRecognizedObject *> mInvalidRecognizedObjects;
WrTexture *mRecognizedObjectsTexture;
bool mIsSubscribedToRayTracing;
// smart camera segmentation
void initializeSegmentationMemoryMappedFile();
void createSegmentationCamera();
Expand Down
2 changes: 1 addition & 1 deletion src/webots/nodes/WbSkin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void WbSkin::applyToScale() {
if (mBaseNode->areWrenObjectsInitialized())
applyScaleToWren();

if (mBaseNode->boundingSphere() && !mBaseNode->isInBoundingObject() && WbSimulationState::instance()->isRayTracingEnabled())
if (WbSimulationState::instance()->isRayTracingEnabled() && mBaseNode->boundingSphere())
mBaseNode->boundingSphere()->setOwnerSizeChanged();

if (mTranslateRotateManipulator && mTranslateRotateManipulator->isAttached())
Expand Down
2 changes: 1 addition & 1 deletion src/webots/nodes/WbTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void WbTransform::applyToScale() {
if (mBaseNode->areWrenObjectsInitialized())
applyScaleToWren();

if (mBaseNode->boundingSphere() && WbSimulationState::instance()->isRayTracingEnabled())
if (WbSimulationState::instance()->isRayTracingEnabled() && mBaseNode->boundingSphere())
mBaseNode->boundingSphere()->setOwnerSizeChanged();

if (mTranslateRotateManipulator && mTranslateRotateManipulator->isAttached())
Expand Down
26 changes: 15 additions & 11 deletions src/webots/nodes/utils/WbBoundingSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void WbBoundingSphere::set(const WbVector3 &center, const double radius) {
return;
mCenter = center;
mRadius = radius;
if (!gRayTracingEnabled) {
if (!gRayTracingEnabled && !mBoundSpaceDirty) {
mBoundSpaceDirty = true;
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
Expand All @@ -156,10 +156,12 @@ void WbBoundingSphere::addSubBoundingSphere(WbBoundingSphere *subBoundingSphere)
return;
mSubBoundingSpheres.append(subBoundingSphere);
subBoundingSphere->setParentBoundingSphere(this);
mBoundSpaceDirty = true;
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
parentUpdateNotification();
if (!mBoundSpaceDirty) {
mBoundSpaceDirty = true;
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
parentUpdateNotification();
}
}

void WbBoundingSphere::removeSubBoundingSphere(WbBoundingSphere *boundingSphere) {
Expand All @@ -168,7 +170,7 @@ void WbBoundingSphere::removeSubBoundingSphere(WbBoundingSphere *boundingSphere)
mSubBoundingSpheres.removeOne(boundingSphere);
if (mSubBoundingSpheres.isEmpty())
empty();
else {
else if (!mBoundSpaceDirty) {
mBoundSpaceDirty = true;
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
Expand Down Expand Up @@ -323,7 +325,7 @@ void WbBoundingSphere::parentUpdateNotification() const {

void WbBoundingSphere::setOwnerMoved() {
assert(mPoseOwner);
if (mParentBoundingSphere) {
if (mParentBoundingSphere && !mParentCoordinatesDirty) {
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
parentUpdateNotification();
Expand All @@ -332,10 +334,12 @@ void WbBoundingSphere::setOwnerMoved() {

void WbBoundingSphere::setOwnerSizeChanged() {
assert(mGeomOwner || mSkinOwner || mPoseOwner);
mBoundSpaceDirty = true;
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
parentUpdateNotification();
if (!mBoundSpaceDirty) {
mBoundSpaceDirty = true;
mParentCoordinatesDirty = true;
if (gUpdatesEnabled)
parentUpdateNotification();
}
}

WbBoundingSphere::IntersectingShape WbBoundingSphere::computeIntersection(const WbRay &ray, double timeStep) {
Expand Down
4 changes: 4 additions & 0 deletions src/webots/nodes/utils/WbVisualBoundingSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "WbBaseNode.hpp"
#include "WbBoundingSphere.hpp"
#include "WbPerspective.hpp"
#include "WbSimulationState.hpp"
#include "WbSphere.hpp"
#include "WbSysInfo.hpp"
#include "WbWorld.hpp"
Expand Down Expand Up @@ -102,10 +103,13 @@ WbVisualBoundingSphere::WbVisualBoundingSphere() :
mWrenSegmentationMaterial(NULL),
mWrenMesh(NULL),
mWrenRenderable(NULL) {
// make sure the bounding spheres are updates when node's position and size changes
WbSimulationState::instance()->subscribeToRayTracing();
}

WbVisualBoundingSphere::~WbVisualBoundingSphere() {
deleteWrenObjects();
WbSimulationState::instance()->unsubscribeToRayTracing();
}

void WbVisualBoundingSphere::show(const WbBaseNode *node) {
Expand Down

0 comments on commit 1225560

Please sign in to comment.