Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/SortedFrames.cpp @ 1842:9568082ee013
If available, use ZIP streaming from Orthanc >= 1.9.4 to create archives
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 24 Jun 2021 14:19:36 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1649
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "SortedFrames.h" |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
1490
5d892f5dd9c4
SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1485
diff
changeset
|
25 #include "GeometryToolbox.h" |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
1631
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
27 #include <Logging.h> |
1490
5d892f5dd9c4
SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1485
diff
changeset
|
28 #include <OrthancException.h> |
5d892f5dd9c4
SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1485
diff
changeset
|
29 #include <Toolbox.h> |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 namespace OrthancStone |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
33 SortedFrames::Frame::Frame(const DicomInstanceParameters& instance, |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
34 unsigned int frameNumber) : |
1485 | 35 instance_(&instance), |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
36 frameNumber_(frameNumber) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
38 if (frameNumber >= instance.GetNumberOfFrames()) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
1648
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
45 double SortedFrames::Frame::ComputeDistance(const Vector& p) const |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
46 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
47 const CoordinateSystem3D& plane = instance_->GetFrameGeometry(frameNumber_); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
48 return plane.ComputeDistance(p); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
49 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
50 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
51 |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
52 const DicomInstanceParameters& SortedFrames::GetInstance(size_t instanceIndex) const |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
54 if (instanceIndex >= instances_.size()) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 else |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
60 assert(instances_[instanceIndex] != NULL); |
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
61 return *instances_[instanceIndex]; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
66 const SortedFrames::Frame& SortedFrames::GetFrame(size_t frameIndex) const |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 if (!sorted_) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 "Sort() has not been called"); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 } |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
73 if (frameIndex >= frames_.size()) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 else |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 { |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
79 return frames_[frameIndex]; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
1479
5e3cfe87a873
SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1478
diff
changeset
|
84 void SortedFrames::Clear() |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 for (size_t i = 0; i < instances_.size(); i++) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 assert(instances_[i] != NULL); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 delete instances_[i]; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 } |
1479
5e3cfe87a873
SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1478
diff
changeset
|
91 |
5e3cfe87a873
SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1478
diff
changeset
|
92 studyInstanceUid_.clear(); |
5e3cfe87a873
SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1478
diff
changeset
|
93 seriesInstanceUid_.clear(); |
5e3cfe87a873
SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1478
diff
changeset
|
94 frames_.clear(); |
1602
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
95 |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
96 instancesIndex_.clear(); |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
97 framesIndex_.clear(); |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
98 |
1479
5e3cfe87a873
SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1478
diff
changeset
|
99 sorted_ = true; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 void SortedFrames::AddInstance(const Orthanc::DicomMap& tags) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 { |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
105 std::unique_ptr<DicomInstanceParameters> instance(new DicomInstanceParameters(tags)); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 if (instances_.empty()) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 { |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
109 studyInstanceUid_ = instance->GetStudyInstanceUid(); |
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
110 seriesInstanceUid_ = instance->GetSeriesInstanceUid(); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 else |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 { |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
114 if (studyInstanceUid_ != instance->GetStudyInstanceUid() || |
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
115 seriesInstanceUid_ != instance->GetSeriesInstanceUid()) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 "Mixing instances from different series"); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
122 if (instancesIndex_.find(instance->GetSopInstanceUid()) != instancesIndex_.end()) |
1599
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
123 { |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
124 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
125 "Cannot register twice the same SOP Instance UID"); |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
126 } |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
127 |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
128 instancesIndex_[instance->GetSopInstanceUid()] = instances_.size(); |
1599
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
129 |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 instances_.push_back(instance.release()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 sorted_ = false; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 frames_.clear(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 |
1599
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
136 bool SortedFrames::LookupSopInstanceUid(size_t& instanceIndex, |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
137 const std::string& sopInstanceUid) const |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
138 { |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
139 InstancesIndex::const_iterator found = instancesIndex_.find(sopInstanceUid); |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
140 |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
141 if (found == instancesIndex_.end()) |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
142 { |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
143 return false; |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
144 } |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
145 else |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
146 { |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
147 instanceIndex = found->second; |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
148 return true; |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
149 } |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
150 } |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
151 |
73cd85d7da6a
SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
152 |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 void SortedFrames::AddFramesOfInstance(std::set<size_t>& remainingInstances, |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
154 size_t instanceIndex) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 { |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
156 assert(instances_[instanceIndex] != NULL); |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
157 const DicomInstanceParameters& instance = *instances_[instanceIndex]; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 { |
1602
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
161 framesIndex_[std::make_pair(instance.GetSopInstanceUid(), i)] = frames_.size(); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 frames_.push_back(Frame(instance, i)); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
165 assert(remainingInstances.find(instanceIndex) != remainingInstances.end()); |
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
166 remainingInstances.erase(instanceIndex); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 namespace |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 template<typename T> |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 class SortableItem |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 private: |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 T value_; |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
177 size_t instanceIndex_; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 std::string sopInstanceUid_; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 public: |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 SortableItem(const T& value, |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
182 size_t instanceIndex, |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 const std::string& sopInstanceUid) : |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 value_(value), |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
185 instanceIndex_(instanceIndex), |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 sopInstanceUid_(sopInstanceUid) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 size_t GetInstanceIndex() const |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 { |
1600
b253b79906fa
clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1599
diff
changeset
|
192 return instanceIndex_; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 bool operator< (const SortableItem& other) const |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 return (value_ < other.value_ || |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 (value_ == other.value_ && |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 sopInstanceUid_ < other.sopInstanceUid_)); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 }; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 void SortedFrames::SortUsingIntegerTag(std::set<size_t>& remainingInstances, |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 const Orthanc::DicomTag& tag) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 std::vector< SortableItem<int32_t> > items; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 items.reserve(remainingInstances.size()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 it != remainingInstances.end(); ++it) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 assert(instances_[*it] != NULL); |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
215 const DicomInstanceParameters& instance = *instances_[*it]; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 int32_t value; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 std::string sopInstanceUid; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 if (instance.GetTags().ParseInteger32(value, tag) && |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 instance.GetTags().LookupStringValue( |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 items.push_back(SortableItem<int32_t>(value, *it, sopInstanceUid)); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 std::sort(items.begin(), items.end()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 for (size_t i = 0; i < items.size(); i++) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 void SortedFrames::SortUsingSopInstanceUid(std::set<size_t>& remainingInstances) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 std::vector<SortableItem<int32_t> > items; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 items.reserve(remainingInstances.size()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 it != remainingInstances.end(); ++it) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 assert(instances_[*it] != NULL); |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
245 const DicomInstanceParameters& instance = *instances_[*it]; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 std::string sopInstanceUid; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 if (instance.GetTags().LookupStringValue( |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 items.push_back(SortableItem<int32_t>(0 /* arbitrary value */, *it, sopInstanceUid)); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 std::sort(items.begin(), items.end()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 for (size_t i = 0; i < items.size(); i++) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 void SortedFrames::SortUsing3DLocation(std::set<size_t>& remainingInstances) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 /** |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 * Compute the mean of the normal vectors, using the recursive |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 * formula for arithmetic means for numerical stability. |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 * https://diego.assencio.com/?index=c34d06f4f4de2375658ed41f70177d59 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 **/ |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 Vector meanNormal; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 LinearAlgebra::AssignVector(meanNormal, 0, 0, 0); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 unsigned int n = 0; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 it != remainingInstances.end(); ++it) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 assert(instances_[*it] != NULL); |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
281 const DicomInstanceParameters& instance = *instances_[*it]; |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1605
diff
changeset
|
283 if (instance.GetGeometry().IsValid()) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 n += 1; |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1605
diff
changeset
|
286 meanNormal += (instance.GetGeometry().GetNormal() - meanNormal) / static_cast<float>(n); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 std::vector<SortableItem<float> > items; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 items.reserve(n); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 it != remainingInstances.end(); ++it) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 assert(instances_[*it] != NULL); |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
297 const DicomInstanceParameters& instance = *instances_[*it]; |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1605
diff
changeset
|
298 |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 std::string sopInstanceUid; |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1605
diff
changeset
|
300 if (instance.GetGeometry().IsValid() && |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 instance.GetTags().LookupStringValue( |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1605
diff
changeset
|
304 double p = LinearAlgebra::DotProduct(meanNormal, instance.GetGeometry().GetOrigin()); |
1605 | 305 items.push_back(SortableItem<float>(static_cast<float>(p), *it, sopInstanceUid)); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 assert(items.size() <= n); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 std::sort(items.begin(), items.end()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 for (size_t i = 0; i < items.size(); i++) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex()); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 size_t SortedFrames::GetFramesCount() const |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 if (sorted_) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 return frames_.size(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 else |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 "Sort() has not been called"); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 |
1631
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
334 CoordinateSystem3D SortedFrames::GetFrameGeometry(size_t frameIndex) const |
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
335 { |
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
336 const Frame& frame = GetFrame(frameIndex); |
1643
882e2253a90e
replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1631
diff
changeset
|
337 return frame.GetInstance().GetFrameGeometry(frame.GetFrameNumberInInstance()); |
1631
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
338 } |
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
339 |
960bb5fcc440
SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
340 |
1602
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
341 bool SortedFrames::LookupFrame(size_t& frameIndex, |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
342 const std::string& sopInstanceUid, |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
343 unsigned int frameNumber) const |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
344 { |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
345 if (sorted_) |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
346 { |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
347 FramesIndex::const_iterator found = framesIndex_.find( |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
348 std::make_pair(sopInstanceUid, frameNumber)); |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
349 |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
350 if (found == framesIndex_.end()) |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
351 { |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
352 return false; |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
353 } |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
354 else |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
355 { |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
356 frameIndex = found->second; |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
357 return true; |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
358 } |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
359 } |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
360 else |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
361 { |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
362 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
363 "Sort() has not been called"); |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
364 } |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
365 } |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
366 |
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
367 |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 void SortedFrames::Sort() |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 if (!sorted_) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 size_t totalFrames = 0; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 std::set<size_t> remainingInstances; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 for (size_t i = 0; i < instances_.size(); i++) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 assert(instances_[i] != NULL); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 totalFrames += instances_[i]->GetNumberOfFrames(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 remainingInstances.insert(i); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 frames_.clear(); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 frames_.reserve(totalFrames); |
1602
b2941196cabf
SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1600
diff
changeset
|
385 framesIndex_.clear(); |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_INSTANCE_NUMBER); // VR is "IS" |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_IMAGE_INDEX); // VR is "US" |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 SortUsing3DLocation(remainingInstances); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 SortUsingSopInstanceUid(remainingInstances); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 // The following could in theory happen if several instances |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 // have the same SOPInstanceUID, no ordering is available |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
394 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); |
1571 | 395 it != remainingInstances.end(); ++it) |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 AddFramesOfInstance(remainingInstances, *it); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 if (frames_.size() != totalFrames || |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 !remainingInstances.empty()) |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 { |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 sorted_ = true; |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 } |
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 } |
1648
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
409 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
410 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
411 bool SortedFrames::FindClosestFrame(size_t& frameIndex, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
412 const Vector& point, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
413 double maximumDistance) const |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
414 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
415 if (sorted_) |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
416 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
417 if (frames_.empty()) |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
418 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
419 return false; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
420 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
421 else |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
422 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
423 frameIndex = 0; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
424 double closestDistance = frames_[0].ComputeDistance(point); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
425 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
426 for (size_t i = 1; i < frames_.size(); i++) |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
427 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
428 double d = frames_[i].ComputeDistance(point); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
429 if (d < closestDistance) |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
430 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
431 frameIndex = i; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
432 closestDistance = d; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
433 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
434 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
435 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
436 return (closestDistance <= maximumDistance); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
437 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
438 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
439 else |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
440 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
441 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
442 "Sort() has not been called"); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
443 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1643
diff
changeset
|
444 } |
1478
fab6c6e795a3
Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 } |