use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class PolygonalMesh method write.
/**
* Writes this mesh to a File, using an Alias Wavefront "obj" file
* format. Behaves the same as {@link
* #write(java.io.PrintWriter,maspack.util.NumberFormat,boolean,boolean)}
* with <code>zeroIndexed</code> and <code>facesClockwise</code> set to
* false.
*
* @param file
* File to write this mesh to
* @param fmtStr
* format string for writing the vertex coordinates. If <code>null</code>,
* a format of <code>"%.8g"</code> is assumed.
*/
public void write(File file, String fmtStr) throws IOException {
if (fmtStr == null) {
fmtStr = "%.8g";
}
NumberFormat fmt = new NumberFormat(fmtStr);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
write(pw, fmt, /*zeroIndexed=*/
false, /*facesClockwise=*/
false);
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class NURBSSurface method write.
/**
* {@inheritDoc}
*/
public void write(PrintWriter pw, String fmtStr, boolean relative) throws IOException {
double[] minmax = new double[2];
int numc = numControlPoints();
NumberFormat fmt = new NumberFormat(fmtStr);
for (int i = 0; i < myCtrlPnts.size(); i++) {
pw.println("v " + myCtrlPnts.get(i).toString(fmt));
}
pw.println("deg " + ucurve.getDegree() + " " + vcurve.getDegree());
resetLine(pw);
addToLine(pw, "surf");
ucurve.getRange(minmax);
addToLine(pw, " " + fmt.format(minmax[0]) + " " + fmt.format(minmax[1]));
vcurve.getRange(minmax);
addToLine(pw, " " + fmt.format(minmax[0]) + " " + fmt.format(minmax[1]));
for (int i = 0; i < numc; i++) {
addToLine(pw, relative ? " " + (-numc + i) : " " + (i + 1));
}
resetLine(pw);
addToLine(pw, "parm u");
if (ucurve.isClosed()) {
addToLine(pw, " closed");
}
double[] knotsu = ucurve.getKnots();
for (int i = 0; i < knotsu.length; i++) {
addToLine(pw, " " + fmt.format(knotsu[i]));
}
resetLine(pw);
addToLine(pw, "parm v");
if (vcurve.isClosed()) {
addToLine(pw, " closed");
}
double[] knotsv = vcurve.getKnots();
for (int i = 0; i < knotsv.length; i++) {
addToLine(pw, " " + fmt.format(knotsv[i]));
}
resetLine(pw);
pw.println("end");
pw.flush();
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class PolylineMesh method write.
/**
* Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file
* format. Vertices are printed first, each starting with the letter "v" and
* followed by x, y, and z coordinates. Lines are printed next, starting
* with the letter "f" and followed by a list of integers which gives the
* indices of that line's vertices. An example of a simple three
* point line is:
*
* <pre>
* v 1.0 0.0 0.0
* v 0.0 1.0 0.0
* v 0.0 0.0 1.0
* l 0 1 2
* </pre>
*
* <p>
* The format used to print vertex coordinates is specified by a
* {@link maspack.util.NumberFormat NumberFormat}.
*
* @param pw
* PrintWriter to write this mesh to
* @param fmt
* format for writing the vertex coordinates. If <code>null</code>,
* a format of <code>"%.8g"</code> is assumed.
* @param zeroIndexed
* if true, index numbering for mesh vertices starts at 0. Otherwise,
* numbering starts at 1.
*/
public void write(PrintWriter pw, NumberFormat fmt, boolean zeroIndexed) throws IOException {
if (fmt == null) {
fmt = new NumberFormat("%.8g");
}
for (Vertex3d vertex : myVertices) {
Point3d pnt = vertex.pnt;
pw.println("v " + fmt.format(pnt.x) + " " + fmt.format(pnt.y) + " " + fmt.format(pnt.z));
}
// int lineCnt = 0;
for (Polyline line : myLines) {
// int idxCnt = 0;
pw.print("l");
int[] idxs = line.getVertexIndices();
for (int i = 0; i < idxs.length; i++) {
if (zeroIndexed) {
pw.print(" " + (idxs[i]));
} else {
pw.print(" " + (idxs[i] + 1));
}
}
pw.println("");
}
pw.flush();
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class ColorBar method setDefaults.
@Override
protected void setDefaults() {
setFont(new Font(defaultFontName, 0, defaultFontSize));
myRenderProps = createDefaultRenderProps();
hAlignment = defaultHAlignment;
vAlignment = defaultVAlignment;
myTextSize = defaultTextSize;
myFontSize = defaultFontSize;
myLoc = new Rectangle2d(defaultLoc);
myColorMap = defaultColorMap;
myValueRange = new DoubleInterval(defaultInterval);
nBarDivisions = defaultBarDivisions;
myTickFractions = new Vector2d(defaultTickFraction);
myLabelPos = new VectorNd(0);
myLabelText = new ArrayList<String>();
myTextOffset = new Vector2d(defaultTextOffset);
myNumberFormat = new NumberFormat(defaultNumberFormat);
myRenderObject = null;
myRenderObjectRebuildRequest = true;
}
use of maspack.util.NumberFormat in project artisynth_core by artisynth.
the class ObjToMdl method main.
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("usage: java artisynth.models.badin.ObjToMdl inputObjMeshName outputMdlMeshName");
return;
}
try {
PolygonalMesh mesh = new PolygonalMesh(new File(args[0]));
PrintWriter pw = new PrintWriter(new File(args[1]));
MDLMeshIO.write(mesh, args[1], pw, new NumberFormat("%g"));
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations