OsiriX Documentation

repository·develop·Indexed 19 days ago

https://github.com/pixmeo/osirix

Open-source medical imaging software viewer. Documentation includes guides for building and running the odt2pdf tool using LibreOffice, OpenOffice.org, or NeoOffice; instructions for creating custom DICOM importers by implementing the GetMetadataForFile function within a CFPlug-in architecture; and details on the NSFont_OpenGL extension for creating OpenGL display lists for fonts.

Tokens
1.9K
Snippets
6
Records
9
Agent score
64%

What's inside OsiriX

  1. Configure odt2pdf for OpenOffice and NeoOffice

    develop

    If you are using distributions other than LibreOffice, you must adjust the DYLD_LIBRARY_PATH, the path to the soffice binary, and the URE_MORE_TYPES path accordingly.

    OpenOffice.org

    export DYLD_LIBRARY_PATH=/Applications/OpenOffice.org.app/Contents/basis-link/ure-link/lib
    /Applications/OpenOffice.org.app/Contents/MacOS/soffice "-accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" &
    ./odt2pdf -env:URE_MORE_TYPES=file:///Applications/OpenOffice.org.app/Contents/basis-link/program/offapi.rdb test.odt test.pdf

    NeoOffice

    export DYLD_LIBRARY_PATH=/Applications/NeoOffice.app/Contents/basis-link/ure-link/lib
    /Applications/NeoOffice.app/Contents/MacOS/soffice "-accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" &
    ./odt2pdf -env:URE_MORE_TYPES=file:///Applications/NeoOffice.app/Contents/basis-link/program/offapi.rdb test.odt test.pdf
  2. Run odt2pdf with LibreOffice

    develop

    The odt2pdf binary requires a running instance of LibreOffice configured to accept socket connections via the UNO (Universal Network Objects) interface.

    1. Start LibreOffice in listener mode

    You must launch LibreOffice with the --accept flag to allow the tool to communicate with it. Note that different versions of LibreOffice may require different hyphenation for the flag (--accept vs -accept).

    For LibreOffice 3.4.3+:

    /Applications/LibreOffice.app/Contents/MacOS/soffice "--accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" &

    2. Execute the conversion

    Set the DYLD_LIBRARY_PATH to point to the LibreOffice URE library and run the binary with the -env:URE_MORE_TYPES flag pointing to the offapi.rdb file.

    export DYLD_LIBRARY_PATH=/Applications/LibreOffice.app/Contents/basis-link/ure-link/lib
    ./odt2pdf -env:URE_MORE_TYPES=file:///Applications/LibreOffice.app/Contents/basis-link/program/offapi.rdb input.odt output.pdf

    3. Cleanup

    To stop the background LibreOffice process:

    killall LibreOffice
    export DYLD_LIBRARY_PATH=/Applications/LibreOffice.app/Contents/basis-link/ure-link/lib
    /Applications/LibreOffice.app/Contents/MacOS/soffice "--accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" &
    ./odt2pdf -env:URE_MORE_TYPES=file:///Applications/LibreOffice.app/Contents/basis-link/program/offapi.rdb test.odt test.pdf
  3. Build the odt2pdf tool

    develop

    To build odt2pdf, you must have the LibreOffice SDK (version 3.4.3 was used in this guide) installed.

    1. Download and move the LibreOffice SDK directory to a permanent location.
    2. Enter the SDK directory and initialize the environment using the setsdkenv_unix script.
    3. Navigate to the odt2pdf source directory.
    4. Run make to compile the tool.

    Upon successful completion, the binary will be located at path/to/odt2pdf/build/odt2pdf.

    cd /path/to/LibreOffice3.4_SDK
    sh setsdkenv_unix
    
    cd path/to/odt2pdf
    make
  4. How the Metadata Importer plugin architecture works

    develop

    The DICOM importer is implemented as a CFPlug-in using a COM-like architecture. The system interacts with the plugin through a factory pattern and reference counting.

    Core Components:

    1. Factory Function (MetadataImporterPluginFactory): The entry point used by the system to instantiate the plugin. It checks if the requested typeID matches kMDImporterTypeID before returning a new instance.
    2. Plugin Instance (MetadataImporterPluginType): A structure that holds the conduitInterface (the function table), the factoryID, and a refCount for memory management.
    3. Interface Table (MDImporterInterfaceStruct): A table of function pointers that defines the plugin's capabilities. The standard table includes:
      • QueryInterface: To allow the system to request specific interfaces (like kMDImporterInterfaceID or IUnknownUUID).
      • AddRef / Release: For manual reference counting.
      • GetMetadataForFile: The user-implemented metadata extraction logic.

    Lifecycle:

    • The system calls the factory to get an instance.
    • The instance is managed via AddRef and Release calls.
    • When the refCount reaches zero, DeallocMetadataImporterPluginType is called to free the memory and unregister the factory.
  5. Configure NSFont OpenGL error logging

    develop

    By default, errors encountered during OpenGL display list creation are logged using NSLog(). You can disable this class-wide logging using the setOpenGLLogging: method on NSFont.

    // Disable logging for all NSFont OpenGL operations
    [NSFont setOpenGLLogging:NO];
  6. Create OpenGL display lists for NSFont

    develop

    The NSFont_OpenGL extension adds a category to NSFont that enables the creation of OpenGL display lists for bitmaps based on a specific font. This is useful for rendering font characters directly via OpenGL.

    To create display lists for a range of characters, use the makeGLDisplayListFirst:count:base: method on an NSFont instance. You must provide a base value obtained from a call to glGenLists().

    // Assuming myFont is an NSFont instance
    // and displayListBase is the value returned from glGenLists()
    
    BOOL success = [myFont makeGLDisplayListFirst:' ' count:95 base:displayListBase];
    
    // Returns TRUE if successful, FALSE otherwise.
  7. Reference: MetadataImporterPluginType structure

    develop

    The MetadataImporterPluginType structure defines the internal layout of a plugin instance used by the importer component.

    typedef struct __MetadataImporterPluginType
    {
        MDImporterInterfaceStruct *conduitInterface;
        CFUUIDRef                 factoryID;
        UInt32                    refCount;
    } MetadataImporterPluginType;
  8. Implement the GetMetadataForFile function to create a DICOM importer

    develop

    To create a custom DICOM importer for OsiriX, you must implement the GetMetadataForFile function in a separate file (typically GetMetadataForFile.c). This function is the core logic of the importer, called by the system to extract metadata from a file.

    Function Signature:

    Boolean GetMetadataForFile(void *thisInterface, 
                               CFMutableDictionaryRef attributes, 
                               CFStringRef contentTypeUTI,
                               CFStringRef pathToFile);

    Parameters:

    • thisInterface: A pointer to the interface being used.
    • attributes: A CFMutableDictionaryRef where you should populate the extracted metadata keys and values.
    • contentTypeUTI: A CFStringRef representing the Uniform Type Identifier of the file.
    • pathToFile: A CFStringRef containing the file system path to the file being imported.
    Boolean GetMetadataForFile(void *thisInterface, 
    		   CFMutableDictionaryRef attributes, 
    		   CFStringRef contentTypeUTI,
    		   CFStringRef pathToFile);