JavaCPP Presets for Spinnaker
=============================
[![Gitter](https://badges.gitter.im/bytedeco/javacpp.svg)](https://gitter.im/bytedeco/javacpp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/spinnaker/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/spinnaker) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.bytedeco/spinnaker.svg)](http://bytedeco.org/builds/)
<sup>Build status for all platforms:</sup> [![spinnaker](https://github.com/bytedeco/javacpp-presets/workflows/spinnaker/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Aspinnaker) <sup>Commercial support:</sup> [![xscode](https://img.shields.io/badge/Available%20on-xs%3Acode-blue?style=?style=plastic&logo=appveyor&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAlUlEQVR42uzXSwqAMAwE0Mn9L+3Ggtgkk35QwcnSJo9S+yGwM9DCooCbgn4YrJ4CIPUcQF7/XSBbx2TEz4sAZ2q1RAECBAiYBlCtvwN+KiYAlG7UDGj59MViT9hOwEqAhYCtAsUZvL6I6W8c2wcbd+LIWSCHSTeSAAECngN4xxIDSK9f4B9t377Wd7H5Nt7/Xz8eAgwAvesLRjYYPuUAAAAASUVORK5CYII=)](https://xscode.com/bytedeco/javacpp-presets)
Introduction
------------
This directory contains the JavaCPP Presets module for:
* Spinnaker 3.0.0.118 https://www.flir.com/products/spinnaker-sdk
Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.
The [Spinnaker SDK](https://www.flir.com/products/spinnaker-sdk) is FLIR's next generation GenICam3 API library built for machine vision developers. It is compatible with Oryx, Blackfly S, and all USB3 Vision camera models.
Documentation
-------------
Java API documentation is available here:
* http://bytedeco.org/javacpp-presets/spinnaker/apidocs/
Sample Usage
------------
Here is a simple example of Spinnaker C API code ported to Java from the `Acquisition_C.cpp` example distributed with Spinnaker SDK.
We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `Acquisition_C.java` source files below, simply execute on the command line:
```bash
$ mvn compile exec:java
```
### The `pom.xml` build file
```xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.spinnaker</groupId>
<artifactId>acquisition_c</artifactId>
<version>1.5.9</version>
<properties>
<exec.mainClass>Acquisition_C</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>spinnaker-platform</artifactId>
<version>3.0.0.118-1.5.9</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>.</sourceDirectory>
</build>
</project>
```
### The `Acquisition_C.java` source file
```java
//=============================================================================
// Copyright © 2018 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR).
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================*/
import java.io.File;
import org.bytedeco.javacpp.*;
import org.bytedeco.spinnaker.Spinnaker_C.*;
import static org.bytedeco.spinnaker.global.Spinnaker_C.*;
/**
* Example how to enumerate cameras, start acquisition, and grab images.
* <p>
* Please see Enumeration_C example for more in-depth comments on preparing and cleaning up the system.
*/
public class Acquisition_C {
private final static int MAX_BUFF_LEN = 256;
private static String findErrorNameByValue(int value) {
for (spinError v : spinError.values()) {
if (v.value == value) {
return v.name();
}
}
return "???";
}
private static String findImageStatusNameByValue(int value) {
for (spinImageStatus v : spinImageStatus.values()) {
if (v.value == value) {
return v.name();
}
}
return "???";
}
/**
* Check if 'err' is 'SPINNAKER_ERR_SUCCESS'.
* If it is do nothing otherwise print error description and exit.
*
* @param err error value.
* @param message additional message to print.
*/
private static void exitOnError(spinError err, String message) {
if (printOnError(err, message)) {
System.out.println("Aborting.");
System.exit(err.value);
}
}
/**
* Check if 'err' is 'SPINNAKER_ERR_SUCCESS'.
* If it is do nothing otherwise print error information.
*
* @param err error value.
* @param message additional message to print.
* @return 'false' if err is not SPINNAKER_ERR_SUCCESS, or 'true' for any other 'err' value.
*/
private static boolean printOnError(spinError err, String message) {
if (err.value != spinError.SPINNAKER_ERR_SUCCESS.value) {
System.out.println(message);
System.out.println("Error " + err.value + " " + findErrorNameByValue(err.value) + "\n");
return true;
} else {
return false;
}
}
/**
* This function helps to check if a node is available and readable
*/
private static boolean isAvailableAndReadable(spinNodeHandle hNode, String nodeName) {
BytePointer pbAvailable = new BytePointer(1);
spinError err;
err = spinNodeIsAvailable(hNode, pbAvailable);
printOnError(err, "Unable to retrieve node availability (" + nodeName + " node)");
BytePointer pbReadable = new BytePointer(1);
err = spinNodeIsReadable(hNode, pbReadable);
printOnError(err, "Unable to retrieve node readability (" + nodeName + " node)");
return pbReadable.getBool() && pbAvailable.getBool();
}
/**
* This function helps to check if a node is available and writable
*/
private static boolean isAvailableAndWritable(spinNodeHandle hNode, String nodeName) {
BytePointer pbAvailable = new BytePointer(1);
spinError err;
err = spinNodeIsAvailable(hNode, pbAvailable);
printOnError(err, "Unable to retrieve node availability (" + nodeName + " node).");
BytePointer pbWritable = new BytePointer(1);
err = spinNodeIsWritable(hNode, pbWritable);
printOnError(err, "Unable to retrieve node writability (" + nodeName + " node).");
return pbWritable.getBool() && pbAvailable.getBool();
}
/**
* This function handles the error prints when a node or entry is unavailable or
* not readable/writable on the connected camera
*/
private static void printRetrieveNodeFailure(String node, String name) {
System.out.println("Unable to get " + node + " (" + name + " " + node + " retrieval failed).\n");
}
/**
* This function prints the device information of the camera from the transport
* layer; please see NodeMapInfo_C example for more in-depth comments on
* printing device information from the nodemap.
*/
private static spinError printDeviceInfo(