7 #ifndef GRAPHGEN_FOREST_HANDLER_H_
8 #define GRAPHGEN_FOREST_HANDLER_H_
42 std::map<ForestHandlerFlags, LineForestHandler>
f_;
43 std::map<ForestHandlerFlags, std::string> names = {
49 std::map<ForestHandlerFlags, std::string> prefixs = {
69 for (
const auto& p : ps) {
71 first_line_constr[p.name_] = 0;
78 for (
const auto& p : ps) {
80 last_line_constr[p.name_] = 0;
87 for (
const auto& p : ps) {
89 single_line_constr[p.name_] = 0;
137 for (
const auto& i : f_) {
139 std::ofstream os(filepath);
141 std::cout <<
"Something went wrong during the generation of " <<
conf.
algorithm_name_ <<
"forest code\n";
145 last_id =
GenerateLineForestCode(os, i.second, prefixs[i.first] +
"_", last_id, before_main, after_main, before_end, after_end_no_loop);
146 os << prefixs[i.first] +
"_" <<
":;\n";
149 last_id =
GenerateLineForestCode(os, i.second, prefixs[i.first] +
"_", last_id, before_main, after_main, before_end, after_end);
170 return f_.at(forest_id);
This class allows to generate the forests associated to an algorithm when the pixel prediction is app...
void GenerateCode(BEFORE_AFTER_FUNC(before_main)=BeforeMainShiftOne, BEFORE_AFTER_FUNC(after_main)=DefaultEmptyFunc, BEFORE_AFTER_FUNC(before_end)=BeforeEnd, BEFORE_AFTER_FUNC(after_end)=AfterEnd, BEFORE_AFTER_FUNC(after_end_no_loop)=AfterEndNoLoop, int flags=0)
Generates the code for the all the forests groups, each of them in a separate file.
void DrawOnFile(const std::string &prefix, DrawDagFlags flags=DrawDagFlags::NONE)
std::map< ForestHandlerFlags, LineForestHandler > f_
void Compress(DragCompressorFlags flags=DragCompressorFlags::PRINT_STATUS_BAR|DragCompressorFlags::IGNORE_LEAVES, int iterations=- 1)
Compresses all the drags of the forest using an exhaustive approach.
ForestHandler(const BinaryDrag< conact > &bd, const pixel_set &ps, ForestHandlerFlags flag=ForestHandlerFlags::CENTER_LINES|ForestHandlerFlags::FIRST_LINE)
LineForestHandler & GetLineForestHandler(ForestHandlerFlags forest_id)
DragCompressorFlags
This enum class defines the available flags for the DragCompression class.
@ IGNORE_LEAVES
Whether to ignore leaves or not during the compression. Please note that compressing the leaves will ...
@ PRINT_STATUS_BAR
Whether to print a sort of progress bar or not.
std::map< std::string, int > constraints
@ FIRST_LINE
Whether to generate the forest for the first line of the image.
@ CENTER_LINES
Whether to generate the forest for the center lines of the image.
@ SINGLE_LINE
Whether to generate the forest for an image composed by a single line.
@ LAST_LINE
Whether to generate the forest for the last line of the image.
std::string BeforeMainShiftOne(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
std::string AfterEndNoLoop(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
std::string AfterEnd(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
std::string BeforeEnd(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
size_t GenerateLineForestCode(std::ostream &os, const LineForestHandler &lfh, std::string prefix, size_t start_id, std::string before_main(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id), std::string after_main(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id), std::string before_end(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id), std::string after_end(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id))
Generate the C++ code for the given Forest.
std::string DefaultEmptyFunc(size_t index, const std::string &prefix, const std::vector< std::vector< size_t >> &mapping, size_t end_group_id)
#define BEFORE_AFTER_FUNC(func_name)
Macro used to define the base signature of before and after functions.
bool DrawForestOnFile(const string &output_file, const LineForestHandler &lfh, DrawDagFlags flags)
DrawDagFlags
Flags for the DrawDagOnFile function.
std::filesystem::path GetForestCodePath(const std::string &out_base_name)
std::string algorithm_name_
Generates all the forests needed to handle one line of the image.
#define DEFINE_ENUM_CLASS_FLAGS(class_name,...)