Search in sources :

Example 1 with SotaTreeCell

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();
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) ModelContentRO(org.knime.core.node.ModelContentRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) DataArray(org.knime.base.node.util.DataArray)

Example 2 with SotaTreeCell

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;
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 3 with SotaTreeCell

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;
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)

Example 4 with SotaTreeCell

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;
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations) ArrayList(java.util.ArrayList)

Example 5 with SotaTreeCell

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());
    }
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)

Aggregations

SotaTreeCell (org.knime.base.node.mine.sota.logic.SotaTreeCell)8 SotaTreeCellLocations (org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)4 DataRow (org.knime.core.data.DataRow)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Dimension (java.awt.Dimension)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FilterColumnRow (org.knime.base.data.filter.column.FilterColumnRow)1 DataArray (org.knime.base.node.util.DataArray)1 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)1 DataCell (org.knime.core.data.DataCell)1 DataTable (org.knime.core.data.DataTable)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 StringCell (org.knime.core.data.def.StringCell)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 ModelContentRO (org.knime.core.node.ModelContentRO)1