Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Enumerations | Functions
geometrize::exporter Namespace Reference

Enumerations

enum  ShapeDataFormat { ShapeDataFormat::JSON, ShapeDataFormat::CUSTOM_ARRAY }
 

Functions

bool exportGIF (const std::vector< geometrize::ShapeResult > &data, std::uint32_t inputWidth, std::uint32_t inputHeight, std::uint32_t outputWidth, std::uint32_t outputHeight, const std::function< bool(std::size_t)> &frameSkipPredicate, const std::string &filePath)
 exportGIF Exports shape data to a GIF image. More...
 
bool exportBitmap (const geometrize::Bitmap &bitmap, const std::string &filePath)
 exportBitmap Exports the Geometrize bitmap data to an image format that Qt supports (depending on the file extension). More...
 
bool exportImage (const QImage &image, const std::string &filePath)
 exportImage Exports the image data to an image format that Qt supports (depending on the file extension). More...
 
bool exportImages (const std::vector< QImage > &images, const std::string &targetDir, const std::string &baseFilename, const std::string &fileExtension)
 exportImages Exports the image data to an image format that Qt supports (depending on the file extension). More...
 
QImage renderSvgShapeDataToImage (const std::vector< geometrize::ShapeResult > &shapes, const std::uint32_t inputWidth, const std::uint32_t inputHeight, const std::uint32_t outputWidth, const std::uint32_t outputHeight)
 renderSvgShapeDataToImage Renders the given shape data to an image via an SVG. More...
 
bool exportRasterizedSvg (const std::vector< geometrize::ShapeResult > &shapes, std::uint32_t inputWidth, std::uint32_t inputHeight, std::uint32_t outputWidth, std::uint32_t outputHeight, const std::string &filePath)
 exportRasterizedSvg Exports the shape data as an image by rasterizing an SVG rendered from the shape data. More...
 
bool exportRasterizedSvgs (const std::vector< geometrize::ShapeResult > &shapes, std::uint32_t inputWidth, std::uint32_t inputHeight, std::uint32_t outputWidth, std::uint32_t outputHeight, const std::string &targetDir, const std::string &baseFilename, const std::string &fileExtension)
 exportRasterizedSvgs Exports the shape data to images by rasterizing SVGs rendered from the shape data. Exports one image for each shape i.e. an image with one shape, two shapes, three shapes. More...
 
std::string exportShapeData (const std::vector< geometrize::ShapeResult > &data, ShapeDataFormat format)
 exportShapeData Exports shape data to a specified format (JSON or a custom textual array format). More...
 
std::string exportCanvasWebpage (const std::vector< geometrize::ShapeResult > &data)
 exportCanvasWebpage Exports shape data to a HTML5 canvas-based webpage. More...
 
std::string exportWebGLWebpage (const std::vector< geometrize::ShapeResult > &data)
 exportWebGLWebpage Exports shape data to a WebGL-based webpage. More...
 

Enumeration Type Documentation

Function Documentation

bool geometrize::exporter::exportBitmap ( const geometrize::Bitmap &  bitmap,
const std::string &  filePath 
)

exportBitmap Exports the Geometrize bitmap data to an image format that Qt supports (depending on the file extension).

Parameters
bitmapThe image data to save as an image file.
filePathThe full path to the image file target (include the filename and file extension).
Returns
True if the image was saved, else false.
25 {
26  const QImage image{geometrize::image::createImage(bitmap)};
27  return exportImage(image, filePath);
28 }
QImage createImage(const Bitmap &data)
createImage Creates an image from the bitmap data object. Assumes RGBA8888 format.
Definition: imageloader.cpp:46
bool exportImage(const QImage &image, const std::string &filePath)
exportImage Exports the image data to an image format that Qt supports (depending on the file extensi...
Definition: imageexporter.cpp:30

Here is the call graph for this function:

Here is the caller graph for this function:

std::string geometrize::exporter::exportCanvasWebpage ( const std::vector< geometrize::ShapeResult > &  data)

exportCanvasWebpage Exports shape data to a HTML5 canvas-based webpage.

Parameters
dataThe shape data to export.
Returns
A string containing the content of the canvas-based webpage.
56 {
57  return exportWebpage(":/web_export/templates/web_export_template.html", ":/web_export/templates/backend_canvas.js", data);
58 }

Here is the caller graph for this function:

bool geometrize::exporter::exportGIF ( const std::vector< geometrize::ShapeResult > &  data,
std::uint32_t  inputWidth,
std::uint32_t  inputHeight,
std::uint32_t  outputWidth,
std::uint32_t  outputHeight,
const std::function< bool(std::size_t)> &  frameSkipPredicate,
const std::string &  filePath 
)

exportGIF Exports shape data to a GIF image.

Parameters
dataThe shape data to export.
inputWidthThe width of the canvas each frame will be rendered to.
inputHeightThe height of the canvas each frame will be rendered to.
outputWidthThe width of the image each frame will be rasterized into.
outputHeightThe height of the image each frame will be rasterized into.
filePathThe full path to the GIF image file target (include the filename and .gif extension).
Returns
True if the GIF was saved, else false.
88 {
89  blk::BurstLinker gif;
90  if(!gif.init(filePath.c_str(), outputWidth, outputHeight, 0, std::max(1U, std::thread::hardware_concurrency()))) {
91  assert(0 && "Failed to initialize BurstLinker GIF export");
92  return false;
93  }
94 
95  // Could start by adding the final result
96  //addFrame(data, inputWidth, inputHeight, outputWidth, outputHeight, 400, gif);
97 
98  for(std::uint32_t i = 0; i < data.size(); i++) {
99  if(frameSkipPredicate(i)) {
100  continue;
101  }
102 
103  std::uint32_t delayMs = i == 0 ? 0 : std::max(20, static_cast<std::int32_t>(1000 / (i + 1)));
104  if(i == data.size() - 1U) {
105  delayMs = 2000; // Extra delay at end of animation
106  }
107 
108  const std::vector<geometrize::ShapeResult> shapes(data.begin(), data.begin() + i);
109  addFrame(shapes, inputWidth, inputHeight, outputWidth, outputHeight, delayMs, gif);
110  }
111 
112  gif.release();
113  return true;
114 }

Here is the caller graph for this function:

bool geometrize::exporter::exportImage ( const QImage &  image,
const std::string &  filePath 
)

exportImage Exports the image data to an image format that Qt supports (depending on the file extension).

Parameters
imageThe image to save as an image file.
filePathThe full path to the image file target (include the filename and file extension).
Returns
True if the image was saved, else false.
31 {
32  return image.save(QString::fromStdString(filePath));
33 }

Here is the caller graph for this function:

bool geometrize::exporter::exportImages ( const std::vector< QImage > &  images,
const std::string &  targetDir,
const std::string &  baseFilename,
const std::string &  fileExtension 
)

exportImages Exports the image data to an image format that Qt supports (depending on the file extension).

Parameters
imagesThe images to save as image files.
targetDirThe target directory.
baseFilenameThe base file name.
fileExtensionThe file extension (".jpg", ".png").
Returns
True if the images were saved, else false.
36 {
37  for(std::size_t i = 0; i < images.size(); i++) {
38  const std::string path{targetDir + baseFilename + "_" + std::to_string(i) + fileExtension};
39  if(!images[i].save(QString::fromStdString(path))) {
40  return false;
41  }
42  }
43  return true;
44 }
bool geometrize::exporter::exportRasterizedSvg ( const std::vector< geometrize::ShapeResult > &  shapes,
std::uint32_t  inputWidth,
std::uint32_t  inputHeight,
std::uint32_t  outputWidth,
std::uint32_t  outputHeight,
const std::string &  filePath 
)

exportRasterizedSvg Exports the shape data as an image by rasterizing an SVG rendered from the shape data.

Parameters
shapesThe shape data to export.
inputWidthThe width of the canvas the SVG will be rendered to.
inputHeightThe height of the canvas the SVG will be rendered to.
outputWidthThe width of the image the SVG will be rasterized into.
outputHeightThe height of the image the SVG will be rasterized into.
filePathThe full path to the image file target (include the filename and file extension).
Returns
True if the image was saved, else false.
81 {
82  const QImage image{geometrize::exporter::renderSvgShapeDataToImage(shapes, inputWidth, inputHeight, outputWidth, outputHeight)};
83  return geometrize::exporter::exportImage(image, filePath);
84 }
bool exportImage(const QImage &image, const std::string &filePath)
exportImage Exports the image data to an image format that Qt supports (depending on the file extensi...
Definition: imageexporter.cpp:30
QImage renderSvgShapeDataToImage(const std::vector< geometrize::ShapeResult > &shapes, const std::uint32_t inputWidth, const std::uint32_t inputHeight, const std::uint32_t outputWidth, const std::uint32_t outputHeight)
renderSvgShapeDataToImage Renders the given shape data to an image via an SVG.
Definition: imageexporter.cpp:46

Here is the call graph for this function:

Here is the caller graph for this function:

bool geometrize::exporter::exportRasterizedSvgs ( const std::vector< geometrize::ShapeResult > &  shapes,
std::uint32_t  inputWidth,
std::uint32_t  inputHeight,
std::uint32_t  outputWidth,
std::uint32_t  outputHeight,
const std::string &  targetDir,
const std::string &  baseFilename,
const std::string &  fileExtension 
)

exportRasterizedSvgs Exports the shape data to images by rasterizing SVGs rendered from the shape data. Exports one image for each shape i.e. an image with one shape, two shapes, three shapes.

Parameters
shapesThe shape data to export.
inputWidthThe width of the canvas the SVG will be rendered to.
inputHeightThe height of the canvas the SVG will be rendered to.
outputWidthThe width of the image the SVG will be rasterized into.
outputHeightThe height of the image the SVG will be rasterized into.
targetDirThe target directory.
baseFilenameThe base file name.
fileExtensionThe file extension (".jpg", ".png").
Returns
True if the images were saved, else false.
95 {
96  for(std::size_t i = 0; i < shapes.size(); i++) {
97  const std::string path{targetDir + "/" + baseFilename + "_" + std::to_string(i) + fileExtension};
98 
99  const std::vector<geometrize::ShapeResult> shapeSubset(shapes.begin(), shapes.begin() + i);
100  if(!exportRasterizedSvg(shapeSubset, inputWidth, inputHeight, outputWidth, outputHeight, path)) {
101  return false;
102  }
103  }
104  return true;
105 }
bool exportRasterizedSvg(const std::vector< geometrize::ShapeResult > &shapes, const std::uint32_t inputWidth, const std::uint32_t inputHeight, const std::uint32_t outputWidth, const std::uint32_t outputHeight, const std::string &filePath)
exportRasterizedSvg Exports the shape data as an image by rasterizing an SVG rendered from the shape ...
Definition: imageexporter.cpp:74

Here is the call graph for this function:

Here is the caller graph for this function:

std::string geometrize::exporter::exportShapeData ( const std::vector< geometrize::ShapeResult > &  data,
ShapeDataFormat  format 
)

exportShapeData Exports shape data to a specified format (JSON or a custom textual array format).

Parameters
dataThe shape data to export.
formatThe format to save to data in.
Returns
A string containing the exported shape data, empty if the format was unrecognized.
18 {
19  switch(format) {
20  case ShapeDataFormat::JSON:
21  return exporter::exportShapeJson(data);
22  case ShapeDataFormat::CUSTOM_ARRAY:
23  return exporter::exportShapeArray(data);
24  }
25 
26  assert(0 && "Unsupported shape data format specified, will default to exporting JSON");
27  return exporter::exportShapeJson(data);
28 }

Here is the caller graph for this function:

std::string geometrize::exporter::exportWebGLWebpage ( const std::vector< geometrize::ShapeResult > &  data)

exportWebGLWebpage Exports shape data to a WebGL-based webpage.

Parameters
dataThe shape data to export.
Returns
A string containing the content of the WebGL-based webpage.
61 {
62  return exportWebpage(":/web_export/templates/web_export_template.html", ":/web_export/templates/backend_threejs.js", data);
63 }

Here is the caller graph for this function:

QImage geometrize::exporter::renderSvgShapeDataToImage ( const std::vector< geometrize::ShapeResult > &  shapes,
const std::uint32_t  inputWidth,
const std::uint32_t  inputHeight,
const std::uint32_t  outputWidth,
const std::uint32_t  outputHeight 
)

renderSvgShapeDataToImage Renders the given shape data to an image via an SVG.

Parameters
shapesThe shape data to render.
inputWidthThe width of the canvas the SVG will be rendered to.
inputHeightThe height of the canvas the SVG will be rendered to.
outputWidthThe width of the image the SVG will be rasterized into.
outputHeightThe height of the image the SVG will be rasterized into.
Returns
The image the shape data was rendered to.
52 {
53  const std::string data{geometrize::exporter::exportSVG(shapes, inputWidth, inputHeight)};
54  const QByteArray arrayData(data.c_str(), static_cast<int>(data.length()));
55  QSvgRenderer renderer;
56  renderer.load(arrayData);
57 
58  if(!renderer.isValid()) {
59  assert(0 && "SVG renderer is in an invalid state");
60  return QImage();
61  }
62 
63  QPainter painter;
64  QImage image(outputWidth, outputHeight, QImage::Format_RGBA8888);
65  image.fill(0);
66 
67  painter.begin(&image);
68  renderer.render(&painter);
69  painter.end();
70 
71  return image;
72 }

Here is the caller graph for this function: