-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
318 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package bigtrace.io; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.text.DecimalFormat; | ||
import java.text.DecimalFormatSymbols; | ||
import java.util.ArrayList; | ||
|
||
import javax.swing.SwingWorker; | ||
|
||
import net.imglib2.RealPoint; | ||
import net.imglib2.type.NativeType; | ||
import net.imglib2.type.numeric.RealType; | ||
|
||
import bigtrace.BigTrace; | ||
import bigtrace.BigTraceBGWorker; | ||
import bigtrace.rois.AbstractCurve3D; | ||
import bigtrace.rois.Roi3D; | ||
|
||
import ij.IJ; | ||
|
||
public class ROIsExportCSV < T extends RealType< T > & NativeType< T > > extends SwingWorker<Void, String> implements BigTraceBGWorker | ||
{ | ||
private String progressState; | ||
public BigTrace<T> bt; | ||
public String sFilename; | ||
|
||
@Override | ||
public String getProgressState() | ||
{ | ||
return progressState; | ||
} | ||
@Override | ||
public void setProgressState(String state_) | ||
{ | ||
progressState=state_; | ||
} | ||
|
||
@Override | ||
protected Void doInBackground() throws Exception { | ||
int nRoi, nRoiN; | ||
|
||
bt.bInputLock = true; | ||
bt.setLockMode(true); | ||
|
||
try { | ||
final File file = new File(sFilename); | ||
|
||
try (FileWriter writer = new FileWriter(file)) | ||
{ | ||
//column titles | ||
|
||
writer.write("ROI_Number,X_coord,Y_coord,Z_coord,ROI_Name,ROI_Type,ROI_Group,ROI_TimePoint\n"); | ||
DecimalFormatSymbols symbols = new DecimalFormatSymbols(); | ||
symbols.setDecimalSeparator('.'); | ||
DecimalFormat df3 = new DecimalFormat ("#.#####", symbols); | ||
nRoiN = bt.roiManager.rois.size(); | ||
String sRoiName; | ||
String sRoiGroup; | ||
String sRoiType; | ||
String sRoiTP; | ||
int nRoiCurrN = 0; | ||
//writer.write("ROIsNumber," + Integer.toString(nRoiN)+"\n"); | ||
for(nRoi=0; nRoi<nRoiN; nRoi++) | ||
{ | ||
//Sleep for up to one second. | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException ignore) {} | ||
setProgress(nRoi*100/nRoiN); | ||
if(bt.roiManager.rois.get( nRoi ) instanceof AbstractCurve3D) | ||
{ | ||
nRoiCurrN++; | ||
AbstractCurve3D currRoi = ((AbstractCurve3D)bt.roiManager.rois.get( nRoi )); | ||
sRoiTP = Integer.toString( currRoi.getTimePoint() ); | ||
sRoiName = currRoi.getName(); | ||
sRoiType = Roi3D.intTypeToString( currRoi.getType()); | ||
sRoiGroup = bt.roiManager.groups.get(currRoi.getGroupInd()).getName(); | ||
ArrayList< RealPoint > points = currRoi.getJointSegmentResampled(); | ||
for(int nP=0; nP<points.size(); nP++) | ||
{ | ||
writer.write( Integer.toString( nRoiCurrN ) +"," ); | ||
for (int d=0;d<3;d++) | ||
{ | ||
writer.write( df3.format(points.get( nP ).getDoublePosition( d ) ) +"," ); | ||
} | ||
writer.write( sRoiName + "," + sRoiType + "," + sRoiGroup + "," + sRoiTP + "\n"); | ||
} | ||
} | ||
|
||
} | ||
writer.close(); | ||
} | ||
setProgress(100); | ||
setProgressState("exporting ROIs done."); | ||
} catch (IOException e) { | ||
IJ.log(e.getMessage()); | ||
//e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
/* | ||
* Executed in event dispatching thread | ||
*/ | ||
@Override | ||
public void done() | ||
{ | ||
//unlock user interaction | ||
bt.bInputLock = false; | ||
bt.setLockMode(false); | ||
setProgress(100); | ||
setProgressState("export ROIs to CSV done."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package bigtrace.io; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.text.DecimalFormat; | ||
import java.text.DecimalFormatSymbols; | ||
import java.util.ArrayList; | ||
|
||
import javax.swing.SwingWorker; | ||
|
||
import net.imglib2.RealPoint; | ||
import net.imglib2.type.NativeType; | ||
import net.imglib2.type.numeric.RealType; | ||
|
||
import bigtrace.BigTrace; | ||
import bigtrace.BigTraceBGWorker; | ||
import bigtrace.BigTraceData; | ||
import bigtrace.rois.AbstractCurve3D; | ||
|
||
import ij.IJ; | ||
|
||
public class ROIsExportSWC< T extends RealType< T > & NativeType< T > > extends SwingWorker<Void, String> implements BigTraceBGWorker | ||
{ | ||
private String progressState; | ||
public BigTrace<T> bt; | ||
public String sFilename; | ||
|
||
@Override | ||
public String getProgressState() | ||
{ | ||
return progressState; | ||
} | ||
@Override | ||
public void setProgressState(String state_) | ||
{ | ||
progressState=state_; | ||
} | ||
|
||
@Override | ||
protected Void doInBackground() throws Exception { | ||
int nRoi, nRoiN; | ||
|
||
bt.bInputLock = true; | ||
bt.setLockMode(true); | ||
|
||
try { | ||
final File file = new File(sFilename); | ||
|
||
try (FileWriter writer = new FileWriter(file)) | ||
{ | ||
DecimalFormatSymbols symbols = new DecimalFormatSymbols(); | ||
symbols.setDecimalSeparator('.'); | ||
DecimalFormat df3 = new DecimalFormat ("#.#####", symbols); | ||
nRoiN = bt.roiManager.rois.size(); | ||
long nPointCount = 1; | ||
//int nCurrActivePoint; | ||
String sRadius; | ||
writer.write("#raw "+ bt.btData.sFileNameFullImg+"\n"); | ||
writer.write("#original_source BigTrace_ver_" +BigTraceData.sVersion+"\n"); | ||
for(nRoi=0; nRoi<nRoiN; nRoi++) | ||
{ | ||
|
||
//Sleep for up to one second. | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException ignore) {} | ||
setProgress(nRoi*100/nRoiN); | ||
if(bt.roiManager.rois.get( nRoi ) instanceof AbstractCurve3D) | ||
{ | ||
AbstractCurve3D currRoi = ((AbstractCurve3D)bt.roiManager.rois.get( nRoi )); | ||
sRadius = df3.format( currRoi.getLineThickness()*0.5*BigTraceData.dMinVoxelSize); | ||
ArrayList< RealPoint > points = currRoi.getJointSegmentResampled(); | ||
for(int nP=0; nP<points.size(); nP++) | ||
{ | ||
writer.write( Long.toString( nPointCount ) +" 0 " ); | ||
for (int d=0;d<3;d++) | ||
{ | ||
writer.write( df3.format(points.get( nP ).getDoublePosition( d ) ) +" " ); | ||
} | ||
writer.write( sRadius + " "); | ||
if(nP == 0) | ||
{ | ||
writer.write( "-1 \n"); | ||
|
||
} | ||
else | ||
{ | ||
writer.write( Long.toString( nPointCount-1 ) + " \n"); | ||
} | ||
nPointCount++; | ||
} | ||
} | ||
|
||
} | ||
writer.close(); | ||
} | ||
setProgress(100); | ||
setProgressState("exporting curve ROIs done."); | ||
} catch (IOException e) { | ||
IJ.log(e.getMessage()); | ||
//e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
/* | ||
* Executed in event dispatching thread | ||
*/ | ||
@Override | ||
public void done() | ||
{ | ||
//unlock user interaction | ||
bt.bInputLock = false; | ||
bt.setLockMode(false); | ||
setProgress(100); | ||
setProgressState("export traces to SWC done."); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters