fw4spl
reader/ie/SpatialFiducials.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/ie/SpatialFiducials.hpp"
8 
9 #include "fwGdcmIO/helper/DicomDataReader.hxx"
10 #include "fwGdcmIO/helper/DicomDataTools.hpp"
11 
12 #include <fwData/Image.hpp>
13 #include <fwData/PointList.hpp>
14 #include <fwData/String.hpp>
15 
16 #include <fwDataTools/fieldHelper/Image.hpp>
17 
18 #include <fwMedData/DicomSeries.hpp>
19 
20 namespace fwGdcmIO
21 {
22 namespace reader
23 {
24 namespace ie
25 {
26 
27 //------------------------------------------------------------------------------
28 
29 SpatialFiducials::SpatialFiducials(const ::fwMedData::DicomSeries::csptr& dicomSeries,
30  const SPTR(::gdcm::Reader)& reader,
31  const ::fwGdcmIO::container::DicomInstance::sptr& instance,
32  const ::fwData::Image::sptr& image,
33  const ::fwLog::Logger::sptr& logger,
34  ProgressCallback progress,
35  CancelRequestedCallback cancel) :
36  ::fwGdcmIO::reader::ie::InformationEntity< ::fwData::Image >(dicomSeries, reader, instance, image,
37  logger, progress, cancel)
38 {
39 }
40 
41 //------------------------------------------------------------------------------
42 
43 SpatialFiducials::~SpatialFiducials()
44 {
45 }
46 
47 //------------------------------------------------------------------------------
48 
49 void SpatialFiducials::readLandmark(const ::gdcm::DataSet& fiducialDataset)
50 {
51  ::fwData::PointList::sptr pointList =
53  if(!pointList)
54  {
55  pointList = ::fwData::PointList::New();
56  m_object->setField(::fwDataTools::fieldHelper::Image::m_imageLandmarksId, pointList);
57  }
58 
59  const ::gdcm::DataElement& graphicCoordinatesDataElement =
60  fiducialDataset.GetDataElement( ::gdcm::Tag(0x0070, 0x0318) );
61  const ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > graphicCoordinatesDataSequence =
62  graphicCoordinatesDataElement.GetValueAsSQ();
63 
64  const std::string label =
65  ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0070, 0x030F >(fiducialDataset);
66 
67  for(unsigned int i = 1; i <= graphicCoordinatesDataSequence->GetNumberOfItems(); ++i)
68  {
69  ::gdcm::Item graphicCoordinatesItem = graphicCoordinatesDataSequence->GetItem(i);
70  const ::gdcm::DataSet& graphicCoordinatesDataset = graphicCoordinatesItem.GetNestedDataSet();
71 
72  // 2D Points
73  ::gdcm::Attribute< 0x0070, 0x0022 > coordinatesAttribute;
74  coordinatesAttribute.SetFromDataElement(graphicCoordinatesDataset.GetDataElement(::gdcm::Tag(0x0070, 0x0022)));
75  const float* pointValues = coordinatesAttribute.GetValues();
76 
77  // Frame number
78  const ::gdcm::DataElement& referencedImageDataElement =
79  graphicCoordinatesDataset.GetDataElement( ::gdcm::Tag(0x0008, 0x1140) );
80  const ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > referencedImageDataSequence =
81  referencedImageDataElement.GetValueAsSQ();
82  ::gdcm::Item referencedImageItem = referencedImageDataSequence->GetItem(1);
83  ::gdcm::DataSet& referencedImageDataset = referencedImageItem.GetNestedDataSet();
84 
85  int frameNumber =
86  ::fwGdcmIO::helper::DicomDataReader::getTagValue< 0x0008, 0x1160, int >(referencedImageDataset);
87  double zCoordinate =
89 
90  ::fwData::Point::sptr point = ::fwData::Point::New(static_cast<double>(pointValues[0]),
91  static_cast<double>(pointValues[1]), zCoordinate);
92  point->setField(::fwDataTools::fieldHelper::Image::m_labelId, ::fwData::String::New(label));
93  pointList->getPoints().push_back(point);
94 
95  }
96 }
97 
98 //------------------------------------------------------------------------------
99 
100 } // namespace ie
101 } // namespace reader
102 } // namespace fwGdcmIO
#define SPTR(_cls_)
static FWGDCMIO_API double convertFrameNumberToZCoordinate(const ::fwData::Image::csptr &image, const std::size_t frameNumber)
Convert a frame number to a Z coordinate.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
static FWDATATOOLS_API const std::string m_labelId
to assign a label
This class defines a list of points.
FWGDCMIO_API SpatialFiducials(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 &series, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
Contains the representation of the data objects used in the framework.