-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pcl::weak_ptr
to have a single-switch move from boost::
to std::
weak pointers
#3753
Conversation
Hah! It is in the public API, it's being passed around after the lock in the .cpp file. I don't think there's a way, is there? |
Creating a |
I have it locally, but it seems way too much for a single instance honestly, don't you think? |
Here you can see what I had |
Another option is to create a local type-alias, like used for all shared_ptr |
Going down the rabbit hole of fixing the weak pointers leads to the app Point Cloud Editor. There, it becomes an exercise in futility as there's a circular dependency between the classes Cloud and Selection impeding progress if one wanted to have nice I stand by the idea of leaving the toggle where it is currently for |
Some of the patch could be integrated as is, while other needs change (for the same reasons as circular dependency). Only public facing API needs to be type-aliased, and I don't think There shouldn't be a circular dependency. The reason is that the class which uses the type-alias is the one declaring it, not the class being used. If this were not the case, every class will need to come with it's own #include <memory>
#include <boost/shared_ptr.hpp>
//---
class A;
class B;
class A{
using DataPtr = std::shared_ptr<B>;
DataPtr data;
};
class B {
using ControllerPtr = boost::shared_ptr<A>;
using ControllerWeakPtr = boost::shared_ptr<A>;
ControllerWeakPtr controller;
ControllerPtr fixController();
}; |
You think I should keep the typedef confined to
Are you suggesting to remove these (in PointCloudEditor only) in favour of private typedefs with the full name
pcl/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/selection.h Lines 55 to 65 in fb8ca1b
pcl/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/selection.h Lines 67 to 72 in fb8ca1b
pcl/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/cloud.h Lines 212 to 216 in fb8ca1b
|
Yeah, sort of, except replace with public type alias if the type is used in public API, else no type alias needed.
PCL hasn't been perfect over the years, and as such there have been exceptions in the code. The best example would be use of
That's the issue. This approach is ok in most cases, but fails when it causes circular references. On the other hand, using approach 1 and 2 (declared when needed and externally declared) don't cause such issues. |
Notes on 4041300: is this how you intended it to be? If it is, I can finish up by removing all the |
Yes. Please note that you can exclude aliases for something not in public domain to reduce the work needed to be done. |
I was doing it but realized there's no real reason to remove aliases in localTypes.h in this PR. This is currently the minimum to get this |
@@ -412,7 +421,7 @@ class Cloud : public Statistics | |||
/// @brief A weak pointer pointing to the selection object. | |||
/// @details This implementation uses the weak pointer to allow for a lazy | |||
/// update of the cloud if the selection object is destroyed. | |||
std::weak_ptr<Selection> selection_wk_ptr_; | |||
SelectionWeakPtr selection_wk_ptr_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from here, this isn't used anywhere else. Is this a public variable (named like a protected/private variable)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pcl/apps/point_cloud_editor/src/cloud.cpp
Lines 184 to 199 in d6ac1e8
void | |
Cloud::setSelection (const SelectionPtr& selection_ptr) | |
{ | |
selection_wk_ptr_ = selection_ptr; | |
if (!selection_ptr || selection_ptr->empty()) | |
return; | |
IncIndex inc; | |
partitioned_indices_.resize(cloud_.size()); | |
std::generate(partitioned_indices_.begin(), partitioned_indices_.end(), inc); | |
unsigned int pos = 0; | |
// assumes selection is sorted small to large | |
for (auto it = selection_ptr->begin(); it != selection_ptr->end(); ++it, ++pos) | |
{ | |
std::swap(partitioned_indices_[pos], partitioned_indices_[*it]); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not an interface boundary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this pointer becomes a boost::weak_ptr
due to being a pcl:weak_ptr
then I can't convert it to a std::shared_ptr
within this function. If this instead will not be changed to a pcl:weak_ptr
then I was right in closing this PR 18 days ago: I thought it was clear I was continuing the work here and within this PCL app only because you indirectly said it was worth it:
I stand by the idea of leaving the toggle where it is currently for
std::weak_ptr
s. [...] To continue here you really need to love the idea of thispcl::weak_ptr
.
from #3753 (comment)
I'd have otherwise left the micro change inside #3750 since it's about 4 lines worth like Sergio pointed out.
Hey @kunaltyagi any feedback here? |
Guys, this PR spiraled out of control. The last boost::weak_ptr replacement will need to happen alongside the shared pointer alias switch.
This would have been enough $ git diff
diff --git a/common/include/pcl/memory.h b/common/include/pcl/memory.h
index 4037c5ace..009f7ee91 100644
--- a/common/include/pcl/memory.h
+++ b/common/include/pcl/memory.h
@@ -47,6 +47,7 @@
#include <boost/make_shared.hpp> // for boost::allocate_shared, boost::make_shared
#include <boost/smart_ptr/shared_ptr.hpp> // for boost::shared_ptr
+#include <boost/smart_ptr/weak_ptr.hpp> // for boost::weak_ptr
#include <Eigen/Core> // for EIGEN_MAKE_ALIGNED_OPERATOR_NEW
@@ -80,6 +81,9 @@ namespace pcl
template <typename T>
using shared_ptr = boost::shared_ptr<T>;
+
+using boost::weak_ptr;
+
#ifdef DOXYGEN_ONLY
/**
diff --git a/io/include/pcl/io/openni_camera/openni_driver.h b/io/include/pcl/io/openni_camera/openni_driver.h
index 6ece49406..9317a7853 100644
--- a/io/include/pcl/io/openni_camera/openni_driver.h
+++ b/io/include/pcl/io/openni_camera/openni_driver.h
@@ -43,6 +43,7 @@
#include "openni_exception.h"
#include "openni_device.h"
#include <pcl/io/boost.h>
+#include <pcl/memory.h>
#include <pcl/pcl_macros.h>
#include <map>
@@ -217,7 +218,7 @@ namespace openni_wrapper
std::shared_ptr<xn::NodeInfo> image_node;
std::shared_ptr<xn::NodeInfo> depth_node;
std::shared_ptr<xn::NodeInfo> ir_node;
- boost::weak_ptr<OpenNIDevice> device;
+ pcl::weak_ptr<OpenNIDevice> device;
} ;
OpenNIDriver (); Why is this PR touching ~1800 lines to address this problem? |
Most of those touched lines are formatting/spaces, so out of scope, I guess. The rest is to have all |
I'm pretty sure the error shows how all the edits in point_cloud_editor are mandatory:
and therefore #3949 would become only a change in the realsense file. Should that be the case? |
This error is because global
I've no idea which is better for apps module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current state is ok for me. Let's get that CI green first though.
diff --git a/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/cloud.h b/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/cloud.h
index fc66674ec..3d1fd80c9 100644
--- a/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/cloud.h
+++ b/apps/point_cloud_editor/include/pcl/apps/point_cloud_editor/cloud.h
@@ -78,11 +78,8 @@
class Cloud : public Statistics
{
public:
- /// The type for shared pointer pointing to a selection buffer
- using SelectionPtr = pcl::shared_ptr<Selection>;
-
/// The type for weak pointer pointing to a selection buffer
- using SelectionWeakPtr = pcl::weak_ptr<Selection>;
+ using SelectionWeakPtr = std::weak_ptr<Selection>;
/// @brief Default Constructor
Cloud (); This fixed it for me. |
The point was having a single switch. Changing the scope of the PR means going directly back to #3753 (comment) to me, there would be no point in being more verbose than those few line changes. |
And, reiterating, I believe all the changes in the now separate PR were due to this CI error we see now. I'll merge that bit in this PR and leave out only the API changes in that PR which are likely only the ones in RealSense scope. |
7dadce9
to
a9a0432
Compare
The file localTypes.h has confusing entries now. The classes are overriding the |
I absolutely know it, that's why the commit regarding point_cloud_editor is named as it is. EDIT: the reason is I tried and it's a long ordeal, there are lots of files using that header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the discussion, this PR LGTM pending an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also LGTM, feel free to merge if CI is green(ish)
Edit: CI is green. Shall we squash the first two and last two commits?
Issue opened |
pcl::weak_ptr
to have a single-switch move from boost::
to std::
weak pointers
Stems from #3750