use of argparser.IntHolder in project artisynth_core by artisynth.
the class MeshViewer method main.
public static void main(String[] args) {
StringHolder fileName = new StringHolder();
IntHolder width = new IntHolder(640);
IntHolder height = new IntHolder(480);
Vector meshFileList = new Vector();
ArrayList<String> meshQueue = new ArrayList<String>();
ArgParser parser = new ArgParser("java maspack.geometry.MeshViewer [options] <objFile> ...");
// parser.addOption ("-file %s #mesh file names", meshFileList);
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("-backgroundColor %fX3 #background color", backgroundColor);
parser.addOption("-rotate %fX4 #rotation (axis-angle)", rotation);
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);
parser.addOption("-class %s #use PolygonalMesh sub class", className);
parser.addOption("-zeroIndexed %v #zero indexed (for writing)", zeroIndexed);
parser.addOption("-queue %v #queue meshes for viewing", queueMeshes);
parser.addOption("-printBounds %v #print bounds for meshes", printBounds);
parser.addOption("-skip %d #for .xyzb point meshes, use every n-th point", skipCount);
parser.addOption("-pointMesh %v #specifies that mesh must be read as a point mesh", pointMesh);
RigidTransform3d X = new RigidTransform3d();
ArrayList<MeshInfo> infoList = new ArrayList<MeshInfo>(0);
int idx = 0;
while (idx < args.length) {
try {
idx = parser.matchArg(args, idx);
if (parser.getUnmatchedArgument() != null) {
String meshFileName = parser.getUnmatchedArgument();
if (queueMeshes.value) {
meshQueue.add(meshFileName);
} else {
X.R.setAxisAngle(rotation[0], rotation[1], rotation[2], Math.toRadians(rotation[3]));
loadMeshes(infoList, meshFileName, X);
}
}
} catch (Exception e) {
// malformed or erroneous argument
parser.printErrorAndExit(e.getMessage());
}
}
// parser.matchAllArgs (args);
// for (Iterator it = meshFileList.iterator(); it.hasNext();) {
// loadMeshes (meshList, ((StringHolder)it.next()).value, X);
// }
// call this to prevent awful looking fonts:
System.setProperty("awt.useSystemAAFontSettings", "on");
final MeshViewer frame = new MeshViewer("MeshViewer", infoList, width.value, height.value);
frame.setMeshQueue(meshQueue);
frame.setVisible(true);
// add close
frame.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent arg0) {
}
@Override
public void windowIconified(WindowEvent arg0) {
}
@Override
public void windowDeiconified(WindowEvent arg0) {
}
@Override
public void windowDeactivated(WindowEvent arg0) {
}
@Override
public void windowClosing(WindowEvent arg0) {
frame.exit(0);
}
@Override
public void windowClosed(WindowEvent arg0) {
}
@Override
public void windowActivated(WindowEvent arg0) {
}
});
}
use of argparser.IntHolder in project artisynth_core by artisynth.
the class MovieMaker method render.
/**
* Renders captured data to a movie with the specified file name.
*/
public void render(String fn) throws Exception {
if (lastFrameCount == 0) {
Main.getMain().getLogger().info("No frames grabbed, no movie to make");
return;
}
// wait for all frames to be done writing
myViewer.awaitScreenShotCompletion();
Method method = myMethodMap.get(myMethodName);
if (myMethodName.equals(INTERNAL_METHOD)) {
String[] frameFileNames = new String[lastFrameCount];
for (int i = 1; i <= lastFrameCount; i++) {
frameFileNames[i - 1] = getFrameFileName(i);
}
new MakeMovieFromData(frameFileNames, dataPath, fn + ".mov");
} else if (myMethodName.equals(ANIMATED_GIF_METHOD)) {
String opts = method.command;
opts = opts.replaceAll("\\$FPS", "" + frameRate);
String[] frameFileNames = new String[lastFrameCount];
for (int i = 1; i <= lastFrameCount; i++) {
frameFileNames[i - 1] = getFrameFileName(i);
}
File outFile = new File(dataPath + File.separator + fn + ".gif");
DoubleHolder delayHolder = new DoubleHolder(0);
IntHolder loopHolder = new IntHolder(0);
AnimatedGifWriter.parseArgs(opts, delayHolder, loopHolder);
AnimatedGifWriter.write(outFile, frameFileNames, delayHolder.value, loopHolder.value);
} else {
// Custom method, execute the specified command in data directory.
String cmd = method.command;
cmd = cmd.replaceAll("\\$FPS", "" + frameRate);
cmd = cmd.replaceAll("\\$FMT", myFormat);
String[] cmdArray = cmd.split("\\s+");
// Substitute $OUT later because file name might contain white space
String finalCmd = "";
for (int i = 0; i < cmdArray.length; i++) {
cmdArray[i] = cmdArray[i].replaceAll("\\$OUT", fn);
finalCmd = finalCmd + " " + cmdArray[i];
}
// Map<String, String> env = System.getenv();
// File dataFile = new File(dataPath);
// Process proc = Runtime.getRuntime().exec (
// cmdArray, /*env=*/null, null);
Main.getMain().getLogger().info("Executing " + finalCmd);
ProcessBuilder procBuild = new ProcessBuilder(cmdArray);
procBuild.directory(new File(dataPath));
Process proc = procBuild.start();
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), System.err, ">>");
// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), System.out, ">>");
// start gobblers
outputGobbler.start();
errorGobbler.start();
int exitVal = proc.waitFor();
if (exitVal != 0) {
Main.getMain().getLogger().error("\nMovie creation failed with exit value: " + exitVal + "\n");
}
}
}
use of argparser.IntHolder in project artisynth_core by artisynth.
the class IntersectorTestViewer 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("-drawIntersection %v #draw mesh intersection", drawIntersection);
parser.addOption("-drawUnion %v #draw mesh union", drawUnion);
parser.addOption("-spinView %v #automatically rotate view", spinView);
String[] otherArgs = parser.matchAllArgs(args, 0, 0);
IntersectorTestViewer frame = new IntersectorTestViewer(width.value, height.value);
frame.myDrawIntersection = drawIntersection.value;
frame.myDrawUnion = drawUnion.value;
frame.mySpinView = spinView.value;
frame.setVisible(true);
frame.runTest();
}
use of argparser.IntHolder 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);
}
use of argparser.IntHolder in project artisynth_core by artisynth.
the class NURBSViewer method main.
public static void main(String[] args) {
StringHolder fileName = new StringHolder();
IntHolder width = new IntHolder(400);
IntHolder height = new IntHolder(400);
ArgParser parser = new ArgParser("java maspack.geometry.NURBSViewer");
parser.addOption("-width %d #width (pixels)", width);
parser.addOption("-height %d #height (pixels)", height);
parser.addOption("-drawAxes %v #draw coordinate axes", drawAxes);
parser.addOption("-file %s #wavefront file name", fileName);
parser.addOption("-sphere %v #create a NURBS sphere", addSphere);
parser.addOption("-circle %v #create a NURBS circle", addCircle);
parser.addOption("-mesh %v #create a mesh for surfaces", addMesh);
parser.addOption("-collider %v #create a colliding object for meshes", collider);
parser.addOption("-axisLength %f #coordinate axis length", axisLength);
parser.addOption("-GLVersion %d{2,3} " + "#version of openGL for graphics", glVersion);
parser.matchAllArgs(args);
NURBSViewer viewFrame = null;
try {
GLVersion glv = (glVersion.value == 3 ? GLVersion.GL3 : GLVersion.GL2);
viewFrame = new NURBSViewer(width.value, height.value, glv);
GLViewer viewer = viewFrame.getViewer();
if (fileName.value != null) {
viewFrame.addNURBS(new File(fileName.value));
}
if (addSphere.value) {
NURBSSurface sphere = new NURBSSurface();
sphere.setSphere(0, 0, 0, 10);
if (addMesh.value) {
viewFrame.addNURBSWithMesh(sphere);
} else {
viewFrame.addNURBS(sphere);
}
}
if (addCircle.value) {
NURBSCurve3d circle = new NURBSCurve3d();
circle.setCircle(0, 0, 10);
viewFrame.addNURBS(circle);
}
viewer.autoFitPerspective();
if (drawAxes.value) {
if (axisLength.value > 0) {
viewer.setAxisLength(axisLength.value);
} else {
viewer.setAxisLength(GLViewer.AUTO_FIT);
}
}
if (collider.value) {
viewFrame.addCollidable();
}
} catch (Exception e) {
e.printStackTrace();
}
viewFrame.setVisible(true);
}
Aggregations