Skip to content

Commit

Permalink
fixing exports
Browse files Browse the repository at this point in the history
  • Loading branch information
wkjarosz committed Dec 27, 2023
1 parent b542ca5 commit 2fa0a69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
4 changes: 2 additions & 2 deletions include/export_to_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
using namespace linalg::aliases;

// encapsulated postscript file
std::string header_eps(const float3 &point_color, float scale, float radius);
std::string header_eps(const float3 &point_color, float radius);
std::string footer_eps();
std::string draw_grid_eps(const float4x4 &mvp, int grid_res);
std::string draw_grids_eps(float4x4 mat, int fgrid_res, int cgrid_res, bool fine_grid, bool coarse_grid, bool bbox);
std::string draw_points_eps(float4x4 mat, int3 dim, const Array2d<float> &points, int2 range);

// scalable vector graphics file
std::string header_svg(const float3 &point_color, float scale = 1.f);
std::string header_svg(const float3 &point_color);
std::string footer_svg();
std::string draw_grid_svg(const float4x4 &mvp, int grid_res, const std::string &css_class);
std::string draw_grids_svg(float4x4 mat, int fgrid_res, int cgrid_res, bool fine_grid, bool coarse_grid, bool bbox);
Expand Down
17 changes: 3 additions & 14 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ string SampleViewer::export_XYZ_points(const string &format)
// radius *= 64.0f / std::sqrt(m_point_count);
float radius = m_radius / (m_scale_radius_with_points ? std::sqrt(m_point_count) : 1.0f);

string out = (format == "eps") ? header_eps(m_point_color, 1.f, radius) : header_svg(m_point_color);
string out = (format == "eps") ? header_eps(m_point_color, radius) : header_svg(m_point_color);

float4x4 mvp = m_camera[CAMERA_CURRENT].matrix(1.0f);

Expand All @@ -1558,12 +1558,9 @@ string SampleViewer::export_XYZ_points(const string &format)

string SampleViewer::export_points_2d(const string &format, CameraType camera_type, int3 dim)
{
// float radius = map_slider_to_radius(m_radius);
// if (m_scale_radius_with_points)
// radius *= 64.0f / std::sqrt(m_point_count);
float radius = m_radius / (m_scale_radius_with_points ? std::sqrt(m_point_count) : 1.0f);

string out = (format == "eps") ? header_eps(m_point_color, 1.f, radius) : header_svg(m_point_color);
string out = (format == "eps") ? header_eps(m_point_color, radius) : header_svg(m_point_color);

float4x4 mvp = m_camera[camera_type].matrix(1.0f);

Expand All @@ -1588,12 +1585,9 @@ string SampleViewer::export_all_points_2d(const string &format)
{
float scale = 1.0f / (m_num_dimensions - 1);

// float radius = map_slider_to_radius(m_radius);
// if (m_scale_radius_with_points)
// radius *= 64.0f / std::sqrt(m_point_count);
float radius = m_radius / (m_scale_radius_with_points ? std::sqrt(m_point_count) : 1.0f);

string out = (format == "eps") ? header_eps(m_point_color, scale, radius) : header_svg(m_point_color, scale);
string out = (format == "eps") ? header_eps(m_point_color, radius * scale) : header_svg(m_point_color);

float4x4 mvp = m_camera[CAMERA_2D].matrix(1.0f);

Expand Down Expand Up @@ -1640,11 +1634,6 @@ float4x4 CameraParameters::matrix(float window_aspect) const

int main(int argc, char **argv)
{
#if defined(HELLOIMGUI_USE_GLES3)
fmt::print("GLES3!\n");
#elif defined(HELLOIMGUI_USE_GLES2)
fmt::print("GLES2!\n");
#endif
vector<string> args;
bool help = false;
bool error = false;
Expand Down
40 changes: 21 additions & 19 deletions src/export_to_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
using std::ofstream;
using std::string;

string header_eps(const float3 &point_color, float scale, float radius)
static const float svg_page_size = 1000.0f;
static const float line_size = 0.001f * svg_page_size;

string header_eps(const float3 &point_color, float radius)
{
string out;

float page_size = 500.f;
float page_size = 0.5f * svg_page_size;

out += fmt::format("%!PS-Adobe-3.0 EPSF-3.0\n");
out += fmt::format("%%HiResBoundingBox: {} {} {} {}\n", -page_size, -page_size, page_size, page_size);
out += fmt::format("%%BoundingBox: {} {} {} {}\n", -page_size, -page_size, page_size, page_size);
out += fmt::format("%%CropBox: {} {} {} {}\n", -page_size, -page_size, page_size, page_size);
out += fmt::format("/radius {{ {} }} def %define variable for point radius\n", radius * 0.3f * scale);
out += fmt::format("/radius {{ {} }} def %define variable for point radius\n", radius * page_size);
out += fmt::format("/p {{ radius 0 360 arc closepath fill }} def %define point command\n");
out += fmt::format("/blw {} def %define variable for bounding box linewidth\n", 2.f * scale);
out += fmt::format("/clw {} def %define variable for coarse linewidth\n", 2.f * scale);
out += fmt::format("/flw {} def %define variable for fine linewidth\n", 2.f * scale);
out += fmt::format("/blw {} def %define variable for bounding box linewidth\n", 2.f);
out += fmt::format("/clw {} def %define variable for coarse linewidth\n", line_size);
out += fmt::format("/flw {} def %define variable for fine linewidth\n", line_size);
out += fmt::format("/pfc {{ {} {} {} }} def %define variable for point fill color\n", point_color.x, point_color.y,
point_color.z);
out += fmt::format("/blc {} def %define variable for bounding box color\n", 0.0f);
Expand Down Expand Up @@ -141,30 +144,27 @@ string draw_points_eps(float4x4 mat, int3 dim, const Array2d<float> &points, int
{
string out;

float page_size = 500.f;
float page_size = 0.5f * svg_page_size;

// Render the point set
out += "% Draw points \n";
out += "pfc setrgbcolor %fill color for points\n";

for (int i = range.x; i < range.x + range.y; ++i)
{
auto v4d = mul(mat, float4{points(dim.x, i), points(dim.y, i), points(dim.z, i), 1.0f});
auto v4d =
mul(mat, float4{points(dim.x, i), points(dim.y, i), points(dim.z, i), 1.0f} - float4{float3{0.5f}, 0.f});
auto v2d = float2{v4d.x / v4d.w, v4d.y / v4d.w} * page_size;
out += fmt::format("{} {} p\n", v2d.x, v2d.y);
}

return out;
}

string header_svg(const float3 &point_color, float scale)
string header_svg(const float3 &point_color)
{
string out;

scale *= 0.5f;

float page_size = 500.f;

out += fmt::format(R"_(<svg
width="{}px"
height="{}px"
Expand Down Expand Up @@ -204,8 +204,9 @@ string header_svg(const float3 &point_color, float scale)
}}
</style>
)_",
1000, 1000, -page_size, -page_size, 2 * page_size, 2 * page_size, int(point_color.x * 255),
int(point_color.y * 255), int(point_color.z * 255), 2.f * scale, 2.f * scale, 2.f * scale);
svg_page_size, svg_page_size, -svg_page_size * 0.5f, -svg_page_size * 0.5f, svg_page_size,
svg_page_size, int(point_color.x * 255), int(point_color.y * 255), int(point_color.z * 255),
0.001f * svg_page_size, 0.001f * svg_page_size, 0.001f * svg_page_size);
return out;
}

Expand All @@ -215,7 +216,7 @@ string draw_grid_svg(const float4x4 &mvp, int grid_res, const string &css_class)
float2 vA, vB;

float scale = 1.f / grid_res;
float page_size = 500.f;
float page_size = 0.5f * svg_page_size;

string out;

Expand Down Expand Up @@ -275,13 +276,14 @@ string draw_grids_svg(float4x4 mat, int fgrid_res, int cgrid_res, bool fine_grid
string draw_points_svg(float4x4 mat, int3 dim, const Array2d<float> &points, int2 range, float radius)
{
string out;
float page_size = 500.f;
float page_size = 0.5f * svg_page_size;

for (int i = range.x; i < range.x + range.y; ++i)
{
auto v4d = mul(mat, float4{points(dim.x, i), points(dim.y, i), points(dim.z, i), 1.0f});
auto v4d =
mul(mat, float4{points(dim.x, i), points(dim.y, i), points(dim.z, i), 1.0f} - float4{float3{0.5f}, 0.f});
auto v2d = float2{v4d.x / v4d.w, v4d.y / v4d.w} * float2{page_size, -page_size};
out += fmt::format(" <circle cx=\"{}\" cy=\"{}\" r=\"{}\"/>\n", v2d.x, v2d.y, radius * 0.3f);
out += fmt::format(" <circle cx=\"{}\" cy=\"{}\" r=\"{}\"/>\n", v2d.x, v2d.y, radius * page_size);
}

return out;
Expand Down

0 comments on commit 2fa0a69

Please sign in to comment.