use of cbit.image.DisplayPreferences in project vcell by virtualcell.
the class IMGExporter method makeMedia.
// private ParticleInfo checkParticles_unused(final ExportSpecs exportSpecs,User user,DataServerImpl dataServerImpl,final long jobID) throws Exception{
// int particleMode = FormatSpecificSpecs.PARTICLE_NONE;
// if(exportSpecs.getFormatSpecificSpecs() instanceof ImageSpecs){
// particleMode = ((ImageSpecs)exportSpecs.getFormatSpecificSpecs()).getParticleMode();
// }else if (exportSpecs.getFormatSpecificSpecs() instanceof MovieSpecs){
// particleMode = ((MovieSpecs)exportSpecs.getFormatSpecificSpecs()).getParticleMode();
// }
// if(particleMode == FormatSpecificSpecs.PARTICLE_NONE){
// return null;
// }
//
// final VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
// CartesianMesh cartesianMesh = dataServerImpl.getMesh(user, vcdID);
// int dimension = cartesianMesh.getGeometryDimension();
//
// String[] variableNames = exportSpecs.getVariableSpecs().getVariableNames();
//
// File visitExeLocation =
// new File(PropertyLoader.getRequiredProperty(PropertyLoader.visitSmoldynVisitExecutableProperty));
// File visitSmoldynScriptLocation =
// new File(PropertyLoader.getRequiredProperty(PropertyLoader.visitSmoldynScriptPathProperty));
// final File visitSmoldynScriptTempDir = PropertyLoader.getSystemTemporaryDirectory();
//
// //-----Get all data (from archive if necessary)
// SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
// SimulationData simData = new SimulationData(vcdID,
// new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty),vcdID.getOwner().getName()),
// new File(PropertyLoader.getProperty(PropertyLoader.primarySimDataDirInternalProperty,null),vcdID.getOwner().getName()),
// simDataAmplistorInfo);
//
// File logFile = simData.getLogFile();
// if(!logFile.exists()){
// throw new Exception("ImgExport particle, Couldn't find Log file "+logFile.getAbsolutePath());
// }
// simData.getMesh();//gets mesh and meshmetrics files from archive if necessary
// simData.getSubdomainFile();
// simData.getFunctionsFile(false);
// int timeIndex = 1;//smoldyn always begins at timeindex 1
// while(true){
// if(!simData.getSmoldynOutputFile(timeIndex).exists()){//get smoldynOutput files
// break;
// }
// timeIndex++;
// }
// //-----
//
// File visitDataPathFragment = new File(logFile.getParent(),vcdID.getID()+"_");
// System.out.println(visitExeLocation.getAbsolutePath());
// System.out.println(visitSmoldynScriptLocation.getAbsolutePath());
// System.out.println(visitSmoldynScriptTempDir.getAbsolutePath());
// System.out.println(visitDataPathFragment.getAbsolutePath());
//
// //if(true){return new ParticleInfo(visitSmoldynScriptTempDir);}
// if(exportSpecs.getTimeSpecs().getAllTimes().length == 1){
// throw new IllegalArgumentException("Time zero not valid for smoldyn particle data");
// }
// int beginIndexTime = exportSpecs.getTimeSpecs().getBeginTimeIndex();
// int endIndexTime = exportSpecs.getTimeSpecs().getEndTimeIndex();
//
// System.out.println("beginIndexTime="+beginIndexTime+" endIndexTime="+endIndexTime);
//
// ArrayList<String> args = new ArrayList<String>();
// args.add(visitExeLocation.getAbsolutePath());//location of visit
// args.add("-nowin");
// args.add("-cli");
// args.add("-s");
//
// args.add(visitSmoldynScriptLocation.getAbsolutePath());//location of the script
// args.add(visitDataPathFragment.getAbsolutePath()); //location of the SimID
// args.add(visitSmoldynScriptTempDir.getAbsolutePath()); // where frames are dumped
// args.add(dimension+""); //dimension
// args.add(beginIndexTime+"");
// args.add(endIndexTime+"");
// args.add(4+"");//particle sphere size
// args.add(FormatSpecificSpecs.SMOLDYN_DEFAULT_FRAME_SIZE.width+"");//frame size X
// args.add(FormatSpecificSpecs.SMOLDYN_DEFAULT_FRAME_SIZE.height+"");//frame size Y
// args.add(variableNames.length+""); // 0 = show all the particles. >0 == show n different particles, to be listed below
// for (int i = 0; i < variableNames.length; i++) {
// args.add(variableNames[i]);
// }
//
// final String tempFilePrefix = vcdID.getID()+"_p3d";
//
// //Monitor progress of smoldyn script
// exportServiceImpl.fireExportProgress(jobID, vcdID, "MEDIA", 0.0);
// final boolean[] finishedFlag = new boolean[] {false};
// final int numTimePoints = exportSpecs.getTimeSpecs().getEndTimeIndex()-exportSpecs.getTimeSpecs().getBeginTimeIndex()+1;
// Thread progressThread = new Thread(new Runnable() {
// public void run() {
// System.out.println("smoldyn progress monitor started");
// while(!finishedFlag[0]){
// int count = 0;
// File[] tempFiles = visitSmoldynScriptTempDir.listFiles();
// for (int i = 0; i < tempFiles.length; i++) {
// if(tempFiles[i].getName().startsWith(tempFilePrefix) ||
// (tempFiles[i].getName().startsWith(vcdID.getID()) &&
// tempFiles[i].getName().endsWith(".jpeg"))){
// count+= 1;
// }
// }
// double progress = .5 * (double)count / (double)(2*numTimePoints);
// exportServiceImpl.fireExportProgress(jobID, vcdID, "MEDIA", progress);
// //System.out.println("All files read="+tempFiles.length+" Files counted="+count+" progress="+progress);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// return;//This shouldn't happen but if so just quit
// }
// }
// System.out.println("smoldyn progress monitor finished");
// }
// });
// progressThread.start();
//
//
// try{
// final long TIME_OUT = 1200000; //20 minutes
// Executable executable = new Executable(args.toArray(new String[0]),TIME_OUT);
// executable.start();//blocking, internal monitoring, return after timeout
// if(!executable.getStatus().equals(ExecutableStatus.COMPLETE)){
// System.out.println(executable.getStderrString());
// System.out.println(executable.getStdoutString());
// throw new Exception("Particle data exporter did not complete normally. "+(executable.getStatus()==null?"":executable.getStatus().toString()));
// }
// }finally{
// finishedFlag[0] = true;
// //Remove temp files created by smoldyn script
// File[] tempFiles = visitSmoldynScriptTempDir.listFiles();
// for (int i = 0; i < tempFiles.length; i++) {
// if(tempFiles[i].getName().startsWith(tempFilePrefix)){
// tempFiles[i].delete();
// }
// }
// }
// return new ParticleInfo(visitSmoldynScriptTempDir);
// }
private static ExportOutput[] makeMedia(ExportServiceImpl exportServiceImpl, OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs, ClientTaskStatusSupport clientTaskStatusSupport, ParticleInfo particleInfo, FileDataContainerManager fileDataContainerManager) throws RemoteException, IOException, GIFFormatException, DataAccessException, Exception {
boolean bOverLay = false;
int sliceIndicator = 0;
if (particleInfo == null) {
sliceIndicator = (exportSpecs.getGeometrySpecs().getModeID() == ExportConstants.GEOMETRY_FULL ? FULL_MODE_ALL_SLICES : exportSpecs.getGeometrySpecs().getSliceNumber());
}
int imageScale = 0;
int meshMode = 0;
int mirroringType = 0;
int membraneScale = 0;
double duration = 1.0;
DisplayPreferences[] displayPreferences = null;
int volVarMembrOutlineThickness = 1;
if (exportSpecs.getFormatSpecificSpecs() instanceof ImageSpecs) {
bOverLay = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getOverlayMode();
imageScale = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getImageScaling();
volVarMembrOutlineThickness = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getVolVarMembrOutlineThickness();
meshMode = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getMeshMode();
mirroringType = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getMirroringType();
membraneScale = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getMembraneScaling();
displayPreferences = ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getDisplayPreferences();
// convert from milliseconds to seconds
duration = (double) ((ImageSpecs) exportSpecs.getFormatSpecificSpecs()).getDuration() / 1000.0;
} else if (exportSpecs.getFormatSpecificSpecs() instanceof MovieSpecs) {
bOverLay = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getOverlayMode();
imageScale = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getImageScaling();
volVarMembrOutlineThickness = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getVolVarMembrOutlineThickness();
meshMode = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getMeshMode();
mirroringType = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getMirroringType();
membraneScale = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getMembraneScaling();
displayPreferences = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getDisplayPreferences();
// convert from milliseconds to seconds
duration = ((MovieSpecs) exportSpecs.getFormatSpecificSpecs()).getDuration() / 1000.0;
} else {
throw new DataFormatException("Unknown FormatSpecificSpec " + exportSpecs.getFormatSpecificSpecs().getClass().getName());
}
Vector<ExportOutput> exportOutputV = new Vector<ExportOutput>();
VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
int beginTimeIndex = exportSpecs.getTimeSpecs().getBeginTimeIndex();
int endTimeIndex = exportSpecs.getTimeSpecs().getEndTimeIndex();
boolean bSingleTimePoint = beginTimeIndex == endTimeIndex;
String[] varNames = (particleInfo == null ? exportSpecs.getVariableSpecs().getVariableNames() : new String[] { "smoldynParticleDummy" });
double[] allTimes = dataServerImpl.getDataSetTimes(user, vcdID);
int startSlice = (sliceIndicator == FULL_MODE_ALL_SLICES ? 0 : sliceIndicator);
int sliceCount = FormatSpecificSpecs.getSliceCount(sliceIndicator == FULL_MODE_ALL_SLICES, exportSpecs.getGeometrySpecs().getAxis(), dataServerImpl.getMesh(user, vcdID));
double progressIncr = 1.0 / (sliceCount * (endTimeIndex - beginTimeIndex + 1) * varNames.length);
double progress = 0.0;
MovieHolder movieHolder = new MovieHolder();
Dimension imageDimension = FormatSpecificSpecs.getImageDimension(meshMode, imageScale, dataServerImpl.getMesh(user, vcdID), exportSpecs.getGeometrySpecs().getAxis());
int originalWidth = (int) imageDimension.getWidth();
int originalHeight = (int) imageDimension.getHeight();
ExportRenderInfo exportRenderInfo = null;
try {
for (int sliceNumber = startSlice; sliceNumber < startSlice + sliceCount; sliceNumber++) {
if (particleInfo == null) {
PDEOffscreenRenderer offScreenRenderer = new PDEOffscreenRenderer(outputContext, user, dataServerImpl, vcdID);
offScreenRenderer.setNormalAxis(exportSpecs.getGeometrySpecs().getAxis());
offScreenRenderer.setSlice(sliceNumber);
exportRenderInfo = new ExportRenderInfo(offScreenRenderer);
} else {
exportRenderInfo = new ExportRenderInfo(particleInfo, allTimes, vcdID, beginTimeIndex);
Dimension particleImageSize = particleInfo.getImageFrameSize(vcdID);
originalWidth = particleImageSize.width;
originalHeight = particleImageSize.height;
}
int varNameIndex0 = 0;
int timeIndex0 = beginTimeIndex;
int[] overLayPixels = null;
// set default time if only 1 timepoint
movieHolder.setSampleDurationSeconds(duration);
boolean bEndslice = sliceNumber == (startSlice + sliceCount - 1);
while (true) {
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setProgress((int) (progress * 100));
if (clientTaskStatusSupport.isInterrupted()) {
throw UserCancelException.CANCEL_GENERIC;
}
}
exportServiceImpl.fireExportProgress(jobID, vcdID, "MEDIA", (particleInfo == null ? progress : .5 + (progress / 2.0)));
progress += progressIncr;
MirrorInfo currentSliceTimeMirrorInfo = renderAndMirrorSliceTimePixels(exportRenderInfo, varNames[varNameIndex0], allTimes[timeIndex0], displayPreferences[varNameIndex0], imageScale, membraneScale, meshMode, volVarMembrOutlineThickness, originalWidth, originalHeight, mirroringType);
if (bOverLay) {
if (varNames.length == 1) {
overLayPixels = currentSliceTimeMirrorInfo.getPixels();
} else {
// Overlay append in Y-direction
if (overLayPixels == null) {
overLayPixels = new int[currentSliceTimeMirrorInfo.getPixels().length * varNames.length];
}
int appendIndex = currentSliceTimeMirrorInfo.getPixels().length * varNameIndex0;
System.arraycopy(currentSliceTimeMirrorInfo.getPixels(), 0, overLayPixels, appendIndex, currentSliceTimeMirrorInfo.getPixels().length);
}
}
if (timeIndex0 != endTimeIndex) {
// calculate duration for each timepoint
movieHolder.setSampleDurationSeconds((allTimes[timeIndex0 + 1] - allTimes[timeIndex0]) / (allTimes[endTimeIndex + (endTimeIndex == allTimes.length - 1 ? 0 : 1)] - allTimes[beginTimeIndex]) * duration);
} else {
// when last or only 1 timepoint, use last duration set
movieHolder.setSampleDurationSeconds(movieHolder.getSampleDurationSeconds());
}
// Index var and time properly
boolean bBegintime = timeIndex0 == beginTimeIndex;
boolean bEndTime = timeIndex0 == endTimeIndex;
if (bOverLay) {
varNameIndex0++;
if (varNameIndex0 == varNames.length) {
String dataID = createDataID(exportSpecs, sliceNumber, "overlay", timeIndex0);
createMedia(exportOutputV, vcdID, dataID, exportSpecs, true, bEndslice, bBegintime, bEndTime, bSingleTimePoint, varNames, displayPreferences, movieHolder, overLayPixels, currentSliceTimeMirrorInfo.getMirrorWidth(), currentSliceTimeMirrorInfo.getMirrorHeight() * varNames.length, fileDataContainerManager);
varNameIndex0 = 0;
timeIndex0++;
if (timeIndex0 > endTimeIndex) {
break;
}
}
} else {
String dataID = createDataID(exportSpecs, sliceNumber, varNames[varNameIndex0], timeIndex0);
boolean bEndVars = varNameIndex0 == varNames.length - 1;
createMedia(exportOutputV, vcdID, dataID, exportSpecs, bEndVars, bEndslice, bBegintime, bEndTime, bSingleTimePoint, new String[] { varNames[varNameIndex0] }, new DisplayPreferences[] { displayPreferences[varNameIndex0] }, movieHolder, currentSliceTimeMirrorInfo.getPixels(), currentSliceTimeMirrorInfo.getMirrorWidth(), currentSliceTimeMirrorInfo.getMirrorHeight(), fileDataContainerManager);
timeIndex0++;
if (timeIndex0 > endTimeIndex) {
timeIndex0 = beginTimeIndex;
varNameIndex0++;
if (varNameIndex0 == varNames.length) {
break;
}
}
}
}
}
} finally {
if (exportRenderInfo != null) {
exportRenderInfo.cleanup();
}
}
return exportOutputV.toArray(new ExportOutput[0]);
}
use of cbit.image.DisplayPreferences in project vcell by virtualcell.
the class RasterExporter method makePLYWithTexData.
public ExportOutput[] makePLYWithTexData(OutputContext outputContext, JobRequest jobRequest, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs, FileDataContainerManager fileDataContainerManager) throws Exception {
String simID = exportSpecs.getVCDataIdentifier().getID();
VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
cbit.vcell.solvers.CartesianMesh mesh = dataServerImpl.getMesh(user, vcdID);
TimeSpecs timeSpecs = exportSpecs.getTimeSpecs();
VariableSpecs variableSpecs = exportSpecs.getVariableSpecs();
Vector<ExportOutput> exportOutV = new Vector<ExportOutput>();
RegionImage regionImage = MeshDisplayAdapter.generateRegionImage(mesh, null);
PLYSpecs plySpecs = (PLYSpecs) exportSpecs.getFormatSpecificSpecs();
DisplayPreferences[] displayPreferences = plySpecs.getDisplayPreferences();
// BitSet bInDomain = null;
// String variableName = variableSpecs.getVariableNames()[0];
// Domain varDomain = null;
// DataIdentifier[] dataIdentifiers = dataServerImpl.getDataIdentifiers(outputContext, user, vcdID);
// for (int i = 0; i < dataIdentifiers.length; i++) {
// //dataIdentifier.getDomain();
// if(dataIdentifiers[i].getName().equals(variableName)){
// varDomain = dataIdentifiers[i].getDomain();
// break;
// }
// }
// MembraneElement membraneElement = mesh.getMembraneElements()[faceIndex];
// String memSubdomainName = (varDomain==null?null:mesh.getMembraneSubdomainNamefromMemIndex(faceIndex));
// boolean bInDomain = (varDomain==null?true:varDomain.getName().equals(memSubdomainName));
DisplayAdapterService das = new DisplayAdapterService();
StringWriter stringWriter = new StringWriter();
PolyTexHelper imgResults = writeStanfordPolygonTex(regionImage, stringWriter, /*,bInDomain*/
mesh);
// mesh
ExportOutput exportOut = new ExportOutput(true, ".ply", simID.toString(), "_memb", fileDataContainerManager);
fileDataContainerManager.append(exportOut.getFileDataContainerID(), stringWriter.toString());
exportOutV.add(exportOut);
// special neighbor annotation image
ExportOutput textImagetOut0 = new ExportOutput(true, ".png", simID.toString(), "_membAnnot", fileDataContainerManager);
fileDataContainerManager.append(textImagetOut0.getFileDataContainerID(), imgResults.specialNeighborImage);
exportOutV.add(textImagetOut0);
for (int varNameIndex = 0; varNameIndex < variableSpecs.getVariableNames().length; varNameIndex++) {
if (das.fetchColorModel(displayPreferences[varNameIndex].getColorMode()) == null) {
if (displayPreferences[varNameIndex].getColorMode().equals(DisplayAdapterService.GRAY)) {
das.addColorModelForValues(DisplayAdapterService.createGrayColorModel(), DisplayAdapterService.createBlueRedSpecialColors(), displayPreferences[varNameIndex].getColorMode());
} else {
das.addColorModelForValues(DisplayAdapterService.createBlueRedColorModel(), DisplayAdapterService.createGraySpecialColors(), displayPreferences[varNameIndex].getColorMode());
// das.setActiveColorModelID("Contrast");
}
}
// BitSet domainValid = (displayPreferences[varNameIndex]==null?null:(displayPreferences[varNameIndex].getDomainValid()==null?null:displayPreferences[varNameIndex].getDomainValid()));
ExportSpecs.setupDisplayAdapterService(displayPreferences[varNameIndex], das, displayPreferences[varNameIndex].getScaleSettings());
for (int j = timeSpecs.getBeginTimeIndex(); j <= timeSpecs.getEndTimeIndex(); j++) {
BufferedImage image = createTextureImage(imgResults.imageSideSize);
int[] imgBuffer = ((DataBufferInt) (image.getRaster().getDataBuffer())).getData();
Arrays.fill(imgBuffer, Integer.MAX_VALUE);
SimDataBlock simDataBlock = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[varNameIndex], timeSpecs.getAllTimes()[j]);
for (int k = 0; k < imgResults.dataIndexes.length; k++) {
if (imgBuffer[k] != Integer.MAX_VALUE) {
System.out.println("texture pixel used twice");
}
double avgVal = 0;
for (int l = 0; l < imgResults.dataIndexes[k].length; l++) {
avgVal += simDataBlock.getData()[imgResults.dataIndexes[k][l]];
}
imgBuffer[k] = das.getColorFromValue(avgVal / imgResults.dataIndexes[k].length);
}
byte[] pngImage = flipPNG(image);
ExportOutput textImagetOut = new ExportOutput(true, ".png", simID.toString(), "_memb_" + variableSpecs.getVariableNames()[varNameIndex] + "_" + j, fileDataContainerManager);
fileDataContainerManager.append(textImagetOut.getFileDataContainerID(), pngImage);
exportOutV.add(textImagetOut);
}
}
ExportOutput[] exportOutputArr = exportOutV.toArray(new ExportOutput[0]);
return exportOutputArr;
}
use of cbit.image.DisplayPreferences in project vcell by virtualcell.
the class FRAPStudyPanel method showMovie.
private void showMovie() {
AsynchClientTask createMovieTask = new AsynchClientTask("Buffering movie data...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
if (fStudy == null) {
return;
}
if (fStudy.getMovieURLString() != null && fStudy.getMovieFileString() != null) {
hashTable.put("FrapStudy", fStudy);
return;
}
// create export specs
Simulation sim = null;
if (fStudy.getBioModel() == null || fStudy.getBioModel().getSimulations() == null || fStudy.getBioModel().getSimulations().length < 1) {
return;
} else {
sim = fStudy.getBioModel().getSimulations()[0];
}
FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier());
}
ExternalDataIdentifier timeSeriesExtDataID = fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier();
ExternalDataIdentifier maskExtDataID = fStudy.getRoiExternalDataInfo().getExternalDataIdentifier();
// add sim
int jobIndex = 0;
SimulationJob simJob = new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs);
VCDataIdentifier[] dataIDs = new VCDataIdentifier[] { timeSeriesExtDataID, maskExtDataID, simJob.getVCDataIdentifier() };
VCDataIdentifier vcDataId = new MergedDataInfo(LocalWorkspace.getDefaultOwner(), dataIDs, FRAPStudy.VFRAP_DS_PREFIX);
PDEDataManager dataManager = new PDEDataManager(null, getLocalWorkspace().getVCDataManager(), vcDataId);
PDEDataContext pdeDataContext = new ClientPDEDataContext(dataManager);
ExportFormat format = ExportFormat.QUICKTIME;
String[] variableNames = new String[] { NORM_FLUOR_VAR, NORM_SIM_VAR };
VariableSpecs variableSpecs = new VariableSpecs(variableNames, ExportConstants.VARIABLE_MULTI);
// int endTimeIndex = (int)Math.round(sim.getSolverTaskDescription().getTimeBounds().getEndingTime()/((UniformOutputTimeSpec)sim.getSolverTaskDescription().getOutputTimeSpec()).getOutputTimeStep());
int endTimeIndex = getFRAPSimDataViewerPanel().getOriginalDataViewer().getPdeDataContext().getTimePoints().length - 1;
TimeSpecs timeSpecs = new TimeSpecs(0, endTimeIndex, pdeDataContext.getTimePoints(), ExportConstants.TIME_RANGE);
int geoMode = ExportConstants.GEOMETRY_SLICE;
GeometrySpecs geometrySpecs = new GeometrySpecs(null, Coordinate.Z_AXIS, 0, geoMode);
// 10s
double duration = 10000;
DisplayPreferences pref1 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
DisplayPreferences pref2 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
DisplayPreferences[] displayPref = new DisplayPreferences[] { pref1, pref2 };
int imageScale = 1;
int membraneScale = 1;
int scaleMode = ImagePaneModel.MESH_MODE;
// the default setting in MediaSettingsPanel.
int volVarMemOutlineThickness = 1;
MovieSpecs mSpec = new MovieSpecs(duration, true, displayPref, ExportFormat.QUICKTIME, ExportConstants.NO_MIRRORING, volVarMemOutlineThickness, imageScale, membraneScale, scaleMode, FormatSpecificSpecs.CODEC_JPEG, 1.0f, /*lossless*/
false, FormatSpecificSpecs.PARTICLE_NONE);
// mSpec.setViewZoom(1);
ExportSpecs exSpecs = new ExportSpecs(vcDataId, format, variableSpecs, timeSpecs, geometrySpecs, mSpec, fStudy.getName(), null);
// pass the request
ExportEvent exportEvt = ((VirtualFrapWindowManager) getFlourDataViewer().getDataViewerManager()).startExportMovie(exSpecs, outputContext, this.getClientTaskStatusSupport());
hashTable.put("ExportEvt", exportEvt);
hashTable.put("FrapStudy", fStudy);
}
};
AsynchClientTask showMovieTask = new AsynchClientTask("Showing movie ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
ExportEvent exportEvt = (ExportEvent) hashTable.get("ExportEvt");
FRAPStudy fStudy = (FRAPStudy) hashTable.get("FrapStudy");
// show movie if successfully exported
if (exportEvt != null) {
final String fileURLString = System.getProperty(PropertyLoader.exportBaseURLProperty) + exportEvt.getJobID() + ".mov";
final String fileString = System.getProperty(PropertyLoader.exportBaseDirInternalProperty) + exportEvt.getJobID() + ".mov";
fStudy.setMovieURLString(fileURLString);
fStudy.setMovieFileString(fileString);
}
showMovieInDialog(fStudy.getMovieURLString(), fStudy.getMovieFileString());
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { createMovieTask, showMovieTask }, true, true, null, true);
}
use of cbit.image.DisplayPreferences in project vcell by virtualcell.
the class IMGExporter method main.
public static void main(String[] args) throws Exception {
if (args.length < 7) {
System.out.println("Usage: IMGExporter username userkey simulationkey userdatadir beginTimeIndex endTimeIndex {varName1 varName2 ...}");
System.exit(0);
}
String userName = args[0];
String userKey = args[1];
String SimulationKey = args[2];
String primaryDirStr = args[3];
int beginTimeIndex = Integer.valueOf(args[4]);
int endTimeIndex = Integer.valueOf(args[5]);
String[] varNames = new String[args.length - 6];
if (args.length > 6) {
for (int i = 6; i < args.length; i++) {
varNames[i - 6] = args[i];
}
}
PropertyLoader.loadProperties();
User user = new User(userName, new KeyValue(userKey));
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(new KeyValue(SimulationKey), user);
VCSimulationDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, 0);
class PrintingExportServiceImpl extends ExportServiceImpl {
public PrintingExportServiceImpl() {
super();
}
@Override
protected void fireExportEvent(ExportEvent event) {
super.fireExportEvent(event);
System.out.println("Event type=" + event.getEventTypeID() + " JobID=" + event.getJobID() + " progress=" + event.getProgress());
}
}
ExportServiceImpl exportServiceImpl = new PrintingExportServiceImpl();
Cachetable cachetable = new Cachetable(10 * Cachetable.minute);
File primaryDir = new File(primaryDirStr);
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cachetable, primaryDir, null);
DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
double[] allTimes = dataSetControllerImpl.getDataSetTimes(vcdID);
TimeSpecs timeSpecs = new TimeSpecs(beginTimeIndex, endTimeIndex, allTimes, ExportConstants.TIME_RANGE);
VariableSpecs variableSpecs = new VariableSpecs(varNames, ExportConstants.VARIABLE_MULTI);
GeometrySpecs geometrySpecs = new GeometrySpecs(null, 0, 0, ExportConstants.GEOMETRY_SLICE);
DisplayPreferences displayPreferences = new DisplayPreferences(DisplayAdapterService.BLUERED, new Range(0, 1), DisplayAdapterService.createBlueRedSpecialColors());
MovieSpecs movieSpecs = new MovieSpecs(// /
1000.0, // /
false, // /
new DisplayPreferences[] { displayPreferences }, // /
ExportFormat.FORMAT_JPEG, // /
0, // /
1, // /
1, // /
1, ImagePaneModel.MESH_MODE, FormatSpecificSpecs.CODEC_JPEG, 1.0f, false, FormatSpecificSpecs.PARTICLE_SELECT);
ExportSpecs exportSpecs = new ExportSpecs(vcdID, ExportFormat.QUICKTIME, variableSpecs, timeSpecs, geometrySpecs, movieSpecs, "IMGExporterTest", null);
exportServiceImpl.makeRemoteFile(null, user, dataServerImpl, exportSpecs);
}
use of cbit.image.DisplayPreferences in project vcell by virtualcell.
the class PDEExportDataPanel method startExport.
/**
* Comment
*/
private void startExport() {
if (getExportSettings1().getSelectedFormat() == ExportFormat.QUICKTIME && getJSlider1().getValue() == getJSlider2().getValue()) {
DialogUtils.showWarningDialog(this, "User selected 'begin' and 'end' export times are the same. 'Movie' export format 'begin' and 'end' times must be different");
return;
}
DisplayPreferences[] displayPreferences = null;
@SuppressWarnings("deprecation") Object[] variableSelections = getJListVariables().getSelectedValues();
boolean selectionHasVolumeVariables = false;
boolean selectionHasMembraneVariables = false;
switch(getExportSettings1().getSelectedFormat()) {
case PLY:
case QUICKTIME:
case GIF:
case FORMAT_JPEG:
case ANIMATED_GIF:
{
displayPreferences = new DisplayPreferences[variableSelections.length];
StringBuffer noScaleInfoNames = new StringBuffer();
for (int i = 0; i < displayPreferences.length; i++) {
BitSet domainValid = null;
try {
if (dataInfoProvider != null) {
DataIdentifier varSelectionDataIdnetDataIdentifier = null;
for (int j = 0; j < dataInfoProvider.getPDEDataContext().getDataIdentifiers().length; j++) {
if (dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j].getName().equals(variableSelections[i])) {
varSelectionDataIdnetDataIdentifier = dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j];
}
}
if (varSelectionDataIdnetDataIdentifier != null) {
selectionHasVolumeVariables = selectionHasVolumeVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.POSTPROCESSING) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME_REGION);
selectionHasMembraneVariables = selectionHasMembraneVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE_REGION);
CartesianMesh cartesianMesh = dataInfoProvider.getPDEDataContext().getCartesianMesh();
int dataLength = cartesianMesh.getDataLength(varSelectionDataIdnetDataIdentifier.getVariableType());
domainValid = new BitSet(dataLength);
domainValid.clear();
for (int j = 0; j < dataLength; j++) {
if (dataInfoProvider.isDefined(varSelectionDataIdnetDataIdentifier, j)) {
domainValid.set(j);
}
}
} else {
throw new Exception("No DataIdentifer found for variable name '" + variableSelections[i] + "'");
}
}
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, "Error during domain evaluation:\n" + e.getMessage());
return;
}
displayPreferences[i] = new DisplayPreferences(getDisplayAdapterService().getDisplayPreferences((String) variableSelections[i]), domainValid);
if (!getDisplayAdapterService().hasStateID((String) variableSelections[i])) {
noScaleInfoNames.append("--- " + (String) variableSelections[i] + "\n");
}
}
break;
}
case CSV:
{
// check for membrane variables... warn for 3D geometry...
// one gets the whole nine yards by index, not generally useful... except for a few people like Boris :)
boolean mbVars = false;
DataIdentifier[] dataIDs = getPdeDataContext().getDataIdentifiers();
for (int i = 0; i < variableSelections.length; i++) {
String varName = (String) variableSelections[i];
for (int j = 0; j < dataIDs.length; j++) {
if (dataIDs[j].getName().equals(varName) && dataIDs[j].getVariableType().equals(VariableType.MEMBRANE)) {
mbVars = true;
break;
}
}
}
if (mbVars && getPdeDataContext().getCartesianMesh().getGeometryDimension() == 3 && getJRadioButtonSlice().isSelected()) {
String choice = PopupGenerator.showWarningDialog(this, getDataViewerManager().getUserPreferences(), UserMessage.warn_exportMembraneData3D, null);
if (choice.equals(UserMessage.OPTION_CANCEL)) {
// user canceled
return;
}
}
getExportSettings1().setSimulationSelector(createSimulationSelector());
getExportSettings1().setIsCSVExport(true);
break;
}
case NRRD:
case IMAGEJ:
case UCD:
case VTK_IMAGE:
case VTK_UNSTRUCT:
break;
default:
break;
}
;
if (getJRadioButtonROI().isSelected() && getROISelections().getSelectedIndex() == -1) {
PopupGenerator.showErrorDialog(this, "To export selections, you must select at least one item from the ROI selection list");
}
getExportSettings1().setTimeSpecs(new TimeSpecs(getJSlider1().getValue(), getJSlider2().getValue(), getPdeDataContext().getTimePoints(), ExportConstants.TIME_RANGE));
getExportSettings1().setDisplayPreferences(displayPreferences, Arrays.asList(variableSelections).toArray(new String[0]), viewZoom);
getExportSettings1().setSliceCount(FormatSpecificSpecs.getSliceCount(getJRadioButtonFull().isSelected(), getNormalAxis(), getPdeDataContext().getCartesianMesh()));
getExportSettings1().setImageSizeCalculationInfo(getPdeDataContext().getCartesianMesh(), getNormalAxis());
getExportSettings1().setIsSmoldyn(isSmoldyn);
ExportFormat format = getSelectedFormat();
if (format.equals(ExportFormat.PLY)) {
getExportSettings1().setFormatSpecificSpecs(new PLYSpecs(true, displayPreferences));
}
if (format.requiresFollowOn()) {
Frame theFrame = JOptionPane.getFrameForComponent(this);
boolean okToExport = getExportSettings1().showFormatSpecificDialog(theFrame, selectionHasVolumeVariables, selectionHasMembraneVariables);
if (!okToExport) {
return;
}
}
if (format.equals(ExportFormat.IMAGEJ)) {
// export nrrd for imagej direct, the we'll send to imagej from vcell client
getExportSettings1().setFormatSpecificSpecs(new RasterSpecs(ExportConstants.NRRD_SINGLE, false));
}
// determine of sim result is from local (quick) run or on server.
final OutputContext outputContext = ((ClientPDEDataContext) getPdeDataContext()).getDataManager().getOutputContext();
final ExportSpecs exportSpecs = getExportSpecs();
boolean isLocalSimResult = false;
VCDataIdentifier vcId = exportSpecs.getVCDataIdentifier();
if (vcId instanceof LocalVCDataIdentifier) {
isLocalSimResult = true;
}
// find out if smoldyn export choice is 'particle' - not available at this time
boolean isParticle = false;
if (getExportSettings1().getFormatSpecificSpecs() instanceof ImageSpecs) {
isParticle = ((ImageSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
} else if (getExportSettings1().getFormatSpecificSpecs() instanceof MovieSpecs) {
isParticle = ((MovieSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
}
if (isLocalSimResult && isParticle) {
DialogUtils.showErrorDialog(this, "Particle export for Smoldyn particles unavailable in local data at this time.");
return;
}
// pass the export request down the line; non-blocking call
if (!isLocalSimResult) {
// for sims that ran on server, do as before.
getDataViewerManager().startExport(this, outputContext, exportSpecs);
} else {
final String SOURCE_FILE_KEY = "SOURCE_FILE_KEY";
final String DESTINATION_FILE_KEY = "DEESTINATION_FILE_KEY";
AsynchClientTask localExportTast = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = User.tempUser;
File usrDir = new File(primaryDir.getAbsolutePath(), usr.getName());
System.setProperty(PropertyLoader.exportBaseDirInternalProperty, usrDir.getAbsolutePath() + File.separator);
System.setProperty(PropertyLoader.exportBaseURLProperty, usrDir.toURI().toURL().toString());
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, localExportServiceImpl);
ExportEvent localExportEvent = dataServerImpl.makeRemoteFile(outputContext, usr, exportSpecs);
File sourceFile = new File(usrDir, new File((new URL(localExportEvent.getLocation()).getPath())).getName());
hashTable.put(SOURCE_FILE_KEY, sourceFile);
} catch (Exception e) {
throw new Exception("Unable to export local sim results data : " + e.getMessage(), e);
}
}
};
AsynchClientTask localSaveTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setSelectedFile(new File(sourceFile.getName()));
if (jFileChooser.showSaveDialog(PDEExportDataPanel.this) == JFileChooser.APPROVE_OPTION) {
File destinationFile = jFileChooser.getSelectedFile();
if (destinationFile.exists()) {
final String OVERWRITE = "Overwrite";
final String CANCEL = "Cancel";
String response = DialogUtils.showWarningDialog(PDEExportDataPanel.this, "OK to Overwrite " + destinationFile.getAbsolutePath() + "?", new String[] { OVERWRITE, CANCEL }, OVERWRITE);
if (response == null || !response.equals(OVERWRITE)) {
return;
}
}
hashTable.put(DESTINATION_FILE_KEY, destinationFile);
}
}
};
AsynchClientTask localDeleteTempTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
File destinationFile = (File) hashTable.get(DESTINATION_FILE_KEY);
if (sourceFile != null && sourceFile.exists()) {
try {
if (destinationFile != null) {
copyFile(sourceFile, destinationFile);
}
} finally {
sourceFile.delete();
}
}
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { localExportTast, localSaveTask, localDeleteTempTask }, false, true, null);
}
}
Aggregations