-
Notifications
You must be signed in to change notification settings - Fork 458
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
ENH: Allow for custom presets prefix and tooltips #1052
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,17 +339,8 @@ bool vtkMRMLSliceNode::MatrixAreEqual(const vtkMatrix4x4 *matrix, | |
//---------------------------------------------------------------------------- | ||
vtkMatrix3x3 *vtkMRMLSliceNode::GetSliceOrientationPreset(const std::string &name) | ||
{ | ||
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
{ | ||
if (it->first == name) | ||
{ | ||
return it->second; | ||
} | ||
} | ||
|
||
vtkErrorMacro("GetSliceOrientationPreset: invalid orientation preset name: " << name); | ||
return NULL; | ||
OrientationPresetType* preset = this->GetOrientationPreset(name); | ||
return preset ? preset->Orientation : nullptr; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
|
@@ -366,11 +357,9 @@ std::string vtkMRMLSliceNode::GetSliceOrientationPresetName(vtkMatrix3x3* orient | |
it != this->OrientationMatrices.rend(); | ||
++it) | ||
{ | ||
std::string presetName = it->first; | ||
vtkMatrix3x3* presetOrientationMatrix = this->GetSliceOrientationPreset(presetName); | ||
if (vtkAddonMathUtilities::MatrixAreEqual(orientationMatrix, presetOrientationMatrix)) | ||
if (vtkAddonMathUtilities::MatrixAreEqual(orientationMatrix, it->Orientation)) | ||
{ | ||
return presetName; | ||
return it->Name; | ||
} | ||
} | ||
return std::string(); | ||
|
@@ -391,6 +380,30 @@ std::string vtkMRMLSliceNode::GetOrientation(vtkMatrix4x4 *sliceToRAS) | |
return "Reformat"; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
std::string vtkMRMLSliceNode::GetSliceOrientationPresetPrefix(const std::string& name) | ||
{ | ||
if (name == "Reformat") | ||
{ | ||
return ""; | ||
} | ||
|
||
OrientationPresetType* preset = this->GetOrientationPreset(name); | ||
return preset ? preset->Prefix : ""; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
std::string vtkMRMLSliceNode::GetSliceOrientationPresetTooltip(const std::string& name) | ||
{ | ||
if (name == "Reformat") | ||
{ | ||
return "Oblique"; | ||
} | ||
|
||
OrientationPresetType* preset = this->GetOrientationPreset(name); | ||
return preset ? preset->Tooltip : ""; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
void vtkMRMLSliceNode::GetSliceOrientationPresetNames(vtkStringArray *presetOrientationNames) | ||
{ | ||
|
@@ -408,7 +421,7 @@ void vtkMRMLSliceNode::GetSliceOrientationPresetNames(vtkStringArray *presetOrie | |
it != this->OrientationMatrices.end(); | ||
++it) | ||
{ | ||
presetOrientationNames->SetValue(id, it->first); | ||
presetOrientationNames->SetValue(id, it->Name); | ||
id++; | ||
} | ||
} | ||
|
@@ -420,7 +433,9 @@ int vtkMRMLSliceNode::GetNumberOfSliceOrientationPresets() const | |
} | ||
|
||
//---------------------------------------------------------------------------- | ||
bool vtkMRMLSliceNode::AddSliceOrientationPreset(const std::string &name, vtkMatrix3x3 *orientationMatrix) | ||
bool vtkMRMLSliceNode::AddSliceOrientationPreset( | ||
const std::string &name, vtkMatrix3x3 *orientationMatrix, | ||
const std::string &prefix, const std::string &tooltip) | ||
{ | ||
if (name == "Reformat") | ||
{ | ||
|
@@ -429,17 +444,19 @@ bool vtkMRMLSliceNode::AddSliceOrientationPreset(const std::string &name, vtkMat | |
return false; | ||
} | ||
|
||
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
if (this->GetOrientationPreset(name, false)) | ||
{ | ||
if (it->first == name) | ||
{ | ||
vtkDebugMacro("AddSliceOrientationPreset: the orientation preset " << name << " is already stored."); | ||
return false; | ||
} | ||
vtkDebugMacro("AddSliceOrientationPreset: the orientation preset " << name << " is already stored."); | ||
return false; | ||
} | ||
|
||
this->OrientationMatrices.push_back(OrientationPresetType(name, orientationMatrix)); | ||
OrientationPresetType newOrientation; | ||
newOrientation.Name = name; | ||
newOrientation.Orientation = orientationMatrix; | ||
newOrientation.Prefix = prefix; | ||
newOrientation.Tooltip = tooltip; | ||
|
||
this->OrientationMatrices.push_back(newOrientation); | ||
return true; | ||
} | ||
|
||
|
@@ -449,7 +466,7 @@ bool vtkMRMLSliceNode::RemoveSliceOrientationPreset(const std::string &name) | |
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
{ | ||
if (it->first == name) | ||
if (it->Name == name) | ||
{ | ||
this->OrientationMatrices.erase(it); | ||
return true; | ||
|
@@ -460,6 +477,26 @@ bool vtkMRMLSliceNode::RemoveSliceOrientationPreset(const std::string &name) | |
return false; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
OrientationPresetType* vtkMRMLSliceNode::GetOrientationPreset(const std::string &name, bool error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead, what do you think of displaying the error on the user side ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a protected method. It only has this option so you can query the preset existence in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not complicate the API with with this "bool error" flag. Since the caller can detect if a preset is not found (by getting NULL as result), it is not essential to log an error.. |
||
{ | ||
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
{ | ||
if (it->Name == name) | ||
{ | ||
return &(*it); | ||
} | ||
} | ||
|
||
if (error) | ||
{ | ||
vtkErrorMacro("GetOrientationPreset: The orientation preset " | ||
"'" << name << "' does NOT exist."); | ||
} | ||
return nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> NULL |
||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
bool vtkMRMLSliceNode::RenameSliceOrientationPreset(const std::string &name, const std::string &updatedName) | ||
{ | ||
|
@@ -479,43 +516,63 @@ bool vtkMRMLSliceNode::RenameSliceOrientationPreset(const std::string &name, con | |
this->SetOrientationReference(updatedName.c_str()); | ||
} | ||
|
||
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
OrientationPresetType* preset = this->GetOrientationPreset(name); | ||
if (preset) | ||
{ | ||
if (it->first == name) | ||
{ | ||
it->first = updatedName; | ||
return true; | ||
} | ||
preset->Name = updatedName; | ||
return true; | ||
} | ||
|
||
vtkErrorMacro("RenameSliceOrientationPreset: The orientation preset " | ||
"'" << name << "' does NOT exist."); | ||
return false; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
bool vtkMRMLSliceNode::HasSliceOrientationPreset(const std::string &name) | ||
bool vtkMRMLSliceNode::RenameSliceOrientationPresetPrefix(const std::string &name, const std::string &prefix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||
{ | ||
if (name == "Reformat") | ||
{ | ||
vtkWarningMacro("HasSliceOrientationPreset: 'Reformat' refers to any " | ||
"arbitrary orientation. It can NOT be used as a preset name."); | ||
vtkErrorMacro("RenameSliceOrientationPresetPrefix: 'Reformat' refers to any " | ||
"arbitrary orientation. It can NOT be used as a preset name."); | ||
return false; | ||
} | ||
OrientationPresetType* preset = this->GetOrientationPreset(name); | ||
if (preset && preset->Prefix.compare(prefix) != 0) | ||
{ | ||
preset->Prefix = prefix; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
//---------------------------------------------------------------------------- | ||
bool vtkMRMLSliceNode::RenameSliceOrientationPresetTooltip(const std::string &name, const std::string &tip) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
if (name == "Reformat") | ||
{ | ||
if (it->first == name) | ||
{ | ||
return true; | ||
} | ||
vtkErrorMacro("RenameSliceOrientationPresetTooltip: 'Reformat' refers to any " | ||
"arbitrary orientation. It can NOT be used as a preset name."); | ||
return false; | ||
} | ||
OrientationPresetType* preset = this->GetOrientationPreset(name); | ||
if (preset && preset->Tooltip.compare(tip) != 0) | ||
{ | ||
preset->Tooltip = tip; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
bool vtkMRMLSliceNode::HasSliceOrientationPreset(const std::string &name) | ||
{ | ||
if (name == "Reformat") | ||
{ | ||
vtkWarningMacro("HasSliceOrientationPreset: 'Reformat' refers to any " | ||
"arbitrary orientation. It can NOT be used as a preset name."); | ||
return false; | ||
} | ||
return this->GetOrientationPreset(name, false) != nullptr; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
void vtkMRMLSliceNode::InitializeAxialMatrix(vtkMatrix3x3* orientationMatrix) | ||
{ | ||
|
@@ -596,9 +653,12 @@ void vtkMRMLSliceNode::AddDefaultSliceOrientationPresets(vtkMRMLScene* scene) | |
scene->AddDefaultNode(defaultNode); | ||
} | ||
vtkMRMLSliceNode * defaultSliceNode = vtkMRMLSliceNode::SafeDownCast(defaultNode); | ||
defaultSliceNode->AddSliceOrientationPreset("Axial", axialSliceToRAS.GetPointer()); | ||
defaultSliceNode->AddSliceOrientationPreset("Sagittal", sagittalSliceToRAS.GetPointer()); | ||
defaultSliceNode->AddSliceOrientationPreset("Coronal", coronalSliceToRAS.GetPointer()); | ||
defaultSliceNode->AddSliceOrientationPreset( | ||
"Axial", axialSliceToRAS.GetPointer(), "S: ", "I <-----> S"); | ||
defaultSliceNode->AddSliceOrientationPreset( | ||
"Sagittal", sagittalSliceToRAS.GetPointer(), "R: ", "L <-----> R"); | ||
defaultSliceNode->AddSliceOrientationPreset( | ||
"Coronal", coronalSliceToRAS.GetPointer(), "A: ", "P <-----> A"); | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
|
@@ -878,14 +938,17 @@ void vtkMRMLSliceNode::WriteXML(ostream& of, int nIndent) | |
{ | ||
for (j=0; j<3; j++) | ||
{ | ||
ss << it->second->GetElement(i,j); | ||
ss << it->Orientation->GetElement(i,j); | ||
if ( !( i==2 && j==2) ) | ||
{ | ||
ss << " "; | ||
} | ||
} | ||
} | ||
of << " orientationMatrix"<< this->URLEncodeString(it->first.c_str()) <<"=\"" << ss.str().c_str() << "\""; | ||
of << " orientationMatrix"<< this->URLEncodeString(it->Name.c_str()) <<"=\"" << ss.str().c_str() | ||
<< " " << this->URLEncodeString(it->Prefix.c_str()) | ||
<< " " << this->URLEncodeString(it->Tooltip.c_str()) | ||
<< "\""; | ||
} | ||
|
||
of << " orientation=\"" << this->GetOrientation() << "\""; | ||
|
@@ -1173,8 +1236,17 @@ void vtkMRMLSliceNode::ReadXMLAttributes(const char** atts) | |
orientationMatrix->SetElement(i,j,val); | ||
} | ||
} | ||
std::string prefix; | ||
ss >> prefix; | ||
|
||
std::string tooltip; | ||
ss >> tooltip; | ||
|
||
name.erase(0,17); | ||
this->AddSliceOrientationPreset(name, orientationMatrix.GetPointer()); | ||
this->AddSliceOrientationPreset( | ||
name, orientationMatrix.GetPointer(), | ||
this->URLDecodeString(prefix.c_str()), | ||
this->URLDecodeString(tooltip.c_str())); | ||
} | ||
else if (!strcmp(attName, "prescribedSliceSpacing")) | ||
{ | ||
|
@@ -1286,8 +1358,11 @@ void vtkMRMLSliceNode::Copy(vtkMRMLNode *anode) | |
|
||
for (int i = 0; i < namedOrientations->GetNumberOfValues(); i++) | ||
{ | ||
this->AddSliceOrientationPreset(namedOrientations->GetValue(i), | ||
node->GetSliceOrientationPreset(namedOrientations->GetValue(i))); | ||
std::string name = namedOrientations->GetValue(i); | ||
this->AddSliceOrientationPreset(name, | ||
node->GetSliceOrientationPreset(name), | ||
node->GetSliceOrientationPresetPrefix(name), | ||
node->GetSliceOrientationPresetTooltip(name)); | ||
} | ||
|
||
std::string orientation = node->GetOrientation(); | ||
|
@@ -1427,8 +1502,10 @@ void vtkMRMLSliceNode::PrintSelf(ostream& os, vtkIndent indent) | |
std::vector< OrientationPresetType >::iterator it; | ||
for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) | ||
{ | ||
os << indent << "OrientationMatrix"<< this->URLEncodeString(it->first.c_str()) <<": \n"; | ||
it->second->PrintSelf(os, indent.GetNextIndent()); | ||
os << indent << "OrientationMatrix"<< this->URLEncodeString(it->Name.c_str()) <<": \n"; | ||
it->Orientation->PrintSelf(os, indent.GetNextIndent()); | ||
os << indent.GetNextIndent() << "Prefix: " << this->URLEncodeString(it->Prefix.c_str()) << "\n"; | ||
os << indent.GetNextIndent() << "Tooltip: " << this->URLEncodeString(it->Tooltip.c_str()) << "\n"; | ||
} | ||
|
||
os << indent << "XYToRAS: \n"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullptr
->NULL
, since we will most likely create 4.10.1 ... let's continue support c++98