<commit_before>#include "DicomMaterialDatabase.hh"

#include <G4Material.hh>
#include <G4NistManager.hh>

using namespace g4dicom;
using namespace std;

G4Material *VDicomMaterialDatabase::GetDefaultMaterial()
{
    return G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");
}

G4Material* DicomMaterialDatabase::GetMaterialByHU(int hu)
{
    if (hu < minHU)
    {
        return GetDefaultMaterial();
    }
    if (_materials.find(hu) == _materials.end())
    {
        G4NistManager* nistManager = G4NistManager::Instance();
        double density = primitiveHUtoDensity(hu);
        _materials[hu] = nistManager->BuildMaterialWithNewDensity("G4_WATER", density);
    }
    return _materials[hu];
}

DicomMaterialDatabase::DicomMaterialDatabase()
{
    _materials[minHU] = GetDefaultMaterial();
}

G4Material* DicomMaterialDatabase::GetMaterial(DicomData* data, int x, int y, int z)
{
    return GetMaterialByHU(data->GetValue(x, y, z));
}

vector<G4Material*> DicomMaterialDatabase::GetAllMaterials()
{
    vector<G4Material*> materials;
    for (auto it = _materials.begin(); it != _materials.end(); it++)
    {
        materials.push_back(it->second);
    }
    return materials;
}

double primitiveHUtoDensity(double hu)
{
    return 1.0 * g / cm3 * (hu + 1000.0) / 1000.0;
}<commit_msg>Fix: DicomMaterialDatabase doesn't compile + produces wrong material names.<commit_after>#include "DicomMaterialDatabase.hh"

#include <G4Material.hh>
#include <G4NistManager.hh>
#include <boost/lexical_cast.hpp>

using namespace g4dicom;
using namespace std;
using namespace boost;

G4Material *VDicomMaterialDatabase::GetDefaultMaterial()
{
    return G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");
}

G4Material* DicomMaterialDatabase::GetMaterialByHU(int hu)
{
    if (hu < minHU)
    {
        return GetDefaultMaterial();
    }
    if (_materials.find(hu) == _materials.end())
    {
        G4NistManager* nistManager = G4NistManager::Instance();
        double density = primitiveHUtoDensity(hu);

        string newName = "VOXEL_WATER";
        newName += lexical_cast<string>(hu);
        _materials[hu] = nistManager->BuildMaterialWithNewDensity(newName, "G4_WATER", density);
    }
    return _materials[hu];
}

DicomMaterialDatabase::DicomMaterialDatabase()
{
    _materials[minHU] = GetDefaultMaterial();
}

G4Material* DicomMaterialDatabase::GetMaterial(DicomData* data, int x, int y, int z)
{
    return GetMaterialByHU(data->GetValue(x, y, z));
}

vector<G4Material*> DicomMaterialDatabase::GetAllMaterials()
{
    vector<G4Material*> materials;
    for (auto it = _materials.begin(); it != _materials.end(); it++)
    {
        materials.push_back(it->second);
    }
    return materials;
}

namespace g4dicom
{
    double primitiveHUtoDensity(double hu)
    {
        return 1.0 * g / cm3 * (hu + 1000.0) / 1000.0;
    }
}

{'fraction_non_alphanumeric': 0.1283760084180989, 'fraction_numerical': 0.018589968432129077, 'mean_word_length': 4.31098696461825, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '3600169', 'n_tokens_mistral': 1008, 'n_tokens_neox': 950, 'n_words': 176}