fw4spl
DicomSRNode.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwGdcmIO/container/sr/DicomSRNode.hpp"
8 
9 #include "fwGdcmIO/helper/DicomDataWriter.hxx"
10 
11 namespace fwGdcmIO
12 {
13 namespace container
14 {
15 namespace sr
16 {
17 
18 //------------------------------------------------------------------------------
19 
21  const std::string& type,
22  const std::string& relationship) :
23  m_codedAttribute(codedAttribute),
24  m_type(type),
25  m_relationship(relationship)
26 {
27 }
28 
29 //------------------------------------------------------------------------------
30 
32 {
33 }
34 
35 //------------------------------------------------------------------------------
36 
38 {
39  m_subNodeContainer.push_back(node);
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 void DicomSRNode::write(::gdcm::DataSet& dataset) const
45 {
46  // Value Type - Type 1
47  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0040, 0xa040 >(m_type, dataset);
48 
49  // Relationship Value - Type 1 (Shouldn't be there for root node)
50  if(!m_relationship.empty())
51  {
52  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0040, 0xa010 >(m_relationship, dataset);
53  }
54 
55  // Concept Name Code Sequence - Type 1C
57  {
58  ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > codeSequence =
60  ::fwGdcmIO::helper::DicomDataWriter::setAndMergeSequenceTagValue<0x0040, 0xa043>(codeSequence, dataset);
61 
62  }
63 
64  // Content sequence - Type 1C
65  if(!m_subNodeContainer.empty())
66  {
67  this->writeContentSequence(dataset);
68  }
69 }
70 
71 //------------------------------------------------------------------------------
72 
73 ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > DicomSRNode::createConceptNameCodeSequence(
74  const DicomCodedAttribute& codedAttribute) const
75 {
76  // Write code sequence
77  ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > codeSequence = new ::gdcm::SequenceOfItems();
78  codeSequence->SetLengthToUndefined();
79 
80  // Create item (shall be one)
81  ::gdcm::Item item;
82  item.SetVLToUndefined();
83  ::gdcm::DataSet& itemDataset = item.GetNestedDataSet();
84 
85  // Code value - Type 1
86  ::fwGdcmIO::helper::DicomDataWriter::setTagValue<0x0008, 0x0100>(codedAttribute.getCodeValue(), itemDataset);
87 
88  // Coding Scheme Designator - Type 1
89  ::fwGdcmIO::helper::DicomDataWriter::setTagValue<0x0008, 0x0102>(
90  codedAttribute.getCodingSchemeDesignator(), itemDataset);
91 
92  // Coding Scheme Version - Type 1C
94  {
95  ::fwGdcmIO::helper::DicomDataWriter::setTagValue<0x0008, 0x0103>(
96  codedAttribute.getCodingSchemeVersion(), itemDataset);
97  }
98 
99  // Code Meaning - Type 1
100  ::fwGdcmIO::helper::DicomDataWriter::setTagValue<0x0008, 0x0104>(codedAttribute.getCodeMeaning(), itemDataset);
101 
102  // Insert in a sequence
103  codeSequence->AddItem(item);
104 
105  return codeSequence;
106 }
107 
108 //------------------------------------------------------------------------------
109 
110 void DicomSRNode::writeContentSequence(::gdcm::DataSet& dataset) const
111 {
112  // Create the content sequence
113  ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence = new ::gdcm::SequenceOfItems();
114 
115  // Write every node
117  {
118  ::gdcm::Item item;
119  item.SetVLToUndefined();
120  ::gdcm::DataSet& itemDataset = item.GetNestedDataSet();
121  child->write(itemDataset);
122  sequence->AddItem(item);
123  }
124 
125  ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0040, 0xa730 >(sequence, dataset);
126 }
127 
128 //------------------------------------------------------------------------------
129 
130 void DicomSRNode::print(std::ostream& os) const
131 {
132  os << m_type;
134  {
135  os << "\\n[" << m_codedAttribute << "]";
136  }
137 }
138 
139 //------------------------------------------------------------------------------
140 
141 } //namespace sr
142 } //namespace container
143 } //namespace fwGdcmIO
#define SPTR(_cls_)
const std::string getCodingSchemeVersion() const
Get coding scheme version.
const std::string getCodeMeaning() const
Get code meaning.
FWGDCMIO_API bool isEmpty() const
Returns true if the attribute is empty.
virtual ~DicomSRNode()
Destructor.
Definition: DicomSRNode.cpp:31
const std::string getCodingSchemeDesignator() const
Get coding scheme designator.
const std::string getCodeValue() const
Get code value.
std::string m_relationship
Node relationship (0040, a010)
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
This class defines a node in a SR document.
Definition: DicomSRNode.hpp:27
This class represents a DICOM basic coded entry. It stores the four mains attributes : Code Value...
virtual void print(std::ostream &os) const
Dump function.
SubNodeContainer m_subNodeContainer
SubNode container.
virtual FWGDCMIO_API void write(::gdcm::DataSet &dataset) const
Write the SR node in the dataset.
Definition: DicomSRNode.cpp:44
std::string m_type
Node type (0040, a040)
DicomSRNode(const DicomCodedAttribute &codedAttribute, const std::string &type, const std::string &relationship="")
Constructor.
Definition: DicomSRNode.cpp:20
FWGDCMIO_API void addSubNode(const std::shared_ptr< DicomSRNode > &node)
Add a sub node.
Definition: DicomSRNode.cpp:37
::gdcm::SmartPointer< ::gdcm::SequenceOfItems > createConceptNameCodeSequence(const DicomCodedAttribute &codedAttribute) const
Create a concept name code sequence.
Definition: DicomSRNode.cpp:73
DicomCodedAttribute m_codedAttribute
Coded entry of the node.
void writeContentSequence(::gdcm::DataSet &dataset) const
Write a content sequence.