Wednesday, 9 July 2014

How to get IP address in Java using InetAddress

An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. The designers of the Internet Protocol defined an IPv4 address as a 32-bit number.
In this tutorial we are going to see how can you get the IP Address that is assigned to your own machine inside your local network and the IP Addresses assigned to specific Domain Names(e.g. www.google.com…).
To do that we are going to use InetAddress.To be more specific we are going to use:
  • getLocalHost().getHostAddress() method of InetAddress to get the IP Address of our machine in our local network
  • getByName() method of InetAddress to get the IP Address of a specific Domain Name
  • getAllByName() method of InetAddress to get all the IP Address of a specific Domain Name.

Tuesday, 8 July 2014

How to print all the Java system properties

The other day, when I was trying to compile all the Tame Swing examples, I had a problem running one of the examples. The problem was that I was running the example in Eclipse, and I was getting an error message showing the Eclipse (the JVM really) couldn't find the icon image files.

I thought I had everything configured properly, but still I kept getting the same error message. Finally I decided to look at my Java system properties and see what my build path really looked like. I couldn't think of the right Java property to show the build path, so instead of trying to print just the one Java property, I decided to print all the Java properties, then dig through them manually. You print Java system properties with the System.getProperties() method.

Here's the code I used to print all the Java system properties:

Properties p = System.getProperties();
Enumeration keys = p.keys();
while (keys.hasMoreElements()) {
  String key = (String)keys.nextElement();
  String value = (String)p.get(key);
  System.out.println(key + ": " + value);
}
And here's the output from that section of code:
java.runtime.name: Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries
java.vm.version: 1.5.0_07-87
awt.nativeDoubleBuffering: true
gopherProxySet: false
java.vm.vendor: "Apple Computer, Inc."
java.vendor.url: http://apple.com/
path.separator: :
java.vm.name: Java HotSpot(TM) Client VM
file.encoding.pkg: sun.io
user.country: US
sun.os.patch.level: unknown
java.vm.specification.name: Java Virtual Machine Specification
user.dir: /Users/al/DD/Projects/TameSwing
java.runtime.version: 1.5.0_07-164
java.awt.graphicsenv: apple.awt.CGraphicsEnvironment
java.endorsed.dirs: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/endorsed
os.arch: i386
java.io.tmpdir: /tmp
line.separator: 

java.vm.specification.vendor: Sun Microsystems Inc.
os.name: Mac OS X
sun.jnu.encoding: MacRoman
java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
java.specification.name: Java Platform API Specification
java.class.version: 49.0
sun.management.compiler: HotSpot Client Compiler
os.version: 10.4.10
user.home: /Users/al
user.timezone: 
java.awt.printerjob: apple.awt.CPrinterJob
file.encoding: MacRoman
java.specification.version: 1.5
java.class.path: /Users/al/DD/Projects/TameSwing/bin:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/.compatibility/14compatibility.jar
user.name: al
apple.awt.graphics.UseQuartz: true
java.vm.specification.version: 1.0
java.home: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
sun.arch.data.model: 32
user.language: en
java.specification.vendor: Sun Microsystems Inc.
awt.toolkit: apple.awt.CToolkit
java.vm.info: mixed mode, sharing
java.version: 1.5.0_07
java.ext.dirs: /Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/ext
sun.boot.class.path: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/charsets.jar
java.vendor: Apple Computer, Inc.
file.separator: /
java.vendor.url.bug: http://developer.apple.com/java/
sun.io.unicode.encoding: UnicodeLittle
sun.cpu.endian: little
mrj.version: 1040.1.5.0_07-164
sun.awt.exception.handler: apple.awt.CToolkit$EventQueueExceptionHandler
sun.cpu.isalist:

Wednesday, 2 July 2014

JavaFX 2 vs Java3D

Java3D

  • The Java 3D API is a high-level library for creating 3D-graphics including animation and transformation of 3D-objects.
  • The Java 3D API operates with objects that are placed in the scene graph that is the tree of 3D-objects and is intended to render.
  • Java3D application can run as a desktop application or as an applet or as a desktop application and an applet.
  • The Java 3D API is presented by the basic package javax.media.j3d and support packages com.sun.j3d.utils, java.awt, javax.vecmath.
  • In fact, the Java 3D API is a wrapper of the graphic systems OpenGL and DirectX.

Java3D installation

  • Download the distributive at http://www.oracle.com/technetwork/java/javase/tech/index-jsp-138252.html.
  • Run the installation program. The result will appear in the JDK directory as the folder Java3D.
  • The installed files on the Java3D folder work as the runtime over JDK for programs that use the Java 3D API.
  • To develop programs using the Java 3D API download the NetBeans plugin at http://plugins.netbeans.org/plugin/32144/java-3d and install it using the option Tools | Plugins | Downloaded | Add Plugins.
  • You can then include the import of the Java 3D API libraries in a Java application project.

Java3D programming model

  • To create a Java3D application first creates the VirtualUniverse object.
  • Each Java3D application has only one object VirtualUniverse, which represents a virtual space that is associated with a scene graph.
  • Further create the BranchGroup object that represents the root node of the branch of the scene graph.
  • Create the Transform3D object representing the three-dimensional transformations and, based on it, create the TransformGroup object that represents the node of the scene graph.
  • Create a 3D-object, which is added to the node TransformGroup.
  • The TransformGroup node is added to the node BranchGroup and the BranchGroup node is added to the virtual space VirtualUniverse.
  • In the BranchGroup node, besides 3D-objects, you can add light sources illuminating 3D-objects.
  • For 3D-objects it is possible to define the appearance by adding colors, materials, textures and effects.
  • With the Canvas3D object it is possible to create 3D-graphics in the program way.
  • Animations of the 3D-object are controlled by changing the object Transform3D in time.
  • The following code is a simple Java3D-program that displays the rotated cube:

JavaFX 2

  • The JavaFX technology provides a powerful graphical user interface for large-scale data-oriented applications, media-rich applications that deliver diverse media content to users, Mashup applications that integrate a variety of web resources for users, high-quality graphical components and animation to web sites, various types of custom programs that saturated graphics, animation and interactive elements.
  • The same Java code created on the basis of the JavaFX platform can be launched as the desktop application or it can be deployed as the Java Web Start application or it can be displayed in the web browser as the JavaFX applet embedded in an HTML page.
  • The JavaFX 2 Platform provides modern GUI-components, the rich set of graphics and media libraries, and the high-performance execution environment for applications.
  • For an alternative declarative description of the GUI the JavaFX platform offers the FXML language.
  • Also, the JavaFX 2 platform provides the new graphical and media engines, which improve the display of graphics and playback of multimedia content, embedding HTML-content in the application, the new plugin for web browsers, and the wide range of the GUI components with the support of CSS3.
  • Currently JavaFX 2 provides:
  1.  JavaFX SDK that provides the JavaFX Packager tool for compiling, packaging, and deploying JavaFX applications, Ant library for building JavaFX applications, the JavaFX doclet for Javadoc, JavaFX API, and documentation.
  2.   JavaFX Runtime for desktop applications and JavaFX applets.
  3. Support of the JavaFX 2 platform for NetBeans IDE 7.
  4. Examples of JavaFX applications.
  • The JavaFX 2 platform is integrated into the platform JDK 7 and does not require separate installation.
  • The site of the JavaFX 2 platform is located at http://javafx.com/.
  • The JavaFX 2 browser plugin is not browser add-ons and its work is provided by the JavaScript-code that embeds the JavaFX-code as a JavaFX-applet on the web page, connecting the JavaFX Runtime installed on the local computer.

Comparison JavaFX 2 and Java3D

  • Both JavaFX 2 and Java3D include API and runtime.
  • Java3D requires a separate installation. JavaFX 2 is included in JDK 7.
  • Both JavaFX 2 and Java3D can create 3D-graphics.
  • Java3D provides ready 3D-objects. JavaFX 2 allows creating 3D-objects from 2D-primitives.
  • JavaFX 2 provides GUI-components, but Java3D is not.
  • Both JavaFX 2 and Java3D provide transformation and animation facilities.
  • The JavaFX 2 code automatically compiled into the desktop application and the applet. For Java3D-applet creation the additional code is required.
  • Both JavaFX 2 and Java3D operate a scene graph.
  • JavaFX 2 provides a declarative description of the scene graph and the visual editor of the scene graph, but Java3D is not.
  • Java3D supports textures, but JavaFX 2 is not.
  • The JavaFX 2 code should be performed in a separate JavaFX Application Thread. The Java3D code runs in the main thread.
  • The entry point of the JavaFX-application is a Java-class that extends the abstract class javafx.application.Application and contains the method main(). The entry point of Java3D-application is the usual Java-class with the method main().

Sunday, 29 June 2014

dcm4che-tool-dcmvalidate

usage: dcmvalidate --iod <iod-file> [<dicom-file>..][<directory>..]

Utility to validate DICOM objects according a specified Information Object
Definition.
-
Options:
 -h,--help             display this help and exit
    --iod <iod-file>   path to xml file with Information Object Definition
 -V,--version          output version information and exit
Example:
$ dcmvalidate --iod etc/dcmvalidate/dicomdir-iod.xml DICOMDIR
 Validate DICOMDIR against IOD specified in etc/dcmvalidate/dicomdir.xml
 
Download Code : dcm4che-tool-dcmvalidate 
For Your reference : dicomdir-iod.xml

Saturday, 28 June 2014

Speaking of 3D

This is a 3D enhanced moving image and not, it seems, a true 3D plot. How did Petrus Soons and his team do this? Notice that the background behind the head is treated differently than the head. Is there anything else peculiar about this? I call your attention to a previous posting, I certainly have real reservations about Petrus Soons’ 3D work. Any comments now?, Do read the many thoughtful comments that resulted. Click here or on the image, below. 


Monday, 16 June 2014

OTech: How Dirty Is Your DICOM Data?


This looks like a nice image, but the
 metadata could be totally incorrect or corrupted
  • If you would take a snapshot of any DICOM archive and check the image headers for correctness, I would argue that there are quite a few hidden problems that you might not know about.

  • Errors in a DICOM header can cause images to be incorrectly displayed, incorrectly added to the database, or being flatly rejected by the PACS. By DICOM errors, I don’t mean an incorrect Accession Number of patient name, or duplicate ID, but rather a violation of the rules defined in the DICOM standard for a particular field entry.
  • For more details : OTech: How Dirty Is Your DICOM Data?:
  • Following is video for showing how to do..