-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from Saverio976/dev
Release 0.5
- Loading branch information
Showing
108 changed files
with
8,838 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Raytracer | ||
** File description: | ||
** BlackAndWhiteCreator.cpp | ||
*/ | ||
|
||
#include "BlackAndWhiteCreator.hpp" | ||
#include "BlackAndWhiteFilter.hpp" | ||
|
||
namespace RayTracer::PluginsExt::BlackAndWhite { | ||
BlackAndWhiteCreator::~BlackAndWhiteCreator() | ||
{ | ||
for (auto element : _elements) { | ||
delete element; | ||
} | ||
} | ||
|
||
Filters::IFilter *BlackAndWhiteCreator::create(const Scenes::ISetting &config, ILogger &logger) | ||
{ | ||
BlackAndWhiteFilter *element = new BlackAndWhiteFilter(config, logger); | ||
_elements.push_back(element); | ||
return element; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Raytracer | ||
** File description: | ||
** BlackAndWhiteCreator.hpp | ||
*/ | ||
|
||
#ifndef SPHERE_CREATOR_HPP_ | ||
#define SPHERE_CREATOR_HPP_ | ||
|
||
#include <vector> | ||
#include <memory> | ||
#include "IFilter.hpp" | ||
#include "IFilterCreator.hpp" | ||
#include "ILogger.hpp" | ||
#include "ISetting.hpp" | ||
#include "BlackAndWhiteFilter.hpp" | ||
|
||
namespace RayTracer::PluginsExt::BlackAndWhite { | ||
class BlackAndWhiteCreator : public Plugins::Filters::IFilterCreator { | ||
public: | ||
~BlackAndWhiteCreator(); | ||
Filters::IFilter *create(const Scenes::ISetting &config, ILogger &logger) final; | ||
|
||
private: | ||
std::vector<BlackAndWhiteFilter *> _elements; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
|
||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Raytracer | ||
** File description: | ||
** BlackAndWhileFilter.hpp | ||
*/ | ||
|
||
#include <algorithm> | ||
#include <exception> | ||
#include <functional> | ||
#include <future> | ||
#include <map> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <vector> | ||
#include "Color.hpp" | ||
#include "ILogger.hpp" | ||
#include "IFilter.hpp" | ||
#include "ISetting.hpp" | ||
#include "Image.hpp" | ||
#include "BlackAndWhiteFilter.hpp" | ||
#include "Vector2i.hpp" | ||
|
||
namespace RayTracer::PluginsExt::BlackAndWhite { | ||
BlackAndWhiteFilter::BlackAndWhiteFilter(const Scenes::ISetting &config, ILogger &logger): | ||
_logger(logger), | ||
_method(*config.get("method")) | ||
{ | ||
std::vector<std::string> availibleModes = { | ||
"R", "G", "B", "Max", "Min", "Average" | ||
}; | ||
try { | ||
_maxThread = static_cast<int>(*config.get("maxThreads")); | ||
_maxThread = (_maxThread == -1) ? std::thread::hardware_concurrency() : _maxThread; | ||
} catch (const Scenes::ISetting::IParsingException &e) { | ||
_maxThread = std::thread::hardware_concurrency(); | ||
} catch (const Scenes::ISetting::ITypeException &e) { | ||
_maxThread = std::thread::hardware_concurrency(); | ||
} | ||
_maxThread = (_maxThread <= 0) ? 1 : _maxThread; | ||
_maxThread = std::thread::hardware_concurrency(); | ||
_logger.info("BlackAndWhile Max threads : " + std::to_string(_maxThread)); | ||
if (std::find(availibleModes.begin(), availibleModes.end(), _method) == availibleModes.end()) { | ||
std::string message = "BlackAndWhile method " + _method + " is not available (choose between:"; | ||
for (auto it : availibleModes) { | ||
message += " " + it; | ||
} | ||
message += ")"; | ||
_logger.fatal(message); | ||
throw std::runtime_error(message); | ||
} | ||
} | ||
|
||
void BlackAndWhiteFilter::waitOnePlace() | ||
{ | ||
while (_futures.size() >= _maxThread) { | ||
for (auto it = _futures.begin() ; it != _futures.end(); it++) { | ||
if ((*it).wait_for(std::chrono::milliseconds(1)) == std::future_status::ready) { | ||
_futures.erase(it); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void BlackAndWhiteFilter::waitAllFinisehd() | ||
{ | ||
while (_futures.size() > 0) { | ||
for (auto it = _futures.begin() ; it != _futures.end(); it++) { | ||
if ((*it).wait_for(std::chrono::milliseconds(1)) == std::future_status::ready) { | ||
_futures.erase(it); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void BlackAndWhiteFilter::apply(Images::Image &image) | ||
{ | ||
_logger.info("Applying BlackAndWhile..."); | ||
|
||
for (int x = 0; x < image.getSize().getX(); x++) { | ||
this->waitOnePlace(); | ||
std::string method = _method; | ||
_futures.push_back(std::async(std::launch::async, [&image, x, method]() { | ||
for (int y = 0; y < image.getSize().getY(); y++) { | ||
image[y][x] = BlackAndWhiteFilter::getColorsMean(image[y][x], method); | ||
} | ||
})); | ||
} | ||
this->waitAllFinisehd(); | ||
_logger.info("BlackAndWhile applied."); | ||
} | ||
|
||
Images::Color BlackAndWhiteFilter::getColorsMean(const Images::Color &color, const std::string &method) | ||
{ | ||
static std::map<std::string, std::function<Images::Color(const Images::Color &)>> _methods = { | ||
{"R", [](const Images::Color &color) { | ||
return Images::Color(color[Images::Color::Types::RED], color[Images::Color::Types::RED], color[Images::Color::Types::RED], color[Images::Color::Types::ALPHA]); | ||
}}, | ||
{"G", [](const Images::Color &color) { | ||
return Images::Color(color[Images::Color::Types::GREEN], color[Images::Color::Types::GREEN], color[Images::Color::Types::GREEN], color[Images::Color::Types::ALPHA]); | ||
}}, | ||
{"B", [](const Images::Color &color) { | ||
return Images::Color(color[Images::Color::Types::BLUE], color[Images::Color::Types::BLUE], color[Images::Color::Types::BLUE], color[Images::Color::Types::ALPHA]); | ||
}}, | ||
{"Max", [](const Images::Color &color) { | ||
double max = std::max(std::max(color[Images::Color::Types::RED], color[Images::Color::Types::GREEN]), color[Images::Color::Types::BLUE]); | ||
return Images::Color(max, max, max, color[Images::Color::Types::ALPHA]); | ||
}}, | ||
{"Min", [](const Images::Color &color) { | ||
double min = std::min(std::min(color[Images::Color::Types::RED], color[Images::Color::Types::GREEN]), color[Images::Color::Types::BLUE]); | ||
return Images::Color(min, min, min, color[Images::Color::Types::ALPHA]); | ||
}}, | ||
{"Average", [](const Images::Color &color) { | ||
double sum = color[Images::Color::Types::RED] + color[Images::Color::Types::GREEN] + color[Images::Color::Types::BLUE]; | ||
return Images::Color(sum / 3, sum / 3, sum / 3, color[Images::Color::Types::ALPHA]); | ||
}} | ||
}; | ||
return _methods[method](color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Raytracer | ||
** File description: | ||
** BlackAndWhiteFilter.hpp | ||
*/ | ||
|
||
#ifndef BASICENTITY_HPP_ | ||
#define BASICENTITY_HPP_ | ||
|
||
#include <future> | ||
#include <string> | ||
#include <vector> | ||
#include "Color.hpp" | ||
#include "ILogger.hpp" | ||
#include "IFilter.hpp" | ||
#include "ISetting.hpp" | ||
#include "Image.hpp" | ||
|
||
namespace RayTracer::PluginsExt::BlackAndWhite { | ||
class BlackAndWhiteFilter : public Filters::IFilter { | ||
public: | ||
BlackAndWhiteFilter(const Scenes::ISetting &config, ILogger &logger); | ||
void apply(Images::Image &image) final; | ||
|
||
private: | ||
/** | ||
* @brief Wait one place in the vector of futures | ||
*/ | ||
void waitOnePlace(); | ||
/** | ||
* @brief Wait all places in the vector of futures | ||
*/ | ||
void waitAllFinisehd(); | ||
/** | ||
* @brief Mean of the colors | ||
* | ||
* @param colors The colors to mean | ||
* | ||
* @return The mean | ||
*/ | ||
static Images::Color getColorsMean(const Images::Color &color, const std::string &method); | ||
ILogger &_logger; | ||
int _maxThread; | ||
std::vector<std::future<void>> _futures; | ||
std::string _method; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
target_sources(BlackAndWhite PRIVATE | ||
EntryPoint.cpp | ||
BlackAndWhiteFilter.cpp | ||
BlackAndWhiteCreator.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** raytracer | ||
** File description: | ||
** EntryPoint.cpp | ||
*/ | ||
|
||
#include <vector> | ||
#include "BlackAndWhiteFilter.hpp" | ||
#include "Api.hpp" | ||
#include "BlackAndWhiteCreator.hpp" | ||
|
||
extern "C" { | ||
void *getCreator(void) | ||
{ | ||
return new RayTracer::PluginsExt::BlackAndWhite::BlackAndWhiteCreator(); | ||
} | ||
|
||
void deleteCreator(void *creator) | ||
{ | ||
delete static_cast<RayTracer::PluginsExt::BlackAndWhite::BlackAndWhiteCreator *>(creator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
target_sources(MirrorMaterial PRIVATE | ||
MirrorMaterial.cpp | ||
MirrorCreator.cpp | ||
EntryPoint.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** raytracer | ||
** File description: | ||
** EntryPoint.cpp | ||
*/ | ||
|
||
#include <vector> | ||
#include "Api.hpp" | ||
#include "MirrorCreator.hpp" | ||
|
||
extern "C" { | ||
void *getCreator(void) | ||
{ | ||
return new RayTracer::PluginsExt::Mirror::MirrorCreator(); | ||
} | ||
|
||
void deleteCreator(void *creator) | ||
{ | ||
delete static_cast<RayTracer::PluginsExt::Mirror::MirrorCreator *>(creator); | ||
} | ||
} |
Oops, something went wrong.