Commit 1be37984 authored by MURRAY David's avatar MURRAY David
Browse files

index by texture OK (need further check)

parent 97fef665
......@@ -1237,6 +1237,7 @@ void OptixMaterialHandler::updateMaterialIndex(mrf::materials::MultiMaterial *mu
if (multi_mat->hasTexture())
{
multi_mat->normalizeMapIndices("");
if (multi_mat->getIndexMap().width() > 0 && multi_mat->getIndexMap().height() > 0)
{
auto it = _mat_index_maps.find(multi_mat);
......
......@@ -60,7 +60,13 @@ IndexedUTIA::IndexedUTIA(std::string const &name): BRDF(name)
//, _phiIdiv(1)
{}
IndexedUTIA::~IndexedUTIA() {}
IndexedUTIA::~IndexedUTIA() {
//for (auto it = _utia_materials.begin(); it != _utia_materials.end(); ++it)
//{
// auto mat = it->second;
// mat->destroy();
//}
}
mrf::image::IMAGE_LOAD_SAVE_FLAGS IndexedUTIA::loadUTIAData(std::string const &filename, const int index)
{
......
......@@ -6,7 +6,7 @@ namespace mrf
{
namespace materials
{
MultiMaterial::MultiMaterial(std::string const &name): BRDF(name) {}
MultiMaterial::MultiMaterial(std::string const &name): BRDF(name), _normalized(false) {}
MultiMaterial::~MultiMaterial() {}
mrf::image::IMAGE_LOAD_SAVE_FLAGS MultiMaterial::loadIndexTexture(std::string const &path)
......@@ -24,5 +24,41 @@ mrf::image::IMAGE_LOAD_SAVE_FLAGS MultiMaterial::loadIndexTexture(std::string co
return mrf::image::IMAGE_LOAD_SAVE_FLAGS::MRF_NO_ERROR;
}
void MultiMaterial::normalizeMapIndices(std::string exportPath)
{
if (!_normalized)
{
std::map<unsigned int, int> matToIndex;
for (int i = 0; i < _mrf_indices.size(); ++i)
{
unsigned int mat = _mrf_indices[i];
matToIndex[mat] = i;
}
for (int i = 0; i < _index_map.get()->width() * _index_map.get()->height(); ++i)
{
mrf::color::Color pixel = _index_map.get()->getPixel(i);
int mat;
if (matToIndex.count(pixel.x() * 255) > 0)
{
mat = matToIndex.at(pixel.x() * 255);
}
else
{
//material is not among the provided UTIA files, disable it.
mat = -1;
}
pixel.r() = mat / 255.f;
_index_map.get()->setPixel(i, pixel);
}
_normalized = true;
}
}
} // namespace materials
} // namespace mrf
\ No newline at end of file
......@@ -24,6 +24,7 @@ protected:
std::string _index_texture_path;
std::unique_ptr<mrf::image::ColorImage> _index_map;
bool _normalized;
public:
MultiMaterial(std::string const &name);
......@@ -48,6 +49,8 @@ public:
bool hasTexture() const { return _index_map.get() != nullptr; }
void normalizeMapIndices(std::string exportPath);
size_t size() { return _names.size(); }
};
} // namespace materials
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment