use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class OffReader method read.
public static PolygonalMesh read(PolygonalMesh mesh, Reader reader) throws IOException {
ReaderTokenizer rtok = new ReaderTokenizer(reader);
ArrayList<Point3d> nodeList = new ArrayList<Point3d>();
ArrayList<ArrayList<Integer>> faceList = new ArrayList<ArrayList<Integer>>();
rtok.eolIsSignificant(false);
int nVerts = 0;
int nFaces = 0;
int nEdges = 0;
// read first info
rtok.nextToken();
if (rtok.ttype != ReaderTokenizer.TT_WORD || !rtok.sval.equalsIgnoreCase("OFF")) {
throw new IOException("Expected 'OFF' at start of file");
}
nVerts = rtok.scanInteger();
nFaces = rtok.scanInteger();
nEdges = rtok.scanInteger();
if (nEdges != 0) {
System.err.println("Separate edges not supported\n");
}
double[] vals = new double[3];
for (int i = 0; i < nVerts; i++) {
int nread = rtok.scanNumbers(vals, 3);
if (nread != 3) {
throw new IOException("Failed to read vertices");
}
Point3d pnt = new Point3d(vals[0], vals[1], vals[2]);
nodeList.add(pnt);
}
for (int i = 0; i < nFaces; i++) {
int nv = rtok.scanInteger();
ArrayList<Integer> vtxs = new ArrayList<Integer>(nv);
for (int j = 0; j < nv; j++) {
int vIdx = rtok.scanInteger();
vtxs.add(vIdx);
}
faceList.add(vtxs);
}
return buildMesh(mesh, nodeList, faceList);
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class OpenSimAscReader method readMesh.
public PolygonalMesh readMesh(PolygonalMesh mesh) throws IOException {
if (mesh == null) {
mesh = new PolygonalMesh();
} else {
mesh.clear();
}
ReaderTokenizer rtok = new ReaderTokenizer(new InputStreamReader(myIstream));
rtok.eolIsSignificant(false);
boolean oldFormat = false;
int nVertices = 0;
int nFaces = 0;
double[] tmp = new double[6];
int nReadVals = 6;
// read first symbol, which should be NORM_ASCII or a number of vertices
if (rtok.nextToken() != ReaderTokenizer.TT_WORD) {
if (rtok.ttype == ReaderTokenizer.TT_NUMBER) {
oldFormat = true;
nReadVals = 3;
nVertices = (int) rtok.nval;
} else {
throw new IOException("Expected " + ReaderTokenizer.TT_WORD + " on line " + rtok.lineno());
}
}
if (!oldFormat) {
String type = rtok.sval;
if (type.compareTo("NORM_ASCII") != 0) {
throw new IOException("Unknown file type: " + type);
}
if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
throw new IOException("Expected " + ReaderTokenizer.TT_NUMBER + " on line " + rtok.lineno());
}
nVertices = (int) rtok.nval;
}
if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
throw new IOException("Expected " + ReaderTokenizer.TT_NUMBER + " on line " + rtok.lineno());
}
nFaces = (int) rtok.nval;
if (!oldFormat) {
// bounding box
int iRead = rtok.scanNumbers(tmp, 6);
if (iRead != 6) {
throw new IOException("Expected bounding box on line " + rtok.lineno());
}
}
// load all vertices now
for (int i = 0; i < nVertices; i++) {
int nRead = rtok.scanNumbers(tmp, nReadVals);
if (nRead != nReadVals) {
throw new IOException("Expected number of values on line " + rtok.lineno());
}
mesh.addVertex(tmp[0], tmp[1], tmp[2]);
}
// load all faces
for (int i = 0; i < nFaces; i++) {
int nV = (int) rtok.scanNumber();
int[] face = new int[nV];
if (scanIntegers(rtok, face, nV) != nV) {
throw new IOException("Expected number of vertices on line " + rtok.lineno());
}
if (oldFormat) {
for (int j = 0; j < nV; j++) {
// start indices at zero
face[j] -= 1;
}
}
mesh.addFace(face);
}
return mesh;
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class VectorTest method doScanWrite.
void doScanWrite(Vector vr, String fmt, boolean withBrackets) {
StringWriter sw = new StringWriter();
try {
vr.write(new PrintWriter(sw), new NumberFormat(fmt), withBrackets);
vr.scan(new ReaderTokenizer(new StringReader(sw.toString())));
} catch (Exception e) {
throw new TestException("scan/write error: " + e.getMessage());
}
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class VectoriTest method doScanWrite.
void doScanWrite(Vectori vr, String fmt, boolean withBrackets) {
StringWriter sw = new StringWriter();
try {
vr.write(new PrintWriter(sw), new NumberFormat(fmt), withBrackets);
vr.scan(new ReaderTokenizer(new StringReader(sw.toString())));
} catch (Exception e) {
throw new TestException("scan/write error: " + e.getMessage());
}
}
use of maspack.util.ReaderTokenizer in project artisynth_core by artisynth.
the class LemkeContactSolverTest method main.
public static void main(String[] args) {
DoubleHolder epsilon = new DoubleHolder(1e-12);
StringHolder fileName = new StringHolder("contactTest.txt");
StringHolder testName = new StringHolder("");
IntHolder debug = new IntHolder(0);
IntHolder randomInput = new IntHolder(0);
BooleanHolder vsize = new BooleanHolder(true);
BooleanHolder reduce = new BooleanHolder(false);
BooleanHolder smartDirs = new BooleanHolder(false);
BooleanHolder timing = new BooleanHolder(false);
IntHolder timingCnt = new IntHolder(1);
BooleanHolder tradSolver = new BooleanHolder(false);
BooleanHolder multiBody = new BooleanHolder(false);
BooleanHolder tradInc = new BooleanHolder(false);
BooleanHolder verbose = new BooleanHolder(false);
ArgParser parser = new ArgParser("java contact.LemkeContactSolverTest");
parser.addOption("-f %s # test file name", fileName);
parser.addOption("-D %d # debug code", debug);
parser.addOption("-vsize %v # variable LCP size", vsize);
parser.addOption("-reduce %v # reducible LCP size", reduce);
parser.addOption("-timing %v # time the functions", timing);
parser.addOption("-timingCnt %d # timing count", timingCnt);
parser.addOption("-trad %v # use traditional solver", tradSolver);
parser.addOption("-multiBody %v # use multi-body solver", multiBody);
parser.addOption("-verbose %v # print solution info", verbose);
parser.addOption("-tradinc %v # use traditional solver with incremental pivoting", tradInc);
parser.addOption("-random %d # random input cnt", randomInput);
parser.addOption("-smartDirs %v # smart friction directions", smartDirs);
parser.addOption("-eps %f # epsilon", epsilon);
parser.addOption("-name %s # test name", testName);
parser.matchAllArgs(args);
if (tradInc.value) {
tradSolver.value = true;
}
LemkeContactSolverTest tester = new LemkeContactSolverTest(tradSolver.value, multiBody.value);
if (tradInc.value) {
tester.testName = testName.value + "Tradinc";
} else if (tradSolver.value) {
tester.testName = testName.value + "Trad";
} else if (vsize.value) {
tester.testName = testName.value + "Vsize";
} else {
tester.testName = testName.value + "Reg";
}
tester.solver.setDebug(debug.value);
tester.solver.setEpsilon(epsilon.value);
if (!tradSolver.value) {
// if (multiBody.value)
// { ContactSolverMbX solverx = (ContactSolverMbX)tester.solver;
// solverx.setVariableSize(vsize.value);
// // solverx.setReducibleSize(reduce.value);
// solverx.setSmartDirections(smartDirs.value);
// }
// else
{
LemkeContactSolver solverx = (LemkeContactSolver) tester.solver;
solverx.setVariableSize(vsize.value);
solverx.setReducibleSize(reduce.value);
solverx.setSmartDirections(smartDirs.value);
}
}
// else
// { if (tradInc.value)
// { if (multiBody.value)
// { ContactSolverMbO solvero = (ContactSolverMbO)tester.solver;
// solvero.setIncrementalPivoting (true);
// }
// else
// { ContactSolverO solvero = (ContactSolverO)tester.solver;
// solvero.setIncrementalPivoting (true);
// }
// }
// }
tester.doTiming = timing.value;
tester.timingCnt = timingCnt.value;
tester.randomInputCnt = randomInput.value;
int cnt = tester.doTiming ? 2 : 1;
for (int i = 0; i < cnt; i++) {
try {
Reader reader = new FileReader(fileName.value);
ReaderTokenizer rtok = new ReaderTokenizer(reader);
rtok.parseNumbers(true);
rtok.commentChar('#');
tester.parseInput(rtok);
reader.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
System.out.println("\nPassed\n");
}
Aggregations