use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class TetGenWriter method writeNodeFile.
public static void writeNodeFile(FemModel3d fem, String fileName) {
try {
PrintWriter pw = new PrintWriter(new File(fileName));
NumberFormat fmt = new NumberFormat("%19g");
ComponentList<FemNode3d> nodeList = fem.getNodes();
pw.println(nodeList.size() + " 3 0 0");
for (FemNode3d n : nodeList) {
pw.print(n.getNumber());
pw.println(" " + n.getPosition().toString(fmt));
}
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class MFreeMeshComp 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);
MFreeNode3d node = (MFreeNode3d) 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 SparseBlockMatrix method toString.
public String toString(String fmtStr, int nrows, int ncols) {
int numValues = numNonZeroVals();
double[] values = new double[numValues];
int[] colIdxs = new int[numValues];
int[] rowOffs = new int[rowSize() + 1];
getCRSIndices(colIdxs, rowOffs, Partition.Full);
getCRSValues(values, Partition.Full);
StringBuffer buf = new StringBuffer(20 * numValues);
NumberFormat fmt = new NumberFormat(fmtStr);
int rowIdx = 0;
for (int i = 0; i < numValues; i++) {
while ((rowIdx + 1) < rowSize() && i >= rowOffs[rowIdx + 1] - 1) {
rowIdx++;
}
buf.append("(" + rowIdx + " " + (colIdxs[i] - 1) + " " + fmt.format(values[i]) + ")\n");
}
return buf.toString();
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class MatrixBase method setDefaultFormat.
/**
* Sets the default format string used in {@link #toString() toString}. For
* a description of the format string syntax, see {@link
* maspack.util.NumberFormat NumberFormat}.
*
* @param fmtStr
* new format string
* @throws IllegalArgumentException
* if the format string is invalid
* @see #getDefaultFormat
*/
public static void setDefaultFormat(String fmtStr) {
NumberFormat fmt = new NumberFormat(fmtStr);
myDefaultFmt = fmt;
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class MatrixBase method writeToFile.
public void writeToFile(String fileName, String fmtStr) {
NumberFormat fmt = new NumberFormat(fmtStr);
try {
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
write(pw, fmt);
pw.close();
} catch (Exception e) {
System.out.println("Error writing matrix to file " + fileName + ":");
System.out.println(e);
}
}
Aggregations