Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Find out if $BUILD_DIR is set, if not then assume it's in a local environment
if [[ -z ${BUILD_DIR} ]]; then
BUILD_DIR=build
fi

if [[ -n ${BUILD_DIR} ]]; then
# Docker is already a virtual environment so no need to create one
# Build the project
Expand All @@ -10,13 +14,13 @@ else
python3 -m venv .venv
source .venv/bin/activate

if [[ -z ${BUILD_TYPE} ]]; then
BUILD_TYPE=Release
fi

# Output BUILD_DIR and BUILD_TYPE
echo "Building in directory: $BUILD_DIR, with build type: $BUILD_TYPE"
if [[ -z ${BUILD_TYPE} ]]; then
BUILD_TYPE=Release
fi

# Output BUILD_DIR and BUILD_TYPE
echo "Building in directory: $BUILD_DIR, with build type: $BUILD_TYPE"
fi
# Warn user if BUILD_DIR already exists
if [[ -d $BUILD_DIR ]]; then
echo "Warning: $BUILD_DIR already exists. Pre-existing cache may interfere with the build process and cause installation to fail. Consider deleting it before proceeding."
Expand Down
2 changes: 1 addition & 1 deletion include/cartogram_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CartogramInfo
void rescale_insets();

std::string set_map_name(const std::string &);
void reposition_insets(bool output_to_stdout = false);
void reposition_insets();

void plot_input();
void preprocess();
Expand Down
1 change: 0 additions & 1 deletion include/inset_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ class InsetState

void write_map(
const std::string &,
bool,
bool equal_area_map = false,
const std::unordered_map<Point, Vector> =
std::unordered_map<Point, Vector>()) const;
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this file has been mistakenly added.

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/cartogram_info/cartogram_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ void CartogramInfo::write_shifted_insets()

void CartogramInfo::write_svg(const std::string &suffix)
{
// Skip SVG output if redirect_exports_to_stdout is enabled
if (args_.redirect_exports_to_stdout) {
return;
}

InsetState insets_combined = convert_to_inset_state();
insets_combined.rescale_map();

Expand Down
6 changes: 3 additions & 3 deletions src/cartogram_info/shift_insets_to_position.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "cartogram_info.hpp"
#include "constants.hpp"

void CartogramInfo::reposition_insets(bool output_to_stdout)
void CartogramInfo::reposition_insets()
{

// Warn user about repositoning insets with `--skip_projection` flag
Expand All @@ -28,7 +28,7 @@ void CartogramInfo::reposition_insets(bool output_to_stdout)
// If the inset actually exists, we get its current bounding box
for (const InsetState &inset_state : inset_states_) {
std::string inset_pos = inset_state.pos();
bboxes.at(inset_pos) = inset_state.bbox(output_to_stdout);
bboxes.at(inset_pos) = inset_state.bbox(args_.redirect_exports_to_stdout);
}

// Calculate the width and height of all positioned insets without spacing
Expand Down Expand Up @@ -100,7 +100,7 @@ void CartogramInfo::reposition_insets(bool output_to_stdout)
// Apply translation to all points
inset_state.transform_points(translate, false);

if (output_to_stdout) {
if (args_.redirect_exports_to_stdout) {
inset_state.transform_points(translate, true);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ void InsetState::write_intersections_image()

void InsetState::write_map(
const std::string &file_name,
const bool plot_grid,
const bool equal_area_map,
const std::unordered_map<Point, Vector> vectors) const
{
Expand All @@ -177,7 +176,7 @@ void InsetState::write_map(
/*colours =*/has_colors,
*this);

if (plot_grid) {
if (args_.plot_grid) {
write_grid(cvs, *this);
write_legend(cvs, equal_area_map, *this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/inset_state/blur_density.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void InsetState::blur_density()
execute_fftw_bwd_plan();
timer.stop("Blur");

// Do not plot if the blur width is too small
if (args_.plot_density && bw > 0.1) {
// Do not plot if the blur width is too small or when redirecting to stdout
if (args_.plot_density && bw > 0.1 && !args_.redirect_exports_to_stdout) {
std::string file_name = file_prefix_ + "_blurred_density.svg";
write_density_image(file_name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/inset_state/fill_with_density.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void InsetState::fill_with_density()
fill_with_density_clip();
}

// Plot density map if requested
if (args_.plot_density) {
// Plot density map if requested (but not when redirecting to stdout)
if (args_.plot_density && !args_.redirect_exports_to_stdout) {
std::string file_name = file_prefix_ + "_unblurred_density.svg";
write_density_image(file_name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/inset_state/flatten_density.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool InsetState::flatten_density()
create_and_refine_quadtree();
create_delaunay_t();

if (args_.plot_quadtree) {
if (args_.plot_quadtree && !args_.redirect_exports_to_stdout) {
write_quadtree(file_prefix_ + "_quadtree");
write_delaunay_triangles(file_prefix_ + "a_delaunay_t", false);
}
Expand Down
13 changes: 7 additions & 6 deletions src/inset_state/integrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ void InsetState::preprocess()
std::cerr << "End of initial simplification of " << pos_ << std::endl;
}

// Plot if requested
if (args_.plot_polygons) {
// Plot if requested (but not when redirecting to stdout)
if (args_.plot_polygons && !args_.redirect_exports_to_stdout) {

// Color if necessary
auto_color();
initialize_identity_proj();
write_map(inset_name_ + "_input", args_.plot_grid, true);
write_map(inset_name_ + "_input", true);
}

timer.stop("Preprocessing");
Expand Down Expand Up @@ -137,9 +137,10 @@ void InsetState::integrate(ProgressTracker &progress_tracker)
std::cerr << "Finished integrating inset " << pos_ << std::endl;
progress_tracker.update_and_print_progress_end_integration(n_geo_divs());

// Write SVG for this inset, if requested
if (args_.plot_polygons) {
write_map(inset_name() + "_output", args_.plot_grid, false);
// Write SVG for this inset, if requested (but not when redirecting to
// stdout)
if (args_.plot_polygons && !args_.redirect_exports_to_stdout) {
write_map(inset_name() + "_output", false);
}

// Project original map with cumulative projection
Expand Down
8 changes: 4 additions & 4 deletions src/inset_state/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ void InsetState::project()
densify_geo_divs_using_delaunay_t();
}

// Plot if requested
if (args_.plot_quadtree) {
// Plot if requested (but not when redirecting to stdout)
if (args_.plot_quadtree && !args_.redirect_exports_to_stdout) {
write_delaunay_triangles(
file_prefix_ + "c_updated_delaunay_t_after_flatten",
false);
Expand All @@ -21,7 +21,7 @@ void InsetState::project()
// Project using the updated Delaunay triangulation and plot
project_with_delaunay_t(args_.redirect_exports_to_stdout);

if (args_.plot_quadtree) {
if (args_.plot_quadtree && !args_.redirect_exports_to_stdout) {
write_delaunay_triangles(
file_prefix_ + "d_projected_with_updated_delaunay_t",
true);
Expand Down Expand Up @@ -50,7 +50,7 @@ void InsetState::project()

simplify(args_.target_points_per_inset);
}
if (args_.plot_intersections) {
if (args_.plot_intersections && !args_.redirect_exports_to_stdout) {
write_intersections_image();
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ int main(const int argc, const char *argv[])
// Store total number of GeoDivs to monitor progress
size_t total_geo_divs = cart_info.n_geo_divs();

// Write input map, with insets nicely placed
if (args.plot_polygons) {
// Write input map, with insets nicely placed (but not when redirecting to
// stdout)
if (args.plot_polygons && !args.redirect_exports_to_stdout) {
cart_info.plot_input();
}

Expand Down Expand Up @@ -59,12 +60,12 @@ int main(const int argc, const char *argv[])
cart_info.rescale_insets();

// Shift insets so that they do not overlap
cart_info.reposition_insets(args.redirect_exports_to_stdout);
cart_info.reposition_insets();

// Output to GeoJSON
cart_info.write_geojson("cartogram");

if (args.plot_polygons) {
if (args.plot_polygons && !args.redirect_exports_to_stdout) {
cart_info.write_svg("cartogram");
}

Expand Down