use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.
the class ImageToTableNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
ImagePortObjectSpec inspec = (ImagePortObjectSpec) inSpecs[0];
DataTableSpec outspec = createResultSpec(inspec, m_columnNameModel.getStringValue());
return new DataTableSpec[] { outspec };
}
use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.
the class WritePNGNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
String outPath = m_fileOutSettings.getStringValue();
boolean overwriteOK = m_overwriteOKBoolean.getBooleanValue();
if (outPath == null || outPath.length() == 0) {
throw new InvalidSettingsException("No output path specified");
}
File f = new File(outPath);
if (f.isDirectory()) {
throw new InvalidSettingsException("Can't write to \"" + outPath + "\": it is a directory");
}
if (f.isFile() && !overwriteOK) {
throw new InvalidSettingsException("Can't write to \"" + outPath + "\": file exists (configure overwrite in dialog)");
}
File directory = f.getParentFile();
if (directory == null || !directory.isDirectory()) {
throw new InvalidSettingsException("Can't write to \"" + outPath + "\": parent directory does not exist");
}
ImagePortObjectSpec imageInObject = (ImagePortObjectSpec) inSpecs[0];
DataType dataType = imageInObject.getDataType();
if (!dataType.isCompatible(PNGImageValue.class)) {
throw new InvalidSettingsException("Unsupported image type, " + "expecting PNG input, got " + dataType);
}
return new PortObjectSpec[0];
}
use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.
the class TableRowToImageNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
String column = m_imageColSettingsModel.getStringValue();
int columnIndex = inSpec.findColumnIndex(column);
if (columnIndex < 0) {
columnIndex = findImageColumnIndex(inSpec);
if (columnIndex >= 0) {
setWarningMessage("Found image column '" + inSpec.getColumnSpec(columnIndex).getName() + "'.");
}
}
if (columnIndex < 0) {
String error = column == null ? "No image column in input" : "No such image column in input table: " + column;
throw new InvalidSettingsException(error);
}
DataColumnSpec columnSpec = inSpec.getColumnSpec(columnIndex);
if (!columnSpec.getType().isCompatible(ImageValue.class)) {
throw new InvalidSettingsException("Column \"" + column + "\" does not contain images");
}
return new PortObjectSpec[] { new ImagePortObjectSpec(columnSpec.getType()) };
}
use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.
the class TableRowToImageNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inTable = (BufferedDataTable) inObjects[0];
// check for empty table
if (inTable.size() == 0) {
throw new IllegalArgumentException("Input table is empty.");
}
// warn if more than one row
if (inTable.size() > 1) {
setWarningMessage("Input data table has more than one rows! " + "Using first row only.");
}
String column = m_imageColSettingsModel.getStringValue();
DataTableSpec inSpec = inTable.getDataTableSpec();
int columnIndex = inSpec.findColumnIndex(column);
if (columnIndex < 0) {
columnIndex = findImageColumnIndex(inSpec);
}
ImagePortObjectSpec imagePortObjectSpec = new ImagePortObjectSpec(inSpec.getColumnSpec(columnIndex).getType());
final RowIterator it = inTable.iterator();
while (it.hasNext()) {
DataRow row = it.next();
DataCell cell = row.getCell(columnIndex);
if (!cell.isMissing()) {
ImageContent ic = ((ImageValue) cell).getImageContent();
return new PortObject[] { new ImagePortObject(ic, imagePortObjectSpec) };
} else {
setWarningMessage("Found missing image cell, skipping it...");
}
}
throw new IllegalArgumentException("Input table contains only missing cells.");
}
use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.
the class WriteImageNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
ImagePortObjectSpec imageInObject = (ImagePortObjectSpec) inSpecs[0];
DataType dataType = imageInObject.getDataType();
if (!dataType.isCompatible(ImageValue.class)) {
throw new InvalidSettingsException("Unsupported image type");
}
// how ugly - we don't know the image extension upon execution, let's
// hope the user gave it the correct extension (e.g. ".png") already,
// otherwise the overwriteOK check may fail during configure
String guessedExtension;
if (dataType.isCompatible(PNGImageValue.class)) {
guessedExtension = ".png";
} else if (dataType.getPreferredValueClass().getSimpleName().equals("SvgImageValue")) {
guessedExtension = ".svg";
} else {
guessedExtension = "";
}
getOutputLocation(guessedExtension, true);
return new PortObjectSpec[0];
}
Aggregations