Search in sources :

Example 1 with MyPoint2DVector

use of geometry.MyPoint2DVector in project facetmodeller by pglelievre.

the class Synthesizer method calculateLineFacet.

/**
 * Calculates a linear edge element facet from the two closest painted nodes.
 * @param p
 * @return
 */
public Facet calculateLineFacet(MyPoint2D p) {
    // Set the currentFacet object to null:
    currentFacet = null;
    // Check for no sections or groups:
    if (!controller.hasSections()) {
        return null;
    }
    if (!controller.hasGroups()) {
        return null;
    }
    // Check at least two nodes have been painted:
    NodeVector nodes = controller.getPaintedNodes();
    if (nodes.size() < 2) {
        return null;
    }
    // Find the two closest painted node points to the selected point p:
    MyPoint2DVector points = controller.getPaintedNodePoints();
    ArrayList<Integer> ibest = points.findClosest(p, 2);
    if (ibest == null) {
        return null;
    }
    // Calculate a length scale based on the points found above:
    double d = 0;
    for (int i = 0; i < 2; i++) {
        int ii = ibest.get(i);
        MyPoint2D pi = points.get(ii);
        double di = p.distanceToPoint(pi);
        d = Math.max(d, di);
    }
    d *= controller.getAutoFacetFactor();
    // Find all points within that length scale distance:
    ibest = points.findClose(p, d);
    // Loop over each possible facet (each possible combination of 2 points found above):
    int n = ibest.size();
    int[] inode = new int[2];
    double dbest = Double.MAX_VALUE;
    for (int i0 = 0; i0 < n - 1; i0++) {
        for (int i1 = i0 + 1; i1 < n; i1++) {
            // Calculate the centroid of the current possible facet:
            MyPoint2DVector pv = new MyPoint2DVector();
            int ii0 = ibest.get(i0);
            int ii1 = ibest.get(i1);
            pv.add(points.get(ii0));
            pv.add(points.get(ii1));
            MyPoint2D centroid = pv.centroid();
            // Calculate the distance to that centroid:
            d = p.distanceToPoint(centroid);
            // Record the closest centroid:
            if (d < dbest) {
                inode[0] = ii0;
                inode[1] = ii1;
                dbest = d;
            }
        }
    // for i1
    }
    // for i0
    // Create a new facet object:
    // NOT LINKED TO A GROUP YET!
    currentFacet = new Facet();
    // Loop over each of the best two points:
    for (int i = 0; i < 2; i++) {
        // Get the ith closest painted node:
        Node node = nodes.get(inode[i]);
        // // Get the section for the ith node so it can be added to the facet:
        // Section section = node.getSection();
        // Add the node to the current facet:
        currentFacet.addNode(node);
    // // Add the relevant section to the current facet: // no longer necessary
    // currentFacet.addSection(section);
    }
    // Return the facet:
    return currentFacet;
}
Also used : MyPoint2DVector(geometry.MyPoint2DVector) NodeVector(facetmodeller.plc.NodeVector) Node(facetmodeller.plc.Node) MyPoint2D(geometry.MyPoint2D) Facet(facetmodeller.plc.Facet)

Example 2 with MyPoint2DVector

use of geometry.MyPoint2DVector in project facetmodeller by pglelievre.

the class Synthesizer method calculateTriFacet.

/**
 * Calculates a triangular facet from the three closest painted nodes.
 * @param p
 * @return
 */
public Facet calculateTriFacet(MyPoint2D p) {
    // Set the currentFacet object to null:
    currentFacet = null;
    // Check for no sections or groups:
    if (!controller.hasSections()) {
        return null;
    }
    if (!controller.hasGroups()) {
        return null;
    }
    // Check at least three nodes have been painted:
    NodeVector nodes = controller.getPaintedNodes();
    if (nodes.size() < 3) {
        return null;
    }
    // Find the three closest painted node points to the selected point p:
    MyPoint2DVector points = controller.getPaintedNodePoints();
    ArrayList<Integer> ibest = points.findClosest(p, 3);
    if (ibest == null) {
        return null;
    }
    // Calculate a length scale based on the points found above:
    double d = 0;
    for (int i = 0; i < 3; i++) {
        int ii = ibest.get(i);
        MyPoint2D pi = points.get(ii);
        double di = p.distanceToPoint(pi);
        d = Math.max(d, di);
    }
    d *= controller.getAutoFacetFactor();
    // Find all points within that length scale distance:
    ibest = points.findClose(p, d);
    // Loop over each possible facet (each possible combination of 3 points found above):
    int n = ibest.size();
    int[] inode = new int[3];
    double dbest = Double.MAX_VALUE;
    for (int i0 = 0; i0 < n - 2; i0++) {
        for (int i1 = i0 + 1; i1 < n - 1; i1++) {
            for (int i2 = i1 + 1; i2 < n; i2++) {
                // Calculate the centroid of the current possible facet:
                MyPoint2DVector pv = new MyPoint2DVector();
                int ii0 = ibest.get(i0);
                int ii1 = ibest.get(i1);
                int ii2 = ibest.get(i2);
                pv.add(points.get(ii0));
                pv.add(points.get(ii1));
                pv.add(points.get(ii2));
                MyPoint2D centroid = pv.centroid();
                // Calculate the distance to that centroid:
                d = p.distanceToPoint(centroid);
                // Record the closest centroid:
                if (d < dbest) {
                    inode[0] = ii0;
                    inode[1] = ii1;
                    inode[2] = ii2;
                    dbest = d;
                }
            }
        // for i2
        }
    // for i1
    }
    // for i0
    // Create a new facet object:
    // NOT LINKED TO A GROUP YET!
    currentFacet = new Facet();
    // Loop over each of the best three points:
    for (int i = 0; i < 3; i++) {
        // Get the ith closest painted node:
        Node node = nodes.get(inode[i]);
        // // Get the section for the ith node so it can be added to the facet:
        // Section section = node.getSection();
        // Add the node to the current facet:
        currentFacet.addNode(node);
    // // Add the relevant section to the current facet: // no longer necessary
    // currentFacet.addSection(section);
    }
    // Return the facet:
    return currentFacet;
}
Also used : MyPoint2DVector(geometry.MyPoint2DVector) NodeVector(facetmodeller.plc.NodeVector) Node(facetmodeller.plc.Node) MyPoint2D(geometry.MyPoint2D) Facet(facetmodeller.plc.Facet)

Example 3 with MyPoint2DVector

use of geometry.MyPoint2DVector in project facetmodeller by pglelievre.

the class DefineNodesSectionMenuTask method execute.

@Override
public void execute() {
    // Check for the required information:
    if (!check()) {
        return;
    }
    // Define 8 new on-section nodes:
    Section currentSection = controller.getSelectedCurrentSection();
    Group currentGroup = controller.getSelectedCurrentGroup();
    if (currentSection == null) {
        return;
    }
    if (currentGroup == null) {
        return;
    }
    NodeVector nodes = new NodeVector();
    MyPoint2DVector p = currentSection.getCorners();
    if (p == null) {
        return;
    }
    int n = p.size();
    if (n != 4) {
        return;
    }
    for (int i = 0; i < n; i++) {
        // new node is not added to the section or group yet
        nodes.add(new NodeOnSection(p.get(i), currentSection, currentGroup));
    }
    // Add the nodes:
    // adds each node to its section and group
    AddNodeCommandVector com = new AddNodeCommandVector(controller.getModelManager(), nodes, "");
    // adds each node to its section and group
    com.execute();
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    controller.redraw();
}
Also used : Group(facetmodeller.groups.Group) MyPoint2DVector(geometry.MyPoint2DVector) NodeVector(facetmodeller.plc.NodeVector) AddNodeCommandVector(facetmodeller.commands.AddNodeCommandVector) Section(facetmodeller.sections.Section) NodeOnSection(facetmodeller.plc.NodeOnSection) NodeOnSection(facetmodeller.plc.NodeOnSection)

Example 4 with MyPoint2DVector

use of geometry.MyPoint2DVector in project facetmodeller by pglelievre.

the class ImageSection method getCorners.

public MyPoint2DVector getCorners() {
    MyPoint2DVector corners = new MyPoint2DVector();
    int w = getWidth();
    int h = getHeight();
    corners.add(new MyPoint2D(0, 0));
    corners.add(new MyPoint2D(w, 0));
    corners.add(new MyPoint2D(0, h));
    corners.add(new MyPoint2D(w, h));
    return corners;
}
Also used : MyPoint2DVector(geometry.MyPoint2DVector) MyPoint2D(geometry.MyPoint2D)

Example 5 with MyPoint2DVector

use of geometry.MyPoint2DVector in project facetmodeller by pglelievre.

the class NoImageSection method getCorners.

public MyPoint2DVector getCorners() {
    MyPoint2DVector corners = new MyPoint2DVector();
    int w = getWidth();
    int h = getHeight();
    corners.add(new MyPoint2D(0, 0));
    corners.add(new MyPoint2D(w, 0));
    corners.add(new MyPoint2D(0, h));
    corners.add(new MyPoint2D(w, h));
    return corners;
}
Also used : MyPoint2DVector(geometry.MyPoint2DVector) MyPoint2D(geometry.MyPoint2D)

Aggregations

MyPoint2DVector (geometry.MyPoint2DVector)9 MyPoint2D (geometry.MyPoint2D)8 NodeVector (facetmodeller.plc.NodeVector)4 Section (facetmodeller.sections.Section)4 MyPoint3D (geometry.MyPoint3D)3 Facet (facetmodeller.plc.Facet)2 Node (facetmodeller.plc.Node)2 AddNodeCommandVector (facetmodeller.commands.AddNodeCommandVector)1 Group (facetmodeller.groups.Group)1 FacetVector (facetmodeller.plc.FacetVector)1 NodeOnSection (facetmodeller.plc.NodeOnSection)1 RegionVector (facetmodeller.plc.RegionVector)1