Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Analyst WebApp
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fidentis
Analyst WebApp
Commits
414ca7c6
There was an error fetching the commit references. Please try again later.
Commit
414ca7c6
authored
3 years ago
by
Mária Kocúreková
Browse files
Options
Downloads
Patches
Plain Diff
#36 - compute rotation parameter
parent
41ccf559
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Comparison/src/main/java/cz/fidentis/analyst/icp/Icp.java
+38
-51
38 additions, 51 deletions
Comparison/src/main/java/cz/fidentis/analyst/icp/Icp.java
with
38 additions
and
51 deletions
Comparison/src/main/java/cz/fidentis/analyst/icp/Icp.java
+
38
−
51
View file @
414ca7c6
...
...
@@ -9,6 +9,7 @@ import javax.vecmath.Quat4d;
import
javax.vecmath.Vector3d
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
public
class
Icp
{
...
...
@@ -23,8 +24,8 @@ public class Icp {
double
prevMeanD
=
Double
.
POSITIVE_INFINITY
;
// mean distance of previous transformation
while
((
currentIteration
<
=
maxIteration
)
&&
(
Double
.
isInfinite
(
prevMeanD
)
||
Math
.
abs
(
prevMeanD
-
transformation
.
getMeanD
())
>
e
)){
while
((
currentIteration
<
maxIteration
)
&&
(
Double
.
isInfinite
(
prevMeanD
)
||
Math
.
abs
(
prevMeanD
-
Objects
.
requireNonNull
(
transformation
)
.
getMeanD
()
)
>
e
)){
hausdorffDist
.
visitMeshFacet
(
comparedFacet
);
List
<
Double
>
distances
=
hausdorffDist
.
getDistances
().
get
(
comparedFacet
);
...
...
@@ -45,8 +46,8 @@ public class Icp {
/**
*
* @param nearestPoints
* @param comparedPoints
* @param nearestPoints
list of the nearest neighbours
* @param comparedPoints
list fo compared points
* @return List with two points. The first one represents center of main facet
* and the second one represents center of compared facet.
*/
...
...
@@ -95,6 +96,7 @@ public class Icp {
p
.
z
,
p
.
y
,
-
p
.
x
,
0
);
}
private
Matrix4d
sumMatrixMain
(
Vector3d
p
)
{
return
new
Matrix4d
(
0
,
-
p
.
x
,
-
p
.
y
,
-
p
.
z
,
p
.
x
,
0
,
-
p
.
z
,
p
.
y
,
...
...
@@ -108,6 +110,7 @@ public class Icp {
0
,
0
,
0
,
0
,
0
,
0
);
}
public
IcpTransformation
computeIcpTransformation
(
List
<
Vector3d
>
nearestPoints
,
List
<
Double
>
distances
,
List
<
MeshPoint
>
comparedPoints
,
boolean
scale
)
{
double
x
,
y
,
z
;
double
meanX
=
0
;
...
...
@@ -115,7 +118,7 @@ public class Icp {
double
meanZ
=
0
;
double
meanD
=
0
;
int
countOfNotNullPoints
=
0
;
double
countOfNotNullPoints
=
0
;
List
<
Vector3d
>
centers
=
computeCenterBothFacets
(
nearestPoints
,
comparedPoints
);
Vector3d
mainCenter
=
centers
.
get
(
0
);
...
...
@@ -124,13 +127,9 @@ public class Icp {
Matrix4d
sumMatrix
=
new
Matrix4d
();
Matrix4d
multipleMatrix
=
new
Matrix4d
();
// List<Vector3d> near = new ArrayList<>(comparedPoints.size());
List
<
Vector3d
>
compared
=
new
ArrayList
<>(
comparedPoints
.
size
());
for
(
int
i
=
0
;
i
<
comparedPoints
.
size
();
i
++)
{
if
(
comp
are
d
Points
.
get
(
i
)
==
null
){
if
(
ne
are
st
Points
.
get
(
i
)
==
null
){
continue
;
}
...
...
@@ -143,24 +142,13 @@ public class Icp {
meanY
+=
y
;
meanZ
+=
z
;
meanD
+=
distances
.
get
(
i
);
//near.add(nearestPoints.get(i));
compared
.
add
(
comparedPoints
.
get
(
i
).
getPosition
());
// END computing Translation coordinates
// START computing Rotation parameters
// set the value of multipleMatrix to transpose of sumMatrix of relative coordinates compared point
multipleMatrix
.
transpose
(
sumMatrixComp
(
relativeCoordinate
(
comparedPoints
.
get
(
i
).
getPosition
(),
comparedCenter
)));
// set the value of multipleMatrix to the result of multiplying itself with sumMatrix of relative coordinates main point
multipleMatrix
.
mul
(
sumMatrixMain
(
relativeCoordinate
(
nearestPoints
.
get
(
i
),
mainCenter
)));
// set the value of sumMatrix to sum of itself and multipleMatrix
//multipleMatrix =
//= (transpose (sumMatrix of relative coordinates of compared point)) x (sumMatrix of relative coordinates of nearest point)
multipleMatrix
.
mulTransposeLeft
(
sumMatrixComp
(
relativeCoordinate
(
comparedPoints
.
get
(
i
).
getPosition
(),
comparedCenter
)),
sumMatrixMain
(
relativeCoordinate
(
nearestPoints
.
get
(
i
),
mainCenter
)));
sumMatrix
.
add
(
multipleMatrix
);
// END computing Rotation parameters
// START computing Scale parameters
countOfNotNullPoints
++;
...
...
@@ -170,29 +158,12 @@ public class Icp {
meanX
/=
countOfNotNullPoints
;
meanY
/=
countOfNotNullPoints
;
meanZ
/=
countOfNotNullPoints
;
// end computing translation parameter
/*
//computing ROTATION parameter
Vector3d mainCenter = computeCenterV(nearestPoints);
Vector3d comparedCenter = computeCenterV(compared);
List<Vector3d> relativeM = relativeCord(nearestPoints, mainCenter);
List<Vector3d> relativeC = relativeCord(compared, comparedCenter);
for(int i = 0; i < relativeC.size(); i++) {
multipleMatrix.transpose(sumMatrixComp(relativeC.get(i)));
multipleMatrix.mul(sumMatrixMain(relativeM.get(i)));
sumMatrix.add(multipleMatrix);
}
*/
// END computing translation parameter
Quat4d
rotation
=
new
Quat4d
();
sumMatrix
.
setRotation
(
rotation
);
rotation
.
set
(
sumMatrix
);
rotation
.
normalize
();
//
end
computing rotation parameter
//
END
computing rotation parameter
//computing SCALE parameter
...
...
@@ -229,25 +200,40 @@ public class Icp {
return
new
IcpTransformation
(
new
Vector3d
(
meanX
,
meanY
,
meanZ
),
rotation
,
scaleFactor
,
meanD
,
null
);
}
private
Vector3d
multiplyVectorByNumber
(
Vector3d
vector
,
double
number
)
{
return
new
Vector3d
(
vector
.
x
*
number
,
vector
.
y
*
number
,
vector
.
z
*
number
);
}
public
Quat4d
multiply
(
Quat4d
q1
,
Quat4d
q2
)
{
double
x
,
y
,
z
,
w
;
w
=
q1
.
w
*
q2
.
w
-
q1
.
x
*
q2
.
x
-
q1
.
y
*
q2
.
y
-
q1
.
z
*
q2
.
z
;
x
=
q1
.
x
*
q2
.
w
+
q1
.
w
*
q2
.
x
+
q1
.
y
*
q2
.
z
-
q1
.
z
*
q2
.
y
;
y
=
q1
.
y
*
q2
.
w
+
q1
.
w
*
q2
.
y
+
q1
.
z
*
q2
.
x
-
q1
.
x
*
q2
.
z
;
z
=
q1
.
z
*
q2
.
w
+
q1
.
w
*
q2
.
z
+
q1
.
x
*
q2
.
y
-
q1
.
y
*
q2
.
x
;
return
new
Quat4d
(
x
,
y
,
z
,
w
);
}
public
void
applyTransformation
(
List
<
MeshPoint
>
comparedPoints
,
IcpTransformation
transformation
,
boolean
scale
)
{
Vector3d
meshPointPosition
;
Quat4d
rotationCopy
=
new
Quat4d
()
;
Quat4d
rotationCopy
;
Quat4d
conjugateRotation
=
new
Quat4d
();
for
(
MeshPoint
comparedPoint
:
comparedPoints
)
{
meshPointPosition
=
comparedPoint
.
getPosition
();
Quat4d
point
=
new
Quat4d
(
meshPointPosition
.
x
,
meshPointPosition
.
y
,
meshPointPosition
.
z
,
1
);
point
.
normalize
();
if
(
comparedPoints
.
size
()
>
1
)
{
conjugateRotation
.
conjugate
(
transformation
.
getRotation
());
rotationCopy
.
mul
(
point
,
conjugateRotation
);
rotationCopy
.
mul
(
transformation
.
getRotation
());
conjugateRotation
.
conjugate
(
transformation
.
getRotation
());
rotationCopy
=
multiply
(
point
,
conjugateRotation
);
rotationCopy
=
multiply
(
transformation
.
getRotation
(),
rotationCopy
);
}
else
{
rotationCopy
=
point
;
}
...
...
@@ -257,10 +243,11 @@ public class Icp {
rotationCopy
.
y
*
transformation
.
getScaleFactor
()
+
transformation
.
getTranslation
().
y
,
rotationCopy
.
z
*
transformation
.
getScaleFactor
()
+
transformation
.
getTranslation
().
z
);
}
else
{
meshPointPosition
.
set
(
rotationCopy
.
x
+
transformation
.
getTranslation
().
x
,
rotationCopy
.
y
+
transformation
.
getTranslation
().
y
,
meshPointPosition
.
set
(
rotationCopy
.
x
+
transformation
.
getTranslation
().
x
,
rotationCopy
.
y
+
transformation
.
getTranslation
().
y
,
rotationCopy
.
z
+
transformation
.
getTranslation
().
z
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment