Developer documentation
Version 3.0.3-105-gd3941f44
write_kernel.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_tracking_write_kernel_h__
18#define __dwi_tractography_tracking_write_kernel_h__
19
20#include <cinttypes>
21#include <string>
22
23#include "timer.h"
24#include "file/ofstream.h"
25
29
34
35
36
37namespace MR
38{
39 namespace DWI
40 {
41 namespace Tractography
42 {
43 namespace Tracking
44 {
45
46
48 { MEMALIGN(WriteKernel)
49 public:
50
51 WriteKernel (const SharedBase& shared,
52 const std::string& output_file,
53 const DWI::Tractography::Properties& properties) :
54 S (shared),
55 writer (output_file, properties),
56 always_increment (S.properties.seeds.is_finite() || !S.max_num_tracks),
57 warn_on_max_seeds (S.implicit_max_num_seeds),
58 seeds (0),
59 streamlines (0),
60 selected (0),
61 progress (printf (" 0 seeds, 0 streamlines, 0 selected", 0, 0), always_increment ? S.max_num_seeds : S.max_num_tracks),
62 early_exit (shared)
63 {
64 const auto p = properties.find ("seed_output");
65 if (p != properties.end()) {
66 output_seeds.reset (new File::OFStream (p->second, std::ios_base::out | std::ios_base::trunc));
67 (*output_seeds) << "# " << App::command_history_string << "\n";
68 (*output_seeds) << "#Track_index,Seed_index,Pos_x,Pos_y,Pos_z,\n";
69 }
70 }
71
72 WriteKernel (const WriteKernel&) = delete;
73 WriteKernel& operator= (const WriteKernel&) = delete;
74
76 {
77 // Use set_text() rather than update() here to force update of the text before progress goes out of scope
78 progress.set_text (printf ("%8" PRIu64 " seeds, %8" PRIu64 " streamlines, %8" PRIu64 " selected", seeds, streamlines, selected));
79 if (warn_on_max_seeds && writer.total_count == S.max_num_seeds
80 && S.max_num_tracks && writer.count < S.max_num_tracks) {
81 WARN ("less than desired streamline number due to implicit maximum number of seeds; set -seeds 0 to override");
82 }
83 if (output_seeds) {
84 (*output_seeds) << "\n";
85 output_seeds->close();
86 }
87
88 }
89
90
91 bool operator() (const GeneratedTrack&);
92
93 bool complete() const { return ((S.max_num_tracks && selected >= S.max_num_tracks) || (S.max_num_seeds && seeds >= S.max_num_seeds)); }
94
95
96 protected:
97 const SharedBase& S;
101 std::unique_ptr<File::OFStream> output_seeds;
104 };
105
106
107
108
109 }
110 }
111 }
112}
113
114#endif
115
116
std::unique_ptr< File::OFStream > output_seeds
Definition: write_kernel.h:101
class to handle writing tracks to file, with RAM buffer
Definition: file.h:353
open output files for writing, checking for pre-existing file if necessary
Definition: ofstream.h:39
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
std::string command_history_string
Definition: base.h:24
std::string printf(const char *format,...)
Definition: mrtrix.h:116