use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class DisplayTimeSeriesOp method getDataSetControllerProvider.
private DataSetControllerProvider getDataSetControllerProvider(final ImageTimeSeries<? extends Image> imageTimeSeries, final PDEDataViewer pdeDataViewer) throws ImageException, IOException {
ISize size = imageTimeSeries.getISize();
int dimension = (size.getZ() > 0) ? (3) : (2);
Extent extent = imageTimeSeries.getExtent();
Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
// don't care ... no surfaces
double filterCutoffFrequency = 0.5;
VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
final DataSetController dataSetController = new DataSetController() {
@Override
public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_START, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
if (!timeSeriesJobSpec.isCalcSpaceStats() && !timeSeriesJobSpec.isCalcTimeStats()) {
int[][] indices = timeSeriesJobSpec.getIndices();
double[] timeStamps = imageTimeSeries.getImageTimeStamps();
// [var][dataindex+1][timeindex]
double[][][] dataValues = new double[1][indices[0].length + 1][timeStamps.length];
for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
// index 0 is time
dataValues[0][0][timeIndex] = timeStamps[timeIndex];
}
for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
float[] pixelValues = imageTimeSeries.getAllImages()[timeIndex].getFloatPixels();
for (int samplePointIndex = 0; samplePointIndex < indices[0].length; samplePointIndex++) {
int pixelIndex = indices[0][samplePointIndex];
dataValues[0][samplePointIndex + 1][timeIndex] = pixelValues[pixelIndex];
}
}
TSJobResultsNoStats timeSeriesJobResults = new TSJobResultsNoStats(new String[] { "var" }, indices, timeStamps, dataValues);
pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_COMPLETE, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
return timeSeriesJobResults;
}
return null;
}
@Override
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
double timePoint = time;
double[] timePoints = getDataSetTimes(vcdataID);
int index = -1;
for (int i = 0; i < timePoints.length; i++) {
if (timePoint == timePoints[i]) {
index = i;
break;
}
}
double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
VariableType varType = VariableType.VOLUME;
return new SimDataBlock(pdeDataInfo, data, varType);
}
@Override
public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return false;
}
@Override
public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
return null;
}
@Override
public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return null;
}
@Override
public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return mesh;
}
@Override
public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return new AnnotatedFunction[0];
}
@Override
public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return imageTimeSeries.getImageTimeStamps();
}
@Override
public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return new DataIdentifier[] { dataIdentifier };
}
@Override
public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
// TODO Auto-generated method stub
return null;
}
@Override
public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
// TODO Auto-generated method stub
return null;
}
@Override
public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
// TODO Auto-generated method stub
return null;
}
};
DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {
@Override
public DataSetController getDataSetController() throws DataAccessException {
return dataSetController;
}
};
return dataSetControllerProvider;
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class VFrapXmlHelper method LoadVFrapSpecialImages.
// // load and compute prebleach average and first postbleach images
// public void LoadVFrapSpecialImages(AnnotatedImageDataset annotatedImages, int startingIndexRecovery)
// {
// // unnormalized prebleach average
// prebleachAvg = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// for(int j = 0; j < prebleachAvg.length; j++)
// {
// double pixelTotal = 0;
// for(int i = 0 ; i < startingIndexRecovery; i++)
// {
// pixelTotal = pixelTotal + (annotatedImages.getImageDataset().getImage(0, 0, i).getPixels()[j] & 0x0000FFFF);
// }
// prebleachAvg[j] = pixelTotal/startingIndexRecovery;
// }
//
// // unnormalized first post bleach
// firstPostBleach = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// short[] pixels = annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getPixels();
// for(int i = 0; i< pixels.length; i++)
// {
// firstPostBleach[i] = pixels[i] & 0x0000FFFF;
// }
// }
//
// Locate the special images within the vFrap files and load them in memory
//
public static boolean LoadVFrapSpecialImages(Hashtable<String, Object> hashTable, Element vFrapRoot) throws IOException, DataAccessException, MathException, ImageException {
// ------ parse the vfrap file and the log/zip files referred within -----
// many channels of 1 timepoint each
int NumTimePoints = 1;
// the channels: prebleach, postbleach, roi1, roi2 ... roiN
int NumChannels = tokenNames.length;
String[] channelNames = new String[NumChannels];
VariableType[] channelTypes = new VariableType[NumChannels];
DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
double[][][] pixData = new double[NumTimePoints][NumChannels][];
// get the path of the file tagged with "ROIExternalDataInfoTag" and open it
Element roiExternalDataInfoElement = vFrapRoot.getChild(MicroscopyXMLTags.ROIExternalDataInfoTag);
if (roiExternalDataInfoElement == null) {
// can't load FieldData for some reason, fall back to importing the biomodel only
return false;
}
// <ROIExternalDataInfo Filename="c:\vFrap\VirtualMicroscopy\SimulationData\SimID_1282941232246_0_.log">
// <ExternalDataIdentifier Name="timeData" KeyValue="1282941232246" OwnerName="SimulationData" OwnerKey="0" />
// </ImageDatasetExternalDataInfo>
// c:\VirtualMicroscopy\SimulationData\SimID_1284149203811_0_.log
String filename = (roiExternalDataInfoElement).getAttributeValue("Filename");
Element childElement = (roiExternalDataInfoElement).getChild("ExternalDataIdentifier");
if (childElement == null) {
// can't load FieldData for some reason, fall back to importing the biomodel only
return false;
}
StringTokenizer tokens = new StringTokenizer(filename, "/\\.");
final ArrayList<String> tokenArray = new ArrayList<String>();
while (tokens.hasMoreElements()) {
tokenArray.add(tokens.nextToken());
}
final String dataID = tokenArray.get(tokenArray.size() - 2);
final String userName = tokenArray.get(tokenArray.size() - 3);
VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public String getID() {
return dataID;
}
public KeyValue getDataKey() {
return null;
}
public User getOwner() {
return new User(userName, new KeyValue("123345432334"));
}
};
// ------- recover simulation data for this user name, load the images in memory ------------
// ex c:\\VirtualMicroscopy\\SimulationData
String userDirName = filename.substring(0, filename.indexOf(dataID) - 1);
File userDir = new File(userDirName);
SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
SimulationData simData = new SimulationData(vcDataIdentifier, userDir, null, simDataAmplistorInfo);
// build a valid mesh in 2 steps, what we have in simData is incomplete
CartesianMesh incompleteMesh = simData.getMesh();
Extent extent = incompleteMesh.getExtent();
ISize isize = new ISize(incompleteMesh.getSizeX(), incompleteMesh.getSizeY(), incompleteMesh.getSizeZ());
Origin origin = new Origin(0, 0, 0);
CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
double[] times = simData.getDataTimes();
for (int i = 0; i < dataIdentifiers.length; i++) {
// ex: prebleach_avg, postbleach_first, postbleach_last, bleached_mask, cell_mask, ring1_mask,... ring8_mask
System.out.println(dataIdentifiers[i].getName());
for (double time : times) {
// this loops only once, we have just 1 timepoint for each "special" image
SimDataBlock simDataBlock = simData.getSimDataBlock(null, dataIdentifiers[i].getName(), time);
channelNames[i] = dataIdentifiers[i].getName();
channelTypes[i] = VariableType.VOLUME;
channelVFrapImageType[i] = SymbolEquivalence.typeFromToken(dataIdentifiers[i].getName());
pixData[0][i] = simDataBlock.getData();
// var = prebleach_avg, time = 0.0, data = { 1.0832530361887216 1.0832530361887216 1.0832530361887216 1.0 .... }
System.out.print("var = " + dataIdentifiers[i].getName() + ", time = " + time + ", data = { ");
// show a few
for (int j = 0; j < 5; j++) {
System.out.print(pixData[0][i][j] + " ");
}
// show a few
;
// show a few
System.out.println(" ... ");
}
}
hashTable.put("mesh", mesh);
hashTable.put("pixData", pixData);
hashTable.put("channelNames", channelNames);
hashTable.put("channelTypes", channelTypes);
hashTable.put("channelVFrapImageType", channelVFrapImageType);
return true;
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class PointSpreadFunctionManagement method importPointSpreadFunction.
public void importPointSpreadFunction() {
AsynchClientTask[] taskArray = new AsynchClientTask[3];
// select the desired PSF file
taskArray[0] = new AsynchClientTask("Select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
ChoosePSFFile(hashTable);
}
};
// create and save the field data object
taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
Component requesterComponent = parentWindow;
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
if (documentManager == null) {
throw new RuntimeException("Not connected to server.");
}
// the following line of code may modify initialFieldDataName
// normal file name
checkNameAvailability(hashTable, false, documentManager, requesterComponent);
File filePSF = (File) hashTable.get("filePSF");
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
ImageDataset imageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(filePSF.getAbsolutePath(), null);
Extent extent = imageDataset.getExtent();
ISize isize = imageDataset.getISize();
Origin origin = new Origin(0, 0, 0);
CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
// save field data
int NumTimePoints = imageDataset.getImageTimeStamps().length;
int NumChannels = 1;
double[][][] pixData = new double[NumTimePoints][NumChannels][];
for (int i = 0; i < NumTimePoints; i++) {
// images according to zIndex at specific time points(tIndex)
short[] originalData = imageDataset.getPixelsZ(0, i);
double[] doubleData = new double[originalData.length];
for (int j = 0; j < originalData.length; j++) {
doubleData[j] = 0x0000ffff & originalData[j];
}
pixData[i][NumChannels - 1] = doubleData;
}
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
// try {
// fdos = ClientRequestManager.createFDOSFromImageFile(filePSF, false, null);
// } catch (DataFormatException ex) {
// throw new Exception("Cannot read image " + filePSF.getAbsolutePath()+"\n"+ex.getMessage());
// }
fdos.owner = documentManager.getUser();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.doubleSpecData = pixData;
fdos.specEDI = null;
fdos.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
fdos.times = imageDataset.getImageTimeStamps();
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
ExternalDataIdentifier pSFImageEDI = documentManager.saveFieldData(fdos, initialFieldDataName);
hashTable.put("pSFImageEDI", pSFImageEDI);
}
};
// create a data symbol for the PSF image saved above as field data
taskArray[2] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// --- create the data symbols associated with the time series
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
ExternalDataIdentifier pSFImageEDI = (ExternalDataIdentifier) hashTable.get("pSFImageEDI");
String fluorName = "psf_" + initialFieldDataName;
DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.POINT_SPREAD_FUNCTION, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), pSFImageEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), 0D);
simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(parentWindow, hash, taskArray, false, true, null);
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class DataSymbolsPanel method addVFrapOriginalImages.
private void addVFrapOriginalImages() {
// add dataset (normal images) from vFrap
AsynchClientTask[] taskArray = new AsynchClientTask[5];
// select the desired vfrap file
taskArray[0] = ChooseVFrapFile();
taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
File vFrapFile = (File) hashTable.get("vFrapFile");
Component requesterComponent = DataSymbolsPanel.this;
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
if (documentManager == null) {
throw new RuntimeException("Not connected to server.");
}
// ex ccc8.vfrap
String vFrapFileNameExtended = vFrapFile.getName();
{
// we want to make sure to reload these strings from the hash later on
String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
// we'll save here the "special" vFrap images (prebleach_avg, ...)
String mixedFieldDataName = initialFieldDataName + "Mx";
hashTable.put("initialFieldDataName", initialFieldDataName);
hashTable.put("mixedFieldDataName", mixedFieldDataName);
}
if (vFrapFileNameExtended.indexOf(".vfrap") <= -1) {
throw new RuntimeException("File extension must be .vfrap");
}
// normal images
checkNameAvailability(hashTable, false, documentManager, requesterComponent);
// ----- read needed info from Virtual FRAP xml file
System.out.println("Loading " + vFrapFileNameExtended + " ...");
String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
// loading frap images
AnnotatedImageDataset annotatedImages = xmlReader.getAnnotatedImageDataset(vFrapRoot, null);
hashTable.put("annotatedImages", annotatedImages);
// loading ROIs for display purposes only (see next task)
ROI[] rois = xmlReader.getPrimaryROIs(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
LoadVFrapDisplayRoi(hashTable, annotatedImages, rois);
// Calendar cal = Calendar.getInstance();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
// DocumentWindow documentWindow = (DocumentWindow)BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
// DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
// VFrapXmlHelper vFrapXmlHelper = new VFrapXmlHelper();
// if(vFrapXmlHelper.isAlreadyImported(vFrapFileName, documentManager)) {
// throw new RuntimeException("FieldData name already in use.");
// }
// // bioModel.setName(vFrapFileName + "-" + sdf.format(cal.getTime()));
// bioModel.setName(vFrapFileName);
// BioModel feedbackModel = documentManager.save(bioModel, null);
// BioModelChildSummary childSummary = BioModelChildSummary.fromDatabaseSerialization(xmlString);
// BioModelInfo biomodelInfo = new BioModelInfo(feedbackModel.getVersion(), feedbackModel.getVersion().getVersionKey(), childSummary );
// documentWindow.getTopLevelWindowManager().getRequestManager().openDocument(biomodelInfo, documentWindow.getTopLevelWindowManager(), true);
}
};
// show the images from the vfrap file in an OverlayEditorPanelJAI dialog
taskArray[2] = new AsynchClientTask("Display images", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
if (initialFieldDataName.equals("")) {
JOptionPane.showMessageDialog(DataSymbolsPanel.this, "Field Data name " + initialFieldDataName + " already in use.");
// prevents the rest of tasks below from running
throw UserCancelException.CANCEL_GENERIC;
}
AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
BufferedImage[] displayROI = (BufferedImage[]) hashTable.get("displayROI");
if (annotatedImages == null || displayROI == null) {
return;
}
// display the images
OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI();
overlayPanel.setAllowAddROI(false);
ImageDataset imageDataset = annotatedImages.getImageDataset();
overlayPanel.setImages(imageDataset, 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200));
overlayPanel.setAllROICompositeImage(displayROI, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
int choice = DialogUtils.showComponentOKCancelDialog(DataSymbolsPanel.this, overlayPanel, "vFrap Field Data");
if (choice != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
}
};
// save the timepoints from memory to the database as field data
taskArray[3] = new AsynchClientTask("Saving time series data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
DocumentManager dm = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
if (dm == null) {
throw new RuntimeException("Not connected to server.");
}
User owner = null;
Version version = simulationContext.getVersion();
if (version == null) {
// new document, so the owner is the user
owner = dm.getUser();
} else {
owner = simulationContext.getVersion().getOwner();
}
// mesh
ImageDataset imageDataset = annotatedImages.getImageDataset();
Extent extent = imageDataset.getExtent();
ISize isize = imageDataset.getISize();
Origin origin = new Origin(0, 0, 0);
CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
// save field data
int NumTimePoints = imageDataset.getImageTimeStamps().length;
int NumChannels = 1;
double[][][] pixData = new double[NumTimePoints][NumChannels][];
for (int i = 0; i < NumTimePoints; i++) {
// images according to zIndex at specific time points(tIndex)
short[] originalData = imageDataset.getPixelsZ(0, i);
double[] doubleData = new double[originalData.length];
for (int j = 0; j < originalData.length; j++) {
doubleData[j] = 0x0000ffff & originalData[j];
}
pixData[i][NumChannels - 1] = doubleData;
}
FieldDataFileOperationSpec timeSeriesFieldDataOpSpec = new FieldDataFileOperationSpec();
timeSeriesFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
timeSeriesFieldDataOpSpec.cartesianMesh = cartesianMesh;
timeSeriesFieldDataOpSpec.doubleSpecData = pixData;
timeSeriesFieldDataOpSpec.specEDI = null;
timeSeriesFieldDataOpSpec.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
timeSeriesFieldDataOpSpec.owner = owner;
timeSeriesFieldDataOpSpec.times = imageDataset.getImageTimeStamps();
timeSeriesFieldDataOpSpec.variableTypes = new VariableType[] { VariableType.VOLUME };
timeSeriesFieldDataOpSpec.origin = origin;
timeSeriesFieldDataOpSpec.extent = extent;
timeSeriesFieldDataOpSpec.isize = isize;
// realignment for the case when first timepoint is not zero
if (timeSeriesFieldDataOpSpec.times[0] != 0) {
double shift = timeSeriesFieldDataOpSpec.times[0];
for (int i = 0; i < NumTimePoints; i++) {
timeSeriesFieldDataOpSpec.times[i] -= shift;
}
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyMMMdd_hhmmss");
String formattedDate = sdf.format(cal.getTime());
hashTable.put("formattedDate", formattedDate);
// ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec,
// initialFieldDataName + "_" + formattedDate);
ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec, initialFieldDataName);
hashTable.put("imageDataset", imageDataset);
hashTable.put("timeSeriesEDI", timeSeriesEDI);
}
};
// create the data symbols for the images saved above and display them in the tree/table
taskArray[4] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// --- create the data symbols associated with the time series
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
ImageDataset imageDataset = (ImageDataset) hashTable.get("imageDataset");
ExternalDataIdentifier timeSeriesEDI = (ExternalDataIdentifier) hashTable.get("timeSeriesEDI");
for (double time : imageDataset.getImageTimeStamps()) {
// String fluorName = TokenMangler.fixTokenStrict("fluor_"+time+"_");
// while (simulationContext.getDataContext().getDataSymbol(fluorName)!=null){
// fluorName = TokenMangler.getNextEnumeratedToken(fluorName);
// }
// max time interval we can display is about 11 days
DecimalFormat df = new DecimalFormat("###000.00");
// String fluorName = "fluor_" + df.format(time) + "_" + formattedDate;
String fluorName = "fluor_" + df.format(time).substring(0, df.format(time).indexOf(".")) + "s" + df.format(time).substring(1 + df.format(time).indexOf(".")) + "_" + initialFieldDataName;
// FieldFunctionArguments fluorFFArgs = new FieldFunctionArguments(timeSeriesEDI.getName(), fluorName, new Expression(time), VariableType.VOLUME);
DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.VFRAP_TIMEPOINT, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), timeSeriesEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), time);
simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
}
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hash, taskArray, false, true, null);
// String name = null;
// try {
// getNewDataSymbolPanel().setSymbolName("");
// getNewDataSymbolPanel().setSymbolExpression("vcField(dataset1,var1,0.0,Volume)");
// int newSettings = org.vcell.util.gui.DialogUtils.showComponentOKCancelDialog(this, getNewDataSymbolPanel(), "New DataSymbol");
// if (newSettings == JOptionPane.OK_OPTION) {
// name = getNewDataSymbolPanel().getSymbolName();
// String expression = getNewDataSymbolPanel().getSymbolExpression();
// Expression exp = new Expression(expression);
// FunctionInvocation[] functionInvocations = exp.getFunctionInvocations(null);
// // DataSymbol ds = new FieldDataSymbol(DataSymbolType.GENERIC_SYMBOL, name, "",
// // simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD,
// // new FieldFunctionArguments(functionInvocations[0]));
// DataSymbol ds = new FieldDataSymbol(name, DataSymbolType.GENERIC_SYMBOL,
// simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD);
// simulationContext.getDataContext().addDataSymbol(ds);
// }
// } catch (java.lang.Throwable ivjExc) {
// DialogUtils.showErrorDialog(this, "Data symbol " + name + " already exists");
// }
}
use of cbit.vcell.geometry.RegionImage in project vcell by virtualcell.
the class ROIMultiPaintManager method getImportSTLtasks.
// private File lastImportDir;
private ArrayList<AsynchClientTask> getImportSTLtasks(File[] selectedFiles, Vect3d primarySampleSizes, Vect3d subSampleOffset) {
// try {
final RegionImage currRegionImage = regionImage;
final TreeMap<Integer, String> newROIindexes = new TreeMap<>();
final TreeMap<BoundingBox, Object[]> regionBounds = new TreeMap<>(new Comparator<BoundingBox>() {
@Override
public int compare(BoundingBox arg0, BoundingBox arg1) {
if (arg1 == arg0) {
return 0;
}
if (arg0.getLoX() == arg1.getLoX() && arg0.getLoY() == arg1.getLoY() && arg0.getLoZ() == arg1.getLoZ() && arg0.getHiX() == arg1.getHiX() && arg0.getHiY() == arg1.getHiY() && arg0.getHiZ() == arg1.getHiZ()) {
return 0;
}
return (arg0.getLoX() >= arg1.getLoX() && arg0.getLoY() >= arg1.getLoY() && arg0.getLoZ() >= arg1.getLoZ() && arg0.getHiX() <= arg1.getHiX() && arg0.getHiY() <= arg1.getHiY() && arg0.getHiZ() <= arg1.getHiZ() ? -1 : +1);
}
});
AsynchClientTask sampleSTLtask = new AsynchClientTask("importSTLtask", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
StatsHelper statsHelper = calcMinMax(selectedFiles);
Vect3d worldOrigin = new Vect3d(statsHelper.xmin, statsHelper.ymin, statsHelper.zmin);
Vect3d worldCollapsedBoundingBox = new Vect3d(statsHelper.xmax - statsHelper.xmin, statsHelper.ymax - statsHelper.ymin, statsHelper.zmax - statsHelper.zmin);
Vect3d scale = new Vect3d(worldCollapsedBoundingBox.getX() / (2.0 * primarySampleSizes.getX()), worldCollapsedBoundingBox.getY() / (2.0 * primarySampleSizes.getY()), worldCollapsedBoundingBox.getZ() / (2.0 * primarySampleSizes.getZ()));
// }
if (scale.getX() != 0 && scale.getX() <= (scale.getY() == 0 ? scale.getX() : scale.getY()) && scale.getX() <= (scale.getZ() == 0 ? scale.getX() : scale.getZ())) {
scale = new Vect3d(scale.getX(), scale.getX(), scale.getX());
} else if (scale.getY() != 0 && scale.getY() <= (scale.getX() == 0 ? scale.getY() : scale.getX()) && scale.getY() <= (scale.getZ() == 0 ? scale.getY() : scale.getZ())) {
scale = new Vect3d(scale.getY(), scale.getY(), scale.getY());
} else if (scale.getZ() != 0 && scale.getZ() <= (scale.getY() == 0 ? scale.getZ() : scale.getY()) && scale.getZ() <= (scale.getX() == 0 ? scale.getZ() : scale.getX())) {
scale = new Vect3d(scale.getZ(), scale.getZ(), scale.getZ());
}
for (int j = 0; j < selectedFiles.length; j++) {
// ClientRequestManager.createSurfaceCollectionFromSurfaceFile(selectedFile);
SurfaceCollection surfaceCollection = statsHelper.recalSurfs.get(j);
for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
Surface surface = surfaceCollection.getSurfaces(i);
// System.out.println("surface "+i);
// Vect3d xyzLow = new Vect3d(surface.getPolygons(0).getNodes(0).getX(),surface.getPolygons(0).getNodes(1).getX(),surface.getPolygons(0).getNodes(2).getX());
// Vect3d xyzHigh = new Vect3d(xyzLow);
ComboboxROIName[] existingRoiNames = overlayEditorPanelJAI.getAllCompositeROINamesAndColors();
int newIndex = getUnusedROIColorIndex(existingRoiNames, newROIindexes.keySet());
newROIindexes.put(newIndex, selectedFiles[j].getName());
byte value = (byte) newIndex;
// overlayEditorPanelJAI.addROIName(roiName, true, roiName, true, value);
for (int k = 0; k < surface.getPolygonCount(); k++) {
Polygon polygon = surface.getPolygons(k);
// for (Node pnode:polygon.getNodes()) {
// xyzLow.set(Math.min(xyzLow.getX(), pnode.getX()),Math.min(xyzLow.getY(), pnode.getY()),Math.min(xyzLow.getZ(), pnode.getZ()));
// xyzHigh.set(Math.max(xyzHigh.getX(), pnode.getX()),Math.max(xyzHigh.getY(), pnode.getY()),Math.max(xyzHigh.getZ(), pnode.getZ()));
// }
// if(k%10000 == 0){
// System.out.println("progress= file "+(j+1)+" of "+selectedFiles.length+" "+((k*100)/surface.getPolygonCount())+"%");
// }
// System.out.println(" polygon "+j+" "+polygon.getNodes(0)+" "+polygon.getNodes(1)+" "+polygon.getNodes(2));
Vect3d line1 = new Vect3d(polygon.getNodes(0));
Vect3d end1 = new Vect3d(polygon.getNodes(2));
Vect3d incr1 = Vect3d.sub(end1, line1);
incr1.unit();
incr1.set(incr1.getX() * scale.getX(), incr1.getY() * scale.getY(), incr1.getZ() * scale.getZ());
Vect3d line2 = new Vect3d(line1);
Vect3d end2 = new Vect3d(polygon.getNodes(1));
Vect3d incr2 = Vect3d.sub(end2, line2);
incr2.unit();
incr2.set(incr2.getX() * scale.getX(), incr2.getY() * scale.getY(), incr2.getZ() * scale.getZ());
while (true) {
Vect3d line3 = new Vect3d(line1);
Vect3d end3 = new Vect3d(line2);
Vect3d incr3 = Vect3d.sub(end3, line3);
if (incr3.length() != 0) {
incr3.unit();
incr3.set(incr3.getX() * scale.getX(), incr3.getY() * scale.getY(), incr3.getZ() * scale.getZ());
}
while (true) {
calcXYZ(line3, worldOrigin, worldCollapsedBoundingBox, primarySampleSizes, subSampleOffset, value);
line3.add(incr3);
Vect3d check = Vect3d.sub(end3, line3);
if ((check.length() == 0) || Math.signum(check.getX()) != Math.signum(incr3.getX()) || Math.signum(check.getY()) != Math.signum(incr3.getY()) || Math.signum(check.getZ()) != Math.signum(incr3.getZ())) {
calcXYZ(end3, worldOrigin, worldCollapsedBoundingBox, primarySampleSizes, subSampleOffset, value);
break;
}
}
if (line1.equals(end1) && line2.equals(end2)) {
break;
}
line1.add(incr1);
Vect3d check = Vect3d.sub(end1, line1);
if (check.length() == 0 || Math.signum(check.getX()) != Math.signum(incr1.getX()) || Math.signum(check.getY()) != Math.signum(incr1.getY()) || Math.signum(check.getZ()) != Math.signum(incr1.getZ())) {
line1 = new Vect3d(end1);
}
line2.add(incr2);
check = Vect3d.sub(end2, line2);
if (check.length() == 0 || Math.signum(check.getX()) != Math.signum(incr2.getX()) || Math.signum(check.getY()) != Math.signum(incr2.getY()) || Math.signum(check.getZ()) != Math.signum(incr2.getZ())) {
line2 = new Vect3d(end2);
}
}
}
// regionBounds.put(new BoundingBox(xyzLow.getX(), xyzHigh.getX(),xyzLow.getY(), xyzHigh.getY(),xyzLow.getZ(), xyzHigh.getZ()),new Object[] {new int[] {j,i},roiName});
}
}
// for(BoundingBox bb:regionBounds.keySet()){
// System.out.println(((int[])regionBounds.get(bb)[0])[0]+","+((int[])regionBounds.get(bb)[0])[1]+" name="+((String)regionBounds.get(bb)[1])+" bound="+bb.getLoX()+","+bb.getHiX()+" "+bb.getLoY()+","+bb.getHiY()+" "+bb.getLoZ()+","+bb.getHiZ());
// }
updateAuxiliaryInfo(originalISize, getClientTaskStatusSupport());
// }
}
};
final int[] checkHolder = new int[1];
final String[] cleanupHolder = new String[1];
final String YES = "Yes";
final ComboboxROIName[] cbxHolder = new ComboboxROIName[1];
final String CHECK = "check";
AsynchClientTask addROInamesTask = new AsynchClientTask("Add new ROI names...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
int i = 0;
for (Integer newIndex : newROIindexes.keySet()) {
String roiName = FilenameUtils.getBaseName(newROIindexes.get(newIndex));
roiName = TokenMangler.fixTokenStrict(roiName, 6);
roiName += "_" + i++;
overlayEditorPanelJAI.addROIName(roiName, true, roiName, true, newIndex);
}
cleanupHolder[0] = DialogUtils.showWarningDialog(overlayEditorPanelJAI, "Cleanup imported geometry?", new String[] { YES, "No" }, YES);
if (!YES.equals(cleanupHolder[0])) {
return;
}
checkHolder[0] = getUnusedROIColorIndex(overlayEditorPanelJAI.getAllCompositeROINamesAndColors(), null);
overlayEditorPanelJAI.addROIName(CHECK, true, CHECK, true, checkHolder[0]);
ComboboxROIName[] temp = overlayEditorPanelJAI.getAllCompositeROINamesAndColors();
for (ComboboxROIName cbx : temp) {
if (cbx.getROIName().equals(CHECK)) {
cbxHolder[0] = cbx;
break;
}
}
}
};
// AsynchClientTask removeCheckROI = new AsynchClientTask("Remove check...",AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
//
// @Override
// public void run(Hashtable<String, Object> hashTable) throws Exception {
// ComboboxROIName[] regNames = overlayEditorPanelJAI.getAllCompositeROINamesAndColors();
// for(ComboboxROIName cbx:regNames){
// if(cbx.get)
// }
// }
// };
final AsynchClientTask mergeBackgroundRegions = new AsynchClientTask("Merge background regions...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (!YES.equals(cleanupHolder[0])) {
return;
}
// long start = System.currentTimeMillis();
// while(currRegionImage == regionImage){
// int dur = (int)((System.currentTimeMillis()-start)/1000);
// if(dur > 10){
// return;
// }
// System.out.println("trying..."+dur);
// Thread.sleep(1000);
// }
final TreeMap<RegionInfo, Vect3d[]> regTobb = new TreeMap<>(new Comparator<RegionInfo>() {
@Override
public int compare(RegionInfo arg0, RegionInfo arg1) {
return arg0.getRegionIndex() - arg1.getRegionIndex();
}
});
Hashtable<String, Object> newRegionImgHolder = new Hashtable<>();
createRegionImageTask.run(newRegionImgHolder);
RegionImage newRegionImage = (RegionImage) newRegionImgHolder.get(LOCAL_REGION_IMAGE);
// ArrayList<RegionInfo> remainingRegionInfos = new ArrayList<>(Arrays.asList(newRegionImage.getRegionInfos()));
// BoundingBox bb = new BoundingBox(0, newRegionImage.getNumX()-1, 0, newRegionImage.getNumY()-1, 0, newRegionImage.getNumZ()-1);
// int currIndex = 0;
// for (int z = 0; z <= bb.getHiZ(); z++) {
// for (int y = 0; y <= bb.getHiY(); y++) {
// for (int x = 0; x <= bb.getHiX(); x++) {
// ArrayList<RegionInfo> tempRegionInfos = (ArrayList<RegionInfo>)remainingRegionInfos.clone();
// if(x==0 || x == bb.getHiX() || y==0 || y == bb.getHiY() || z==0 || z == bb.getHiZ()){
// for(RegionInfo reg:tempRegionInfos){
// if(reg.getPixelValue() == 0 && reg.isIndexInRegion(currIndex)){
// remainingRegionInfos.remove(reg);
// break;
// }
// }
// }else{
// for(RegionInfo reg:tempRegionInfos){
// if(reg.getPixelValue() == 0 && reg.isIndexInRegion(currIndex)){
// remainingRegionInfos.remove(reg);
// break;
// }
// }
// }
// currIndex++;
// }
// }
// }
// Remove unfilled regions (background) that touch the whole region border
int allPixCnt = 0;
ArrayList<RegionInfo> excluded = new ArrayList<>();
for (int z = 0; z < newRegionImage.getNumZ(); z++) {
for (int y = 0; y < newRegionImage.getNumY(); y++) {
for (int x = 0; x < newRegionImage.getNumX(); x++) {
RegionInfo regInfo = newRegionImage.getRegionInfoFromOffset(allPixCnt);
allPixCnt += 1;
if (excluded.contains(regInfo)) {
continue;
}
if (regInfo.getPixelValue() == 0 && (x == 0 || x == newRegionImage.getNumX() - 1 || y == 0 || y == newRegionImage.getNumY() - 1 || z == 0 || z == newRegionImage.getNumZ() - 1)) {
excluded.add(regInfo);
if (regTobb.containsKey(regInfo)) {
regTobb.remove(regInfo);
}
continue;
}
Vect3d[] bounds = regTobb.get(regInfo);
if (bounds == null) {
bounds = new Vect3d[] { new Vect3d(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), new Vect3d(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY) };
regTobb.put(regInfo, bounds);
}
bounds[0].set(Math.min(bounds[0].getX(), x), Math.min(bounds[0].getY(), y), Math.min(bounds[0].getZ(), z));
bounds[1].set(Math.max(bounds[1].getX(), x), Math.max(bounds[1].getY(), y), Math.max(bounds[1].getZ(), z));
}
}
}
// ArrayList<Object[]> tree = new ArrayList<>();//arraylist<object[]>,regionInfo
// ArrayList<RegionInfo> bucket = new ArrayList<>(regTobb.keySet());
// tree.add(new Object[] {null,regTobb.firstKey()});
// // ArrayList<Object[]> stack = new ArrayList<>();
// // stack.add(tree.get(0));
// while(bucket.size() > 0){
// // Object[] next = stack.remove(0);
// RegionInfo next = bucket.remove(0);
// Vect3d[] o2v = (Vect3d[])regTobb.get(regTobb.get(next));
// for(Object[] objArr:tree){
// // if(((RegionInfo)next[1]).getRegionIndex() != reg.getRegionIndex()){
// // for(RegionInfo bucketReg:bucket){
// Vect3d[] o1v = (Vect3d[])regTobb.get(objArr[1]);
// if( o1v[0].getX() >= o2v[0].getX() && o1v[0].getX() <= o2v[1].getX() &&
// o1v[0].getY() >= o2v[0].getY() && o1v[0].getY() <= o2v[1].getY() &&
// o1v[0].getZ() >= o2v[0].getZ() && o1v[0].getZ() <= o2v[1].getZ()
// ){
//
// }
// // }
// // }
// }
// }
// Sort filled/unfilled regions by boundingbox
ArrayList<RegionInfo> sortedRegionInfos = new ArrayList<>(Arrays.asList(regTobb.keySet().toArray(new RegionInfo[0])));
Collections.sort(sortedRegionInfos, new Comparator<RegionInfo>() {
@Override
public int compare(RegionInfo o1, RegionInfo o2) {
Vect3d[] o1v = (Vect3d[]) regTobb.get(o1);
Vect3d[] o2v = (Vect3d[]) regTobb.get(o2);
// }
if (o1v[0].getX() == o2v[0].getX() && o1v[1].getX() == o2v[1].getX() && o1v[0].getY() == o2v[0].getY() && o1v[1].getY() == o2v[1].getY() && o1v[0].getZ() >= o2v[0].getZ() && o1v[1].getZ() == o2v[1].getZ()) {
System.out.println(o1.getRegionIndex() + " == " + o2.getRegionIndex());
return 0;
} else if (o1v[0].getX() >= o2v[0].getX() && o1v[0].getX() <= o2v[1].getX() && // o1v[1].getX() >= o2v[0].getX() && o1v[1].getX() <= o2v[1].getX() &&
o1v[0].getY() >= o2v[0].getY() && o1v[0].getY() <= o2v[1].getY() && // o1v[1].getY() >= o2v[0].getY() && o1v[1].getY() <= o2v[1].getY() &&
o1v[0].getZ() >= o2v[0].getZ() && o1v[0].getZ() <= o2v[1].getZ()) // && o1v[1].getZ() >= o2v[0].getZ() && o1v[1].getZ() <= o2v[1].getZ()
{
System.out.println(o1.getRegionIndex() + " > " + o2.getRegionIndex());
return 1;
} else if (o1v[0].getX() <= o2v[0].getX() && o1v[1].getX() >= o2v[1].getX() && o1v[0].getY() <= o2v[0].getY() && o1v[1].getY() >= o2v[1].getY() && o1v[0].getZ() <= o2v[0].getZ() && o1v[1].getZ() >= o2v[1].getZ()) // (o1v[0].getX() < o2v[0].getX() && o1v[1].getX() < o2v[0].getX()) ||
// (o1v[0].getX() > o2v[1].getX() && o1v[1].getX() > o2v[1].getX()) ||
//
// (o1v[0].getY() < o2v[0].getY() && o1v[1].getY() < o2v[0].getY()) ||
// (o1v[0].getY() > o2v[1].getY() && o1v[1].getY() > o2v[1].getY()) ||
//
// (o1v[0].getZ() < o2v[0].getZ() && o1v[1].getZ() < o2v[0].getZ()) ||
// (o1v[0].getZ() > o2v[1].getZ() && o1v[1].getZ() > o2v[1].getZ())
//
// /* (o1v[0].getX() < o2v[0].getX() && o1v[0].getX() > o2v[1].getX() &&
// o1v[1].getX() < o2v[0].getX() && o1v[1].getX() > o2v[1].getX()) ||
// (o1v[0].getY() < o2v[0].getY() && o1v[0].getY() > o2v[1].getY() &&
// o1v[1].getY() < o2v[0].getY() && o1v[1].getY() > o2v[1].getY()) ||
// (o1v[0].getZ() < o2v[0].getZ() && o1v[0].getZ() > o2v[1].getZ() &&
// o1v[1].getZ() < o2v[0].getZ() && o1v[1].getZ() > o2v[1].getZ())*/
{
System.out.println(o1.getRegionIndex() + " <a " + o2.getRegionIndex());
return -1;
} else if ((o1v[0].getX() < o2v[0].getX() && o1v[1].getX() < o2v[0].getX()) || (o1v[0].getX() > o2v[1].getX() && o1v[1].getX() > o2v[1].getX()) || (o1v[0].getY() < o2v[0].getY() && o1v[1].getY() < o2v[0].getY()) || (o1v[0].getY() > o2v[1].getY() && o1v[1].getY() > o2v[1].getY()) || (o1v[0].getZ() < o2v[0].getZ() && o1v[1].getZ() < o2v[0].getZ()) || (o1v[0].getZ() > o2v[1].getZ() && o1v[1].getZ() > o2v[1].getZ())) {
System.out.println(o1.getRegionIndex() + " <b " + o2.getRegionIndex());
return -1;
}
System.out.println("inconclusive " + o1.getRegionIndex() + " == " + o2.getRegionIndex());
return 0;
// System.out.println("inconclusive "+o1.getRegionIndex()+" "+(o1.getNumPixels() - o2.getNumPixels()<0?"<":(o1.getNumPixels() - o2.getNumPixels()>0?">":"=="))+" "+o2.getRegionIndex());
// return o1.getNumPixels() - o2.getNumPixels();
// System.out.println("inconclusive "+o1.getRegionIndex()+" "+(o1.getRegionIndex()-o2.getRegionIndex()<0?"<":(o1.getRegionIndex()-o2.getRegionIndex()>0?">":"=="))+" "+o2.getRegionIndex());
// return o1.getRegionIndex()-o2.getRegionIndex();
// if(o1v[0].getZ() != o2v[0].getZ()){
// return (int)(o1v[0].getZ() - o2v[0].getZ());
// }else if(o1v[0].getY() != o2v[0].getY()){
// return (int)(o1v[0].getY() - o2v[0].getY());
// }else if(o1v[0].getX() != o2v[0].getX()){
// return (int)(o1v[0].getX() - o2v[0].getX());
// }else
// return 0;
}
});
// Convert unfilled regions into parent regions
int currColorIndex = -1;
// for (int i = sortedRegionInfos.size()-1; i >= 0; i--) {
for (int i = 0; i < sortedRegionInfos.size(); i++) {
RegionInfo regInfo = sortedRegionInfos.get(i);
Vect3d[] o1v = (Vect3d[]) regTobb.get(regInfo);
ComboboxROIName cbxroiName = overlayEditorPanelJAI.getComboboxROIName(regInfo);
// System.out.println(cbxroiName+" colorIndex="+regInfo.getPixelValue()+" regIndex="+regInfo.getRegionIndex()+" pixels="+regInfo.getNumPixels()+" "+o1v[0]+" "+o1v[1]);
if (cbxroiName != null) {
currColorIndex = cbxroiName.getContrastColorIndex();
continue;
}
allPixCnt = 0;
for (int z = 0; z < newRegionImage.getNumZ(); z++) {
for (int y = 0; y < newRegionImage.getNumY(); y++) {
for (int x = 0; x < newRegionImage.getNumX(); x++) {
if (regInfo.isIndexInRegion(allPixCnt)) {
BufferedImage plane = roiComposite[z];
byte[] data = ((DataBufferByte) plane.getRaster().getDataBuffer()).getData();
data[x + (plane.getWidth() * y)] = (byte) currColorIndex;
}
allPixCnt++;
}
}
}
}
// for(RegionInfo regInfo:regTobb.keySet()){
// Vect3d[] varr = regTobb.get(regInfo);
// ComboboxROIName cbxroiName = overlayEditorPanelJAI.getComboboxROIName(regInfo);
// regionBounds.put(new BoundingBox(varr[0].getX(), varr[1].getX(),varr[0].getY(), varr[1].getY(),varr[0].getZ(), varr[1].getZ()),new Object[] {cbxroiName});
// }
// for(BoundingBox bb:regionBounds.keySet()){
// ComboboxROIName cbxroiName = ((ComboboxROIName)regionBounds.get(bb)[0]);
// System.out.println(cbxroiName+" bound="+bb.getLoX()+","+bb.getHiX()+" "+bb.getLoY()+","+bb.getHiY()+" "+bb.getLoZ()+","+bb.getHiZ());
//
// }
// Make sure every pixel has only 1 kind of neighbor
// createRegionImageTask.run(newRegionImgHolder);
// newRegionImage = (RegionImage)newRegionImgHolder.get(LOCAL_REGION_IMAGE);
boolean bHasCheck = false;
VCImage checkImage = ROIMultiPaintManager.createVCImageFromBufferedImages(ROIMultiPaintManager.DEFAULT_EXTENT, roiComposite);
newRegionImage = new RegionImage(checkImage, 0, /*0 means generate no surfacecollection*/
checkImage.getExtent(), ROIMultiPaintManager.DEFAULT_ORIGIN, RegionImage.NO_SMOOTHING, null);
TreeSet<Integer> diffNeighbors = new TreeSet<>();
int[][] offsets = new int[][] { { -1, 0, 0 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, { 0, 0, 1 } };
for (int z = 0; z < newRegionImage.getNumZ(); z++) {
BufferedImage plane = roiComposite[z];
byte[] data = ((DataBufferByte) plane.getRaster().getDataBuffer()).getData();
allPixCnt = 0;
for (int y = 0; y < newRegionImage.getNumY(); y++) {
for (int x = 0; x < newRegionImage.getNumX(); x++) {
diffNeighbors.clear();
RegionInfo regInfo = newRegionImage.getRegionInfoFromOffset(allPixCnt);
if (regInfo.getPixelValue() == 0) {
allPixCnt++;
continue;
}
if (x == 19 && y == 15) {
System.out.println("here");
}
for (int i = 0; i < offsets.length; i++) {
int tmpx = offsets[i][0] + x;
if (tmpx < 0 || tmpx >= newRegionImage.getNumX()) {
continue;
}
int tmpy = offsets[i][1] + y;
if (tmpy < 0 || tmpy >= newRegionImage.getNumY()) {
continue;
}
int tmpz = offsets[i][2] + z;
if (tmpz < 0 || tmpz >= newRegionImage.getNumZ()) {
continue;
}
BufferedImage plane0 = roiComposite[tmpz];
byte[] data0 = ((DataBufferByte) plane.getRaster().getDataBuffer()).getData();
byte shiftb = data0[tmpx + (tmpy * newRegionImage.getNumX())];
if (shiftb != regInfo.getPixelValue()) {
diffNeighbors.add(0x000000FF & shiftb);
}
}
// for (int z0 = -1; z0 <= 1; z0+=2) {
// int tmpz = z+z0;
// if(tmpz < 0 || tmpz >= newRegionImage.getNumZ()){
// continue;
// }
// // tmpz = allPixCnt+(z0*newRegionImage.getNumXY());
// BufferedImage plane0 = roiComposite[z+z0];
// byte[] data0 = ((DataBufferByte)plane.getRaster().getDataBuffer()).getData();
// for (int y0 = -1; y0 <= 1; y0+=2) {
// int tmpy = y+y0;
// if(tmpy < 0 || tmpy >= newRegionImage.getNumY()){
// continue;
// }
// // tmpy = tmpz+(y0*newRegionImage.getNumX());
// for (int x0 = -1; x0 <= 1; x0+=2) {
// int tmpx = x+x0;
// if(tmpx < 0 || tmpx >= newRegionImage.getNumX()){
// continue;
// }
// // tmpx = tmpy+(x0);
// byte shiftb = data0[tmpx+(tmpy*newRegionImage.getNumX())];
// if(shiftb != regInfo.getPixelValue()){
// diffNeighbors.add(0x000000FF&shiftb);
// }
// }
// }
// }
allPixCnt++;
if (diffNeighbors.size() > 1) {
bHasCheck = true;
data[x + y * newRegionImage.getNumX()] = (byte) checkHolder[0];
}
}
}
}
if (!bHasCheck && cbxHolder[0] != null) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
overlayEditorPanelJAI.deleteROIName(cbxHolder[0]);
}
});
}
}
};
// }).start();
return new ArrayList<>(Arrays.asList(new AsynchClientTask[] { sampleSTLtask, addROInamesTask, mergeBackgroundRegions, getUpdateDisplayAfterCropTask() }));
// JFileChooser importJFC = new JFileChooser(ClientRequestManager.getPreferredPath(UserPreferences.getLastUserPreferences()));
// importJFC.setDialogTitle("Choose .stl file to import");
// importJFC.setMultiSelectionEnabled(true);
// int result = importJFC.showOpenDialog(overlayEditorPanelJAI);
// if(result == JFileChooser.APPROVE_OPTION){
// File[] selectedFiles = importJFC.getSelectedFiles();
// if(statsHelper == null){
// statsHelper = calcMinMax(selectedFiles);
// }
// ClientRequestManager.setPreferredPath(UserPreferences.getLastUserPreferences(), selectedFiles[0]);
//
// Vect3d worldOrigin = new Vect3d(statsHelper.xmin, statsHelper.ymin, statsHelper.zmin);
// Vect3d worldCollapsedBoundingBox = new Vect3d(statsHelper.xmax-statsHelper.xmin, statsHelper.ymax-statsHelper.ymin, statsHelper.zmax-statsHelper.zmin);
// Vect3d scale = new Vect3d(worldCollapsedBoundingBox.getX()/(2.0*primarySampleSizes.getX()), worldCollapsedBoundingBox.getY()/(2.0*primarySampleSizes.getY()), worldCollapsedBoundingBox.getZ()/(2.0*primarySampleSizes.getZ()));
// // if(scale.getX() !=0 && scale.getX() >= (scale.getY()==0?scale.getX():scale.getY()) && scale.getX() >= (scale.getZ()==0?scale.getX():scale.getZ())){
// // scale = new Vect3d(scale.getX(), scale.getX(), scale.getX());
// // }else if(scale.getY() !=0 && scale.getY() >= (scale.getX()==0?scale.getY():scale.getX()) && scale.getY() >= (scale.getZ()==0?scale.getY():scale.getZ())){
// // scale = new Vect3d(scale.getY(), scale.getY(), scale.getY());
// // }else if(scale.getZ() !=0 && scale.getZ() >= (scale.getY()==0?scale.getZ():scale.getY()) && scale.getZ() >= (scale.getX()==0?scale.getZ():scale.getX())){
// // scale = new Vect3d(scale.getZ(), scale.getZ(), scale.getZ());
// // }
// if(scale.getX() !=0 && scale.getX() <= (scale.getY()==0?scale.getX():scale.getY()) && scale.getX() <= (scale.getZ()==0?scale.getX():scale.getZ())){
// scale = new Vect3d(scale.getX(), scale.getX(), scale.getX());
// }else if(scale.getY() !=0 && scale.getY() <= (scale.getX()==0?scale.getY():scale.getX()) && scale.getY() <= (scale.getZ()==0?scale.getY():scale.getZ())){
// scale = new Vect3d(scale.getY(), scale.getY(), scale.getY());
// }else if(scale.getZ() !=0 && scale.getZ() <= (scale.getY()==0?scale.getZ():scale.getY()) && scale.getZ() <= (scale.getX()==0?scale.getZ():scale.getX())){
// scale = new Vect3d(scale.getZ(), scale.getZ(), scale.getZ());
// }
// TreeMap<BoundingBox,Object[]> regionBounds = new TreeMap<>(new Comparator<BoundingBox>() {
// @Override
// public int compare(BoundingBox arg0, BoundingBox arg1) {
// if(arg1 == arg0){
// return 0;
// }
// if(arg0.getLoX() == arg1.getLoX() &&
// arg0.getLoY() == arg1.getLoY() &&
// arg0.getLoZ() == arg1.getLoZ() &&
// arg0.getHiX() == arg1.getHiX() &&
// arg0.getHiY() == arg1.getHiY() &&
// arg0.getHiZ() == arg1.getHiZ()){
// return 0;
// }
// return (arg0.getLoX() >= arg1.getLoX() &&
// arg0.getLoY() >= arg1.getLoY() &&
// arg0.getLoZ() >= arg1.getLoZ() &&
// arg0.getHiX() <= arg1.getHiX() &&
// arg0.getHiY() <= arg1.getHiY() &&
// arg0.getHiZ() <= arg1.getHiZ()?-1:+1);
// }
// });
// for (int j = 0; j < selectedFiles.length; j++) {
// SurfaceCollection surfaceCollection = statsHelper.recalSurfs.get(j);//ClientRequestManager.createSurfaceCollectionFromSurfaceFile(selectedFile);
// for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
// Surface surface = surfaceCollection.getSurfaces(i);
// System.out.println("surface "+i);
// Vect3d xyzLow = new Vect3d(surface.getPolygons(0).getNodes(0).getX(),surface.getPolygons(0).getNodes(1).getX(),surface.getPolygons(0).getNodes(2).getX());
// Vect3d xyzHigh = new Vect3d(xyzLow);
// ComboboxROIName[] existingRoiNames = overlayEditorPanelJAI.getAllCompositeROINamesAndColors();
// byte value = (byte)getUnusedROIColorIndex(existingRoiNames);
// String roiName = FilenameUtils.getBaseName(selectedFiles[j].getName());
// roiName = TokenMangler.fixTokenStrict(roiName, 6);
// roiName+= "_"+i;
// overlayEditorPanelJAI.addROIName(roiName, true, roiName, true, value);
// for (int k = 0; k < surface.getPolygonCount(); k++){
// Polygon polygon = surface.getPolygons(k);
// // for (Node pnode:polygon.getNodes()) {
// // xyzLow.set(Math.min(xyzLow.getX(), pnode.getX()),Math.min(xyzLow.getY(), pnode.getY()),Math.min(xyzLow.getZ(), pnode.getZ()));
// // xyzHigh.set(Math.max(xyzHigh.getX(), pnode.getX()),Math.max(xyzHigh.getY(), pnode.getY()),Math.max(xyzHigh.getZ(), pnode.getZ()));
// // }
// if(k%10000 == 0){
// System.out.println("progress= file "+(j+1)+" of "+selectedFiles.length+" "+((k*100)/surface.getPolygonCount())+"%");
// }
// // System.out.println(" polygon "+j+" "+polygon.getNodes(0)+" "+polygon.getNodes(1)+" "+polygon.getNodes(2));
// Vect3d line1 = new Vect3d(polygon.getNodes(0));
// Vect3d end1 = new Vect3d(polygon.getNodes(2));
// Vect3d incr1 = Vect3d.sub(end1,line1);
// incr1.unit();
// incr1.set(incr1.getX()*scale.getX(), incr1.getY()*scale.getY(), incr1.getZ()*scale.getZ());
// Vect3d line2 = new Vect3d(line1);
// Vect3d end2 = new Vect3d(polygon.getNodes(1));
// Vect3d incr2 = Vect3d.sub(end2,line2);
// incr2.unit();
// incr2.set(incr2.getX()*scale.getX(), incr2.getY()*scale.getY(), incr2.getZ()*scale.getZ());
// while(true){
// Vect3d line3 = new Vect3d(line1);
// Vect3d end3 = new Vect3d(line2);
// Vect3d incr3 = Vect3d.sub(end3,line3);
// if(incr3.length() != 0){
// incr3.unit();
// incr3.set(incr3.getX()*scale.getX(), incr3.getY()*scale.getY(), incr3.getZ()*scale.getZ());
// }
// while(true){
// calcXYZ(line3, worldOrigin, worldCollapsedBoundingBox, primarySampleSizes,subSampleOffset,value);
// line3.add(incr3);
// Vect3d check = Vect3d.sub(end3, line3);
// if((check.length()==0) || Math.signum(check.getX()) != Math.signum(incr3.getX()) || Math.signum(check.getY()) != Math.signum(incr3.getY()) || Math.signum(check.getZ()) != Math.signum(incr3.getZ())){
// calcXYZ(end3, worldOrigin, worldCollapsedBoundingBox, primarySampleSizes,subSampleOffset,value);
// break;
// }
// }
// if(line1.equals(end1) && line2.equals(end2)){
// break;
// }
//
// line1.add(incr1);
// Vect3d check = Vect3d.sub(end1, line1);
// if(check.length()==0 || Math.signum(check.getX()) != Math.signum(incr1.getX()) || Math.signum(check.getY()) != Math.signum(incr1.getY()) || Math.signum(check.getZ()) != Math.signum(incr1.getZ())){
// line1 = new Vect3d(end1);
// }
// line2.add(incr2);
// check = Vect3d.sub(end2, line2);
// if(check.length()==0 || Math.signum(check.getX()) != Math.signum(incr2.getX()) || Math.signum(check.getY()) != Math.signum(incr2.getY()) || Math.signum(check.getZ()) != Math.signum(incr2.getZ())){
// line2 = new Vect3d(end2);
// }
// }
// }
// // regionBounds.put(new BoundingBox(xyzLow.getX(), xyzHigh.getX(),xyzLow.getY(), xyzHigh.getY(),xyzLow.getZ(), xyzHigh.getZ()),new Object[] {new int[] {j,i},roiName});
// }
// }
// // for(BoundingBox bb:regionBounds.keySet()){
// // System.out.println(((int[])regionBounds.get(bb)[0])[0]+","+((int[])regionBounds.get(bb)[0])[1]+" name="+((String)regionBounds.get(bb)[1])+" bound="+bb.getLoX()+","+bb.getHiX()+" "+bb.getLoY()+","+bb.getHiY()+" "+bb.getLoZ()+","+bb.getHiZ());
// // }
// updateAuxiliaryInfo(originalISize, null);
// getUpdateDisplayAfterCropTask().run(null);
//
// new Thread(new Runnable() {
// @Override
// public void run() {
// while(ClientTaskDispatcher.isBusy()){
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// TreeMap<RegionInfo, Vect3d[]> regTobb = new TreeMap<>(new Comparator<RegionInfo>() {
// @Override
// public int compare(RegionInfo arg0, RegionInfo arg1) {
// return arg0.getRegionIndex()-arg1.getRegionIndex();
// }
// });
// int allPixCnt = regionImage.getNumX()*regionImage.getNumY()*regionImage.getNumZ();
// for (int z = 0; z < regionImage.getNumZ(); z++) {
// for (int y = 0; y < regionImage.getNumY(); y++) {
// for (int x = 0; x < regionImage.getNumX(); x++) {
// allPixCnt-=1;
// RegionInfo regInfo = regionImage.getRegionInfoFromOffset(allPixCnt);
// Vect3d[] bounds = regTobb.get(regInfo);
// if(bounds == null){
// bounds = new Vect3d[] {new Vect3d(),new Vect3d()};
// regTobb.put(regInfo, bounds);
// }
// bounds[0].set(Math.min(bounds[0].getX(), x),Math.min(bounds[0].getY(), y),Math.min(bounds[0].getZ(), z));
// bounds[1].set(Math.max(bounds[1].getX(), x),Math.max(bounds[1].getY(), y),Math.max(bounds[1].getZ(), z));
//
// }
// }
// }
// for(RegionInfo regInfo:regTobb.keySet()){
// Vect3d[] varr = regTobb.get(regInfo);
// ComboboxROIName cbxroiName = overlayEditorPanelJAI.getComboboxROIName(regInfo);
// regionBounds.put(new BoundingBox(varr[0].getX(), varr[1].getX(),varr[0].getY(), varr[1].getY(),varr[0].getZ(), varr[1].getZ()),new Object[] {cbxroiName});
// }
// for(BoundingBox bb:regionBounds.keySet()){
// ComboboxROIName cbxroiName = ((ComboboxROIName)regionBounds.get(bb)[0]);
// System.out.println(cbxroiName+" bound="+bb.getLoX()+","+bb.getHiX()+" "+bb.getLoY()+","+bb.getHiY()+" "+bb.getLoZ()+","+bb.getHiZ());
//
// }
// }
// }).start();
// }
// }catch (Exception e) {
// e.printStackTrace();
// DialogUtils.showErrorDialog(overlayEditorPanelJAI, e.getMessage());
// }
}
Aggregations