7 #include "fwGdcmIO/container/sr/DicomSRCodeNode.hpp" 8 #include "fwGdcmIO/container/sr/DicomSRContainerNode.hpp" 9 #include "fwGdcmIO/container/sr/DicomSRImageNode.hpp" 10 #include "fwGdcmIO/container/sr/DicomSRNumNode.hpp" 11 #include "fwGdcmIO/container/sr/DicomSRSCoord3DNode.hpp" 12 #include "fwGdcmIO/container/sr/DicomSRSCoordNode.hpp" 13 #include "fwGdcmIO/container/sr/DicomSRTextNode.hpp" 14 #include "fwGdcmIO/container/sr/DicomSRUIDRefNode.hpp" 15 #include "fwGdcmIO/helper/DicomDataReader.hxx" 16 #include "fwGdcmIO/helper/StructuredReport.hpp" 30 const std::string type = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0040, 0xa040 >(dataset);
33 const ::fwGdcmIO::container::DicomCodedAttribute& codedAttribute =
34 ::fwGdcmIO::helper::StructuredReport::readCodeSequence<0x0040, 0xa043>(dataset);
36 if(type ==
"CONTAINER" && !codedAttribute.isEmpty())
38 result = std::make_shared< ::fwGdcmIO::container::sr::DicomSRContainerNode >(codedAttribute);
51 if(dataset.FindDataElement(::gdcm::Tag(0x0040, 0xa730)))
53 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence =
54 dataset.GetDataElement(::gdcm::Tag(0x0040, 0xa730)).GetValueAsSQ();
56 for(
unsigned int i = 1; i <= sequence->GetNumberOfItems(); ++i)
58 const ::gdcm::DataSet& itemDataset = sequence->GetItem(i).GetNestedDataSet();
73 const std::string type = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0040, 0xa040 >(dataset);
76 const ::fwGdcmIO::container::DicomCodedAttribute& codedAttribute =
77 ::fwGdcmIO::helper::StructuredReport::readCodeSequence<0x0040, 0xa043>(dataset);
80 const std::string relationship = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0040, 0xa010 >(dataset);
85 const std::string textValue = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0040, 0xa160 >(dataset);
88 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRTextNode >(
89 codedAttribute, relationship, textValue);
91 else if(type ==
"NUM")
94 if(dataset.FindDataElement(::gdcm::Tag(0x0040, 0xa300)))
96 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence =
97 dataset.GetDataElement(::gdcm::Tag(0x0040, 0xa300)).GetValueAsSQ();
98 if(sequence->GetNumberOfItems() > 0)
100 const ::gdcm::DataSet& itemDataset = sequence->GetItem(1).GetNestedDataSet();
103 const double numValue =
104 ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0040, 0xa30a, double >(itemDataset);
107 const ::fwGdcmIO::container::DicomCodedAttribute& measurementUnits =
108 ::fwGdcmIO::helper::StructuredReport::readCodeSequence<0x0040, 0x08ea>(itemDataset);
111 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRNumNode >(
112 codedAttribute, relationship, numValue, measurementUnits);
117 else if(type ==
"SCOORD")
120 ::gdcm::Attribute< 0x0070, 0x0022 > graphicDataAttribute;
121 graphicDataAttribute.SetFromDataElement(dataset.GetDataElement(::gdcm::Tag(0x0070, 0x0022)));
122 const float* graphicData = graphicDataAttribute.GetValues();
125 const std::string graphicType = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0070, 0x0023 >(dataset);
127 if(graphicType ==
"POINT" && graphicDataAttribute.GetNumberOfValues() == 2)
130 std::vector<float> scoordVector(graphicData, graphicData + 2);
131 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRSCoordNode >(
132 codedAttribute, relationship, graphicType, scoordVector);
134 else if(graphicType ==
"POLYLINE" && graphicDataAttribute.GetNumberOfValues() == 4)
137 std::vector<float> scoordVector(graphicData, graphicData + 4);
138 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRSCoordNode >(
139 codedAttribute, relationship, graphicType, scoordVector);
143 SLM_WARN(
"Graphic type is not handled or data size doesn't match type. The SR node has been ignored.");
147 else if(type ==
"SCOORD3D")
150 const std::string frameOfReferenceUID =
151 ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x3006, 0x0024 >(dataset);
154 ::gdcm::Attribute< 0x0070, 0x0022 > graphicDataAttribute;
155 graphicDataAttribute.SetFromDataElement(dataset.GetDataElement(::gdcm::Tag(0x0070, 0x0022)));
156 const float* graphicData = graphicDataAttribute.GetValues();
159 const std::string graphicType = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0070, 0x0023 >(dataset);
161 if(graphicType ==
"POINT" && graphicDataAttribute.GetNumberOfValues() == 3)
164 std::vector<float> scoordVector(graphicData, graphicData + 3);
165 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRSCoord3DNode >(
166 codedAttribute, relationship, graphicType, scoordVector, frameOfReferenceUID);
168 else if(graphicType ==
"POLYLINE" && graphicDataAttribute.GetNumberOfValues() == 6)
171 std::vector<float> scoordVector(graphicData, graphicData + 6);
172 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRSCoord3DNode >(
173 codedAttribute, relationship, graphicType, scoordVector, frameOfReferenceUID);
177 SLM_WARN(
"Graphic type is not handled or data size doesn't match type. The SR node has been ignored.");
181 else if(type ==
"IMAGE")
184 if(dataset.FindDataElement(::gdcm::Tag(0x0008, 0x1199)))
186 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence =
187 dataset.GetDataElement(::gdcm::Tag(0x0008, 0x1199)).GetValueAsSQ();
188 if(sequence->GetNumberOfItems() > 0)
190 const ::gdcm::DataSet& itemDataset = sequence->GetItem(1).GetNestedDataSet();
193 const std::string sopClassUID = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0008, 0x1150 >(itemDataset);
196 const std::string sopInstanceUID =
197 ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0008, 0x1155 >(itemDataset);
200 int frameNumber = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0008, 0x1160, int >(itemDataset);
203 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRImageNode >(
204 codedAttribute, relationship, sopClassUID, sopInstanceUID, frameNumber);
209 else if(type ==
"CODE")
211 const ::fwGdcmIO::container::DicomCodedAttribute& codedEntry =
212 ::fwGdcmIO::helper::StructuredReport::readCodeSequence<0x0040, 0xa168>(dataset);
215 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRCodeNode >(codedAttribute, relationship, codedEntry);
219 else if(type ==
"UIDREF")
222 const std::string uidValue = ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0040, 0xa124 >(dataset);
225 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRUIDRefNode >(codedAttribute, relationship, uidValue);
227 else if(type ==
"CONTAINER")
230 node = std::make_shared< ::fwGdcmIO::container::sr::DicomSRContainerNode >(codedAttribute, relationship);
247 out <<
"graph SR {" << std::endl;
250 out <<
"}" << std::endl;
260 out <<
"\t" << index <<
"[label=\"" << (*root) <<
"\"][shape=box];" << std::endl;
262 const int parentIndex = index;
266 out <<
"\t" << parentIndex <<
"--" << (index+1) <<
"[label=\"" 267 << child->getRelationship() <<
"\"];" << std::endl;
static FWGDCMIO_API void dumpSR(const std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > &root, std::ostream &out=std::cout)
Dump the SR in graphviz format.
const SubNodeContainer & getSubNodeContainer() const
Get Sub node container.
static void readSubNode(const ::gdcm::DataSet &dataset, std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > parent)
Read a sub node and add it as a child to the parent node.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
#define SLM_WARN(message)
static void readSubNodeContainer(const ::gdcm::DataSet &dataset, std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > parent)
Read all sub nodes and add it as children to the parent node.
This class defines a node in a SR document.
This class defines a CONTAINER node in a SR document.
FWGDCMIO_API void addSubNode(const std::shared_ptr< DicomSRNode > &node)
Add a sub node.
This class contains helpers for DICOM Structured Reporting (SR).
static FWGDCMIO_API void dumpSRNode(const std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > &node, std::ostream &out, int &index)
Dump an SR node in graphviz format.