Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for region labels to egs_kerma #1235

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions HEN_HOUSE/egs++/egs_base_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void EGS_BaseGeometry::getNumberRegions(const string &str, vector<int> &regs) {
}
}

void EGS_BaseGeometry::getLabelRegions(const string &str, vector<int> &regs) {
void EGS_BaseGeometry::getLabelRegions(const string &str, vector<int> &regs, bool sanitize) {

// Tokenize the input string - this allows for multiple labels
vector<string> tokens;
Expand All @@ -1080,18 +1080,40 @@ void EGS_BaseGeometry::getLabelRegions(const string &str, vector<int> &regs) {
}
while (*ptr++ != '\0');

// Start insertion at the beginning of regs
size_t insert_pos = 0;
bool foundLabel;

// Get all regions lists for this named label
for (int j=0; j<tokens.size(); j++) {
for (int i=0; i<labels.size(); i++) {
for (int j = 0; j < tokens.size(); j++) {
foundLabel = false;
for (int i = 0; i < labels.size(); i++) {
if (labels[i].name.compare(tokens[j]) == 0) {
regs.insert(regs.end(), labels[i].regions.begin(), labels[i].regions.end());

// Insert at the current position
regs.insert(regs.begin() + insert_pos, labels[i].regions.begin(), labels[i].regions.end());

// Update the insertion position to reflect the newly added elements
insert_pos += labels[i].regions.size();

foundLabel = true;
break;
}
}

// Just increment the insertion position by one, because this token was a number not a label
if(!foundLabel) {
insert_pos += 1;
}
}

// Sort region list and remove duplicates
sort(regs.begin(), regs.end());
regs.erase(unique(regs.begin(), regs.end()), regs.end());
// By default this is always done
// Turn it off if the list contains parameters that are not regions and/or you want to maintain the original order
if(sanitize) {
sort(regs.begin(), regs.end());
regs.erase(unique(regs.begin(), regs.end()), regs.end());
}
}


Expand Down
2 changes: 1 addition & 1 deletion HEN_HOUSE/egs++/egs_base_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ class EGS_EXPORT EGS_BaseGeometry {
virtual void getNumberRegions(const string &str, vector<int> &regs);

/*! \brief Get the list of all regions labeled with \a str */
virtual void getLabelRegions(const string &str, vector<int> &regs);
virtual void getLabelRegions(const string &str, vector<int> &regs, bool sanitize=true);

/*! \brief Get the name of the i-th explicit label in the geometry */
virtual const string &getLabelName(const int i) {
Expand Down
Loading