use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.
the class SotaNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
File file = new File(internDir, TREE_FILE);
FileInputStream fis = new FileInputStream(file);
ModelContentRO modelContent = ModelContent.loadFromXML(fis);
// Load settings
int inDataSize = 0;
int origDataSize = 0;
try {
m_sota.setUseHierarchicalFuzzyData(modelContent.getBoolean(SotaPortObject.CFG_KEY_USE_FUZZY_HIERARCHY));
m_sota.setMaxHierarchicalLevel(modelContent.getInt(SotaPortObject.CFG_KEY_MAX_FUZZY_LEVEL));
inDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_INDATA_SIZE);
origDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_ORIGDATA_SIZE);
} catch (InvalidSettingsException e1) {
IOException ioe = new IOException("Could not load settings," + "due to invalid settings in model content !");
ioe.initCause(e1);
fis.close();
throw ioe;
}
// Load in data
DataTable table = DataContainer.readFromZip(new File(internDir, IN_DATA_FILE));
final DataArray inData = new DefaultDataArray(table, 1, inDataSize);
m_sota.setInData(inData);
// Load orig data
table = DataContainer.readFromZip(new File(internDir, ORIG_DATA_FILE));
final DataArray origData = new DefaultDataArray(table, 1, origDataSize);
m_sota.setOriginalData(origData);
// Load tree
SotaTreeCell root = new SotaTreeCell(0, false);
try {
root.loadFrom(modelContent, 0, null, false);
} catch (InvalidSettingsException e) {
IOException ioe = new IOException("Could not load tree cells," + "due to invalid settings in model content !");
ioe.initCause(e);
fis.close();
throw ioe;
}
m_sota.setRoot(root);
fis.close();
}
use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.
the class SotaPortObject method load.
/**
* {@inheritDoc}
*/
@Override
protected void load(final ModelContentRO model, final PortObjectSpec spec, final ExecutionMonitor exec) throws InvalidSettingsException, CanceledExecutionException {
if (model != null) {
// Load tree
m_sotaRoot = new SotaTreeCell(0, false);
try {
m_sotaRoot.loadFrom(model, 0, null, false);
} catch (InvalidSettingsException e) {
InvalidSettingsException ioe = new InvalidSettingsException("Could not load tree cells, due to invalid settings in " + "model content !");
ioe.initCause(e);
throw ioe;
}
m_distance = model.getString(CFG_KEY_DIST);
} else {
m_sotaRoot = null;
}
m_spec = spec;
}
use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.
the class SotaDrawingPane method getCellAtCursor.
/**
* Returns the cell related to the given mouse position, if no cell is
* related to that position <code>null</code> is returned.
*
* @param x mouse position on x coordinate
* @param y mouse position on y coordinate
* @return the cell related to the given mouse position or <code>null</code>
* if no cell is available at that position
*/
private SotaTreeCell getCellAtCursor(final int x, final int y) {
if (m_data != null && m_root != null) {
int maxX = m_data.size() * m_pixelWidth;
int yCoord = y;
int xCoord;
// for a cell.
for (int j = 0; j <= m_impreciseness; j++) {
for (int dir = -1; dir <= 1; dir += 2) {
xCoord = x + (j * dir);
if (xCoord <= maxX && xCoord >= 0 && yCoord <= m_jpHeight - PIXEL_HEIGHT) {
ArrayList<SotaTreeCell> list = m_nodesCoordIndex.get(xCoord);
if (list != null) {
for (int i = 0; i < list.size(); i++) {
SotaTreeCellLocations cellLocation = m_cellLocations.get(list.get(i));
if (yCoord <= cellLocation.getStartY() && yCoord >= cellLocation.getEndY()) {
return list.get(i);
}
}
}
}
}
}
}
return null;
}
use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.
the class SotaDrawingPane method computeParentTreeNodeCoordinates.
/**
* Computes the coordinates of the parents of the given children nodes.
*
* @param children the children of the parents to compute the coordinates
* for
* @param level current tree level
* @return the parents in a list for which the coordinates were computed
*/
private ArrayList<?> computeParentTreeNodeCoordinates(final ArrayList<SotaTreeCell> children, final int level) {
ArrayList<SotaTreeCell> parents = new ArrayList<SotaTreeCell>();
for (int i = 0; i < children.size(); i++) {
// only if cell has given level, if not put cell in parents array
if (children.get(i).getLevel() == level) {
// if parent is not in parents list and has no coordinates
if (!parents.contains(children.get(i).getAncestor())) {
parents.add(children.get(i).getAncestor());
// SotaTreeCell c = children.get(i);
// SotaTreeCell cS = children.get(i).getSister();
SotaTreeCellLocations childrenCellLocation = m_cellLocations.get(children.get(i));
SotaTreeCellLocations childrenSisterCellLocation = m_cellLocations.get(children.get(i).getSister());
int x = (childrenCellLocation.getStartX() + childrenSisterCellLocation.getStartX()) / 2;
int startY = childrenCellLocation.getEndY();
int heightFactor = 0;
if (m_isHierarchicalFuzzyData && m_drawHierarchicalFuzzyData) {
// if hierarchical data is used:
heightFactor = level - children.get(i).getAncestor().getLevel();
int currentHLevel = children.get(i).getAncestor().getHierarchyLevel();
int childrenHLevel = children.get(i).getHierarchyLevel();
if (currentHLevel != childrenHLevel) {
heightFactor += m_hierarchicalMaxLevels.get(currentHLevel) - children.get(i).getAncestor().getLevelInHierarchy();
for (int l = childrenHLevel - 1; l > currentHLevel; l--) {
heightFactor += m_hierarchicalMaxLevels.get(l);
}
}
} else {
heightFactor = level - children.get(i).getAncestor().getLevel();
}
int endY = startY - (heightFactor * m_clusterLineHeight);
SotaTreeCellLocations childrenAncestorCellLocation = m_cellLocations.get(children.get(i).getAncestor());
if (childrenAncestorCellLocation != null) {
childrenAncestorCellLocation.setStartX(x);
childrenAncestorCellLocation.setEndX(x);
childrenAncestorCellLocation.setStartY(startY);
childrenAncestorCellLocation.setEndY(endY);
}
// Save the X coordinates and the related cell
addCellToCoordHash(x, children.get(i).getAncestor());
}
} else if (children.get(i).getLevel() < level) {
parents.add(children.get(i));
}
}
if (level > 1) {
return computeParentTreeNodeCoordinates(parents, level - 1);
}
return null;
}
use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.
the class SotaDrawingPane method drawTreeNode.
/**
* Draws the given {@link SotaTreeCell} and its children recursive, by using
* their coordinates.
*
* @param g graphics instance to draw with
* @param cell the cell to draw
*/
private void drawTreeNode(final Graphics g, final SotaTreeCell cell) {
if (!cell.isCell()) {
drawTreeNode(g, cell.getLeft());
drawTreeNode(g, cell.getRight());
}
g.setColor(getCellColor(cell, false));
SotaTreeCellLocations cellLocation = m_cellLocations.get(cell);
// Draw cluster line
g.drawLine(cellLocation.getStartX(), cellLocation.getStartY(), cellLocation.getEndX(), cellLocation.getEndY());
// Draw cluster rectangle
g.drawRect(cellLocation.getEndX() - (m_clusterRectWidth / 2), cellLocation.getEndY() - (m_clusterRectWidth / 2), m_clusterRectWidth, m_clusterRectWidth);
SotaTreeCell sister = cell.getSister();
if (sister == null) {
sister = cell;
}
if (cell.isHilited() && sister.isHilited() && !cell.isSelected()) {
g.setColor(m_hilit);
} else if (cell.isHilited() && sister.isHilited() && cell.isSelected()) {
g.setColor(m_selectedHilited);
} else {
g.setColor(getCellColor(cell, true));
}
// Draw line between sisters
if (cell.getSister() != null) {
SotaTreeCellLocations sisterCellLocation = m_cellLocations.get(cell.getSister());
g.drawLine(cellLocation.getStartX(), cellLocation.getEndY(), sisterCellLocation.getStartX(), sisterCellLocation.getEndY());
}
}
Aggregations