use of org.vcell.util.ISize in project vcell by virtualcell.
the class MeshSpecification method getVCML.
/**
* This method was created by a SmartGuide.
* @return java.lang.String
*/
public String getVCML() {
StringBuffer buffer = new StringBuffer();
buffer.append(VCML.MeshSpecification + " {\n");
ISize size = getSamplingSize();
buffer.append("\t" + VCML.Size + " " + size.getX() + " " + size.getY() + " " + size.getZ() + "\n");
buffer.append("}\n");
return buffer.toString();
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class GeometryGuiTest method main.
public static void main(java.lang.String[] args) {
try {
javax.swing.JFrame frame = new javax.swing.JFrame();
GeometryViewer aGeometryViewer;
aGeometryViewer = new GeometryViewer();
frame.setContentPane(aGeometryViewer);
frame.setSize(aGeometryViewer.getSize());
frame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
Geometry csGeometry = getExampleGeometryCSG();
// try to convert this CSG geometry to image
ISize imageSize = csGeometry.getGeometrySpec().getDefaultSampledImageSize();
Geometry imageGeometry = RayCaster.resampleGeometry(new GeometryThumbnailImageFactoryAWT(), csGeometry, imageSize);
// aGeometryViewer.setGeometry(csGeometry);
aGeometryViewer.setGeometry(imageGeometry);
frame.setSize(600, 600);
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JPanel");
exception.printStackTrace(System.out);
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class OverlayEditorPanelJAI method getImagePane.
/**
* Method getImagePane.
* @return OverlayImageDisplayJAI
*/
private OverlayImageDisplayJAI getImagePane() {
if (imagePane == null) {
imagePane = new OverlayImageDisplayJAI();
// imagePane = new ZoomableOverlayImagePane();
imagePane.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseExited(MouseEvent e) {
imagePane.setCursor(Cursor.getDefaultCursor());
imagePane.setBrush(null);
imagePane.refreshImage();
updateLabel(-1, -1);
if (histogramPanel.isVisible()) {
histogramPanel.setSpecialValue(null);
}
}
public void mousePressed(MouseEvent e) {
if (!bAllowAddROI) {
return;
}
updateLabel(e.getX(), e.getY());
lastMousePoint = e.getPoint();
if (showConvertPopup(e, true) == SHOWCONVERT.HANDLED) {
return;
} else if (SwingUtilities.isLeftMouseButton(e) && (paintButton.isSelected() || eraseButton.isSelected()) && !brushToolHelper.isBrushSizeClickDragMode()) {
if (roiComboBox.getItemCount() == 0) {
giveROIRequiredWarning("paint or erase");
return;
}
firePropertyChange(FRAP_DATA_PAINTERASE_PROPERTY, null, null);
getImagePane().setBrush(null);
drawHighlight(e.getX(), e.getY(), brushToolHelper.getBrushSize(getImagePane().getZoom()), eraseButton.isSelected());
} else if (SwingUtilities.isLeftMouseButton(e) && (paintButton.isSelected() || eraseButton.isSelected()) && brushToolHelper.isBrushSizeClickDragMode()) {
brushToolHelper.startBrushSizeClickDragMode(e);
}
}
public void mouseReleased(MouseEvent e) {
if (!bAllowAddROI) {
return;
}
if (showConvertPopup(e, true) == SHOWCONVERT.HANDLED) {
return;
} else if (SwingUtilities.isLeftMouseButton(e) && (paintButton.isSelected() || eraseButton.isSelected()) && !brushToolHelper.isBrushSizeClickDragMode()) {
getImagePane().setBrush(brushToolHelper.getBrushShape(e));
firePropertyChange(FRAP_DATA_PAINTERASE_FINISH_PROPERTY, null, e);
} else if (SwingUtilities.isLeftMouseButton(e) && cropButton.isSelected()) {
ISize iSize = getISizeDataset();
if (iSize == null || imagePane.getCrop() == null) {
imagePane.setCrop(null, null);
return;
}
// Copy crop from mousedragged rectangle
Rectangle cropRect = (Rectangle) imagePane.getCrop().clone();
// Check crop within bounds of dataset
cropRect.x = (int) (cropRect.x / imagePane.getZoom());
cropRect.y = (int) (cropRect.y / imagePane.getZoom());
cropRect.width = (int) (cropRect.width / imagePane.getZoom());
cropRect.height = (int) (cropRect.height / imagePane.getZoom());
if (cropRect.x < 0) {
cropRect.x = 0;
}
if (cropRect.y < 0) {
cropRect.y = 0;
}
if (cropRect.x >= iSize.getX() || cropRect.y >= iSize.getY()) {
imagePane.setCrop(null, null);
return;
}
if (cropRect.x + cropRect.width >= iSize.getX()) {
cropRect.width = iSize.getX() - cropRect.x;
}
if (cropRect.y + cropRect.height >= iSize.getY()) {
cropRect.height = iSize.getY() - cropRect.y;
}
if (cropRect.width <= 0) {
cropRect.width = 1;
}
if (cropRect.height <= 0) {
cropRect.height = 1;
}
// tell manager about crop
firePropertyChange(FRAP_DATA_CROP_PROPERTY, null, cropRect);
} else if (SwingUtilities.isLeftMouseButton(e) && (paintButton.isSelected() || eraseButton.isSelected()) && brushToolHelper.isBrushSizeClickDragMode()) {
brushToolHelper.stopBrushSizeClickDragMode(e, imagePane);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (!bAllowAddROI) {
return;
}
if (showConvertPopup(e, true) == SHOWCONVERT.HANDLED) {
return;
} else if (SwingUtilities.isLeftMouseButton(e) && fillButton.isSelected()) {
if (roiComboBox.getItemCount() == 0) {
giveROIRequiredWarning("fill");
return;
}
firePropertyChange(FRAP_DATA_FILL_PROPERTY, null, new Point((int) (e.getPoint().getX() / imagePane.getZoom()), (int) (e.getPoint().getY() / imagePane.getZoom())));
} else if (SwingUtilities.isLeftMouseButton(e) && selectButton.isSelected()) {
Object[] selectedResolvedObjects = resolvedList.getSelectedValues();
if (selectedResolvedObjects != null && selectedResolvedObjects.length > 0) {
if (selectedResolvedObjects[0] instanceof String) {
return;
}
}
fireSelectFromImage(e, false);
}
}
@Override
public void mouseEntered(MouseEvent e) {
// Set cursor
changeCursor();
if (!paintButton.isSelected() && !eraseButton.isSelected()) {
getImagePane().setBrush(null);
}
}
});
imagePane.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
@Override
public void mouseDragged(java.awt.event.MouseEvent e) {
updateLabel(e.getX(), e.getY());
if (!bAllowAddROI) {
return;
}
if (SwingUtilities.isLeftMouseButton(e) && (paintButton.isSelected() || eraseButton.isSelected()) && !brushToolHelper.isBrushSizeClickDragMode()) {
drawHighlight(e.getX(), e.getY(), brushToolHelper.getBrushSize(getImagePane().getZoom()), eraseButton.isSelected());
lastMousePoint = e.getPoint();
} else if (SwingUtilities.isLeftMouseButton(e) && cropButton.isSelected()) {
imagePane.setCrop(lastMousePoint, e.getPoint());
} else if (SwingUtilities.isLeftMouseButton(e) && (paintButton.isSelected() || eraseButton.isSelected()) && brushToolHelper.isBrushSizeClickDragMode()) {
brushToolHelper.dragBrushSizeClickDragMode(e, imagePane);
}
}
@Override
public void mouseMoved(java.awt.event.MouseEvent e) {
updateLabel(e.getX(), e.getY());
if (!brushToolHelper.isBrushSizeClickDragMode() && (paintButton.isSelected() || eraseButton.isSelected())) {
getImagePane().setBrush(brushToolHelper.getBrushShape(e));
getImagePane().refreshImage();
}
}
});
}
return imagePane;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method generateHighlightROIInfo.
private static HighlightROIInfo generateHighlightROIInfo(byte debugValue, BufferedImage[] roiArr, RegionImage regionImage, RegionAction regionAction, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
HighlightROIInfo highlightROIInfo = new HighlightROIInfo();
// Create lookup map to speedup highlighting operation for large dataset
RegionImage.RegionInfo[] selectedRegionMap = new RegionImage.RegionInfo[regionAction.getAllRegionInfos().length];
Iterator<RegionImage.RegionInfo> selectedIter = regionAction.getSelectedRegionInfos().iterator();
while (selectedIter.hasNext()) {
RegionImage.RegionInfo nextRegion = selectedIter.next();
selectedRegionMap[nextRegion.getRegionIndex()] = nextRegion;
}
byte[] shortEncodedRegionIndexes = regionImage.getShortEncodedRegionIndexImage();
final int XSIZE = roiArr[0].getWidth();
if (regionAction.getAction() == RegionAction.REGION_ACTION_HIGHLIGHT) {
highlightROIInfo.highlightROI = createEmptyROI(new ISize(roiArr[0].getWidth(), roiArr[0].getHeight(), roiArr.length));
}
int allIndex = 0;
final int ZMAX = roiArr.length - 1;
final int XMAX = roiArr[0].getWidth() - 1;
final int YMAX = roiArr[0].getHeight() - 1;
for (int z = 0; z < roiArr.length; z++) {
if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
return null;
}
int index = 0;
byte[] zSlice = ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData();
for (int y = 0; y < roiArr[0].getHeight(); y++) {
for (int x = 0; x < XSIZE; x++) {
int regionIndex = (shortEncodedRegionIndexes[allIndex] & 0x000000FF) | (shortEncodedRegionIndexes[allIndex + 1] & 0x000000FF) << 8;
if (selectedRegionMap[regionIndex] != null) {
RegionInfo currentRegionInfo = selectedRegionMap[regionIndex];
if (regionAction.getAction() == RegionAction.REGION_ACTION_CHECKNEIGHBORSONLY) {
// Find neighbors
int[] neighbors = new int[6];
Arrays.fill(neighbors, -1);
if (z > 0) {
// top neighbor
neighbors[0] = 0x000000FF & ((DataBufferByte) roiArr[z - 1].getRaster().getDataBuffer()).getData()[index];
}
if (z < ZMAX) {
// bottom neighbor
neighbors[1] = 0x000000FF & ((DataBufferByte) roiArr[z + 1].getRaster().getDataBuffer()).getData()[index];
}
if (x > 0) {
// left neighbor
neighbors[2] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index - 1];
}
if (x < XMAX) {
// right neighbor
neighbors[3] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index + 1];
}
if (y > 0) {
// front neighbor
neighbors[4] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index - XSIZE];
}
if (y < YMAX) {
// back neighbor
neighbors[5] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index + XSIZE];
}
if (!highlightROIInfo.neighborsForRegionsMap.containsKey(currentRegionInfo)) {
highlightROIInfo.neighborsForRegionsMap.put(currentRegionInfo, new TreeSet<Integer>());
}
TreeSet<Integer> neighborTreeSet = highlightROIInfo.neighborsForRegionsMap.get(currentRegionInfo);
for (int i = 0; i < neighbors.length; i++) {
if (neighbors[i] != -1 && neighbors[i] != currentRegionInfo.getPixelValue()) {
neighborTreeSet.add(neighbors[i]);
}
}
if (!highlightROIInfo.coordIndexForRegionsMap.containsKey(currentRegionInfo)) {
highlightROIInfo.coordIndexForRegionsMap.put(currentRegionInfo, new CoordinateIndex(x, y, z));
}
} else if (regionAction.getAction() == RegionAction.REGION_ACTION_HIGHLIGHT) {
highlightROIInfo.highlightROI.getRoiImages()[z].getPixels()[index] = 1;
} else if (regionAction.getAction() == RegionAction.REGION_ACTION_MERGESELECTEDWITHNEIGHBORS) {
int numNeighbors = regionAction.getNeighborsForRegionMap().get(currentRegionInfo).size();
if (/*!regionAction.bLeaveMultiNeighborUnchanged || */
numNeighbors == 1) {
zSlice[index] = (byte) regionAction.getNeighborsForRegionMap().get(currentRegionInfo).first().intValue();
} else {
boolean hasBG = false;
Integer randomNeighbor = null;
Iterator<Integer> pixelValIter = regionAction.getNeighborsForRegionMap().get(currentRegionInfo).iterator();
while (pixelValIter.hasNext()) {
Integer pixelValue = pixelValIter.next();
if (pixelValue == 0) {
hasBG = true;
break;
} else {
randomNeighbor = pixelValue;
}
}
if (hasBG) {
// merge with background
zSlice[index] = 0;
} else {
// merge with random
zSlice[index] = randomNeighbor.byteValue();
}
}
}
}
index++;
allIndex += 2;
}
}
}
return highlightROIInfo;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method createVCImageFromBufferedImages.
public static VCImage createVCImageFromBufferedImages(Extent extent, BufferedImage[] bufferedImages) throws Exception {
// collect z-sections into 1 array for VCImage
ISize isize = new ISize(bufferedImages[0].getWidth(), bufferedImages[0].getHeight(), bufferedImages.length);
int sizeXY = isize.getX() * isize.getY();
byte[] segmentedData = new byte[isize.getXYZ()];
int index = 0;
for (int i = 0; i < bufferedImages.length; i++) {
System.arraycopy(((DataBufferByte) bufferedImages[i].getRaster().getDataBuffer()).getData(), 0, segmentedData, index, sizeXY);
index += sizeXY;
}
return new VCImageUncompressed(null, segmentedData, extent, isize.getX(), isize.getY(), isize.getZ());
}
Aggregations