annotate OrthancStone/Sources/Toolbox/SortedFrames.cpp @ 1964:2034ae383cfd deep-learning

integration default->deep-learning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 28 Oct 2022 07:47:55 +0200
parents 7053b8a0aaec
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * 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
15 * 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
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "SortedFrames.h"
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1490
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
26 #include "GeometryToolbox.h"
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1631
960bb5fcc440 SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
28 #include <Logging.h>
1490
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
29 #include <OrthancException.h>
5d892f5dd9c4 SortedFrames::IsFrameMonochrome1()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
30 #include <Toolbox.h>
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace OrthancStone
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
34 SortedFrames::Frame::Frame(const DicomInstanceParameters& instance,
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
35 unsigned int frameNumber) :
1485
60be4627ae52 fix for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1479
diff changeset
36 instance_(&instance),
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
37 frameNumber_(frameNumber)
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
39 if (frameNumber >= instance.GetNumberOfFrames())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
1648
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
46 double SortedFrames::Frame::ComputeDistance(const Vector& p) const
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
47 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
48 const CoordinateSystem3D& plane = instance_->GetFrameGeometry(frameNumber_);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
49 return plane.ComputeDistance(p);
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
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
52
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
53 const DicomInstanceParameters& SortedFrames::GetInstance(size_t instanceIndex) const
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
55 if (instanceIndex >= instances_.size())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
61 assert(instances_[instanceIndex] != NULL);
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
62 return *instances_[instanceIndex];
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
67 const SortedFrames::Frame& SortedFrames::GetFrame(size_t frameIndex) const
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (!sorted_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 "Sort() has not been called");
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
74 if (frameIndex >= frames_.size())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
80 return frames_[frameIndex];
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
1479
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
85 void SortedFrames::Clear()
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 for (size_t i = 0; i < instances_.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 assert(instances_[i] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 delete instances_[i];
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
1479
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
92
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
93 studyInstanceUid_.clear();
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
94 seriesInstanceUid_.clear();
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
95 frames_.clear();
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
96
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
97 instancesIndex_.clear();
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
98 framesIndex_.clear();
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
99
1479
5e3cfe87a873 SortedFrames::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1478
diff changeset
100 sorted_ = true;
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 void SortedFrames::AddInstance(const Orthanc::DicomMap& tags)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
106 std::unique_ptr<DicomInstanceParameters> instance(new DicomInstanceParameters(tags));
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (instances_.empty())
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
110 studyInstanceUid_ = instance->GetStudyInstanceUid();
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
111 seriesInstanceUid_ = instance->GetSeriesInstanceUid();
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
115 if (studyInstanceUid_ != instance->GetStudyInstanceUid() ||
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
116 seriesInstanceUid_ != instance->GetSeriesInstanceUid())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 "Mixing instances from different series");
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 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
123 if (instancesIndex_.find(instance->GetSopInstanceUid()) != instancesIndex_.end())
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
124 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
126 "Cannot register twice the same SOP Instance UID");
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
127 }
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
128
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
129 instancesIndex_[instance->GetSopInstanceUid()] = instances_.size();
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
130
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 instances_.push_back(instance.release());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 sorted_ = false;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 frames_.clear();
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
1599
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
137 bool SortedFrames::LookupSopInstanceUid(size_t& instanceIndex,
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
138 const std::string& sopInstanceUid) const
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
139 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
140 InstancesIndex::const_iterator found = instancesIndex_.find(sopInstanceUid);
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
141
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
142 if (found == instancesIndex_.end())
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
143 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
144 return false;
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
145 }
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
146 else
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
147 {
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
148 instanceIndex = found->second;
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
149 return true;
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
73cd85d7da6a SortedFrames::LookupSopInstanceUid()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
153
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 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
155 size_t instanceIndex)
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
157 assert(instances_[instanceIndex] != NULL);
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
158 const DicomInstanceParameters& instance = *instances_[instanceIndex];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
162 framesIndex_[std::make_pair(instance.GetSopInstanceUid(), i)] = frames_.size();
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 frames_.push_back(Frame(instance, i));
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
166 assert(remainingInstances.find(instanceIndex) != remainingInstances.end());
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
167 remainingInstances.erase(instanceIndex);
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 namespace
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 template<typename T>
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 class SortableItem
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 private:
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 T value_;
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
178 size_t instanceIndex_;
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 std::string sopInstanceUid_;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 public:
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 SortableItem(const T& value,
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
183 size_t instanceIndex,
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 const std::string& sopInstanceUid) :
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 value_(value),
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
186 instanceIndex_(instanceIndex),
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 sopInstanceUid_(sopInstanceUid)
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 size_t GetInstanceIndex() const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
1600
b253b79906fa clarifying variable names: frameIndex vs numberIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1599
diff changeset
193 return instanceIndex_;
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 bool operator< (const SortableItem& other) const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 return (value_ < other.value_ ||
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 (value_ == other.value_ &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 sopInstanceUid_ < other.sopInstanceUid_));
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 void SortedFrames::SortUsingIntegerTag(std::set<size_t>& remainingInstances,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 const Orthanc::DicomTag& tag)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 std::vector< SortableItem<int32_t> > items;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 items.reserve(remainingInstances.size());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 assert(instances_[*it] != NULL);
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
216 const DicomInstanceParameters& instance = *instances_[*it];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 int32_t value;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 std::string sopInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 if (instance.GetTags().ParseInteger32(value, tag) &&
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 instance.GetTags().LookupStringValue(
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 items.push_back(SortableItem<int32_t>(value, *it, sopInstanceUid));
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 std::sort(items.begin(), items.end());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 for (size_t i = 0; i < items.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex());
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 void SortedFrames::SortUsingSopInstanceUid(std::set<size_t>& remainingInstances)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 std::vector<SortableItem<int32_t> > items;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 items.reserve(remainingInstances.size());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 assert(instances_[*it] != NULL);
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
246 const DicomInstanceParameters& instance = *instances_[*it];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 std::string sopInstanceUid;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 if (instance.GetTags().LookupStringValue(
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 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
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 std::sort(items.begin(), items.end());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 for (size_t i = 0; i < items.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex());
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 void SortedFrames::SortUsing3DLocation(std::set<size_t>& remainingInstances)
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 /**
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 * Compute the mean of the normal vectors, using the recursive
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 * formula for arithmetic means for numerical stability.
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 * https://diego.assencio.com/?index=c34d06f4f4de2375658ed41f70177d59
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 Vector meanNormal;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 LinearAlgebra::AssignVector(meanNormal, 0, 0, 0);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 unsigned int n = 0;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 assert(instances_[*it] != NULL);
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
282 const DicomInstanceParameters& instance = *instances_[*it];
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1605
diff changeset
284 if (instance.GetGeometry().IsValid())
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 n += 1;
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1605
diff changeset
287 meanNormal += (instance.GetGeometry().GetNormal() - meanNormal) / static_cast<float>(n);
1478
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 std::vector<SortableItem<float> > items;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 items.reserve(n);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 it != remainingInstances.end(); ++it)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 assert(instances_[*it] != NULL);
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
298 const DicomInstanceParameters& instance = *instances_[*it];
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1605
diff changeset
299
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 std::string sopInstanceUid;
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1605
diff changeset
301 if (instance.GetGeometry().IsValid() &&
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 instance.GetTags().LookupStringValue(
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1605
diff changeset
305 double p = LinearAlgebra::DotProduct(meanNormal, instance.GetGeometry().GetOrigin());
1605
b3c439d96d3e warning fix
Benjamin Golinvaux <bgo@osimis.io>
parents: 1602
diff changeset
306 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
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 assert(items.size() <= n);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 std::sort(items.begin(), items.end());
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 for (size_t i = 0; i < items.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex());
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 size_t SortedFrames::GetFramesCount() const
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 if (sorted_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 return frames_.size();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 else
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 "Sort() has not been called");
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
1631
960bb5fcc440 SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
335 CoordinateSystem3D SortedFrames::GetFrameGeometry(size_t frameIndex) const
960bb5fcc440 SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
336 {
960bb5fcc440 SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
337 const Frame& frame = GetFrame(frameIndex);
1643
882e2253a90e replacing SortedFrames::Instance by DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1631
diff changeset
338 return frame.GetInstance().GetFrameGeometry(frame.GetFrameNumberInInstance());
1631
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
960bb5fcc440 SortedFrames::GetFrameGeometry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
341
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
342 bool SortedFrames::LookupFrame(size_t& frameIndex,
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
343 const std::string& sopInstanceUid,
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
344 unsigned int frameNumber) const
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
345 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
346 if (sorted_)
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
347 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
348 FramesIndex::const_iterator found = framesIndex_.find(
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
349 std::make_pair(sopInstanceUid, frameNumber));
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
350
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
351 if (found == framesIndex_.end())
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
352 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
353 return false;
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
354 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
355 else
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
356 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
357 frameIndex = found->second;
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
358 return true;
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 }
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
361 else
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
362 {
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
363 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
364 "Sort() has not been called");
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
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
368
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 void SortedFrames::Sort()
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (!sorted_)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 size_t totalFrames = 0;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 std::set<size_t> remainingInstances;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 for (size_t i = 0; i < instances_.size(); i++)
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 assert(instances_[i] != NULL);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 totalFrames += instances_[i]->GetNumberOfFrames();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 remainingInstances.insert(i);
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 frames_.clear();
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 frames_.reserve(totalFrames);
1602
b2941196cabf SortedFrames::LookupFrame()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1600
diff changeset
386 framesIndex_.clear();
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_INSTANCE_NUMBER); // VR is "IS"
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_IMAGE_INDEX); // VR is "US"
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 SortUsing3DLocation(remainingInstances);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 SortUsingSopInstanceUid(remainingInstances);
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 // The following could in theory happen if several instances
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 // have the same SOPInstanceUID, no ordering is available
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 for (std::set<size_t>::const_iterator it = remainingInstances.begin();
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
396 it != remainingInstances.end(); ++it)
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 AddFramesOfInstance(remainingInstances, *it);
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 if (frames_.size() != totalFrames ||
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 !remainingInstances.empty())
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
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
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 sorted_ = true;
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
1648
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
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
412 bool SortedFrames::FindClosestFrame(size_t& frameIndex,
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
413 const Vector& point,
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
414 double maximumDistance) const
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
415 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
416 if (sorted_)
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
417 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
418 if (frames_.empty())
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
419 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
420 return false;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
421 }
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
422 else
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
423 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
424 frameIndex = 0;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
425 double closestDistance = frames_[0].ComputeDistance(point);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
426
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
427 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
428 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
429 double d = frames_[i].ComputeDistance(point);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
430 if (d < closestDistance)
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
431 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
432 frameIndex = i;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
433 closestDistance = d;
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
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
437 return (closestDistance <= maximumDistance);
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 }
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
440 else
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
441 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
442 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
443 "Sort() has not been called");
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
444 }
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1643
diff changeset
445 }
1478
fab6c6e795a3 Framework/Toolbox/SortedFrames.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 }