<commit_before>#ifndef VOXBLOX_CORE_BLOCK_H
#define VOXBLOX_CORE_BLOCK_H

#include "voxblox/core/common.h"
#include "voxblox/core/voxel.h"
#include "voxblox/core/voxel_array.h"

namespace voxblox {

class BaseBlock {
 public:
  typedef std::shared_ptr<BaseBlock> Ptr;
  typedef std::shared_ptr<const BaseBlock> ConstPtr;

  BaseBlock(size_t num_layers, const Coordinates& origin,
            FloatingPoint block_size)
      : num_layers_(num_layers),
        origin_(origin),
        block_size_(block_size),
        has_data_(false) {}
  virtual ~BaseBlock() {}

  inline size_t computeLinearIndexFromVoxelIndex(const VoxelIndex& index,
                                                 size_t vps) const {
    return index.x() + vps * (index.y() + index.z() * vps);
  }

  inline VoxelIndex computeVoxelIndexFromCoordinates(
      const Coordinates& coords, FloatingPoint voxel_size_inv) const {
    return VoxelIndex(static_cast<int>(std::floor((coords.x() - origin_.x()) *
                                                  voxel_size_inv)),
                      static_cast<int>(std::floor((coords.y() - origin_.y()) *
                                                  voxel_size_inv)),
                      static_cast<int>(std::floor((coords.z() - origin_.z()) *
                                                  voxel_size_inv)));
  }

  inline size_t computeLinearIndexFromCoordinates(const Coordinates& coords,
                                                  FloatingPoint voxel_size_inv,
                                                  size_t vps) const {
    return computeLinearIndexFromVoxelIndex(
        computeVoxelIndexFromCoordinates(coords, voxel_size_inv), vps);
  }

  inline Coordinates computeCoordinatesFromLinearIndex(size_t linear_index,
                                                       FloatingPoint voxel_size,
                                                       size_t vps) const {
    return computeCoordinatesFromVoxelIndex(
        computeVoxelIndexFromLinearIndex(linear_index, vps), voxel_size);
  }

  inline Coordinates computeCoordinatesFromVoxelIndex(
      const VoxelIndex& index, FloatingPoint voxel_size) const {
    return index.cast<FloatingPoint>() * voxel_size + origin_;
  }

  inline VoxelIndex computeVoxelIndexFromLinearIndex(size_t linear_index,
                                                     size_t vps) const {
    int rem = linear_index;
    VoxelIndex result;
    std::div_t div_temp = std::div(rem, vps * vps);
    rem = div_temp.rem;
    result.z() = div_temp.quot;
    div_temp = std::div(rem, vps);
    result.y() = div_temp.quot;
    result.x() = div_temp.rem;
    return result;
  }

 protected:
  size_t num_layers_;
  Coordinates origin_;
  FloatingPoint block_size_;
  bool has_data_;
};

class TsdfBlock : BaseBlock {
 public:
  typedef std::shared_ptr<TsdfBlock> Ptr;
  typedef std::shared_ptr<const BaseBlock> ConstPtr;

  TsdfBlock(const Coordinates& origin, size_t voxels_per_side,
            FloatingPoint voxel_size)
      : BaseBlock(1, origin, voxels_per_side * voxel_size),
        has_changed_(false) {<commit_msg>Fixed coordinates for voxels to be in the center.<commit_after>#ifndef VOXBLOX_CORE_BLOCK_H
#define VOXBLOX_CORE_BLOCK_H

#include "voxblox/core/common.h"
#include "voxblox/core/voxel.h"
#include "voxblox/core/voxel_array.h"

namespace voxblox {

class BaseBlock {
 public:
  typedef std::shared_ptr<BaseBlock> Ptr;
  typedef std::shared_ptr<const BaseBlock> ConstPtr;

  BaseBlock(size_t num_layers, const Coordinates& origin,
            FloatingPoint block_size)
      : num_layers_(num_layers),
        origin_(origin),
        block_size_(block_size),
        has_data_(false) {}
  virtual ~BaseBlock() {}

  inline size_t computeLinearIndexFromVoxelIndex(const VoxelIndex& index,
                                                 size_t vps) const {
    return index.x() + vps * (index.y() + index.z() * vps);
  }

  inline VoxelIndex computeVoxelIndexFromCoordinates(
      const Coordinates& coords, FloatingPoint voxel_size_inv) const {
    return VoxelIndex(static_cast<int>(std::floor((coords.x() - origin_.x()) *
                                                  voxel_size_inv)),
                      static_cast<int>(std::floor((coords.y() - origin_.y()) *
                                                  voxel_size_inv)),
                      static_cast<int>(std::floor((coords.z() - origin_.z()) *
                                                  voxel_size_inv)));
  }

  inline size_t computeLinearIndexFromCoordinates(const Coordinates& coords,
                                                  FloatingPoint voxel_size_inv,
                                                  size_t vps) const {
    return computeLinearIndexFromVoxelIndex(
        computeVoxelIndexFromCoordinates(coords, voxel_size_inv), vps);
  }

  inline Coordinates computeCoordinatesFromLinearIndex(size_t linear_index,
                                                       FloatingPoint voxel_size,
                                                       size_t vps) const {
    return computeCoordinatesFromVoxelIndex(
        computeVoxelIndexFromLinearIndex(linear_index, vps), voxel_size);
  }

  inline Coordinates computeCoordinatesFromVoxelIndex(
      const VoxelIndex& index, FloatingPoint voxel_size) const {
    return (index.cast<FloatingPoint>() + 0.5 * Coordinates::Ones()) *
               voxel_size +
           origin_;
  }

  inline VoxelIndex computeVoxelIndexFromLinearIndex(size_t linear_index,
                                                     size_t vps) const {
    int rem = linear_index;
    VoxelIndex result;
    std::div_t div_temp = std::div(rem, vps * vps);
    rem = div_temp.rem;
    result.z() = div_temp.quot;
    div_temp = std::div(rem, vps);
    result.y() = div_temp.quot;
    result.x() = div_temp.rem;
    return result;
  }

 protected:
  size_t num_layers_;
  Coordinates origin_;
  FloatingPoint block_size_;
  bool has_data_;
};

class TsdfBlock : BaseBlock {
 public:
  typedef std::shared_ptr<TsdfBlock> Ptr;
  typedef std::shared_ptr<const BaseBlock> ConstPtr;

  TsdfBlock(const Coordinates& origin, size_t voxels_per_side,
            FloatingPoint voxel_size)
      : BaseBlock(1, origin, voxels_per_side * voxel_size),
        has_changed_(false) {
{'fraction_non_alphanumeric': 0.08713561470215463, 'fraction_numerical': 0.0006337135614702154, 'mean_word_length': 2.2094560244026438, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4212036', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1811, 'n_words': 354}