Tips for VVectors and Structures in ESAPI

Hey guys!

Today I will write about some shortcuts and interesting things I’ve learned when playing with structures and VVectors in ESAPI.

All the code will be shared at my GitHub page! So don’t worry about copy and paste today!

What are VVectors?

The VVector class is a recipient to the coordinates in the X, Y and Z direction in the CT DICOM. You can perform the usual vector operations, such as dot product, vector product, scalar product, addition, subtraction.

How do I access the coordinates:

It’s interesting that you can also treat it like a C# array, vVector[0] (access x coordinates) and so on.

Where is the origin?

the DICOM coordinates of the center point of the upper-left hand corner voxel of the first image plane.

In which Slice this VVector is?

public static int _GetSlice(double z, StructureSet SS)       {                       var imageRes = SS.Image.ZRes;
return Convert.ToInt32((z - SS.Image.Origin.z) / imageRes);
}

How can I get the user’s coordinates:

Image.DicomToUser(vVector, plan) //Outputs the User Coordinates

How to access a Structure:

var ptv = scriptContext.StructureSet.Structures.First(e => e.Id == "PTV");

In which slice is the center point of a structure?

ptv.CenterPoint; // VVector

Where does it ends and begins, introducing MeshGeometry:

MeshGeometry representation

You can get the list of slices of the structure is using the following method:

public static IEnumerable<int> _GetMeshBounds(Structure structure, StructureSet SS)       { 
var mesh = structure.MeshGeometry.Bounds;
var meshLow = _GetSlice(mesh.Z, SS);
var meshUp = _GetSlice(mesh.Z + mesh.SizeZ, SS) + 1; return Enumerable.Range(meshLow, meshUp);
}

WPF ViewPort3D:

We’ll use it to perform some checks later in this article.

You can check the code in my GitHub page. This binary plugin called StructureOnWPF can copy and move structures based on the selected structure.

Remember to run this code on TBOX… It’s just a test, and it’s not recommended for clinical use.

StructureOnWPF Project, Left Slider (Zoom), Right Sliders (Rotation), The text box, fields for displacements in mm

A structure contour is a List of VVectors:

ptv.GetContoursOnImagePlane(plane);

It is an array of arrays of VVectors 😥.

You can access the x,y and z positions of the points via MeshGeometry.

It is simpler than the former alternative, and you can transform it into VVectors.

contours = ptv.MeshGeometry.Points.Select(e=>new VVector(e.x,e.y,e.z));

How to draw a structure?

ptv.AddContourOnImagePlane(arrayOfVvector, slice);

This is interesting… Even knowing that your VVectors have the Z coordinates, ESAPI needs you to explicitly tell which slice to draw, and it will use only the X and Y coordinates.

Be careful with high resolution:

Drawing the structure, but not converting to high resolution before.

DicomTypes:

Possible values are “AVOIDANCE”, “CAVITY”, “CONTRAST_AGENT”, “CTV”, “EXTERNAL”, “GTV”, “IRRAD_VOLUME”, “ORGAN”, “PTV”, “TREATED_VOLUME”, “SUPPORT”, “FIXATION”, “CONTROL”, and “DOSE_REGION”.

How to operate between structures:

var ss =  scriptContext.StructureSet;
var overlap = ss.
AddStructure("CONTROL",CheckStructureIds(ss,"organ_ovl");
overlap.SegmentVolume = ptv.SegmentVolume.And(oar.SegmentVolume);

Check for high resolution, you can’t operate in ESAPI between default and high resolution segment volumes.

Contouring vs ESAPI:

Since operations in ESAPI are done with a different engine, they lead to a different result, however this has little optimization impact (this could be a nice science experiment). Here is an overlap example:

Script Overlap is in blue, it’s statistics are represented in the left. The magenta is the contouring Overlap, it’s statistics are represented in the right.

Be careful with Structure Id max length:

Structure Color:

Maximum number of Structures:

Moving a structure:

It uses all the previous concepts we’ve been discussing in this article.

Real number coordinates versus CT resolution:

If you try to displace below the CT resolution:

For my own surprise, the structure is indeed displaced, but the results are not linear, some points do arrange and others don’t.

Here is the result if you displace with the CT resolution:

The result makes more sense.

More on operation between structures:

It is a simple user interface of PTV and GTV unions that can get you insight in how to develop your own optimization structures routine.

Photo by Leon Seibert on Unsplash

Thanks for reading!

See you next time!

What do you guys think it is a good topic for my next post?

Are you used to use GitHub?

Thanks to Jonas to review this article!

--

--

Radiation Therapy Medical Physicist and Programmer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store