diff --git a/Code/Mantid/Geometry/MDGeometry.vcxproj.filters b/Code/Mantid/Geometry/MDGeometry.vcxproj.filters index 8442982b131e806d588cf2f868ee17eb840b2db2..3939b061a7fe1f2f573b192862de8c30da762d7c 100644 --- a/Code/Mantid/Geometry/MDGeometry.vcxproj.filters +++ b/Code/Mantid/Geometry/MDGeometry.vcxproj.filters @@ -41,10 +41,10 @@ <ClCompile Include="src\MDGeometry\MDDimensionRes.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="src\MDGeometry\MDGeometry.cpp"> + <ClCompile Include="src\MDGeometry\MDGeometryBasis.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="src\MDGeometry\MDGeometryBasis.cpp"> + <ClCompile Include="src\MDGeometry\MDGeometry.cpp"> <Filter>Source Files</Filter> </ClCompile> <ClCompile Include="src\MDGeometry\MDGeometryDescription.cpp"> diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimension.h b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimension.h index b497b604a730e2776225ef7818565ddb1149ecd3..0b2214904d521f33114a43218cbbdc5aad63921a 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimension.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimension.h @@ -46,15 +46,17 @@ namespace Mantid{ namespace Geometry{ -class DLLExport MDDimension:public DimensionID +class DLLExport MDDimension { public: virtual ~MDDimension(); /// function returns the name of the axis in this direction std::string const &getName()const{return AxisName;} -/// function return the unique dimension ID, identifying the current dimension among others <-inherited -// std::string getDimensionTag(void)const{return DimensionID::getDimensionTag;} +/// function return the unique dimension ID, identifying the current dimension among others + std::string getDimensionTag(void)const{return dimTag;} +/// get maximal value along the dimension double getMaximum(void)const{return rMax;} +/// get minimal value along the dimension double getMinimum(void)const{return rMin;} /// range of data along this axis double getRange(void)const{return (rMax-rMin);} @@ -76,8 +78,10 @@ public: /// function returns the dimension stride, e.g. the step of change for 1D index of a dimension in multidimensional array, if an index of this dimension changes by one size_t getStride(void)const{return nStride;} - //Throws through vector if ind out of range? (hope so TO DO: check) + //Get coordinate for index; Throws through vector if ind out of range double getX(unsigned int ind){return Axis.at(ind);} + /// it is not reciprocal dimension -> convenience function + virtual bool isReciprocal(void)const{return false;} protected: /// this is to initiate and set the Dimensions from the Geometry; The geometry is in fact a collection of Dimensions + a bit more friend class MDGeometry; @@ -104,9 +108,9 @@ protected: /// differs from setRange by the fact that the limits has to be within the existing ranges void setExpanded(double rxMin, double rxMax,unsigned int nBins); // dodgy constructor has to be hidden from clients except the childs. - MDDimension(const DimensionID &ID); + MDDimension(const std::string &ID); - /// should not be public to everybody as chanded by MDGeometry while reshaping or shaping; + /// should not be public to everybody as chanded by MDGeometry while reshaping or rebinning; void setStride(size_t newStride){nStride=newStride; } /// the coordinate of a dimension in an WorkspaceGeometry system of coordinates (always 1 here and triplet for reciprocals) -- need further exploration -> which coordinate systen it is. std::vector<double> coord; @@ -115,6 +119,8 @@ protected: private: /// name of the axis; std::string AxisName; + /// the name of the dimension in the dimensions basis; + std::string dimTag; /// The parameter, which specify if the axis is integraged. If it is, nBins =1; @@ -130,8 +136,8 @@ private: /// lattice sacale in this direction double latticeParam; - // ************* should be private: - MDDimension(const MDDimension &); + // ************* should be prohibited?: + MDDimension(const MDDimension &){}; MDDimension & operator=(const MDDimension &rhs); /// internal function which verify if the ranges of the argumens are permitted; Used by many setRanges functions void check_ranges(double rxMin,double rxMax); diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimensionRes.h b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimensionRes.h index 79391c86d7ef2c46e9071468459152c2de0d7101..6e0f4e6fbae52d0f1640fa902e25bfbd63cbc2c8 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimensionRes.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDDimensionRes.h @@ -30,6 +30,12 @@ namespace Mantid{ File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ + /** enum describes reciprocal dimension numbers and reflects the request to up to three reciprocal dimensions */ + enum rec_dim{ + q1, + q2, + q3 + }; class DLLExport MDDimensionRes : public MDDimension { @@ -38,12 +44,17 @@ class DLLExport MDDimensionRes : public MDDimension public: virtual ~MDDimensionRes(void); + /// it is reciprocal dimension -> convenience function + virtual bool isReciprocal(void)const{return true;} + /// virtual std::vector<double> const & getCoord(void)const{return this->coord;} protected: - MDDimensionRes(const DimensionID &ID); + MDDimensionRes(const std::string &ID,const rec_dim nDim); private: // function sets the coordinates of the dimension; virtual void setCoord(const std::vector<double> &theCoord); + /// number of this reciprocal dimension (one of 3) + rec_dim nRecDim; }; } // MDDataObjects } // Mantid diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometry.h b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometry.h index 90c2c0180c6d867de4f6f4d49b75c2d56dac8ed2..70b370f08cbaa75e20161a54efd6b3e42670fb53 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometry.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometry.h @@ -55,11 +55,14 @@ public: MDDimension & getTDimension(void)const; std::vector<MDDimension *> getIntegratedDimensions(void); + /// returns the number of expanded (non-integrated) dimensions + unsigned int getNExpandedDims(void)const{return n_expanded_dim;} + /// functions return the pointer to the dimension requested as the dimension num. Throws if dimension is out of range. Convenient for looping though dimensions instead of /// asking for DimX, Y and Z; MDDimension * getDimension(unsigned int i)const; - /// functions return the pointer to the dimension requested by the dimension tag. throws if no such dimension is present in the Geometry ; - MDDimension * getDimension(const std::string &tag)const; + /// functions return the pointer to the dimension requested by the dimension tag. throws if such dimension is not present in the Geometry (or NULL if not throwing); + MDDimension * getDimension(const std::string &tag,bool do_throw=true)const; /// function returns an axis vector of the dimension, specified by ID; it is 1 for orthogonal dimensions and triplet for the reciprocal /// (but in a form of <1,0,0> if reciprocals are orthogonal to each other; @@ -92,11 +95,9 @@ public: void reinit_Geometry(const MDGeometryDescription &trf,unsigned int nReciprocalDims=3); void reinit_Geometry(const std::vector<std::string> &DimensionTags,unsigned int nReciprocalDims=3); private: - void init_empty_dimensions(const std::vector<DimensionID> &tags); - /// internal function returning the number of the dimension with the supplied tag in the dimensions stack - int getDimNum(const std::string &tag,bool do_throw=true)const; - /// the map used for fast search of a dumension from its tag. - std::map<size_t,int> dimensions_map; + void init_empty_dimensions(); + /// the map used for fast search of a dumension from its tag. + std::map<std::string,MDDimension *> dimensions_map; }; } // Geometry } // Mantid diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryBasis.h b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryBasis.h index 10685e7ee16a6c3219c2bf355af2a01da2fa5bc5..0ec162afe8e208f4ea043a3bbf08822c3af9a9f5 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryBasis.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryBasis.h @@ -7,6 +7,7 @@ #include <vector> #include <string> #include <map> +#include <set> #include "MantidKernel/Exception.h" #include "MantidKernel/Logger.h" #include "MantidGeometry/MDGeometry/MDWorkspaceConstants.h" @@ -17,7 +18,8 @@ * and number of additional ortogonal dimensions, e.g. temperature, pressure etc. * * Class provides the reference framework for visualisation and analysis operations alowing to compare different workspaces and to modify - the visualisation geometry as requested by user. +* the visualisation geometry as requested by user +* It also keeps the crystall information necessary to transform a Mantid workspace into MD workspace @author Alex Buts, RAL ISIS @date 27/09/2010 @@ -48,8 +50,13 @@ namespace Mantid namespace Geometry { -/** The class DimensionID describes set of the dimensions, which can be present in dataset; -* it has just name and ID and set these values properly is the MDGeometryBasis responsibility; +//**************************************************************************************************************************************** + class DLLExport MDGeometryBasis + { + public: + +/** The class DimensionID describes one of the set of the dimensions, which can be present in dataset; +* it has just keeps the name of the dimension and the number which identifies, what data column corresponds to this tag */ class DimensionID { @@ -58,40 +65,34 @@ namespace Mantid std::string getDimensionTag(void)const{return DimensionTag;} /// returns true if this dimension is reciprocal bool isReciprocal(void)const{return is_reciprocal;} - /// all dimensions has to be arranged in the order of incrreased id; - bool operator <(const DimensionID &other)const{return this->iDimID< other.iDimID;} - bool operator<=(const DimensionID &other)const{return this->iDimID<=other.iDimID;} - bool operator> (const DimensionID &other)const{return this->iDimID> other.iDimID;} - bool operator>=(const DimensionID &other)const{return this->iDimID>=other.iDimID;} - bool operator==(const DimensionID &other)const{return this->iDimID==other.iDimID;} + /// all dimensions has to be arranged in the order of incrreased ascii string value; + bool operator <(const DimensionID &other)const{return ((this->DimensionTag.compare(other.DimensionTag)< 0)?true:false);} + bool operator<=(const DimensionID &other)const{return ((this->DimensionTag.compare(other.DimensionTag)<=0)?true:false);} + bool operator> (const DimensionID &other)const{return ((this->DimensionTag.compare(other.DimensionTag)> 0)?true:false);} + bool operator>=(const DimensionID &other)const{return ((this->DimensionTag.compare(other.DimensionTag)>=0)?true:false);} + bool operator==(const DimensionID &other)const{return ((this->DimensionTag.compare(other.DimensionTag)==0)?true:false);} /// copy constructor and operator()= are public /// to initate array, which has to be reset as meaningless and not checked against this later - DimensionID(int iDimID0=-1,const char *name0="",bool if_reciprocal=true): - iDimID(iDimID0),tagHash(0),is_reciprocal(if_reciprocal),DimensionTag(name0){}; + DimensionID(int iDimNum0=-1,const char *name0="",bool if_reciprocal=true): + iDimNum(iDimNum0),is_reciprocal(if_reciprocal),DimensionTag(name0){}; /// function compares the tag of this DimensionID with the input tag and returns the numeric value of the ID if the names coinside or -1 if not. - int getDimID(const std::string &aTag)const{return (this->DimensionTag.compare(aTag)==0)?this->iDimID:-1;} + int getDimNum(const std::string &aTag)const{return (this->DimensionTag.compare(aTag)==0)?this->iDimNum:-1;} /// this should be prviate or protected?; - int getDimID(void)const{return iDimID;} - /// - size_t getDimHash(void)const{return tagHash;} + int getDimNum(void)const{return iDimNum;} /// this should be reserved to friends? - void setDimensionIDValues(int newNum,const std::string &newTag,bool is_recipocal); + void setDimensionIDValues(int newNum,const std::string &newTag,bool recipocal=false){ + iDimNum=newNum;is_reciprocal=recipocal;DimensionTag.assign(newTag);} private: - /// actual Dimension ID numbe used to identify the dimension; Strictly internal or shared with MDGeometryBasis - int iDimID; - /// hash for the dimension tag used for sorting - size_t tagHash; - /// number of reciprocal dimensions (which are non-orthogonal to each other n_rsprcl_dim<=n_total_dim) + /// actual Dimension number used to identify the dimension; Strictly internal or shared with MDGeometryBasis + int iDimNum; + /// number of reciprocal dimensions (which are non-orthogonal to each other n_rsprcl_dim<=n_total_dim) bool is_reciprocal; /// default dimension name used to identify a dimension among others; std::string DimensionTag; - // + }; - -//**************************************************************************************************************************************** - class DLLExport MDGeometryBasis - { - public: +//************* ACCESSORS **************************************************************************************** + virtual ~MDGeometryBasis(void); /// return the numbers of dimensions in current geometry; unsigned int getNumDims(void)const{return n_total_dim;} @@ -100,20 +101,16 @@ namespace Mantid /// function returns the vector of the names of the dimensions, which are defined in the workspace std::vector<std::string> getBasisTags(void)const; - /// function returns the workspace ID, which defines the workspace with particular kind of dimensions std::string getWorkspaceIDname()const{return workspace_name;} - /// function checks if the tags supplied coinside with the tags for current basis ? - bool calculateTagsCompartibility(const std::vector<std::string> &newTags)const; - - /// gettind dimension tag (name) - std::string getTag(unsigned int nDim)const; - /// ort of the dimension. Initial are reciprocal (up to 3), returning {x,y,z}, x^2+y^2+z^2=1; and other are orthogonal {1}. (or may be should be scaled?) + + //TO DO: Define this operations better on the basis of algorithm to build MD from Mantid Workspaces; + // ort of the dimension. Initial are reciprocal (up to 3), returning {x,y,z}, x^2+y^2+z^2=1; and other are orthogonal {1}. (or may be should be scaled?) //const std::vector<double> & getOrt(unsigned int nDim)const; //const std::vector<double> & getOrt(const std::string &tag)const; - /// - double getScale(unsigned int nDim); - size_t getDimHash(const std::string &tag)const; + // + //double getScale(unsigned int nDim); + protected: /*! class constructor:; Protected as GeometryBasis should not exist alone * @param nDimensions -- maximal number of the dimensions all datasets will have @@ -121,20 +118,30 @@ protected: * or 2 for powder (angle and energy or n_detector and energy or |Q| and energy) */ MDGeometryBasis(unsigned int nDimensions=4,unsigned int nReciprocalDimensions=3); - - // init class with new number of dimensions and new dimensions types regardless of previous initialisation (which will be lost) + /// the constructor which builds dimensions from the list of its names; + MDGeometryBasis(const std::vector<std::string> &tags,unsigned int nReciprocal_dims=3); + /// init the class with new number of dimensions and new dimensions types regardless of previous initialisation (which will be lost); Both constructors + /// refer to this class for its initiation; Reciprocal dimensions will be names by the names, located in the beginning of the list of tags; void reinit_GeometryBasis(const std::vector<std::string> &tags,unsigned int nReciprocal_dims=3); /** return the number of the dimension which corresponds to the tag provided - * in a future there will be group of this kind of functions used to construct a transformation matrix from the set of - * dim ID-s - * @param tag -- the tag of the dimention + * @param tag -- the name(tag) of the dimention * @param nothrow -- function throws if the dimension ID falls outside of the range defined for this geometry * if nothrow==true, function returns negative value instead */ - int getDimIDNum(const std::string &tag, bool do_throw=false)const; - std::vector<DimensionID> & getDimensionIDs(void){return DimensionIDs;} + int getDimNum(const std::string &tag, bool do_throw=false)const; + /// returns tag of the column nColumn specified; throws out of range if asked too much; + std::string getColumnName(unsigned int nColumn)const; + + /// get the list of the column numbers for the list of column names + std::vector<int> getColumnNumbers(const std::vector<std::string> &tag_list)const; + + /// the function used by MDGeometry to obtain exisiting dimension ID and to initiate real dimensions in accordance with dimension basis + std::vector<DimensionID> getDimIDs(void)const; + + /// function checks if the tags supplied coinside with the tags for current basis e.g all existing tags have to be here (the order of tags may be different) + bool checkTagsCompartibility(const std::vector<std::string> &newTags)const; /// logger -> to provide logging, for MD workspaces static Kernel::Logger& g_log; @@ -143,36 +150,30 @@ protected: /// number of reciprocal dimensions (which are non-orthogonal to each other n_rsprcl_dim<=n_total_dim) unsigned int n_reciprocal_dimensions; private: - /// vector of dimensions id-s, specific for current architecture, the size of dimensions is n_total_dimensions, - std::vector<DimensionID> DimensionIDs; - // - int findTag(const std::string &tag, bool do_throw)const; - /// function returns the id of the dimension No requseted - //DimensionID getDimensionID(unsigned int nDim)const; - std::map<size_t ,int> dim_list; - // this are the vectors of the primitive cell of the reciprocal lattice // expressed in the framework of ???; All other vectors are orthogonal to this triplet std::vector<double> lattice_ort[3]; std::vector<double> unit; - + /// vector of dimensions id-s, specific for current architecture, the size of dimensions is n_total_dimensions, + std::set<DimensionID> DimensionIDs; + std::map<unsigned int,std::string> dim_names; // build default geometry based on cubic lattice. void buildCubicGeometry(void); - /// copy constructor - MDGeometryBasis(const MDGeometryBasis&); + /// default copy constructor exist + //MDGeometryBasis(const MDGeometryBasis&); /// it is unclear what is the meaning of = - MDGeometryBasis& operator=(const MDGeometryBasis&); + MDGeometryBasis& operator=(const MDGeometryBasis&){return *this;} - - /// gettind dimension name - //std::string getTag(const DimensionID &id)const; - // unique name of workspace as an assembly of a sorted dimension tags + + // unique name of workspace as an assembly of a sorted dimension tags plus some ID for nDims and nReciprocalDims std::string workspace_name; + /// checks if nDimensions consistent with n_reciprocal_dimensions; throws if not + void MDGeometryBasis::check_nDims(unsigned int nDimensions,unsigned int nReciprocalDimensions); }; } // namespace Geometry } // namespace MANTID diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryDescription.h b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryDescription.h index 4b1a54ad467d61457c991b1d64cbca7bdd6a81dd..fdcb6197ded279fb3ec46b1e76306481ff9f13f7 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryDescription.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryDescription.h @@ -1,13 +1,13 @@ #ifndef MDGEOMETRY_DESCRIPTION_H #define MDGEOMETRY_DESCRIPTION_H -#include <list> +#include <deque> #include "MantidGeometry/MDGeometry/MDGeometry.h" /** class describes slicing and rebinning matrix and the geometry of the MD workspace * -* it is possible that such class should be just the MD-geometry as it actually describes it. +* it is possible that such class should be just the MD-geometry as it actually describes it, thoug each class has set of its unique features @author Alex Buts (ISIS, RAL) @date 05/10/2010 @@ -36,30 +36,18 @@ namespace Mantid{ namespace Geometry { // - struct TagIndex{ - int index; - std::string Tag; - }; /// class descries data in one dimension; - + // class SlicingData{ public: + std::string Tag; //< unuque dimension identifier (tag) double trans_bott_left; //< shift in all directions (tans_elo is 4th element of transf_bott_left. Shift expressed in the physical units double cut_min; //< min limits to extract data; double cut_max; //< max limits to extract data; unsigned int nBins; //< number of bins in each direction, bins of size 1 are integrated (collased); - size_t stride; //< the step this dimension index makes in 1D array, when this dimension index changes by one; should be 0 for integrated dimensions; std::string AxisName; //< new names for axis; - SlicingData():trans_bott_left(0),cut_min(-1),cut_max(1),nBins(1),AxisName(""){}; - SlicingData &operator=(const SlicingData &source) { - this->trans_bott_left= source.trans_bott_left; - this->cut_min = source.cut_min; - this->cut_max = source.cut_max; - this->nBins = source.nBins; - this->stride = source.stride; - this->AxisName.assign(source.AxisName); - return *this; - } + SlicingData():Tag(""),trans_bott_left(0),cut_min(-1),cut_max(1),nBins(1),AxisName(""){}; + }; @@ -70,7 +58,8 @@ public: MDGeometryDescription(unsigned int numDims=4,unsigned int nReciprocalDims=3); MDGeometryDescription(const MDGeometry &origin); virtual ~MDGeometryDescription(void); - unsigned int getNumDims(void)const{return nDimensions;} + unsigned int getNumDims(void)const{return nDimensions;} + /// the function sets the rotation matrix which allows to transform vector inumber i into the basis; // TO DO : it is currently a stub returning argument independant unit matrix; has to be written propely std::vector<double> setRotations(unsigned int i,const std::vector<double> basis[3]); @@ -90,12 +79,12 @@ public: unsigned int numBins(unsigned int i)const; bool isAxisNamePresent(unsigned int i)const; std::string getAxisName(unsigned int i)const; - std::string getPAxisTag(unsigned int i)const; - size_t getStride(unsigned int i)const{return data[i].stride;} - + std::string getTag(unsigned int i)const; + + /// finds the location of the dimension, defined by the tag in the list of all dimensions; int getTagNum(const std::string &Tag, bool do_throw=false)const; - /// returns the list of the axis tags sorted in the order requested for view - std::vector<std::string> getAxisTags(void)const; + ///returns the list of the axis tags sorted in the order requested for view + std::vector<std::string> getDimensionsTags(void)const; @@ -132,7 +121,7 @@ public: * * The requested tag is deleted from old location and inserted into the new location, leaving all other data as before. * the tag has to be present in the array initially -> throws otherwise */ - void setPAxis(unsigned int i, const std::string &tagID); + void setPAxis(unsigned int i, const std::string &tag); private: unsigned int nDimensions; /**< real number of dimensions in the target dataset. @@ -140,9 +129,6 @@ private: unsigned int nReciprocalDimensions; // number of reciprocal dimensions from the nDimensions std::vector<double> coordinates[3]; //< The coordinates of the target dataset in the WorkspaceGeometry system of coordinates (define the rotation matrix for qx,qy,qz coordinates;) - std::vector<SlicingData> data; //< data describes one dimension; - std::list<TagIndex> DimTags; // the list of size Ndimensions, which describes the order of the dimensions in the final object; - std::vector<double> rotations; /** auxiliary function which check if the index requested is allowed. ErrinFuncName allows to add to the error message the name of the calling function*/ @@ -153,9 +139,11 @@ private: /// logger -> to provide logging, for MD workspaces static Kernel::Logger& g_log; - - // sort data arrays in accordence with the tags supplied earlier -> this allows the functions which ask a data as a function of a dimension index work properly - void sortAxisTags(void); + std::deque<SlicingData> data; //< data describes one dimension; + +typedef std::deque<SlicingData>::iterator it_data; +typedef std::deque<SlicingData>::const_iterator it_const_data; + }; } // Geometry diff --git a/Code/Mantid/Geometry/src/MDGeometry/MDDimension.cpp b/Code/Mantid/Geometry/src/MDGeometry/MDDimension.cpp index 4721882b171bf925aa659004512a19518d5a84ed..593de3e039baf21ed1402b75f787d578b997908d 100644 --- a/Code/Mantid/Geometry/src/MDGeometry/MDDimension.cpp +++ b/Code/Mantid/Geometry/src/MDGeometry/MDDimension.cpp @@ -17,23 +17,24 @@ MDDimension::getAxisPoints(std::vector<double> &rez)const } // default dimension is always integrated (it has one point and limits) -MDDimension::MDDimension(const DimensionID &ID): -DimensionID(ID), +MDDimension::MDDimension(const std::string &ID): +dimTag(ID), latticeParam(1), isIntegrated(true), coord(1,1), -nStride(1) +nStride(0), +nBins(1) { // default name coinside with the tag but can be overwritten later this->setRange(); - this->setName(DimensionID::getDimensionTag()); + this->setName(dimTag); } /// this function sets Linear range. void MDDimension::setRange(double rxMin,double rxMax,unsigned int nxBins) { if(rxMin>rxMax){ - g_log.error()<< "Attempting to set minimal integration limit higer then maximal for Dimension tag: "<<this->DimensionID::getDimensionTag()<<std::endl; + g_log.error()<< "Attempting to set minimal integration limit higer then maximal for Dimension tag: "<<this->dimTag<<std::endl; g_log.error()<< "setting MinVal: "<<rxMin<<" MaxVal: "<<rxMax<<std::endl; throw(std::invalid_argument("setRange: wrong argument")); @@ -59,13 +60,13 @@ void MDDimension::check_ranges(double rxMin,double rxMax) { if(rxMin>rxMax){ - g_log.error()<< "Attempting to set minimal integration limit higer then maximal for Dimension tag: "<<this->DimensionID::getDimensionTag()<<std::endl; + g_log.error()<< "Attempting to set minimal integration limit higer then maximal for Dimension tag: "<<this->dimTag<<std::endl; g_log.error()<< "setting MinVal: "<<rxMin<<" MaxVal: "<<rxMax<<std::endl; throw(std::invalid_argument("checkRanges: rMin>rMax")); } if(rxMin>this->rMax||rxMax<this->rMin){ - g_log.error()<< "Attempting to set integration limits outside the data range in Dimension ID N: "<<this->DimensionID::getDimensionTag()<<std::endl; + g_log.error()<< "Attempting to set integration limits outside the data range in Dimension ID N: "<<this->dimTag<<std::endl; g_log.error()<< "existing MinVal: "<<this->rMin<<" MaxVal: "<<this->rMax<<" Setting: minVal: "<<rxMin<<" maxVal: "<<rxMax<<std::endl; throw(std::invalid_argument("checkRanges: wrong rMin or rMax")); @@ -76,7 +77,7 @@ void MDDimension::setExpanded(unsigned int nxBins) { if(nxBins<1||nxBins>MAX_REASONABLE_BIN_NUMBER){ - g_log.error()<< "Setting number of bins="<<nxBins<<" our of range for Dimension tag: "<<this->DimensionID::getDimensionTag()<<std::endl; + g_log.error()<< "Setting number of bins="<<nxBins<<" our of range for Dimension tag: "<<this->dimTag<<std::endl; throw(std::invalid_argument("setExpanded: wrong number of bin")); } if(nxBins> 1){ @@ -94,14 +95,16 @@ MDDimension::setExpanded(unsigned int nxBins) r=this->rMin+i*Delta; this->Axis.push_back(r); } - +// but all this is not enough -- > stride has to be set extrenaly, on the basis of other dimensions which were or were not integrated; +// stide is undefined here } /// clear dimension and sets integrated sign; void MDDimension::setIntegrated(void) { this->isIntegrated=true; - this->nBins=1; + this->nBins =1; + this->nStride=0; // the stride of neighboring dimensions has to change accordingly this->Axis.clear(); this->Axis.assign(2,0); this->Axis[0] = this->rMin; @@ -110,7 +113,7 @@ MDDimension::setIntegrated(void) void MDDimension::setIntegrated(double rxMin){ if(rxMin>this->rMax){ - g_log.error()<< "Attempting to set minimal integration limit higer then maximal for Dimension tag: "<<this->DimensionID::getDimensionTag()<<std::endl; + g_log.error()<< "Attempting to set minimal integration limit higer then maximal for Dimension tag: "<<this->dimTag<<std::endl; g_log.error()<< "existing MaxVal: "<<this->rMax<<" setting minVal: "<<rxMin<<std::endl; throw(std::invalid_argument("setIntegrated: new min integration limit is higer than existing max integration limit")); } diff --git a/Code/Mantid/Geometry/src/MDGeometry/MDDimensionRes.cpp b/Code/Mantid/Geometry/src/MDGeometry/MDDimensionRes.cpp index f831e6642dae762276955d883c3e93c8da205e17..65d22fd5a9f0eecdb0d1cd7e2626ba5d01aea8d8 100644 --- a/Code/Mantid/Geometry/src/MDGeometry/MDDimensionRes.cpp +++ b/Code/Mantid/Geometry/src/MDGeometry/MDDimensionRes.cpp @@ -3,19 +3,12 @@ namespace Mantid{ namespace Geometry{ -MDDimensionRes::MDDimensionRes(const DimensionID &ID): -MDDimension(ID) +MDDimensionRes::MDDimensionRes(const std::string &ID,const rec_dim nRecDim0): +MDDimension(ID), +nRecDim(nRecDim0) { - - - int id= MDDimension::getDimID(); - if(id<0||id>=3){ - g_log.error()<<"MDDimensionRes: dimension ID exceeds the acceptable range; Are you trying to initiate an resiprocal dimension using ortogonal dimension using constructor?"; - throw(std::out_of_range("dimension ID exceeds the acceptable range; Are you trying to initiate an resiprocal dimension using ortogonal dimension using constructor?")); - } - this->coord.assign(3,0); - this->coord[id]=1; + this->coord[nRecDim]=1; } void MDDimensionRes::setCoord(const std::vector<double> &theCoord) diff --git a/Code/Mantid/Geometry/src/MDGeometry/MDGeometry.cpp b/Code/Mantid/Geometry/src/MDGeometry/MDGeometry.cpp index 84dd94a5c68ed6d46075f5cd37d7ab1d86c19dee..e152a071153c5a18ed2d154ad7283989475ffd0f 100644 --- a/Code/Mantid/Geometry/src/MDGeometry/MDGeometry.cpp +++ b/Code/Mantid/Geometry/src/MDGeometry/MDGeometry.cpp @@ -18,10 +18,11 @@ MDGeometry::setRanges(MDGeometryDescription const &trf) unsigned int n_new_dims=trf.getNumDims(); MDDimension *pDim; if(n_new_dims>this->n_total_dim){ - throw(std::invalid_argument("Geometry::setRanges: Attempting to set more dimensions then are currently defined ")); + g_log.error()<<" MDGeometry::setRanges transformation sets more ranges then already defined\n"; + throw(std::invalid_argument("Geometry::setRanges: Attempting to set more dimensions then are currently defined ")); } - //this->arrangeDimensionsProperly(trf.getAxisTags()); - std::vector<std::string> tag=trf.getAxisTags(); + + std::vector<std::string> tag=trf.getDimensionsTags(); // let's analyse the dimensions, which were mentioned in transformation matrix and set the ranges of these dimensions // as requested @@ -41,14 +42,15 @@ MDGeometry::setRanges(MDGeometryDescription const &trf) this->n_expanded_dim++; } } - this->arrangeDimensionsProperly(trf.getAxisTags()); + this->arrangeDimensionsProperly(trf.getDimensionsTags()); } // void MDGeometry::reinit_Geometry(const MDGeometryDescription &trf,unsigned int nReciprocalDims) { - this->reinit_Geometry(trf.getAxisTags(),nReciprocalDims); + this->reinit_Geometry(trf.getDimensionsTags(),nReciprocalDims); + this->setRanges(trf); /* // all reciprocal dimensions may have new coordinates in the WorkspaceGeometry coordinate system, so these coordinates have to @@ -67,13 +69,14 @@ MDGeometry::reinit_Geometry(const MDGeometryDescription &trf,unsigned int nRecip } */ } + // void MDGeometry::reinit_Geometry(const std::vector<std::string> &DimensionTags,unsigned int nReciprocalDims) { unsigned int i; - bool congruent_geometries; + bool congruent_geometries(true); @@ -81,7 +84,7 @@ MDGeometry::reinit_Geometry(const std::vector<std::string> &DimensionTags,unsign if(DimensionTags.size()!=this->getNumDims()||nReciprocalDims!=this->getNumReciprocalDims()){ congruent_geometries=false; }else{ - congruent_geometries=calculateTagsCompartibility(DimensionTags); + congruent_geometries=checkTagsCompartibility(DimensionTags); } if(!congruent_geometries){ @@ -94,13 +97,11 @@ MDGeometry::reinit_Geometry(const std::vector<std::string> &DimensionTags,unsign theDimension[i]=NULL; } } - - std::vector<DimensionID> &ID = this->getDimensionIDs(); - this->init_empty_dimensions(ID); + this->init_empty_dimensions(); + }else{ + this->arrangeDimensionsProperly(DimensionTags); } - this->arrangeDimensionsProperly(DimensionTags); - } void @@ -125,20 +126,23 @@ MDGeometry::arrangeDimensionsProperly(const std::vector<std::string> &tags) unsigned int n_expanded_dimensions(0),n_collapsed_dimensions(0); - int dim_num; + MDDimension *pDim; + std::map<std::string,MDDimension *>::iterator it; // let's sort dimensions as requested by the list of tags for(i=0;i<n_new_dims;i++){ // when dimension num we want to use next - dim_num = this->getDimIDNum(tags[i],false); - if(dim_num<0){ + it = dimensions_map.find(tags[i]); + if(it==dimensions_map.end()){ g_log.error()<<" The dimension with tag "<<tags[i]<<" does not belong to current geometry\n"; throw(std::invalid_argument("Geometry::arrangeDimensionsProperly: new dimension requested but this function can not add new dimensions")); } - pDim = this->theDimension[dim_num]; - this->theDimension[dim_num] = NULL; + // get the dimension itself + pDim = it->second; + // clear map for future usage; + dimensions_map.erase(it); // set range according to request; if(pDim->getIntegrated()){ // this is collapsed dimension; @@ -151,9 +155,8 @@ MDGeometry::arrangeDimensionsProperly(const std::vector<std::string> &tags) } // deal with the dimensions, which were not menshioned in the transformation request - for(i=0;i<this->getNumDims();i++){ - pDim = this->theDimension[i]; - if(!pDim)continue; + for(it=dimensions_map.begin();it!=dimensions_map.end();it++){ + pDim = it->second; if(pDim->getIntegrated()){ // this is collapsed dimension; pCollapsedDims[n_collapsed_dimensions]=pDim; @@ -162,9 +165,9 @@ MDGeometry::arrangeDimensionsProperly(const std::vector<std::string> &tags) pExpandedDims[n_expanded_dimensions] =pDim; n_expanded_dimensions++; } - theDimension[i]=NULL; } - + // invalidate map which is not nedded any more; + dimensions_map.clear(); this->n_expanded_dim=n_expanded_dimensions; // total number of dimensions should not change; @@ -177,26 +180,25 @@ MDGeometry::arrangeDimensionsProperly(const std::vector<std::string> &tags) // deal with expanded dimensions for(i=0;i<this->n_expanded_dim;i++){ pDim = pExpandedDims[i]; + + // store the dimension in the vector and the map this->theDimension[i]=pDim; + dimensions_map[pDim->getDimensionTag()]=pDim; - this->theDimension[i]->setStride(dimension_stride); + // set integral dimensions characteristics; + this->theDimension[i]->setStride(dimension_stride); dimension_stride *= this->theDimension[i]->getNBins(); + } // now with collapsed dimensions; unsigned int ind(n_expanded_dim); for(i=0;i<n_collapsed_dimensions;i++){ pDim = pCollapsedDims[i]; - this->theDimension[ind+i]=pDim; - this->theDimension[ind+i]->setStride(0); - } + this->theDimension[ind+i]=pDim; + dimensions_map[pDim->getDimensionTag()]=pDim; -// fill up the dimensions map used for fast search of a dimension by its tag; - size_t hash; - for(i=0;i<getNumDims();i++){ - hash = theDimension[i]->getDimHash(); - dimensions_map[hash]=i; - //theDimension[i]->set + this->theDimension[ind+i]->setStride(0); } }; @@ -252,36 +254,24 @@ MDGeometry::getDimension(unsigned int i)const return theDimension[i]; } MDDimension * -MDGeometry::getDimension(const std::string &tag)const +MDGeometry::getDimension(const std::string &tag,bool do_throw)const { MDDimension *pDim(NULL); - int dim_num=this->getDimNum(tag,true); - - return theDimension[dim_num]; -} - - -int -MDGeometry::getDimNum(const std::string &tag,bool do_throw)const -{ -// finds the index of the dimension in the array of dimensions - int dimNum=-1; - - std::map<size_t,int>::const_iterator it; - - size_t tag_hash = this->getDimHash(tag); - it = dimensions_map.find(tag_hash); + std::map<std::string,MDDimension *>::const_iterator it; + it = dimensions_map.find(tag); if(it == dimensions_map.end()){ if(do_throw){ - g_log.error()<<" MDGeometry::getDimNum: dimension with tag: "<<tag<<" does not exist in current geometry\n"; + g_log.error()<<" MDGeometry::getDimension: dimension with tag: "<<tag<<" does not exist in current geometry\n"; throw(std::invalid_argument("Geometry::getDimension: wrong dimension tag")); } - }else{ - dimNum = it->second; } - return dimNum; + pDim = it->second; + + return pDim; } + + /* std::vector<double> MDGeometry::getOrt(DimensionsID id)const @@ -309,25 +299,32 @@ MDGeometryBasis(nDimensions,nReciprocalDimensions), n_expanded_dim(0) { this->theDimension.assign(nDimensions,NULL); - this->init_empty_dimensions(this->getDimensionIDs()); - this->reinit_Geometry(this->getBasisTags(),nReciprocalDimensions); - + this->init_empty_dimensions(); + } - void -MDGeometry::init_empty_dimensions(const std::vector<DimensionID> &ID) +void +MDGeometry::init_empty_dimensions() { - unsigned int i; - for(i=0;i<ID.size();i++){ - if(ID[i].isReciprocal()){ // 1) initialize reciprocal space dimensions (momentum components) - this->theDimension[i] = new MDDimensionRes(ID[i]); - }else{ // 2) initialize additional orthogonal dimensions - this->theDimension[i] = new MDDimension(ID[i]); - } -// this->theDimension[i]->setDimensionNum(i); + std::vector<MDGeometryBasis::DimensionID> ID=this->getDimIDs(); + std::string tag; + unsigned int i; + unsigned int nRec_count(0); + dimensions_map.clear(); + + for(i=0;i<ID.size();i++){ + tag = ID[i].getDimensionTag(); + if(ID[i].isReciprocal()){ // 1) initialize reciprocal space dimensions (momentum components) + this->theDimension[i] = new MDDimensionRes(tag,(rec_dim)nRec_count); + nRec_count++; + }else{ // 2) initialize additional orthogonal dimensions + this->theDimension[i] = new MDDimension(ID[i].getDimensionTag()); } + // initiate map to search dimensions by names + dimensions_map[tag]=this->theDimension[i]; + } // all dimensions initiated by default constructor are integrated; - this->n_expanded_dim=0; + this->n_expanded_dim=0; } MDGeometry::~MDGeometry(void) @@ -338,6 +335,7 @@ MDGeometry::~MDGeometry(void) } this->theDimension.clear(); + this->dimensions_map.clear(); } diff --git a/Code/Mantid/Geometry/src/MDGeometry/MDGeometryBasis.cpp b/Code/Mantid/Geometry/src/MDGeometry/MDGeometryBasis.cpp index e94c36b21f619aa5324ee187affbeea6bb5a1648..462924d267b49f29d646fa3ab57c2c68467fd336 100644 --- a/Code/Mantid/Geometry/src/MDGeometry/MDGeometryBasis.cpp +++ b/Code/Mantid/Geometry/src/MDGeometry/MDGeometryBasis.cpp @@ -11,42 +11,19 @@ namespace Mantid { using namespace Kernel; - /// hasher; - boost::hash<std::string> hash_string; + Logger& MDGeometryBasis::g_log=Kernel::Logger::get("MDWorkspaces"); -void -DimensionID::setDimensionIDValues(int newNum,const std::string &newTag,bool if_recipocal) -{ - iDimID = newNum; - DimensionTag.assign(newTag); - is_reciprocal =if_recipocal; - - // boost::hash<std::string> hash_string; - tagHash=hash_string(DimensionTag); -} - - -Logger& MDGeometryBasis::g_log=Kernel::Logger::get("MDWorkspaces"); // default names for Dimensions used by default constructor; length should match the size of the MAX_MD_DIMENSIONS_NUM const char *DefaultDimTags[]={"q1","q2","q3","en","u1","u2","u3","u4","u5","u6","u7"}; - // Protected constructor; + +// Protected constructor; MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): n_total_dim(nDimensions), n_reciprocal_dimensions(nReciprocalDimensions), unit(1,1) { - if(nReciprocalDimensions<1||nReciprocalDimensions>3){ - g_log.error()<<"MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): number of reciprocal dimensions can vary from 1 to 3 but attempted"<<nReciprocalDimensions<<std::endl; - throw(std::invalid_argument("This constructor can not be used to buid low dimension datasets geometry")); - } - if(nDimensions>MAX_MD_DIMS_POSSIBLE||nDimensions<1){ - g_log.error()<<"MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): This constructor attempts to initiate wrong number of dimensions\n"; - throw(std::invalid_argument("This constructor attempts to initiate more than allowed number of dimensions")); - } - if(nDimensions<nReciprocalDimensions){ - g_log.error()<<"MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): Attempting to initiate total dimensions less than reciprocal dimensions\n"; - throw(std::invalid_argument("Number of reciprocal dimensions is bigger than the total number of dimensions")); - } + this->check_nDims(nDimensions,nReciprocalDimensions); + // assign default tags to the array of string; std::vector<std::string> DIMS(nDimensions,""); unsigned int ic(0); @@ -58,29 +35,55 @@ unit(1,1) ic++; } - this->reinit_GeometryBasis(DIMS,nReciprocalDimensions); } // -size_t -MDGeometryBasis::getDimHash(const std::string &tag)const +MDGeometryBasis::MDGeometryBasis(const std::vector<std::string> &tags_list,unsigned int nReciprocalDimensions): +n_total_dim(0), +n_reciprocal_dimensions(nReciprocalDimensions), +unit(1,1) +{ + unsigned int nDimensions = tags_list.size(); + n_total_dim =nDimensions; + + this->check_nDims(nDimensions,nReciprocalDimensions); + + this->reinit_GeometryBasis(tags_list,nReciprocalDimensions); +} +// +void +MDGeometryBasis::check_nDims(unsigned int nDimensions,unsigned int nReciprocalDimensions) { - - int dim_num=findTag(tag, true); - return DimensionIDs[dim_num].getDimHash(); + if(nReciprocalDimensions<1||nReciprocalDimensions>3){ + g_log.error()<<"MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): number of reciprocal dimensions can vary from 1 to 3 but attempted"<<nReciprocalDimensions<<std::endl; + throw(std::invalid_argument("This constructor can not be used to buid low dimension datasets geometry")); + } + if(nDimensions>MAX_MD_DIMS_POSSIBLE||nDimensions<1){ + g_log.error()<<"MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): This constructor attempts to initiate wrong number of dimensions\n"; + throw(std::invalid_argument("This constructor attempts to initiate more than allowed number of dimensions")); + } + if(nDimensions<nReciprocalDimensions){ + g_log.error()<<"MDGeometryBasis::MDGeometryBasis(unsigned int nDimensions,unsigned int nReciprocalDimensions): Attempting to initiate total dimensions less than reciprocal dimensions\n"; + throw(std::invalid_argument("Number of reciprocal dimensions is bigger than the total number of dimensions")); + } } // bool -MDGeometryBasis::calculateTagsCompartibility(const std::vector<std::string> &newTags)const +MDGeometryBasis::checkTagsCompartibility(const std::vector<std::string> &newTags)const { // if size is different, tags are not compartible; if(newTags.size()!=this->getNumDims())return false; + DimensionID id; + std::set<DimensionID>::const_iterator it; + - int ind; for(unsigned int i=0;i<newTags.size();i++){ // if one new tag is not among the old one -- the tags lists are not compartible - if((ind=getDimIDNum(newTags[i],false))<0)return false; + id.setDimensionIDValues(-1,newTags[i]); + + it = DimensionIDs.find(id); + if(it==DimensionIDs.end())return false; } return true; } @@ -92,21 +95,16 @@ MDGeometryBasis::reinit_GeometryBasis(const std::vector<std::string> &tag_list,u unsigned int i; this->n_reciprocal_dimensions= nReciprocalDims; this->n_total_dim = tag_list.size(); + this->check_nDims(n_total_dim,n_reciprocal_dimensions); - if(n_total_dim<1||n_total_dim>MAX_MD_DIMS_POSSIBLE){ - g_log.error()<<"WorkspaceGeometry::reinit_class: Attemted to create workspace with "<<n_total_dim<<" is out of the limits allowed\n"; - throw(std::out_of_range("WorkspaceGeometry::reinit_class: too many dimensions requested")); - } - if(this->n_reciprocal_dimensions<1||this->n_reciprocal_dimensions>3){ - g_log.error()<<"WorkspaceGeometry::reinit_class: number of reciprocal dimensions out of range (nr-dim<1||nr-dim>3)\n"; - throw(std::out_of_range("WorkspaceGeometry::reinit_class: number of reciprocal dimensions out of range (nr-dim<1||nr-dim>3)")); - } - // clear contents of previous map if it was any - dim_list.clear(); + // clear contents of previous map and set if it was any + this->dim_names.clear(); + this->DimensionIDs.clear(); + std::pair<std::set<DimensionID>::iterator,bool> ret; + // default geometry assumes all resiprocal dimensions at the beginning and all other orthogonal dimensions after that. - std::vector<DimensionID> DIMS(n_total_dim,DimensionID()); - size_t tagHash; + DimensionID id; bool isReciprocal(true); for(i=0;i<n_total_dim;i++){ if(i<nReciprocalDims){ @@ -114,36 +112,37 @@ MDGeometryBasis::reinit_GeometryBasis(const std::vector<std::string> &tag_list,u }else{ isReciprocal=false; } - DIMS[i].setDimensionIDValues(i,tag_list[i],isReciprocal); - - + + id.setDimensionIDValues(i,tag_list[i],isReciprocal); + // remember the id; + ret=this->DimensionIDs.insert(id); + if(!ret.second){ + g_log.error()<<" all tags have to be unique but the list of imput tags have some equivalent elements\n"; + throw(std::invalid_argument("Imput tags have equivalent elements")); + } + // specify the map to find the name by index + dim_names.insert(std::pair<int,std::string>(i,tag_list[i])); } // initiate all real orts to 0 for(i=0;i<nReciprocalDims;i++){ this->lattice_ort[i].assign(3,0); } - - // default reciprocal lattice: cubic Define three orthogonal unit vectors. this->buildCubicGeometry(); - // the WorkspaceGeometry has to have all their dimensions sorted properly. - //sort(DIMS.begin(),DIMS.end()); - - - for(i=0;i<n_total_dim;i++){ - tagHash = DIMS[i].getDimHash(); - dim_list[tagHash]=i; + + - workspace_name+=tag_list[i]; + // build workspace name + for(i=0;i<n_total_dim;i++){ + workspace_name+=tag_list[i]+":"; } - std::stringstream n_rec_dim; - n_rec_dim<<"_rcd"<<this->n_reciprocal_dimensions; + n_rec_dim<<"_NDIM_"<<this->n_total_dim<<"x"<<this->n_reciprocal_dimensions; workspace_name+=n_rec_dim.str(); - this->DimensionIDs=DIMS; + this->DimensionIDs; } // @@ -152,24 +151,48 @@ MDGeometryBasis::getBasisTags(void)const { std::vector<std::string> tmp(this->getNumDims(),""); for(unsigned int i=0;i<this->getNumDims();i++){ - tmp[i].assign(this->DimensionIDs[i].getDimensionTag()); + tmp[i].assign(dim_names.find(i)->second); } return tmp; } +// +std::vector<MDGeometryBasis::DimensionID> +MDGeometryBasis::getDimIDs(void)const +{ + DimensionID id; + std::string tag; + std::vector<MDGeometryBasis::DimensionID> IDs(this->n_total_dim,id); + std::set<DimensionID>::const_iterator it; + for(unsigned int i=0;i<IDs.size();i++){ + tag = dim_names.find(i)->second; + id.setDimensionIDValues(-1,tag); -// copy constructr -MDGeometryBasis::MDGeometryBasis(const MDGeometryBasis &orgn){ - - this->n_total_dim=orgn.n_total_dim; - /// vector of dimensions id-s, specific for current architecture, the size of dimensions is n_total_dimensions, - this->DimensionIDs=orgn.DimensionIDs; - - - for(int i=0;i<3;i++){ - this->lattice_ort[i]=orgn.lattice_ort[i]; - } + it = DimensionIDs.find(id); + IDs[i] = *it; + } + return IDs; +} +// get the list of the column numbers for the list of column names +std::vector<int> +MDGeometryBasis::getColumnNumbers(const std::vector<std::string> &tag_list)const +{ + size_t n_elements=tag_list.size(); + std::vector<int> nums(n_elements,-1); + std::set<DimensionID>::const_iterator it; + DimensionID id; + for(unsigned int i=0;i<tag_list.size();i++){ + id.setDimensionIDValues(-1,tag_list[i]); + it = DimensionIDs.find(id); + if(it==DimensionIDs.end()){ + g_log.error()<<" dimension with name: "<<tag_list[i]<<" can not be found among the basis\n"; + throw(std::invalid_argument("MDGeometryBasis::getOrt: argument out of range")); + } + nums[i]=it->getDimNum(); + } + return nums; } + /* const std::vector<double> & MDGeometryBasis::getOrt(const std::string &tag)const @@ -196,53 +219,34 @@ MDGeometryBasis::getOrt(unsigned int dimNum)const */ // std::string -MDGeometryBasis::getTag(unsigned int dimNum)const +MDGeometryBasis::getColumnName(unsigned int dimNum)const { if(dimNum>=this->n_total_dim){ g_log.error()<<"WorkspaceGeometry::getOrt: Workspace has "<<this->n_total_dim<<" dimensions but the coordinate for Dimension N: "<<dimNum<<" reqested\n"; throw(std::invalid_argument("MDGeometryBasis::getOrt: argument out of range")); } - return this->DimensionIDs[dimNum].getDimensionTag(); + + return dim_names.find(dimNum)->second; } // int -MDGeometryBasis::getDimIDNum(const std::string &tag, bool do_throw)const -{ - int ind = findTag(tag,do_throw); - if(ind>-1){ - return DimensionIDs[ind].getDimID(); - } - return -1; -} -/* -int MDGeometryBasis::getDimNum(const std::string &tag, bool do_throw)const { - int ind = findTag(tag,do_throw); - if(ind>0){ - return DimensionIDs[ind].getDimNum(); + int i(-1); + DimensionID id(-1,tag.c_str()); + std::set<DimensionID>::iterator it = this->DimensionIDs.find(id); + if(it != DimensionIDs.end()){ + i=it->getDimNum(); + }else{ + if(do_throw){ + g_log.error()<<"tag "<<tag<<" does not exist in these dimensions\n"; + throw(std::invalid_argument("Wrong tag requested")); } - return -1; + } + return i; } -*/ -int -MDGeometryBasis::findTag(const std::string &tag, bool do_throw)const -{ - int rez=-1; - std::map<size_t,int>::const_iterator it; - size_t hash = hash_string(tag); - it = this->dim_list.find(hash); - if(it==dim_list.end()){ - if(do_throw){ - g_log.error()<<"MDGeometryBasis::getDimIDNum: the tag: "<<tag<<" does not belong to current geometry\n"; - throw(std::out_of_range("MDGeometryBasis::getDimRefNum: the tag requested does not belong to current geometry")); - } - }else{ - rez = it->second; - } - return rez; -} + /** Build cubic geometry of three orthogonal vectors. */ void diff --git a/Code/Mantid/Geometry/src/MDGeometry/MDGeometryDescription.cpp b/Code/Mantid/Geometry/src/MDGeometry/MDGeometryDescription.cpp index edccbce3cf9a2b48613abe19380a570bb1dc9947..123948511a0134d8e77c97e5bf18fcd87bd8ed3b 100644 --- a/Code/Mantid/Geometry/src/MDGeometry/MDGeometryDescription.cpp +++ b/Code/Mantid/Geometry/src/MDGeometry/MDGeometryDescription.cpp @@ -35,13 +35,13 @@ void MDGeometryDescription::build_from_geometry(const MDGeometry &origin) { - std::vector<std::string> tag = origin.getBasisTags(); + this->nDimensions = origin.getNumDims(); this->nReciprocalDimensions = origin.getNumReciprocalDims(); for(unsigned int i=0;i<nReciprocalDimensions;i++){ this->coordinates[i].assign(3,0); - MDDimension * pDim = origin.getDimension(tag[i]); + MDDimension * pDim = origin.getDimension(i); if(pDim){ this->coordinates[i] = pDim->getCoord(); } @@ -51,21 +51,16 @@ MDGeometryDescription::build_from_geometry(const MDGeometry &origin) this->data.assign(nDimensions,any); unsigned int i; - TagIndex curTag; - - this->DimTags.clear(); for(i=0;i<nDimensions;i++){ + MDDimension *pDim = origin.getDimension(i); - this->data[i].trans_bott_left=0; - this->data[i].cut_min = pDim->getMinimum(); - this->data[i].cut_max = pDim->getMaximum(); - this->data[i].nBins = pDim->getNBins(); - this->data[i].stride = pDim->getStride(); - this->data[i].AxisName = pDim->getName(); - - curTag.index=i; - curTag.Tag =pDim->getDimensionTag(); - this->DimTags.push_back(curTag); + this->data[i].Tag = pDim->getDimensionTag(); + this->data[i].trans_bott_left= 0; + this->data[i].cut_min = pDim->getMinimum(); + this->data[i].cut_max = pDim->getMaximum(); + this->data[i].nBins = pDim->getNBins(); + this->data[i].AxisName = pDim->getName(); + } } @@ -73,12 +68,14 @@ MDGeometryDescription::build_from_geometry(const MDGeometry &origin) int MDGeometryDescription::getTagNum(const std::string &Tag,bool do_throw)const{ int iTagNum=-1; - std::list<TagIndex>::const_iterator it; - for(it=DimTags.begin();it!=DimTags.end();it++){ + int ic(0); + it_const_data it; + for(it=data.begin();it!=data.end();it++){ if(it->Tag.compare(Tag)==0){ - iTagNum=it->index; - break; + iTagNum=ic; + break; } + ic++; } if(iTagNum<0 && do_throw){ g_log.error()<<" Tag "<<Tag<<" does not exist\n"; @@ -90,36 +87,40 @@ MDGeometryDescription::getTagNum(const std::string &Tag,bool do_throw)const{ //****** SET ******************************************************************************* void -MDGeometryDescription::setPAxis(unsigned int i, const std::string &Tag) +MDGeometryDescription::setPAxis(unsigned int i, const std::string &Tag) { + this->check_index(i,"setPAxis"); - unsigned int ic(0); +// move existing dimension structure, described by the tag into new position, described by the index i; + unsigned int ic(0),old_place_index; - std::list<TagIndex>::iterator it,old_place, new_place; - old_place = DimTags.end(); - for(it=DimTags.begin();it!=old_place;it++){ + it_data it,old_place, new_place; + old_place = data.end(); + for(it=data.begin();it!=old_place;it++){ if(it->Tag.compare(Tag)==0){ - old_place=it; - if(ic >i)break; + old_place = it; + old_place_index= ic; + if(ic >i){ + old_place_index=ic+1; // after insertion it will be one index higher + break; + } } if(ic == i){ new_place=it; - if(old_place!=DimTags.end())break; + if(old_place!=data.end())break; } ic++; } - if(old_place==DimTags.end()){ + if(old_place==data.end()){ g_log.error()<<" Tag "<<Tag<<" does not exist\n"; throw(std::invalid_argument(" The requested tag does not exist")); } if(new_place!=old_place){ - DimTags.insert(new_place,*old_place); - DimTags.erase(old_place); - this->sortAxisTags(); + data.insert(new_place,*old_place); // this invalidates old iterators + old_place = data.begin()+old_place_index; + data.erase(old_place); } - - } // @@ -148,6 +149,7 @@ MDGeometryDescription::setNumBins(unsigned int i,unsigned int Val) if(Val>MAX_REASONABLE_BIN_NUMBER){ throw(std::invalid_argument("SlicingProperty::setNumBins value bin requested is larger than MAX_REASONABLE_BIN_NUMBER")); } + if(Val==0)Val=1; this->data[i].nBins=Val; } void @@ -201,46 +203,27 @@ MDGeometryDescription::getAxisName(unsigned int i)const this->check_index(i,"getAxisName"); return (this->data[i].AxisName); } - -void -MDGeometryDescription::sortAxisTags(void) +std::string +MDGeometryDescription::getTag(unsigned int i)const { - - std::list<TagIndex>::iterator it; - std::vector<SlicingData> sorted_data(nDimensions,SlicingData()); - unsigned int ic(0); - SlicingData Current; - for(it=this->DimTags.begin();it!=DimTags.end();it++){ - sorted_data[ic]=data[it->index]; - it->index = ic; - ic++; - } - this->data=sorted_data; + this->check_index(i,"getTag"); + return (this->data[i].Tag); } - std::vector<std::string> -MDGeometryDescription::getAxisTags(void)const +MDGeometryDescription::getDimensionsTags(void)const { std::vector<std::string> tags(this->nDimensions,""); - std::list<TagIndex>::const_iterator it; + it_const_data it; unsigned int ic(0); - for(it=this->DimTags.begin();it!=DimTags.end();it++){ + for(it=this->data.begin();it!=data.end();it++){ tags[ic] = it->Tag; ic++; } return tags; } -/* -DimensionsID -SlicingProperty::getPAxis(unsigned int i)const -{ - this->check_index(i,"getPAxis"); - return this->pAxis[i]; -} -*/ MDGeometryDescription::MDGeometryDescription(unsigned int numDims,unsigned int numRecDims): nDimensions(numDims), @@ -299,7 +282,7 @@ MDGeometryDescription::intit_default_slicing(unsigned int nDims,unsigned int nRe defaults.cut_max = 1; defaults.nBins = 1; defaults.AxisName.assign(""); - defaults.stride = 0; + this->data.assign(nDimensions,defaults); @@ -307,15 +290,11 @@ MDGeometryDescription::intit_default_slicing(unsigned int nDims,unsigned int nRe this->coordinates[i].assign(3,0); this->coordinates[i].at(i)= 1; } - DimTags.clear(); - TagIndex cur; + + for(i=0;i<nDimensions;i++){ - cur.index=i; - cur.Tag = def_tags[i]; - this->DimTags.push_back(cur); - this->data[i].AxisName = def_tags[i]; - - + data[i].Tag =def_tags[i]; + this->data[i].AxisName = def_tags[i]; } } diff --git a/Code/Mantid/Geometry/test/MDDimensionTest.h b/Code/Mantid/Geometry/test/MDDimensionTest.h index 442d549c372d03ddcbbcdb0ad7f335f2404f92f0..6b190c50935177afbc5136dec7ed087122e44bfc 100644 --- a/Code/Mantid/Geometry/test/MDDimensionTest.h +++ b/Code/Mantid/Geometry/test/MDDimensionTest.h @@ -12,7 +12,7 @@ using namespace Geometry; class tDimension: public MDDimension { public: - tDimension(const DimensionID &ID):MDDimension(ID){}; + tDimension(const std::string &ID):MDDimension(ID){}; virtual void setRange(double rMin=-1,double rMax=1,unsigned int nBins=1){ MDDimension::setRange(rMin,rMax,nBins); } @@ -34,7 +34,7 @@ public: class tDimensionRes: public MDDimensionRes { public: - tDimensionRes(const DimensionID &ID):MDDimensionRes(ID){}; + tDimensionRes(const std::string &ID,const rec_dim nDim):MDDimensionRes(ID,nDim){}; virtual void setRange(double rMin=-1,double rMax=1,unsigned int nBins=1){ MDDimensionRes::setRange(rMin,rMax,nBins); } @@ -56,12 +56,10 @@ class testMDDimension : public CxxTest::TestSuite tDimension *pOrtDim; public: void testDimensionConstructor(void){ - DimensionID res(0,"x"); - DimensionID ort(3,"T"); // define one reciprocal - TS_ASSERT_THROWS_NOTHING(pResDim = new tDimensionRes(res)); + TS_ASSERT_THROWS_NOTHING(pResDim = new tDimensionRes("x",q1)); // and one orthogonal dimension - TS_ASSERT_THROWS_NOTHING(pOrtDim = new tDimension(ort)); + TS_ASSERT_THROWS_NOTHING(pOrtDim = new tDimension("en")); } void testSetRanges(){ if(!pOrtDim)TS_FAIL("pOrtDim class has not been constructed properly"); @@ -83,9 +81,23 @@ public: TS_ASSERT_DELTA(pOrtDim->getMaximum(), 200,FLT_EPSILON); // check axis name - const char *NAME="T"; - TS_ASSERT_SAME_DATA(pOrtDim->getName().c_str(),NAME,1); + TS_ASSERT_EQUALS(pOrtDim->getName(),"en"); } + void testGetX(){ + double x; + if(!pOrtDim)TS_FAIL("pOrtDim class has not been constructed properly"); + TS_ASSERT_THROWS_NOTHING(x=pOrtDim->getX(0)); + TS_ASSERT_DELTA(x,pOrtDim->getMinimum(),FLT_EPSILON); + unsigned int nBins; + TS_ASSERT_THROWS_NOTHING(nBins = pOrtDim->getNBins()); + + TS_ASSERT_THROWS_NOTHING(x=pOrtDim->getX(nBins)); + TS_ASSERT_DELTA(x,pOrtDim->getMaximum(),FLT_EPSILON); + // out of range request + TS_ASSERT_THROWS_ANYTHING(x=pOrtDim->getX(-1)); + TS_ASSERT_THROWS_ANYTHING(x=pOrtDim->getX(nBins+1)); + } + void testSetAxisName(){ if(!pOrtDim)TS_FAIL("pOrtDim class has not been constructed properly"); // set axis name @@ -126,10 +138,9 @@ public: } void testDimensionRes(void){ - DimensionID res(1,"yy"); - tDimensionRes dimY(res); + tDimensionRes dimY("yy",q2); std::vector<double> e0; TS_ASSERT_THROWS_NOTHING(e0=dimY.getCoord()); diff --git a/Code/Mantid/Geometry/test/MDGeometryBasisTest.h b/Code/Mantid/Geometry/test/MDGeometryBasisTest.h index af1094a14f70fb4149494821fe86beffb7dafea7..e66dc9752b6015268e7578306b81f50a0ab096a0 100644 --- a/Code/Mantid/Geometry/test/MDGeometryBasisTest.h +++ b/Code/Mantid/Geometry/test/MDGeometryBasisTest.h @@ -12,9 +12,14 @@ class publicWorkspaceGeometry: public MDGeometryBasis { public: publicWorkspaceGeometry(unsigned int nDims=4,unsigned int nReciprocalDims=3):MDGeometryBasis(nDims,nReciprocalDims){}; - int getDimRefNum(const std::string &tag, bool nothrow=false)const{return MDGeometryBasis::getDimIDNum(tag,nothrow);} - // DimensionID getDimensionID(unsigned int nDim)const{return MDGeometryBasis::getDimensionID(nDim);} - void reinit_GeometryBasis(const std::vector<std::string> &ID){MDGeometryBasis::reinit_GeometryBasis(ID);} + publicWorkspaceGeometry(const std::vector<std::string> &tags,unsigned int nReciprocalDims=3):MDGeometryBasis(tags,nReciprocalDims){}; + int getDimNum(const std::string &tag, bool nothrow=false)const{return MDGeometryBasis::getDimNum(tag,nothrow);} + std::string getColumnName(unsigned int nColumn)const{return MDGeometryBasis::getColumnName(nColumn);} + void reinit_GeometryBasis(const std::vector<std::string> &ID,unsigned int nReciprocal_dims=3){MDGeometryBasis::reinit_GeometryBasis(ID,nReciprocal_dims);} + /// function checks if the tags supplied coinside with the tags for current basis e.g all existing tags have to be here (the order of tags may be different) + bool checkTagsCompartibility(const std::vector<std::string> &newTags)const{return MDGeometryBasis::checkTagsCompartibility(newTags);} + std::vector<int> getColumnNumbers(const std::vector<std::string> &tag_list)const{return MDGeometryBasis::getColumnNumbers(tag_list);} + std::vector<MDGeometryBasis::DimensionID> getDimIDs(void)const{return MDGeometryBasis::getDimIDs();} }; @@ -23,11 +28,25 @@ class testWorkspaceGm : public CxxTest::TestSuite publicWorkspaceGeometry *pGeometry5x3; publicWorkspaceGeometry *pGeom4x2; std::vector<std::string> names; + std::vector<std::string> default_tags; public: void test2x4Basis(){ - TS_ASSERT_THROWS_NOTHING(pGeom4x2= new publicWorkspaceGeometry(4,2)); - //TS_ASSERT_THROWS_NOTHING(ID2x4=pGeom4x2->getWorkspaceID()); + std::vector<std::string> non_default_tags(4,""); + non_default_tags[0]="aa"; + non_default_tags[1]="bb"; + non_default_tags[2]="bb"; + non_default_tags[3]="dddd"; + // equivalent tags would not initiate + TS_ASSERT_THROWS_ANYTHING(pGeom4x2= new publicWorkspaceGeometry(non_default_tags,2)); + + // now should be ok; + non_default_tags[2]="cc"; + TS_ASSERT_THROWS_NOTHING(pGeom4x2= new publicWorkspaceGeometry(non_default_tags,2)); + // get workspace name; + std::string ws_name; + TS_ASSERT_THROWS_NOTHING(ws_name=pGeom4x2->getWorkspaceIDname()); + TS_ASSERT_EQUALS(ws_name,"aa:bb:cc:dddd:_NDIM_4x2"); } void testWorkspaceGeometryConstructor(void){ @@ -42,15 +61,70 @@ public: // now we do define 5-d workspace TS_ASSERT_THROWS_NOTHING(pGeometry5x3 = new publicWorkspaceGeometry(5)); - //TS_ASSERT_THROWS_NOTHING(ID3x2=pGeometry5x3->getWorkspaceID()); + std::string default_name("q1:q2:q3:en:u1:_NDIM_5x3"); + TS_ASSERT_EQUALS(pGeometry5x3->getWorkspaceIDname(),default_name); + + TS_ASSERT_THROWS_NOTHING(default_tags=pGeometry5x3->getBasisTags()); + + } + + void testDIMIDS(){ + if(!pGeom4x2)TS_FAIL("MDGeomBasis class has not been constructed"); + if(!pGeometry5x3)TS_FAIL("MDGeomBasis class has not been constructed"); + + std::vector<MDGeometryBasis::DimensionID> dimIDs; + + + TS_ASSERT_THROWS_NOTHING(dimIDs=pGeometry5x3->getDimIDs()); + for(unsigned int i=0;i<dimIDs.size();i++){ + TS_ASSERT_EQUALS(dimIDs[i].getDimensionTag(),default_tags[i]); + if(i<3){ + TS_ASSERT_EQUALS(dimIDs[i].isReciprocal(),true); + }else{ + TS_ASSERT_EQUALS(dimIDs[i].isReciprocal(),false); + } + } + + } + void testColNumbers(void){ + std::vector<std::string> tags(3,""); + tags[0]="aa"; + tags[1]="bb"; + tags[2]="dddd"; + if(!pGeom4x2)TS_FAIL("MDGeomBasis class has not been constructed"); + + + std::vector<int> nums; + TS_ASSERT_THROWS_NOTHING(nums = pGeom4x2->getColumnNumbers(tags)); + + TS_ASSERT_EQUALS(nums[0],0); + TS_ASSERT_EQUALS(nums[1],1); + TS_ASSERT_EQUALS(nums[2],3); + + } + void testTagsCompartibility(){ + if(!pGeom4x2)TS_FAIL("MDGeomBasis class has not been constructed"); + std::vector<std::string> new_tags(4,""); + new_tags[0]="cc"; + new_tags[1]="bb"; + new_tags[2]="aa"; + new_tags[3]="dddd"; + TS_ASSERT_EQUALS(pGeom4x2->checkTagsCompartibility(new_tags),true); + new_tags[0]="q1"; + TS_ASSERT_EQUALS(pGeom4x2->checkTagsCompartibility(new_tags),false); - //TS_ASSERT_DIFFERS(ID2x4,ID3x2); } void testNDim(){ if(!pGeometry5x3)TS_FAIL("MDGeomBasis class has not been constructed"); // we have defined 5 dimension above - TS_ASSERT_EQUALS((pGeometry5x3->getNumDims()),5); + TS_ASSERT_EQUALS(pGeometry5x3->getNumDims(),5); + TS_ASSERT_EQUALS(pGeometry5x3->getNumReciprocalDims(),3); + // and 4x2 + if(!pGeom4x2)TS_FAIL("MDGeomBasis class has not been constructed"); + TS_ASSERT_EQUALS(pGeom4x2->getNumDims(),4); + TS_ASSERT_EQUALS(pGeom4x2->getNumReciprocalDims(),2); + } void testDefaultNames(){ if(!pGeometry5x3)TS_FAIL("MDGeomBasis class has not been constructed"); @@ -58,40 +132,49 @@ public: TS_ASSERT_THROWS_NOTHING(names=pGeometry5x3->getBasisTags()); // these tags are: const char *defaultTags[]={"q1","q2","q3","en","u1"}; - const char *default4x2Tags[]={"q1","q2","en","u1"}; + const char *nondef4x2Tags[]={"aa","bb","cc","dddd"}; for(int i=0;i<5;i++){ - TS_ASSERT_SAME_DATA(names[i].c_str(),defaultTags[i],2); + TS_ASSERT_EQUALS(names[i],defaultTags[i]); } TS_ASSERT_THROWS_NOTHING(names=pGeom4x2->getBasisTags()); for(int i=0;i<4;i++){ - TS_ASSERT_SAME_DATA(names[i].c_str(),default4x2Tags[i],2); + TS_ASSERT_EQUALS(names[i],nondef4x2Tags[i]); } } void testSimpleDimensionID(){ - DimensionID ID1(0,"aa",true); - DimensionID ID2(1,"bb",true); + // this class should be usually unavaile to users + MDGeometryBasis::DimensionID ID1(0,"aa",true); + MDGeometryBasis::DimensionID ID2(1,"bb",true); - TS_ASSERT_EQUALS(ID1.getDimID("bb"),-1); - TS_ASSERT_EQUALS(ID1.getDimID("aa"),0); + TS_ASSERT_EQUALS(ID1.getDimNum("bb"),-1); + TS_ASSERT_EQUALS(ID1.getDimNum("aa"),0); - TS_ASSERT_EQUALS(ID2.getDimID("blabla"),-1); - TS_ASSERT_EQUALS(ID2.getDimID("x"),-1); - TS_ASSERT_EQUALS(ID2.getDimID("bb"),1); + TS_ASSERT_EQUALS(ID2.getDimNum("blabla"),-1); + TS_ASSERT_EQUALS(ID2.getDimNum("x"),-1); + TS_ASSERT_EQUALS(ID2.getDimNum("bb"),1); + TS_ASSERT_EQUALS(ID2.getDimensionTag(),"bb"); } void testOrts0(){ if(!pGeometry5x3)TS_FAIL("MDGeomBasis class has not been constructed"); // check if we are getting proper numbers for id-s - TS_ASSERT_EQUALS((pGeometry5x3->getDimRefNum("q1")),0); + TS_ASSERT_EQUALS((pGeometry5x3->getDimNum("q1")),0); + TS_ASSERT_EQUALS((pGeometry5x3->getDimNum("u1")),4); + TS_ASSERT_EQUALS((pGeometry5x3->getDimNum("q3")),2); // this dimension does not exis in 5D workspace - TS_ASSERT_EQUALS(pGeometry5x3->getDimRefNum("u7",false),-1); - TS_ASSERT_THROWS_ANYTHING(pGeometry5x3->getDimRefNum("u7",true)); - + TS_ASSERT_EQUALS(pGeometry5x3->getDimNum("u7",false),-1); + TS_ASSERT_THROWS_ANYTHING(pGeometry5x3->getDimNum("u7",true)); + // and what about column names + TS_ASSERT_EQUALS((pGeometry5x3->getColumnName(0)),"q1"); + TS_ASSERT_EQUALS((pGeometry5x3->getColumnName(1)),"q2"); + TS_ASSERT_EQUALS((pGeometry5x3->getColumnName(3)),"en"); + TS_ASSERT_EQUALS((pGeometry5x3->getColumnName(4)),"u1"); +/*TO DO: ORTS ARE disabled for the moment // attempting to get the coordinate of an non-existing dimension - // TS_ASSERT_THROWS_ANYTHING(pGeometry5x3->getOrt("u7")); -/* + TS_ASSERT_THROWS_ANYTHING(pGeometry5x3->getOrt("u7")); + // this is 3-vector of first dimension std::vector<double> e2; // TS_ASSERT_THROWS_NOTHING(e2=pGeometry5x3->getOrt("kc")); @@ -116,24 +199,20 @@ public: if(!pGeometry5x3)TS_FAIL("MDGeomBasis class has not been constructed"); // let's try to kill old geometry and build a new one; This option should be availible inside a child class only; - std::vector<std::string>ID(4,"en"); + std::vector<std::string>Tags(4,""); // this will initiate the tags for "ereciprocal_energyn" to be a first (0) reciprocal dimension - ID[0]="reciprocal energy";ID[1]="hc_reciprocal";ID[2]="kc_rec";ID[3]="lc_orthogonal"; + Tags[0]="reciprocal energy";Tags[1]="hc_reciprocal";Tags[2]="kc_rec";Tags[3]="lc_orthogonal"; //would not work without any reciprocal dimension, one has to be present; - TS_ASSERT_THROWS_NOTHING(pGeometry5x3->reinit_GeometryBasis(ID)); + TS_ASSERT_THROWS_NOTHING(pGeometry5x3->reinit_GeometryBasis(Tags)); // WorkspaceGeometry dimensions are arranged according to their definition, - TS_ASSERT_EQUALS(pGeometry5x3->getDimRefNum("reciprocal energy"),0); - TS_ASSERT_EQUALS(pGeometry5x3->getDimRefNum("hc_reciprocal"),1); - TS_ASSERT_EQUALS(pGeometry5x3->getDimRefNum("kc_rec"),2); - TS_ASSERT_EQUALS(pGeometry5x3->getDimRefNum("lc_orthogonal"),3); - -// unsigned int id=pGeometry5x3->getWorkspaceID(); -// TS_ASSERT_DIFFERS(ID2x4,id); -// TS_ASSERT_DIFFERS(ID3x2,id); + TS_ASSERT_EQUALS(pGeometry5x3->getDimNum("reciprocal energy"),0); + TS_ASSERT_EQUALS(pGeometry5x3->getDimNum("hc_reciprocal"),1); + TS_ASSERT_EQUALS(pGeometry5x3->getDimNum("kc_rec"),2); + TS_ASSERT_EQUALS(pGeometry5x3->getDimNum("lc_orthogonal"),3); -// the techncalities of woriking with 2D+1 and 1D+1 workspaced have not been tested + TS_ASSERT_EQUALS((pGeometry5x3->getColumnName(0)),"reciprocal energy"); } testWorkspaceGm():pGeometry5x3(NULL),pGeom4x2(NULL){} diff --git a/Code/Mantid/Geometry/test/MDGeometryTest.h b/Code/Mantid/Geometry/test/MDGeometryTest.h index 2a9370cad28e0cddb5912bfbb42050e743400296..ad832d04bac443502ac3a4fde8b9990175d580f6 100644 --- a/Code/Mantid/Geometry/test/MDGeometryTest.h +++ b/Code/Mantid/Geometry/test/MDGeometryTest.h @@ -14,7 +14,7 @@ public: void reinit_Geometry(const MDGeometryDescription &slice){MDGeometry::reinit_Geometry(slice);} }; -// + class testMDGeometry : public CxxTest::TestSuite { tMDGeometry *tDND_geometry; @@ -42,7 +42,7 @@ public: MDDimension *pDim; // get pointer to the dimension 0 TS_ASSERT_THROWS_NOTHING(pDim=tDND_geometry->getDimension(0)); - TS_ASSERT_SAME_DATA(pDim->getDimensionTag().c_str(),"q1",2); + TS_ASSERT_EQUALS(pDim->getDimensionTag(),"q1"); MDDimension *pDim0; // no such dimension TS_ASSERT_THROWS_ANYTHING(pDim0=tDND_geometry->getDimension(8)); @@ -70,34 +70,80 @@ public: // and the third (2) ->el (z-axis) TS_ASSERT_THROWS_NOTHING(pSlice->setPAxis(3,"q3")); TS_ASSERT_THROWS_NOTHING(pSlice->setPAxis(2,"q3")); - // should be already there - check reinsertion; - TS_ASSERT_THROWS_NOTHING(pSlice->setPAxis(3,"q2")); + + TS_ASSERT_THROWS_NOTHING(pSlice->setPAxis(3,"q1")); - std::vector<std::string> names = pSlice->getAxisTags(); + std::vector<std::string> names = pSlice->getDimensionsTags(); for(unsigned int i=0;i<names.size();i++){ - TS_ASSERT_SAME_DATA(names[i].c_str(),pSlice->getAxisName(i).c_str(),2); + TS_ASSERT_EQUALS(names[i],pSlice->getTag(i)); + TS_ASSERT_EQUALS(names[i],pSlice->getAxisName(i)); } } - void testMDGeomSetFromSlice(void){ + void testMDGeomSetFromSlice1(void){ TS_ASSERT_THROWS_NOTHING(tDND_geometry->setRanges(*pSlice)); -/* + unsigned int i,ic; + + MDDimension *pDim; + + std::vector<std::string> expanded_tags(tDND_geometry->getNumDims()); + + // arrange dimensions tags like the dimensions are arranged in the geometry + ic=0; + TS_ASSERT_THROWS_NOTHING( + for(i=0;i<expanded_tags.size();i++){ + if(pSlice->numBins(i)>1){ // non-integrated; + expanded_tags[ic]=pSlice->getTag(i); + ic++; + } + } + for(i=0;i<expanded_tags.size();i++){ + if(pSlice->numBins(i)<2){ // non-integrated; + expanded_tags[ic]=pSlice->getTag(i); + ic++; + } + } + ) + + + + for(i=0;i<tDND_geometry->getNumDims();i++){ + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(i)); + TS_ASSERT_EQUALS(pDim->getDimensionTag(),expanded_tags[i]); + } + + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(0)); + TS_ASSERT_EQUALS(pDim->getStride(),1); + + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(1)); + TS_ASSERT_EQUALS(pDim->getStride(),100); + TS_ASSERT_EQUALS(pDim->getIntegrated(),false); + + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(2)); + TS_ASSERT_EQUALS(pDim->getStride(),0); + TS_ASSERT_EQUALS(pDim->getIntegrated(),true); + } + void testMDGeomSetFromSlice2(void){ + // this should be fully equivalent to 1 + // arrange final dimensions according to pAxis, this will run through one branch of reinit_Geometry only TS_ASSERT_THROWS_NOTHING(tDND_geometry->reinit_Geometry(*pSlice)); MDDimension *pDim; + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(0)); - TS_ASSERT_SAME_DATA(pDim->getDimensionTag().c_str(),pSlice->getAxisName(0).c_str(),2); + TS_ASSERT_EQUALS(pDim->getStride(),1); + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(1)); - TS_ASSERT_SAME_DATA(pDim->getDimensionTag().c_str(),pSlice->getAxisName(1).c_str(),2); + TS_ASSERT_EQUALS(pDim->getStride(),100); + TS_ASSERT_EQUALS(pDim->getIntegrated(),false); + TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(2)); - TS_ASSERT_SAME_DATA(pDim->getDimensionTag().c_str(),pSlice->getAxisName(2).c_str(),2); - TS_ASSERT_THROWS_NOTHING(pDim = tDND_geometry->getDimension(3)); - TS_ASSERT_SAME_DATA(pDim->getDimensionTag().c_str(),pSlice->getAxisName(3).c_str(),2); -*/ + TS_ASSERT_EQUALS(pDim->getStride(),0); + TS_ASSERT_EQUALS(pDim->getIntegrated(),true); } - + testMDGeometry(void):tDND_geometry(NULL),pSlice(NULL){}; ~testMDGeometry(void){ diff --git a/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj b/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj index 875e087eda6c2cd74ac4f39a42d9143aec7940d7..2768a64fb5756310552d2286bde58b8629df7798 100644 --- a/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj +++ b/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj @@ -20,8 +20,8 @@ </ItemGroup> <ItemGroup> <CustomBuild Include="MDGeometryBasisTest.h"> - <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> - <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building test: %(Filename)</Message> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --runner=ParenPrinter -o "%(Filename).cpp" "%(FullPath)"</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building test for: %(Filename)</Message> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp</Outputs> <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --runner=ParenPrinter -o "%(Filename).cpp" "%(FullPath)"</Command> <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building test: %(Filename)</Message> @@ -35,15 +35,15 @@ </CustomBuild> </ItemGroup> <ItemGroup> - <CustomBuild Include="MDGeometryTest.h"> - <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building test: %(Filename)</Message> - <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building test: %(Filename)</Message> - <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Building test: %(Filename)</Message> - <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building test: %(Filename)</Message> + <CustomBuild Include="MDDimensionTest.h"> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building test for: %(Filename)</Message> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp</Outputs> @@ -51,16 +51,42 @@ </CustomBuild> </ItemGroup> <ItemGroup> - <CustomBuild Include="MDDimensionTest.h"> - <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --runner=ParenPrinter -o "%(Filename).cpp" "%(FullPath)"</Command> - <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">building test for: %(Filename)</Message> + <ClCompile Include="MDDimensionTest.cpp" /> + <ClCompile Include="MDGeometryBasisTest.cpp" /> + <ClCompile Include="MDGeometryDescriptionTest.cpp" /> + <ClCompile Include="MDGeometryTest.cpp" /> + </ItemGroup> + <ItemGroup> + <CustomBuild Include="MDGeometryTest.h"> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building test for: %(Filename)</Message> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp</Outputs> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp</Outputs> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp</Outputs> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp</Outputs> </CustomBuild> </ItemGroup> <ItemGroup> - <ClCompile Include="MDDimensionTest.cpp" /> - <ClCompile Include="MDGeometryBasisTest.cpp" /> - <ClCompile Include="MDGeometryTest.cpp" /> + <CustomBuild Include="MDGeometryDescriptionTest.h"> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">c:\Mantid\Code\Third_Party\src\cxxtest\cxxtestgen.py --part -o "%(Filename).cpp" "%(FullPath)"</Command> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Building test for: %(Filename)</Message> + <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building test for: %(Filename)</Message> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp</Outputs> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp</Outputs> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp</Outputs> + <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp</Outputs> + </CustomBuild> </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>{8D1C3555-5A0F-48E0-95E3-DFEB025DE53F}</ProjectGuid> diff --git a/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj.filters b/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj.filters index da08fe17723cbba2630979ea08a6235fe6087ed9..4e1ad201bd19011984f10d41bc97bc4e55a1ecdc 100644 --- a/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj.filters +++ b/Code/Mantid/Geometry/test/MDGeometryTest.vcxproj.filters @@ -18,10 +18,13 @@ <CustomBuild Include="MDGeometryBasisTest.h"> <Filter>Header Files</Filter> </CustomBuild> + <CustomBuild Include="MDDimensionTest.h"> + <Filter>Header Files</Filter> + </CustomBuild> <CustomBuild Include="MDGeometryTest.h"> <Filter>Header Files</Filter> </CustomBuild> - <CustomBuild Include="MDDimensionTest.h"> + <CustomBuild Include="MDGeometryDescriptionTest.h"> <Filter>Header Files</Filter> </CustomBuild> </ItemGroup> @@ -35,5 +38,8 @@ <ClCompile Include="MDGeometryTest.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="MDGeometryDescriptionTest.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/Code/Mantid/Kernel/src/ConfigService.cpp b/Code/Mantid/Kernel/src/ConfigService.cpp index 7b450a1c8fe2ec11d53b4e3f5f946a598283b3a7..cd778f343d37cdcbda3c3721195327461d23bffa 100644 --- a/Code/Mantid/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Kernel/src/ConfigService.cpp @@ -918,7 +918,7 @@ void ConfigServiceImpl::updateFacilities(const std::string& fName) pDoc->release(); } -/** Get the default facility +/** Get the default ` */ const FacilityInfo& ConfigServiceImpl::Facility() const { diff --git a/Code/Mantid/MDAlgorithms/inc/MantidMDAlgorithms/CenterpieceRebinning.h b/Code/Mantid/MDAlgorithms/inc/MantidMDAlgorithms/CenterpieceRebinning.h index 902f7e5288588a1cb6fe244d75b87fd0c438a8de..56165792d72b6851673400be698e437f8397ea76 100644 --- a/Code/Mantid/MDAlgorithms/inc/MantidMDAlgorithms/CenterpieceRebinning.h +++ b/Code/Mantid/MDAlgorithms/inc/MantidMDAlgorithms/CenterpieceRebinning.h @@ -47,7 +47,7 @@ private: bool ignore_nan,ignore_inf; // function builds the vector of cell indexes which can contribute into the cut, described by the transformation matrix supplied; - void preselect_cells(std::vector<long> &selected_cells,long &n_preselected_pix); + // void preselect_cells(std::vector<long> &selected_cells,long &n_preselected_pix); /*! function returns the list of the cell numbers which can contribute into the cut described by transformation matrix @@ -77,7 +77,7 @@ private: * @param nPix number of points in the buffer * @param *data the pointer to the structure with Image data; */ - size_t rebin_dataset4D(const MDDataObjects::transf_matrix &rescaled_transf, const MDDataObjects::sqw_pixel *source_pix, size_t nPix, MDDataObjects::MD_image_point *data, + size_t rebin_dataset4D(const MDDataObjects::transf_matrix &rescaled_transf, const std::vector<size_t> &strides,const MDDataObjects::sqw_pixel *source_pix, size_t nPix, MDDataObjects::MD_image_point *data, double boxMin[],double boxMax[]); // finalsizes rebinoing operations; e.g. calculates averages and calculates location of pixels (filesystem) size_t finalise_rebinning(MDDataObjects::MD_image_point *data,size_t data_size); diff --git a/Code/Mantid/MDAlgorithms/src/CenterpieceRebinning.cpp b/Code/Mantid/MDAlgorithms/src/CenterpieceRebinning.cpp index ed7dcadb9e0018d500186dea63a0a498bf79daf3..6712bcdee0a38706915f4c6a103ad5730bbb6794 100644 --- a/Code/Mantid/MDAlgorithms/src/CenterpieceRebinning.cpp +++ b/Code/Mantid/MDAlgorithms/src/CenterpieceRebinning.cpp @@ -152,15 +152,16 @@ CenterpieceRebinning::exec() double boxMin[4],boxMax[4]; boxMin[0]=boxMin[1]=boxMin[2]=boxMin[3]=FLT_MAX; boxMax[0]=boxMax[1]=boxMax[2]=boxMax[3]=FLT_MIN; + std::vector<size_t> strides = outputWS->getStrides(); transf_matrix trf = this->build_scaled_transformation_matrix(*inputWS,*pSlicing); // start reading and rebinning; size_t n_starting_cell(0); - for(unsigned int i=0;i<1;i++){ + for(unsigned int i=0;i<n_hits;i++){ n_starting_cell+=inputWS->read_pix_selection(preselected_cells_indexes,n_starting_cell,pix_buf,pix_buffer_size,n_pix_in_buffer); n_pixels_read +=n_pix_in_buffer; - n_pixels_selected+=this->rebin_dataset4D(trf,&pix_buf[0],n_pix_in_buffer,pImage,boxMin,boxMax); + n_pixels_selected+=this->rebin_dataset4D(trf,strides,&pix_buf[0],n_pix_in_buffer,pImage,boxMin,boxMax); } this->finalise_rebinning(pImage,image_size); @@ -212,7 +213,7 @@ CenterpieceRebinning::build_scaled_transformation_matrix(const Geometry::MDGeome trf.cut_min.assign(nDims,-1); trf.cut_max.assign(nDims,1); trf.axis_step.assign(nDims,1); - trf.stride.assign(nDims,0); + // trf.stride.assign(nDims,0); MDDimension *pDim(NULL); // for convenience can use dimension accessors from source @@ -223,7 +224,7 @@ CenterpieceRebinning::build_scaled_transformation_matrix(const Geometry::MDGeome trf.axis_step[i]=(target.cutMax(i)-target.cutMin(i))/target.numBins(i); trf.cut_max[i] = target.cutMax(i)/trf.axis_step[i]; trf.cut_min[i] = target.cutMin(i)/trf.axis_step[i]; - trf.stride[i] = target.getStride(i); + // trf.stride[i] = target.getStride(i); } std::vector<double> rot = target.getRotations(); std::vector<double> basis[3]; // not used at the momemnt; @@ -428,7 +429,7 @@ CenterpieceRebinning::preselect_cells(const MDDataObjects::MDData &Source, const } // size_t -CenterpieceRebinning::rebin_dataset4D(const transf_matrix &rescaled_transf, const sqw_pixel *source_pix, size_t nPix,MDDataObjects::MD_image_point *data, double boxMin[],double boxMax[]) +CenterpieceRebinning::rebin_dataset4D(const transf_matrix &rescaled_transf,const std::vector<size_t> &stride, const sqw_pixel *source_pix, size_t nPix,MDDataObjects::MD_image_point *data, double boxMin[],double boxMax[]) { // set up auxiliary variables and preprocess them. double xt,yt,zt,xt1,yt1,zt1,Et,Inf(0), @@ -463,9 +464,10 @@ int num_OMP_Threads(1); bool keep_pixels(false); //int nRealThreads; + size_t i,indl; int indX,indY,indZ,indE; -size_t nDimX(rescaled_transf.stride[0]),nDimY(rescaled_transf.stride[1]),nDimZ(rescaled_transf.stride[2]),nDimE(rescaled_transf.stride[3]); // reduction dimensions; if 0, the dimension is reduced; +size_t nDimX(stride[0]),nDimY(stride[1]),nDimZ(stride[2]),nDimE(stride[3]); // reduction dimensions; if 0, the dimension is reduced; // min-max value initialization diff --git a/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDData.h b/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDData.h index 35a5c96aa91b9d00deb4de2396f7d0637d701b2c..79212a78619e4c46f8e51d07b451cfad491f2e3d 100644 --- a/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDData.h +++ b/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDData.h @@ -69,6 +69,8 @@ public: void getPointData(std::vector<point3D> & image_data)const; /// returns the size of the Image array as 1D array; size_t getDataSize(void)const{return data_size;} + /// returns dimension strides e.g. the changes of a position in 1D array when an M-th dimension index changes by 1; + std::vector<size_t> getStrides(void)const; //****************************************************************************************************** // IMD workspace interface functions /// return ID specifying the workspace kind diff --git a/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDPixels.h b/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDPixels.h index 79527c9ab67097f42573b9e7b9bc5137d6826f11..bc17a22d22aad7f714ded550b3f52f8594d2e90c 100644 --- a/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDPixels.h +++ b/Code/Mantid/MDDataObjects/inc/MDDataObjects/MDPixels.h @@ -65,7 +65,7 @@ public: std::vector<double> cut_min; // min limits to extract data; std::vector<double> cut_max; // max limits to extract data; std::vector<double> axis_step; // (cut_max-cut_min)/(nBins); - std::vector<size_t> stride; + //std::vector<size_t> stride; }; // diff --git a/Code/Mantid/MDDataObjects/src/CenterpieceRebinning.cpp b/Code/Mantid/MDDataObjects/src/CenterpieceRebinning.cpp deleted file mode 100644 index c541c0f3866f9c72bf37d648900758a02fed0a12..0000000000000000000000000000000000000000 --- a/Code/Mantid/MDDataObjects/src/CenterpieceRebinning.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "stdafx.h" -#include "CenterpieceRebinning.h" - -void -CenterpieceRebinning::build_transformation_matrix() -{ - - this->trans_bott_left.resize(this->nDims); - this->cut_min.resize(this->nDims); - this->cut_max.resize(this->nDims); -/* - int i,j,ic; - for(i=0;i<this->nDims;i++){ - ///if( - //transform data limits into integer length along each axis selected; - if(this->dim_sizes[i]==0){ // if axis is a reduction axis, we do not rescale in this direction -> - // its limits equal to cut-off limits but axis_step should be 1 ; - Axis[i]->push_back(trf.cut_min[i]); - Axis[i]->push_back(trf.cut_max[i]); - axis_step[i]= 1; - }else{ // all limits are rescaled into ints along the axis otherwise; - axis_step[i] =(trf.cut_max[i]-trf.cut_min[i])/this->dim_sizes[i]; - for(j=0;j<=this->dim_sizes[i];j++){ - Axis[i]->push_back(trf.cut_min[i]+i*axis_step[i]); - } - } - shifts[i] =trf.trans_bott_left[i]; - min_limit[i] =trf.cut_min[i]/axis_step[i]; - max_limit[i] =trf.cut_max[i]/axis_step[i]; - } - for(i=0;i<3;i++){ - ic = i*3; - for(j=0;j<3;j++){ - rotations[i+j*3]=trf.rotations[i+j*3]/axis_step[i]; - } - } - - unsigned int i; - SlicingData tt; - for(i=0;i<this->n_total_dim;i++){ - this->theDimension[i]->setRange(trf.cutMin(i),trf.cut_max(i),trf.numBins(i)); - if(trf.isAxisNamePresent(i)){ - this->theDimension[i]->setName(trf.AxisName(i)); - } - } -*/ -} -CenterpieceRebinning::CenterpieceRebinning(const SQW &orig,const SlicingData &tansformation): -origin(&orig), -trf(&tansformation), -nDims(trf->getNumDims()) -{ - if(origin->getNumDims()!=trf->getNumDims()){ - throw(errorMantid("CenterpieceRebinning::CenterpieceRebinning: dimensions of the rebinning request do not equal to the dimensions of the original dataset")); - } - this->build_transformation_matrix(); -} - -CenterpieceRebinning::~CenterpieceRebinning(void) -{ -} diff --git a/Code/Mantid/MDDataObjects/src/MDData.cpp b/Code/Mantid/MDDataObjects/src/MDData.cpp index f4cf59d1592fc474706fe620441e341d944a4f78..74927837cc6bebfc3f1d9e2f826e7da5cbaf46ac 100644 --- a/Code/Mantid/MDDataObjects/src/MDData.cpp +++ b/Code/Mantid/MDDataObjects/src/MDData.cpp @@ -279,6 +279,18 @@ MDData::~MDData() { this->clear_class(); } + +std::vector<size_t> +MDData::getStrides(void)const +{ + unsigned int nDims = this->getNumDims(); + std::vector<size_t> strides(nDims,0); + for(unsigned int i=0;i<nDims;i++){ + strides[i] = this->getDimension(i)->getStride(); + } + return strides; + +} // void MDData::identify_SP_points_locations()