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
Fixing PointVector implicit conversions #1345
Conversation
3719705
to
07df84d
Compare
07df84d
to
7429806
Compare
Fix wrong implicit conversion about pointvector from MeshVoxelizer
For ParametricShapeArcLengthFunctor.h, you can use RealPoint instead of Vector. |
Ok, thanks ! By the way, what is the purpose of the double n = (double) NumberTraits<Integer>::castToInt64_t( (const DGtal::int32_t)v.norm(Vector::L_infty) );
unsigned int nbSamples = (unsigned int) ceil( n*100 ); |
I have no idea... If you use RealPoint, then |
Ok, thanks 😉 |
To solve issues involved in exampleConvexHull2D.cpp and exampleAlphaShape.cpp (and maybe other similar issues), I suggest to add a constructor to HyperRectDomain that takes input bounds of type Space::RealPoint. Something like (using C++11 syntax, but I didn't test the code):
|
Ok, good idea ! However, it is not clear for me if, for example, [3.4, 3.6] should lead to an empty 1D domain (since no integer point is within the given interval) or to the [3, 4] domain ? |
In my view, it is better to have a digital bounding box larger than the real one (for digitization purpose for instance). That's why I suggest to do "floor" on the lower bound and "ceil" on the upper one. So [3.4, 3.6] -> [3,4] is fine for me. |
It creates the smallest domain with integer coordinates that contains the given bounds. It fixes several conversion issues when creating an HyperRectDomain from a shape bounds.
Ok, thanks ! |
The call is now ambiguous due to the additional HyperRectDomain constructor that take RealPoint bounds.
hi @rolanddenis and @kerautret, can we push forward a bit this PR ? what remains to be done ? |
hi David yes for me all fine, just merge the branch of src remote of @rolanddenis |
Sorry, I was on vacation for few days, I will reviews your PRs later today or tomorrow ! |
Fix pt mesh
A point with signed integer coordinates was multiplied by an unsigned integer resulting in a point with unsigned integer coordinates. The assignment to a point with signed integer was then resulting in a conversion error. The fix is simply to cast the factor (myNbRepeat) to the coordinate type before multiplying.
The fix of Mesh::changeScale argument type from double to the Component type of the handled points implies that a Component typedef is needed for all Point class used with Mesh.
I've added the "Ready to review" tag to this PR since the proposed modifications to the Since the last accepted PR, the main Travis jobs (that includes only the tests) run now successfully, thanks everyone 🎉 🎊 It remains We are almost at the end of this PR! |
What is the problem with testMonge ? The numerical values ? |
you haven't use my testMonge edit ? |
volDTgranulo (and more... wait for it)
Indeed, just merged your PR, thanks! |
About the issues in DGtal, it seems that last commits solve all remaining examples 😉 It just remains |
Thx! Let’s wait for Travis and I’ll merge. Huge thank for this painful pandora box ;) I’ve PR some edits in Bertrand’s DGtaltools fixes. Tools should be ok. |
For the remaining failing test.. can you please open up a new issue ? |
Tools failing but it’s normal ;) |
Yep, already done in #1348 😉 |
Oops, it seems that I just forget to finish the documentation of |
PR Description
Fixing conversions between
PointVector
with different Euclidean Ring type and storage (see #1341).Automatic Euclidean Ring return type for compatible operations.
Note that all external operators (
+
,-
,<
, ...) and functions (dotProduct
,crossProduct
, ...) that are related toPointVector
are declared as friend of this class. It is not necessary since those operators and functions never access to protected/private members but it allows to have them documented on the same page asPointVector
in a "Friends" section.Checklist
cmake
mode (otherwise, Travis C.I. will fail).PointVector checklist
+=
,-=
,...)PointVector
(dot
,crossProduct
,inf
,...) . Also external versions.partialCopy
andpartialEqual
std::round
)crossProduct
of 2D vectors returns a scalar. This is a critical change that may lead to compilation errors (e.g. https://github.com/rolanddenis/DGtal/blob/fix_pointvector/src/DGtal/shapes/Mesh.ih#L464)Conversion fixes
Q&A
Why is there a conversion issue ?
When a
PointVector<dim,T>
is converted into anotherPointVector<dim,U>
in a implicit way (e.g. when passing the first type to a function accepting the second type) and if converting fromT
toU
is ambiguous (e.g. fromdouble
toint
), then this conversion will fail.Which conversions are valid ?
The conversion follows the implicit arithmetic conversion rules (see https://en.cppreference.com/w/cpp/language/operator_arithmetic#Conversions), that is
T
can be converted toU
ifT + U
has typeU
. This type deduction is explained in the link above and is quite natural except for the signed/unsigned conversion: ifT
andU
are both integers with same precision but one is signed and the other unsigned, thenT + U
is unsigned. Thus, conversion fromsigned int
tounsigned int
is valid while the contrary,unsigned int
tosigned int
, is invalid.How to fix a conversion issue ?
It depends on what the initial code was supposed to do:
static_cast
or explicitly call the constructor: instead ofwrite
src/DGtal/base/BasicFunctors.h
):instead of
write
So basically, in most cases, we just need to know if the conversion should be fixed using
static_cast
,trunc
,ceil
,floor
,round
or something more exotic.Why are some developers pinned to specific issues ?
I've just use
git blame
on erroneous lines 😉I need to know if the proposed fix is valid or, if the issue is not already fixed (unchecked box), I need to know how to fix it (basically, what conversion function should be used).
Remaining issues
In DGtal
Point2DEmbedderIn3D
constructor: usingstd::round
to convert fromdouble
toint
components.testBasicPointFunctors
now fails... (see Incertitude on the chosen basis in Point2DEmbedderIn3D #1348 and 2abba3d, ping @kerautret)DGtal::functions::Hull2D::computeHProjDistance
,computeVProjDistance
andcomputeEuclideanDistance
(see 7429806, ping @kerautret).testAlphaThickSegmentComputer.cpp
: usingstd::round
to convert fromdouble
toint
components (see b71531a, ping @kerautret).testAlphaThickSegmentComputer.cpp
, there is a conversion error inAlphaThickSegmentComputer.ih
.aLastExtrPt
is of typeInputPoint
(template parameter ofAlphaThickSegmentComputer
) whilepointEnvConv
is of typePointD
, that is alwaysPointVector<2, double>
(ping @kerautret)testCombinDSS.cpp
, there is a conversion error inOneBalancedWordComputer.ih
. The right-hand-side has Euclidean ring of typeunsigned int
while the left-hand-side is signed that is surprisingly not a valid conversion ... StoringmyNbRepeat
as anint
or simply casting it toint
on this line should be enough to fix this issue. Do you agree @xprov ?testTrueLocalEstimator.cpp
andshapeGridCurveEstimator.cpp
, there is a conversion error inParametricShapeArcLengthFunctor.h
. The shape bounds (aBall2D
) are of typeSpace::RealPoint
andv
is aVector
, akaSpace::Point
(thanks @troussil).testDistanceTransformation.cpp
, there is a conversion error when passing theAccFlower2D
shape bounds (akaSpace::RealPoint
) as the bounds of aHyperRectDomain
(thanks @troussil).testTensorVoting.cpp
,testLocalEstimatorFromFunctorAdapter.cpp
,testSphericalHoughNormalVectorEstimator.cpp
,exampleEstimatorFromSurfelFunctors.cpp
,dvcm-2d-curvature.cpp
andshortcuts-geometry.cpp
, there is a conversion error inLocalEstimatorFromSurfelFunctorAdapter.ih
. When binding the first parameter of*myMetric
tomyEmbedder(*it)
, the problem is that the first should be aPointVector<3, int>
while the second is aPointVector<3, double>
(Value
type of aCCellEmbedder
model) (thanks @dcoeurjo)testDistancePropagation.cpp
there is a conversion error when binding the first argument of adistance
(akaSpace::Point
) to the result of aCanonicEmbedder
(akaSpace::RealPoint
) (thanks @dcoeurjo).testMesh.cpp
, there is a conversion error inMesh.ih
. The problem is that theMesh
vertex have integer component (is that always the case ?) and those components are here scaled by adouble
thus leading to an invalid conversion (ping @kerautret).testMeshVoxelization.cpp
andexampleMeshVoxelizer.cpp
, there is a conversion error inMeshVoxelizer.ih
. ASpace::RealPoint
is assigned to aSpace::Point
(thanks @hadjiszs).exampleAlphaThickSegment.cpp
, there is a conversion error inAlphaThickSegmentComputer.ih
. APointD
(akaPointVector<2, double>
) is assigned to aInputPoint
(akaSpace::Point
here but it is not clear if it always has integer components) (ping @kerautret).exampleConvexHull2D.cpp
, there is a conversion error: the bounds of aBall2D
shape (akaSpace::RealPoint
) are given as parameters to aHyperRectDomain
constructor (Space::Point
expected) (thanks @troussil).exampleAlphaShape.cpp
, there is a conversion error: the bounds of aBall2D
shape (akaSpace::RealPoint
) are given as parameters to aHyperRectDomain
constructor (Space::Point
expected) (thanks @troussil).tests/geometry/curves/testAlphaThickSegmentComputer.cpp
tests/geometry/curves/testMonge.cpp
examples/io/viewers/viewer3D-8bis-2Dimages.cpp
examples/geometry/curves/exampleGridCurve3d.cpp
examples/tutorial-examples/volDTGranulo.cpp
examples/graph/volDistanceTraversal.cpp
In DGtalTools
estimators/2dLocalEstimators.cpp
estimators/volSurfaceRegularization.cpp
converters/mesh2heightfield.cpp
converters/img2freeman.cpp
converters/vol2heightfield.cpp
visualisation/3dCurvatureViewerNoise.cpp
visualisation/3dCurvatureViewer.cpp
visualisation/3dVolViewer.cpp
In DGtalTools-contrib
geometry3d/basicEditMesh.cpp