use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class ChomboMeshMapping method fromMeshData3D.
private VisMesh fromMeshData3D(ChomboMeshData chomboMeshData, ChomboCombinedVolumeMembraneDomain chomboCombinedVolumeMembraneDomain) {
int dimension = chomboMeshData.getMesh().getDimension();
if (dimension != 3) {
throw new RuntimeException("expecting a 3D mesh");
}
ChomboMesh chomboMesh = chomboMeshData.getMesh();
ChomboLevel finestLevel = chomboMesh.getLevel(chomboMesh.getNumLevels() - 1);
int finestAbsRefinement = finestLevel.getAbsoluteRefinement();
ISize size = finestLevel.getSize();
int numX = size.getX();
int numY = size.getY();
int numZ = size.getZ();
Vect3D origin = new Vect3D(chomboMesh.getOrigin().x, chomboMesh.getOrigin().y, chomboMesh.getOrigin().z);
Vect3D extent = new Vect3D(chomboMesh.getExtent().x, chomboMesh.getExtent().y, chomboMesh.getExtent().z);
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(chomboMesh.getDimension(), origin, extent);
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
double originX = chomboMesh.getOrigin().x;
double originY = chomboMesh.getOrigin().y;
double originZ = chomboMesh.getOrigin().z;
double extentX = chomboMesh.getExtent().x;
double extentY = chomboMesh.getExtent().y;
double extentZ = chomboMesh.getExtent().z;
ChomboBoundaries chomboBoundaries = chomboMesh.getBoundaries();
for (ChomboBoundaries.Point chomboPoint : chomboBoundaries.getPoints()) {
double px = chomboPoint.x;
double py = chomboPoint.y;
double pz = chomboPoint.z;
px = (px - originX) * (numX) / extentX * 2 - 1;
py = (py - originY) * (numY) / extentY * 2 - 1;
pz = (pz - originZ) * (numZ) / extentZ * 2 - 1;
VisPoint newVisPoint = new VisPoint(px, py, pz);
String coordKey = toStringKey(newVisPoint);
pointDict.put(coordKey, currPointIndex);
visMesh.addToPoints(newVisPoint);
visMesh.addToSurfacePoints(newVisPoint);
currPointIndex += 1;
}
for (ChomboBoundaries.SurfaceTriangle surfaceTriangle : chomboBoundaries.getSurfaceTriangles()) {
List<Integer> vertices = Arrays.asList(new Integer[] { surfaceTriangle.getP1(), surfaceTriangle.getP2(), surfaceTriangle.getP3() });
org.vcell.vis.vismesh.thrift.Face face = org.vcell.vis.vismesh.thrift.Face.valueOf(surfaceTriangle.getFace().name());
VisSurfaceTriangle newVisSurfaceTriangle = new VisSurfaceTriangle(vertices, face);
newVisSurfaceTriangle.setChomboSurfaceIndex(new ChomboSurfaceIndex(surfaceTriangle.getChomboIndex()));
visMesh.addToSurfaceTriangles(newVisSurfaceTriangle);
}
for (int levelIndex = 0; levelIndex < chomboMesh.getNumLevels(); levelIndex++) {
ChomboLevelData chomboLevelData = chomboMeshData.getLevelData(levelIndex);
ChomboLevel currLevel = chomboMesh.getLevel(levelIndex);
int currAbsRefinement = currLevel.getAbsoluteRefinement();
Covering covering = currLevel.getCovering();
int[] levelMap = covering.getLevelMap();
int[] boxNumberMap = covering.getBoxNumberMap();
int[] boxIndexMap = covering.getBoxIndexMap();
int levelNumX = currLevel.getSize().getX();
int levelNumY = currLevel.getSize().getY();
int levelNumZ = currLevel.getSize().getZ();
for (int x = 0; x < levelNumX; x++) {
for (int y = 0; y < levelNumY; y++) {
for (int z = 0; z < levelNumZ; z++) {
int mapIndex = x + y * levelNumX + z * levelNumX * levelNumY;
if (levelMap[mapIndex] == levelIndex) {
//
// if fraction (volume fraction of element in box) is 0 ... then skip this element
//
int boxNumber = boxNumberMap[mapIndex];
int boxIndex = boxIndexMap[mapIndex];
double fraction = chomboLevelData.getCellFraction(currLevel, boxNumber, boxIndex);
if (fraction > 0) {
//
// add cell
//
ChomboBox chomboBox = new ChomboBox(currLevel, x, x, y, y, z, z, dimension).getProjectedBox(currAbsRefinement, finestAbsRefinement);
double minX = 2 * chomboBox.getMinX() - 1;
double maxX = 2 * chomboBox.getMaxX() + 1;
double minY = 2 * chomboBox.getMinY() - 1;
double maxY = 2 * chomboBox.getMaxY() + 1;
double minZ = 2 * chomboBox.getMinZ() - 1;
double maxZ = 2 * chomboBox.getMaxZ() + 1;
//
// 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 i = pointDict.get(key);
if (i == null) {
pointDict.put(key, currPointIndex);
i = currPointIndex;
visMesh.addToPoints(visPoint);
currPointIndex++;
}
indices[v] = i;
}
VisVoxel voxel = new VisVoxel(Arrays.asList(indices));
voxel.setChomboVolumeIndex(new ChomboVolumeIndex(levelIndex, boxNumber, boxIndex, fraction));
// print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
visMesh.addToVisVoxels(voxel);
}
}
}
}
}
}
cropVoxels(visMesh, chomboBoundaries, chomboCombinedVolumeMembraneDomain);
return visMesh;
}
use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class ChomboVtkFileWriter method writeEmptyMeshFiles.
public File[] writeEmptyMeshFiles(ChomboFiles chomboFiles, File destinationDirectory, ProgressListener progressListener) throws IOException, MathException, DataAccessException {
ArrayList<File> meshFiles = new ArrayList<File>();
int timeIndex = 0;
HashMap<String, VisMesh> domainMeshMap = new HashMap<String, VisMesh>();
ChomboDataset chomboDataset;
try {
chomboDataset = ChomboFileReader.readDataset(chomboFiles, chomboFiles.getTimeIndices().get(timeIndex));
} catch (Exception e) {
throw new DataAccessException("failed to read Chombo Dataset: " + e.getMessage(), e);
}
for (ChomboCombinedVolumeMembraneDomain chomboCombinedVolumeMembraneDomain : chomboDataset.getCombinedVolumeMembraneDomains()) {
ChomboMeshData chomboMeshData = chomboCombinedVolumeMembraneDomain.getChomboMeshData();
ChomboMeshMapping chomboMeshMapping = new ChomboMeshMapping();
VisMesh visMesh = domainMeshMap.get(chomboCombinedVolumeMembraneDomain.getVolumeDomainName());
if (visMesh == null) {
visMesh = chomboMeshMapping.fromMeshData(chomboMeshData, chomboCombinedVolumeMembraneDomain);
domainMeshMap.put(chomboCombinedVolumeMembraneDomain.getVolumeDomainName(), visMesh);
}
String volumeDomainName = chomboCombinedVolumeMembraneDomain.getVolumeDomainName();
//
// write volume mesh file
//
{
File volumeMeshFile = getVtuMeshFileName(destinationDirectory, chomboFiles, volumeDomainName);
File chomboIndexDataFile = getChomboIndexDataFileName(destinationDirectory, chomboFiles, volumeDomainName);
VtkService.getInstance().writeChomboVolumeVtkGridAndIndexData(visMesh, volumeDomainName, volumeMeshFile, chomboIndexDataFile);
meshFiles.add(volumeMeshFile);
}
if (chomboMeshData.getMembraneVarData().size() > 0) {
//
// write membrane mesh file
//
String membraneDomainName = chomboCombinedVolumeMembraneDomain.getMembraneDomainName();
File membraneMeshFile = getVtuMeshFileName(destinationDirectory, chomboFiles, membraneDomainName);
File membraneIndexDataFile = getChomboIndexDataFileName(destinationDirectory, chomboFiles, membraneDomainName);
VtkService.getInstance().writeChomboMembraneVtkGridAndIndexData(visMesh, membraneDomainName, membraneMeshFile, membraneIndexDataFile);
meshFiles.add(membraneMeshFile);
}
}
return meshFiles.toArray(new File[0]);
}
use of org.vcell.vis.vismesh.thrift.VisMesh 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.VisMesh 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;
}
use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class MovingBoundaryMeshMapping method fromReader.
public VisMesh fromReader(MovingBoundaryReader reader, DomainType domainType, int timeIndex) {
MeshInfo meshInfo = reader.getMeshInfo();
ISize size = new ISize(meshInfo.xinfo.number(), meshInfo.yinfo.number(), 1);
Plane plane = reader.getPlane(timeIndex);
int numX = size.getX();
int numY = size.getY();
int dimension = 2;
Vect3D origin = new Vect3D(meshInfo.xinfo.start, meshInfo.yinfo.start, 0.0);
Vect3D extent = new Vect3D(meshInfo.xinfo.end - meshInfo.xinfo.start, meshInfo.yinfo.end - meshInfo.yinfo.start, 1.0);
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(dimension, origin, extent);
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
PointIndex pointIndex = reader.getPointIndex();
if (domainType == DomainType.INSIDE || domainType == DomainType.OUTSIDE) {
int volumeIndex = 0;
for (int j = 0; j < numY; j++) {
for (int i = 0; i < numX; i++) {
Element mbElement = plane.get(i, j);
if ((domainType == DomainType.INSIDE && (mbElement.position == Position.INSIDE || mbElement.position == Position.BOUNDARY)) || (domainType == DomainType.OUTSIDE && mbElement.position == Position.OUTSIDE)) {
ArrayList<Integer> elementVisIndices = new ArrayList<Integer>();
int[] elementPointIndices = mbElement.boundary();
// first and last index is same
int numUniqueElementIndices = elementPointIndices.length - 1;
for (int p = 0; p < numUniqueElementIndices; p++) {
Vect3Didx point = pointIndex.lookup(elementPointIndices[p]);
VisPoint visPoint = new VisPoint(point.x, point.y, point.z);
String visPointKey = toStringKey(visPoint);
Integer visPointIndex = pointDict.get(visPointKey);
if (visPointIndex == null) {
visPointIndex = currPointIndex++;
pointDict.put(visPointKey, visPointIndex);
visMesh.addToPoints(visPoint);
}
elementVisIndices.add(visPointIndex);
}
VisPolygon polygon = new VisPolygon(elementVisIndices);
polygon.setMovingBoundaryVolumeIndex(new MovingBoundaryVolumeIndex(volumeIndex));
visMesh.addToPolygons(polygon);
volumeIndex++;
}
// end if
}
// end i
}
// end j
} else if (domainType == DomainType.MEMBRANE) {
throw new RuntimeException("DomainType MEMBRANE not yet implemented for moving boundary vtk processing");
}
return visMesh;
}
Aggregations