The first thing you should do is create a maven project with the standard directory structure, and a pom.xml. I used maven in 5 minutes to accomplish that. Once you know the structure though, it appears you can just create the files/folders manually.
I was attempting to get ClearVolume to build using this reference which had some trouble, but anyway. The important thing are the two external repositories that we have to add, and requiring the artifacts.
In this pom I add the repositories in the repositories section. And then the dependencies to the dependencies section, of course. This pom goes an step further and creates an uber jar of all the libs via the shade plugin. If I wanted to create an executable jar I include the following:
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.orangepalantir</groupId> <artifactId>ClearVolumeLib</artifactId> <version>0.1</version> <repositories> <repository> <id>net.clearvolume</id> <url>http://dl.bintray.com/clearvolume/ClearVolume</url> </repository> <repository> <id>net.coremem</id> <url>http://dl.bintray.com/rtlib/CoreMem</url> </repository> </repositories> <dependencies> <dependency> <groupId>net.clearvolume</groupId> <artifactId>clearvolume</artifactId> <version>[1.1,)</version> <scope>compile</scope> </dependency> <dependency> <groupId>net.coremem</groupId> <artifactId>coremem</artifactId> <version>[0.1,)</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
If I wanted an executable jar then I would add the following to the execution tag.
<configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>org.orangepalantir.cv.App</mainClass> </transformer> </transformers> </configuration>
I based this pom information on the official reference. The jar is build by running,
mvn package
The App.java was created when I generated the project, and I filled in the code.
package org.orangepalantir.cv; import clearvolume.renderer.ClearVolumeRendererInterface; import clearvolume.renderer.factory.ClearVolumeRendererFactory; import clearvolume.transferf.TransferFunctions; import coremem.types.NativeTypeEnum; import java.nio.ByteBuffer; /** * Hello world! * */ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); // obtain the best renderer, this usually means picking the best supported GPU programming framwork such as CUDA or OpenCL or GLSL on the most performant GPU installed. final ClearVolumeRendererInterface lClearVolumeRenderer = ClearVolumeRendererFactory.newBestRenderer( "ClearVolumeTest",768,768, NativeTypeEnum.UnsignedShort,768,768,2, false ); // Different transfer functions can be used: lClearVolumeRenderer.setTransferFunction(TransferFunctions.getGrayLevel()); lClearVolumeRenderer.setVisible(true); // volume dimensions: final int lResolutionX = 256; final int lResolutionY = 256; final int lResolutionZ = 256; // size of the buffer in bytes (16bit data) final int lLengthInBytes = lResolutionX * lResolutionY* lResolutionZ* 2; // standard java byte array for holding the data: final byte[] lVolumeDataArray = new byte[lLengthInBytes]; // Filling the buffer with some dummy yet interesting looking data: for (int z = 0; z < lResolutionZ; z++) for (int y = 0; y < lResolutionY; y++) for (int x = 0; x < lResolutionX; x++) { final int lIndex = 2 * (x + lResolutionX * y + lResolutionX * lResolutionY * z); lVolumeDataArray[lIndex + 1] = (byte) (((byte) x ^ (byte) y ^ (byte) z)); } // sets the current buffer to be displayed: lClearVolumeRenderer.setVolumeDataBuffer( 0, ByteBuffer.wrap(lVolumeDataArray), lResolutionX, lResolutionY, lResolutionZ ); // Waits for the renderer's window to be closed: while (lClearVolumeRenderer.isShowing()) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); System.exit(-1); } } // closes the renderer and release all resources: lClearVolumeRenderer.close(); } }
Another way to run the program is to use:
mvn exec:java -Dexec.mainClass="org.orangepalantir.cv.App"
Based on info found here.