How to save R plot image to database? - database

I'd like to save a plot image directly to the database.
Is the best way in R to do this:
Write the plot image (png) to the filesystem
Read the file that was written
Send the file to the database via query (RODBC)
Ideally I'd like to combine steps 1 and 2 above by simply write the png image to a binary connection. Does R support this?

No, the graphics devices are file-based, so your steps 1-3 are correct. You need a fourth to unlink the temporary file but that is about it.

If you use either lattice or ggplot, you can save the plot object (rather than the image itself) to the database (although I don't know if that meets your requirement). The benefit of that approach is that you can easily recreate/alter the image.

Instead of writing to a regular file, could you write it to a FIFO that would in turn store it in the DB? Will graphics devices write to a FIFO if it's created externally?

Related

Is there a way to store either animation data or arbitrary data in a Collada file from SceneKit?

I'm building a tool to convert an old proprietary mesh+animations file format into Collada DAE files, and so I have been using SceneKit to cheat a bit and just build the geometry and run [scene writeToUrl].
I am able to build correct CABasicAnimations for all the model animations, which are basically sets of morph targets (no bone definitions exist in the original file - only mesh morph targets).
Is there a way to include SceneKit-generated CAAnimationGroup or animations in the file export? Relatedly, is there a way to write and read arbitrary information to and from the export? If I can write and read the total animation duration and the FPS rate then I can reproduce the animations on the game engine side.
All animations should be exported automatically. You can verify that they are correctly exported by opening the Collada file as a xml file. If they are not exporte correctly, then it's a good idea to file a bug.
As for arbitrary data you can maybe use tricks such as using node names to store that information.

3D Line Graph manipulation

I am writing software for a device that would plot a 3D graph/line plot of where someone has traveled. This plotting will be during post-processing of the data, so real time is not a requirement.
My key problem is, I can't find suitable tools or even other CAD software (eg. Autocad) which will plot a line graph (I imagine it would plot it as a 'path'?) from a data file (eg. CSV) which I can then manipulate like a CAD model (ie. move it around, rotate it to view from different angles, etc).
There is a real-time aspect to it where my computer will connect to the device at regular intervals, pull current location data, and store it. The computer will run and communicate through a Windows Forms app but only at the end do I need to plot the graph.
Would you have any suggestions on how to go about this?
Thanks in advance
So much easier than I though it would be.
Basically, generate a new file named points.scr (this is an AutoCAD script file), that contains the following:
._LINE
0,0,0
1,2,4
2,2,4
C
Run this is AutoCAD by typing "scr" into the command prompt and selecting the points.scr file.
http://forums.autodesk.com/t5/AutoCAD-2004-2005-2006/script-to-draw-line/td-p/1219015

Using video/image files in C

I'm trying to look through and find a way to annotate a video in C with polygons bounding boxes, however I'm stuck at a very elementary step.
Assuming I know how to break a .MPEG movie up into multiple JPEG images, how do I manipulate that file in C? The things I'll eventually need to draw on are text, points, and lines, but I am having a hard time figuring out how to get started with this.
If I declare:
FILE* img = fopen('foo.jpeg', 'r');
then what could I do with img? Is there a way to access certain pixels in the drawing?
What you did in your code sample is just opening a file. You didn't even read any data from it yet.
The simplest way to load an image file is to use dedicated library, such as SOIL.
If you weren't able to do it by yourself, however, I really don't think you will be able to accomplish your project goals - it is really advanced stuff you want to create, and you failed, as you already noticed, on the most basic of steps.

Getting JPEG Redundant Data

I am doing some project related to image compression and I need a way to save the data lost in JPEG compression (like bits per pixel..). I guess I would need to build a custom libjpeg for that. Appreciate any suggestions/help on the subject (maybe even guidance to what part to modify in the source code).
Thanks in advance!
Edit: To clarify myself, I am not looking into embedding hidden information. I am looking for a method to get the data lost during JPEG compression. I am also OK with getting the data lost from re-compressing a JPEG image (from 90 to 80).
If you are in need to embed private data into JPEG bitstream, you might want to take advantage of APPn markers. There are few great things about them:
the image will still be readable and compatible with software out there
the format is simple enough so that you can leave libjpeg or your another favorite JPEG library intact, and add/read the data modifying the bitstream directly
JPEG File Interchange Format is using APP0 and APP1, you can read the details and there are still more available markers like APP2 which you can use for your purposes.
There's at least four steps where you can lose information in jpeg compression. I don't really know what you're getting at. If you want to measure the lost information, you can just compress/decompress and compare with the original.
I guess you want to encode RGB to standard JFIF, then you lose information in the color conversion, subsampling, after that you have to do FDCT and I don't think that is exactly reversible so you lose information in that step and then you have the quantization step. Unless you have quantization tables containing all ones you will lose information there also.
To sum it up:
Color conversion
Subsamling
FDCT/IDCT
Quantization

Java Project Modules - use InputStream/OutputStream or .tmpFile/byte[]

I found myself passing InputStream/OutputStream objects around my application modules.
I'm wondering if it's better to - save the content to disk and pass something like a Resource between the various methods calls - use a byte[] array instead of having to deal with streams everytime.
What's your approach in these situations?Thanks
Edit:
I've a Controller that receives a file uploaded by the user. I've an utility module that provides some functionality to render a file.
utilityMethod(InputStream is, OutputStream os)
The file in InputStream is the one uploaded by the user. os is the stream associated with the response. I'm wondering if it's better to have the utility method to save the generated file in a .tmp file and return the file path, or a byte[], etc. and have the controller to deal with the outputStream directly.
I try to keep as much in RAM as possible (mostly because of performance reasons and RAM is cheap). So I'm using a FileBackedBuffer to "save" data of unknown size. It has a limit. When less than limit bytes are written to it, it will keep them in an internal buffer. If more data is written, I'll create the actual file. This class has methods to get an InputStream and an OutputStream from it, so the using code isn't bothered with the petty details.
The answer actually depends on the context of the problem, which we dont know.
So, imagining the most generic case, I would create two abstractions. The first abstraction would take InputStream/OutputStream as parameters, whereas the other would take byte[].
The one that takes streams can read and pass the data to the byte[] implementation. So now your users can use both the stream abstraction and byte[] abstraction based on thier needs/comfort.

Resources