org.scijava.convert.ConvertService Java Examples

The following examples show how to use org.scijava.convert.ConvertService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StringToDatasetConverterTest.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testFileToDatasetConverter() {
	final ConvertService convertService = c.service(ConvertService.class);
	String imagePath = "image&pixelType=uint8&axes=X,Y,Z&lengths=256,128,32.fake";
	
	Converter<?, ?> handler = convertService.getHandler(imagePath, Dataset.class);
	// Make sure we got the right converter back
	assertSame(StringToDatasetConverter.class, handler.getClass());
	
	// Test handler capabilities
	assertTrue(handler.canConvert(imagePath, Dataset.class));
	assertFalse(handler.canConvert(null, Dataset.class));

	// Make sure we can convert with ConvertService
	assertTrue(convertService.supports(imagePath, Dataset.class));

	// Convert and check dimensions
	Dataset dataset = convertService.convert(imagePath, Dataset.class);
	assertEquals(256, dataset.dimension(0));
	assertEquals(128, dataset.dimension(1));
	assertEquals(32, dataset.dimension(2));
}
 
Example #2
Source File: FileToDatasetConverterTest.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testFileToDatasetConverter() {
	final ConvertService convertService = c.service(ConvertService.class);
	File imageFile = new File("image&pixelType=uint8&axes=X,Y,Z&lengths=256,128,32.fake");
	
	Converter<?, ?> handler = convertService.getHandler(imageFile, Dataset.class);
	// Make sure we got the right converter back
	assertSame(FileToDatasetConverter.class, handler.getClass());
	
	// Test handler capabilities
	assertTrue(handler.canConvert(imageFile, Dataset.class));
	assertFalse(handler.canConvert(null, Dataset.class));

	// Make sure we can convert with ConvertService
	assertTrue(convertService.supports(imageFile, Dataset.class));

	// Convert and check dimensions
	Dataset dataset = convertService.convert(imageFile, Dataset.class);
	assertEquals(256, dataset.dimension(0));
	assertEquals(128, dataset.dimension(1));
	assertEquals(32, dataset.dimension(2));
}
 
Example #3
Source File: OpSearchResult.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public OpSearchResult(final Context context, final OpInfo info,
	final String baseDir)
{
	cacheService = context.getService(CacheService.class);
	convertService = context.getService(ConvertService.class);
	this.info = info;

	final Object shortSigKey = new ShortSigKey(info);
	final Object shortSigValue = cacheService.get(shortSigKey);
	if (shortSigValue == null) {
		shortSig = buildShortSig();
		cacheService.put(shortSigKey, shortSig);
	}
	else shortSig = (String) shortSigValue;

	props = new LinkedHashMap<>();

	props.put("Signature", info.toString());

	final String opType = info.getType().getName();
	props.put("Op type", opType.startsWith("net.imagej.ops.Ops$") ? //
		opType.substring(15).replace('$', '.') : opType);

	final String[] aliases = info.getAliases();
	if (aliases != null && aliases.length > 0) {
		props.put("Aliases", Arrays.toString(aliases));
	}

	props.put("Identifier", info.cInfo().getIdentifier());
	props.put("Location", ModuleSearcher.location(info.cInfo(), baseDir));
}