fw4spl
reader/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/reader/tid/Fiducial.hpp"
8 
9 #include "fwGdcmIO/container/sr/DicomSRImageNode.hpp"
10 #include "fwGdcmIO/container/sr/DicomSRSCoord3DNode.hpp"
11 #include "fwGdcmIO/container/sr/DicomSRSCoordNode.hpp"
12 #include "fwGdcmIO/container/sr/DicomSRTextNode.hpp"
13 #include "fwGdcmIO/helper/DicomDataTools.hpp"
14 
15 #include <fwData/Boolean.hpp>
16 #include <fwData/PointList.hpp>
17 #include <fwData/String.hpp>
18 
19 #include <fwDataTools/fieldHelper/Image.hpp>
20 
21 namespace fwGdcmIO
22 {
23 namespace reader
24 {
25 namespace tid
26 {
27 
28 //------------------------------------------------------------------------------
29 
30 Fiducial::Fiducial(const ::fwMedData::DicomSeries::csptr& dicomSeries,
31  const SPTR(::gdcm::Reader)& reader,
32  const ::fwGdcmIO::container::DicomInstance::sptr& instance,
33  const ::fwData::Image::sptr& image,
34  const ::fwLog::Logger::sptr& logger) :
35  ::fwGdcmIO::reader::tid::TemplateID< ::fwData::Image >(dicomSeries, reader, instance, image, logger)
36 {
37 }
38 
39 //------------------------------------------------------------------------------
40 
41 Fiducial::~Fiducial()
42 {
43 }
44 
45 //------------------------------------------------------------------------------
46 
47 void Fiducial::readNode(const SPTR(::fwGdcmIO::container::sr::DicomSRNode)& node)
48 {
49  if(node->getCodedAttribute() == ::fwGdcmIO::container::DicomCodedAttribute("122340", "DCM", "Fiducial feature") &&
50  !node->getSubNodeContainer().empty())
51  {
52  std::string label = "";
53  double x, y, z;
54  bool foundLandmark = false;
55  for(const SPTR(::fwGdcmIO::container::sr::DicomSRNode)& subNode : node->getSubNodeContainer())
56  {
57  // Read label
58  if(subNode->getCodedAttribute() ==
59  ::fwGdcmIO::container::DicomCodedAttribute("122369", "DCM", "Fiducial intent"))
60  {
62  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRTextNode >(subNode);
63  if(intentNode)
64  {
65  label = intentNode->getTextValue();
66  }
67  }
68  // 2D Coordinate
69  else if(subNode->getType() == "SCOORD")
70  {
72  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRSCoordNode >(subNode);
73  if(scoordNode && scoordNode->getGraphicType() == "POINT")
74  {
75  // Retrieve coordinates
76  ::fwGdcmIO::container::sr::DicomSRSCoordNode::GraphicDataContainerType coordinates =
77  scoordNode->getGraphicDataContainer();
78 
79  x = coordinates[0];
80  y = coordinates[1];
81 
82  if(!scoordNode->getSubNodeContainer().empty())
83  {
85  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRImageNode >(
86  *scoordNode->getSubNodeContainer().begin());
87  if(imageNode)
88  {
89  const int frameNumber = imageNode->getFrameNumber();
91  frameNumber);
92  foundLandmark = true;
93  }
94  }
95  }
96  }
97  // 3D Coordinate
98  else if(subNode->getType() == "SCOORD3D")
99  {
101  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRSCoord3DNode >(subNode);
102  if(scoord3DNode && scoord3DNode->getGraphicType() == "POINT")
103  {
104  // Retrieve coordinates
105  ::fwGdcmIO::container::sr::DicomSRSCoordNode::GraphicDataContainerType coordinates =
106  scoord3DNode->getGraphicDataContainer();
107  x = coordinates[0];
108  y = coordinates[1];
109  z = coordinates[2];
110  foundLandmark = true;
111  }
112  }
113 
114  }
115 
116  if(foundLandmark)
117  {
118  this->addLandmark(x, y, z, label);
119  }
120 
121  }
122 }
123 
124 //------------------------------------------------------------------------------
125 
126 void Fiducial::addLandmark(double x, double y, double z, const std::string& label)
127 {
128  ::fwData::Point::sptr point = ::fwData::Point::New(x, y, z);
129  point->setField(::fwDataTools::fieldHelper::Image::m_labelId, ::fwData::String::New(label));
130 
131  ::fwData::PointList::sptr pointList =
133 
134  if(!pointList)
135  {
136  pointList = ::fwData::PointList::New();
137  m_object->setField(::fwDataTools::fieldHelper::Image::m_imageLandmarksId, pointList);
138  }
139 
140  pointList->getPoints().push_back(point);
141  m_object->setField("ShowLandmarks", ::fwData::Boolean::New(true));
142 }
143 
144 //------------------------------------------------------------------------------
145 
146 } // namespace tid
147 } // namespace reader
148 } // namespace fwGdcmIO
#define SPTR(_cls_)
const SubNodeContainer & getSubNodeContainer() const
Get Sub node container.
Definition: DicomSRNode.hpp:53
static FWGDCMIO_API double convertFrameNumberToZCoordinate(const ::fwData::Image::csptr &image, const std::size_t frameNumber)
Convert a frame number to a Z coordinate.
This class defines a TEXT node in a SR document.
This class defines an IMAGE node in a SR document.
const GraphicDataContainerType & getGraphicDataContainer() const
Get Graphic data container.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
This class defines a node in a SR document.
Definition: DicomSRNode.hpp:27
const GraphicDataContainerType & getGraphicDataContainer() const
Get Graphic data container.
This class represents a DICOM basic coded entry. It stores the four mains attributes : Code Value...
This class defines a SCOORD node in a SR document.
static FWDATATOOLS_API const std::string m_labelId
to assign a label
This class defines a list of points.
Contains the representation of the data objects used in the framework.
const int & getFrameNumber() const
Get Frame number.
This class defines a SCOORD3D node in a SR document.
FWGDCMIO_API Fiducial(const std::shared_ptr< const ::fwMedData::DicomSeries > &dicomSeries, const std::shared_ptr< ::gdcm::Reader > &reader, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwData::Image::sptr &image, const ::fwLog::Logger::sptr &logger)
Constructor.
const DicomCodedAttribute & getCodedAttribute() const
Get Coded attribute.
Definition: DicomSRNode.hpp:65
const std::string & getTextValue() const
Get Text value.