imageJ的问题.急

ethansunxin2 2011-08-08 12:54:19
我想给一个软件写宏.有一步不能自动纪录进去..估计是bug..那个软件是java写的
http://fiji.sc/wiki/index.php/Fiji
图片设置好了之后,打开plugin里面的3Dviewer. 我想做的就是用宏导出.stl(binary)文件..但是不能自动纪录进那一步的宏..
下面这段代码是ImageJ的macro代码

var greyVal;
for(greyVal=2000;greyVal<12000;greyVal+=500)
{
run("Image Sequence...", "open=[C:\\Users\\microway\\Desktop\\blender&fuji sources\\00001.tif] number=150 starting=1 increment=1 scale=100 file=[] or=[] sort");
run("Properties...", "channels=1 slices=150 frames=1 unit=pixel pixel_width=1.0000 pixel_height=1.0000 voxel_depth=5 frame=[0 sec] origin=0,0");
setAutoThreshold("Default");
//run("Threshold...");
setAutoThreshold("Default");
setThreshold(greyVal, greyVal+500);
run("Convert to Mask", " black");
//setTool("hand");
run("3D Viewer");
call("ij3d.ImageJ3DViewer.setCoordinateSystem", "false");
call("ij3d.ImageJ3DViewer.add", "blender&fuji sources", "None", "blender&fuji sources", "50", "true", "true", "true", "2", "2");
//应该是在这里加入那一行代码..导出.stl(binary)文件
close();
call("ij3d.ImageJ3DViewer.close");
}

那个软件的源代码我找到了..

public static void saveAsSTL(Collection meshgroups, int filetype) {
if (null == meshgroups || 0 == meshgroups.size())
return;
meshgroups = filterMeshes(meshgroups);
if (0 == meshgroups.size()) {
IJ.log("No meshes to export!");
return;
}
SaveDialog sd = new SaveDialog("Save as STL ("
+ ((filetype == ASCII) ? "ASCII" : "binary") + ")",
"untitled", ".stl");
String dir = sd.getDirectory();
if (null == dir)
return;
if (IJ.isWindows())
dir = dir.replace('\\', '/');
if (!dir.endsWith("/"))
dir += "/";
String stl_filename = sd.getFileName();
if (!stl_filename.toLowerCase().endsWith(".stl"))
stl_filename += ".stl";

File stl_file = new File(dir + "/" + stl_filename);
// check if file exists
if (!IJ.isMacOSX()) {
if (stl_file.exists()) {
YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(),
"Overwrite?", "File " + stl_filename
+ " exists!\nOverwrite?");
if (!yn.yesPressed())
return;
}
}

OutputStreamWriter dos = null;
DataOutputStream out = null;
try {
if (filetype == ASCII) {
dos = new OutputStreamWriter(new BufferedOutputStream(
new FileOutputStream(stl_file)), "8859_1");
writeAsciiSTL(meshgroups, dos, stl_filename);
dos.flush();
} else {
out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(stl_file)));
writeBinarySTL(meshgroups, out);
out.flush();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (null != dos)
dos.close();
if (null != out)
out.close();
} catch (Exception e) {
}
}
}

private static void writeBinarySTL(Collection meshgroups,
DataOutputStream out) {

// get all the meshes and sort them into a hash
HashMap<String, CustomMesh> meshes = new HashMap<String, CustomMesh>();
for (Iterator<Content> it = meshgroups.iterator(); it.hasNext();) {
Content mob = (Content) it.next();

ContentNode node = mob.getContent();
// First CustomMultiMesh, which is also a CustomMeshNode:
if (node instanceof CustomMultiMesh) {
CustomMultiMesh multi = (CustomMultiMesh) node;
for (int i = 0; i < multi.size(); i++) {
meshes.put(mob.getName() + " [" + (i + 1) + "]", multi
.getMesh(i));
}
// Then CustomMeshNode (all custom meshes):
} else if (node instanceof CustomMeshNode) {
meshes
.put(mob.getName(), ((CustomMeshNode) node)
.getMesh());
// An image volume rendered as isosurface:
} else if (node instanceof MeshGroup) {
meshes.put(mob.getName(), ((MeshGroup) node).getMesh());
} else {
IJ.log("Ignoring " + mob.getName() + " with node of class "
+ node.getClass());
continue;
}
}
//count all the triangles and add them to a list
int triangles = 0;
ArrayList<List<Point3f>> surfaces = new ArrayList<List<Point3f>>();
for (String name : meshes.keySet()) {
CustomMesh cmesh = meshes.get(name);
if (cmesh.getClass() == CustomQuadMesh.class) {
IJ.log("Quad meshes are unsupported, can't save " + name
+ " as STL");
continue;
} else if (cmesh.getClass() != CustomTriangleMesh.class) {
IJ.log("Unsupported content type, can't save " + name
+ " as STL");
continue;
}
List<Point3f> vertices = cmesh.getMesh();
triangles += vertices.size() / 3;
surfaces.add(vertices);
}

String header = "Binary STL created by ImageJ 3D Viewer.";
for (int i = header.length(); i < 80; i++){
header = header+".";
}
try {
out.writeBytes(header);
out.writeByte(triangles & 0xFF);
out.writeByte((triangles >> 8) & 0xFF);
out.writeByte((triangles >> 16) & 0xFF);
out.writeByte((triangles >> 24) & 0xFF);
for (List<Point3f> vertices : surfaces){
for (int i = 0; i < vertices.size(); i+=3){
Point3f p0 = vertices.get(i);
Point3f p1 = vertices.get(i+1);
Point3f p2 = vertices.get(i+2);
Point3f n = unitNormal(p0, p1, p2);
ByteBuffer bb = ByteBuffer.allocate(50);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.putFloat(n.x);
bb.putFloat(n.y);
bb.putFloat(n.z);
bb.putFloat(p0.x);
bb.putFloat(p0.y);
bb.putFloat(p0.z);
bb.putFloat(p1.x);
bb.putFloat(p1.y);
bb.putFloat(p1.z);
bb.putFloat(p2.x);
bb.putFloat(p2.y);
bb.putFloat(p2.z);
bb.putShort((short)0);
out.write(bb.array());
}
}
} catch (IOException e) {
e.printStackTrace();
}

}

请大神们帮我看看....怎么调用这个...应该就是一行能解决的..
应该是有2个变量,但是我怎么得到第一个变量?..这个软件是自动生成图像的...得不到
可能我说话逻辑比较差..见谅..
谢谢了..
...全文
545 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ethansunxin2 2011-08-08
  • 打赏
  • 举报
回复
这个我读完了
As mentioned above, all elements of the 3D scene are related in a graph structure. Our constructed Java 3D graph links image objects (as Content instances) by wrapping them in ContentNode objects. The latter extend the functionality of basic Java 3D BranchGroup class, to serve as high-level scene elements. The ContentNode class is abstract; the four classes VoltexGroup, MeshGroup, OrthoGroup and CustomNode respectively represent volume renderings, surface renderings, orthoslices and custom geometries.
我明天回到lab之后查查这个ContentNode class.
wxxth 2011-08-08
  • 打赏
  • 举报
回复
wxxth 2011-08-08
  • 打赏
  • 举报
回复
我又查了一下,你的哪个fiji软件里面应该有种结构是meshgroups, 你找到那个对象,然后放在这里就行了
wxxth 2011-08-08
  • 打赏
  • 举报
回复 1
我先解释下saveAsSTL(Collection meshgroups, int filetype)这个函数,你看看有没有什么帮助,
这个函数是能把一个数据对象写到一个文件里,如果你学过数据结构的话,就应该知道一些像是链表啊什么的,都是Collection的子类(就是Collection中的一种),然后后面的filetype是你要的。stl文件格式,是ASCII还是binary(二进制)
你现在要做的就是找找自己要写的数据是哪些,他们是什么样的数据结构,他们在哪里,从你上面给的代码我暂时还看不出这些来
ethansunxin2 2011-08-08
  • 打赏
  • 举报
回复
这个软件是自动生成的数据...从一堆2D图片生成3D图形...我怎么得到数据?
wxxth 2011-08-08
  • 打赏
  • 举报
回复
我觉得你要先找到你要记录的数据对象是哪个
wxxth 2011-08-08
  • 打赏
  • 举报
回复
Collection 是一些数据结构的类,具体要看你要写入的对象
ethansunxin2 2011-08-08
  • 打赏
  • 举报
回复
是这个.我之前查过.但是我得不到第一个Collection meshgroups
wxxth 2011-08-08
  • 打赏
  • 举报
回复
http://pacific.mpi-cbg.de/javadoc/isosurface/MeshExporter.html
这里应该有你要的详细说明,先把连接给你你先看看,然后我也看看再解释
wxxth 2011-08-08
  • 打赏
  • 举报
回复
首先,肯定是调用saveAsSTL(Collection meshgroups, int filetype)这个方法没错,
至于两个参数还在慢慢看
ethansunxin2 2011-08-08
  • 打赏
  • 举报
回复
能帮忙看看么..
桃园闲人 2011-08-08
  • 打赏
  • 举报
回复
这么多代码看得人晕!!!

50,531

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧