Skip to content

Commit

Permalink
Refs #7728. Adding logic to sort boxes once.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reuter committed Aug 12, 2013
1 parent 77ffb44 commit 89af600
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MANTID_VATES_vtkSplatterPlotFactory_H_

#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidAPI/IMDNode.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDEventWorkspace.h"
#include "MantidVatesAPI/ThresholdRange.h"
Expand Down Expand Up @@ -95,6 +96,12 @@ class DLLExport vtkSplatterPlotFactory : public vtkDataSetFactory
/// Size of the initial portion of the sorted list of boxes to use.
double m_percentToUse;

/// Flag indicating whether or not the sorted list must be built
mutable bool m_buildSortedList;

/// Save name of current workspace so we can re-sort if it changes
mutable std::string m_wsName;

/// Data set that will be generated
mutable vtkDataSet *dataSet;

Expand All @@ -106,6 +113,11 @@ class DLLExport vtkSplatterPlotFactory : public vtkDataSetFactory

/// Implicit function to define which boxes to render.
mutable Mantid::Geometry::MDImplicitFunction *sliceImplicitFunction;

/// Variable to hold sorted list, so sort doesn't have to be repeated
mutable std::vector< Mantid::API::IMDNode * > m_sortedBoxes;


};

}
Expand Down
59 changes: 33 additions & 26 deletions Code/Mantid/Vates/VatesAPI/src/vtkSplatterPlotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace VATES
*/
vtkSplatterPlotFactory::vtkSplatterPlotFactory(ThresholdRange_scptr thresholdRange, const std::string& scalarName, const size_t numPoints, const double percentToUse ) :
m_thresholdRange(thresholdRange), m_scalarName(scalarName),
m_numPoints(numPoints), m_percentToUse(percentToUse)
m_numPoints(numPoints), m_percentToUse(percentToUse),
m_buildSortedList(true), m_wsName("")
{
}

Expand Down Expand Up @@ -111,50 +112,56 @@ namespace VATES
std::cout << tim << " to retrieve the "<< boxes.size() << " boxes down."<< std::endl;
}

// get list of boxes with signal > 0 and sort
// the list in order of decreasing signal
std::vector< MDBox<MDE,nd> * > sorted_boxes;
sorted_boxes.reserve( 100000 );
for (size_t i = 0; i < boxes.size(); i++)
std::string new_name = ws->getName();
if (new_name != m_wsName || m_buildSortedList)
{
MDBox<MDE,nd> * box = dynamic_cast<MDBox<MDE,nd> *>(boxes[i]);
if (box)
m_wsName = new_name;
m_buildSortedList = false;
m_sortedBoxes.clear();
// get list of boxes with signal > 0 and sort
// the list in order of decreasing signal
for (size_t i = 0; i < boxes.size(); i++)
{
size_t newPoints = box->getNPoints();
if (newPoints > 0)
MDBox<MDE,nd> * box = dynamic_cast<MDBox<MDE,nd> *>(boxes[i]);
if (box)
{
sorted_boxes.push_back(box);
size_t newPoints = box->getNPoints();
if (newPoints > 0)
{
m_sortedBoxes.push_back(box);
}
}
}
}

if (VERBOSE)
{
std::cout << "START SORTING" << std::endl;
}
std::sort(sorted_boxes.begin(), sorted_boxes.end(), CompareNormalizedSignal);
if (VERBOSE)
{
std::cout << "DONE SORTING" << std::endl;
if (VERBOSE)
{
std::cout << "START SORTING" << std::endl;
}
std::sort(m_sortedBoxes.begin(), m_sortedBoxes.end(),
CompareNormalizedSignal);
if (VERBOSE)
{
std::cout << "DONE SORTING" << std::endl;
}
}

size_t num_boxes_to_use = static_cast<size_t>(percent_to_use * static_cast<double>(sorted_boxes.size()) / 100.0);
size_t num_boxes_to_use = static_cast<size_t>(percent_to_use * static_cast<double>(m_sortedBoxes.size()) / 100.0);
if (num_boxes_to_use <= 0)
{
num_boxes_to_use = 1;
}

if (num_boxes_to_use >= sorted_boxes.size())
if (num_boxes_to_use >= m_sortedBoxes.size())
{
num_boxes_to_use = sorted_boxes.size()-1;
num_boxes_to_use = m_sortedBoxes.size()-1;
}

// restrict the number of points to the
// number of points in boxes being used
size_t total_points_available = 0;
for (size_t i = 0; i < num_boxes_to_use; i++)
{
size_t newPoints = sorted_boxes[i]->getNPoints();
size_t newPoints = m_sortedBoxes[i]->getNPoints();
total_points_available += newPoints;
}

Expand All @@ -179,7 +186,7 @@ namespace VATES
{
std::cout << "numPoints = " << numPoints << std::endl;
std::cout << "num boxes in all = " << boxes.size() << std::endl;
std::cout << "num boxes above zero = " << sorted_boxes.size() << std::endl;
std::cout << "num boxes above zero = " << m_sortedBoxes.size() << std::endl;
std::cout << "num boxes to use = " << num_boxes_to_use << std::endl;
std::cout << "total_points_available = " << total_points_available << std::endl;
std::cout << "points needed per box = " << points_per_box << std::endl;
Expand All @@ -205,7 +212,7 @@ namespace VATES
bool done = false;
while (box_index < num_boxes_to_use && !done)
{
MDBox<MDE,nd> *box = sorted_boxes[box_index];
MDBox<MDE,nd> *box = dynamic_cast<MDBox<MDE,nd> *>(m_sortedBoxes[box_index]);
box_index++;
float signal_normalized = float(box->getSignalNormalized());
size_t newPoints = box->getNPoints();
Expand Down

0 comments on commit 89af600

Please sign in to comment.