ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkFDFCommonImageIO.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkFDFCommonImageIO_h
19#define itkFDFCommonImageIO_h
20
21#include <itkFDFImageIO.h>
22#include <itkIndent.h>
23
24#include <iostream>
25#include <fstream>
26#include <sstream>
27#include <vector>
28#include <iterator>
29#include <algorithm>
30
31namespace itk
32{
33
34std::string
35RemoveCharacters(std::string, char);
36
37void
38Tokenize(const std::string & str, std::vector<std::string> & tokens, const std::string & delimiters = " ");
39
40std::string
41ParseLine(std::string line);
42
43template <typename T>
44void
45ConvertFromString(std::string s, T & value)
46{
47 std::stringstream str;
48 str << s;
49 str >> value;
50}
51
52template <typename T>
53void
54StringToVector(std::string value, std::vector<T> & values)
55{
56 std::vector<std::string> tokens;
57
58 // value consists of something like {256,256}
59 std::string::size_type startBracketPosition = value.find_first_of("{", 0);
60 std::string::size_type endBracketPosition = value.find_first_of("}", startBracketPosition);
61
62 if (startBracketPosition != std::string::npos && endBracketPosition != std::string::npos)
63 {
64 std::string elements = value.substr(startBracketPosition + 1, endBracketPosition - startBracketPosition - 1);
65
66
67 Tokenize(elements, tokens, ",");
68 }
69
70 T element;
71
72 for (auto & token : tokens)
73 {
74 ConvertFromString(token, element);
75 values.push_back(element);
76 }
77}
78
79template <typename T>
80void
81PrintVector(std::ostream & os, std::string name, const std::vector<T> & vect)
82{
83 int size = vect.size();
84
85 os << name << " {";
86
87 for (int i = 0; i < size; i++)
88 {
89 os << vect[i];
90
91 if (i < size - 1)
92 os << ", ";
93 }
94
95 os << "}" << std::endl;
96}
97
98} // namespace itk
99
100#endif
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
std::string ParseLine(std::string line)
std::string RemoveCharacters(std::string, char)
void ConvertFromString(std::string s, T &value)
void StringToVector(std::string value, std::vector< T > &values)
void PrintVector(std::ostream &os, std::string name, const std::vector< T > &vect)