fw4spl
reader/tid/Measurement.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/Measurement.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 #include <fwData/Vector.hpp>
19 
20 #include <fwDataTools/fieldHelper/Image.hpp>
21 
22 namespace fwGdcmIO
23 {
24 namespace reader
25 {
26 namespace tid
27 {
28 
29 //------------------------------------------------------------------------------
30 
31 Measurement::Measurement(const ::fwMedData::DicomSeries::csptr& dicomSeries,
32  const SPTR(::gdcm::Reader)& reader,
33  const ::fwGdcmIO::container::DicomInstance::sptr& instance,
34  const ::fwData::Image::sptr& image,
35  const ::fwLog::Logger::sptr& logger) :
36  ::fwGdcmIO::reader::tid::TemplateID< ::fwData::Image >(dicomSeries, reader, instance, image, logger)
37 {
38 }
39 
40 //------------------------------------------------------------------------------
41 
42 Measurement::~Measurement()
43 {
44 }
45 
46 //------------------------------------------------------------------------------
47 
48 void Measurement::readNode(const SPTR(::fwGdcmIO::container::sr::DicomSRNode)& node)
49 {
50  if(node->getCodedAttribute() == ::fwGdcmIO::container::DicomCodedAttribute("121206", "DCM", "Distance") &&
51  !node->getSubNodeContainer().empty())
52  {
53  for(const SPTR(::fwGdcmIO::container::sr::DicomSRNode)& subNode : node->getSubNodeContainer())
54  {
55  if(subNode->getType() == "SCOORD")
56  {
58  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRSCoordNode >(subNode);
59  if(scoordNode && scoordNode->getGraphicType() == "POLYLINE")
60  {
61  // Retrieve coordinates
62  ::fwGdcmIO::container::sr::DicomSRSCoordNode::GraphicDataContainerType coordinates =
63  scoordNode->getGraphicDataContainer();
64 
65  if(!scoordNode->getSubNodeContainer().empty())
66  {
68  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRImageNode >(
69  *scoordNode->getSubNodeContainer().begin());
70  if(imageNode)
71  {
72  const int frameNumber = imageNode->getFrameNumber();
74  m_object, frameNumber);
75 
76  auto origin = ::fwData::Point::New(static_cast<double>(coordinates[0]),
77  static_cast<double>(coordinates[1]), zCoordinate);
78  auto destination = ::fwData::Point::New(static_cast<double>(coordinates[2]),
79  static_cast<double>(coordinates[3]), zCoordinate);
80  this->addDistance(origin, destination);
81  }
82  }
83  }
84  }
85  // 3D Coordinate
86  else if(subNode->getType() == "SCOORD3D")
87  {
89  std::dynamic_pointer_cast< ::fwGdcmIO::container::sr::DicomSRSCoord3DNode >(subNode);
90  if(scoord3DNode && scoord3DNode->getGraphicType() == "POLYLINE")
91  {
92  // Retrieve coordinates
93  ::fwGdcmIO::container::sr::DicomSRSCoordNode::GraphicDataContainerType coordinates =
94  scoord3DNode->getGraphicDataContainer();
95  this->addDistance(::fwData::Point::New(coordinates[0], coordinates[1], coordinates[2]),
96  ::fwData::Point::New(coordinates[3], coordinates[4], coordinates[5]));
97  }
98  }
99  }
100  }
101 }
102 
103 //------------------------------------------------------------------------------
104 
105 void Measurement::addDistance(const SPTR(::fwData::Point)& point1,
106  const SPTR(::fwData::Point)& point2)
107 {
108  ::fwData::Vector::sptr distanceVector =
110 
111  if(!distanceVector)
112  {
113  distanceVector = ::fwData::Vector::New();
114  m_object->setField(::fwDataTools::fieldHelper::Image::m_imageDistancesId, distanceVector);
115  }
116 
117  ::fwData::PointList::sptr pointList = ::fwData::PointList::New();
118  pointList->getPoints().push_back(point1);
119  pointList->getPoints().push_back(point2);
120 
121  distanceVector->getContainer().push_back(pointList);
122  m_object->setField("ShowDistances", ::fwData::Boolean::New(true));
123 }
124 
125 //------------------------------------------------------------------------------
126 
127 } // namespace tid
128 } // namespace reader
129 } // namespace fwGdcmIO
#define SPTR(_cls_)
FWGDCMIO_API Measurement(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 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 define a 3D point.
Definition: Point.hpp:22
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 defines a vector of objects.
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.
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.
const DicomCodedAttribute & getCodedAttribute() const
Get Coded attribute.
Definition: DicomSRNode.hpp:65