Skip to content

Commit

Permalink
refs #9194. Remove need for std::find.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Mar 31, 2014
1 parent 41405e6 commit 3473739
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Expand Up @@ -71,7 +71,11 @@ namespace Crystal
/// Get the number of threads to use.
int getNThreads() const;
/// Calculate the disjoint element tree across the image.
void calculateDisjointTree(Mantid::API::IMDHistoWorkspace_sptr ws, BackgroundStrategy * const strategy, std::vector<DisjointElement>& neighbourElements) const;
void calculateDisjointTree(Mantid::API::IMDHistoWorkspace_sptr ws,
BackgroundStrategy * const strategy, std::vector<DisjointElement>& neighbourElements,
ConnectedComponentMappingTypes::LabelIdIntensityMap& labelMap,
ConnectedComponentMappingTypes::PositionToLabelIdMap& positionLabelMap) const;

/// Start labeling index
size_t m_startId;
/// Run multithreaded
Expand Down
35 changes: 17 additions & 18 deletions Code/Mantid/Framework/Crystal/src/ConnectedComponentLabeling.cpp
Expand Up @@ -90,7 +90,11 @@ namespace Mantid
return m_runMultiThreaded ? API::FrameworkManager::Instance().getNumOMPThreads() : 1;
}

void ConnectedComponentLabeling::calculateDisjointTree(IMDHistoWorkspace_sptr ws, BackgroundStrategy * const strategy, VecElements& neighbourElements) const
void ConnectedComponentLabeling::calculateDisjointTree(IMDHistoWorkspace_sptr ws,
BackgroundStrategy * const strategy, VecElements& neighbourElements,
LabelIdIntensityMap& labelMap,
PositionToLabelIdMap& positionLabelMap
) const
{

VecIndexes allNonBackgroundIndexes;
Expand Down Expand Up @@ -168,6 +172,9 @@ namespace Mantid
if (nonEmptyNeighbourIndexes.empty())
{
neighbourElements[currentIndex] = DisjointElement(static_cast<int>(currentLabelCount)); // New leaf
labelMap[currentLabelCount] = 0; // Pre-fill the currentlabelcount.
const VMD& center = iterator->getCenter();
positionLabelMap[V3D(center[0], center[1], center[2])] = currentLabelCount; // Get the position at this label.
++currentLabelCount;
}
else if (neighbourIds.size() == 1) // Do we have a single unique id amongst all neighbours.
Expand Down Expand Up @@ -211,7 +218,9 @@ namespace Mantid
VecElements neighbourElements(ws->getNPoints());

// Perform the bulk of the connected component analysis, but don't collapse the elements yet.
calculateDisjointTree(ws, strategy, neighbourElements);
LabelIdIntensityMap labelMap; // This will not get used.
PositionToLabelIdMap positionLabelMap; // This will not get used.
calculateDisjointTree(ws, strategy, neighbourElements, labelMap, positionLabelMap);

// Create the output workspace from the input workspace
IMDHistoWorkspace_sptr outWS = cloneInputWorkspace(ws);
Expand Down Expand Up @@ -242,7 +251,7 @@ namespace Mantid
VecElements neighbourElements(ws->getNPoints());

// Perform the bulk of the connected component analysis, but don't collapse the elements yet.
calculateDisjointTree(ws, strategy, neighbourElements);
calculateDisjointTree(ws, strategy, neighbourElements, labelMap, positionLabelMap);

// Create the output workspace from the input workspace
IMDHistoWorkspace_sptr outWS = cloneInputWorkspace(ws);
Expand All @@ -259,27 +268,17 @@ namespace Mantid
// Set the output cluster workspace signal value
outWS->setSignalAt(i, labelId);

if(labelMap.find(labelId) != labelMap.end()) // Have we already started integrating over this label
{
SignalErrorSQPair current = labelMap[labelId];
// Sum labels. This is integration!
labelMap[labelId] = SignalErrorSQPair(current.get<0>() + signal, current.get<1>() + errorSQ);
}
else // This label is unknown to us.
{
labelMap[labelId] = SignalErrorSQPair(signal, errorSQ);

const VMD& center = ws->getCenter(i);
V3D temp(center[0], center[1], center[2]);
positionLabelMap[temp] = labelId; //Record charcteristic position of the cluster.
}
SignalErrorSQPair current = labelMap[labelId];
// Sum labels. This is integration!
labelMap[labelId] = SignalErrorSQPair(current.get<0>() + signal, current.get<1>() + errorSQ);

outWS->setSignalAt(i, neighbourElements[i].getRoot());
}
else
{
outWS->setSignalAt(i, 0);
outWS->setErrorSquaredAt(i, 0);
}
outWS->setErrorSquaredAt(i, 0);
}

return outWS;
Expand Down

0 comments on commit 3473739

Please sign in to comment.