Skip to content

Commit

Permalink
ENH: Expose markups JSON reader/writer
Browse files Browse the repository at this point in the history
Allows custom markup classes (implemented outside Slicer core) to store additional properties in the markups file in JSON.
vtkMRMLMarkupsJsonElement, vtkMRMLMarkupsJsonReader, and vtkMRMLMarkupsJsonWriter provide a simple JSON reading/writing interface
without exposing the internal RapidJSON implementation.

Fixed saving of coded entries (such as units, quantityCode, derivationCode) in markup json files.
  • Loading branch information
lassoan committed Jan 2, 2023
1 parent 7b24024 commit af7c986
Show file tree
Hide file tree
Showing 16 changed files with 2,149 additions and 1,425 deletions.
30 changes: 30 additions & 0 deletions Libs/MRML/Core/vtkCodedEntry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ void vtkCodedEntry::SetValueSchemeMeaning(const std::string& value,
this->SetCodeMeaning(meaning.c_str());
}

//----------------------------------------------------------------------------
bool vtkCodedEntry::SetValueSchemeMeaning(const std::vector<std::string>& codeValueSchemeMeaning)
{
if (codeValueSchemeMeaning.size() < 2 || codeValueSchemeMeaning.size() > 3)
{
vtkErrorMacro("SetValueSchemeMeaning failed: codeValueSchemeMeaning must contain 2 or 3 strings");
return false;
}
this->SetCodeValue(codeValueSchemeMeaning[0].c_str());
this->SetCodingSchemeDesignator(codeValueSchemeMeaning[1].c_str());
if (codeValueSchemeMeaning.size() > 2)
{
this->SetCodeMeaning(codeValueSchemeMeaning[3].c_str());
}
else
{
this->SetCodeMeaning(codeValueSchemeMeaning[0].c_str());
}
}

//----------------------------------------------------------------------------
std::vector<std::string> vtkCodedEntry::GetValueSchemeMeaning()
{
std::vector<std::string> code;
code.push_back(this->GetCodeValue() ? this->GetCodeValue() : "");
code.push_back(this->GetCodingSchemeDesignator() ? this->GetCodingSchemeDesignator() : "");
code.push_back(this->GetCodeMeaning() ? this->GetCodeMeaning() : "");
return code;
}

//----------------------------------------------------------------------------
std::string vtkCodedEntry::GetAsPrintableString()
{
Expand Down
9 changes: 9 additions & 0 deletions Libs/MRML/Core/vtkCodedEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ or http://www.slicer.org/copyright/copyright.txt for details.
// VTK includes
#include <vtkObject.h>

// STL includes
#include <vector>

/// \brief Simple class for storing standard coded entries (coding scheme, value, meaning triplets)
///
/// vtkCodedEntry is a lightweight class that stores standard coded entries consisting of
Expand Down Expand Up @@ -62,6 +65,12 @@ class VTK_MRML_EXPORT vtkCodedEntry : public vtkObject
/// Convenience function for setting code value, coding scheme, and code meaning with a single method call
virtual void SetValueSchemeMeaning(const std::string& value, const std::string& scheme, const std::string& meaning);

/// Convenience function for setting code value, coding scheme, and code meaning with a single method call from a string vector
virtual bool SetValueSchemeMeaning(const std::vector<std::string>& valueSchemeMeaning);

/// Convenience function for getting code value, coding scheme, and code meaning as a string vector
virtual std::vector<std::string> GetValueSchemeMeaning();

///
/// Get content of the object as a single human-readable string.
/// Example: ([hnsf'U], UCUM, "Hounsfield unit")
Expand Down
18 changes: 18 additions & 0 deletions Modules/Loadable/Markups/MRML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,39 @@ set(${KIT}_INCLUDE_DIRECTORIES

set(${KIT}_SRCS
vtkMRML${MODULE_NAME}AngleNode.cxx
vtkMRML${MODULE_NAME}AngleNode.h
vtkMRML${MODULE_NAME}ClosedCurveNode.cxx
vtkMRML${MODULE_NAME}ClosedCurveNode.h
vtkMRML${MODULE_NAME}CurveNode.cxx
vtkMRML${MODULE_NAME}CurveNode.h
vtkMRML${MODULE_NAME}DisplayNode.cxx
vtkMRML${MODULE_NAME}DisplayNode.h
vtkMRML${MODULE_NAME}FiducialDisplayNode.cxx
vtkMRML${MODULE_NAME}FiducialDisplayNode.h
vtkMRML${MODULE_NAME}FiducialStorageNode.cxx
vtkMRML${MODULE_NAME}FiducialStorageNode.h
vtkMRML${MODULE_NAME}FiducialNode.cxx
vtkMRML${MODULE_NAME}FiducialNode.h
vtkMRML${MODULE_NAME}JsonElement.cxx
vtkMRML${MODULE_NAME}JsonElement.h
vtkMRML${MODULE_NAME}JsonStorageNode.cxx
vtkMRML${MODULE_NAME}JsonStorageNode.h
vtkMRML${MODULE_NAME}LineNode.cxx
vtkMRML${MODULE_NAME}LineNode.h
vtkMRML${MODULE_NAME}Node.cxx
vtkMRML${MODULE_NAME}Node.h
vtkMRML${MODULE_NAME}PlaneDisplayNode.cxx
vtkMRML${MODULE_NAME}PlaneDisplayNode.h
vtkMRML${MODULE_NAME}PlaneJsonStorageNode.cxx
vtkMRML${MODULE_NAME}PlaneJsonStorageNode.h
vtkMRML${MODULE_NAME}PlaneNode.cxx
vtkMRML${MODULE_NAME}PlaneNode.h
vtkMRML${MODULE_NAME}ROIDisplayNode.cxx
vtkMRML${MODULE_NAME}ROIDisplayNode.h
vtkMRML${MODULE_NAME}ROIJsonStorageNode.cxx
vtkMRML${MODULE_NAME}ROIJsonStorageNode.cxx
vtkMRML${MODULE_NAME}ROINode.cxx
vtkMRML${MODULE_NAME}ROINode.h
vtkCurveGenerator.cxx
vtkCurveGenerator.h
vtkCurveMeasurementsCalculator.cxx
Expand Down

0 comments on commit af7c986

Please sign in to comment.