Search in sources :

Example 1 with MyPoint3D

use of geometry.MyPoint3D in project facetmodeller by pglelievre.

the class SessionLoader method loadSessionAscii2.

private static boolean loadSessionAscii2(FacetModeller controller, File file, boolean merge) {
    int loadVersion = 2;
    // We will be constructing some new objects as we read the file:
    PLC plc = new PLC();
    SectionVector sections = new SectionVector();
    GroupVector groups = new GroupVector();
    // We will be saving some information to set later:
    int ndim;
    // these colours will be overwritten
    Color calibrationColor = Color.CYAN;
    Color edgeColor = Color.BLACK;
    Color defineFacetEdgeColor = Color.WHITE;
    int pointWidth = 5;
    int lineWidth = 1;
    // Open the file for reading:
    BufferedReader reader = FileUtils.openForReading(file);
    if (reader == null) {
        return false;
    }
    // Put everything below in an infinite loop that we can break out of when something goes wrong:
    boolean ok = true;
    while (true) {
        // Read the floored version number:
        String textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        textLine = textLine.trim();
        String[] ss = textLine.split("[ ]+", 2);
        int version;
        try {
            // converts to integer
            version = Integer.parseInt(ss[0].trim());
        } catch (NumberFormatException e) {
            ok = false;
            break;
        }
        if (!ok) {
            break;
        }
        // Check the version number:
        if (version != loadVersion) {
            // Close the file:
            FileUtils.close(reader);
            // Return unsuccessfully:
            return false;
        }
        // Read the number of dimensions, nodes, facets, regions, samples and groups:
        textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        int nnodes, nregions, nfacets, nsections, ngroups;
        textLine = textLine.trim();
        ss = textLine.split("[ ]+", 7);
        try {
            // converts to integer
            ndim = Integer.parseInt(ss[0].trim());
            // converts to integer
            nnodes = Integer.parseInt(ss[1].trim());
            // converts to integer
            nfacets = Integer.parseInt(ss[2].trim());
            // converts to integer
            nregions = Integer.parseInt(ss[3].trim());
            // converts to integer
            nsections = Integer.parseInt(ss[4].trim());
            // converts to integer
            ngroups = Integer.parseInt(ss[5].trim());
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
            ok = false;
            break;
        }
        if (!ok) {
            break;
        }
        // Check ndim:
        if (ndim != controller.numberOfDimensions()) {
            ok = false;
            break;
        }
        // Loop over each node:
        for (int i = 0; i < nnodes; i++) {
            // Read the coordinates of the ith node:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            boolean isTopo;
            // initialization of z is needed to avoid compiler warning
            double x, y, z = 0.0;
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 4);
            try {
                isTopo = Boolean.parseBoolean(ss[0].trim());
                // converts to Double
                x = Double.parseDouble(ss[1].trim());
                // converts to Double
                y = Double.parseDouble(ss[2].trim());
                if (isTopo) {
                    z = Double.parseDouble(ss[3].trim());
                }
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                ok = false;
                break;
            }
            if (!ok) {
                break;
            }
            // Add a new node to the plc:
            if (isTopo) {
                plc.addNode(new NodeOffSection(x, y, z));
            } else {
                plc.addNode(new NodeOnSection(x, y));
            }
        // section and group membership will be added later
        }
        if (!ok) {
            break;
        }
        // Loop over each facet:
        for (int i = 0; i < nfacets; i++) {
            // Add a new empty facet to the plc (these facets are filled later):
            plc.addFacet(new Facet());
        }
        // Loop over each region:
        for (int i = 0; i < nregions; i++) {
            // Read the coordinates of the ith region and the isControl information:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            double x, y;
            boolean isCon;
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 4);
            // Try parsing coordinates (must be able to do this):
            try {
                // converts to Double
                x = Double.parseDouble(ss[0].trim());
                // converts to Double
                y = Double.parseDouble(ss[1].trim());
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                ok = false;
                break;
            }
            if (!ok) {
                break;
            }
            // Check for iscontrol information:
            if (ss.length < 3) {
                isCon = false;
            } else {
                if (ss[2].trim().isEmpty()) {
                    // missing from file (old version of session saver was used)
                    isCon = false;
                } else {
                    // converts to Boolean
                    isCon = Boolean.parseBoolean(ss[2].trim());
                }
            }
            // Add a new region to the plc:
            // section and group membership will be added later
            plc.addRegion(new Region(isCon, x, y));
        }
        if (!ok) {
            break;
        }
        for (int i = 0; i < nsections; i++) {
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            int sectionType;
            try {
                sectionType = Integer.parseInt(textLine);
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            if (!ok) {
                break;
            }
            Section section = null;
            switch(sectionType) {
                case 1:
                    // Read the file name:
                    textLine = FileUtils.readLine(reader);
                    if (textLine == null) {
                        ok = false;
                        break;
                    }
                    textLine = textLine.trim();
                    File imageFile;
                    if (textLine.startsWith("null")) {
                        imageFile = null;
                    } else {
                        try {
                            URI uri = new URI(textLine);
                            // image file or .node file
                            imageFile = new File(uri);
                        } catch (URISyntaxException e) {
                            ok = false;
                            break;
                        }
                    }
                    // Make a new HasImage object associated with the file:
                    section = new ImageCrossSection(imageFile);
                    break;
                case 3:
                    // Read the section name:
                    textLine = FileUtils.readLine(reader);
                    if (textLine == null) {
                        ok = false;
                        break;
                    }
                    String name = textLine.trim();
                    // Read the image height:
                    textLine = FileUtils.readLine(reader);
                    if (textLine == null) {
                        ok = false;
                        break;
                    }
                    textLine = textLine.trim();
                    int height;
                    try {
                        height = Integer.parseInt(textLine);
                    } catch (NumberFormatException e) {
                        ok = false;
                        break;
                    }
                    // Read the image color:
                    Color color;
                    try {
                        // parse from RGB string
                        color = new Color(Integer.parseInt(textLine.trim()));
                    } catch (NumberFormatException e) {
                        ok = false;
                        break;
                    }
                    section = new NoImageCrossSection(name, color);
                    break;
                case 2:
                    File nodeFile = null;
                    File eleFile = null;
                    // Read the node file name:
                    textLine = FileUtils.readLine(reader);
                    if (textLine == null) {
                        ok = false;
                        break;
                    }
                    textLine = textLine.trim();
                    if (textLine.startsWith("null")) {
                        nodeFile = null;
                    } else {
                        URI uri = null;
                        try {
                            uri = new URI(textLine);
                        } catch (URISyntaxException e) {
                            ok = false;
                        }
                        if (!ok) {
                            break;
                        }
                        try {
                            // image file or .node file
                            nodeFile = new File(uri);
                        } catch (IllegalArgumentException e) {
                            ok = false;
                        }
                    }
                    if (!ok) {
                        break;
                    }
                    // Read the ele file name:
                    textLine = FileUtils.readLine(reader);
                    if (textLine == null) {
                        ok = false;
                        break;
                    }
                    textLine = textLine.trim();
                    if (textLine.startsWith("null")) {
                        eleFile = null;
                    } else {
                        try {
                            URI uri = new URI(textLine);
                            // image file or .node file
                            eleFile = new File(uri);
                        } catch (URISyntaxException e) {
                            ok = false;
                        }
                    }
                    if (!ok) {
                        break;
                    }
                    // formerly a TopoSection
                    section = new NoImageDepthSection(nodeFile, eleFile);
                    break;
                default:
                    ok = false;
                    break;
            }
            if (!ok) {
                break;
            }
            if (section == null) {
                ok = false;
                break;
            }
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 2);
            Dir3D sliceDirection;
            try {
                // converts to integer
                int idir = Integer.parseInt(ss[0].trim());
                sliceDirection = Dir3D.fromInt(idir);
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            if (!ok) {
                break;
            }
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 2);
            double loc;
            try {
                // converts to Double
                loc = Double.parseDouble(ss[0].trim());
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            if (!ok) {
                break;
            }
            double x, y;
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            if (!textLine.startsWith("null")) {
                ss = textLine.split("[ ]+", 3);
                try {
                    // converts to Double
                    x = Double.parseDouble(ss[0].trim());
                    // converts to Double
                    y = Double.parseDouble(ss[1].trim());
                } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                    ok = false;
                    break;
                }
                if (!ok) {
                    break;
                }
                section.setTyped1(new MyPoint3D(x, y, sliceDirection, loc));
            }
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            if (!textLine.startsWith("null")) {
                ss = textLine.split("[ ]+", 3);
                try {
                    // converts to Double
                    x = Double.parseDouble(ss[0].trim());
                    // converts to Double
                    y = Double.parseDouble(ss[1].trim());
                } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                    ok = false;
                    break;
                }
                if (!ok) {
                    break;
                }
                section.setTyped2(new MyPoint3D(x, y, sliceDirection, loc));
            }
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            if (!textLine.startsWith("null")) {
                ss = textLine.split("[ ]+", 3);
                try {
                    // converts to Double
                    x = Double.parseDouble(ss[0].trim());
                    // converts to Double
                    y = Double.parseDouble(ss[1].trim());
                } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                    ok = false;
                    break;
                }
                if (!ok) {
                    break;
                }
                section.setClicked1(new MyPoint2D(x, y));
            }
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            if (!textLine.startsWith("null")) {
                ss = textLine.split("[ ]+", 3);
                try {
                    // converts to Double
                    x = Double.parseDouble(ss[0].trim());
                    // converts to Double
                    y = Double.parseDouble(ss[1].trim());
                } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                    ok = false;
                    break;
                }
                if (!ok) {
                    break;
                }
                section.setClicked2(new MyPoint2D(x, y));
            }
            sections.add(section);
        }
        if (!ok) {
            break;
        }
        // Loop over each group:
        for (int i = 0; i < ngroups; i++) {
            // Create the group object:
            Group group = new Group();
            // Read the group name:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            group.setName(textLine.trim());
            // Read the group colours:
            Color col;
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            try {
                // parse from RGB string
                col = new Color(Integer.parseInt(textLine.trim()));
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            group.setNodeColor(col);
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            try {
                // parse from RGB string
                col = new Color(Integer.parseInt(textLine.trim()));
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            group.setFacetColor(col);
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            try {
                // parse from RGB string
                col = new Color(Integer.parseInt(textLine.trim()));
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            group.setRegionColor(col);
            // Add the group to the list of groups:
            groups.add(group);
        }
        if (!ok) {
            break;
        }
        // Loop over each node:
        for (int i = 0; i < nnodes; i++) {
            Node node = plc.getNode(i);
            // The node gets linked to the facets in the loop over each facet below.
            // Read the section id and group id:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 3);
            // section and group id
            int sid, gid;
            try {
                // converts to integer
                sid = Integer.parseInt(ss[0].trim());
                // converts to integer
                gid = Integer.parseInt(ss[1].trim());
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                ok = false;
                break;
            }
            // Cross-link the node and section:
            node.setSection(sections.get(sid));
            sections.get(sid).addNode(node);
            // Cross-link the node and group:
            node.setGroup(groups.get(gid));
            groups.get(gid).addNode(node);
        }
        if (!ok) {
            break;
        }
        // Loop over each facet:
        for (int i = 0; i < nfacets; i++) {
            Facet facet = plc.getFacet(i);
            // Read the node id's and link those nodes to the facet:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+");
            // number of nodes
            int n;
            try {
                // converts to integer
                n = Integer.parseInt(ss[0].trim());
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            if (!ok) {
                break;
            }
            for (int j = 0; j < n; j++) {
                // node id
                int id;
                try {
                    // converts to integer
                    id = Integer.parseInt(ss[j + 1].trim());
                } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                    ok = false;
                    break;
                }
                // Cross-link the facet and node:
                facet.addNode(plc.getNode(id));
                plc.getNode(id).addFacet(facet);
            }
            // Read the section id's:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            /*
                textLine = textLine.trim();
                ss = textLine.split("[ ]+");
                try {
                    n = Integer.parseInt(ss[0].trim()); // converts to integer
                } catch (NumberFormatException e) { ok=false; break; }
                if (!ok) { break; }
                for (int j=0 ; j<n ; j++ ) {
                    int id;
                    try {
                        id = Integer.parseInt(ss[j+1].trim()); // converts to integer
                    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { ok=false; break; }
                    // Cross-link the facet and section:
//                    facet.addSection( sections.get(id) ); // no longer necessary because facet sections defined by the facet nodes
                    sections.get(id).addFacet(facet);
                }
                */
            // Read the group id:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 2);
            int id;
            try {
                // converts to integer
                id = Integer.parseInt(ss[0].trim());
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            // Cross-link the facet and group:
            facet.setGroup(groups.get(id));
            groups.get(id).addFacet(facet);
        }
        if (!ok) {
            break;
        }
        // Loop over each region:
        for (int i = 0; i < nregions; i++) {
            Region region = plc.getRegion(i);
            // Read the section id:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 2);
            int id;
            try {
                // converts to integer
                id = Integer.parseInt(ss[0].trim());
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            // Cross-link the region and section:
            region.setSection(sections.get(id));
            sections.get(id).addRegion(region);
            // Read the group id and link that group to the node:
            textLine = FileUtils.readLine(reader);
            if (textLine == null) {
                ok = false;
                break;
            }
            textLine = textLine.trim();
            ss = textLine.split("[ ]+", 2);
            try {
                // converts to integer
                id = Integer.parseInt(ss[0].trim());
            } catch (NumberFormatException e) {
                ok = false;
                break;
            }
            // Cross-link the region and group:
            region.setGroup(groups.get(id));
            // groups.get(id).setRegion(region);
            groups.get(id).addRegion(region);
        }
        if (!ok) {
            break;
        }
        // ---------- Finish with the rest of the information: ----------
        // Read painting colours, etc.:
        textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        try {
            // parse from RGB string
            calibrationColor = new Color(Integer.parseInt(textLine.trim()));
        } catch (NumberFormatException e) {
            ok = false;
            break;
        }
        textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        try {
            // parse from RGB string
            edgeColor = new Color(Integer.parseInt(textLine.trim()));
        } catch (NumberFormatException e) {
            ok = false;
            break;
        }
        textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        try {
            // parse from RGB string
            defineFacetEdgeColor = new Color(Integer.parseInt(textLine.trim()));
        } catch (NumberFormatException e) {
            ok = false;
            break;
        }
        textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        try {
            pointWidth = Integer.parseInt(textLine.trim());
        } catch (NumberFormatException e) {
            ok = false;
            break;
        }
        textLine = FileUtils.readLine(reader);
        if (textLine == null) {
            ok = false;
            break;
        }
        try {
            lineWidth = Integer.parseInt(textLine.trim());
        } catch (NumberFormatException e) {
            ok = false;
            break;
        }
        // Always break from while here:
        break;
    }
    // Close the file:
    FileUtils.close(reader);
    // Check for a problem:
    if (!ok) {
        return false;
    }
    // Reset the FacetModeller plc, section lists and group lists:
    controller.resetPLC(plc, merge);
    controller.resetSectionVector(sections, merge);
    controller.resetGroupVector(groups, merge);
    // If it is a large model then don't display anything:
    if (plc.numberOfNodes() >= LARGE_MODEL) {
        controller.clearGroupSelections();
    }
    // Reset some other information:
    if (!merge) {
        controller.setCalibrationColor(calibrationColor);
        controller.setEdgeColor(edgeColor);
        controller.setDefineFacetEdgeColor(defineFacetEdgeColor);
        controller.setPointWidth(pointWidth);
        controller.setLineWidth(lineWidth);
    }
    // Return successfully:
    return true;
}
Also used : SectionVector(facetmodeller.sections.SectionVector) Group(facetmodeller.groups.Group) NoImageDepthSection(facetmodeller.sections.NoImageDepthSection) PLC(facetmodeller.plc.PLC) Node(facetmodeller.plc.Node) URISyntaxException(java.net.URISyntaxException) NodeOnSection(facetmodeller.plc.NodeOnSection) URI(java.net.URI) MyPoint3D(geometry.MyPoint3D) NoImageCrossSection(facetmodeller.sections.NoImageCrossSection) Facet(facetmodeller.plc.Facet) Color(java.awt.Color) NodeOffSection(facetmodeller.plc.NodeOffSection) Section(facetmodeller.sections.Section) NoImageCrossSection(facetmodeller.sections.NoImageCrossSection) ImageCrossSection(facetmodeller.sections.ImageCrossSection) NodeOffSection(facetmodeller.plc.NodeOffSection) NodeOnSection(facetmodeller.plc.NodeOnSection) NoImageDepthSection(facetmodeller.sections.NoImageDepthSection) MyPoint2D(geometry.MyPoint2D) Dir3D(geometry.Dir3D) GroupVector(facetmodeller.groups.GroupVector) NoImageCrossSection(facetmodeller.sections.NoImageCrossSection) ImageCrossSection(facetmodeller.sections.ImageCrossSection) BufferedReader(java.io.BufferedReader) Region(facetmodeller.plc.Region) File(java.io.File)

Example 2 with MyPoint3D

use of geometry.MyPoint3D in project facetmodeller by pglelievre.

the class VOI method getCorners.

public MyPoint3D[] getCorners() {
    // Corners will be placed into an array:
    MyPoint3D[] corners = new MyPoint3D[8];
    corners[0] = new MyPoint3D(x1, y1, z1);
    corners[1] = new MyPoint3D(x2, y1, z1);
    corners[2] = new MyPoint3D(x1, y2, z1);
    corners[3] = new MyPoint3D(x2, y2, z1);
    corners[4] = new MyPoint3D(x1, y1, z2);
    corners[5] = new MyPoint3D(x2, y1, z2);
    corners[6] = new MyPoint3D(x1, y2, z2);
    corners[7] = new MyPoint3D(x2, y2, z2);
    // Return the corners:
    return corners;
}
Also used : MyPoint3D(geometry.MyPoint3D)

Example 3 with MyPoint3D

use of geometry.MyPoint3D in project facetmodeller by pglelievre.

the class VOI method getEdges.

public MyPoint3D[][] getEdges() {
    // Edges will be placed into an array:
    MyPoint3D[][] edges = new MyPoint3D[N_EDGES][2];
    // Edges in x direction:
    edges[0][0] = new MyPoint3D(x1, y1, z1);
    edges[0][1] = new MyPoint3D(x2, y1, z1);
    edges[1][0] = new MyPoint3D(x1, y2, z1);
    edges[1][1] = new MyPoint3D(x2, y2, z1);
    edges[2][0] = new MyPoint3D(x1, y1, z2);
    edges[2][1] = new MyPoint3D(x2, y1, z2);
    edges[3][0] = new MyPoint3D(x1, y2, z2);
    edges[3][1] = new MyPoint3D(x2, y2, z2);
    // Edges in y direction:
    edges[4][0] = new MyPoint3D(x1, y1, z1);
    edges[4][1] = new MyPoint3D(x1, y2, z1);
    edges[5][0] = new MyPoint3D(x1, y1, z2);
    edges[5][1] = new MyPoint3D(x1, y2, z2);
    edges[6][0] = new MyPoint3D(x2, y1, z1);
    edges[6][1] = new MyPoint3D(x2, y2, z1);
    edges[7][0] = new MyPoint3D(x2, y1, z2);
    edges[7][1] = new MyPoint3D(x2, y2, z2);
    // Edges in z direction:
    edges[8][0] = new MyPoint3D(x1, y1, z1);
    edges[8][1] = new MyPoint3D(x1, y1, z2);
    edges[9][0] = new MyPoint3D(x2, y1, z1);
    edges[9][1] = new MyPoint3D(x2, y1, z2);
    edges[10][0] = new MyPoint3D(x1, y2, z1);
    edges[10][1] = new MyPoint3D(x1, y2, z2);
    edges[11][0] = new MyPoint3D(x2, y2, z1);
    edges[11][1] = new MyPoint3D(x2, y2, z2);
    // Return the edges:
    return edges;
}
Also used : MyPoint3D(geometry.MyPoint3D)

Example 4 with MyPoint3D

use of geometry.MyPoint3D in project facetmodeller by pglelievre.

the class ChangeNodeSectionClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Get the current section:
    Section currentSection = controller.getSelectedCurrentSection();
    // Calculate the closest node to the clicked point:
    if (!controller.calculateClosestNode(p)) {
        return;
    }
    // just in case the closestNode object gets nullified by a mouse move (not sure if that is possible but better safe than sorry)
    Node node = controller.getClosestNode();
    if (node == null) {
        return;
    }
    // Check if the node is already a 3D node in the current section:
    if (node.getSection() == currentSection && node.isOff()) {
        return;
    }
    // Nullify temporary objects:
    // (or else the old closest node point will be painted)
    controller.clearClosestNode();
    // Check if node is on or off section (it will be changed to off section regardless):
    if (!node.isOff()) {
        // Ask user for confirmation and calculate 3D point:
        int response = Dialogs.confirm(controller, "The node will be changed to a 3D off-section node.", title());
        if (response != Dialogs.OK_OPTION) {
            return;
        }
    }
    MyPoint3D p3 = node.getPoint3D();
    if (p3 == null) {
        return;
    }
    p3 = p3.deepCopy();
    // Create a new off-section node object:
    Node newNode = new NodeOffSection(p3, currentSection, node.getGroup());
    // Replace the old node with the new node:
    MergeNodesCommand com = new MergeNodesCommand(controller.getModelManager(), node, newNode, title());
    com.execute();
    controller.undoVectorAdd(com);
    // Enable or disable menu items:
    controller.checkItemsEnabled();
    // Repaint:
    controller.redraw();
}
Also used : MergeNodesCommand(facetmodeller.commands.MergeNodesCommand) Node(facetmodeller.plc.Node) NodeOffSection(facetmodeller.plc.NodeOffSection) Section(facetmodeller.sections.Section) NodeOffSection(facetmodeller.plc.NodeOffSection) MyPoint3D(geometry.MyPoint3D)

Example 5 with MyPoint3D

use of geometry.MyPoint3D in project facetmodeller by pglelievre.

the class DepthSection method imageToSpace.

/**
 * Transforms from section image pixel coordinates to real-space measurements for a topography slice
 * (horizontal depth-slice, assumed to be in map view with North up, East right).
 * @param p2
 * @return
 */
@Override
public MyPoint3D imageToSpace(MyPoint2D p2) {
    // Check input and calibration:
    if (p2 == null) {
        return null;
    }
    if (!isCalibrated()) {
        return null;
    }
    // Calculate some quantities required for interpolation:
    MyPoint2D v2 = getClicked1().vectorToPoint(getClicked2());
    MyPoint3D v3 = getTyped1().vectorToPoint(getTyped2());
    // x and y vary linearly with horizontal and vertical pixel coordinates respectively:
    double mx = v3.getX() / v2.getX();
    double my = v3.getY() / v2.getY();
    double x = getTyped1().getX() + mx * (p2.getX() - getClicked1().getX());
    double y = getTyped1().getY() + my * (p2.getY() - getClicked1().getY());
    // z is constant across a depth slice:
    double z = getTyped1().getZ();
    // Return a new MyPoint3D object:
    return new MyPoint3D(x, y, z);
}
Also used : MyPoint2D(geometry.MyPoint2D) MyPoint3D(geometry.MyPoint3D)

Aggregations

MyPoint3D (geometry.MyPoint3D)71 MyPoint2D (geometry.MyPoint2D)23 Section (facetmodeller.sections.Section)14 Node (facetmodeller.plc.Node)13 Group (facetmodeller.groups.Group)9 NodeOffSection (facetmodeller.plc.NodeOffSection)9 Facet (facetmodeller.plc.Facet)6 NodeOnSection (facetmodeller.plc.NodeOnSection)6 NodeVector (facetmodeller.plc.NodeVector)6 Color (java.awt.Color)6 FacetVector (facetmodeller.plc.FacetVector)5 CommandVector (facetmodeller.commands.CommandVector)4 MoveNodeCommand (facetmodeller.commands.MoveNodeCommand)4 GroupVector (facetmodeller.groups.GroupVector)4 AddNodeCommand (facetmodeller.commands.AddNodeCommand)3 SceneInfo (facetmodeller.gui.SceneInfo)3 Region (facetmodeller.plc.Region)3 SectionVector (facetmodeller.sections.SectionVector)3 Dir3D (geometry.Dir3D)3 Matrix3D (geometry.Matrix3D)3