1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/************************************************************************
*
* Copyright (C) 2017-2021 IRCAD France
* Copyright (C) 2017-2019 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#pragma once
#include "io/dicom/config.hpp"
#include "io/dicom/container/DicomCodedAttribute.hpp"
#include <data/Object.hpp>
#include <array>
#include <filesystem>
#include <string>
namespace sight::core::log
{
class Logger;
}
namespace sight::io::dicom
{
namespace helper
{
/**
* @brief Registry of Segment Properties.
* This class defines a registry which links a structure type to an entry.
* Each entry is composed of 5 attributes :
* - Property Type
* - Property Category
* - Property Type Modifiers
* - Anatomic Region
* - Anatomic Region Modifiers
*/
class IO_DICOM_CLASS_API SegmentedPropertyRegistry
{
public:
/// Entry containing the 5 attributes of a structure type
typedef std::array<std::string, 5> EntryType;
/// Constructor
IO_DICOM_API SegmentedPropertyRegistry();
/**
* @brief Read an extract registry values from a CSV file
* Each lines shall contain at least 6 elements :
* - Structure Type
* - Property Type (With unique (AAA;BBB;CCC) value) [MANDATORY]
* - Property Category (With unique (AAA;BBB;CCC) value) [MANDATORY]
* - Property Type Modifiers (With one or more (AAA;BBB;CCC) values)
* - Anatomic Region (With unique (AAA;BBB;CCC) value) [MANDATORY]
* - Anatomic Region Modifiers (With one or more (AAA;BBB;CCC) values)
* Each of those elements shall be separated using the '|' separator
* @param[in] filepath Path of the CSV file
* @param[in] omitFirstLine If set to 'true', the first line of the file is omitted
* @param[in] logger Logger used to display errors
*/
IO_DICOM_API bool readSegmentedPropertyRegistryFile(
const std::filesystem::path& filepath,
bool omitFirstLine = false,
const SPTR(core::log::Logger)& logger = 0
);
/**
* @brief Read an extract registry values from a CSV stream
* Each lines shall contain at least 6 elements :
* - Structure Type
* - Property Type (With unique (AAA;BBB;CCC) value) [MANDATORY]
* - Property Category (With unique (AAA;BBB;CCC) value) [MANDATORY]
* - Property Type Modifiers (With one or more (AAA;BBB;CCC) values)
* - Anatomic Region (With unique (AAA;BBB;CCC) value)
* - Anatomic Region Modifiers (With one or more (AAA;BBB;CCC) values)
* Each of those elements shall be separated using the '|' separator
* @param[in] csvStream CSV stream
* @param[in] omitFirstLine If set to 'true', the first line of the file is omitted
* @param[in] logger Logger used to display errors
*/
IO_DICOM_API bool readSegmentedPropertyRegistryFile(
std::istream& csvStream,
bool omitFirstLine = false,
const SPTR(core::log::Logger)& logger = 0
);
/// Returns whether the registry is empty or not
IO_DICOM_API bool empty() const;
/// Returns the number of entries
IO_DICOM_API std::size_t count() const;
/// Clear the registry
IO_DICOM_API void clear();
/**
* @brief Check if there is an entry for the corresponding structure type
* @param[in] structureType Structure type
*/
IO_DICOM_API bool hasEntry(const std::string& structureType) const;
/**
* @brief Returns matching entry for the corresponding structure type
* @param[in] structureType Structure type
*/
IO_DICOM_API EntryType getEntry(const std::string& structureType) const;
/**
* @brief Getters for entry's attributes
* @param[in] structureType Structure type
* @{ */
IO_DICOM_API std::string getPropertyType(const std::string& structureType) const;
IO_DICOM_API std::string getPropertyCategory(const std::string& structureType) const;
IO_DICOM_API std::string getPropertyTypeModifiers(const std::string& structureType) const;
IO_DICOM_API std::string getAnatomicRegion(const std::string& structureType) const;
IO_DICOM_API std::string getAnatomicRegionModifiers(const std::string& structureType) const;
/** @} */
/**
* @brief Returns the structure type associated to the attribute list.
* If no match is found, it returns an empty string.
* @param[in] propertyType Property Type
* @param[in] propertyCategory Property Category
* @param[in] propertyTypeModifiers Property Modifiers
* @param[in] anatomicRegion Anatomic Region
* @param[in] anatomicRegionModifiers Anatomic Region Modifiers
*/
IO_DICOM_API std::string getStructureType(
const std::string& propertyType,
const std::string& propertyCategory,
const std::string& propertyTypeModifiers,
const std::string& anatomicRegion,
const std::string& anatomicRegionModifiers
) const;
private:
/// Entry registry type
typedef std::map<std::string, EntryType> EntryRegistryType;
/// Default entry value
static const EntryType s_DEFAULT_ENTRY_VALUE;
/// Segmented Property Registry
EntryRegistryType m_registry;
};
} //namespace helper
} //namespace sight::io::dicom
|