SurfaceMesh deepCopy parameter
Not necessarily a big deal, but it was unexpected to me that I can only deep copy SurfaceMesh's if the one I want to copy is stored in a shared_ptr
. I would expect the signature to instead be void deepCopy(const SurfaceMesh& srcMesh)
, as there is no true requirement that one can only copy 1) surface meshes that are specifically stored in shared pointer, and 2) non-const surface meshes (as the current parameter is shared_ptr<SurfaceMesh>
and not shared_ptr<const SurfaceMesh>
.
As an aside regarding a comment in the code for deepCopy, \todo: generalize base classes and implement for every geometry
, please consider using a clone approach rather than a deep copy approach so it will work nicely with class hierarchies. You wouldn't really be able to implement void PointSet::deepCopy(const PointSet& src)
because I could do something like surfaceMesh.deepCopy(lineMesh)
and that can't happen (yes, you could detect this at runtime and throw and exception (or do the VTK method and silently ignore it), but ensuring the type safe clone can always happen is better). However, doing surfaceMesh.clone()
or even pointSetThatCouldBeASurfaceMesh.clone()
is always well defined.
Also, should you go the clone route, I found this a neat way to fake covariant return types with smart pointers. https://www.fluentcpp.com/2017/09/12/how-to-return-a-smart-pointer-and-use-covariance/
For reference: