Converting webGL html to SVG - r

I am using R, with the misc3d and rpanel libraries, to create a 3d image in webGL. I then need to embed the image into a PDF via Latex.
The 3d image renders fine and looks great - but I'm thinking I need to convert the webGL HTML file into an SVG or some other kind of vector graphics file which can be embedded in Latex.
Any suggestions on how to accomplish this?

Maybe I am wrong but this way doesn't make sense to me.
You have 3D coordinates
You render objects based on 3D coordinates to a 2D rasterized image using webGL
Then you want to extract 2D vector coordinates from the rendered image?
From the webGL framebuffer you can get the rasterized data (no vector information). So it is like converting a rasterized image (like png) to SVG. Since there is no way (I know) to get the vector information back from a rasterized image chances are high that the image will just be embedded in the SVG file. This wouldn't be a real benefit compared to a rasterized image.
Maybe you can use the vector informations (which you are using for drawing the webGL image) for drawing to a SVG image directly?

Is there a reason you can't use the rgl package instead (I'm not really familiar with rpanel, but I'm pretty sure that misc3d was originally design to work in conjunction with rgl) and use rgl.postscript(...,fmt="pdf") to export directly to PDF? rgl.postscript also offers an SVG option. The results are admittedly a little wonky sometimes (the underlying package it uses isn't completely reliable), but it's definitely the past of least resistance.
Also, I haven't tried it out myself, but I think the following article gives some information about embedding rgl images in their full, rotatable glory into PDFs: Levine, Richard A., Luke Tierney, Hadley Wickham, Eric Sampson, Dianne Cook, and David A. van Dyk. 2010. “Editorial: Publishing Animations, 3D Visualizations, and Movies in JCGS.” Journal of Computational and Graphical Statistics 19 (1) (January): 1–2. doi:10.1198/jcgs.2010.191ed. http://amstat.tandfonline.com/doi/abs/10.1198/jcgs.2010.191ed.

Related

How reduce the noise of a image?

I am loading text from some images. With some of them, I am having problems, with this type of image
library(magick)
library(tesseract)
image_read(fichero.jpg) %>%
tesseract::ocr(engine = tesseract("eng")) %>%
cat()
Result
I am assuming (correct me if not) that tesseract fail because of the low quality of the image (it is a scanned document), and I don´t know if there is a way to make the image better.
I tried also some convultion methods with several kernels, trying to reduce the noise of the photo, but it was worse.
Is there a way to handle this or I have to assume that is not possible to get the text in this quality-images?
Regards
Looking at this with the experience of a photographer rather than as a programmer, I would guess that the poor focus and camera jiggle make this image pretty well unreadable by most OCR options. I just used the OCR in Adobe Acrobat to play with it on my own PC and I could get "FECHA" to recognize, but not "NUMERO" and not any of the numbers.
I pulled it into a photo editor and messed around with the contrast, as sometimes it's possible to convert a grayscale image such as this to pure black-and-white and get rid of some of the fuzziness, but I couldn't produce a readable image in my quick-and-dirty experiment.
So realistically, you'll need images that are scanned/photographed with higher resolution and better contrast to get reliable OCR.
It looks like you are trying to create a cow from ground beef. The big problem is that JPEG is not suited for this type of non-photographic image. Your png looks fine because it is a lossless format.
If you don't want this problem, do not save the files as JPEG.

Successive pictures on R

I have a code to plot a world map with a meteorological field for one moment (or one measure).
Is it possible to successively plot the map for different moments (for i from 1 to 125) in order to view a sort of video when we run the code?
Yes, look at the animation package.
It can creates an animated gif for you (as well as other tricks). There are live examples you can look at as eg Buffon's needle, a CLT demo and much more.
The package abstracts away some of the OS-dependent layers. If you know the basics, you can of course just call the corresponding tool from the imagemagick project which is likely to be available on OS of choice too.

rgl plot: point size does not change when saving as postscript

I'm trying to generate a 3d scatterplot using rgl. It looks great on my screen, but whenever I export it as a PDF (or any other postscript format) it completely ignores any size specifications I use.
(I'm running RGui v.2.15.1 and rgl v.0.92.892 on a Macbook under Mountain Lion.)
For example:
library(rgl)
set.seed(1982)
points3d(runif(5),runif(5),runif(5), size=20)
# points look huge
rgl.postscript('testplot.pdf', fmt='pdf')
# points look tiny
Does anyone have an idea for a way to get this to work? The resolution of the images I get using rgl.snapshot don't look so good, and I would really like to get a vector image for this plot.
Also, I followed this thread and I got text to resize just fine, but not points. So I thought one way to work around this would be to plot my points as text using a circle as my character, but I couldn't get rgl to accept symbols or expressions either...
Confirmed on Windows, look like some paper size scaling problem. You might try
spheres3d(runif(5),runif(5),runif(5),radius=0.1)
as a workaround if you can live with real 3d.

Qt and exporting vector images

I am using QPainter to draw some graphs on the screen and save these graphs as a raster images.
Is it possible to use the same logic I used for rasterizing these graphs to have them exported to vector images that I can use in a PDF?
You can use a QSvgGenerator as a "backend" to your QPainter, and you'll get an SVG document out of it. (The documentation has an example for how to do that.)
I don't know if you can use that directly in PDFs, but there are converters out there if you need a different vector graphics format.

Combining 3D/2D plots

I'm trying to make a visualization that looks like this http://www.gradient-da.com/img/temperature%20surface%20plot%20470x406.JPG http://www.gradient-da.com/img/temperature%20surface%20plot%20470x406.JPG.
The idea is to have a 3D surface plot overlapping a 2d representation of a surface.
I can build arbitrary surfaces/polygon shapes (as in http://addictedtor.free.fr/graphiques/graphcode.php?graph=135 ) and I can make the respective 2D plot. What I don't seem to be able to figure out is the way to put them together in a nice way (like the one shown in the jpg above).
I've tried googling for the answer, but I wasn't able to find anything similar done in R.
Any help would be greatly appreciated!
EDIT: The 2D portion is not a projection of the 2D one. I chose this specific picture to illustrate this. For example
Here the 2D portion is the image of the circuit and on the 3D portion is the temperature).
In 2D you can have the map of a city and in 3D the traffic
etc...
Best,
Bruno
I will give a theoretical Idea,
In the same 3D plot, select a plane perpendicular to the 3D surface (just below the 3D-surface) and project all the values to it. Instead of 2D & 3D plot, you will use only a 3D plot, which also plots your surface.
HTH
It looks like the 2D plot is a layout of a microelectronic circuit, albeit with some detail skipped, and the 3D plot is perhaps a thermal plot of the same circuit.
I don't know enough about R's capabilities, but I imagine it would be easier to generate the two plots separately with R from the same dataset which represents the layout information (but with and without the thermal data) and then combine them with a graphics manipulation program.
No help in R, but you can do something similar in ROOT as seen in this image:
taken from the THistPainter class documentation.
The code is open source and could be examined if wanted for reimplementation.
Maybe you should try to make an opengl texture out of your 2d picture and map it on a 3d polygon to be included in your scenegraph?
Don't really understand if you wish to do it with R specifically, so maybe diving in opengl is a too low level for you. In case you'd be ready for that, you may reuse a simple java library that simplify plotting 3d surface: http://code.google.com/p/jzy3d
Hope that helps,
Martin
What you're looking for is called a texture map -- and if it's not provided in the R graphics package, you may be able to do it "by hand". The suggestion below may not be fast or convenient (or even helpful, as I'm not really familiar with R), but it may actually work...
Since you know you can draw a 3D surface plot with specified colors, you can try drawing a flat 3D surface using the colors of your image.
If R also lacks methods for extracting its data from image formats, there is an image format called PPM (standing for Portable PixMap), one variant of which is basically space-separated decimal numbers. After converting your image to this format (using Photoshop, say, or some dedicated image conversion program), it should be relatively easy to input into R.

Resources