File: elxIterationInfo.cxx

package info (click to toggle)
elastix 5.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 45,644 kB
  • sloc: cpp: 85,720; lisp: 4,118; python: 1,045; sh: 200; xml: 182; makefile: 33
file content (122 lines) | stat: -rw-r--r-- 2,353 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*=========================================================================
 *
 *  Copyright UMC Utrecht and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/


#include "elxIterationInfo.h" // Its own header
#include "elxlog.h"

#include <fstream>
#include <map>
#include <sstream>
#include <string>


namespace elastix
{

std::ostream &
IterationInfo::operator[](const char * const cellName)
{
  return m_CellMap[cellName];
}


void
IterationInfo::AddNewTargetCell(const char * const cellName)
{
  m_CellMap[cellName] = {};
}


void
IterationInfo::RemoveTargetCell(const char * const cellName)
{
  m_CellMap.erase(cellName);
}

void
IterationInfo::WriteHeaders() const
{
  std::string headers;
  const auto  begin = m_CellMap.cbegin();
  const auto  end = m_CellMap.cend();

  if (begin != end)
  {
    headers = begin->first;

    for (auto it = std::next(begin); it != end; ++it)
    {
      headers.push_back('\t');
      headers += it->first;
    }
  }
  log::info(headers);

  if (m_OutputFile)
  {
    *m_OutputFile << headers << std::endl;
  }
}


void
IterationInfo::WriteBufferedData()
{
  std::string data;
  const auto  begin = m_CellMap.cbegin();
  const auto  end = m_CellMap.cend();

  if (begin != end)
  {
    data = begin->second.str();

    for (auto it = std::next(begin); it != end; ++it)
    {
      data.push_back('\t');
      data += it->second.str();
    }
  }
  log::info(data);

  if (m_OutputFile)
  {
    *m_OutputFile << data << std::endl;
  }

  for (auto & cell : m_CellMap)
  {
    cell.second.str("");
  }
}


void
IterationInfo::RemoveOutputFile()
{
  m_OutputFile = nullptr;
}


void
IterationInfo::SetOutputFile(std::ofstream & outputFile)
{
  m_OutputFile = &outputFile;
}

} // namespace elastix