Show ROI boxes - if loading from .obj file then all boxes appear in yellow color

Hi, I have saved bounding box coordinates in an .obj file and i am able to load it in slicer and visualize it correctly. I also have a .mtl file that contains the box color information; however, every time i load up the .obj file, it only shows up in yellow color box. I am not sure if i am specifying the color parameter in the .mtl file correctly. This is what i have in the 6b.nii.obj file:

mtllib 6b.nii.mtl

v 240.0158052444458 92.24226522445679 -170.0
v 240.0158052444458 78.96100568771362 -170.0
v 226.73454570770264 78.96100568771362 -170.0
v 226.73454570770264 92.24226522445679 -170.0
v 240.0158052444458 92.24226522445679 -190.0
v 240.0158052444458 78.96100568771362 -190.0
v 226.73454570770264 78.96100568771362 -190.0
v 226.73454570770264 92.24226522445679 -190.0

usemtl bbox
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8

This is what i have in the 6b.nii.mtl file

newmtl bbox
Ka 0 0 0
Kd 0.0 1.0 0.0
Ks 0 0 0
Ns 3
Tr 1
illum 3

Any help is greatly appreciated. Also, is there a way to specify line-width in the .mtl file ? Please let me know. Thank you!

Slicer only loads the geometry from OBJ files. Material files are ignored.

It would not be too hard to implement an importer that creates multiple models (one per material), color and opacity set for each based on the material. Would this be sufficient?

If you just want to load a single colored mesh then your can use ply or vtk file format instead.

What is your overall goal? What would you like to do with the mesh in Slicer?

In slicermorph, you can import an OBJ file with materials. We haven’t tested extensively but seem to work for the photogrammetry models we have built for a project.

@ayadav01
Install slicermorph extension, restart slicer, drag and drop your model, and in the dialog box, choose OBJ Textured Model as the Description (as opposed to default Model).

See if that helps…

Thanks Andras. I have a bunch of .obj files that correspond to different type of detections in a CT scans, and i would like to visualize those detected boxes in different colors (i.e., each .obj should display with a unique color). I am not sure how to convert the coordinates in the .obj to a .vtk file and how to specify the color or line width parameter in that file.

I am working on a plugin that is specific to slicer so ideally i want it to be able to work with slicer.

I would recommend to use “Markups ROI” nodes for showing ROI boxes in Slicer. You can create a myregions.mrk.json and add any number of ROI boxes to it. For example, file content for two ROI boxes:

{
    "@schema": "https://raw.githubusercontent.com/slicer/slicer/master/Modules/Loadable/Markups/Resources/Schema/markups-schema-v1.0.3.json#",
    "markups": [
        {
            "name": "My first region",
            "type": "ROI", "roiType": "Box", "coordinateSystem": "LPS", "coordinateUnits": "mm",
            "controlPoints": [{"position": [5.9, -12.3, -10.2], "locked": true}],
            "orientation": [-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0],
            "size": [39.3, 32.4, 32.4],
            "display": {"selectedColor": [0.4, 1.0, 1.0], "handlesInteractive": false}
        },
        {
            "name": "My second region",
            "type": "ROI", "roiType": "Box", "coordinateSystem": "LPS", "coordinateUnits": "mm",
            "controlPoints": [{"position": [45.9, -102.3, -10.2], "locked": true}],
            "orientation": [-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0],
            "size": [20.0, 30.5, 44.4],
            "display": {"selectedColor": [1.0, 0.0, 1.0], "handlesInteractive": false}
        }
     ]
}

Thanks Andras. This is exactly what i was looking for. Is there a way to change the opacity of the box in the axial view or line-width of the box by any chance ?

Actually nevermind, i see the opacity key in the template from the github link.

You can see most options if you save a markup ROI to file and have a look at the file.

1 Like