Cinema 4D - Importing models from IMOD to C4D R11
IMOD is a free set of image processing, modeling and display programs used for tomographic reconstruction. After generating 3D model of cells using IMOD/3dmod, I like to render them nicely and make moving in a program called Cinema 4D - a commercial, cross-platform, high-end 3D graphics application. On this page I explain how I import models from IMOD into Cinema 4D, and if you're interested you can ask me for the plugin I wrote which streamlines this process.
WARNING: These are old instructions for Cinema 4D R11 and earlier versions. While these instructions work fine for Cinema R11, Cinema R12 and later versions do not open VRML 1.0 files read more. If you are using C4D R12 you will instead need to use VRML 2.0 and you should get these instructions from: Cinema 4D - Importing models from IMOD.
Importing an IMOD model into Cinema 4D R11
Putting an IMOD model file into Cinema 4D R11 or earlier involves first exporting it to a VRML 1.0 file and can be quite tricky.
Some of the major problems are:
- The exported meshes are often too fine and/or contained jagged edges along Z - hence you may want to use the low res mesh, or use Cinema 4D to do a polygon reduction.
- The "imodmesh" algorithm tends to produce some very irregularly shaped triangles and certain points may connect to numerous other points (ideally you want each point in the mesh to shares only 3 or 4 edges, and triangles should be fairly uniform)
- Polygons are generated between slices in such a way that almost every point is duplicated - once to the contour above, and once to the contour below - in such a way that each surface appears to have multiple "rings" along Z (although this is not hard to fix in Cinema 4D by connecting all polygons then using Functions > Optimize)
- Point normals are usually screwy (so the solution is to delete them)
Below is the sequence to use to import an IMOD model file and then correct most of these problem:
- #1) Prepare mod file and convert to VRML:
- Open your IMOD model file in 3dmod, press [v] to bring up the ModelView window.
- Make sure all your desired objects are turned on (anything off is not included) and correctly meshed using the "Object ..." window.
- NOTE: IMOD often produces meshes which are unnecessarily fine and/or contain jagged edges along Z. To reduce this problem consider running the "smoothsurf" command line or generate a low res mesh for certain object.
- TIP: The command imodextract 1,2 foo.mod foo_obj1-2.mod can be used to to extract only certain objects
- Once satisfied press [t] (for top view) - otherwise your model will export at a weird orientation in the VRML file.
- Save [s] and close 3dmod.
- Open a terminal window and use the imod2vrml command: as demonstrated:
- imod2vrml foo.mod foo.vrml
- #2) Open VRML file in Cinema 4D:
- Open or drag foo.vrml into Cinema 4D
- WARNING: Depending on the size of the vrml and number of spheres, opening the vrml can take many minutes
- Save the file as foo.c4d (which should load faster) and don't forget to save regularly.
- In the "Objects" manager panel (on the left) expand "Axis", then expand the first object (Object0Data) to see its children.
- #3) Correct bad tags:
- Not only does IMOD export bad normals, but also has undesirable texture and phong settings, and so we may as well delete ALL tags from the new object. Select the first tag (the sphere-like icon representing texure) of the first object then scroll to the bottom, hold [shift] and click the last tag (the skin-like icon representing normals) to select all tags and hit [delete].
- Select Object0Data and drag in the appropriate colored texture from the "Materials" manager panel down the bottom.
- Right click the object and select "CINEMA 4D Tags > Phong" under "basic properties" untick "angle limit" - this will smooth over edges and render surfaces nicely once properly connected.
- #4) Connect polygons and reduce the number of points:
- In imod, contours are connected between adjacent slices: once to the contour above, and once to the contour below. As a result, each point is duplicated and polygons exist in such as multiple "rings" along Z (which you can observe when you select a single child polygon). We want to now connect all polygons as a single smooth polygon.
- Right click Object0Data and "Select Children", then right click it again and "Connect". This will connect all polygons and form a single polygon object (added at the top).
- Select and delete the original object, or click the two little dots till they both show red - meaning they won't be displayed any viewport or when rendering. Double click the new object to rename it to something more sensible.
- With the newly generated object selected go: Functions > Optimize, leave default settings and click OK. By removing duplicate points this should roughly have the total number of points.
- NOTE: To see the total number of point you can select the "Structure" manager panel on the right, and scroll down to the bottom.
- If you discover your mesh still contains too much "jaggedness" or too many points (say >100,000) to render well you may wish to click and hold the modifier icon (the icon of a bending prism on the top menu bar) and select "polygon reduction". Drag the new polygon reduction icon under your polygon object. When happy with results, right click your polygon object and select "Current State to Object". This should generate a new polygon object with significantly fewer points, although for some reason it puts it under a new null object (which you don't need).
- #5) Repeat these steps for each object.
- NOTE: For IMOD scattered point objects (spheres) you can delete textures as above, but won't have any polygons to connect. For IMOD open contour objects which have been meshed as tubes you may wish to delete or separate out any spheres in the object before proceeding with the other steps.
- #6) Order all your objects under a new null object.
- Once finished, it's a good idea to delete anything you don't need and place all your new objects/polygons into a single container. Click and hold the array object icon (7 from the right on the top menu bar) and select "Null Object". Rename this to "my model" and drag your new objects directly underneath it. Notice you can use this to apply transforms to all your objects (eg: select this container and enter a P (pitch rotation) value of -90 in the Coordinates manager to make your model "lie flat" along X-Z).
To help automate the process above Graham and I wrote a small COFFEE menu plugin available on request.
NOTE: "1 m" in C4D is equal to 1 pixel in IMOD (after importing) - with the Z axis already stretched by the "Z-scale" in your model. Although not important when working with single models, you can change Edit > Preferences > Units > Display Units from meters (m) to nanometers (nm), then scale "My Model" by your pixel size, to achieve the "correct scale" (sort of).
To render the scene within the viewing port click [Cmd+R]. The next thing you'll probably want to do is: (1) modify the textures to look nicer, (2) set up your scene with lights and then (3) create a movie. For these instructions you should return to the Cinema 4D page where each of these steps is explained.