2.1. How to use a ROI as mask for operation on Channel

In this example we will use a ROI to mask a Channel.

First create a example channel:

from ORSModel import Channel
channel = Channel()
#set it sizes, since we use the default voxel size, the channel is for now 100 meter cube
channel.setXYZTSize(100,100,100,1)
channel.setXSpacing(0.01)
channel.setYSpacing(0.01)
channel.setZSpacing(0.01)
#now the channel is 1 meter cube
#initilize it for float32 data
channel.initializeDataForFLOAT()
#put some data in the channel
channel.paintSphere(channel.getBox().getCenter(), channel.getBox().getDirection0Size()*0.5, 1, 0)
#tell the channel that it data was modified (this can trigger event trapped by the UI)
channel.setDataDirty()
#publish it so that it is visible in the Object properties list
channel.publish()

Second let’s create a ROI of the same shape as the channel:

from ORSModel import ROI, orsColor
roi = ROI()
roi.setInitialColor(orsColor(1,0,0,1))
roi.copyShapeFromStructuredGrid(channel)
channel.getAsROIWithinRangeInArea(1, 1, 0, 0, 0, channel.getXSize()*0.5, channel.getYSize()*0.5, channel.getZSize()*0.5, None, roi)
roi.publish()

Third let’s overwrite the channel with the roi:

channel.overwriteValueWithROI(roi, -1)
channel.setDataDirty()