fw4spl
core/fwMedData/src/fwMedData/DicomSeries.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 "fwMedData/DicomSeries.hpp"
8 
9 #include <fwData/Exception.hpp>
10 #include <fwData/registry/macros.hpp>
11 
12 #include <fwMemory/stream/in/Raw.hpp>
13 
14 #include <boost/filesystem/operations.hpp>
15 
16 fwDataRegisterMacro( ::fwMedData::DicomSeries );
17 
18 namespace fwMedData
19 {
20 
22  Series(key),
23  m_numberOfInstances(0),
24  m_firstInstanceNumber(0)
25 {
26 }
27 
28 //------------------------------------------------------------------------------
29 
31 {
32 }
33 
34 //------------------------------------------------------------------------------
35 
36 void DicomSeries::shallowCopy(const ::fwData::Object::csptr& _source)
37 {
38  DicomSeries::csptr other = DicomSeries::dynamicConstCast(_source);
39  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
40  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
41  + " to " + this->getClassname()), !bool(other) );
42 
43  this->::fwMedData::Series::shallowCopy(_source);
44 
45  m_numberOfInstances = other->m_numberOfInstances;
46  m_dicomContainer = other->m_dicomContainer;
47  m_SOPClassUIDs = other->m_SOPClassUIDs;
48  m_computedTagValues = other->m_computedTagValues;
49  m_firstInstanceNumber = other->m_firstInstanceNumber;
50 }
51 
52 //------------------------------------------------------------------------------
53 
54 void DicomSeries::cachedDeepCopy(const ::fwData::Object::csptr& _source, DeepCopyCacheType& cache)
55 {
56  DicomSeries::csptr other = DicomSeries::dynamicConstCast(_source);
57  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
58  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
59  + " to " + this->getClassname()), !bool(other) );
60 
61  this->::fwMedData::Series::cachedDeepCopy(_source, cache);
62 
63  m_numberOfInstances = other->m_numberOfInstances;
64  m_SOPClassUIDs = other->m_SOPClassUIDs;
65  m_computedTagValues = other->m_computedTagValues;
66  m_firstInstanceNumber = other->m_firstInstanceNumber;
67 
68  m_dicomContainer.clear();
69  for(const auto& elt : other->m_dicomContainer)
70  {
71  const ::fwMemory::BufferObject::sptr& bufferSrc = elt.second;
72  ::fwMemory::BufferObject::Lock lockerSource(bufferSrc);
73 
74  if( !bufferSrc->isEmpty() )
75  {
76  ::fwMemory::BufferObject::sptr bufferDest = ::fwMemory::BufferObject::New();
77  ::fwMemory::BufferObject::Lock lockerDest(bufferDest);
78 
79  bufferDest->allocate(bufferSrc->getSize());
80 
81  char* buffDest = static_cast< char* >( lockerDest.getBuffer() );
82  char* buffSrc = static_cast< char* >( lockerSource.getBuffer() );
83  std::copy(buffSrc, buffSrc + bufferSrc->getSize(), buffDest );
84 
85  m_dicomContainer[elt.first] = bufferDest;
86  }
87  }
88 }
89 
90 //------------------------------------------------------------------------------
91 
92 void DicomSeries::addDicomPath(std::size_t instanceIndex, const ::boost::filesystem::path& path)
93 {
94  ::fwMemory::BufferObject::sptr buffer = ::fwMemory::BufferObject::New();
95  const size_t buffSize = ::boost::filesystem::file_size(path);
96  buffer->setIStreamFactory( std::make_shared< ::fwMemory::stream::in::Raw >(path),
97  buffSize, path, ::fwMemory::RAW);
98  m_dicomContainer[instanceIndex] = buffer;
99 }
100 
101 //------------------------------------------------------------------------------
102 
103 void DicomSeries::addBinary(std::size_t instanceIndex, const ::fwMemory::BufferObject::sptr& buffer)
104 {
105  m_dicomContainer[instanceIndex] = buffer;
106 }
107 
108 //------------------------------------------------------------------------------
109 
110 bool DicomSeries::isInstanceAvailable(std::size_t instanceIndex) const
111 {
112  const auto& dicomContainerIter = m_dicomContainer.find(instanceIndex);
113  return (dicomContainerIter != m_dicomContainer.end());
114 }
115 
116 //------------------------------------------------------------------------------
117 
118 void DicomSeries::addSOPClassUID(const std::string& sopClassUID)
119 {
120  m_SOPClassUIDs.insert(sopClassUID);
121 }
122 
123 //------------------------------------------------------------------------------
124 
125 void DicomSeries::addComputedTagValue(const std::string& tagName, const std::string& value)
126 {
127  m_computedTagValues[tagName] = value;
128 }
129 
130 //------------------------------------------------------------------------------
131 
132 bool DicomSeries::hasComputedValues(const std::string& tagName) const
133 {
134  return m_computedTagValues.find(tagName) != m_computedTagValues.end();
135 }
136 
137 } // namespace fwMedData
FWMEDDATA_API void addSOPClassUID(const std::string &sopClassUID)
Add a SOPClassUID that is used by this series.
std::size_t m_firstInstanceNumber
First instance number (0 or 1) - Used for PACS preview.
FWMEDDATA_API void addComputedTagValue(const std::string &tagName, const std::string &value)
Add a computed value to the specified tag.
Namespace containing medical data.
FWMEDDATA_API void shallowCopy(const ::fwData::Object::csptr &_source) override
Defines shallow copy.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
Implements data exception class.
FWMEDDATA_API void cachedDeepCopy(const ::fwData::Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.
size_t m_numberOfInstances
Number of instances in the series (0020,1209)
ComputedTagValueContainerType m_computedTagValues
Computed tag values.
base class for BufferObject Lock
virtual const std::string & getClassname() const override
return full object&#39;s classname with its namespace, i.e. fwCore::BaseObject
FWMEDDATA_API void addBinary(std::size_t instanceIndex, const ::fwMemory::BufferObject::sptr &buffer)
Add binary buffer.
DicomContainerType m_dicomContainer
Dicom container.
virtual FWMEDDATA_API ~DicomSeries() override
Destructor.
LockBase< T >::BufferType getBuffer() const
Returns BufferObject&#39;s buffer pointer.
SOPClassUIDContainerType m_SOPClassUIDs
SOP Class UIDs.
FWMEDDATA_API void addDicomPath(std::size_t instanceIndex, const ::boost::filesystem::path &path)
Add dicom path.
FWMEDDATA_API void cachedDeepCopy(const ::fwData::Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.
FWMEDDATA_API bool isInstanceAvailable(std::size_t instanceIndex) const
Return true if the instance is available on the local computer.
FWMEDDATA_API void shallowCopy(const ::fwData::Object::csptr &_source) override
Defines shallow copy.
FWMEDDATA_API DicomSeries(::fwData::Object::Key key)
Constructor.
FWMEDDATA_API bool hasComputedValues(const std::string &tagName) const
Return true if there is a computed value for the specified tag.