Search in sources :

Example 86 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MeshCollisionViewer method main.

public static void main(String[] args) {
    IntHolder width = new IntHolder(640);
    IntHolder height = new IntHolder(480);
    ArgParser parser = new ArgParser("java maspack.geometry.TwoMeshViewer [options] meshFile1 meshFile2");
    parser.addOption("-width %d #width (pixels)", width);
    parser.addOption("-height %d #height (pixels)", height);
    parser.addOption("-drawAxes %v #draw coordinate axes", drawAxes);
    parser.addOption("-drawEdges %v #draw mesh edges", drawEdges);
    parser.addOption("-noDrawFaces %v #do not draw faces", noDrawFaces);
    parser.addOption("-edgeColor %fX3 #edge color", edgeColor);
    parser.addOption("-axisLength %f #coordinate axis length", axisLength);
    parser.addOption("-smooth %v #use smooth shading", smooth);
    parser.addOption("-oneSided %v #draw only front faces", oneSided);
    String[] otherArgs = parser.matchAllArgs(args, 0, 0);
    if (otherArgs == null || otherArgs.length != 2) {
        System.out.println("Usage: " + parser.getSynopsisString());
        System.out.println("Use -help for more info");
        System.exit(1);
    }
    PolygonalMesh mesh1 = null;
    PolygonalMesh mesh2 = null;
    try {
        mesh1 = new PolygonalMesh(new File(otherArgs[0]));
        mesh2 = new PolygonalMesh(new File(otherArgs[1]));
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    MeshCollisionViewer frame = new MeshCollisionViewer(mesh1, mesh2, width.value, height.value);
    frame.setVisible(true);
}
Also used : IntHolder(argparser.IntHolder) ArgParser(argparser.ArgParser) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File)

Example 87 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MeshInfo method printInfo.

public void printInfo(File inputFile) throws IOException {
    MeshBase mesh = getMesh(inputFile);
    if (mesh instanceof PolygonalMesh) {
        PolygonalMesh pmesh = (PolygonalMesh) mesh;
        System.out.println("meshType= " + mesh.getClass());
        System.out.println("numVertices= " + pmesh.numVertices());
        System.out.println("numFaces= " + pmesh.numFaces());
        System.out.println("isClosed= " + pmesh.isClosed());
        System.out.println("isManifold= " + pmesh.isManifold());
        System.out.println("volume= " + pmesh.computeVolume());
        System.out.println("area= " + pmesh.computeArea());
        System.out.println("averageEdgeLength= " + pmesh.computeAverageEdgeLength());
        doPrintBounds(pmesh);
    } else if (mesh != null) {
        System.out.println("meshType= " + mesh.getClass());
        System.out.println("numVertices= " + mesh.numVertices());
        doPrintBounds(mesh);
    }
}
Also used : MeshBase(maspack.geometry.MeshBase) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 88 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MeshMaker method main.

public static void main(String[] args) {
    ArgParser parser = new ArgParser("java maspack.geometry.MeshMaker");
    parser.addOption("-file %s #mesh file name", fileName);
    parser.addOption("-radius %f #radius", radius);
    parser.addOption("-wx %f #x width", wx);
    parser.addOption("-wy %f #y width", wy);
    parser.addOption("-wz %f #z width", wz);
    parser.addOption("-nslices %d #number of slices", nslices);
    args = parser.matchAllArgs(args, 0, ArgParser.EXIT_ON_ERROR);
    PolygonalMesh mesh = null;
    if (args[0].equals("sphere")) {
        mesh = MeshFactory.createQuadSphere(radius.value, nslices.value);
    } else if (args[0].equals("box")) {
        mesh = MeshFactory.createQuadBox(wx.value, wy.value, wz.value);
    } else if (args[0].equals("cylinder")) {
        mesh = MeshFactory.createCylinder(radius.value, wz.value, nslices.value);
    } else if (args[0].equals("roundedCylinder")) {
        mesh = MeshFactory.createQuadRoundedCylinder(radius.value, wz.value, nslices.value, /*nsegs=*/
        1, /*flatBottom=*/
        false);
    } else {
        System.err.println("Unknown mesh type: " + args[0]);
        System.exit(1);
    }
    try {
        mesh.write(new PrintWriter(new BufferedWriter(new FileWriter(fileName.value))), "%10.5f");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : FileWriter(java.io.FileWriter) ArgParser(argparser.ArgParser) PolygonalMesh(maspack.geometry.PolygonalMesh) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 89 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MeshSeparator method main.

public static void main(String[] args) {
    ArgParser parser = new ArgParser("[options] <infileName>");
    // parser.addOption ("-inFile %s #input file name", inFileName);
    parser.addOption("-out %s #base name for output file", outFileName);
    parser.addOption("-format %s #printf-syle format string for vertex output", formatStr);
    int idx = 0;
    while (idx < args.length) {
        try {
            idx = parser.matchArg(args, idx);
            if (parser.getUnmatchedArgument() != null) {
                String fileName = parser.getUnmatchedArgument();
                if (inFileName.value == null) {
                    inFileName.value = fileName;
                } else {
                    System.out.println("Ignoring extra input file " + fileName);
                }
            }
        } catch (Exception e) {
            // malformed or erroneous argument
            parser.printErrorAndExit(e.getMessage());
        }
    }
    if (inFileName.value == null) {
        parser.printErrorAndExit("input file name missing");
    }
    if (outFileName.value == null) {
        int dotIdx = inFileName.value.lastIndexOf('.');
        if (dotIdx == -1) {
            outFileName.value = inFileName.value;
        } else {
            outFileName.value = inFileName.value.substring(0, dotIdx);
        }
    }
    try {
        File meshFile = new File(inFileName.value);
        if (!meshFile.exists()) {
            System.out.println("Error: mesh file " + meshFile.getName() + " not found");
            meshFile = null;
            System.exit(1);
        }
        PolygonalMesh mesh = new PolygonalMesh(meshFile);
        PolygonalMesh[] meshes = mesh.partitionIntoConnectedMeshes();
        if (meshes == null) {
            System.out.println("Mesh " + meshFile + " has no separate components");
            System.exit(0);
        }
        double[] numv = new double[meshes.length];
        int[] idxs = new int[meshes.length];
        for (int i = 0; i < meshes.length; i++) {
            numv[i] = meshes[i].numVertices();
            idxs[i] = i;
        }
        ArraySort.quickSort(numv, idxs);
        for (int i = 0; i < meshes.length; i++) {
            NumberFormat fmt = new NumberFormat("%03d");
            File outFile = new File(outFileName.value + "_" + fmt.format(meshes.length - 1 - i) + ".obj");
            meshes[idxs[i]].write(outFile, formatStr.value);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : ArgParser(argparser.ArgParser) PolygonalMesh(maspack.geometry.PolygonalMesh) NumberFormat(maspack.util.NumberFormat)

Example 90 with PolygonalMesh

use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.

the class MeshThicken method actionPerformed.

public void actionPerformed(ActionEvent evt) {
    String cmd = evt.getActionCommand();
    if (cmd.equals("Load mesh ...")) {
        if (myMeshFile != null) {
            myMeshChooser.setSelectedFile(myMeshFile);
        }
        int retVal = myMeshChooser.showOpenDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = myMeshChooser.getSelectedFile();
            try {
                loadMesh(file, /*vertexSkip=*/
                1);
            } catch (Exception e) {
                showError("Can't load mesh", e);
            }
        }
    } else if (cmd.equals("Save mesh")) {
        saveMesh(myMeshFile);
    } else if (cmd.equals("Save mesh as ...")) {
        if (myMeshFile != null) {
            myMeshChooser.setSelectedFile(myMeshFile);
        }
        int retVal = myMeshChooser.showSaveDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = myMeshChooser.getSelectedFile();
            if (!file.exists() || confirmOverwrite(file)) {
                try {
                    saveMesh(file);
                } catch (Exception e) {
                    showError("Can't save mesh", e);
                }
            }
        }
    } else if (cmd.equals("Clear regions")) {
        clearRegions();
    } else if (cmd.equals("Load regions ...")) {
        if (myRegionFile != null) {
            myRegionChooser.setSelectedFile(myRegionFile);
        }
        int retVal = myRegionChooser.showOpenDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = myRegionChooser.getSelectedFile();
            try {
                loadRegions(file);
            } catch (Exception e) {
                showError("Can't load regions", e);
            }
        }
    } else if (cmd.equals("Save regions")) {
        saveRegions(myRegionFile);
    } else if (cmd.equals("Save regions as ...")) {
        if (myRegionFile != null) {
            myRegionChooser.setSelectedFile(myRegionFile);
        }
        int retVal = myRegionChooser.showSaveDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            File file = myRegionChooser.getSelectedFile();
            if (!file.exists() || confirmOverwrite(file)) {
                try {
                    saveRegions(file);
                } catch (Exception e) {
                    showError("Can't save regions", e);
                }
            }
        }
    } else if (cmd.equals("Grow")) {
        PolygonalMesh pmesh = (PolygonalMesh) myMesh;
        applyGrowth(pmesh, myGrowLength);
    } else if (cmd.equals("Remesh")) {
        PolygonalMesh pmesh = (PolygonalMesh) myMesh;
        applyRemesh(pmesh, myRemeshRes);
    } else if (cmd.equals("Thicken")) {
        for (Region region : myRegions) {
            applyThickening(region, myMesh, region.getThickening());
        }
    } else if (cmd.equals("Unthicken")) {
        for (Region region : myRegions) {
            applyThickening(region, myMesh, -region.getUnthickening());
        }
    } else if (cmd.equals("Reverse thicken")) {
        for (Region region : myRegions) {
            applyThickening(region, myMesh, -region.getThickening());
        }
    } else if (cmd.equals("Reverse unthicken")) {
        for (Region region : myRegions) {
            applyThickening(region, myMesh, region.getUnthickening());
        }
    } else if (cmd.equals("Smooth")) {
        PolygonalMesh pmesh = (PolygonalMesh) myMesh;
        LaplacianSmoother.smooth(pmesh, mySmoothingCount, mySmoothingLambda, mySmoothingMu);
        pmesh.notifyVertexPositionsModified();
        viewer.rerender();
    } else if (cmd.equals("Hide all regions")) {
        for (Region region : myRegions) {
            region.setVisible(false);
        }
        viewer.rerender();
    } else if (cmd.equals("Hide regions")) {
        for (Region region : getSelectedRegions()) {
            region.setVisible(false);
        }
        viewer.rerender();
    } else if (cmd.equals("Show all regions")) {
        for (Region region : myRegions) {
            region.setVisible(true);
        }
        viewer.rerender();
    } else if (cmd.equals("Edit MeshThicken properties ...")) {
        ArrayList<HasProperties> list = new ArrayList<HasProperties>();
        list.add(this);
        PropertyDialog dialog = PropertyDialog.createDialog("MeshThicken properties", list, "OK Cancel", viewer.getCanvas().getComponent(), myRerenderListener);
        if (dialog != null) {
            dialog.setVisible(true);
        }
    } else if (cmd.equals("Edit region properties ...")) {
        PropertyDialog dialog = PropertyDialog.createDialog("Region properties", getSelectedRegions(), "OK Cancel", viewer.getCanvas().getComponent(), myRerenderListener);
        if (dialog != null) {
            dialog.setVisible(true);
        }
    } else if (cmd.equals("Edit mesh render properties ...")) {
        PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(myMesh.getRenderProps())), "Done");
        dialog.locateRight(this);
        dialog.addGlobalValueChangeListener(myRerenderListener);
        dialog.setVisible(true);
    } else if (cmd.equals("Quit")) {
        System.exit(0);
    } else {
        super.actionPerformed(evt);
    }
}
Also used : PropertyDialog(maspack.widgets.PropertyDialog) RenderPropsPanel(maspack.widgets.RenderPropsPanel) ArrayList(java.util.ArrayList) HasProperties(maspack.properties.HasProperties) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh) IOException(java.io.IOException)

Aggregations

PolygonalMesh (maspack.geometry.PolygonalMesh)128 Point3d (maspack.matrix.Point3d)30 Vertex3d (maspack.geometry.Vertex3d)24 Vector3d (maspack.matrix.Vector3d)23 RigidTransform3d (maspack.matrix.RigidTransform3d)21 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 File (java.io.File)14 Face (maspack.geometry.Face)14 ContactPoint (artisynth.core.mechmodels.ContactPoint)11 Point (artisynth.core.mechmodels.Point)11 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)10 Color (java.awt.Color)10 MeshBase (maspack.geometry.MeshBase)10 RigidBody (artisynth.core.mechmodels.RigidBody)9 MechModel (artisynth.core.mechmodels.MechModel)8 BufferedReader (java.io.BufferedReader)8 AxisAngle (maspack.matrix.AxisAngle)8 RenderProps (maspack.render.RenderProps)8 HashMap (java.util.HashMap)7