<commit_before>/*
    Copyright 2008 Brain Research Institute, Melbourne, Australia

    Written by <NAME>, 27/06/08.

    This file is part of MRtrix.

    MRtrix is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    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.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MRtrix.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "file/path.h"
#include "file/dicom/image.h"
#include "file/dicom/series.h"
#include "file/dicom/study.h"
#include "file/dicom/patient.h"
#include "file/dicom/csa_entry.h"

namespace MR
{
  namespace File
  {
    namespace Dicom
    {

      void Image::parse_item (Element& item, const std::string& dirname)
      {
        switch (item.group) {
          case 0x0004U:
            if (item.element == 0x1500U) {
              assert (dirname.size());
              filename = dirname;
              std::vector<std::string> V (item.get_string());
              for (size_t n = 0; n < V.size(); n++)
                filename = Path::join (filename, V[n]);
            }
            break;
          case 0x0008U:
            if (item.element == 0x0070U) manufacturer = item.get_string() [0];
            return;
          case 0x0018U:
            switch (item.element) {
              case 0x0050U:
                slice_thickness = item.get_float() [0];
                return;
              case 0x0088U:
                slice_spacing = item.get_float() [0];
                return;
              case 0x1310U:
                acq_dim[0] = std::max (item.get_uint() [0], item.get_uint() [1]);
                acq_dim[1] = std::max (item.get_uint() [2], item.get_uint() [3]);

                return;
              case 0x0024U:
                sequence_name = item.get_string() [0];
                if (!sequence_name.size()) return;
                {
                  int c = sequence_name.size()-1;
                  while (c >= 0 && isdigit (sequence_name[c])) c--;
                  c++;
                  sequence = c < int(sequence_name.size()-1) ? to<size_t> (sequence_name.substr (c)) : 0;
                }
                return;
              case 0x9087U:
                bvalue = item.get_float() [0];
                return;
              case 0x9089U:
                G[0] = item.get_float() [0];
                G[1] = item.get_float() [1];
                G[2] = item.get_float() [2];
                return;

            }
            return;
          case 0x0019U:
            switch (item.element) { // GE DW encoding info:
              case 0x10BBU:
                if (item.get_float().size()) G[0] = item.get_float() [0];
                return;
              case 0x10BCU:
                if (item.get_float().size()) G[1] = item.get_float() [0];
                return;
              case 0x10BDU:
                if (item.get_float().size()) G[2] = item.get_float() [0];
                return;
            }
            return;
          case 0x0020U:
            switch (item.element) {
              case 0x0012U:
                acq = item.get_uint() [0];
                return;
              case 0x0013U:
                instance = item.get_uint() [0];
                return;
              case 0x0032U:
                position_vector[0] = item.get_float() [0];
                position_vector[1] = item.get_float() [1];<commit_msg>added support for reading Siemens private DICOM tags (0019,100C) & (0019,100D) to retrieve DW information - needed for some Skyra data<commit_after>/*
    Copyright 2008 Brain Research Institute, Melbourne, Australia

    Written by <NAME>, 27/06/08.

    This file is part of MRtrix.

    MRtrix is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    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.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MRtrix.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "file/path.h"
#include "file/dicom/image.h"
#include "file/dicom/series.h"
#include "file/dicom/study.h"
#include "file/dicom/patient.h"
#include "file/dicom/csa_entry.h"

namespace MR
{
  namespace File
  {
    namespace Dicom
    {

      void Image::parse_item (Element& item, const std::string& dirname)
      {
        switch (item.group) {
          case 0x0004U:
            if (item.element == 0x1500U) {
              assert (dirname.size());
              filename = dirname;
              std::vector<std::string> V (item.get_string());
              for (size_t n = 0; n < V.size(); n++)
                filename = Path::join (filename, V[n]);
            }
            break;
          case 0x0008U:
            if (item.element == 0x0070U) manufacturer = item.get_string() [0];
            return;
          case 0x0018U:
            switch (item.element) {
              case 0x0050U:
                slice_thickness = item.get_float() [0];
                return;
              case 0x0088U:
                slice_spacing = item.get_float() [0];
                return;
              case 0x1310U:
                acq_dim[0] = std::max (item.get_uint() [0], item.get_uint() [1]);
                acq_dim[1] = std::max (item.get_uint() [2], item.get_uint() [3]);

                return;
              case 0x0024U:
                sequence_name = item.get_string() [0];
                if (!sequence_name.size()) return;
                {
                  int c = sequence_name.size()-1;
                  while (c >= 0 && isdigit (sequence_name[c])) c--;
                  c++;
                  sequence = c < int(sequence_name.size()-1) ? to<size_t> (sequence_name.substr (c)) : 0;
                }
                return;
              case 0x9087U:
                bvalue = item.get_float() [0];
                return;
              case 0x9089U:
                G[0] = item.get_float() [0];
                G[1] = item.get_float() [1];
                G[2] = item.get_float() [2];
                return;

            }
            return;
          case 0x0019U:
            switch (item.element) { // GE DW encoding info:
              case 0x10BBU:
                if (item.get_float().size()) G[0] = item.get_float() [0];
                return;
              case 0x10BCU:
                if (item.get_float().size()) G[1] = item.get_float() [0];
                return;
              case 0x10BDU:
                if (item.get_float().size()) G[2] = item.get_float() [0];
                return;
              case 0x100CU: //Siemens private DW encoding tags:
                if (item.get_int().size()) bvalue = item.get_int()[0]; 
                return;
              case 0x100EU: 
                if (item.get_float().size() == 3) {
                  G[0] = item.get_float()[0];
                  G[1] = item.get_float()[1];
                  G[2] = item.get_float()[2];
                }
                return;
            }
            return;
          case 0x0020U:
            switch (item.element) {
              case 0x0012U:
                acq = item.get_uint() [0];
                return;
              case 0x0013U:
                instance = item.get_uint() [0];
                return;
              case 0x0032U:
                position_vector[0] = item.get_float() [0];
                position_vector[1] = item.get_float() [1];
{'fraction_non_alphanumeric': 0.11334981458590852, 'fraction_numerical': 0.03683559950556242, 'mean_word_length': 1.4857142857142858, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '1426865', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2330, 'n_words': 655}