Search in sources :

Example 1 with RegionVector

use of facetmodeller.plc.RegionVector in project facetmodeller by pglelievre.

the class DefineRegionClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Get the current group:
    Group group = controller.getSelectedCurrentGroup();
    // Check if regions already exist in the current group and ask user what to do:
    boolean deleteRegions = false;
    if (group.numberOfRegions() != 0) {
        String message = "Do you want to delete the current region(s) in the group?";
        int response = Dialogs.question(controller, message, title());
        if (response == Dialogs.CANCEL_OPTION) {
            return;
        }
        if (response == Dialogs.YES_OPTION) {
            deleteRegions = true;
        }
    }
    // Ask if this is a regular region point or a control point:
    int response = Dialogs.question(controller, "What type of point is this?", title(), "Region", "Control", "Cancel");
    boolean isCon;
    switch(response) {
        case Dialogs.YES_OPTION:
            // region point
            isCon = false;
            break;
        case Dialogs.NO_OPTION:
            // control point
            isCon = true;
            break;
        default:
            // user cancelled
            return;
    }
    // Create a new region object linked to the current section and current group:
    Region newRegion = new Region(isCon, p, controller.getSelectedCurrentSection(), group);
    // Add the region, deleting the current regions if requested:
    Command com;
    if (deleteRegions) {
        RegionVector regions = group.getRegions();
        com = new ReplaceRegionCommand(controller.getModelManager(), regions, newRegion);
    } else {
        com = new AddRegionCommand(controller.getModelManager(), newRegion);
    }
    com.execute();
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    controller.redraw();
}
Also used : Group(facetmodeller.groups.Group) Command(facetmodeller.commands.Command) ReplaceRegionCommand(facetmodeller.commands.ReplaceRegionCommand) AddRegionCommand(facetmodeller.commands.AddRegionCommand) Region(facetmodeller.plc.Region) RegionVector(facetmodeller.plc.RegionVector) AddRegionCommand(facetmodeller.commands.AddRegionCommand) ReplaceRegionCommand(facetmodeller.commands.ReplaceRegionCommand)

Example 2 with RegionVector

use of facetmodeller.plc.RegionVector in project facetmodeller by pglelievre.

the class SectionImagePanel method paintComponent.

/**
 * Paints graphics on the panel.
 * @param g Graphics context in which to draw.
 */
@Override
public void paintComponent(Graphics g) {
    // Paint background:
    super.paintComponent(g);
    // Clear the lists of painted nodes, node points, etc.:
    paintedNodes.clear();
    paintedNodePoints.clear();
    paintedFacets.clear();
    paintedFacetCentroids.clear();
    paintedRegions.clear();
    paintedRegionPoints.clear();
    // Return if no sections exist:
    if (!controller.hasSections()) {
        return;
    }
    // Return if no current section exists:
    Section currentSection = controller.getSelectedCurrentSection();
    if (currentSection == null) {
        return;
    }
    // Set some local variables:
    int shiftX = controller.getShiftingX();
    int shiftY = controller.getShiftingY();
    int mode = controller.getClickMode();
    boolean showImage = controller.getShowImage();
    boolean showImageOutline = controller.getShowImageOutline();
    // Get the other sections being displayed (if any exist):
    SectionVector otherSections;
    // if (controller.getShowOther()) {
    otherSections = controller.getSelectedOtherSections();
    // } else {
    // otherSections = null;
    // }
    // Determine the facets to paint:
    FacetVector facetsToPaint = new FacetVector();
    GroupVector groups = controller.getSelectedFacetGroups();
    if (groups != null) {
        // for (int i=0 ; i<groups.size(); i++ ) { // loop over every selected facet group
        for (int i = (groups.size() - 1); i >= 0; i--) {
            // loop over every selected facet group in reverse order
            FacetVector facets = groups.get(i).getFacets();
            for (int j = 0; j < facets.size(); j++) {
                // loop over every facet in the ith group
                Facet facet = facets.get(j);
                // Make sure there is more than one node in the facet:
                // number of nodes in the facet
                int nn = facet.size();
                if (nn <= 1) {
                    continue;
                }
                // Make sure the facet belongs to no other sections than those selected:
                boolean ok = true;
                for (int k = 0; k < nn; k++) {
                    // loop over each node in the facet
                    // Check if the kth node in the facet should be plotted: it must be either
                    // 1) in the current section, which must be calibrated if its the topo section; OR
                    // 2) in one of the other selected sections, which must be calibrated:
                    // kth node in the facet
                    Node node = facet.getNode(k);
                    // section for the kth node
                    Section s = node.getSection();
                    if (s.equals(currentSection)) {
                        // node is in current section
                        if (node.getPoint2D() == null) {
                            // node not paintable
                            ok = false;
                            break;
                        }
                    } else {
                        // node not in current section
                        if (otherSections == null || !otherSections.contains(s) || !s.isCalibrated()) {
                            // (calibration required for projection)
                            ok = false;
                            break;
                        }
                        if (node.getPoint3D() == null) {
                            // node not paintable
                            ok = false;
                            break;
                        }
                    }
                }
                if (!ok) {
                    continue;
                }
                // Add the facet to the list of facets to paint:
                facetsToPaint.add(facet);
            }
        }
    }
    /*
        // Determine the nodes to paint in the current section:
        NodeVector nodesToPaintCurrent = new NodeVector();
        NodeVector nodes = currentSection.getNodes();
        for (int i=0 ; i<nodes.size() ; i++ ) {
            Node node = nodes.get(i);
            // Make sure the node is in one of the selected groups to paint:
            if (!controller.isSelectedNodeGroup(node.getGroup())) { continue; } // cycle to next node
            // Make sure the node is paintable:
            if (node.getPoint2D()==null) { continue; } // cycle to next node
            // Add the node to the list of nodes to paint:
            nodesToPaintCurrent.add(node);
        }
        
        // Determine the nodes to paint in the other sections:
        NodeVector nodesToPaintOther = new NodeVector();
        if (otherSections!=null) {
            if (!otherSections.isEmpty()) {
                for (int j=0 ; j<otherSections.size() ; j++ ) {
                    // Skip the section if it is the current section:
                    Section s = otherSections.get(j);
                    if (s.equals(currentSection)) { continue; }
                    // Skip the section if it is not calibrated (calibration is required for projection):
                    if (!s.isCalibrated()) { continue; }
                    // Loop over the nodes:
                    nodes = s.getNodes();
                    for (int i=0 ; i<nodes.size() ; i++ ) {
                        Node node = nodes.get(i);
                        // Make sure the node is in one of the selected groups to paint:
                        if (!controller.isSelectedNodeGroup(node.getGroup())) { continue; } // cycle to next node
                        // Make sure the node is paintable:
                        if (node.getPoint3D()==null) { continue; } // cycle to next node
                        // Add the node to the list of nodes to paint:
                        nodesToPaintOther.add(node);
                    }
                }
            }
        }
        */
    // Determine the nodes to paint in the current and other sections:
    NodeVector nodesToPaint = new NodeVector();
    groups = controller.getSelectedNodeGroups();
    if (groups != null) {
        for (int i = (groups.size() - 1); i >= 0; i--) {
            // loop over every selected node group in reverse order
            NodeVector nodes = groups.get(i).getNodes();
            for (int j = 0; j < nodes.size(); j++) {
                // loop over every node in the ith group
                Node node = nodes.get(j);
                // Check if the node is in the current section:
                if (node.getSection() == currentSection) {
                    // cycle to next node
                    if (node.getPoint2D() == null) {
                        continue;
                    }
                    // Add the node to the list of nodes to paint and cycle to the next node:
                    nodesToPaint.add(node);
                    continue;
                }
                // Check if there are any other sections selected:
                if (otherSections == null) {
                    continue;
                }
                if (otherSections.isEmpty()) {
                    continue;
                }
                // Check if the node is in one of the other sections selected:
                Section s = node.getSection();
                if (!otherSections.contains(s)) {
                    continue;
                }
                // Skip the node if it's section is not calibrated (calibration is required for projection):
                if (!s.isCalibrated()) {
                    continue;
                }
                // cycle to next node
                if (node.getPoint3D() == null) {
                    continue;
                }
                // Add the node to the list of nodes to paint:
                nodesToPaint.add(node);
            }
        }
    }
    // Calculate the range, in image panel units, across which we'll need to plot:
    // will hold minimum coordinate values
    MyPoint2D p1 = MyPoint2D.zero();
    // will hold maximum coordinate values
    MyPoint2D p2 = new MyPoint2D(currentSection.getWidth(), currentSection.getHeight());
    RegionVector regions = currentSection.getRegions();
    if (!(currentSection instanceof SnapshotSection)) {
        for (int i = 0; i < facetsToPaint.size(); i++) {
            // loop over facets
            Facet facet = facetsToPaint.get(i);
            for (int j = 0; j < facet.size(); j++) {
                Node node = facet.getNode(j);
                MyPoint2D p = shiftNode(node, currentSection, shiftX, shiftY);
                if (p == null) {
                    // shouldn't happen, but I'll check for it anyway
                    facetsToPaint.remove(facet);
                    continue;
                }
                p1.min(p);
                p2.max(p);
            }
        }
        /*
            for (int i=0 ; i<nodesToPaintCurrent.size() ; i++ ) { // loop over nodes for current section
                Node node = nodesToPaintCurrent.get(i);
                MyPoint2D p = shiftNode(node,currentSection,shiftX,shiftY);
                if (p==null) { // shouldn't happen, but I'll check for it anyway
                    nodesToPaintCurrent.remove(node);
                    continue;
                }
                p1.min(p);
                p2.max(p);
            }
            for (int i=0 ; i<nodesToPaintOther.size() ; i++ ) { // loop over nodes for other section
                Node node = nodesToPaintOther.get(i);
                MyPoint2D p = shiftNode(node,currentSection,shiftX,shiftY);
                if (p==null) {  // shouldn't happen, but I'll check for it anyway
                    nodesToPaintOther.remove(node);
                    continue;
                }
                p1.min(p);
                p2.max(p);
            }
            */
        for (int i = 0; i < nodesToPaint.size(); i++) {
            // loop over nodes for other section
            Node node = nodesToPaint.get(i);
            MyPoint2D p = shiftNode(node, currentSection, shiftX, shiftY);
            if (p == null) {
                // shouldn't happen, but I'll check for it anyway
                nodesToPaint.remove(node);
                continue;
            }
            p1.min(p);
            p2.max(p);
        }
        if (controller.getShowRegions()) {
            for (int i = 0; i < regions.size(); i++) {
                // loop over regions
                Region region = regions.get(i);
                MyPoint2D p = region.getPoint2D();
                p1.min(p);
                p2.max(p);
            }
        }
    }
    // coordinate ranges
    MyPoint2D dp = MyPoint2D.minus(p2, p1);
    if (dp.min() <= 0.0) {
        return;
    }
    // Tightly fit the plot inside the panel but maintain aspect ratio:
    calculateTightFitTransform(p1, dp);
    boolean hasImage = currentSection.hasImage();
    if (hasImage && showImage) {
        // Get the current section image:
        BufferedImage image = currentSection.getImage();
        // Check the image exists:
        if (image != null) {
            // this may happen if the image file specified in a session file is not found
            // Calculate the tight fit transform:
            tightFitImage(g, image);
        }
    }
    // Get drawing styles for overlays:
    final int nodeWidth = controller.getPointWidth();
    final int edgeWidth = controller.getLineWidth();
    // centroids drawn half the node width
    final int centroidWidth = (int) Math.ceil(nodeWidth / 2.0);
    final float transparency = (float) controller.getTransparency();
    // transparency factor
    AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency);
    // final boolean showPickingRadius = controller.getShowPickingRadius();
    // final int pickingRadius = (int)( controller.getPickingRadius() * scaling ); // panel pixel width
    // The space-to-image transform may not be equidistance (may have different scalings for horizontal and vertical panel directions)
    // so, without knowing how best to show a picking radius in spatial units (it used to be in image pixel units but that caused some issues)
    // I have just gotten rid of the plotting of the picking radius.
    // Use Java2D graphics for overlays:
    Graphics2D g2 = (Graphics2D) g;
    g2.setComposite(composite);
    if (!hasImage || !showImage) {
        // section does not have an image or user does not want image shown
        double imageWidth = currentSection.getWidth();
        double imageHeight = currentSection.getHeight();
        double scaledWidth = scaling * imageWidth;
        double scaledHeight = scaling * imageHeight;
        Color col = currentSection.getColor();
        boolean ok = false;
        if (col == null) {
            col = getBackground();
        }
        // Plot a coloured rectangle:
        if (!hasImage && showImage) {
            // section does not have an image and user wants image shown
            g2.setColor(col);
            g2.fillRect((int) translation.getX(), (int) translation.getY(), (int) scaledWidth, (int) scaledHeight);
            ok = true;
        }
        // Plot outline of image:
        if (showImageOutline) {
            g2.setColor(Color.black);
            g2.drawRect((int) translation.getX(), (int) translation.getY(), (int) scaledWidth, (int) scaledHeight);
            ok = true;
        }
        // Make sure something is plotted:
        if (!ok) {
            col = getBackground();
            g2.setColor(col);
            g2.drawRect((int) translation.getX(), (int) translation.getY(), (int) scaledWidth, (int) scaledHeight);
        }
    }
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // line style
    g2.setStroke(new BasicStroke(edgeWidth));
    // Get number of dimensions:
    int ndim = controller.numberOfDimensions();
    // Get the drawing options for colouring the nodes and facets:
    int nodeColorBy = controller.getNodeColorBy();
    int facetColorBy = controller.getFacetColorBy();
    // Paint the patches, edges and centroids of the facets:
    for (int i = 0; i < facetsToPaint.size(); i++) {
        // loop over every facet that needs to be painted
        Facet facet = facetsToPaint.get(i);
        // Create a path around possibly shifted node coordinates:
        HasPathAndCentroid tmp = addFacetToPath(facet, currentSection, shiftX, shiftY);
        // shouldn't happen, but I'll check for it anyway
        if (tmp == null) {
            continue;
        }
        // Close the path:
        tmp.path.closePath();
        // Transform the path from section to panel coordinates:
        tmp.path.transform(imageToPanel);
        // Determine the painting colour for the facet:
        Color col = getFacetPaintingColor(facetColorBy, facet);
        // Greate a filled, semi-transparent polygonal patch:
        if (facet.size() > 2) {
            // (no patch exists for edge-element facets)
            g2.setPaint(col);
            g2.fill(tmp.path);
        }
        // Draw the path (i.e. the facet edges):
        if (ndim == 3) {
            col = controller.getEdgeColor();
        }
        // else {
        // color = facet.getColor();
        // }
        g2.setPaint(col);
        g2.draw(tmp.path);
        // Draw a small point at the facet centroid:
        if (ndim == 2) {
            col = controller.getEdgeColor();
        }
        g2.setPaint(col);
        // filled
        PaintingUtils.paintPoint(g2, imageToPanel, tmp.centroid, centroidWidth, true);
        // Add to the list of painted facets and centroids:
        paintedFacets.add(facet);
        paintedFacetCentroids.add(tmp.centroid);
    }
    // Paint the edges of the current facet being defined:
    BasicStroke dashedStroke = new BasicStroke(edgeWidth + 1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, (float) 10.0, new float[] { 2f, 16f }, (float) 0.0);
    Facet currentFacet = controller.getCurrentFacet();
    if (currentFacet != null) {
        // Create a path around the node coordinates:
        if (currentFacet.size() > 1) {
            HasPathAndCentroid tmp = addFacetToPath(currentFacet, currentSection, shiftX, shiftY);
            if (tmp != null) {
                // May want to close the path:
                if (mode == ClickModeManager.MODE_DEFINE_TRI_FACETS || mode == ClickModeManager.MODE_ADD_NODES_IN_FACETS) {
                    tmp.path.closePath();
                }
                // Transform the path from section to panel coordinates:
                tmp.path.transform(imageToPanel);
                // Draw the path:
                // line style changed
                g2.setStroke(dashedStroke);
                g2.setPaint(controller.getDefineFacetEdgeColor());
                g2.draw(tmp.path);
                // line style reset
                g2.setStroke(new BasicStroke(edgeWidth));
            }
        }
    }
    // Paint the edges of the facet closest to the cursor position:
    if (mouseInside && currentFacet == null) {
        Facet facet = controller.getClosestFacet();
        if (facet != null) {
            // Create a path around the node coordinates:
            if (facet.size() > 1) {
                HasPathAndCentroid tmp = addFacetToPath(facet, currentSection, shiftX, shiftY);
                if (tmp != null) {
                    // null shouldn't happen, but I'll check for it anyway
                    // Close the path:
                    tmp.path.closePath();
                    // Transform the path from section to panel coordinates:
                    tmp.path.transform(imageToPanel);
                    // Draw the path:
                    // line style changed
                    g2.setStroke(dashedStroke);
                    g2.setPaint(controller.getDefineFacetEdgeColor());
                    g2.draw(tmp.path);
                    // line style reset
                    g2.setStroke(new BasicStroke(edgeWidth));
                }
            }
        }
    }
    // Paint the nodes for the current and other sections:
    for (int i = 0; i < nodesToPaint.size(); i++) {
        Node node = nodesToPaint.get(i);
        // Check if the node is on the current section:
        MyPoint2D p;
        boolean filled;
        if (node.getSection() == currentSection) {
            // node on current section
            p = node.getPoint2D();
            // nodes on current section are painted filled
            filled = true;
        } else {
            // node is on another section so it may be shifted
            p = shiftNode(node, currentSection, shiftX, shiftY);
            // nodes on other sections are painted unfilled
            filled = false;
        }
        // shouldn't happen, but I'll check for it anyway
        if (p == null) {
            continue;
        }
        // Determine the painting colour for the node:
        Color col = getNodePaintingColor(nodeColorBy, node);
        // Paint the node:
        g2.setPaint(col);
        PaintingUtils.paintPoint(g2, imageToPanel, p, nodeWidth, filled);
        // Add to the list of painted nodes and node points:
        paintedNodes.add(node);
        paintedNodePoints.add(p);
    }
    // Paint the region points for the current section:
    if (controller.getShowRegions()) {
        for (int i = 0; i < regions.size(); i++) {
            Region region = regions.get(i);
            MyPoint2D p = region.getPoint2D();
            // shouldn't happen, but I'll check for it anyway
            if (p == null) {
                continue;
            }
            g2.setPaint(region.getColor());
            PaintingUtils.paintPoint(g2, imageToPanel, p, nodeWidth, true);
            // Add to the list of painted regions and region points:
            paintedRegions.add(region);
            paintedRegionPoints.add(p);
        }
    }
    // Paint circles around the nodes of the current facet being defined:
    if (currentFacet != null) {
        if (mode == ClickModeManager.MODE_DEFINE_TRI_FACETS) {
            g2.setPaint(Color.WHITE);
        } else {
            g2.setPaint(Color.BLACK);
        }
        for (int i = 0; i < currentFacet.size(); i++) {
            Node node = currentFacet.getNode(i);
            // Only paint the node if it is in the current or other sections:
            Section s = node.getSection();
            if (s.equals(currentSection) || (otherSections != null && otherSections.contains(s))) {
                MyPoint2D p = shiftNode(node, currentSection, shiftX, shiftY);
                if (p == null) {
                    continue;
                }
                PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
            }
        }
    }
    // Paint circles around the nodes of the facet closest to the cursor position:
    if (mouseInside && currentFacet == null) {
        Facet facet = controller.getClosestFacet();
        if (facet != null) {
            // Paint circles around the node coordinates:
            g2.setPaint(Color.WHITE);
            for (int i = 0; i < facet.size(); i++) {
                Node node = facet.getNode(i);
                MyPoint2D p = shiftNode(node, currentSection, shiftX, shiftY);
                if (p == null) {
                    continue;
                }
                PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
            }
            // If in MODE_INFO or MODE_REVERSE_FACETS then paint a thicker circle around the first and possibly second node:
            if (mode == ClickModeManager.MODE_INFO || mode == ClickModeManager.MODE_REVERSE_FACETS) {
                Node node = facet.getNode(0);
                MyPoint2D p = shiftNode(node, currentSection, shiftX, shiftY);
                if (p != null) {
                    g2.setStroke(new BasicStroke(ndim * edgeWidth));
                    PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
                    // line style reset
                    g2.setStroke(new BasicStroke(edgeWidth));
                }
                if (ndim == 3) {
                    node = facet.getNode(1);
                    p = shiftNode(node, currentSection, shiftX, shiftY);
                    if (p != null) {
                        g2.setStroke(new BasicStroke(2 * edgeWidth));
                        PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
                        // line style reset
                        g2.setStroke(new BasicStroke(edgeWidth));
                    }
                }
            }
        // // Paint a white circle around the centroid:
        // if (showPickingRadius) {
        // HasPathAndCentroid tmp = addFacetToPath(facet,currentSection,shiftX,shiftY);
        // if (tmp!=null) { // shouldn't happen, but I'll check for it anyway
        // tmp.path.closePath();
        // tmp.path.transform(imageToPanel);
        // PaintingUtils.paintPoint(g2,imageToPanel,tmp.centroid,2*centroidWidth,false); // not filled
        // g2.setPaint(Color.BLACK);
        // PaintingUtils.paintPoint(g2,imageToPanel,tmp.centroid,2*pickingRadius,false); // not filled
        // }
        // }
        }
    }
    // boolean isTopo = currentSection.isTopo();
    if (hasImage && currentSection.isCalibrated()) {
        g2.setPaint(controller.getCalibrationColor());
        PaintingUtils.paintPoint(g2, imageToPanel, currentSection.getClicked1(), nodeWidth, false);
        PaintingUtils.paintPoint(g2, imageToPanel, currentSection.getClicked2(), nodeWidth, false);
    }
    // // If calibrating then draw large cross-hairs across the image:
    // if ( controller.getMode() == FacetModeller.MODE_CALIBRATE ) {
    // p = new MyPoint2D(getMousePosition());
    // g2.setColor(Color.white);
    // g2.setStroke(new BasicStroke(1)); // line style reset
    // double x = p.getX();
    // double y = p.getY();
    // double w = getWidth()/2.0;
    // g2.drawLine((int)(x-w),(int)y,(int)(x+w),(int)y);
    // g2.drawLine((int)x,(int)(y-w),(int)x,(int)(y+w));
    // }
    // Paint a large circle around the origin node of the same colour as the node if it is present in those painted:
    Node originNode = controller.getOriginNode3D();
    if (originNode != null) {
        int i = paintedNodes.indexOf(originNode);
        if (i >= 0) {
            MyPoint2D p = shiftNode(originNode, currentSection, shiftX, shiftY);
            if (p != null) {
                // shouldn't happen, but I'll check for it anyway
                // Determine the painting colour for the origin node:
                Color col = getNodePaintingColor(nodeColorBy, originNode);
                // Paint the origin node:
                g2.setPaint(col);
                // g2.setStroke(new BasicStroke(2*edgeWidth));
                PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
            // g2.setStroke(new BasicStroke(edgeWidth)); // line style reset
            }
        }
    }
    // Paint a white circle around the current node (e.g. being moved or first in an edge being flipped):
    Node currentNode = controller.getCurrentNode();
    if (currentNode != null) {
        MyPoint2D p = shiftNode(currentNode, currentSection, shiftX, shiftY);
        if (p != null) {
            g2.setPaint(Color.WHITE);
            // not filled
            PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
        }
    }
    // Paint a white circle around the node closest to the cursor position (e.g. or that being moved):
    MyPoint2D p = controller.getClosestNodePoint();
    if (mouseInside && p != null) {
        g2.setPaint(Color.WHITE);
        // not filled
        PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
    // if (showPickingRadius) {
    // g2.setPaint(Color.BLACK);
    // PaintingUtils.paintPoint(g2,imageToPanel,p,2*pickingRadius,false); // not filled
    // }
    }
    // Paint a white circle around the region closest to the cursor position:
    p = controller.getClosestRegionPoint();
    if (mouseInside && p != null) {
        g2.setPaint(Color.WHITE);
        // not filled
        PaintingUtils.paintPoint(g2, imageToPanel, p, 2 * nodeWidth, false);
    // if (showPickingRadius) {
    // g2.setPaint(Color.BLACK);
    // PaintingUtils.paintPoint(g2,imageToPanel,p,2*pickingRadius,false); // not filled
    // }
    }
}
Also used : SectionVector(facetmodeller.sections.SectionVector) FacetVector(facetmodeller.plc.FacetVector) Node(facetmodeller.plc.Node) Section(facetmodeller.sections.Section) SnapshotSection(facetmodeller.sections.SnapshotSection) MyPoint2D(geometry.MyPoint2D) GroupVector(facetmodeller.groups.GroupVector) NodeVector(facetmodeller.plc.NodeVector) RegionVector(facetmodeller.plc.RegionVector) Region(facetmodeller.plc.Region) SnapshotSection(facetmodeller.sections.SnapshotSection) Facet(facetmodeller.plc.Facet)

Example 3 with RegionVector

use of facetmodeller.plc.RegionVector in project facetmodeller by pglelievre.

the class Synthesizer method calculateClosestRegion.

/**
 * Determines the closest region point to the input point (e.g. the cursor position)
 * and sets the closestRegion object to that region.
 * @param p
 * @return
 */
public boolean calculateClosestRegion(MyPoint2D p) {
    // Set the closestRegion object to null:
    closestRegion = null;
    closestRegionPoint = null;
    // Get the current section:
    if (!controller.hasSections()) {
        return false;
    }
    Section currentSection = controller.getSelectedCurrentSection();
    if (currentSection == null) {
        return false;
    }
    // Check regions exist for the current section:
    // RegionVector regions = getCurrentSection().getRegions(); // the regions for the current section
    // if (regions.size()==0) { return; }
    // Check regions have been painted:
    RegionVector regions = controller.getPaintedRegions();
    if (regions.isEmpty()) {
        return false;
    }
    // Find the closest painted region point to the point p:
    MyPoint2DVector points = controller.getPaintedRegionPoints();
    int ic = points.findClosest(p);
    if (ic < 0) {
        return false;
    }
    MyPoint2D point = points.get(ic);
    // Convert points from image pixel coordinates to spatial coordinates:
    MyPoint3D p3 = currentSection.imageToSpace(p);
    if (p3 == null) {
        return false;
    }
    MyPoint3D point3 = currentSection.imageToSpace(point);
    if (point3 == null) {
        return false;
    }
    // Check the distance is small enough:
    Double d = point3.distanceToPoint(p3);
    if (d > controller.getPickingDistance()) {
        return false;
    }
    // Get the closest painted region:
    closestRegion = regions.get(ic);
    closestRegionPoint = points.get(ic);
    // Return successfully:
    return true;
}
Also used : MyPoint2DVector(geometry.MyPoint2DVector) RegionVector(facetmodeller.plc.RegionVector) Section(facetmodeller.sections.Section) MyPoint2D(geometry.MyPoint2D) MyPoint3D(geometry.MyPoint3D)

Aggregations

RegionVector (facetmodeller.plc.RegionVector)3 Region (facetmodeller.plc.Region)2 Section (facetmodeller.sections.Section)2 MyPoint2D (geometry.MyPoint2D)2 AddRegionCommand (facetmodeller.commands.AddRegionCommand)1 Command (facetmodeller.commands.Command)1 ReplaceRegionCommand (facetmodeller.commands.ReplaceRegionCommand)1 Group (facetmodeller.groups.Group)1 GroupVector (facetmodeller.groups.GroupVector)1 Facet (facetmodeller.plc.Facet)1 FacetVector (facetmodeller.plc.FacetVector)1 Node (facetmodeller.plc.Node)1 NodeVector (facetmodeller.plc.NodeVector)1 SectionVector (facetmodeller.sections.SectionVector)1 SnapshotSection (facetmodeller.sections.SnapshotSection)1 MyPoint2DVector (geometry.MyPoint2DVector)1 MyPoint3D (geometry.MyPoint3D)1