How to use DCMTK library with javascript - javascript

After working with dcmtk in C++, I'd like to use it in javascript but I think it's not as easy as it is with C++.
is there any way to do that ?
thank you in advance.

I agree to John, I would rather advise to seek for a JavaScript DICOM toolkit instead of establishing an interface between DCMTK and JavaScript.
To answer your question, however:
First, make a basic decision if you want to use the toolkit's executables through kind of a scripting layer that is invoked through JS functions or to write C++ - CGI funtions based on the DCMTK libraries. I think it is obvious that the latter approach gives you far more flexibility in designing the DICOM functionality. In the following, I am going to mention executables which can accomplish particular tasks. In case you want to go the CGI way, the source code of the executable is a good starting point to learn how to use the library.
To read the DICOM header information, have a look at dcmdump. It can convert the binary DICOM header format into a text file which can be easily parsed with non-DICOM-aware JS functions.
To create binary DICOM objects, use the complementary tool dump2dcm, which converts a text file in the format that dcmdump creates back to a binary DICOM file.
To render images to a "web image format" (i.e. PNG or JPEG), you can use dcmj2pnm. It takes a DICOM image and renders it with some simple rendering functions (scale, rotate, windowing).
All of these tools provide a lot of options through the command-line interface to control the output.
There are more tools around which may be helpful but without knowing more about the use cases you want to support this is the information I can provide. Please note again, that I explicitly do not want to advise you to use these approaches, as they are very limited in terms of performance optimization and error handling.

Related

Processing SVG in Python

I am trying to use python and understand SVG drawings. I would like python to behave similar to java script and get information from SVG. I understand that there can be 2 types of information in SVG.
XML based information - such as elementbyID, elementbyTagNames
Structural information - positional information taking transformations in to consideration too - such as getelementfrompoint, getboundingbox
I have searched around and found python libraries such as lxml for xml processing in svg. Also I found libraries such as svgpathtools, svg.path , but as I understand, these deal only with svgpath elements.
So my question is,
Are there any good libraries which support processing svg in python?(similar to java script)
I don't think this is feasible. I was directing you to an answer about rendering SVG with Python - but after that all you have got is pixels.
Extracting positional information from SVG data at arbitrary points between transformations is likely something only implemented in browsers themselves. You will likely have two options: use a headless browser and selenium/splinter to load your SVG data in a real browser and run javascript statements in there, OR make your Python code run in Brython, and run everything inside the browser. From Brython you should be able to use the Javascript calls as methods of the SVG object as it is exposed to Brython itself.
Try to use Pygal. It's used for creating interactive .svg pictures.
Thank you for all the answers and help.
After reading all comments and even more www search, I agree with the idea that there is much more support in Java script supported web browsers for dealing with SVG. So I decided to use JS and to use python only when there is no choice. I will however use python libraries such as(https://pypi.python.org/pypi/svgpathtools/1.0.1) I think. But as of now I handed over all the SVG feature finding to java script
Start your search by visiting www.pypi.org and search for "svg". Review what exists and see what suits your needs.

On-Disk Text Processing With Javascript

I have some html files that I need to do automated processing on, basically regex replaces, but also some more complex actions like copying select blocks of text from one file to another.
I want to create a series of scripts that will let me do this processing (it will need to be done more than once on different batches of files). It would be trivial to use Go for this (read the file into memory, regex, save to disk) but I am the only member of the project that's familiar with Go.
Javascript is a tad more ubiquitous, and I do have project members who are familiar with the language, so it's a better fit in that respect. If I'm not around later, someone else could edit the scripts.
Is there a simple way to write some JS scripts to do on-disk text processing? I'm looking for a cross-platform solution (OSX, Windows). Ideally, once the scripts are written, they can be executed by double-clicking an icon--there will be "not computer people" involved at some point.
Also, I'd like to be able to do some kind of alert/message box to inform the user of the success/failure of the script. (This may be a tall order, and is of secondary importance.)
What I've looked at:
Node.js was the first thing that popped into my head, because I know that it has file system access tools, and obviously regex capacity. But I've never used Node before, and based on the tutorials I've read, it seems like overkill for something this simple.
There's a whole slew of "javascript compiling" tools that you can find by googling around. Some are not cross-platform, some seem old or not actively maintained, etc. None of them caught my eye as easy to pick up and just write some JS scripts with.
Any thoughts?
Node.js is a simple solution and with it's framework you can create or later modify your script to your needs. This way you will not be locked down by someone else's code. And it is not that difficult to to use.
Here is a quick tutorial on accesing files using node.js
http://www.sitepoint.com/accessing-the-file-system-in-node-js/
And here is a quick tutorial on using a node module called Cheerio. It allow you to access html files using "jquery like syntax". You don't need to use regex.
http://maxogden.com/scraping-with-node.html
I worked on a project for a client once and it required parsing thru hundreds of html files to check and replace certain image files based on certain criterias. I wasn't familiar with node at the time so I read some tutorials and wrote the script in about an hour.
And as long as Nodejs' path is set, you can run it on the command line.
Some tips:
You need any kind of DOM HTML parser, not only JS nor specifically JS.
You can do that thing with Java with use of jTidy or jSoup libraries (I've used second one few times). It's pretty simple language to learn if you know JS and IDE like Netbeans helps a lot. So can be made quickly with that.
You can use PhantomJS to create some job files and create shell/batch code to run them on some files. You might need to write a generator for job files (like taking a list of files, creating job files for each and running them).
You can use Node.js which isn't much overkill, I'm sure any solution won't be trivial.
You can create an ETL for processing with for example Pentaho ETL (which has JS embedded as one of two scripting languages... but without DOM parser - for that one you would need to use a bit of Java there and some library in way similar to this article).
You can also do that with PHP with Simple HTML DOM Parser - so you can make a service online (or on local server) that takes those html files and throws out processed ones.
First I think you underestimate the complexity. The statement
"It would be trivial to use Go for this (read the file into memory,
regex, save to disk) but I am the only member of the project that's
familiar with Go."
is probably false. Parsing HTML with RegExp is just a bad idea. (Google it and you will see why)
Second, if you can trivially write the code using RegExps in Go, you can just as easily write the same thing in Javascript. They both support RegExp and file operations. If you are unsure about the Javascript/Node.js details, I suggest writing the trivial solution in Go and then translate the thing into Javascript with a colleague.
Since Javascript is a script language, writing command line utilities in Node.js is straight forward.
Some pointers to get you started
RegExp in Javascript
Building command line apps in Node.js

Javascript C++ binding?

I have some C++ code that I want to expose to client side of a web app. Ideally, I want to write Javascript wrapper objects for my C++ classes so that I can use them clientside.
Has this been done before?. Does anyone have a link to show how this may be achieved?
There is a library to convert C++ code to javascript, it might help:
emscripten
Libjspp C++ template based wrapper for embedding and extending Javascript engine spidermonkey 1 . 8 . 5 and more
SpiderMonkey? is Mozilla Project's Javascript/ECMAScript engine.
Libjspp allows C++ developers to embed SpiderMonkey? simply and easily into their applications. Libjspp allows to run multiple Javascript Engines within same process which suits one engine per thread para dime which is helpful in achieving true parallisim. Also Libjspp no way stops user from running multiple threads within engine.
http://code.google.com/p/libjspp/
I guess that RPC is what you want. You'll need to wrap your functions on the server side using some sort of framework. I've not yet used it, but this one looks promising.
On the client side you use proxy objects to dispatch the function calls. The communication is handled usually either via XML-RPC or JSON-RPC. I used this client side framework and was quite content but I'm sure you'll find many others.
This is an old topi, however, I was in the exact situation right now, and all of the solutions I found on the net complicated or outdated.
Recently, I ran across a library which supports V8 engine (including the new isolation API, which makes 90% of the libraries I found outdated) and provides great exposure and interaction API.
https://github.com/QuartzTechnologies/v8bridge
I hope that my solution will help anybody.
There's a relatively new library for doing this called nbind. Maybe that would suit you? It looks very good to me, and I'm just about to start using it.
I think you want a C++ JSON parser. You should be able to find one here http://www.json.org/. It may not do all you want because it just serializes and deserializes C++ objects without any behavior, but it should be good enough. See https://stackoverflow.com/questions/245973/whats-the-best-c-json-parser for some discussion.
If the C++ code has to be on the client, then there is no simple way to do this for a web app. A solution may involve coding plugins for the browsers you want to support, which may then be accessed from javascript code.
If, for example, you need this for a client application, that is another case. Such a thing has been done and involves linking your application to (or running from outside) with for example chromium library, or any other javascript execution engine. That way you can create bindings to C++ classes and use such objects from javascript and vice-versa. Note that this is also not a trivial solution and may be a big effort to implement (also requires additional resources).
You could for example wrap the C++ classes in PHP or Python, and then implement an API over HTTP to access the required functions.
Or if you insist on exposing the functions as JavaScript you could try using Node.js, and create an C++ add-on to wrap you classes. See the Node.js documentation here: http://nodejs.org/api/addons.html#addons_wrapping_c_objects
But either way, I don't think avoid creating some sort of API (HTTP SOAP, XML RPC) to access the functions on your server.
Though QML is not exactly Javascript, Qt is not plain C++, but what they do together seem just like what you need

How to use JavaScript to stream parts of a file?

Given a really large, 3+ gig, binary file is there anyway that I could stream, from client to server, only portions of the file using JavaScript given that I know what byte range of the file that I want to receive?
I have a Ruby on Rails application that needs to grab specific portions of a file from the client. As one user has stated I could do this using Java.
Edit: After some reading it appears that HTML5 via slicing a file may be the best bet. http://www.html5rocks.com/en/tutorials/file/dndfiles/
The basic answer is yes, assuming your web server supports it (which many do).
You can use the Range HTTP header to request only a part of the file (e.g. Range: bytes=1000-2000). Whether this works for you depends heavily on what you’re trying to accomplish — more information would help.
See this answer for a discussion on using it.
No, not really (at least not now, anyways). The file handling capabilities exposed to Javascript is not powerful enough to really do anything useful client-side when processing files to send back to the server (including things like only take part of a file). There are proposed w3c specs for better client-side file handling for javascript, but none of the major browsers implement it to a sufficient level to really handle this case quite yet.
I'm currently working on a project with similar needs, and the only options we found when we looked into this was to either use Flash, or to use Java. Since we are much more comfortable with Java than flash, we went that route.
We are currently using Groovy and the Griffon framework, as well as Grails for the server-side pieces. Griffon has been great because it frees us from the hassles of desktop vs. webstart vs. applet, and since it's built on Groovy, it can leverage the Swing DSLs so it is much less painless to write Swing.

Best way to design cross-platform multi-content-type file format?

I need to redesign a file format for a set of applications ( desktop/online/mobile.. ) which is to contain a set of non-linear data and multiple images.
I do not want to make it one large XML with embedded images as:
first of all it could grow to a size that would be for example slow to parse using javascript
second of all I want it to be editable 'by hand'.
The compression is not necessary. I just want to distribute this as a single files. I would like my solution to be as cross-platform as possible.
What I made up recently is a *.tar.gz archive with xmls and images inside.
The desktop (C++ / Qt) version of my application is reading the file using zlib (which was hard to code but works).
The online version is using PHP (execing tar) to uncompress the file (caches contents in database) and passes xmls and images to javascript via ajax.
When I came to develop an android version I'm kinda stuck and I don't know how to read it here.
I was wondering if there is a better / simpler solution to achieve this?
Solutions I found are for example:
Blender .blend files http://en.wikipedia.org/wiki/Blender_%28software%29#File_format But this is not readable without any special tool.
OpenOffice files which are in fact zips.
But I guess there is no big difference using this or tar.gz. It still would be a problem to read it on a mobile platform or with javascript.
Probably there is no 'best way' to do this but i hope there are some widely used solutions?
I will appreciate any thoughts on this.
I'm not sure if this will meet your "editable by hand" criteria, but to make a single-file, cross-platform binary format, Google Protocol Buffers are very useful and efficient, and work across major platforms and languages.
If "editable by hand" is critical, with a little extra work, you can write simple utilities using your own message libraries to support creating/updating/deleting portions of existing files (e.g. extract out images for editing, and support replacing them.)
If it must be editable in JavaScript, perhaps JSON might be a good option? You can insert pictures/video/other files by using base64 data url encoding, which is supported in Javascript and many other languages.

Categories

Resources