Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fdt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
FSL
fdt
Commits
64f833fe
Commit
64f833fe
authored
14 years ago
by
Stamatios Sotiropoulos
Browse files
Options
Downloads
Patches
Plain Diff
Sort a dataset according to the angular distance of each DW direction with a reference vector
parent
c85007f3
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
rearrange.cc
+86
-0
86 additions, 0 deletions
rearrange.cc
with
86 additions
and
0 deletions
rearrange.cc
0 → 100755
+
86
−
0
View file @
64f833fe
/* Copyright (C) 2010 University of Oxford */
/* CCOPYRIGHT */
#include
<iostream>
#include
<fstream>
#include
<iomanip>
#include
<string>
#include
<cmath>
#include
"newimage/newimageall.h"
using
namespace
std
;
using
namespace
NEWIMAGE
;
using
namespace
NEWMAT
;
//Rearranges a dataset according to the angular distance between the corresponding bvecs entry and a reference vector
int
main
(
int
argc
,
char
*
argv
[]){
if
(
argc
<
5
||
argc
>
6
){
cerr
<<
" "
<<
endl
;
cerr
<<
"usage: rearrange data bvecs ref_dyads [brain_mask] ouput"
<<
endl
;
cerr
<<
" "
<<
endl
;
exit
(
1
);
}
ColumnVector
ref_vector
(
3
);
Matrix
bvecs
;
//Read Input
volume4D
<
float
>
data
,
ref
;
volume
<
float
>
mask
;
read_volume4D
(
data
,
argv
[
1
]);
bvecs
=
read_ascii_matrix
(
argv
[
2
]);
read_volume4D
(
ref
,
argv
[
3
]);
if
(
argc
==
6
)
read_volume
(
mask
,
argv
[
4
]);
else
{
mask
.
reinitialize
(
data
.
xsize
(),
data
.
ysize
(),
data
.
zsize
());
mask
=
1
;
}
volume4D
<
float
>
output
(
data
.
xsize
(),
data
.
ysize
(),
data
.
zsize
(),
data
.
tsize
());
copybasicproperties
(
data
,
output
);
output
=
0
;
if
(
bvecs
.
Nrows
()
>
3
)
bvecs
=
bvecs
.
t
();
//Make sure the bvecs entries are normalized unit vectors
for
(
int
i
=
1
;
i
<=
bvecs
.
Ncols
();
i
++
){
float
tmpsum
=
sqrt
(
bvecs
(
1
,
i
)
*
bvecs
(
1
,
i
)
+
bvecs
(
2
,
i
)
*
bvecs
(
2
,
i
)
+
bvecs
(
3
,
i
)
*
bvecs
(
3
,
i
));
if
(
tmpsum
!=
0
){
bvecs
(
1
,
i
)
=
bvecs
(
1
,
i
)
/
tmpsum
;
bvecs
(
2
,
i
)
=
bvecs
(
2
,
i
)
/
tmpsum
;
bvecs
(
3
,
i
)
=
bvecs
(
3
,
i
)
/
tmpsum
;
}
}
for
(
int
z
=
data
.
minz
();
z
<=
data
.
maxz
();
z
++
){
//Rearrange data for each voxel
for
(
int
y
=
data
.
miny
();
y
<=
data
.
maxy
();
y
++
){
for
(
int
x
=
data
.
minx
();
x
<=
data
.
maxx
();
x
++
){
if
(
mask
(
x
,
y
,
z
)
!=
0
){
vector
<
pair
<
float
,
int
>
>
dot
;
//Keep in the first entry of each pair the dot product value and the in the second the index
pair
<
float
,
int
>
ftmp
;
ref_vector
(
1
)
=
ref
(
x
,
y
,
z
,
0
);
ref_vector
(
2
)
=
ref
(
x
,
y
,
z
,
1
);
ref_vector
(
3
)
=
ref
(
x
,
y
,
z
,
2
);
for
(
int
n
=
1
;
n
<=
bvecs
.
Ncols
();
n
++
){
//Get the dot product of each bvecs entry with the reference orientation in this voxel
if
(
bvecs
(
1
,
n
)
==
0
&&
bvecs
(
2
,
n
)
==
0
&&
bvecs
(
3
,
n
)
==
0
)
ftmp
.
first
=
2.0
;
//The b=0 entries are first in the sequence
else
ftmp
.
first
=
fabs
(
ref_vector
(
1
)
*
bvecs
(
1
,
n
)
+
ref_vector
(
2
)
*
bvecs
(
2
,
n
)
+
ref_vector
(
3
)
*
bvecs
(
3
,
n
));
ftmp
.
second
=
n
-
1
;
dot
.
push_back
(
ftmp
);
}
sort
(
dot
.
begin
(),
dot
.
end
());
//Sort the dot products in ascending order
reverse
(
dot
.
begin
(),
dot
.
end
());
//Reverse the ordering, so that it is in descending order
for
(
int
n
=
0
;
n
<
bvecs
.
Ncols
();
n
++
)
//Get the dot product of each bvecs entry with the reference orientation in this voxel
output
(
x
,
y
,
z
,
n
)
=
data
(
x
,
y
,
z
,
dot
[
n
].
second
);
}
}
}
cout
<<
z
+
1
<<
" slices processed"
<<
endl
;
}
save_volume4D
(
output
,
argv
[
argc
-
1
]);
return
0
;
}
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