Search in sources :

Example 1 with NodeVector

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

the class ModelManager method writeSessionInformation.

@Override
public boolean writeSessionInformation(BufferedWriter writer) {
    // Write the number of dimensions, nodes, facets, regions, sections and groups:
    int ndim = numberOfDimensions();
    int nnodes = numberOfNodes();
    int nfacets = numberOfFacets();
    int nregions = numberOfRegions();
    int nsections = numberOfSections();
    int ngroups = numberOfGroups();
    String textLine = ndim + " " + nnodes + " " + nfacets + " " + nregions + " " + nsections + " " + ngroups;
    if (!FileUtils.writeLine(writer, textLine)) {
        return false;
    }
    // Comment start of node definitions:
    if (!FileUtils.writeLine(writer, "# NODES")) {
        return false;
    }
    // Loop over each node:
    for (int i = 0; i < nnodes; i++) {
        Node node = getNode(i);
        // Write node ID, indication of ith node type and boundary marker (the latter is a later addition):
        textLine = node.getID() + " " + node.getType() + " " + node.getBoundaryMarker();
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
        // Write the node information:
        if (!node.writeSessionInformation(writer)) {
            return false;
        }
    }
    // Comment start of region definitions:
    if (!FileUtils.writeLine(writer, "# REGIONS")) {
        return false;
    }
    // Loop over each region:
    for (int i = 0; i < nregions; i++) {
        Region region = getRegion(i);
        // Write the region information information:
        if (!region.writeSessionInformation(writer)) {
            return false;
        }
    }
    // Comment start of section definitions:
    if (!FileUtils.writeLine(writer, "# SECTIONS")) {
        return false;
    }
    // Loop over each section:
    for (int i = 0; i < nsections; i++) {
        Section section = getSection(i);
        // Comment start of ith section definition:
        textLine = "# Section " + section.getID();
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
        // Write indication of the type of section:
        textLine = Integer.toString(section.getType());
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
        // Write the section information:
        if (!section.writeSessionInformation(writer)) {
            return false;
        }
    }
    // Comment start of group definitions:
    if (!FileUtils.writeLine(writer, "# GROUPS")) {
        return false;
    }
    // Loop over each group:
    for (int i = 0; i < ngroups; i++) {
        Group group = getGroup(i);
        // Write the group information:
        if (!group.writeSessionInformation(writer)) {
            return false;
        }
    }
    // Comment start of node linkages:
    if (!FileUtils.writeLine(writer, "# NODE LINKS")) {
        return false;
    }
    // Loop over each node:
    for (int i = 0; i < nnodes; i++) {
        Node node = getNode(i);
        // FacetVector facets = node.getFacets();
        /* I don't need to write the facet id's here because
             * the same information is written below in the loop over each facet. */
        // Write the section id and group id:
        textLine = node.getSection().getID() + " " + node.getGroup().getID();
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
    }
    // Comment start of node linkages:
    if (!FileUtils.writeLine(writer, "# FACET LINKS")) {
        return false;
    }
    // Loop over each facet:
    for (int i = 0; i < nfacets; i++) {
        Facet facet = getFacet(i);
        NodeVector nodes = facet.getNodes();
        SectionVector facetSections = facet.getSections();
        // Write the node id's:
        int n = nodes.size();
        textLine = Integer.toString(n);
        for (int j = 0; j < n; j++) {
            textLine = textLine + " " + nodes.get(j).getID();
        }
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
        // Write the section id's:
        n = facetSections.size();
        textLine = Integer.toString(n);
        for (int j = 0; j < n; j++) {
            textLine = textLine + " " + facetSections.get(j).getID();
        }
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
        // Write the group id and boundary marker (the latter is a later addition):
        textLine = facet.getGroup().getID() + " " + facet.getBoundaryMarker();
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
    }
    // Comment start of node linkages:
    if (!FileUtils.writeLine(writer, "# REGION LINKS")) {
        return false;
    }
    // Loop over each region:
    for (int i = 0; i < nregions; i++) {
        Region region = getRegion(i);
        // Write the section id:
        textLine = Integer.toString(region.getSection().getID());
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
        // Write the group id:
        textLine = Integer.toString(region.getGroup().getID());
        if (!FileUtils.writeLine(writer, textLine)) {
            return false;
        }
    }
    // Comment start of VOI information:
    if (!FileUtils.writeLine(writer, "# VOI")) {
        return false;
    }
    // Write the VOI:
    if (hasVOI()) {
        if (!getVOI().writeSessionInformation(writer)) {
            return false;
        }
    } else {
        if (!FileUtils.writeLine(writer, "null")) {
            return false;
        }
    }
    // Return true:
    return true;
}
Also used : Group(facetmodeller.groups.Group) SectionVector(facetmodeller.sections.SectionVector) NodeVector(facetmodeller.plc.NodeVector) Node(facetmodeller.plc.Node) Region(facetmodeller.plc.Region) NoImageCrossSection(facetmodeller.sections.NoImageCrossSection) NodeOffSection(facetmodeller.plc.NodeOffSection) NoImageDepthSection(facetmodeller.sections.NoImageDepthSection) Section(facetmodeller.sections.Section) ImageCrossSection(facetmodeller.sections.ImageCrossSection) SnapshotSection(facetmodeller.sections.SnapshotSection) NodeOnSection(facetmodeller.plc.NodeOnSection) ImageDepthSection(facetmodeller.sections.ImageDepthSection) Facet(facetmodeller.plc.Facet)

Example 2 with NodeVector

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

the class FlipEdgeClickTask method mouseClick.

@Override
public void mouseClick(MyPoint2D p) {
    // Check for the required information:
    if (!check()) {
        return;
    }
    if (p == null) {
        return;
    }
    // Calculate the closest node to the clicked point:
    if (!controller.calculateClosestNode(p)) {
        return;
    }
    Node node2 = controller.getClosestNode();
    // Check if we need to start, continue or stop the edge flipping operation:
    Node currentNode = controller.getCurrentNode();
    if (currentNode == null) {
        // need to start fresh
        controller.setCurrentNode(node2);
    } else {
        // first node was already selected
        // Find the triangular facets containing the edge (triangular facets that contain the two selected nodes):
        // will hold the triangular facets containing the edge
        FacetVector edgeFacets = new FacetVector();
        // will hold the 4 nodes
        NodeVector nodes = new NodeVector();
        nodes.add(currentNode);
        nodes.add(node2);
        // the facets for the first node
        FacetVector facets1 = currentNode.getFacets();
        for (int i1 = 0; i1 < facets1.size(); i1++) {
            // loop over each facet for the first node
            Facet f1 = facets1.get(i1);
            // Skip non-triangular facets:
            if (f1.size() != 3) {
                continue;
            }
            // Check if the facet contains the second node:
            if (f1.containsNode(node2)) {
                // Add the facet to the list:
                edgeFacets.add(f1);
            }
        }
        // Nullify the temporary object before any dialogs can launch:
        controller.clearCurrentNode();
        // Check that the two nodes define an edge:
        if (edgeFacets.isEmpty()) {
            Dialogs.error(controller, "Those nodes don't define an edge.", title());
            return;
        }
        // Check for a boundary edge:
        if (edgeFacets.size() == 1) {
            Dialogs.error(controller, "Boundary edges can not be flipped.", title());
            return;
        }
        // Check for a triple point:
        if (edgeFacets.size() != 2) {
            Dialogs.error(controller, "Triple point edges can not be flipped.", title());
            return;
        }
        // TODO: check for a convex situation
        // Determine the two other nodes to use:
        // duplicates are not added in this call
        nodes.addAll(edgeFacets.get(0).getNodes());
        // duplicates are not added in this call
        nodes.addAll(edgeFacets.get(1).getNodes());
        // Check I did it correctly:
        if (nodes.size() != 4) {
            Dialogs.error(controller, "That edge can not be flipped.", title());
            return;
        }
        // Figure out which group to use:
        Group group = edgeFacets.get(0).getGroup();
        if (edgeFacets.get(1).getGroup() != group) {
            // the two facets belong to different groups
            group = controller.getSelectedCurrentGroup();
        }
        // Define two new facets:
        Facet newFacet1 = new Facet(group);
        newFacet1.addNode(nodes.get(0));
        newFacet1.addNode(nodes.get(2));
        newFacet1.addNode(nodes.get(3));
        Facet newFacet2 = new Facet(group);
        newFacet2.addNode(nodes.get(1));
        newFacet2.addNode(nodes.get(2));
        newFacet2.addNode(nodes.get(3));
        FacetVector newFacets = new FacetVector();
        newFacets.add(newFacet1);
        newFacets.add(newFacet2);
        // Perform the edge flip (add the new facets, delete the existing facets):
        FlipEdgeCommand com = new FlipEdgeCommand(controller.getModelManager(), edgeFacets, newFacets);
        com.execute();
        controller.undoVectorAdd(com);
    }
    // Repaint:
    controller.redraw();
}
Also used : Group(facetmodeller.groups.Group) NodeVector(facetmodeller.plc.NodeVector) FacetVector(facetmodeller.plc.FacetVector) Node(facetmodeller.plc.Node) FlipEdgeCommand(facetmodeller.commands.FlipEdgeCommand) Facet(facetmodeller.plc.Facet)

Example 3 with NodeVector

use of facetmodeller.plc.NodeVector 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 4 with NodeVector

use of facetmodeller.plc.NodeVector 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 5 with NodeVector

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

the class SectionVector method removeNodesRange.

public NodeVector removeNodesRange() {
    // Loop over each section:
    NodeVector nodesToRemove = new NodeVector();
    for (int i = 0; i < size(); i++) {
        // Get the ith section:
        Section section = get(i);
        // Skip topography sections, or others where deleting nodes outside the calibration points is not allowed:
        if (!section.canDeleteNodesRange()) {
            continue;
        }
        // Process the section:
        nodesToRemove = section.removeNodesRange(nodesToRemove);
    }
    return nodesToRemove;
}
Also used : NodeVector(facetmodeller.plc.NodeVector)

Aggregations

NodeVector (facetmodeller.plc.NodeVector)29 Node (facetmodeller.plc.Node)14 Group (facetmodeller.groups.Group)11 Facet (facetmodeller.plc.Facet)9 FacetVector (facetmodeller.plc.FacetVector)9 Section (facetmodeller.sections.Section)9 MyPoint2D (geometry.MyPoint2D)7 MyPoint3D (geometry.MyPoint3D)6 AddNodeCommandVector (facetmodeller.commands.AddNodeCommandVector)5 GroupVector (facetmodeller.groups.GroupVector)5 ModelManager (facetmodeller.ModelManager)4 ChangeNodeGroupCommandVector (facetmodeller.commands.ChangeNodeGroupCommandVector)4 SectionVector (facetmodeller.sections.SectionVector)4 SnapshotSection (facetmodeller.sections.SnapshotSection)4 MyPoint2DVector (geometry.MyPoint2DVector)4 NodeOnSection (facetmodeller.plc.NodeOnSection)3 Region (facetmodeller.plc.Region)3 File (java.io.File)3 AddFacetCommandVector (facetmodeller.commands.AddFacetCommandVector)2 RemoveNodeCommandVector (facetmodeller.commands.RemoveNodeCommandVector)2