Skip to content

Commit

Permalink
ENH: Terminology contexts from color nodes are offered in selector
Browse files Browse the repository at this point in the history
  • Loading branch information
cpinter committed Dec 20, 2024
1 parent 4b10852 commit c5af455
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Libs/MRML/Core/vtkMRMLColorNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void vtkMRMLColorNode::Copy(vtkMRMLNode *anode)
this->SetNoName(node->NoName);

// copy names
this->Properties = node->Properties;
this->Properties = node->Properties; //TODO: Probably does not work like this. But vtkMRMLColorLogic::CopyNode is used for copying

this->EndModify(disabledModify);
}
Expand Down Expand Up @@ -585,6 +585,9 @@ bool vtkMRMLColorNode::SetTerminologyFromString(int ind, std::string terminology

this->Properties[ind] = prop;

// Set attribute indicating that the color table contains terminology
this->SetAttribute(this->GetContainTerminologyAttributeName(), "true");

return true;
}

Expand Down
27 changes: 11 additions & 16 deletions Libs/MRML/Core/vtkMRMLColorNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
virtual int GetFirstType () { return this->User; }
virtual int GetLastType () { return this->File; }

/// return a text string describing the color look up table type
/// Return a text string describing the color look up table type.
virtual const char* GetTypeAsString();

/// TypeModifiedEvent is generated when the type of the color look up table changes
Expand Down Expand Up @@ -141,7 +141,7 @@ class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
std::string GetColorNameWithoutSpaces(int ind, const char *subst);

/// Set the 0th based nth name of this color.
/// Returns 1 on success, 0 on failure.
/// \return 1 on success, 0 on failure.
int SetColorName(int ind, const char *name, bool autoGenerated=false);

///
Expand All @@ -161,23 +161,18 @@ class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
vtkCodedEntry* anatomicRegion=nullptr, vtkCodedEntry* anatomicRegionModifier=nullptr);

bool SetTerminologyFromString(int ind, std::string terminologyString);
std::string SetTerminologyFromString(int ind, std::string terminologyString,
vtkCodedEntry* category, vtkCodedEntry* type, vtkCodedEntry* typeModifier,
//std::string anatomicContextName="", //TODO: Needed?
vtkCodedEntry* anatomicRegion=nullptr, vtkCodedEntry* anatomicRegionModifier=nullptr);

///
/// Get attribute name that indicates if the color table has terminology entries.
const char* GetContainTerminologyAttributeName() { return "ContainTerminology"; };

/// Get the number of colors in the table
virtual int GetNumberOfColors() = 0;

/// Retrieve the color associated to the index
/// Must be reimplemented in the derived classes
/// Return 1 if the color exists, 0 otherwise
/// Retrieve the color associated to the index. Must be reimplemented in the derived classes.
/// \return 1 if the color exists, 0 otherwise
virtual bool GetColor(int ind, double color[4]) = 0;

///
/// Most color nodes will implement a look up table, so provide a top level
/// get method
/// Most color nodes will implement a look up table, so provide a top level get method.
virtual vtkLookupTable* GetLookupTable();

/// Utility function that either returns a vtkLookupTable or a
Expand All @@ -186,13 +181,11 @@ class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
/// the method if you want it to return something else in subclasses
virtual vtkScalarsToColors* GetScalarsToColors();

/// get/set the string used for an unnamed color
/// "(none)" by default.
/// Get/set the string used for an unnamed color "(none)" by default.
/// \sa SetColorName
vtkGetStringMacro(NoName);
vtkSetStringMacro(NoName);

///
/// Set values in the names vector from the colors in the node
void SetNamesFromColors();

Expand Down Expand Up @@ -226,6 +219,7 @@ class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
{
// The label value and corresponding color has been explicitly set.
// If the label value is not included in the color table file then "Defined" will set to false.
//TODO: All members not coded entries are unused (currently terminology string is used for get/set)
bool Defined{ false };
std::string Name;
// Name is automatically generated (e.g., from color)
Expand All @@ -236,6 +230,7 @@ class VTK_MRML_EXPORT vtkMRMLColorNode : public vtkMRMLStorableNode
vtkCodedEntry* AnatomicRegion{ nullptr };
vtkCodedEntry* AnatomicRegionModifier{ nullptr };
// Context name in case it originates from a terminology context
//TODO: Unused. Add also anatomic context name and columns in the storage tables for the context names.
std::string ContextName;
};

Expand Down
4 changes: 3 additions & 1 deletion Libs/MRML/Logic/vtkMRMLColorLogic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ vtkMRMLColorTableNode* vtkMRMLColorLogic::CopyNode(vtkMRMLColorNode* nodeToCopy,
double color[4];
nodeToCopy->GetColor(i, color);
colorNode->SetColor(i, nodeToCopy->GetColorName(i), color[0], color[1], color[2], color[3]);
// TODO: copy properties
// Copy terminologies
std::string terminologyString = nodeToCopy->GetTerminologyAsString(i);
colorNode->SetTerminologyFromString(i, terminologyString);
}
return colorNode;
}
Expand Down
Loading

0 comments on commit c5af455

Please sign in to comment.