From 5f5e795855a1d9c7a00164295199a5ed10ebdb7c Mon Sep 17 00:00:00 2001 From: Janik Zikovsky <zikovskyjl@ornl.gov> Date: Mon, 29 Aug 2011 19:02:33 +0000 Subject: [PATCH] Refs #3638 --- .../MantidMDEvents/BinToMDHistoWorkspace.h | 9 ++- .../MDEvents/src/BinToMDHistoWorkspace.cpp | 55 ++++++++++++++----- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/BinToMDHistoWorkspace.h b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/BinToMDHistoWorkspace.h index 4c010ef995f..79e16e25c7f 100644 --- a/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/BinToMDHistoWorkspace.h +++ b/Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/BinToMDHistoWorkspace.h @@ -12,6 +12,7 @@ #include "MantidMDEvents/MDHistoWorkspace.h" #include "MantidMDEvents/MDBox.h" #include "MantidAPI/IMDEventWorkspace.h" +#include "MantidGeometry/MDGeometry/MDImplicitFunction.h" using Mantid::API::IMDEventWorkspace_sptr; @@ -59,6 +60,9 @@ namespace MDEvents void checkBinDimensions(); void createAlignedTransform(); + template<typename MDE, size_t nd> + Mantid::Geometry::MDImplicitFunction * getImplicitFunctionForChunk(typename MDEventWorkspace<MDE, nd>::sptr ws, size_t * chunkMin, size_t * chunkMax); + /// Helper method template<typename MDE, size_t nd> void do_centerpointBin(typename MDEventWorkspace<MDE, nd>::sptr ws); @@ -87,9 +91,12 @@ namespace MDEvents /// Index of the dimension in the MDEW for the dimension in the output. std::vector<size_t> dimensionToBinFrom; - /// Do we perform a coordinate transformation? NULL if no. + /// Coordinate transformation to apply CoordTransform * m_transform; + /// Set to true if the cut is aligned with the axes + bool m_axisAligned; + /// Number of dimensions in the output (binned) workspace. size_t outD; diff --git a/Code/Mantid/Framework/MDEvents/src/BinToMDHistoWorkspace.cpp b/Code/Mantid/Framework/MDEvents/src/BinToMDHistoWorkspace.cpp index 3a72199113c..5ce5336258a 100644 --- a/Code/Mantid/Framework/MDEvents/src/BinToMDHistoWorkspace.cpp +++ b/Code/Mantid/Framework/MDEvents/src/BinToMDHistoWorkspace.cpp @@ -284,6 +284,43 @@ namespace MDEvents } + //---------------------------------------------------------------------------------------------- + /** Create an implicit function for picking boxes, based on the indexes in the + * output MDHistoWorkspace. + * This needs to be in the space of the INPUT MDEventWorkspace + * + * @param chunkMin :: the minimum index in each dimension to consider "valid" (inclusive) + * @param chunkMax :: the maximum index in each dimension to consider "valid" (exclusive) + * @return MDImplicitFunction + */ + template<typename MDE, size_t nd> + MDImplicitFunction * BinToMDHistoWorkspace::getImplicitFunctionForChunk(typename MDEventWorkspace<MDE, nd>::sptr ws, + size_t * chunkMin, size_t * chunkMax) + { + UNUSED_ARG(ws); + + if (m_axisAligned) + { + std::vector<coord_t> function_min(nd, -1e50); // default to all space if the dimension is not specified + std::vector<coord_t> function_max(nd, +1e50); // default to all space if the dimension is not specified + for (size_t bd=0; bd<outD; bd++) + { + // Dimension in the MDEventWorkspace + size_t d = dimensionToBinFrom[bd]; + function_min[d] = binDimensions[bd]->getX(chunkMin[bd]); + function_max[d] = binDimensions[bd]->getX(chunkMax[bd]); + } + MDBoxImplicitFunction * function = new MDBoxImplicitFunction(function_min, function_max); + return function; + } + else + { + // General implicit function + // TODO: Apply the transform! + return new MDImplicitFunction; + } + } + //---------------------------------------------------------------------------------------------- /** Perform binning by iterating through every event and placing them in the output workspace * @@ -326,7 +363,7 @@ namespace MDEvents // Run the chunks in parallel. There is no overlap in the output workspace so it is // thread safe to write to it.. - //PRAGMA_OMP( parallel for schedule(dynamic,1) if (doParallel) ) + PRAGMA_OMP( parallel for schedule(dynamic,1) if (doParallel) ) for(int chunk=0; chunk < int(binDimensions[chunkDimension]->getNBins()); chunk += chunkNumBins) { // Region of interest for this chunk. @@ -346,24 +383,13 @@ namespace MDEvents chunkMax[chunkDimension] = size_t(chunk+chunkNumBins); // Build an implicit function (it needs to be in the space of the MDEventWorkspace) - // TODO: Apply the transform! - std::vector<coord_t> function_min(nd, -1e50); // default to all space if the dimension is not specified - std::vector<coord_t> function_max(nd, +1e50); // default to all space if the dimension is not specified - for (size_t bd=0; bd<outD; bd++) - { - // Dimension in the MDEventWorkspace - size_t d = dimensionToBinFrom[bd]; - function_min[d] = binDimensions[bd]->getX(chunkMin[bd]); - function_max[d] = binDimensions[bd]->getX(chunkMax[bd]); - } - MDBoxImplicitFunction * function = new MDBoxImplicitFunction(function_min, function_max); + MDImplicitFunction * function = this->getImplicitFunctionForChunk<MDE,nd>(ws, chunkMin, chunkMax); // Use getBoxes() to get an array with a pointer to each box std::vector<IMDBox<MDE,nd>*> boxes; // Leaf-only; no depth limit; with the implicit function passed to it. ws->getBox()->getBoxes(boxes, 1000, true, function); - // For progress reporting, the # of boxes if (prog) { @@ -601,14 +627,15 @@ namespace MDEvents Poco::XML::Element* pRootElem = pDoc->documentElement(); CoordTransformAffineParser parser; m_transform = parser.createTransform(pRootElem); + m_axisAligned = false; } else { // Make an aligned transform out of the parameters this->createAlignedTransform(); + m_axisAligned = true; } - prog = new Progress(this, 0, 1.0, 1); // This gets deleted by the thread pool; don't delete it in here. // Create the dense histogram. This allocates the memory -- GitLab