use of maspack.geometry.MeshBase 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 maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class MeshViewer method cleanMeshes.
private void cleanMeshes() {
System.out.println("Cleaning ...");
for (MeshBase m : myMeshes) {
if (m instanceof PolygonalMesh) {
boolean modified = false;
PolygonalMesh pmesh = (PolygonalMesh) m;
int nv = pmesh.mergeCloseVertices(myVertexMergeDist);
if (nv > 0) {
System.out.println("removed " + nv + " vertices");
modified = true;
}
int nf = pmesh.removeDisconnectedFaces();
if (nf > 0) {
System.out.println("removed " + nf + " disconnected faces");
modified = true;
}
if (modified) {
pmesh.notifyVertexPositionsModified();
if (m == myMeshes.get(myMeshes.size() - 1)) {
// if last mesh in list, need to update label text as well
setLabelText(myLastMeshName, m);
}
}
}
}
System.out.println("done");
viewer.rerender();
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class MeshViewer method loadMeshes.
public static void loadMeshes(ArrayList<MeshInfo> infoList, String fileName, AffineTransform3dBase X) {
try {
File meshFile = new File(fileName);
if (!meshFile.exists()) {
System.out.println("Error: mesh file " + meshFile.getName() + " not found");
return;
}
if (meshFile.getName().endsWith(".obj") && !pointMesh.value) {
Class meshClass = Class.forName(className.value);
Class meshBaseClass = new PolygonalMesh().getClass();
if (meshClass == null) {
System.out.println("can't find class " + className.value);
return;
}
if (!meshBaseClass.isAssignableFrom(meshClass)) {
System.out.println(className.value + " is not an instance of " + meshBaseClass.getName());
return;
}
WavefrontReader reader = new WavefrontReader(meshFile);
reader.parse();
String[] names = reader.getPolyhedralGroupNames();
for (int i = 0; i < names.length; i++) {
if (meshClass == PolygonalMesh.class) {
PolygonalMesh mesh = (PolygonalMesh) meshClass.newInstance();
reader.setMesh(mesh, names[i]);
if (printBounds.value) {
doPrintBounds(mesh);
}
if (mesh.numVertices() > 0) {
System.out.print("mesh " + names[i] + ": " + mesh.numVertices() + " vertices, " + mesh.numFaces() + " faces, ");
if (mesh.isTriangular()) {
System.out.println("triangular");
} else if (mesh.isQuad()) {
System.out.println("quad");
} else {
System.out.println("polygonal");
}
mesh.transform(X);
if (names[i].equals("default")) {
infoList.add(new MeshInfo(meshFile.getName(), mesh));
} else {
infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
}
}
} else if (meshClass == PolylineMesh.class) {
PolylineMesh mesh = (PolylineMesh) meshClass.newInstance();
reader.setMesh(mesh, names[i]);
mesh.transform(X);
if (printBounds.value) {
doPrintBounds(mesh);
}
if (names[i].equals("default")) {
infoList.add(new MeshInfo(meshFile.getName(), mesh));
} else {
infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
}
} else if (meshClass == PointMesh.class) {
PointMesh mesh = (PointMesh) meshClass.newInstance();
reader.setMesh(mesh, names[i]);
mesh.transform(X);
if (printBounds.value) {
doPrintBounds(mesh);
}
if (names[i].equals("default")) {
infoList.add(new MeshInfo(meshFile.getName(), mesh));
} else {
infoList.add(new MeshInfo(meshFile.getName() + "(" + names[i] + ")", mesh));
}
}
}
} else {
MeshReader reader;
if (meshFile.getName().endsWith(".xyzb")) {
XyzbReader xyzbReader = new XyzbReader(meshFile);
xyzbReader.setSkip(skipCount.value);
reader = xyzbReader;
} else {
reader = new GenericMeshReader(meshFile);
}
MeshBase mesh = pointMesh.value ? new PointMesh() : null;
mesh = reader.readMesh(mesh);
if (printBounds.value) {
doPrintBounds(mesh);
}
infoList.add(new MeshInfo(meshFile.getName(), mesh));
}
} catch (Exception e) {
System.out.println("Error creating mesh");
e.printStackTrace();
}
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class MeshViewer method actionPerformed.
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("Edit render props")) {
PropertyDialog dialog = new PropertyDialog("Edit render props", new RenderPropsPanel(PropertyUtils.createProperties(myRenderProps)), "OK Cancel");
dialog.locateRight(this);
dialog.addGlobalValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent e) {
for (MeshBase mesh : myMeshes) {
mesh.setRenderProps(myRenderProps);
}
viewer.rerender();
}
});
myPopupManager.registerDialog(dialog);
dialog.setVisible(true);
} else if (cmd.equals("Edit viewer props")) {
PropertyDialog dialog = myPopupManager.createPropertyDialog("OK Cancel");
dialog.setVisible(true);
} else if (cmd.equals("Quit")) {
exit(0);
} else if (cmd.equals("Load mesh ...")) {
int retVal = myMeshChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myMeshChooser.getSelectedFile();
loadMesh(file);
}
} else if (cmd.equals("Save mesh ...")) {
int retVal = myMeshChooser.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = myMeshChooser.getSelectedFile();
saveMesh(file);
}
} else if (cmd.equals("Show mesh selector")) {
if (myMeshSelector == null) {
createMeshSelector();
myMeshSelector.setSelected(myMeshCursor);
}
myMeshSelector.setLocationRelativeTo(this);
myMeshSelector.setVisible(true);
} else if (cmd.equals("Hide mesh selector")) {
myMeshSelector.setVisible(false);
} else if (cmd.equals("Show property dialog ...")) {
setPropertyDialogVisible(true);
} else if (cmd.equals("Hide property dialog")) {
setPropertyDialogVisible(false);
} else if (cmd.equals("Background color")) {
setBackgroundColor();
} else if (cmd.equals("Perspective view")) {
viewer.setOrthographicView(false);
} else if (cmd.equals("Orthographic view")) {
viewer.setOrthographicView(true);
}
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class GenericMeshReader method readMesh.
public MeshBase readMesh(MeshBase mesh) throws IOException {
MeshBase newMesh = myReader.readMesh(mesh);
if (myReader instanceof PlyReader) {
myDataFormat = ((PlyReader) myReader).getDataFormat();
myFloatType = ((PlyReader) myReader).getFloatType();
} else if (myReader instanceof XyzbReader) {
myDataFormat = DataFormat.BINARY_LITTLE_ENDIAN;
myFloatType = FloatType.FLOAT;
} else {
myDataFormat = DataFormat.ASCII;
myFloatType = FloatType.ASCII;
}
return newMesh;
}
Aggregations