use of org.vcell.vis.vismesh.thrift.Vect3D in project vcell by virtualcell.
the class CartesianMeshMapping method fromMesh3DMembrane.
private VisMesh fromMesh3DMembrane(CartesianMesh cartesianMesh, String domainName) {
ISize size = cartesianMesh.getSize();
int numX = size.getX();
int numY = size.getY();
int dimension = 3;
Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(dimension, origin, extent);
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
List<MembraneElement> membraneElements = cartesianMesh.getMembraneElements(domainName);
for (MembraneElement membraneElement : membraneElements) {
// inside
int insideVolumeIndex = membraneElement.getInsideVolumeIndex();
int insideI = insideVolumeIndex % numX;
int insideJ = (insideVolumeIndex % (numX * numY)) / numX;
int insideK = insideVolumeIndex / (numX * numY);
Box3D insideBox = cartesianMesh.getVolumeElementBox(insideI, insideJ, insideK);
// outside
int outsideVolumeIndex = membraneElement.getOutsideVolumeIndex();
int outsideI = outsideVolumeIndex % numX;
int outsideJ = (outsideVolumeIndex % (numX * numY)) / numX;
int outsideK = outsideVolumeIndex / (numX * numY);
VisPoint p1Coord;
VisPoint p2Coord;
VisPoint p3Coord;
VisPoint p4Coord;
if (insideI == outsideI + 1) {
// x- z cross y
double x = insideBox.x_lo;
p1Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_lo);
p2Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_hi);
p3Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_hi);
p4Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_lo);
} else if (outsideI == insideI + 1) {
// x+ y cross z
double x = insideBox.x_hi;
p1Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_lo);
p2Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_lo);
p3Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_hi);
p4Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_hi);
} else if (insideJ == outsideJ + 1) {
// y- x cross z
double y = insideBox.y_lo;
p1Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_lo);
p2Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_lo);
p3Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_hi);
p4Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_hi);
} else if (outsideJ == insideJ + 1) {
// y+ z cross x
double y = insideBox.y_hi;
p1Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_lo);
p2Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_hi);
p3Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_hi);
p4Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_lo);
} else if (insideK == outsideK + 1) {
// z- y cross x
double z = insideBox.z_lo;
p1Coord = new VisPoint(insideBox.x_lo, insideBox.y_lo, z);
p2Coord = new VisPoint(insideBox.x_lo, insideBox.y_hi, z);
p3Coord = new VisPoint(insideBox.x_hi, insideBox.y_hi, z);
p4Coord = new VisPoint(insideBox.x_hi, insideBox.y_lo, z);
} else if (outsideK == insideK + 1) {
// z+ x cross y
double z = insideBox.z_hi;
p1Coord = new VisPoint(insideBox.x_lo, insideBox.y_lo, z);
p2Coord = new VisPoint(insideBox.x_hi, insideBox.y_lo, z);
p3Coord = new VisPoint(insideBox.x_hi, insideBox.y_hi, z);
p4Coord = new VisPoint(insideBox.x_lo, insideBox.y_hi, z);
} else {
throw new RuntimeException("inside/outside volume indices not reconciled in membraneElement " + membraneElement.getMembraneIndex() + " in domain " + domainName);
}
//
// make sure vertices are added to model without duplicates and get the assigned identifier.
//
String p1Key = toStringKey(p1Coord);
Integer i1 = pointDict.get(p1Key);
if (i1 == null) {
pointDict.put(p1Key, currPointIndex);
i1 = currPointIndex;
visMesh.addToPoints(p1Coord);
currPointIndex++;
}
String p2Key = toStringKey(p2Coord);
Integer i2 = pointDict.get(p2Key);
if (i2 == null) {
pointDict.put(p2Key, currPointIndex);
i2 = currPointIndex;
visMesh.addToPoints(p2Coord);
currPointIndex++;
}
String p3Key = toStringKey(p3Coord);
Integer i3 = pointDict.get(p3Key);
if (i3 == null) {
pointDict.put(p3Key, currPointIndex);
i3 = currPointIndex;
visMesh.addToPoints(p3Coord);
currPointIndex++;
}
String p4Key = toStringKey(p4Coord);
Integer i4 = pointDict.get(p4Key);
if (i4 == null) {
pointDict.put(p4Key, currPointIndex);
i4 = currPointIndex;
visMesh.addToPoints(p4Coord);
currPointIndex++;
}
VisPolygon quad = new VisPolygon(Arrays.asList(new Integer[] { i1, i2, i3, i4 }));
quad.setFiniteVolumeIndex(new FiniteVolumeIndex(membraneElement.getMembraneIndex(), cartesianMesh.getMembraneRegionIndex(membraneElement.getMembraneIndex())));
// print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
visMesh.addToPolygons(quad);
}
return visMesh;
}
use of org.vcell.vis.vismesh.thrift.Vect3D in project vcell by virtualcell.
the class ComsolMeshReader method read.
public static void read(VisMesh visMesh, File comsolFile) throws IOException {
ArrayList<Field> fields = new ArrayList<Field>();
try (BufferedReader br = new BufferedReader(new FileReader(comsolFile))) {
//
// read header lines
//
String model = readStringParameter(br.readLine(), "Model");
String version = readStringParameter(br.readLine(), "Version");
String date = readStringParameter(br.readLine(), "Date");
int dimension = readIntegerParameter(br.readLine(), "Dimension");
int numNodes = readIntegerParameter(br.readLine(), "Nodes");
int numElements = readIntegerParameter(br.readLine(), "Elements");
int numExpressions = readIntegerParameter(br.readLine(), "Expressions");
String description = readStringParameter(br.readLine(), "Description");
String lengthUnit = readStringParameter(br.readLine(), "Length unit");
visMesh.setDimension(dimension);
//
// read coordinates (and set points, origin and extent on VisMesh
//
readCoordinates(br, visMesh, numNodes);
List<VisPoint> points = visMesh.getPoints();
double minX = Double.POSITIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double minZ = Double.POSITIVE_INFINITY;
double maxX = Double.NEGATIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
double maxZ = Double.NEGATIVE_INFINITY;
for (VisPoint p : points) {
minX = Math.min(p.x, minX);
minY = Math.min(p.y, minY);
minZ = Math.min(p.z, minZ);
maxX = Math.max(p.x, maxX);
maxY = Math.max(p.y, maxY);
maxZ = Math.max(p.z, maxZ);
}
visMesh.setExtent(new Vect3D(maxX - minX, maxY - minY, maxZ - minZ));
visMesh.setOrigin(new Vect3D(minX, minY, minZ));
//
// read triangles
//
readElements(br, visMesh, numElements);
//
for (int fieldIndex = 0; fieldIndex < numExpressions; fieldIndex++) {
fields.add(readField(br, numNodes));
}
}
VtkService vtkService = VtkService.getInstance();
String prefix = comsolFile.getName().replace(".comsoldat", "");
File vtuFile = new File(comsolFile.getParentFile(), prefix + ".vtu");
File indexFile = new File(comsolFile.getParentFile(), prefix + ".comsolindex");
vtkService.writeComsolVtkGridAndIndexData(visMesh, "domain", vtuFile, indexFile);
HashSet<Double> times = new HashSet<Double>();
for (Field field : fields) {
times.add(field.time);
int timeIndex = times.size() - 1;
File outputMeshFile = new File(comsolFile.getParentFile(), prefix + "_" + field.name + "_" + timeIndex + ".vtu");
VisMeshUtils.writePointDataToVtu(vtuFile, field.name, field.data, outputMeshFile);
}
}
use of org.vcell.vis.vismesh.thrift.Vect3D in project vcell by virtualcell.
the class DebugWriteProblem method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
VisMesh visMesh = new VisMesh(3, new Vect3D(0, 0, 0), new Vect3D(3, 1, 1));
VisPoint[] points0 = new VisPoint[] { new VisPoint(0, 0, 0), new VisPoint(1, 0, 0), new VisPoint(0, 1, 0), new VisPoint(0, 0, 1) };
visMesh.addToPoints(points0[0]);
visMesh.addToPoints(points0[1]);
visMesh.addToPoints(points0[2]);
visMesh.addToPoints(points0[3]);
List<PolyhedronFace> faces0 = Arrays.asList(new PolyhedronFace(Arrays.asList(0, 1, 3)), new PolyhedronFace(Arrays.asList(0, 3, 2)), new PolyhedronFace(Arrays.asList(0, 2, 1)), new PolyhedronFace(Arrays.asList(1, 3, 2)));
int level = 0;
int boxNumber = 0;
int boxIndex = 0;
int fraction = 0;
VisIrregularPolyhedron genPolyhedra0 = new VisIrregularPolyhedron(faces0);
genPolyhedra0.setChomboVolumeIndex(new ChomboVolumeIndex(level, boxNumber, boxIndex, fraction));
visMesh.addToIrregularPolyhedra(genPolyhedra0);
// VisPoint[] points1 = new VisPoint[] {
// new VisPoint(2+0, 0, 0),
// new VisPoint(2+1, 0, 0),
// new VisPoint(2+0, 1, 0),
// new VisPoint(2+0, 0, 1)
// };
//
// visMesh.addPoint(points1[0]);
// visMesh.addPoint(points1[1]);
// visMesh.addPoint(points1[2]);
// visMesh.addPoint(points1[3]);
//
// vtkUnstructuredGrid vtkgrid = VtkGridUtils.getVolumeVtkGrid(visMesh);
// String filenameASCII = "testASCII.vtk";
// String filenameBinary = "testBinary.vtk";
// VtkGridUtils.writeXML(vtkgrid, filenameASCII, true);
// VtkGridUtils.writeXML(vtkgrid, filenameBinary, false);
// vtkgrid = VtkGridUtils.read(filenameBinary);
// vtkgrid.BuildLinks();
// SimpleVTKViewer simpleViewer = new SimpleVTKViewer();
// String[] varNames = visDomain.getVisMeshData().getVarNames();
// simpleViewer.showGrid(vtkgrid, varNames[0], varNames[1]);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of org.vcell.vis.vismesh.thrift.Vect3D in project vcell by virtualcell.
the class CartesianMeshMapping method fromMesh2DVolume.
private VisMesh fromMesh2DVolume(CartesianMesh cartesianMesh, String domainName) {
ISize size = cartesianMesh.getSize();
int numX = size.getX();
int numY = size.getY();
int numZ = size.getZ();
int dimension = 2;
int z = 0;
Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(dimension, origin, extent);
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
List<Integer> volumeRegionIDs = cartesianMesh.getVolumeRegionIDs(domainName);
int volumeIndex = 0;
for (int k = 0; k < numZ; k++) {
for (int j = 0; j < numY; j++) {
for (int i = 0; i < numX; i++) {
int regionIndex = cartesianMesh.getVolumeRegionIndex(volumeIndex);
if (volumeRegionIDs.contains(regionIndex)) {
Box3D element = cartesianMesh.getVolumeElementBox(i, j, k);
double minX = element.x_lo;
double maxX = element.x_hi;
double minY = element.y_lo;
double maxY = element.y_hi;
//
// counter clockwise points for a VisPolygon ... initially a quad ... then may be
//
// minX,minY
// minX,maxY
// maxX,maxY
// maxX,minY
//
VisPoint p1Coord = new VisPoint(minX, minY, z);
String p1Key = toStringKey(p1Coord);
Integer i1 = pointDict.get(p1Key);
if (i1 == null) {
pointDict.put(p1Key, currPointIndex);
i1 = currPointIndex;
visMesh.addToPoints(p1Coord);
currPointIndex++;
}
VisPoint p2Coord = new VisPoint(minX, maxY, z);
String p2Key = toStringKey(p2Coord);
Integer i2 = pointDict.get(p2Key);
if (i2 == null) {
pointDict.put(p2Key, currPointIndex);
i2 = currPointIndex;
visMesh.addToPoints(p2Coord);
currPointIndex++;
}
VisPoint p3Coord = new VisPoint(maxX, maxY, z);
String p3Key = toStringKey(p3Coord);
Integer i3 = pointDict.get(p3Key);
if (i3 == null) {
pointDict.put(p3Key, currPointIndex);
i3 = currPointIndex;
visMesh.addToPoints(p3Coord);
currPointIndex++;
}
VisPoint p4Coord = new VisPoint(maxX, minY, z);
String p4Key = toStringKey(p4Coord);
Integer i4 = pointDict.get(p4Key);
if (i4 == null) {
pointDict.put(p4Key, currPointIndex);
i4 = currPointIndex;
visMesh.addToPoints(p4Coord);
currPointIndex++;
}
VisPolygon quad = new VisPolygon(Arrays.asList(new Integer[] { i1, i2, i3, i4 }));
quad.setFiniteVolumeIndex(new FiniteVolumeIndex(volumeIndex, cartesianMesh.getVolumeRegionIndex(volumeIndex)));
// print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
visMesh.addToPolygons(quad);
}
// end if
volumeIndex++;
}
// end i
}
// end j
}
return visMesh;
}
use of org.vcell.vis.vismesh.thrift.Vect3D in project vcell by virtualcell.
the class CartesianMeshMapping method fromMesh3DVolume.
private VisMesh fromMesh3DVolume(CartesianMesh cartesianMesh, String domainName) {
ISize size = cartesianMesh.getSize();
int numX = size.getX();
int numY = size.getY();
int numZ = size.getZ();
int dimension = 3;
Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(dimension, origin, extent);
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
List<Integer> volumeRegionIDs = cartesianMesh.getVolumeRegionIDs(domainName);
int volumeIndex = 0;
for (int k = 0; k < numZ; k++) {
for (int j = 0; j < numY; j++) {
for (int i = 0; i < numX; i++) {
int regionIndex = cartesianMesh.getVolumeRegionIndex(volumeIndex);
if (volumeRegionIDs.contains(regionIndex)) {
Box3D element = cartesianMesh.getVolumeElementBox(i, j, k);
double minX = element.x_lo;
double maxX = element.x_hi;
double minY = element.y_lo;
double maxY = element.y_hi;
double minZ = element.z_lo;
double maxZ = element.z_hi;
//
// points for a VisPolyhedra ... initially a hex ... then may be clipped
//
// p6-------------------p7
// /| /|
// / | / |
// p4-------------------p5 |
// | | | |
// | | | |
// | | | | z y
// | p2................|..p3 | /
// | / | / | /
// |/ |/ |/
// p0-------------------p1 O----- x
//
// p0 = (X-,Y-,Z-)
// p1 = (X+,Y-,Z-)
// p2 = (X-,Y+,Z-)
// p3 = (X+,Y+,Z-)
// p4 = (X-,Y-,Z+)
// p5 = (X+,Y-,Z+)
// p6 = (X-,Y+,Z+)
// p7 = (X+,Y+,Z+)
//
VisPoint[] visPoints = { // p0
new VisPoint(minX, minY, minZ), // p1
new VisPoint(maxX, minY, minZ), // p2
new VisPoint(minX, maxY, minZ), // p3
new VisPoint(maxX, maxY, minZ), // p4
new VisPoint(minX, minY, maxZ), // p5
new VisPoint(maxX, minY, maxZ), // p6
new VisPoint(minX, maxY, maxZ), // p7
new VisPoint(maxX, maxY, maxZ) };
Integer[] indices = new Integer[8];
for (int v = 0; v < 8; v++) {
VisPoint visPoint = visPoints[v];
String key = toStringKey(visPoint);
Integer p = pointDict.get(key);
if (p == null) {
pointDict.put(key, currPointIndex);
p = currPointIndex;
visMesh.addToPoints(visPoint);
currPointIndex++;
}
indices[v] = p;
}
VisVoxel voxel = new VisVoxel(Arrays.asList(indices));
voxel.setFiniteVolumeIndex(new FiniteVolumeIndex(volumeIndex, cartesianMesh.getVolumeRegionIndex(volumeIndex)));
// print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
visMesh.addToVisVoxels(voxel);
}
// end if
volumeIndex++;
}
// end for i
}
// end for j
}
// end for k
return visMesh;
}
Aggregations