Skip to content

Commit

Permalink
Significant changes to DataSet interface:
Browse files Browse the repository at this point in the history
- revert back to operator[] instead of pos (aided by new DataSet::Position template class)
- revert back to value() as an lvalue (aided by new DataSet::Value template class)
- use strides as axis layout specifier (removed old Axes::Order class)

Also simplified Math::Matrix class, removing the Math::MatrixView class.

Some changes to the configuration script for improved OpenGL detection
  • Loading branch information
jdtournier committed Feb 3, 2010
1 parent a55df4e commit dc3003f
Show file tree
Hide file tree
Showing 42 changed files with 1,265 additions and 825 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PROJECT_NAME = MRtrix
# This could be handy for archiving the generated documentation or
# if some version control system is used.

PROJECT_NUMBER = 0.3.2
PROJECT_NUMBER = 0.3.3

# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
Expand Down
34 changes: 17 additions & 17 deletions cmd/bogus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ typedef float T;

EXECUTE {
Image::Header header;
header.axes.resize (3);
header.axes[0].dim = 1024;
header.axes[1].dim = 1024;
header.axes[2].dim = 1024;
header.axes.ndim() = 3;
header.axes.dim(0) = 1024;
header.axes.dim(1) = 1024;
header.axes.dim(2) = 1024;

header.axes[0].vox = 1.0;
header.axes[1].vox = 1.0;
header.axes[2].vox = 1.0;
header.axes.vox(0) = 1.0;
header.axes.vox(1) = 1.0;
header.axes.vox(2) = 1.0;

header.axes[0].order = 0;
header.axes[1].order = 1;
header.axes[2].order = 2;
header.axes.order(0) = 0;
header.axes.order(1) = 1;
header.axes.order(2) = 2;

VAR (header.data_type.description());
VAR (header.datatype().description());
//header.data_type = DataType::UInt8;

Image::Object obj;
const Image::Header obj;
obj.create ("poo.mif", header);

Image::Voxel vox (obj);
vox[0] = 1023;
vox[1] = 1023;
vox[2] = 1023;
Image::Voxel<float> vox (obj);
vox.pos(0, 1023);
vox.pos(1, 1023);
vox.pos(2, 1023);

vox.value() = 0.0;
vox.value (0.0);


/*
Expand Down
34 changes: 17 additions & 17 deletions cmd/csdeconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Item {
class Allocator {
public:
Allocator (size_t data_size) : N (data_size) { }
Item* alloc () { Item* item = new Item; item->data.resize (N); return (item); }
Item* alloc () { Item* item = new Item; item->data.allocate (N); return (item); }
void reset (Item* item) { }
void dealloc (Item* item) { delete item; }
private:
Expand Down Expand Up @@ -163,23 +163,23 @@ class DataLoader {
value_type norm = 0.0;
if (P.normalise) {
for (size_t n = 0; n < P.bzeros.size(); n++) {
D.pos(3, P.bzeros[n]);
D[3] = P.bzeros[n];
norm += D.value ();
}
norm /= P.bzeros.size();
}

for (size_t n = 0; n < P.dwis.size(); n++) {
D.pos(3, P.dwis[n]);
D[3] = P.dwis[n];
item->data[n] = D.value();
if (!finite (item->data[n])) return;
if (item->data[n] < 0.0) item->data[n] = 0.0;
if (P.normalise) item->data[n] /= norm;
}

item->pos[0] = D.pos(0);
item->pos[1] = D.pos(1);
item->pos[2] = D.pos(2);
item->pos[0] = D[0];
item->pos[1] = D[1];
item->pos[2] = D[2];

if (!item.write()) throw Exception ("error writing to work queue");
}
Expand Down Expand Up @@ -213,12 +213,12 @@ class Processor {
str(item->pos[0]) + " " + str(item->pos[1]) + " " + str(item->pos[2]) +
" ] failed to converge");

SH.pos(0, item->pos[0]);
SH.pos(1, item->pos[1]);
SH.pos(2, item->pos[2]);
SH[0] = item->pos[0];
SH[1] = item->pos[1];
SH[2] = item->pos[2];

for (SH.pos(3,0); SH.pos(3) < SH.dim(3); SH.move(3,1))
SH.value (sdeconv.FOD()[SH.pos(3)]);
for (SH[3] = 0; SH[3] < SH.dim(3); ++SH[3])
SH.value() = sdeconv.FOD()[SH[3]];
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ EXECUTE {
else {
if (!header.DW_scheme.is_set())
throw Exception ("no diffusion encoding found in image \"" + header.name() + "\"");
grad = header.DW_scheme;
grad.copy (header.DW_scheme);
}

if (grad.rows() < 7 || grad.columns() != 4)
Expand Down Expand Up @@ -301,15 +301,15 @@ EXECUTE {
if (opt.size()) HR_dirs.load (opt[0][0].get_string());
else {
HR_dirs.allocate (300,2);
HR_dirs.view() = Math::MatrixView<float> (default_directions, 300, 2);
HR_dirs = Math::Matrix<float> (default_directions, 300, 2);
}

header.axes.dim(3) = Math::SH::NforL (lmax);
header.datatype() = DataType::Float32;
header.axes.order(0) = 1; header.axes.forward(0) = true;
header.axes.order(1) = 2; header.axes.forward(1) = true;
header.axes.order(2) = 3; header.axes.forward(2) = true;
header.axes.order(3) = 0; header.axes.forward(3) = true;
header.axes.stride(0) = 2;
header.axes.stride(1) = 3;
header.axes.stride(2) = 4;
header.axes.stride(3) = 1;

const Image::Header* mask_header = NULL;
opt = get_options (2); // mask
Expand Down
4 changes: 2 additions & 2 deletions cmd/gendir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ EXECUTE {
ProgressBar::init (0, "Optimising directions");
for (power = -1.0; power >= -target_power/2.0; power *= 2.0) {
info ("setting power = " + str (-power*2.0));
gsl_multimin_fdfminimizer_set (minimizer, &fdf, &v, 0.01, 1e-4);
gsl_multimin_fdfminimizer_set (minimizer, &fdf, v.gsl(), 0.01, 1e-4);

for (uint iter = 0; iter < niter; iter++) {

Expand All @@ -147,7 +147,7 @@ EXECUTE {

ProgressBar::inc();
}
gsl_vector_memcpy (&v, minimizer->x);
gsl_vector_memcpy (v.gsl(), minimizer->x);
}
ProgressBar::done();

Expand Down
25 changes: 9 additions & 16 deletions cmd/mrconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,26 @@ OPTIONS = {
template <class Set, class Set2> void copy_replace_NaN_kernel (Set& destination, Set2& source) {
typedef typename Set::value_type T;
T val = source.value();
destination.value (isnan(val) ? 0.0 : val);
destination.value() = ( isnan(val) ? 0.0 : val );
}


template <class Set, class Set2> void copy (Set& destination, Set2& source, bool replace_NaN)
{
std::string progress_message ("copying from \"" + source.name() + "\" to \"" + destination.name() + "\"...");

typedef DataSet::Reorder<Set> S1;
typedef DataSet::Reorder<Set2> S2;
typedef DataSet::Reorder<Set2> SetR;

S1 dest (destination, NULL, destination.name());
S2 src (source, dest.layout(), source.name());
SetR src (source, destination, source.name());

if (replace_NaN) DataSet::loop2 (progress_message, DataSet::copy_kernel<S1,S2>, dest, src);
else DataSet::loop2 (progress_message, copy_replace_NaN_kernel<S1,S2>, dest, src);
if (replace_NaN) DataSet::loop2 (progress_message, DataSet::copy_kernel<Set,SetR>, destination, src);
else DataSet::loop2 (progress_message, copy_replace_NaN_kernel<Set,SetR>, destination, src);
}



EXECUTE {
std::vector<OptBase> opt = get_options (1); // vox
OptionList opt = get_options (1); // vox
std::vector<float> vox;
if (opt.size())
vox = parse_floats (opt[0][0].get_string());
Expand Down Expand Up @@ -158,14 +156,12 @@ EXECUTE {

opt = get_options (7); // layout
if (opt.size()) {
std::vector<Image::Axes::Order> ax = parse_axes_specifier (header.axes, opt[0][0].get_string());
std::vector<ssize_t> ax = Image::Axes::parse (header.ndim(), opt[0][0].get_string());
if (ax.size() != header.axes.ndim())
throw Exception (std::string("specified layout \"") + opt[0][0].get_string() + "\" does not match image dimensions");

for (size_t i = 0; i < ax.size(); i++) {
header.axes.order(i) = ax[i].order;
header.axes.forward(i) = ax[i].forward;
}
for (size_t i = 0; i < ax.size(); i++)
header.axes.stride(i) = ax[i];
}


Expand Down Expand Up @@ -219,6 +215,3 @@ EXECUTE {
}





Loading

0 comments on commit dc3003f

Please sign in to comment.