C#
C++/CLI
using Leadtools;
using Leadtools.Codecs;
using Leadtools.MedicalViewer;
using Leadtools.Medical3D;
public void Medical3DControlExample()
{
Medical3DLoadDICOMSeriesExamples LoadObject = new Medical3DLoadDICOMSeriesExamples();
MedicalViewerSeriesManager output = LoadObject.LoadJamesHead();
MainForm1 form = new MainForm1(output);
form.ShowDialog();
}
// MainForm1 will be the owner of the medical viewer control.
class MainForm1 : Form
{
private Medical3DControl _medical3DControl;
public MainForm1(MedicalViewerSeriesManager output)
{
RasterCodecs _codecs = new RasterCodecs();
RasterImage _image;
CodecsImageInfo codecsInformation;
_medical3DControl = new Medical3DControl();
this.SizeChanged += new EventHandler(MainForm1_SizeChanged);
this.FormClosing += new FormClosingEventHandler(MainForm1_FormClosing);
_medical3DControl.ObjectsContainer.Objects.Add(new Medical3DObject());
int index;
codecsInformation = _codecs.GetInformation((string)output.Stacks[0].Items[0].Data, true);
int width = codecsInformation.Width;
int height = codecsInformation.Height;
int depth = 256;
_medical3DControl.ObjectsContainer.Objects[0].MemoryEfficientInit(depth);
for (index = 0; index < depth; index++)
{
_image = _codecs.Load((string)output.Stacks[0].Items[index].Data, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1);
_medical3DControl.ObjectsContainer.Objects[0].MemoryEfficientSetFrame(_image, index, output.Stacks[0].Items[index].ImagePosition, true);
}
string spearator = ("\\");
string[] test = output.Stacks[0].Items[0].ImageOrientation.Split(spearator.ToCharArray());
float[] orientation = new float[6];
int i;
for (i = 0; i < 6; i++)
{
orientation[i] = (float)Convert.ToDouble(test[i]);
}
_medical3DControl.ObjectsContainer.Objects[0].MemoryEfficientEnd(orientation, output.Stacks[0].PixelSpacing);
_medical3DControl.ObjectsContainer.Camera.ProjectionMethod = Medical3DProjectionMethod.Orthogonal;
_medical3DControl.AddAction(MedicalViewerActionType.Rotate3DCamera);
_medical3DControl.SetAction(MedicalViewerActionType.Rotate3DCamera, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active);
_medical3DControl.AddAction(MedicalViewerActionType.Translate3DCamera);
_medical3DControl.SetAction(MedicalViewerActionType.Translate3DCamera, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active);
_medical3DControl.SetTag(1, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "");
_medical3DControl.SetTag(2, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "");
_medical3DControl.SetTag(3, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "");
_medical3DControl.SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "");
_medical3DControl.CameraSettingsChanged += new EventHandler<Medical3DCameraEventArgs>(_medical3DControl_CameraSettingsChanged);
Controls.Add(_medical3DControl);
}
void _medical3DControl_CameraSettingsChanged(object sender, Medical3DCameraEventArgs e)
{
_medical3DControl.EditTag(1, MedicalViewerTagAlignment.TopLeft, new MedicalViewerTagInformation(1, MedicalViewerTagAlignment.TopLeft,
"X = " + _medical3DControl.ObjectsContainer.Camera.XOffset.ToString() +
" Y = " + _medical3DControl.ObjectsContainer.Camera.YOffset.ToString() +
" Z = " + _medical3DControl.ObjectsContainer.Camera.ZOffset.ToString(), MedicalViewerTagType.UserData));
_medical3DControl.EditTag(2, MedicalViewerTagAlignment.TopLeft, new MedicalViewerTagInformation(2, MedicalViewerTagAlignment.TopLeft,
"XRotation = " + _medical3DControl.ObjectsContainer.Camera.XRotation.ToString() +
" YRotation = " + _medical3DControl.ObjectsContainer.Camera.YRotation.ToString() +
" ZRotation = " + _medical3DControl.ObjectsContainer.Camera.AxialRotation.ToString(), MedicalViewerTagType.UserData));
_medical3DControl.EditTag(3, MedicalViewerTagAlignment.TopLeft, new MedicalViewerTagInformation(3, MedicalViewerTagAlignment.TopLeft,
"Projection Method = " + _medical3DControl.ObjectsContainer.Camera.ProjectionMethod.ToString(), MedicalViewerTagType.UserData));
_medical3DControl.EditTag(4, MedicalViewerTagAlignment.TopLeft, new MedicalViewerTagInformation(4, MedicalViewerTagAlignment.TopLeft,
"Zoom = " + _medical3DControl.ObjectsContainer.Camera.Zoom.ToString(), MedicalViewerTagType.UserData));
}
void MainForm1_FormClosing(object sender, FormClosingEventArgs e)
{
_medical3DControl.Dispose();
}
void MainForm1_SizeChanged(object sender, EventArgs e)
{
if (_medical3DControl != null)
_medical3DControl.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom);
}
}