MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
24
25//----------------------------------------------------------------------------------
28
37//----------------------------------------------------------------------------------
38template <class T> void AdjustDimensionInfos(std::vector<T>& dimInfo, MLssize_t newStartPos, size_t newSize,
39 size_t oldSize, T defaultValue = T{})
40{
41 // Dim info specified and size changed?
42 if (!dimInfo.empty() && (newStartPos || newSize != oldSize)) {
43 // Dim info has valid size?
44 if (dimInfo.size() == oldSize) {
45 auto it = dimInfo.begin();
46 if (newStartPos > 0) {
47 // cast is now always ok
48 if (static_cast<size_t>(newStartPos) < oldSize) {
49 // Remove first pos entries
50 dimInfo.erase(it, it + newStartPos);
51 }
52 else {
53 // Remove all entries
54 dimInfo.clear();
55 }
56 }
57 else if (newStartPos < 0) {
58 // Insert pos entries at beginning
59 dimInfo.insert(it, static_cast<size_t>(-newStartPos), defaultValue);
60 }
61 // Set size
62 dimInfo.resize(newSize, defaultValue);
63 }
64 else {
65 // Size of dim info invalid, discard
66 dimInfo.clear();
67 }
68 }
69}
70
71//----------------------------------------------------------------------------------
74
82//----------------------------------------------------------------------------------
83template <class T>
85{
86 // Dim info specified and size changed?
87 if (!dimInfo.empty() && (newStartPos != 0 || newSize != oldSize)) {
88 if (dimInfo.size() == oldSize && newStartPos >= 0 && static_cast<size_t>(newStartPos) < oldSize &&
89 static_cast<size_t>(newStartPos + newSize) <= oldSize)
90 {
91 // New range is subset of old range?
92 auto it = dimInfo.begin();
93 dimInfo.erase(it, it + newStartPos);
94 dimInfo.resize(newSize);
95 }
96 else {
97 // Size of dim info or new range invalid, discard
98 dimInfo.clear();
99 }
100 }
101}
102
@ T
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Definition mlTypeDefs.h:563
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...
void AdjustOrClearDimensionInfos(std::vector< T > &dimInfo, MLssize_t newStartPos, size_t newSize, size_t oldSize)
Cut a new sub region out of existing C, T, or U dimension infos, or clear the dimension info if undef...