use of argparser.ArgParser 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);
}
}
use of argparser.ArgParser 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.ArgParser in project artisynth_core by artisynth.
the class SurfaceMeshIntersectorTest method main.
public static void main(String[] args) {
ArgParser parser = new ArgParser("java maspack.collision.SurfaceMeshIntersectorTest [options]");
parser.addOption("-test %s #test with a specific test file", testFile);
parser.addOption("-timing %v #run timing tests", testTiming);
parser.addOption("-randomSeed %x " + "#seed for random values. -1 means choose one randomly", randomSeed);
parser.matchAllArgs(args, 0, 0);
System.out.println("randomSeed=" + randomSeed.value);
SurfaceMeshIntersectorTest tester = new SurfaceMeshIntersectorTest(randomSeed.value);
if (testFile.value != null) {
try {
tester.runTestProblem(testFile.value);
} catch (Exception e) {
e.printStackTrace();
}
} else if (testTiming.value) {
tester.runTimingTest();
} else {
tester.setTestFailFileName("contactTestFail.out");
tester.runtest();
}
// String testFile = null;
// boolean testTiming = false;
// for (int i=0; i<args.length; i++) {
// if (args[i].equals ("-help")) {
// printUsageAndExit();
// }
// else if (args[i].equals ("-test")) {
// if (++i == args.length) {
// printUsageAndExit();
// }
// testFile = args[i];
// }
// else if (args[i].equals ("-timing")) {
// testTiming = true;
// }
// else {
// printUsageAndExit();
// }
// }
// SurfaceMeshIntersectorTest tester = new SurfaceMeshIntersectorTest();
// if (testFile != null) {
// try {
// tester.runTestProblem (testFile);
// }
// catch (Exception e) {
// e.printStackTrace();
// }
// }
// else if (testTiming) {
// tester.runTimingTest();
// }
// else {
// tester.setTestFailFileName ("contactTestFail.out");
// tester.runtest();
// }
}
use of argparser.ArgParser in project artisynth_core by artisynth.
the class Main method main.
/**
* the main entry point
*
* @param args command line arguments
*/
public static void main(String[] args) {
// some interfaces (like Matlab) may pass args in as null
if (args == null) {
args = new String[0];
}
ArgParser parser = new ArgParser("java artisynth.core.driver.Main", false);
parser.addOption("-help %v #prints help message", printHelp);
parser.addOption("-width %d #width (pixels)", viewerWidth);
parser.addOption("-height %d #height (pixels)", viewerHeight);
parser.addOption("-bgColor %fX3 #background color (3 rgb values, 0 to 1)", bgColor);
parser.addOption("-maxStep %f #maximum time for a single step (sec)", maxStep);
parser.addOption("-drawAxes %v #draw coordinate axes", drawAxes);
parser.addOption("-drawGrid %v #draw grid", drawGrid);
parser.addOption("-axisLength %f #coordinate axis length", axisLength);
parser.addOption("-play %v #play model immediately", play);
parser.addOption("-playFor %f #play model immediately for x seconds", playFor);
parser.addOption("-exitOnBreak %v #exit artisynth when playing stops", exitOnBreak);
parser.addOption("-demosFile %s #demo file (e.g. .demoModels)", demosFilename);
parser.addOption("-demosMenu %s #demo menu file (e.g. .demoMenu.xml)", demosMenuFilename);
parser.addOption("-historyFile %s #model history file (e.g. .history)", historyFilename);
parser.addOption("-scriptsFile %s #script file (e.g. .artisynthModels)", scriptsFilename);
parser.addOption("-mousePrefs %s #kees for pure mouse controls", mousePrefs);
parser.addOption("-ortho %v #use orthographic viewing", orthographic);
parser.addOption("-axialView %s{xy,xz} #initial view of x-y or x-z axes", axialView);
parser.addOption("-noTimeline %v{false} #do not start with a timeline", startWithTimeline);
parser.addOption("-showJythonConsole %v{true} #create jython console on startup", startWithJython);
parser.addOption("-largeTimeline %v{true} #start with vertically expanded timeline", largeTimeline);
parser.addOption("-timelineRight %v{true} #start with a timeline alligned to the right", timelineRight);
parser.addOption("-fps %f#frames per second", framesPerSecond);
parser.addOption("-fullscreen %v #full screen renderer", fullScreen);
// parser.addOption("-yup %v #initialize viewer with Y-axis up", yup);
parser.addOption("-timelineZoom %d #zoom level for timeline", zoom);
parser.addOption("-options %v #print options only", printOptions);
parser.addOption("-abortOnInvertedElems %v #abort on nonlinear element inversion", abortOnInvertedElems);
parser.addOption("-disableHybridSolves %v #disable hybrid linear solves", disableHybridSolves);
parser.addOption("-numSolverThreads %d #number of threads to use for linear solver", numSolverThreads);
parser.addOption("-posCorrection %s{Default,GlobalMass,GlobalStiffness} " + "#position correction mode", posCorrection);
parser.addOption("-noIncompressDamping %v #ignore incompress stiffness for damping", noIncompressDamping);
// parser.addOption ("-useOldTimeline %v #use old timeline", useOldTimeline);
parser.addOption("-useSignedDistanceCollider %v " + "#use SignedDistanceCollider where possible", useSignedDistanceCollider);
parser.addOption("-useAjlCollision" + "%v #use AJL collision detection", useAjlCollision);
parser.addOption("-useBodyVelsInSolve" + "%v #use body velocities for dynamic solves", useBodyVelsInSolve);
parser.addOption("-useArticulatedTransforms %v #enforce articulation " + "constraints with transformers", useArticulatedTransforms);
parser.addOption("-updateLibs %v #update libraries from ArtiSynth server", updateLibs);
parser.addOption("-flags %x #flag bits passed to the application", flags);
parser.addOption("-noGui %v #run ArtiSynth without the GUI", noGui);
parser.addOption("-openMatlabConnection %v " + "#open a MATLAB connection if possible", openMatlab);
parser.addOption("-GLVersion %d{2,3} " + "#version of openGL for graphics", glVersion);
parser.addOption("-useGLJPanel %v " + "#use GLJPanel for creating the openGL viewer", useGLJPanel);
parser.addOption("-useGLCanvas %v{false} " + "#use GLJCanvas for creating the openGL viewer", useGLJPanel);
parser.addOption("-logLevel %s", logLevel);
parser.addOption("-testSaveRestoreState %v #test save/restore state when running models", testSaveRestoreState);
parser.addOption("-movieFrameRate %f #frame rate to use when making movies", movieFrameRate);
parser.addOption("-movieMethod %s #method to use when making movies", movieMethod);
Locale.setDefault(Locale.CANADA);
URL initUrl = ArtisynthPath.findResource(".artisynthInit");
if (initUrl == null) {
// Removed warning message for now
// System.out.println (".artisynthInit not found");
} else {
InputStream is = null;
try {
is = initUrl.openStream();
} catch (Exception e) {
// do nothing if we can't open
System.out.println(".artisynthInit not found");
}
if (is != null) {
try {
args = ArgParser.prependArgs(new InputStreamReader(is), args);
} catch (Exception e) {
System.err.println("Error reading init file " + initUrl);
System.err.println(e.getMessage());
}
}
}
if (System.getProperty("file.separator").equals("\\")) {
// then we are running windows, so set noerasebackground to
// try and remove flicker bug
System.setProperty("sun.awt.noerasebackground", "true");
} else {
System.setProperty("awt.useSystemAAFontSettings", "on");
}
// Separate program arguments from model arguments introduced by -M
ArrayList<String> progArgs = new ArrayList<String>();
ArrayList<String> modelArgs = null;
ArrayList<String> scriptArgs = null;
ArrayList<String> taskManagerArgs = null;
for (String arg : args) {
if (modelArgs != null) {
modelArgs.add(arg);
} else {
if (arg.equals("-M")) {
modelArgs = new ArrayList<String>();
} else {
progArgs.add(arg);
}
}
}
// Match arguments one at a time so we can avoid exitOnError if we are
// running inside matlab
String[] pargs = progArgs.toArray(new String[0]);
int lastSwitch = -1;
int idx = 0;
while (idx < pargs.length) {
try {
int pidx = idx;
// check for list of arguments:
if ("-model".equals(pargs[pidx])) {
modelName.value = pargs[++idx];
modelArgs = new ArrayList<String>();
int nidx = maybeCollectArgs(pargs, ++idx, modelArgs);
if (nidx == idx) {
modelArgs = null;
}
idx = nidx;
} else if ("-script".equals(pargs[pidx])) {
scriptFile.value = pargs[++idx];
scriptArgs = new ArrayList<String>();
int nidx = maybeCollectArgs(pargs, ++idx, scriptArgs);
if (nidx == idx) {
scriptArgs = null;
}
idx = nidx;
} else if ("-taskManager".equals(pargs[pidx])) {
taskManagerClassName.value = pargs[++idx];
taskManagerArgs = new ArrayList<String>();
int nidx = maybeCollectArgs(pargs, ++idx, taskManagerArgs);
if (nidx == idx) {
taskManagerArgs = null;
}
idx = nidx;
} else {
idx = parser.matchArg(pargs, idx);
}
String unmatched;
if ((unmatched = parser.getUnmatchedArgument()) != null) {
boolean valid = false;
if (!valid) {
System.err.println("Unrecognized argument: " + unmatched + "\nUse -help for help information");
return;
}
} else {
lastSwitch = pidx;
}
} catch (Exception e) {
System.err.println("Error parsing options: " + e.getMessage());
return;
}
}
// parser.matchAllArgs (progArgs.toArray(new String[0]));
if (printOptions.value || printHelp.value) {
System.out.println(parser.getOptionsMessage(2));
System.out.println(" -model <string> [ <string>... ]\n" + " name of model to start, with optional arguments\n" + " delimited by square brackets\n" + " -script <string> [ <string>... ]\n" + " script to run immediately, with optional arguments\n" + " delimited by square brackets\n" + " -taskManager <className> [ <string>... ]\n" + " name of task manager class to run immediately, with\n" + " optional arguments delimited by square brackets\n");
return;
}
// Set system logger level
Logger.getSystemLogger().setLogLevel(LogLevel.find(logLevel.value));
MechSystemSolver.myDefaultHybridSolveP = !disableHybridSolves.value;
if (numSolverThreads.value > 0) {
PardisoSolver.setDefaultNumThreads(numSolverThreads.value);
}
FemModel3d.abortOnInvertedElems = abortOnInvertedElems.value;
// }
if (posCorrection.value.equals("GlobalMass")) {
MechSystemBase.setDefaultStabilization(PosStabilization.GlobalMass);
} else if (posCorrection.value.equals("GlobalStiffness")) {
MechSystemBase.setDefaultStabilization(PosStabilization.GlobalStiffness);
}
FemModel3d.noIncompressStiffnessDamping = noIncompressDamping.value;
if (useAjlCollision.value) {
CollisionManager.setDefaultColliderType(ColliderType.AJL_CONTOUR);
}
if (testSaveRestoreState.value) {
RootModel.testSaveAndRestoreState = true;
}
if (useGLJPanel.value == true) {
maspack.render.GL.GLViewer.useGLJPanel = true;
}
if (noGui.value == true) {
viewerWidth.value = -1;
}
GLVersion glv = (glVersion.value == 3 ? GLVersion.GL3 : GLVersion.GL2);
Main m = new Main(PROJECT_NAME, viewerWidth.value, viewerHeight.value, glv);
m.setArticulatedTransformsEnabled(useArticulatedTransforms.value);
if (axialView.value.equals("xy")) {
m.setDefaultViewOrientation(AxisAngle.IDENTITY);
} else if (axialView.value.equals("xz")) {
m.setDefaultViewOrientation(AxisAngle.ROT_X_90);
} else {
throw new InternalErrorException("Unknown axial view: " + axialView.value);
}
if (m.myFrame != null) {
m.myViewer.setBackgroundColor(bgColor[0], bgColor[1], bgColor[2]);
// XXX this should be done in the Main constructor, but needs
// to be done here instead because of sizing effects
m.myMenuBarHandler.initToolbar();
if (movieMethod.value != null) {
MovieMaker movieMaker = m.getMovieMaker();
try {
movieMaker.setMethod(movieMethod.value);
} catch (Exception e) {
System.out.println("Warning: unknown movie making method " + movieMethod.value);
}
}
if (movieFrameRate.value != -1) {
MovieMaker movieMaker = m.getMovieMaker();
try {
movieMaker.setFrameRate(movieFrameRate.value);
} catch (Exception e) {
System.out.println("Warning: illegal movie frame rate " + movieFrameRate.value);
}
}
}
if (mousePrefs.value != null && m.myViewer != null) {
m.setMouseBindings(mousePrefs.value);
}
m.setFlags(flags.value);
if (useBodyVelsInSolve.value) {
Frame.dynamicVelInWorldCoords = false;
}
m.start(startWithTimeline.value, timelineRight.value, largeTimeline.value);
// because setting it earlier can cause incorrect results
if (m.myFrame != null) {
m.setViewerSize(viewerWidth.value, viewerHeight.value);
}
if (System.getProperty("os.name").contains("Windows")) {
// XXX see function docs
fixPardisoThreadCountHack();
}
m.verifyNativeLibraries(updateLibs.value);
// the whole frame to be visible
if (m.myFrame != null && orthographic.value) {
m.getViewer().setOrthographicView(true);
}
// XXX store model arguments for future use?
if (modelArgs != null) {
m.myModelArgs = modelArgs.toArray(new String[modelArgs.size()]);
}
if (modelName.value != null) {
// load the specified model. See first if the name corresponds to a file
File file = new File(modelName.value);
if (file.exists() && file.canRead()) {
try {
m.loadModelFile(file);
} catch (IOException e) {
System.out.println("Error reading or loading model file " + modelName.value);
e.printStackTrace();
m.setRootModel(new RootModel(), null, null);
}
} else // otherwise, try to determine the model from the class name or alias
{
String className = m.getDemoClassName(modelName.value);
if (className == null) {
System.out.println("No class associated with model name " + modelName.value);
m.setRootModel(new RootModel(), null, null);
} else {
String name = modelName.value;
if (name.indexOf('.') != -1) {
name = name.substring(name.lastIndexOf('.') + 1);
if (name.length() == 0) {
name = "Unknown";
}
}
// load the model
ModelInfo mi = new ModelInfo(className, name, createArgArray(modelArgs));
m.loadModel(mi);
}
}
} else {
m.setRootModel(new RootModel(), null, null);
}
if (exitOnBreak.value) {
m.myScheduler.addListener(new QuitOnBreakListener(m));
}
if (playFor.value > 0) {
m.play(playFor.value);
} else if (play.value) {
m.play();
}
if (scriptFile.value != null && taskManagerClassName.value != null) {
System.out.println("Cannot specify both a script (option '-script') and a task manager (option \n" + "'-taskManager' at the same time");
System.exit(1);
} else if (scriptFile.value != null) {
m.runScriptFile(scriptFile.value, scriptArgs);
} else if (taskManagerClassName.value != null) {
m.runTaskManager(taskManagerClassName.value, taskManagerArgs);
}
if (m.myJythonConsole != null && m.myJythonFrame == null) {
m.myJythonConsole.interact();
}
if (openMatlab.value) {
m.openMatlabConnection();
}
}
use of argparser.ArgParser 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();
}
Aggregations