Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
Christopher Steward
VTK
Commits
b9ae8b0a
Commit
b9ae8b0a
authored
5 years ago
by
Christopher Steward
Browse files
Options
Downloads
Patches
Plain Diff
Update class version with newest Code
Newest version of ASOPA code. Changed from row to column vectors.
parent
a31182f9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Common/Transforms/vtkAnisotropicLandmarkTransform.cxx
+25
-23
25 additions, 23 deletions
Common/Transforms/vtkAnisotropicLandmarkTransform.cxx
with
25 additions
and
23 deletions
Common/Transforms/vtkAnisotropicLandmarkTransform.cxx
+
25
−
23
View file @
b9ae8b0a
...
...
@@ -114,8 +114,8 @@ void vtkAnisotropicLandmarkTransform::InternalUpdate()
}
//put the points into eigen matrices
Eigen
::
MatrixXd
X
(
N_PTS
,
3
);
Eigen
::
MatrixXd
Y
(
N_PTS
,
3
);
Eigen
::
MatrixXd
X
(
3
,
N_PTS
);
Eigen
::
MatrixXd
Y
(
3
,
N_PTS
);
double
p1
[
3
];
double
p2
[
3
];
for
(
int
i
=
0
;
i
<
N_PTS
;
i
++
)
...
...
@@ -124,41 +124,42 @@ void vtkAnisotropicLandmarkTransform::InternalUpdate()
this
->
TargetLandmarks
->
GetPoint
(
i
,
p2
);
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
X
(
i
,
j
)
=
p1
[
j
];
Y
(
i
,
j
)
=
p2
[
j
];
X
(
j
,
i
)
=
p1
[
j
];
Y
(
j
,
i
)
=
p2
[
j
];
}
}
//find centroids
Eigen
::
Vector3d
X_centroid
=
X
.
col
wise
().
mean
();
Eigen
::
Vector3d
Y_centroid
=
Y
.
col
wise
().
mean
();
Eigen
::
Vector3d
X_centroid
=
X
.
row
wise
().
mean
();
Eigen
::
Vector3d
Y_centroid
=
Y
.
row
wise
().
mean
();
//translate input by centroids
Eigen
::
MatrixXd
X_trans
=
X
.
row
wise
()
-
X_centroid
.
transpose
()
;
Eigen
::
MatrixXd
Y_trans
=
Y
.
row
wise
()
-
Y_centroid
.
transpose
()
;
Eigen
::
MatrixXd
X_trans
=
X
.
col
wise
()
-
X_centroid
;
Eigen
::
MatrixXd
Y_trans
=
Y
.
col
wise
()
-
Y_centroid
;
//normalise translated source input
Eigen
::
MatrixXd
X_norm
=
X_trans
.
col
wise
().
normalized
();
Eigen
::
MatrixXd
X_norm
=
X_trans
.
row
wise
().
normalized
();
//Find the cross covariance matrix
Eigen
::
Matrix3d
B
=
Y_trans
.
transpose
()
*
X_norm
;
Eigen
::
Matrix3d
B
=
Y_trans
*
X_norm
.
transpose
();
//use SVD to decompose B such that B=USV^T
Eigen
::
JacobiSVD
<
Eigen
::
Matrix3d
>
svd
(
B
,
Eigen
::
ComputeFullU
|
Eigen
::
ComputeFullV
);
Eigen
::
Matrix3d
U
=
svd
.
matrixU
();
Eigen
::
Matrix3d
V
=
svd
.
matrixV
().
transpose
();
//create D where the last element is the determinant of UV
^T
//create D where the last element is the determinant of UV
Eigen
::
Matrix3d
D
(
3
,
3
);
D
=
Eigen
::
Matrix3d
::
Identity
();
D
(
2
,
2
)
=
(
U
*
V
).
determinant
();
//Find the rotation
Eigen
::
Matrix3d
Q
=
U
*
D
*
V
;
Eigen
::
Matrix3d
Q
(
3
,
3
);
Q
=
U
*
D
*
V
;
//Calculate the FRE for the given rotation
Eigen
::
MatrixXd
FRE_vect
(
N_PTS
,
3
);
FRE_vect
=
X_norm
*
Q
.
transpose
()
-
Y_trans
;
Eigen
::
MatrixXd
FRE_vect
(
3
,
N_PTS
);
FRE_vect
=
Y_trans
-
Q
.
transpose
()
*
X_norm
;
double
FRE
=
sqrt
(
FRE_vect
.
squaredNorm
()
/
N_PTS
);
//starting FRE value to compare to
...
...
@@ -181,29 +182,30 @@ void vtkAnisotropicLandmarkTransform::InternalUpdate()
Q
=
U
*
D
*
V
;
//recompute FRE value
FRE_vect
=
X_norm
*
Q
.
transpose
()
-
Y_trans
;
FRE_vect
=
Y_trans
-
Q
.
transpose
()
*
X_norm
;
FRE_orig
=
FRE
;
FRE
=
0.0
f
;
FRE
=
sqrt
(
FRE_vect
.
squaredNorm
()
/
N_PTS
);
}
//calculate final scaling
B
=
Y_trans
.
transpose
()
*
X_trans
;
B
=
Y_trans
*
X_trans
.
transpose
();
U
=
B
.
transpose
()
*
Q
;
V
=
X_trans
.
transpose
()
*
X_trans
;
Eigen
::
Matrix3d
A
=
Eigen
::
Matrix3d
::
Zero
();
V
=
X_trans
*
X_trans
.
transpose
();
Eigen
::
Matrix3d
A
(
3
,
3
);
A
=
Eigen
::
Matrix3d
::
Zero
();
A
(
0
,
0
)
=
U
(
0
,
0
)
/
V
(
0
,
0
);
A
(
1
,
1
)
=
U
(
1
,
1
)
/
V
(
1
,
1
);
A
(
2
,
2
)
=
U
(
2
,
2
)
/
V
(
2
,
2
);
//calculate final translation
Eigen
::
Vector3d
t
(
3
);
t
=
Y_centroid
-
(
Q
*
(
A
*
X_centroid
));
//calculate final FRE values
FRE_vect
=
Y_trans
-
(
X_trans
*
A
*
Q
.
transpose
());
Eigen
::
MatrixXd
FRE_mag
=
FRE_vect
.
rowwise
().
squaredNorm
();
FRE_vect
=
Y
-
((
Q
*
(
A
*
X
)).
colwise
()
+
t
);
FRE
=
sqrt
(
FRE_vect
.
squaredNorm
()
/
N_PTS
);
//calculate final translation
Eigen
::
Vector3d
t
=
Y_centroid
-
(
Q
*
A
*
X_centroid
);
//set scaling and rotation matrices sperate to regular
//transformation matrix output
this
->
RotationMatrix
->
Identity
();
...
...
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