Re: Questions about 3D Viewer

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Questions about 3D Viewer

dscho
Hi Erik,

I Cc:ed the mailing list so that Google can find my answers for others'
benefit, too.

On Tue, 7 Jan 2014, Erik Meijering wrote:

> Recently I was trying to contact Benjamin Schmid with some questions
> about 3D Viewer

I Cc:ed him, too.

> Dear Benjamin,
>
> First, many thanks for the great 3D Viewer plugin for ImageJ.
>
> I have a few questions about the plugin and related things, and I'd be very
> happy if you could help me with them. Hopefully they are easy.
>
> The 3D Viewer website http://3dviewer.neurofly.de/ doesn't seem to be working
> at the moment (don't know since when). When I try to access it, basically
> nothing happens, and the message "The operation timed out" appears after a
> while.

That website is indeed down (as I feared a long time ago, hoping to
encourage Bene to move the documentation to a safer place such as
http://fiji.sc/). But the Wayback Machine has some of it:

        https://web.archive.org/web/*/http://3dviewer.neurofly.de/

It also suggests that the website went down some time after September 9,
2013.

> That's a pity, because I was looking for some tips and tricks. I started
> looking into the source code, available at Fiji's gitweb, but since I'm
> not familiar with the design it is a time consuming process. So I was
> hoping you could help me with the following.
>
> Basically I am trying to use the package in my own code, where I have a
> bunch of objects for which I generate my own triangular meshes and I
> want to add them one by one, each with its own color.
>
> Here is the setup:
>
> 1   Image3DUniverse universe = new Image3DUniverse();
> 2   for (int i=0; i<n; ++i) { // n objects
> 3      Vector<Point3f> mesh = new Vector<Point3f>();
> 4      // ...code that fills "mesh" with triangles...
> 5      CustomTriangleMesh ctm = new CustomTriangleMesh(mesh,color,0);
> 6      universe.addCustomMesh(ctm,"Object "+n);
> 7   }
> 8   universe.show();
>
> The number of objects (n) is a few dozen, or maybe up to a few hundreds. And
> the mesh for each object consists of up to a few tens of thousands of
> triangles.
>
> In principle this code works fine, except for two things:
>
> 1) It is very slow. I'm working on a reasonably fast PC running Windows
> 7 with Java 6 and a completely up-to-date version of Fiji, but even with
> only 30 objects, each having perhaps 25,000 triangles, it takes up to 7
> seconds before the 3D Viewer window shows up. I've done some checks and
> found out that virtually all of this time is spent on the creation of
> the CustomTriangleMesh objects (line 5). Is there a more efficient way
> to add my meshes to the universe?

My guess is that that time is spent in `MeshProperties.compute()`:

        https://github.com/fiji/fiji/blob/master/src-plugins/3D_Viewer/src/main/java/customnode/CustomTriangleMesh.java#L40

Unfortunately, I am not very familiar with that part of the code. My
advice would be to import it into the same Eclipse workspace (or
equivalent) and instrument the 3D Viewer code with debug output to measure
where the time is lost.

I have to admit, however, that I never loaded more than about a thousand
triangles into the 3D Viewer at a time...

> 2) After the 3D Viewer is launched, the object names ("Object n") that
> were specified while adding the objects to the universe, do not show up
> in the menu item Edit -> Select. (If I manually add other objects
> afterwards, for example some spheres using the menu item Add -> Sphere,
> the names of those objects do appear in the list.) I remember having
> played with similar code before, and then the names did show up. Did
> something change in your code recently that may cause this problem? Or
> am I overlooking something in my own code?

I am not aware of any changes to that extent. That code should actually
work... If you could make source code publicly available that demonstrates
the problem, I would set aside an hour to have a look at it.

> Finally I would like to know how to set some properties of the
> individual mesh objects. For example, in the 3D Viewer window, by
> default it is possible to select any one of them and rotate or translate
> them. I would like to disable that. How should this be done?

As CustomTriangleMesh is a subclass of Shape3D, I would imagine that the
rotation or translation would be performed by one of the methods listed
here:

        http://download.java.net/media/java3d/javadoc/1.5.2/javax/media/j3d/Shape3D.html

To prevent rotation or translation, I would therefore subclass
CustomTriangleMesh and disallow certain transformations. Sorry, I am not
aware of a more elegant way.

If you go that route, you need to be careful not to disallow *all*
transformations, though, because the global rotation should still be
allowed, correct? If I had to do it, I would probably hack it: add code
that inspects the stack trace and disables the update of the geometry
based on the presence of methods which I would find out by calling the 3D
Viewer in debug mode, setting a breakpoint on the geometry update, and
translating the object.

I actually lied above when I said that I am not aware of a more elegant
way, though: An elegant way would be to enhance the 3D Viewer... but I
figure that you do not have the time, correct? ;-)

Oh, and there is yet another thought: have you seen the CustomMultiMesh?
If you add the CustomTriangleMeshes to a MultiMesh, I believe the multi
mesh can only be transformed as a whole. It is not exactly disabling the
rotation or translation as you requested, but at least it disables the
*individual* rotation or translation.

> Many thanks in advance for any help!
>
> Merry Christmas,

And a happy new year!
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Questions about 3D Viewer

Erik Meijering
An update on some of the issues I raised:

> 1   Image3DUniverse universe = new Image3DUniverse();
> 2   for (int i=0; i<n; ++i) { // n objects
> 3      Vector<Point3f> mesh = new Vector<Point3f>();
> 4      // ...code that fills "mesh" with triangles...
> 5      CustomTriangleMesh ctm = new CustomTriangleMesh(mesh,color,0);
> 6      universe.addCustomMesh(ctm,"Object "+n);
> 7   }
> 8   universe.show();
>
> After the 3D Viewer is launched, the object names ("Object n") that
> were specified while adding the objects to the universe, do not show up
> in the menu item Edit -> Select.

They do show up if you first call:

   universe.show();

and then:

   universe.addCustomMesh(ctm,name);

where "name" is the String with the name you want.

> I would like to know how to set some properties of the
> individual mesh objects. For example, in the 3D Viewer window, by
> default it is possible to select any one of them and rotate or translate
> them. I would like to disable that. How should this be done?

This can be done very simply by:

   universe.getContent(name).setLocked(true);

Cheers,

Erik

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Questions about 3D Viewer

Benjamin Schmid-2
Hi Erik,

> The 3D Viewer website http://3dviewer.neurofly.de/ doesn't seem to be
> working at the moment (don't know since when). When I try to access it,
> basically nothing happens, and the message "The operation timed out"
> appears after a while.
> [...]

* The website is up again, as you'll probably have noticed.

> 1) It is very slow. I'm working on a reasonably fast PC running Windows
> 7 with Java 6 and a completely up-to-date version of Fiji, but even with
> only 30 objects, each having perhaps 25,000 triangles, it takes up to 7
> seconds before the 3D Viewer window shows up. I've done some checks and
> found out that virtually all of this time is spent on the creation of
> the CustomTriangleMesh objects (line 5). Is there a more efficient way
> to add my meshes to the universe?

There is no better way to do it at the moment. I guess most of the time
will be spent in CustomMesh.createGeometry()
(http://fiji.sc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/3D_Viewer/src/main/java/customnode/CustomTriangleMesh.java;h=9696cefc06da52d797e4142c883a2c2375364eb6;hb=refs/heads/master),
probably when converting the list of triangles to Java3D's internal
representation, calculating normals, stripping vertex arrays etc.

> Finally I would like to know how to set some properties of the
> individual mesh objects. For example, in the 3D Viewer window, by
> default it is possible to select any one of them and rotate or translate
> them. I would like to disable that. How should this be done?

> This can be done very simply by:
>
>    universe.getContent(name).setLocked(true);
>
Actually, universe.addCustomMesh(...) returns a reference to the Content
object, which you can use directly, as you've figured out, to lock it or
set attributes like color, transparency etc. (Content.getColor(Color3f
c), Content.setTransparency(float transparency)).

If you don't want the individual meshes to be transformed, you might be
interested in the so-called 'CustomMultiMesh'. It contains several
CustomMesh objects, all combined in one Content. You can add it to the
universe with universe.addCustomMesh(CustomMultiMesh mesh, String name).

Best wishes,
Bene

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html