MeVisLab Toolbox Reference
mlCTUDimensionInfoSupport.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2018, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 
15 
16 #pragma once
17 
18 #include <mlTypeDefs.h>
19 #include <ThirdPartyWarningsDisable.h>
20 #include <vector>
21 #include <ThirdPartyWarningsRestore.h>
22 
23 ML_START_NAMESPACE
24 
25 //----------------------------------------------------------------------------------
28 
37 //----------------------------------------------------------------------------------
38 template <class T>
39 void AdjustDimensionInfos (std::vector<T> &dimInfo, MLssize_t newStartPos, size_t newSize, size_t oldSize, T defaultValue = T{})
40 {
41  // Dim info specified and size changed?
42  if (!dimInfo.empty() && (newStartPos || newSize != oldSize))
43  {
44  // Dim info has valid size?
45  if (dimInfo.size() == oldSize)
46  {
47  auto it = dimInfo.begin();
48  if (newStartPos > 0)
49  {
50  // cast is now always ok
51  if (static_cast<size_t>(newStartPos) < oldSize){
52  // Remove first pos entries
53  dimInfo.erase(it, it+newStartPos);
54  }
55  else{
56  // Remove all entries
57  dimInfo.clear();
58  }
59  }
60  else if (newStartPos < 0){
61  // Insert pos entries at beginning
62  dimInfo.insert(it, static_cast<size_t>(-newStartPos), defaultValue);
63  }
64  // Set size
65  dimInfo.resize(newSize, defaultValue);
66  }
67  else{
68  // Size of dim info invalid, discard
69  dimInfo.clear();
70  }
71  }
72 }
73 
74 ML_END_NAMESPACE
75 
76 
77 
@ T
Definition: SoKeyGrabber.h:71
SSIZE_T MLssize_t
The signed ML size type which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
Definition: mlTypeDefs.h:654
void AdjustDimensionInfos(std::vector< T > &dimInfo, MLssize_t newStartPos, size_t newSize, size_t oldSize, T defaultValue=T{})
Cut a new sub region out of existing C, T, or U dimension infos, filling undefined range with default...