<commit_before>/*
 * Copyright (c) 2008-2016 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 www.mrtrix.org
 * 
 */

#ifndef __surface_algo_image2mesh_h__
#define __surface_algo_image2mesh_h__

#include <array>
#include <map>
#include <vector>

#include "image_helpers.h"
#include "transform.h"

#include "surface/mesh.h"
#include "surface/types.h"



namespace MR
{
  namespace Surface
  {
    namespace Algo
    {


      // Function to convert a binary image into a mesh
      // Note that this produces a mesh that follows the voxel boundaries exactly;
      //   it therefore appears very 'blocky'
      template <class ImageType>
      void image2mesh_blocky (const ImageType& input_image, Mesh& out)
      {

        static const Vox steps[6] = { Vox ( 0,  0, -1),
                                      Vox ( 0, -1,  0),
                                      Vox (-1,  0,  0),
                                      Vox ( 0,  0,  1),
                                      Vox ( 0,  1,  0),
                                      Vox ( 1,  0,  0) };

        static const int plane_axes[6][2] = { {0, 1},
                                              {0, 2},
                                              {1, 2},
                                              {0, 1},
                                              {0, 2},
                                              {1, 2} };

        if (input_image.ndim() != 3)
          throw Exception ("Voxel-to-mesh conversion only works for 3D images");

        ImageType voxel (input_image), neighbour (input_image);
        VertexList vertices;
        TriangleList triangles;
        std::map<Vox, size_t> vox2vertindex;

        // Perform all initial calculations in voxel space;
        //   only once the final vertex position in voxel space is determined
        //   is it transformed to real space for the final output
        Transform transform (input_image);

        // Also, for initial calculations, do this such that a voxel location actually
        //   refers to the lower corner of the voxel; that way searches for existing
        //   vertices can be done using a simple map<commit_msg>Surface::Algo::image2mesh_blocky(): Fix RH rule of output<commit_after>/*
 * Copyright (c) 2008-2016 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 www.mrtrix.org
 * 
 */

#ifndef __surface_algo_image2mesh_h__
#define __surface_algo_image2mesh_h__

#include <array>
#include <map>
#include <vector>

#include "image_helpers.h"
#include "transform.h"

#include "surface/mesh.h"
#include "surface/types.h"



namespace MR
{
  namespace Surface
  {
    namespace Algo
    {


      // Function to convert a binary image into a mesh
      // Note that this produces a mesh that follows the voxel boundaries exactly;
      //   it therefore appears very 'blocky'
      template <class ImageType>
      void image2mesh_blocky (const ImageType& input_image, Mesh& out)
      {

        static const Vox steps[6] = { Vox ( 0,  0, -1),
                                      Vox ( 0, -1,  0),
                                      Vox (-1,  0,  0),
                                      Vox ( 0,  0,  1),
                                      Vox ( 0,  1,  0),
                                      Vox ( 1,  0,  0) };

        static const int plane_axes[6][2] = { {1, 0},
                                              {0, 2},
                                              {2, 1},
                                              {0, 1},
                                              {2, 0},
                                              {1, 2} };

        if (input_image.ndim() != 3)
          throw Exception ("Voxel-to-mesh conversion only works for 3D images");

        ImageType voxel (input_image), neighbour (input_image);
        VertexList vertices;
        TriangleList triangles;
        std::map<Vox, size_t> vox2vertindex;

        // Perform all initial calculations in voxel space;
        //   only once the final vertex position in voxel space is determined
        //   is it transformed to real space for the final output
        Transform transform (input_image);

        // Also, for initial calculations, do this such that a voxel location actually
        //   refers to the lower corner of the voxel; that way searches for existing
        //   vertices can be done using a simple map
{'fraction_non_alphanumeric': 0.0813276397515528, 'fraction_numerical': 0.020380434782608696, 'mean_word_length': 1.5920523138832998, 'pattern_counts': {'":': 0, '<': 13, '<?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': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '791695', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1328, 'n_words': 536}