Developer documentation
Version 3.0.3-105-gd3941f44
receiver.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __dwi_tractography_editing_receiver_h__
18#define __dwi_tractography_editing_receiver_h__
19
20
21#include <string>
22#include <cinttypes>
23
24#include "progressbar.h"
25
29
30
31namespace MR {
32 namespace DWI {
33 namespace Tractography {
34 namespace Editing {
35
36
37
38
40 { MEMALIGN(Receiver)
41
42 public:
43
44 Receiver (const std::string& path, const Properties& properties, const size_t n, const size_t s) :
45 writer (path, properties),
46 number (n),
47 skip (s),
48 // Need to use local counts instead of writer class members due to track cropping
49 count (0),
50 total_count (0),
51 crop (properties.mask.size()),
52 segments (0),
53 progress (std::string(" 0 read, 0 written") + (crop ? ", 0 segments" : "")) { }
54
55 ~Receiver()
56 {
57 // Use set_text() rather than update() here to force update of the text before progress goes out of scope
58 progress.set_text (std::string(printf ("%8" PRIu64 " read, %8" PRIu64 " written", total_count, count)) + (crop ? printf(", %8" PRIu64 " segments", segments) : ""));
59 if (number && (count != number))
60 WARN ("User requested " + str(number) + " streamlines, but only " + str(count) + " were written to file");
61 }
62
63
64 bool operator() (const Streamline<>&);
65
66
67 private:
68
69 Writer<> writer;
70 const uint64_t number;
71 uint64_t skip;
72 uint64_t count, total_count;
73 bool crop;
74 uint64_t segments;
75 ProgressBar progress;
76
77 };
78
79
80
81 }
82 }
83 }
84}
85
86#endif
class to handle writing tracks to file, with RAM buffer
Definition: file.h:353
implements a progress meter to provide feedback to the user
Definition: progressbar.h:58
void set_text(const std::string &new_text)
Definition: progressbar.h:228
#define WARN(msg)
Definition: exception.h:73
Definition: base.h:24
std::string str(const T &value, int precision=0)
Definition: mrtrix.h:247
std::string printf(const char *format,...)
Definition: mrtrix.h:116