How to develop a Horos/Osirix Plugin - new tutorial
Do you want to write an Horos/Osirix plugin? Basic tutorials you have found so far in the internet are confusing? Try this one!
Useful resources
Osirix plugins Github repository
OsiriX website
OsiriX plugin basics website
OsiriX plugin by osirixnewby
OsiriX plugin development tutorial by Kyung Hyun Sung
OsiriX ITK plugin development tutorial by Brian Jensen
Basic configuration
- Get a copy of Plugin Template from osirix plugin github repository.
- (Optional) Rename the plugin in XCode:
- Project name on in the left panel.
- Target name in the left panel of general setting of the projects.
- In Build settings of the Target change product name.
- Select class name in .h file, Edit->Refactor the name.
- Replace all occurrences in
xxx_Prefix.pchfile and folder names. - Change name is Mange schemes.
- Verify everything is working.
- In XCode click Edit Scheme. As executable choose Horos/Osirix (you can choose the one in Application directory).
- Go to Arguments, Arguments Passed on Launch and add
--LoadPlugin $(BUILT_PRODUCTS_DIR)/$(PRODUCT_NAME).$(WRAPPER_EXTENSION) - Verify that everything is working.
ITK configuration
- (If you do not have ITK installed already).
- In terminal navigate to the directory where you want to have ITK code, for example you can use
~(your home directory) as<myCodeDir>.cd <myCodeDir> git clone git://itk.org/ITK.git cd ITK git checkout --track -b release origin/release - In CMake use source code directory
<myCodeDir>/ITKand build the binaries directory you can use for example<myCodeDir>/ITK_bin. Configure. As generator for the project selectUnix Makefiles. UncheckBuild_Tests. SelectModule_ITKVtkGlueif you have VTK. SelectModule_Revisionif you want to use Elastix. Generate.cd <myCodeDir>/ITK_bin make sudo make install
- In terminal navigate to the directory where you want to have ITK code, for example you can use
- In your project in XCode rename your filter file extension to
.mm. - Create a
symbolListfile, and fill it with.objc_class_name_<myPluginFilter>. Replace<myPluginFilter>with your filter class name (see also OsirixPluginBasics). - In build settings:
- Set
Other Linker Flagsto-undefined dynamic_lookup -exported_symbols_list symbolList(see also OsirixPluginBasics). - Add ITK header paths. Check your ITK installation directory. If you did not change it during the ITK installation, it should be
/usr/local. Go there to confirm (Command Shift Gin Finder). SetHeader Search Pathsto/usr/local/include/ITK-4.12or similar. - Add ITK library paths. Set
Library Search Pathto/usr/local/lib/. Add ITK library files (.aextension) to your project for example by dragging and dropping it from Finder.
- Set
- Add some ITK code to verify if everything works. For example code from here.
CorePlot
- (If you do not have CorePlot).
- In terminal navigate to the directory where you want to have CorePlot code, for example you can use
~(your home directory) as<myCodeDir>.cd <myCodeDir> git clone git@github.com:core-plot/core-plot.git cd ITK git checkout --track -b release origin/release-2.3
- In terminal navigate to the directory where you want to have CorePlot code, for example you can use
- Annoyingly, following CorePlot instructions does not do the job (XCode cannot localize
CorePlot.h) as far as I tried it. To make CorePlot work you can try the following steps:- Open CorePlot project and build it. You can build Release version by Edit Scheme -> Build Configuration -> Deployment.
- CorePlot is build to
/core-plot/build/ folder. Drag and drop CorePlot.framework to your project opened in XCode. Select 'Copy files if needed'. - Add
#import <CorePlot/CorePlot.h>in your code to verify everything works. - It is time to display something with CorePlot. Copy
Controller.handController.mfrom MinorTickLabels example in CorePlot. - If you are getting error messages about the code, update project setting to recommended by XCode and in Build settings set
macos deployment targetto a current one (for example10.12). - Create a new window xib, call it
Window.xib. Add aCustom View. Set theCustom Viewclass toCPTGraphHostingView. - Add following lines to your plugin:
NSWindowController *mywindow = [[NSWindowController alloc] initWithWindowNibName:@"Window" owner:self]; [mywindow showWindow:self]; - Still in xib editor, add a new object and set its class to
Controller. - In connections inspector connect
hostViewoutlet to theCustom View. - Everything should compile but you can run into a problem with loading your plugin
Library not loaded,Reason: image not found. In build settings setRunpath search pathstoLD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks. In build phases addNew copy files phaseusing+at the top of the screen. ChangeDestinationtoFrameworksand drag and dropCorePlot.frameworkfrom the left panel.
Troubleshooting
Typeinfo file not found
Error: ` /usr/local/include/ITK-4.12/itkMacro.h:45:10: ‘typeinfo’ file not found `
Solution: change file extension from .m to .mm