/* Copyright (C) 2010 University of Oxford Stamatios Sotiropoulos - FMRIB Image Analysis Group */ /* Part of FSL - FMRIB's Software Library http://www.fmrib.ox.ac.uk/fsl fsl@fmrib.ox.ac.uk Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance Imaging of the Brain), Department of Clinical Neurology, Oxford University, Oxford, UK LICENCE FMRIB Software Library, Release 5.0 (c) 2012, The University of Oxford (the "Software") The Software remains the property of the University of Oxford ("the University"). The Software is distributed "AS IS" under this Licence solely for non-commercial use in the hope that it will be useful, but in order that the University as a charitable foundation protects its assets for the benefit of its educational and research purposes, the University makes clear that no condition is made or to be implied, nor is any warranty given or to be implied, as to the accuracy of the Software, or that it will be suitable for any particular purpose or for use under any specific conditions. Furthermore, the University disclaims all responsibility for the use which is made of the Software. It further disclaims any liability for the outcomes arising from using the Software. The Licensee agrees to indemnify the University and hold the University harmless from and against any and all claims, damages and liabilities asserted by third parties (including claims for negligence) which arise directly or indirectly from the use of the Software or the sale of any products based on the Software. No part of the Software may be reproduced, modified, transmitted or transferred in any form or by any means, electronic or mechanical, without the express permission of the University. The permission of the University is not required if the said reproduction, modification, transmission or transference is done without financial return, the conditions of this Licence are imposed upon the receiver of the product, and all original and amended source code is included in any transmitted product. You may be held legally responsible for any copyright infringement that is caused or encouraged by your failure to abide by these terms and conditions. You are not permitted under this Licence to use this Software commercially. Use for which any financial return is received shall be defined as commercial use, and includes (1) integration of all or part of the source code or the Software into a product for sale or license by or on behalf of Licensee to third parties or (2) use of the Software or any derivative of it for research with the final aim of developing software products for sale or license to a third party or (3) use of the Software or any derivative of it for research with the final aim of developing non-software products for sale or license to a third party, or (4) use of the Software to provide any service to an external organisation for which payment is received. If you are interested in using the Software commercially, please contact Isis Innovation Limited ("Isis"), the technology transfer company of the University, to negotiate a licence. Contact details are: innovation@isis.ox.ac.uk quoting reference DE/9564. */ #if !defined(sphere_tessellation_h) #define sphere_tessellation_h using namespace NEWMAT; namespace ODFs{ //Class that holds points uniformly distributed on the surface of a sphere //Points are obtained using an icosahedral tessellation. //The Matrix index contains indices of the closest num_neighbours of each point. class Points{ Matrix Tess_Points; //Matrix that keeps points from a sphere tesselation (3 x Npoints) int num_points; //Number of points obtained after tesselation Matrix index; double mean_Eucl_dist; //Mean Euclidean distance between neighbouring points double mean_ang_dist; //Mean angular distance between neighbouring points const int& degree; //Tessellation degree (0-5) const int& num_neighbours; //Number of neighbours that will be considered public: //constructor Points(const int& tessel_degree, const int& neighbours): degree(tessel_degree), num_neighbours(neighbours){ sphere_tessellation_points(); num_points=Tess_Points.Ncols(); index.ReSize(num_points, num_neighbours); find_closest(); distances(); } //destructor ~Points(){} Matrix& get_TessPoints_Ref() { return Tess_Points; } Matrix get_TessPoints() { return Tess_Points; } ColumnVector get_TessPoints_coord(int coord_index) { return Tess_Points.t().Column(coord_index); } //Return x, y or z coordinates of Points (coord_index=1,2 or 3) Matrix& get_index_Ref() { return index; } Matrix get_index() { return index; } double get_Eucl_dist() const {return mean_Eucl_dist;} double get_ang_dist() const {return mean_ang_dist;} //Function that returns a matrix with pre-calculated points evenly distributed on the sphere. //Points have been calculated using a tessellation of an icosahedron. Degree corresponds to degree of //tesselation (from 0 to 5). void sphere_tessellation_points(){ switch (degree){ case 0: Tess_Points=tessellation_points0(); break; case 1: Tess_Points=tessellation_points1(); break; case 2: Tess_Points=tessellation_points2(); break; case 3: Tess_Points=tessellation_points3(); break; case 4: Tess_Points=tessellation_points4(); break; case 5: Tess_Points=tessellation_points5(); break; } } //For each of the Tess_Points returns the indices of the "num_neighbours" closer points. So index(j,k) will have an index to Tess_Points //for the kth closest point of the grid to point j (k<=num_neighbours). Stored indices start from 1! //The algortihm computes the dot product of each point with all the others and keeps the points that correspond to the num_neighbours maximum dot products. void find_closest(){ float min_entry, dot_prod; vector max_dots(num_neighbours); vector temp_index(num_neighbours); int min_index,i,k,j; for (i=1; i<=num_points; i++){ //for each point for (k=0; kmin_entry){ //if the dot product is larger than the smaller value of tha max_dots array max_dots[min_index]=dot_prod; //replace it temp_index[min_index]=j; //include this point in the list of closest neighbours min_entry=1; //find the min and its location of the updated max_dots array for (k=0; k