Skip to content

Commit

Permalink
Merge pull request #547 from pangenome/color-better
Browse files Browse the repository at this point in the history
write highlights over the rasterized image
  • Loading branch information
AndreaGuarracino authored Feb 7, 2024
2 parents 9ae6a65 + d55a6aa commit 7f4f78a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/algorithms/atomic_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ std::ostream& operator<<(std::ostream& out, const color_t& c) {
return out;
}

bool operator==(const color_t& a, const color_t& b) {
return a.c.r == b.c.r && a.c.g == b.c.g && a.c.b == b.c.b && a.c.a == b.c.a;
}

color_t lighten(const color_t& c, const double& f) {
return layer(c, COLOR_WHITE, f);
}
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/atomic_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef union rgb_t {
} color_t;

std::ostream& operator<<(std::ostream& out, const color_t& c);
bool operator==(const color_t& a, const color_t& b);

color_t hash_color(const std::string& s);
color_t lighten(const color_t& c, const double& f);
Expand Down
20 changes: 18 additions & 2 deletions src/algorithms/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,18 @@ std::vector<uint8_t> rasterize(const std::vector<double> &X,
source_min_x, source_min_y);

auto range_itr = component_ranges.begin();
struct draw_target_t {
xy_d_t xy0;
xy_d_t xy1;
algorithms::color_t color;
};

for (auto& component : weak_components) {
auto& range = *range_itr++;
auto& x_off = range.x_offset;
auto& y_off = range.y_offset;
#pragma omp parallel for
std::vector<draw_target_t> highlights;
//#pragma omp parallel for
for (uint64_t i = 0; i < component.size(); ++i) {
const handle_t& handle = component[i];
uint64_t a = 2 * number_bool_packing::unpack_number(handle);
Expand Down Expand Up @@ -252,9 +259,18 @@ std::vector<uint8_t> rasterize(const std::vector<double> &X,
*/
const algorithms::color_t node_color = !node_id_to_color.empty() ? node_id_to_color[graph.get_id(handle)] : COLOR_BLACK;

wu_calc_wide_line(xy0, xy1, node_color, image, line_width);
// if gray or black color, otherwise save for later
if (node_color == COLOR_BLACK || node_color == COLOR_LIGHTGRAY) {
wu_calc_wide_line(xy0, xy1, node_color, image, line_width);
} else {
highlights.push_back({xy0, xy1, node_color});
}
}
}
// color highlights
for (auto& highlight : highlights) {
wu_calc_wide_line(highlight.xy0, highlight.xy1, highlight.color, image, line_width);
}
}

// todo, edges, paths, coverage, bins
Expand Down

0 comments on commit 7f4f78a

Please sign in to comment.