use of cbit.vcell.geometry.surface.Quadrilateral in project vcell by virtualcell.
the class RegionImage method addQuadToSurface.
private void addQuadToSurface(Vector<Vector<Quadrilateral>> surfQuadsV, int[][] mapInsideOutsideToSurface, int indexNeighbor1, int neighbor1, int indexNeighbor2, int neighbor2, cbit.vcell.geometry.surface.Node[] nodeArr, int numRegions, MembraneElementIdentifier.PerpendicularTo plane) {
Quadrilateral surfQuad = new Quadrilateral(nodeArr, indexNeighbor1, indexNeighbor2);
if (neighbor1 > neighbor2) {
surfQuad.reverseDirection();
int temp = neighbor1;
neighbor1 = neighbor2;
neighbor2 = temp;
}
if (mapInsideOutsideToSurface[neighbor1] == null) {
mapInsideOutsideToSurface[neighbor1] = new int[numRegions];
Arrays.fill(mapInsideOutsideToSurface[neighbor1], -1);
}
if (mapInsideOutsideToSurface[neighbor1][neighbor2] == -1) {
mapInsideOutsideToSurface[neighbor1][neighbor2] = surfQuadsV.size();
surfQuadsV.add(new Vector<Quadrilateral>());
}
int surfIndex = mapInsideOutsideToSurface[neighbor1][neighbor2];
surfQuadsV.elementAt(surfIndex).add(surfQuad);
try {
if (!bMembraneNeighborCalculationFailed) {
updateEdgeMap(nodeArr, surfIndex, surfQuadsV.elementAt(surfIndex).size() - 1, plane);
}
} catch (Exception e) {
e.printStackTrace();
bMembraneNeighborCalculationFailed = true;
}
}
use of cbit.vcell.geometry.surface.Quadrilateral in project vcell by virtualcell.
the class RegionImage method generateSurfaceCollection.
private void generateSurfaceCollection(int numRegions, // int[] mapImageIndexToLinkRegion,int[] mapLinkRegionToDistinctRegion,
VCImage vcImage, BitSet xSurfElements, BitSet ySurfElements, BitSet zSurfElements, int dimension, Extent extent, Origin origin) {
bMembraneNeighborCalculationFailed = false;
int masterIndex = 0;
double dX = extent.getX() / (vcImage.getNumX() - 1);
double dY = extent.getY() / (vcImage.getNumY() - 1);
double dZ = extent.getZ() / (vcImage.getNumZ() - 1);
//
double loX = origin.getX() - 0.5 * dX;
double loY = origin.getY() - 0.5 * dY;
double loZ = origin.getZ() - 0.5 * dZ;
Vector<Vector<Quadrilateral>> surfQuadsV = new Vector<Vector<Quadrilateral>>();
int[][] mapInsideOutsideToSurface = new int[numRegions][];
Vector<cbit.vcell.geometry.surface.Node> nodeListV = new Vector<cbit.vcell.geometry.surface.Node>();
cbit.vcell.geometry.surface.Node[][][] mapImageIndexToNode = new cbit.vcell.geometry.surface.Node[2][vcImage.getNumY() + 1][vcImage.getNumX() + 1];
double zComp, zpComp;
double yComp, ypComp;
double xComp, xpComp;
final int yStep = vcImage.getNumX();
final int zStep = vcImage.getNumX() * vcImage.getNumY();
boolean bMvXm, bMvYm, bMvZm;
boolean bMvXp, bMvYp, bMvZp;
double xmEdge = origin.getX();
double xpEdge = origin.getX() + extent.getX();
double ymEdge = origin.getY();
double ypEdge = origin.getY() + extent.getY();
double zmEdge = origin.getZ();
double zpEdge = origin.getZ() + extent.getZ();
for (int zIndex = 0; zIndex < vcImage.getNumZ(); zIndex++) {
mapImageIndexToNode[0] = mapImageIndexToNode[1];
mapImageIndexToNode[1] = new cbit.vcell.geometry.surface.Node[vcImage.getNumY() + 1][vcImage.getNumX() + 1];
zComp = loZ + zIndex * dZ;
zpComp = zComp + dZ;
bMvZm = (zIndex != 0);
bMvZp = (zIndex != (vcImage.getNumZ() - 1));
for (int yIndex = 0; yIndex < vcImage.getNumY(); yIndex++) {
yComp = loY + yIndex * dY;
ypComp = yComp + dY;
bMvYm = (yIndex != 0);
bMvYp = (yIndex != (vcImage.getNumY() - 1));
for (int xIndex = 0; xIndex < vcImage.getNumX(); xIndex++) {
if (xSurfElements.get(masterIndex)) {
bMvXp = (xIndex != (vcImage.getNumX() - 1));
xpComp = loX + (xIndex + 1) * dX;
cbit.vcell.geometry.surface.Node[] nodeArr = new cbit.vcell.geometry.surface.Node[4];
nodeArr[0] = mapImageIndexToNode[0][yIndex][xIndex + 1];
if (nodeArr[0] == null) {
// nodeArr[0] = new cbit.vcell.geometry.surface.Node(xpComp,yComp,zComp);
nodeArr[0] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYm ? yComp : ymEdge), (bMvZm ? zComp : zmEdge));
nodeArr[0].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[0]);
nodeArr[0].setMoveX(bMvXp);
nodeArr[0].setMoveY(bMvYm);
nodeArr[0].setMoveZ(bMvZm);
mapImageIndexToNode[0][yIndex][xIndex + 1] = nodeArr[0];
}
nodeArr[1] = mapImageIndexToNode[0][yIndex + 1][xIndex + 1];
if (nodeArr[1] == null) {
// nodeArr[1] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zComp);
nodeArr[1] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZm ? zComp : zmEdge));
nodeArr[1].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[1]);
nodeArr[1].setMoveX(bMvXp);
nodeArr[1].setMoveY(bMvYp);
nodeArr[1].setMoveZ(bMvZm);
mapImageIndexToNode[0][yIndex + 1][xIndex + 1] = nodeArr[1];
}
nodeArr[2] = mapImageIndexToNode[1][yIndex + 1][xIndex + 1];
if (nodeArr[2] == null) {
// nodeArr[2] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zpComp);
nodeArr[2] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[2].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[2]);
nodeArr[2].setMoveX(bMvXp);
nodeArr[2].setMoveY(bMvYp);
nodeArr[2].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex + 1][xIndex + 1] = nodeArr[2];
}
nodeArr[3] = mapImageIndexToNode[1][yIndex][xIndex + 1];
if (nodeArr[3] == null) {
// nodeArr[3] = new cbit.vcell.geometry.surface.Node(xpComp,yComp,zpComp);
nodeArr[3] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYm ? yComp : ymEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[3].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[3]);
nodeArr[3].setMoveX(bMvXp);
nodeArr[3].setMoveY(bMvYm);
nodeArr[3].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex][xIndex + 1] = nodeArr[3];
}
addQuadToSurface(surfQuadsV, mapInsideOutsideToSurface, // masterIndex+1,mapImageIndexToRegionIndex.getValue(masterIndex+1),
masterIndex, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]], masterIndex + 1, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex + 1]], nodeArr, numRegions, MembraneElementIdentifier.PerpendicularTo.X);
// surfQuad =
// new Quadrilateral(nodeArr,
// mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]],
// mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex+1]]);
// if(surfQuad.getVolIndexNeighbor1() > surfQuad.getVolIndexNeighbor2()){
// surfQuad.reverseDirection();
// }
// if(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()] == null){
// mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()] = new int[numRegions];
// Arrays.fill(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()], -1);
// }
// if(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()][surfQuad.getVolIndexNeighbor2()] == -1){
// mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()][surfQuad.getVolIndexNeighbor2()] = surfQuadsV.size();
// surfQuadsV.add(new Vector<Quadrilateral>());
// }
// surfQuadsV.elementAt(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()][surfQuad.getVolIndexNeighbor2()]).add(surfQuad);
}
if (ySurfElements.get(masterIndex)) {
bMvXm = (xIndex != 0);
bMvXp = (xIndex != (vcImage.getNumX() - 1));
xComp = loX + xIndex * dX;
xpComp = loX + (xIndex + 1) * dX;
cbit.vcell.geometry.surface.Node[] nodeArr = new cbit.vcell.geometry.surface.Node[4];
nodeArr[0] = mapImageIndexToNode[0][yIndex + 1][xIndex + 1];
if (nodeArr[0] == null) {
// nodeArr[0] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zComp);
nodeArr[0] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZm ? zComp : zmEdge));
nodeArr[0].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[0]);
nodeArr[0].setMoveX(bMvXp);
nodeArr[0].setMoveY(bMvYp);
nodeArr[0].setMoveZ(bMvZm);
mapImageIndexToNode[0][yIndex + 1][xIndex + 1] = nodeArr[0];
}
nodeArr[1] = mapImageIndexToNode[0][yIndex + 1][xIndex];
if (nodeArr[1] == null) {
// nodeArr[1] = new cbit.vcell.geometry.surface.Node(xComp,ypComp,zComp);
nodeArr[1] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYp ? ypComp : ypEdge), (bMvZm ? zComp : zmEdge));
nodeArr[1].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[1]);
nodeArr[1].setMoveX(bMvXm);
nodeArr[1].setMoveY(bMvYp);
nodeArr[1].setMoveZ(bMvZm);
mapImageIndexToNode[0][yIndex + 1][xIndex] = nodeArr[1];
}
nodeArr[2] = mapImageIndexToNode[1][yIndex + 1][xIndex];
if (nodeArr[2] == null) {
// nodeArr[2] = new cbit.vcell.geometry.surface.Node(xComp,ypComp,zpComp);
nodeArr[2] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[2].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[2]);
nodeArr[2].setMoveX(bMvXm);
nodeArr[2].setMoveY(bMvYp);
nodeArr[2].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex + 1][xIndex] = nodeArr[2];
}
nodeArr[3] = mapImageIndexToNode[1][yIndex + 1][xIndex + 1];
if (nodeArr[3] == null) {
// nodeArr[3] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zpComp);
nodeArr[3] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[3].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[3]);
nodeArr[3].setMoveX(bMvXp);
nodeArr[3].setMoveY(bMvYp);
nodeArr[3].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex + 1][xIndex + 1] = nodeArr[3];
}
addQuadToSurface(surfQuadsV, mapInsideOutsideToSurface, // masterIndex+yStep,mapImageIndexToRegionIndex.getValue(masterIndex+yStep),
masterIndex, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]], masterIndex + yStep, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex + yStep]], nodeArr, numRegions, MembraneElementIdentifier.PerpendicularTo.Y);
// surfQuad =
// new Quadrilateral(nodeArr,
// mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]],
// mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex+yStep]]);
// if(surfQuad.getVolIndexNeighbor1() > surfQuad.getVolIndexNeighbor2()){
// surfQuad.reverseDirection();
// }
// surfQuadsV[surfQuad.getVolIndexNeighbor1()].add(surfQuad);
}
if (zSurfElements.get(masterIndex)) {
bMvXm = (xIndex != 0);
bMvXp = (xIndex != (vcImage.getNumX() - 1));
xComp = loX + xIndex * dX;
xpComp = loX + (xIndex + 1) * dX;
cbit.vcell.geometry.surface.Node[] nodeArr = new cbit.vcell.geometry.surface.Node[4];
nodeArr[0] = mapImageIndexToNode[1][yIndex][xIndex + 1];
if (nodeArr[0] == null) {
// nodeArr[0] = new cbit.vcell.geometry.surface.Node(xpComp,yComp,zpComp);
nodeArr[0] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYm ? yComp : ymEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[0].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[0]);
nodeArr[0].setMoveX(bMvXp);
nodeArr[0].setMoveY(bMvYm);
nodeArr[0].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex][xIndex + 1] = nodeArr[0];
}
nodeArr[1] = mapImageIndexToNode[1][yIndex + 1][xIndex + 1];
if (nodeArr[1] == null) {
// nodeArr[1] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zpComp);
nodeArr[1] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[1].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[1]);
nodeArr[1].setMoveX(bMvXp);
nodeArr[1].setMoveY(bMvYp);
nodeArr[1].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex + 1][xIndex + 1] = nodeArr[1];
}
nodeArr[2] = mapImageIndexToNode[1][yIndex + 1][xIndex];
if (nodeArr[2] == null) {
// nodeArr[2] = new cbit.vcell.geometry.surface.Node(xComp,ypComp,zpComp);
nodeArr[2] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[2].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[2]);
nodeArr[2].setMoveX(bMvXm);
nodeArr[2].setMoveY(bMvYp);
nodeArr[2].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex + 1][xIndex] = nodeArr[2];
}
nodeArr[3] = mapImageIndexToNode[1][yIndex][xIndex];
if (nodeArr[3] == null) {
// nodeArr[3] = new cbit.vcell.geometry.surface.Node(xComp,yComp,zpComp);
nodeArr[3] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYm ? yComp : ymEdge), (bMvZp ? zpComp : zpEdge));
nodeArr[3].setGlobalIndex(nodeListV.size());
nodeListV.add(nodeArr[3]);
nodeArr[3].setMoveX(bMvXm);
nodeArr[3].setMoveY(bMvYm);
nodeArr[3].setMoveZ(bMvZp);
mapImageIndexToNode[1][yIndex][xIndex] = nodeArr[3];
}
addQuadToSurface(surfQuadsV, mapInsideOutsideToSurface, // masterIndex+zStep,mapImageIndexToRegionIndex.getValue(masterIndex+zStep),
masterIndex, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]], masterIndex + zStep, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex + zStep]], nodeArr, numRegions, MembraneElementIdentifier.PerpendicularTo.Z);
// surfQuad =
// new Quadrilateral(nodeArr,
// mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]],
// mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex+zStep]]);
// if(surfQuad.getVolIndexNeighbor1() > surfQuad.getVolIndexNeighbor2()){
// surfQuad.reverseDirection();
// }
// surfQuadsV[surfQuad.getVolIndexNeighbor1()].add(surfQuad);
}
masterIndex += 1;
}
}
}
remapQuadIndexes = new int[surfQuadsV.size()][];
int quadCounter = 0;
surfaceCollection = new SurfaceCollection();
cbit.vcell.geometry.surface.Node[] allNodes = new cbit.vcell.geometry.surface.Node[nodeListV.size()];
nodeListV.copyInto(allNodes);
surfaceCollection.setNodes(allNodes);
for (int surfaceIndex = 0; surfaceIndex < surfQuadsV.size(); surfaceIndex++) {
Vector<Quadrilateral> surfV = surfQuadsV.elementAt(surfaceIndex);
remapQuadIndexes[surfaceIndex] = new int[surfV.size()];
OrigSurface surface = new OrigSurface(// surfV.elementAt(0).getVolIndexNeighbor1(),
mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[surfV.elementAt(0).getVolIndexNeighbor1()]], // surfV.elementAt(0).getVolIndexNeighbor2()
mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[surfV.elementAt(0).getVolIndexNeighbor2()]]);
for (int faceIndex = 0; faceIndex < surfV.size(); faceIndex++) {
surface.addPolygon(surfV.elementAt(faceIndex));
remapQuadIndexes[surfaceIndex][faceIndex] = quadCounter;
quadIndexToSurfAndFace.add(new SurfAndFace(surfaceIndex, faceIndex));
quadCounter++;
}
surfaceCollection.addSurface(surface);
}
try {
if (!bMembraneNeighborCalculationFailed) {
calculateNeighbors();
surfaceCollection.setMembraneEdgeNeighbors(membraneEdgeNeighbors);
}
} catch (Exception e) {
// If MembraneNeighbors fails somewhere let Surfacecollection generate without membraneneighbors (original behavior just in case)
e.printStackTrace();
bMembraneNeighborCalculationFailed = true;
} finally {
// these aren't needed after fail or surfacecollection.set(...)
remapQuadIndexes = null;
edgeMap = null;
}
// RegionImage.sortSurfaceCollection(surfaceCollection);
// //check
// for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
// Surface surface = surfaceCollection.getSurfaces(i);
// for (int j = 0; j < surface.getPolygonCount(); j++) {
// Polygon polygon = surface.getPolygons(j);
// for (int k = 0; k < polygon.getNodes().length; k++) {
// if(surfaceCollection.getNodes()[polygon.getNodes()[k].getGlobalIndex()] != polygon.getNodes()[k]){
// throw new RuntimeException("Nodes not match");
// }
// }
// }
// }
}
use of cbit.vcell.geometry.surface.Quadrilateral in project vcell by virtualcell.
the class RasterExporter method calculateCommonNeighbor.
private static CommonNeighb calculateCommonNeighbor(CartesianMesh mesh, RegionImage regionImage, MembraneElement membraneElementN0, MembraneElement membraneElementN1, int parentMembrIndex) {
// find common node
Quadrilateral quadp = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(regionImage.getQuadIndexToSurfAndFace().get(parentMembrIndex).getSurf()).getPolygons(regionImage.getQuadIndexToSurfAndFace().get(parentMembrIndex).getFace());
Quadrilateral quad0 = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(regionImage.getQuadIndexToSurfAndFace().get(membraneElementN0.getMembraneIndex()).getSurf()).getPolygons(regionImage.getQuadIndexToSurfAndFace().get(membraneElementN0.getMembraneIndex()).getFace());
Quadrilateral quad1 = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(regionImage.getQuadIndexToSurfAndFace().get(membraneElementN1.getMembraneIndex()).getSurf()).getPolygons(regionImage.getQuadIndexToSurfAndFace().get(membraneElementN1.getMembraneIndex()).getFace());
List<Node> nodesp = Arrays.asList(quadp.getNodes());
List<Node> nodes0 = Arrays.asList(quad0.getNodes());
List<Node> nodes1 = Arrays.asList(quad1.getNodes());
List<Node> intersectN = new ArrayList<>(nodes0);
intersectN.retainAll(nodes1);
intersectN.retainAll(nodesp);
if (intersectN.size() != 1) {
System.out.println("Couldn't find parent node");
return null;
}
ArrayList<Integer> commonNeighbors = new ArrayList<>();
findNeighborNeighborsWithNode(regionImage, membraneElementN0, intersectN.get(0), parentMembrIndex, commonNeighbors);
findNeighborNeighborsWithNode(regionImage, membraneElementN1, intersectN.get(0), parentMembrIndex, commonNeighbors);
return new CommonNeighb(intersectN.get(0), commonNeighbors);
}
use of cbit.vcell.geometry.surface.Quadrilateral in project vcell by virtualcell.
the class CartesianMesh method createSimpleCartesianMesh.
public static CartesianMesh createSimpleCartesianMesh(Geometry geometry, Map<Polygon, MembraneElement> polygonMembaneElementMap) throws IOException, MathFormatException {
GeometrySurfaceDescription geometrySurfaceDescription = geometry.getGeometrySurfaceDescription();
RegionImage regionImage = geometrySurfaceDescription.getRegionImage();
ISize iSize = new ISize(regionImage.getNumX(), regionImage.getNumY(), regionImage.getNumZ());
CartesianMesh mesh = createSimpleCartesianMesh(geometry.getOrigin(), geometry.getExtent(), iSize, regionImage);
GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions();
if (geometricRegions != null) {
int memRegionCount = 0;
for (int i = 0; i < geometricRegions.length; i++) {
if (geometricRegions[i] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion vgr = (VolumeGeometricRegion) geometricRegions[i];
mesh.meshRegionInfo.mapVolumeRegionToSubvolume(vgr.getRegionID(), vgr.getSubVolume().getHandle(), vgr.getSize(), vgr.getName());
} else if (geometricRegions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion sgr = (SurfaceGeometricRegion) geometricRegions[i];
GeometricRegion[] neighbors = sgr.getAdjacentGeometricRegions();
VolumeGeometricRegion insideRegion = (VolumeGeometricRegion) neighbors[0];
VolumeGeometricRegion outsideRegion = (VolumeGeometricRegion) neighbors[1];
mesh.meshRegionInfo.mapMembraneRegionToVolumeRegion(memRegionCount, insideRegion.getRegionID(), outsideRegion.getRegionID(), sgr.getSize());
memRegionCount++;
}
}
}
SurfaceCollection surfaceCollection = geometrySurfaceDescription.getSurfaceCollection();
if (surfaceCollection != null) {
int numMembraneElement = surfaceCollection.getTotalPolygonCount();
mesh.membraneElements = new MembraneElement[numMembraneElement];
boolean bMembraneEdgeNeighborsAvailable = surfaceCollection.getMembraneEdgeNeighbors() != null && surfaceCollection.getMembraneEdgeNeighbors().length == surfaceCollection.getSurfaceCount();
int[] membraneElementMapMembraneRegion = new int[numMembraneElement];
mesh.meshRegionInfo.mapMembraneElementsToMembraneRegions(membraneElementMapMembraneRegion);
int memCount = 0;
// original values when no membraneedgeneighbors
int[] membraneNeighbors = new int[] { 0, 0, 0, 0 };
for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
Surface surface = surfaceCollection.getSurfaces(i);
bMembraneEdgeNeighborsAvailable = bMembraneEdgeNeighborsAvailable && surfaceCollection.getMembraneEdgeNeighbors()[i].length == surface.getPolygonCount();
for (int j = 0; j < surface.getPolygonCount(); j++) {
if (bMembraneEdgeNeighborsAvailable) {
membraneNeighbors = new int[MembraneElement.MAX_POSSIBLE_NEIGHBORS];
Arrays.fill(membraneNeighbors, MembraneElement.NEIGHBOR_UNDEFINED);
for (int k = 0; k < surfaceCollection.getMembraneEdgeNeighbors()[i][j].size(); k++) {
membraneNeighbors[k] = surfaceCollection.getMembraneEdgeNeighbors()[i][j].get(k).getMasterPolygonIndex();
}
}
Quadrilateral polygon = (Quadrilateral) surface.getPolygons(j);
int volNeighbor1Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor1()).getRegionIndex();
int volNeighbor2Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor2()).getRegionIndex();
HashMap<Integer, int[]> map = mesh.getMembraneRegionMapSubvolumesInOut();
Set<Entry<Integer, int[]>> entries = map.entrySet();
for (Entry<Integer, int[]> entry : entries) {
int[] volNeighbors = entry.getValue();
if (volNeighbors[0] == volNeighbor1Region && volNeighbors[1] == volNeighbor2Region || volNeighbors[1] == volNeighbor1Region && volNeighbors[0] == volNeighbor2Region) {
membraneElementMapMembraneRegion[memCount] = entry.getKey();
break;
}
}
mesh.membraneElements[memCount] = new MembraneElement(memCount, polygon.getVolIndexNeighbor1(), polygon.getVolIndexNeighbor2(), membraneNeighbors[0], membraneNeighbors[1], membraneNeighbors[2], membraneNeighbors[3], MembraneElement.AREA_UNDEFINED, 0, 0, 0, 0, 0, 0);
if (polygonMembaneElementMap != null) {
polygonMembaneElementMap.put(polygon, mesh.membraneElements[memCount]);
}
memCount++;
}
}
}
return mesh;
}
use of cbit.vcell.geometry.surface.Quadrilateral in project vcell by virtualcell.
the class RasterExporter method writeStanfordPolygonTex.
public static PolyTexHelper writeStanfordPolygonTex(RegionImage regionImage, Writer writer, /*BitSet bInDomain,*/
CartesianMesh mesh) throws IOException, MathException {
int totalPolygons = regionImage.getSurfacecollection().getTotalPolygonCount();
int totalVerts = totalPolygons * 4;
final int ALL_NEIGHBOR_QUAD_BOX_SIDE = 3;
// 2D image texture
int imgSideSize = (int) Math.ceil(Math.sqrt((totalPolygons)));
int texelXSize = (imgSideSize * ALL_NEIGHBOR_QUAD_BOX_SIDE);
int[][] texIndexToFaceIndexPtrs = new int[texelXSize * texelXSize][0];
// Arrays.fill(texImage0, Integer.MAX_VALUE);
final int squareSize = 40;
int fontXSize = texelXSize * squareSize;
int fontYSize = texelXSize * squareSize;
BufferedImage image0 = createTextureImage(fontXSize);
// int[] texFontImage = new int[fontXSize*fontYSize];
// Arrays.fill(texFontImage, 0xFF000000);
// int[] bitMasks0 = new int[]{0xFF0000, 0xFF00, 0xFF, 0xFF000000};
// SinglePixelPackedSampleModel sm0 = new SinglePixelPackedSampleModel(
// DataBuffer.TYPE_INT, texelXSize*squareSize, texelXSize*squareSize, bitMasks0);
// DataBufferInt db0 = new DataBufferInt(texFontImage, texFontImage.length);
// WritableRaster wr0 = Raster.createWritableRaster(sm0, db0, new Point());
// BufferedImage image0 = new BufferedImage(ColorModel.getRGBdefault(), wr0, false, null);
Graphics2D g2d = image0.createGraphics();
g2d.setColor(Color.white);
Font bigF = Font.decode("Dialog-plain-10");
g2d.setFont(bigF);
float texelSize = 1.0f / texelXSize;
writer.write("ply\n");
writer.write("format ascii 1.0\n");
// writer.write("comment "+geometrySurfaceDescription.getGeometry().getName()+"\n");
writer.write("comment textureImage size is " + imgSideSize + "x" + imgSideSize + "\n");
writer.write("element vertex " + totalVerts + "\n");
writer.write("property float x\n");
writer.write("property float y\n");
writer.write("property float z\n");
// must be 's' for blender (u texture coord)
writer.write("property float s\n");
// must be 't' for blender (v texture coord)
writer.write("property float t\n");
writer.write("element face " + totalPolygons + "\n");
writer.write("property list uchar int vertex_index\n");
writer.write("end_header\n");
StringBuffer sbVert = new StringBuffer();
StringBuffer sbFace = new StringBuffer();
int faceIndex = 0;
int vertIndex = 0;
for (int currSurf = 0; currSurf < regionImage.getSurfacecollection().getSurfaceCount(); currSurf++) {
for (int currFace = 0; currFace < regionImage.getSurfacecollection().getSurfaces(currSurf).getPolygonCount(); currFace++) {
// if(bInDomain != null && !bInDomain.get(faceIndex)){
// continue;
// }
g2d.setColor(Color.white);
Quadrilateral quad = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(currSurf).getPolygons(currFace);
NAHelper naHelper0 = calcNAHelper(quad);
Point2D p2dm = Coordinate.get2DProjection(naHelper0.middle, naHelper0.normalAxis);
int x = faceIndex % imgSideSize;
int y = faceIndex / imgSideSize;
int boxX = (x * ALL_NEIGHBOR_QUAD_BOX_SIDE) + 1;
int boxY = (y * ALL_NEIGHBOR_QUAD_BOX_SIDE) + 1;
int fontX = boxX * squareSize;
int fontY = boxY * squareSize;
// das.getColorFromValue(data[faceIndex]);//face color
texIndexToFaceIndexPtrs[boxY * texelXSize + boxX] = new int[] { faceIndex };
g2d.drawString(currSurf + "-" + currFace, fontX, fontY);
float imgXTexelCenter = (boxX + .5f) * texelSize;
float imgYTexelCenter = (boxY + .5f) * texelSize;
ArrayList<RegionImage.MembraneEdgeNeighbor> neighbors = regionImage.getMembraneEdgeNeighbors()[currSurf][currFace];
sbFace.append(quad.getNodeCount() + "");
for (int vrt = 0; vrt < quad.getNodeCount(); vrt++) {
g2d.setColor(Color.white);
RegionImage.MembraneEdgeNeighbor membraneEdgeNeighbor = neighbors.get(vrt);
MembraneElementIdentifier neighb = membraneEdgeNeighbor.getMembraneElementIdentifier();
if (neighb != null) {
Quadrilateral quadNeighbor = (Quadrilateral) regionImage.getSurfacecollection().getSurfaces(neighb.surfaceIndex).getPolygons(neighb.nonMasterPolygonIndex);
NAHelper naHelper1 = calcNAHelper(quadNeighbor);
Point2D p2dmNeighb = Coordinate.get2DProjection(naHelper1.middle, naHelper0.normalAxis);
double xdiff = p2dmNeighb.getX() - p2dm.getX();
double ydiff = p2dmNeighb.getY() - p2dm.getY();
int dxn = (int) Math.signum((Math.abs(xdiff) < 1e-9 ? 0 : xdiff));
int dyn = (int) Math.signum((Math.abs(ydiff) < 1e-9 ? 0 : ydiff));
// das.getColorFromValue(data[membraneEdgeNeighbor.getMasterPolygonIndex()]);
texIndexToFaceIndexPtrs[(boxY + dyn) * texelXSize + (boxX + dxn)] = new int[] { membraneEdgeNeighbor.getMasterPolygonIndex() };
g2d.drawString(neighb.nonMasterPolygonIndex + "", fontX + (dxn * squareSize), fontY + (dyn * squareSize));
RegionImage.MembraneEdgeNeighbor membraneEdgeNeighbor2 = neighbors.get((vrt + 1 == quad.getNodeCount() ? 0 : vrt + 1));
MembraneElementIdentifier neighb2 = membraneEdgeNeighbor2.getMembraneElementIdentifier();
if (neighb2 != null) {
CommonNeighb commonNeighb = calculateCommonNeighbor(mesh, regionImage, mesh.getMembraneElements()[membraneEdgeNeighbor.getMasterPolygonIndex()], mesh.getMembraneElements()[membraneEdgeNeighbor2.getMasterPolygonIndex()], faceIndex);
if (commonNeighb != null) {
if (commonNeighb.neighborneighbos.size() == 0) {
commonNeighb.neighborneighbos.add(membraneEdgeNeighbor.getMasterPolygonIndex());
commonNeighb.neighborneighbos.add(membraneEdgeNeighbor2.getMasterPolygonIndex());
}
// mesh.getMembraneElements()[commonNeighb].getCentroid();
Coordinate commonCoord = new Coordinate(commonNeighb.node.getX(), commonNeighb.node.getY(), commonNeighb.node.getZ());
Point2D p2dmcommon = Coordinate.get2DProjection(commonCoord, naHelper0.normalAxis);
double xdiff1 = p2dmcommon.getX() - p2dm.getX();
double ydiff1 = p2dmcommon.getY() - p2dm.getY();
int dxc = (int) Math.signum((Math.abs(xdiff1) < 1e-9 ? 0 : xdiff1));
int dyc = (int) Math.signum((Math.abs(ydiff1) < 1e-9 ? 0 : ydiff1));
g2d.setColor(Color.green);
int xloc = fontX + (dxc * squareSize);
int yloc = fontY + (dyc * squareSize);
double avgVal = 0;
int texIndex = (boxY + dyc) * texelXSize + boxX + dxc;
texIndexToFaceIndexPtrs[texIndex] = new int[commonNeighb.neighborneighbos.size()];
for (int k = 0; k < commonNeighb.neighborneighbos.size(); k++) {
g2d.drawString(regionImage.getQuadIndexToSurfAndFace().get(commonNeighb.neighborneighbos.get(k)).getFace() + "", xloc, yloc + (k * 11));
// avgVal+= data[commonNeighb.neighborneighbos.get(k)];
// das.getColorFromValue(avgVal/commonNeighb.neighborneighbos.size());
texIndexToFaceIndexPtrs[texIndex][k] = commonNeighb.neighborneighbos.get(k);
}
// if(texImage0[texIndex] != Integer.MAX_VALUE){
// System.out.println("texture pixel used twice");
// }
}
}
} else {
System.out.println("neighbor null");
}
Point2D p2dv = Coordinate.get2DProjection(new Coordinate(quad.getNodes(vrt).getX(), quad.getNodes(vrt).getY(), quad.getNodes(vrt).getZ()), naHelper0.normalAxis);
double xdiff3 = p2dv.getX() - p2dm.getX();
double ydiff3 = p2dv.getY() - p2dm.getY();
int dx = (int) Math.signum((Math.abs(xdiff3) < 1e-9 ? 0 : xdiff3));
int dy = (int) Math.signum((Math.abs(ydiff3) < 1e-9 ? 0 : ydiff3));
float u = (float) imgXTexelCenter + ((float) dx * texelSize / 2.0f);
float v = (float) imgYTexelCenter + ((float) dy * texelSize / 2.0f);
Node vertex = quad.getNodes()[vrt];
sbVert.append((float) vertex.getX() + " " + (float) vertex.getY() + " " + (float) vertex.getZ() + " " + u + " " + v + "\n");
sbFace.append(" ");
sbFace.append(vertIndex + "");
vertIndex++;
}
sbFace.append("\n");
faceIndex++;
}
}
if (faceIndex != totalPolygons || vertIndex != totalVerts) {
throw new IOException("Final faces and verts count don't match");
}
writer.write(sbVert.toString());
writer.write(sbFace.toString());
// ImageIO.write(op0.filter(image0, null), "png", baos);
return new PolyTexHelper(texIndexToFaceIndexPtrs, flipPNG(image0), texelXSize);
}
Aggregations