Search in sources :

Example 1 with PointMesh

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

the class MeshMerger method main.

public static void main(String[] args) {
    ArgParser parser = new ArgParser("[options] <infileNames> ...");
    // parser.addOption ("-inFile %s #input file name", inFileName);
    parser.addOption("-out %s #name for output file", outFileName);
    parser.addOption("-pointMesh %v #meshes are assumed to be point meshes", pointMesh);
    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) {
                inFileNames.add(parser.getUnmatchedArgument());
            }
        } catch (Exception e) {
            // malformed or erroneous argument
            parser.printErrorAndExit(e.getMessage());
        }
    }
    if (inFileNames.size() == 0) {
        parser.printErrorAndExit("input file name(s) missing");
    }
    if (outFileName.value == null) {
        parser.printErrorAndExit("out file name missing");
    }
    try {
        MeshBase mesh = null;
        if (pointMesh.value) {
            mesh = new PointMesh();
        } else {
            mesh = new PolygonalMesh();
        }
        for (int i = 0; i < inFileNames.size(); i++) {
            File file = new File(inFileNames.get(i));
            if (!file.canRead()) {
                System.out.println("Warning: mesh file " + file.getName() + " not found or not reeadable");
            } else {
                if (pointMesh.value) {
                    PointMesh m = (PointMesh) GenericMeshReader.readMesh(file, new PointMesh());
                    ((PointMesh) mesh).addMesh(m);
                } else {
                    PolygonalMesh m = new PolygonalMesh(file);
                    ((PolygonalMesh) mesh).addMesh(m);
                }
            }
        }
        if (pointMesh.value) {
            GenericMeshWriter.writeMesh(new File(outFileName.value), mesh);
        } else {
            ((PolygonalMesh) mesh).write(new File(outFileName.value), formatStr.value);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : PointMesh(maspack.geometry.PointMesh) MeshBase(maspack.geometry.MeshBase) ArgParser(argparser.ArgParser) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 2 with PointMesh

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

the class MeshViewer method loadMeshes.

public static void loadMeshes(ArrayList<MeshInfo> infoList, String fileName, AffineTransform3dBase X) {
    try {
        File meshFile = new File(fileName);
        if (!meshFile.exists()) {
            System.out.println("Error: mesh file " + meshFile.getName() + " not found");
            return;
        }
        if (meshFile.getName().endsWith(".obj") && !pointMesh.value) {
            Class meshClass = Class.forName(className.value);
            Class meshBaseClass = new PolygonalMesh().getClass();
            if (meshClass == null) {
                System.out.println("can't find class " + className.value);
                return;
            }
            if (!meshBaseClass.isAssignableFrom(meshClass)) {
                System.out.println(className.value + " is not an instance of " + meshBaseClass.getName());
                return;
            }
            WavefrontReader reader = new WavefrontReader(meshFile);
            reader.parse();
            String[] names = reader.getPolyhedralGroupNames();
            for (int i = 0; i < names.length; i++) {
                if (meshClass == PolygonalMesh.class) {
                    PolygonalMesh mesh = (PolygonalMesh) meshClass.newInstance();
                    reader.setMesh(mesh, names[i]);
                    if (printBounds.value) {
                        doPrintBounds(mesh);
                    }
                    if (mesh.numVertices() > 0) {
                        System.out.print("mesh " + names[i] + ": " + mesh.numVertices() + " vertices, " + mesh.numFaces() + " faces, ");
                        if (mesh.isTriangular()) {
                            System.out.println("triangular");
                        } else if (mesh.isQuad()) {
                            System.out.println("quad");
                        } else {
                            System.out.println("polygonal");
                        }
                        mesh.transform(X);
                        if (names[i].equals("default")) {
                            infoList.add(new MeshInfo(meshFile.getName(), mesh));
                        } else {
                            infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
                        }
                    }
                } else if (meshClass == PolylineMesh.class) {
                    PolylineMesh mesh = (PolylineMesh) meshClass.newInstance();
                    reader.setMesh(mesh, names[i]);
                    mesh.transform(X);
                    if (printBounds.value) {
                        doPrintBounds(mesh);
                    }
                    if (names[i].equals("default")) {
                        infoList.add(new MeshInfo(meshFile.getName(), mesh));
                    } else {
                        infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
                    }
                } else if (meshClass == PointMesh.class) {
                    PointMesh mesh = (PointMesh) meshClass.newInstance();
                    reader.setMesh(mesh, names[i]);
                    mesh.transform(X);
                    if (printBounds.value) {
                        doPrintBounds(mesh);
                    }
                    if (names[i].equals("default")) {
                        infoList.add(new MeshInfo(meshFile.getName(), mesh));
                    } else {
                        infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
                    }
                }
            }
        } else {
            MeshReader reader;
            if (meshFile.getName().endsWith(".xyzb")) {
                XyzbReader xyzbReader = new XyzbReader(meshFile);
                xyzbReader.setSkip(skipCount.value);
                reader = xyzbReader;
            } else {
                reader = new GenericMeshReader(meshFile);
            }
            MeshBase mesh = pointMesh.value ? new PointMesh() : null;
            mesh = reader.readMesh(mesh);
            if (printBounds.value) {
                doPrintBounds(mesh);
            }
            infoList.add(new MeshInfo(meshFile.getName(), mesh));
        }
    } catch (Exception e) {
        System.out.println("Error creating mesh");
        e.printStackTrace();
    }
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) MeshReader(maspack.geometry.io.MeshReader) GenericMeshReader(maspack.geometry.io.GenericMeshReader) PolygonalMesh(maspack.geometry.PolygonalMesh) Point(java.awt.Point) GenericMeshReader(maspack.geometry.io.GenericMeshReader) PointMesh(maspack.geometry.PointMesh) MeshBase(maspack.geometry.MeshBase) PolylineMesh(maspack.geometry.PolylineMesh) File(java.io.File) XyzbReader(maspack.geometry.io.XyzbReader)

Example 3 with PointMesh

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

the class XyzReader method read.

public PointMesh read(PointMesh mesh, File file) throws IOException {
    FileInputStream fin = new FileInputStream(file);
    PointMesh out = null;
    try {
        out = read(mesh, fin);
    } catch (IOException e) {
        throw e;
    } finally {
        closeQuietly(fin);
    }
    return out;
}
Also used : PointMesh(maspack.geometry.PointMesh)

Example 4 with PointMesh

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

the class XyzReader method read.

public PointMesh read(PointMesh mesh, InputStream in) throws IOException {
    ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(in)));
    if (mesh == null) {
        mesh = new PointMesh();
    }
    mesh.clear();
    ArrayList<Point3d> vtxs = new ArrayList<Point3d>();
    ArrayList<Vector3d> nrms = new ArrayList<Vector3d>();
    boolean done = false;
    while (!done) {
        try {
            double vx = rtok.scanNumber();
            double vy = rtok.scanNumber();
            double vz = rtok.scanNumber();
            double nx = rtok.scanNumber();
            double ny = rtok.scanNumber();
            double nz = rtok.scanNumber();
            vtxs.add(new Point3d(vx, vy, vz));
            nrms.add(new Vector3d(nx, ny, nz));
        } catch (EOFException e) {
            done = true;
        }
    }
    mesh.set(vtxs.toArray(new Point3d[0]), nrms.toArray(new Vector3d[0]));
    return mesh;
}
Also used : PointMesh(maspack.geometry.PointMesh) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ReaderTokenizer(maspack.util.ReaderTokenizer) ArrayList(java.util.ArrayList)

Example 5 with PointMesh

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

the class RigidCompositeBody method addMeshInertia.

protected void addMeshInertia(MeshBase base, double density) {
    if (base == null) {
        throw new IllegalStateException("Mesh has not been set");
    }
    if (base instanceof PolygonalMesh) {
        PolygonalMesh mesh = (PolygonalMesh) base;
        SpatialInertia M = mesh.createInertia(density);
        mySpatialInertia.add(M);
    } else if (base instanceof PointMesh) {
    // XXX to implement
    } else if (base instanceof PolylineMesh) {
    // XXX to implement
    }
}
Also used : PointMesh(maspack.geometry.PointMesh) PolylineMesh(maspack.geometry.PolylineMesh) PolygonalMesh(maspack.geometry.PolygonalMesh) SpatialInertia(maspack.spatialmotion.SpatialInertia)

Aggregations

PointMesh (maspack.geometry.PointMesh)7 PolygonalMesh (maspack.geometry.PolygonalMesh)4 ArrayList (java.util.ArrayList)3 Point3d (maspack.matrix.Point3d)3 Vector3d (maspack.matrix.Vector3d)3 MeshBase (maspack.geometry.MeshBase)2 PolylineMesh (maspack.geometry.PolylineMesh)2 BinaryInputStream (maspack.util.BinaryInputStream)2 ReaderTokenizer (maspack.util.ReaderTokenizer)2 ArgParser (argparser.ArgParser)1 Point (java.awt.Point)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 GenericMeshReader (maspack.geometry.io.GenericMeshReader)1 MeshReader (maspack.geometry.io.MeshReader)1 WavefrontReader (maspack.geometry.io.WavefrontReader)1 XyzbReader (maspack.geometry.io.XyzbReader)1