mobie / mobie-viewer-fiji

BSD 2-Clause "Simplified" License
30 stars 12 forks source link

3D viewer origin with transformed sources #946

Closed martinschorb closed 8 months ago

martinschorb commented 1 year ago

Hi, I have transformed segmentations (3D CLEM both LM and EM, none is centered at the origin) that we like to visualize in the 3D viewer.

Can the origin of the 3D viewer be set to the center of the bounding box containing all visible objects instead of 0,0,0 ? The 3DViewer is barely usable otherwise (rotations are crazy). Screenshot from 2023-01-25 10-16-17

tischi commented 1 year ago

@martinschorb you have to show me in person; let's mattermost chat to find a date.

martinschorb commented 1 year ago

this happens with the segmentations in here: https://github.com/mobie/environmental-dinoflagellate-vCLEM

tischi commented 1 year ago

I feel the issue is that due to your coordinate system the mesh has negative coordinates. It may be that the 3D viewer code has issue with this.

I think the main issue right now for navigation is that it computes a totally wrong bounding box of the mesh.

Is there any way you could test this in a coordinate system, where your y-axis is shifted such that we have only positive coordinates?

image
tischi commented 1 year ago

Super weird:

The min and max of the mesh seem to be wrong:

image

But the bounds are correct:

image

I think this 1.4E-45 is the issue. No idea where that comes from...

constantinpape commented 1 year ago

Did you check the corresponding table? Maybe this was some issue related to the empty objects. If you tell me which of the segmentations causes these issues I can also check.

tischi commented 1 year ago

I found the bug. It is within the ImageJ 3D Universe code:

    public void calculateMinMaxCenterPoint(final Point3f min, final Point3f max,
        final Point3f center)
    {

        if (mesh == null || mesh.size() == 0) {
            min.set(0, 0, 0);
            max.set(0, 0, 0);
            center.set(0, 0, 0);
            return;
        }

        min.x = min.y = min.z = Float.MAX_VALUE;
        max.x = max.y = max.z = Float.MIN_VALUE; // <= WRONG, correct would be:   -Float.MAX_VALUE
        for (int i = 0; i < mesh.size(); i++) {
            final Point3f p = mesh.get(i);
            if (p.x < min.x) min.x = p.x;
            if (p.y < min.y) min.y = p.y;
            if (p.z < min.z) min.z = p.z;
            if (p.x > max.x) max.x = p.x;
            if (p.y > max.y) max.y = p.y;
            if (p.z > max.z) max.z = p.z;
        }
        center.x = (max.x + min.x) / 2;
        center.y = (max.y + min.y) / 2;
        center.z = (max.z + min.z) / 2;
    }
tischi commented 1 year ago

I think I fixed it (follow the link above).

However, whether and when this fix will be shipped with Fiji is not clear.

I think there are three (non-exclusive) options:

  1. You could move your coordinate system such that everything has positive coordinates
  2. We ship our own version of 3D_Viewer
  3. We wait until this is fixed in Fiji