Example: Create an Intersection Structure #85
kyleburnett
started this conversation in
Show and tell
Replies: 1 comment
-
|
@kyleburnett - thanks for working through this example, much apprecaited. I will see if I can figure out the union operation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The example below shows how you can create an intersection structure using ProKnow's Python SDK. Please do no copy this code without making appropriate modifications and verifying that it is doing what you want it to do.
Let's go through this file step-by-step to understand what's happening.
These are the import statements and assume that you have the packages
proknowandpyclipperalready installed withpip.These functions are responsible for converting ProKnow contour paths to clipper paths and vice versa.
This line creates an instance of the ProKnow class. Note that you will need to replace
{base_url_here}with the base URL of your ProKnow organization.This statement finds a patient and gets the patient details (e.g., its studies and entities).
{workspace_name}and{patient_mrn}should be replaced with the values for a patient with a structure set containing structures you want to intersect.These statements find all structure set entities and gets the details for the first one in the list.
These lines are responsible for finding structures we want to intersect by name.
These lines extract the contour data for the two input structures and creates an empty array to hold the contours for the resulting intersection structure.
These lines loop through the slices with contours for structure "A" and attempts to find a slice at the same position in structure "B".
Since this is an intersection operation, we only consider slices in which there are contours defined for both structures on the same slice, which is what the
ifcondition ensures. The next four lines extract the paths from the dictionary object and convert the paths to a form that clipper can use.These lines perform the clipping operation by (a) creating a new
Pyclipperinstance, (b) adding the clip and subject paths, and (c) executing the intersection operation. Before appending to the contour slices array, the contour points are cleaned to removing artifacts (using a distance of 2 units, i.e., 0.002 mm).This line creates a draft of the structure set or opens the existing draft if it already exists, automatically renewing the current user's claim on the draft. When the interpreter exists the with block, the claim will be automatically released if applicable.
This line creates a new ROI on the draft. It is given the name "C," the color green, and a type of "ORGAN."
These lines overwrites the default, empty contours array with the contours that represent the intersection of contours "A" and "B." Then the data is saved.
Beta Was this translation helpful? Give feedback.
All reactions