-
Notifications
You must be signed in to change notification settings - Fork 125
Plugins: 04 Process Input Data
Kaspar Schmid edited this page Apr 16, 2015
·
2 revisions
processInputData()
is called when either the process properties or the input data for your algorithm have changed by user interaction or any preceding process items. This is the place where you do the heavy lifting.
Delete the previous result data in order to prevent memory leaks and create a new instance for saving your algorithm's result.
// delete previous result
delete _result;
_result = new IPLImage( image->type(), width, height );
Get the process properties which you have defined before in init()
// get properties
float threshold = getProcessPropertyDouble("threshold");
Iterate over image planes (input channels). OpenMP can be used to distribute the processing of each plane to a different thread, which results in much faster processing on muticore CPUs.
#pragma omp parallel for
for(int planeNr=0; planeNr < nrOfPlanes; planeNr++)
Iterate over pixel rows and columns
for(int y=0; y<height; y++)
for(int x=0; x<width; x++)
Access input pixels
input->plane(planeNr)->p(x, y); // fast, unchecked
input->plane(planeNr)->cp(x, y); // zero for invalid coordinates
input->plane(planeNr)->bp(x, y); // extend border mode
input->plane(planeNr)->wp(x, y); // wrap border mode
Write to output pixels
_result->plane(planeNr)->p(x, y) = value;
Notify the GUI about your progress between 0 and 100%
// progress
notifyProgressEventHandler(100*progress++/maxProgress);