<commit_before>package org.vitrivr.cineast.core.data.m3d;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.joml.Vector3f;

import java.util.*;

/**
 * @author rgasser
 * @version 1.0
 * @created 06.01.17
 */
public class Voxelizer {
    /**
     *
     */
    private static final Logger LOGGER = LogManager.getLogger();

    /**
     * Constant: Square-root of 3.
     */
    private static final float sqrt3 =  (float)Math.sqrt(3);

    /**
     * Resolution, i.e. size of a single voxel.
     */
    private final float resolution;

    /**
     * Half of the resolution. Pre-calculated for convenience.
     */
    private final float rc;

    /**
     * Half the resolution squared. Pre-calculated for convenience.
     */
    private final float rcsq;


    /**
     * Default constructor. Defines the resolution of the Voxelizer.
     *
     * @param resolution
     */
    public Voxelizer(float resolution) {
        this.resolution = resolution;
        this.rc = resolution/2;
        this.rcsq = (float)Math.pow(this.rc,2);
    }

    /**
     * Voxelizes the provided mesh, returning a VoxelGrid with the specified resolution.
     *
     * @param mesh Mesh that should be voxelized.
     * @return Voxel representation of the mesh.
     */
    public VoxelGrid voxelize(Mesh mesh) {
        long start =  System.currentTimeMillis();

        /* Calculate bounding box of mesh. */
        float[] boundingBox = this.bounds(mesh.getVertices());
        short sizeX = (short)Math.abs((short)Math.ceil(((boundingBox[0]-boundingBox[1])/this.resolution)));
        short sizeY = (short)Math.abs((short)Math.ceil(((boundingBox[2]-boundingBox[3])/this.resolution)));
        short sizeZ = (short)Math.abs((short)Math.ceil(((boundingBox[4]-boundingBox[5])/this.resolution)));

        /* Initializes a new voxel-grid. */
        VoxelGrid grid = new VoxelGrid(sizeX, sizeY, sizeZ, this.resolution, false);

        /* Prepare emtpy HashSets. */
        for (Mesh.Face face : mesh.getFaces()) {<commit_msg>Added additional "safety-voxel" to initial grid in Voxelizer.<commit_after>package org.vitrivr.cineast.core.data.m3d;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.joml.Vector3f;

import java.util.*;

/**
 * @author rgasser
 * @version 1.0
 * @created 06.01.17
 */
public class Voxelizer {
    /**
     *
     */
    private static final Logger LOGGER = LogManager.getLogger();

    /**
     * Constant: Square-root of 3.
     */
    private static final float sqrt3 =  (float)Math.sqrt(3);

    /**
     * Resolution, i.e. size of a single voxel.
     */
    private final float resolution;

    /**
     * Half of the resolution. Pre-calculated for convenience.
     */
    private final float rc;

    /**
     * Half the resolution squared. Pre-calculated for convenience.
     */
    private final float rcsq;


    /**
     * Default constructor. Defines the resolution of the Voxelizer.
     *
     * @param resolution
     */
    public Voxelizer(float resolution) {
        this.resolution = resolution;
        this.rc = resolution/2;
        this.rcsq = (float)Math.pow(this.rc,2);
    }

    /**
     * Voxelizes the provided mesh, returning a VoxelGrid with the specified resolution.
     *
     * @param mesh Mesh that should be voxelized.
     * @return Voxel representation of the mesh.
     */
    public VoxelGrid voxelize(Mesh mesh) {
        long start =  System.currentTimeMillis();

        /* Calculate bounding box of mesh. */
        float[] boundingBox = this.bounds(mesh.getVertices());
        short sizeX = (short)(Math.abs(Math.ceil(((boundingBox[0]-boundingBox[1])/this.resolution))) + 1);
        short sizeY = (short)(Math.abs(Math.ceil(((boundingBox[2]-boundingBox[3])/this.resolution))) + 1);
        short sizeZ = (short)(Math.abs(Math.ceil(((boundingBox[4]-boundingBox[5])/this.resolution))) + 1);

        /* Initializes a new voxel-grid. */
        VoxelGrid grid = new VoxelGrid(sizeX, sizeY, sizeZ, this.resolution, false);

        /* Prepare emtpy HashSets. */
        for (Mesh.Face face : mesh.getFaces()) {
{'fraction_non_alphanumeric': 0.12951167728237792, 'fraction_numerical': 0.012031139419674451, 'mean_word_length': 2.587140439932318, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4224965', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1312, 'n_words': 322}