use of maspack.util.NumberFormat 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);
}
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class WavefrontToMaya method main.
public static void main(String[] args) {
String outfile = null;
String fmt = "%g";
if (args.length < 1) {
System.out.println("arguments: input_file [output_file] [number_format]");
return;
}
if (args.length > 1) {
outfile = args[1];
}
if (args.length > 2) {
fmt = args[2];
}
doFiberExport(args[0], outfile, new NumberFormat(fmt));
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class FemModel3d method printANSYSNodes.
/**
* Prints the nodes of this FEM in a format which is compatible with ANSYS.
*
* @param pw
* PrintWriter to which nodes are written
*/
public void printANSYSNodes(PrintWriter pw) {
NumberFormat ifmt = new NumberFormat("%8d");
int nodeIdx = 1;
for (FemNode3d n : myNodes) {
pw.println(ifmt.format(nodeIdx) + " " + n.myRest.toString("%16.9e "));
nodeIdx++;
}
pw.flush();
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class FemMeshComp method writeMesh.
public boolean writeMesh(PrintWriter pw, boolean nodeFormat) {
PolygonalMesh mesh = null;
if (!(getMesh() instanceof PolygonalMesh)) {
return false;
}
mesh = (PolygonalMesh) getMesh();
pw.print("[ ");
NumberFormat fmt = new NumberFormat("%.8g");
IndentingPrintWriter.addIndentation(pw, 2);
if (!nodeFormat) {
for (Vertex3d vtx : mesh.getVertices()) {
writeVertexInfo(pw, vtx, fmt);
}
}
ArrayList<Integer> nodeNums = new ArrayList<Integer>();
for (Face face : mesh.getFaces()) {
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
pw.print("f");
do {
int vidx = he.head.getIndex();
if (nodeFormat) {
PointParticleAttachment ppa = (PointParticleAttachment) getAttachment(vidx);
FemNode3d node = (FemNode3d) ppa.getParticle();
pw.print(" " + node.getNumber());
} else {
pw.print(" " + (vidx + 1));
}
he = he.getNext();
} while (he != he0);
pw.println("");
}
IndentingPrintWriter.addIndentation(pw, -2);
pw.println("]");
return true;
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class TetGenWriter method writeElemFile.
public static void writeElemFile(FemModel3d fem, String fileName) {
try {
PrintWriter pw = new PrintWriter(new File(fileName));
NumberFormat dfmt = new NumberFormat("%6d");
ComponentList<FemElement3d> elemList = fem.getElements();
pw.println(elemList.size() + " 4 0");
for (FemElement3d e : elemList) {
FemNode3d[] nodes = e.getNodes();
int[] firstRow = new int[4];
if (e instanceof TetElement) {
firstRow[0] = nodes[0].getNumber();
firstRow[1] = nodes[1].getNumber();
firstRow[2] = nodes[2].getNumber();
firstRow[3] = nodes[3].getNumber();
} else {
System.out.println("Unknown element type: " + e.getClass().getName());
continue;
}
pw.print(e.getNumber() + " ");
for (int i = 0; i < firstRow.length; i++) {
pw.print(dfmt.format(firstRow[i]));
}
pw.println();
}
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Aggregations