<commit_before>/* Copyright (c) 2008-2017 the MRtrix3 contributors.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * MRtrix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * For more details, see http://www.mrtrix.org/.
 */


#include "command.h"
#include "datatype.h"
#include "image.h"
#include "adapter/replicate.h"
#include "algo/loop.h"
#include "file/ofstream.h"

using namespace MR;
using namespace App;


void usage ()
{
  AUTHOR = "<NAME> (<EMAIL>)";

  SYNOPSIS = "Print out the values within an image";

  DESCRIPTION
  + "If no destination file is specified, the voxel locations will be "
    "printed to stdout.";

  ARGUMENTS
  + Argument ("input",  "the input image.").type_image_in()
  + Argument ("output", "the (optional) output text file.").type_file_out().optional();

  OPTIONS
  + Option ("mask", "only write the image values within voxels specified by a mask image")
    + Argument ("image").type_image_in();
}



template <typename T, class StreamType>
void write (Image<T>& image, StreamType& out)
{
  TRACE;
  for (auto l = Loop(image) (image); l; ++l)
    out << image.value() << "\n";
}

template <typename T, class StreamType>
void write (Image<T> image, Image<bool>& mask, StreamType& out)
{
  if (!mask.valid()) {
    write (image, out);
    return;
  }
  Adapter::Replicate<Image<bool>> replicate (mask, image);
  for (auto l = Loop(image) (image, replicate); l; ++l) {
    if (replicate.value())
      out << image.value() << "\n";
  }
}



template <class StreamType>
void write (Header& header, Image<bool>& mask, StreamType& out)
{<commit_msg>mrdump: Remove erroneous TRACE call<commit_after>/* Copyright (c) 2008-2017 the MRtrix3 contributors.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * MRtrix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * For more details, see http://www.mrtrix.org/.
 */


#include "command.h"
#include "datatype.h"
#include "image.h"
#include "adapter/replicate.h"
#include "algo/loop.h"
#include "file/ofstream.h"

using namespace MR;
using namespace App;


void usage ()
{
  AUTHOR = "<NAME> (<EMAIL>)";

  SYNOPSIS = "Print out the values within an image";

  DESCRIPTION
  + "If no destination file is specified, the voxel locations will be "
    "printed to stdout.";

  ARGUMENTS
  + Argument ("input",  "the input image.").type_image_in()
  + Argument ("output", "the (optional) output text file.").type_file_out().optional();

  OPTIONS
  + Option ("mask", "only write the image values within voxels specified by a mask image")
    + Argument ("image").type_image_in();
}



template <typename T, class StreamType>
void write (Image<T>& image, StreamType& out)
{
  for (auto l = Loop(image) (image); l; ++l)
    out << image.value() << "\n";
}

template <typename T, class StreamType>
void write (Image<T> image, Image<bool>& mask, StreamType& out)
{
  if (!mask.valid()) {
    write (image, out);
    return;
  }
  Adapter::Replicate<Image<bool>> replicate (mask, image);
  for (auto l = Loop(image) (image, replicate); l; ++l) {
    if (replicate.value())
      out << image.value() << "\n";
  }
}



template <class StreamType>
void write (Header& header, Image<bool>& mask, StreamType& out)
{
{'fraction_non_alphanumeric': 0.14015454303224087, 'fraction_numerical': 0.006927791100452971, 'mean_word_length': 3.812820512820513, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3984660', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1176, 'n_words': 441}