fw4spl
writer/tid/Fiducial.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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/writer/tid/Fiducial.hpp"
8 
9 #include "fwGdcmIO/container/DicomCodedAttribute.hpp"
10 #include "fwGdcmIO/container/sr/DicomSRCodeNode.hpp"
11 #include "fwGdcmIO/container/sr/DicomSRImageNode.hpp"
12 #include "fwGdcmIO/container/sr/DicomSRSCoord3DNode.hpp"
13 #include "fwGdcmIO/container/sr/DicomSRSCoordNode.hpp"
14 #include "fwGdcmIO/container/sr/DicomSRTextNode.hpp"
15 #include "fwGdcmIO/container/sr/DicomSRUIDRefNode.hpp"
16 #include "fwGdcmIO/helper/DicomDataTools.hpp"
17 
18 #include <fwData/PointList.hpp>
19 #include <fwData/String.hpp>
20 #include <fwData/Vector.hpp>
21 
22 #include <fwDataTools/fieldHelper/Image.hpp>
23 
24 #include <fwMedData/Series.hpp>
25 #include <fwMedData/types.hpp>
26 
27 #include <fwTools/Stringizer.hpp>
28 
29 #include <boost/algorithm/string/split.hpp>
30 
31 #include <gdcmUIDGenerator.h>
32 
33 #include <sstream>
34 
35 namespace fwGdcmIO
36 {
37 namespace writer
38 {
39 namespace tid
40 {
41 
42 //------------------------------------------------------------------------------
43 
44 Fiducial::Fiducial(const SPTR(::gdcm::Writer)& writer,
45  const SPTR(::fwGdcmIO::container::DicomInstance)& instance,
46  const ::fwData::Image::csptr& image) :
47  ::fwGdcmIO::writer::tid::TemplateID< ::fwData::Image >(writer, instance, image)
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
60  bool useSCoord3D)
61 {
62  ::fwData::PointList::sptr pointList =
64  if (pointList)
65  {
66  unsigned int id = 1;
67  for(const ::fwData::Point::sptr& point : pointList->getPoints())
68  {
69  this->createFiducial(parent, point, id++, useSCoord3D);
70  }
71  }
72 }
73 
74 //------------------------------------------------------------------------------
75 
77  const ::fwData::Point::csptr& point,
78  unsigned int id, bool useSCoord3D)
79 {
80  // Create Fiducial node
82  std::make_shared< ::fwGdcmIO::container::sr::DicomSRCodeNode >(
83  ::fwGdcmIO::container::DicomCodedAttribute("122340", "DCM", "Fiducial feature"), "CONTAINS",
84  ::fwGdcmIO::container::DicomCodedAttribute("111123", "DCM", "Marker placement")); //FIXME : Find a better
85  // representation
86  parent->addSubNode(rootNode);
87 
88  // Create Fiducial ID node
90  std::make_shared< ::fwGdcmIO::container::sr::DicomSRUIDRefNode >(
92  "Fiducial ID"), "HAS PROPERTIES", ::fwTools::getString(id));
93  rootNode->addSubNode(idNode);
94 
95  // Create Fiducial UID node
96  ::gdcm::UIDGenerator generator;
98  std::make_shared< ::fwGdcmIO::container::sr::DicomSRUIDRefNode >(
99  ::fwGdcmIO::container::DicomCodedAttribute("dd1202", "DCM", "Fiducial UID"), "HAS PROPERTIES",
100  generator.Generate());
101  rootNode->addSubNode(uidNode);
102 
103  // Create Fiducial intent node
104  const std::string label =
107  std::make_shared< ::fwGdcmIO::container::sr::DicomSRTextNode >(
108  ::fwGdcmIO::container::DicomCodedAttribute("122369", "DCM", "Fiducial intent"), "HAS PROPERTIES", label);
109  rootNode->addSubNode(intentNode);
110 
111  if(useSCoord3D)
112  {
113  // Create SCoord3D Node
114  const float scoord[] = {
115  static_cast<float>(point->getCoord()[0]),
116  static_cast<float>(point->getCoord()[1]),
117  static_cast<float>(point->getCoord()[2])
118  };
119  std::vector<float> scoordVector(scoord, scoord + 3);
121  std::make_shared< ::fwGdcmIO::container::sr::DicomSRSCoord3DNode >(
122  ::fwGdcmIO::container::DicomCodedAttribute(), "HAS PROPERTIES", "POINT", scoordVector,
123  m_instance->getSOPInstanceUIDContainer()[0]);
124  rootNode->addSubNode(scoord3DNode);
125  }
126  else
127  {
128  // Create SCoord Node
129  const float scoord[] = {
130  static_cast<float>(point->getCoord()[0]),
131  static_cast<float>(point->getCoord()[1])
132  };
133  std::vector<float> scoordVector(scoord, scoord + 2);
135  std::make_shared< ::fwGdcmIO::container::sr::DicomSRSCoordNode >(
136  ::fwGdcmIO::container::DicomCodedAttribute(), "HAS PROPERTIES", "POINT", scoordVector);
137  rootNode->addSubNode(scoordNode);
138 
139  // Create Image Node
140  const std::size_t frameNumber = ::fwGdcmIO::helper::DicomDataTools::convertPointToFrameNumber(m_object, point);
142  std::make_shared< ::fwGdcmIO::container::sr::DicomSRImageNode >(
143  ::fwGdcmIO::container::DicomCodedAttribute(), "SELECTED FROM", m_instance->getSOPClassUID(),
144  m_instance->getSOPInstanceUIDContainer()[frameNumber-1], frameNumber);
145  scoordNode->addSubNode(imageNode);
146  }
147 
148 }
149 
150 //------------------------------------------------------------------------------
151 
152 } // namespace tid
153 } // namespace writer
154 } // namespace fwGdcmIO
#define SPTR(_cls_)
This class defines a UIDREF node in a SR document.
std::shared_ptr< const ::fwData::Image > m_object
FW4SPL Object.
void createFiducial(const std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > &parent, const std::shared_ptr< const ::fwData::Point > &point, unsigned int id, bool useSCoord3D)
Create a fiducial node.
This class defines a TEXT node in a SR document.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
This class defines an IMAGE node in a SR document.
FWGDCMIO_API Fiducial(const std::shared_ptr< ::gdcm::Writer > &writer, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwData::Image::csptr &image)
Constructor.
virtual FWGDCMIO_API void createNodes(const std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > &parent, bool useSCoord3D=true)
Create nodes according to the template.
TemplateID base class used to write templates.
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...
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_instance
DICOM Instance.
This class defines a SCOORD node in a SR document.
static FWDATATOOLS_API const std::string m_labelId
to assign a label
virtual FWGDCMIO_API ~Fiducial()
Destructor.
This class defines a CODE node in a SR document.
This class defines a list of points.
FWGDCMIO_API void addSubNode(const std::shared_ptr< DicomSRNode > &node)
Add a sub node.
Definition: DicomSRNode.cpp:37
Contains the representation of the data objects used in the framework.
This class defines a SCOORD3D node in a SR document.
static FWGDCMIO_API std::size_t convertPointToFrameNumber(const ::fwData::Image::csptr &image, const ::fwData::Point::csptr &point)
Convert a 3D point to the closest frame number index.
This class contains an std::string value.