Adding filters to zinc
Find the itk filter you require
The insight tool kit has a large number of filters already written. Rather than reinvent the wheel, use one of their filters if it will do the job you want. You should get a copy of the ITK software guide. This is a large book available in pdf form that documents many of the itk filters available. The latest copy is available online at http://www.itk.org/ItkSoftwareGuide.pdf
Find the filter you want and read up about it.
Write the cmgui wrapper to use the itk filter
Two files need to be written, a .h header file and a .cpp source file. These will be placed in the directory:
$CMISS_ROOT/cmgui/source/image_processingThe easiest way to write these files is to start by copying an existing filter and modifying it accordingly. A nice simple one to look at is computed_field_binaryThresholdFilter.cpp
Add the wrappers into the main cmiss program
Edit the file #CMISS_ROOT/cmgui/source/command/cmiss.c
Search the file for USE_ITK and you will find the two spots where code needs to be added. Add a link to include your header:
#include "image_processing/computed_field_binaryThresholdFilter.h"
and also add a line later to register the filter type:
Computed_field_register_types_binaryThresholdFilter(command_data->computed_field_package);
Add api support (optional)
If you wish to use your field from an XPCOM object much of the code for the XPCOM object can be generated automatically from the xpidl compiler if certain conventions are followed. Using the following conventions will allow you to call the get and set type routines in a javascript implementation of your XPCOM object simply by adding them into the idl file.
Edit the .h and .cpp files for your cmgui wrapper and replace any float parameters with doubles and any int parameters with longs.
The .h file for your cmgui wrapper also needs to have some code added to allow api access. Edit '$CMISS_ROOT/cmgui/source/image_processing/computed_field_my_image_filter.h'
Add the following lines above the function definitions:
#include "api/cmiss_computed_field.h" /* API functions are prefixed with Cmiss */ #define Computed_field_set_type_my_image_filter \ Cmiss_Computed_field_set_type_my_image_filter #define Computed_field_get_type_my_image_filter \ Cmiss_Computed_field_get_type_my_image_filterEdit the file '$CMISS_ROOT/cmgui/source/api/cmiss_computed_field.h'
Add the function headers for the get and set routines for your filter. Eg:
int Cmiss_computed_field_get_type_binary_threshold_image_filter(struct Computed_field *field, struct Computed_field **source_field, double *lower_threshold, double *upper_threshold); int Cmiss_computed_field_set_type_binary_threshold_image_filter(struct Computed_field *field, struct Computed_field *source_field, double lower_threshold, double upper_threshold);
Edit the cmgui.Makefile
Edit the makefile $CMISS_ROOT/source/cmgui.Makefile
To find where to edit it do a search on IMAGE_PROCESSING and add in your .cpp file to the list of source files:
image_processing/computed_field_binaryThresholdFilter.cpp\
Build cmgui
To build the version you require for zinc type:
cd $CMISS_ROOT/cmgui make cmgui-gtk-gtkmain-debug-static-lib
Build zinc
To build a new version of the zinc plugin type:
cd $CMISS_ROOT/zinc make zincIMPORTANT: make sure you are not in the directory '$CMISS_ROOT/zinc/zinc' as make will also run there but will not build the entire application.
Install your new plugin
Open the file zinc.xpi that will have been built in $CMISS_ROOT/zinc/zinc/install
Wait a few seconds and then click install. You will then need to restart your browser.
Using your new filter
The above process with enable you to define your new filter with gfx commands and executed them through the 'commandData.executeCommand' syntax. If you have a debug version of the zinc plugin you can try typing gfx commands directly into the command window.
It is also possible to add an XPCOM object for your filter into mozilla which will deal with opening a dialog and allowing options to be set for the filter. If you want to do this then I recommend adding the optional code for the api as described above.