Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/ImageAccessor.h @ 4337:7707fa761b71
OrthancImport.py sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Dec 2020 11:01:59 +0100 |
parents | b30a8de92ad9 |
children | d9473bd5ed43 |
rev | line source |
---|---|
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
983
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #pragma once |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
25 #include "../Compatibility.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "../Enumerations.h" |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
1396
ac4efabeb80c
Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
28 #include <string> |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
29 #include <stdint.h> |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
30 #include <boost/noncopyable.hpp> |
1396
ac4efabeb80c
Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
31 |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 namespace Orthanc |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 { |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
34 class ORTHANC_PUBLIC ImageAccessor : public boost::noncopyable |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 private: |
4297 | 37 template <PixelFormat Format> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
38 friend struct ImageTraits; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
39 |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 bool readOnly_; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 PixelFormat format_; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 unsigned int width_; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 unsigned int height_; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 unsigned int pitch_; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
45 uint8_t *buffer_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
47 template <typename T> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
48 const T& GetPixelUnchecked(unsigned int x, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
49 unsigned int y) const |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
50 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
51 const uint8_t* row = reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
52 return reinterpret_cast<const T*>(row) [x]; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
53 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
54 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
55 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
56 template <typename T> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
57 T& GetPixelUnchecked(unsigned int x, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
58 unsigned int y) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
59 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
60 uint8_t* row = reinterpret_cast<uint8_t*>(buffer_) + y * pitch_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
61 return reinterpret_cast<T*>(row) [x]; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
62 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
63 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
64 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
65 // Alias for binary compatibility with Orthanc Framework 1.7.2 => don't use it anymore |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
66 void* GetBuffer() const; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
67 void* GetRow(unsigned int y) const; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
68 #endif |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
69 |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 public: |
4300 | 71 ImageAccessor(); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
4300 | 73 virtual ~ImageAccessor(); |
1605 | 74 |
4300 | 75 bool IsReadOnly() const; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
4300 | 77 PixelFormat GetFormat() const; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
4300 | 79 unsigned int GetBytesPerPixel() const; |
983
80d4f1618b33
Sample plugin to replace DCMTK by GDCM when decoding images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
80 |
4300 | 81 unsigned int GetWidth() const; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
4300 | 83 unsigned int GetHeight() const; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
4300 | 85 unsigned int GetPitch() const; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
4300 | 87 unsigned int GetSize() const; |
844 | 88 |
4300 | 89 const void* GetConstBuffer() const; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
4201 | 91 void* GetBuffer(); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 const void* GetConstRow(unsigned int y) const; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
4201 | 95 void* GetRow(unsigned int y); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 void AssignEmpty(PixelFormat format); |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 void AssignReadOnly(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 const void *buffer); |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 |
4300 | 105 void GetReadOnlyAccessor(ImageAccessor& target) const; |
2865
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
106 |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 void AssignWritable(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 void *buffer); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
844
diff
changeset
|
112 |
2865
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
113 void GetWriteableAccessor(ImageAccessor& target) const; |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
114 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
844
diff
changeset
|
115 void ToMatlabString(std::string& target) const; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
116 |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
117 void GetRegion(ImageAccessor& accessor, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
118 unsigned int x, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
119 unsigned int y, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
120 unsigned int width, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
121 unsigned int height) const; |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
122 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
123 void SetFormat(PixelFormat format); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 }; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 } |