How to crop 3D image from a 2D free-hand ROI?

This feature is implemented in 3D Slicer (Segment Editor / Scissors effect). You can use it as is, or use the source code in your application, or customize Slicer to do exactly what you need.