using System; using System.IO; using System.Drawing; using System.Windows.Forms; using ClassLibrary; namespace Treko3D { public class Treko3D : Technology { private Bitmap[] _rakurseBmps; //private string _outDirName; // We have tvo displays for test: int _imgDisplayTreko3DWidthPix = 2000; int _imgDisplayTreko3DHeightPix = 2000; int _imgDisplayVoxelWidthPix = 2500; int _imgDisplayVoxelHeightPix = 2500; Image _imgDisplayTreko3D; Image _imgDisplayVoxel; int _imageWidthPix; int _imageHeightPix; int _voxelWidthPix; int _voxelHeightPix; double _radiusMax; double _step; int _arcWidth = 20; // Width of arcs (in numbers of arcs or pixels) Strip[] _strips; string[] _rakurseFiles; int _nRakurses; public int ImgDisplayTreko3DWidthPix { get { return _imgDisplayTreko3DWidthPix; } set { _imgDisplayTreko3DWidthPix = value; } } public int ImgDisplayTreko3DHeightPix { get { return _imgDisplayTreko3DHeightPix; } set { _imgDisplayTreko3DHeightPix = value; } } public int ImgDisplayVoxelWidthPix { get { return _imgDisplayVoxelWidthPix; } set { _imgDisplayVoxelWidthPix = value; } } public int JmgDisplayVoxelHeightPix { get { return _imgDisplayVoxelHeightPix; } set { _imgDisplayVoxelHeightPix = value; } } public Image ImgDisplayTreko3D { get { return _imgDisplayTreko3D; } set { _imgDisplayTreko3D = value; } } public Image ImgDisplayVoxel { get { return _imgDisplayVoxel; } set { _imgDisplayVoxel = value; } } public int ImageWidthPix { get { return _imageWidthPix; } set { _imageWidthPix = value; } } public int ImageHeightPix { get { return _imageHeightPix; } set { _imageHeightPix = value; } } public Bitmap[] RakurseBmps { get { return _rakurseBmps; } set { _rakurseBmps = value; } } public int VoxelWidthPix { get { return _voxelWidthPix; } set { _voxelWidthPix = value; } } public int VoxelHeightPix { get { return _voxelHeightPix; } set { _voxelHeightPix = value; } } public double RadiusMax { get { return _radiusMax; } set { _radiusMax = value; } } public double Step { get { return _step; } set { _step = value; } } public int ArcWidth { get { return _arcWidth; } set { _arcWidth = value; } } public Strip[] Strips { get { return _strips; } set { _strips = value; } } public string[] RakurseFiles { get { return _rakurseFiles; } set { _rakurseFiles = value; } } public int NRakurses { get { return _nRakurses; } set { _nRakurses = value; } } public void CreateImageTreko3D() { if (_imgDisplayTreko3D == null) { _imgDisplayTreko3D = new Bitmap(_imgDisplayTreko3DWidthPix, _imgDisplayTreko3DHeightPix); } } public void CreateImageVoxel() { if (_imgDisplayVoxel == null) { _imgDisplayVoxel = new Bitmap(_imgDisplayVoxelWidthPix, _imgDisplayVoxelHeightPix); } } public Strip GenerateAndSaveStrip(int nStrip, string fullName, string outDirName, int decimate) { Strip strip = new Strip(nStrip, this); // rakurseFiles); strip.GenerateAndSaveStrip(nStrip, outDirName, decimate); return strip; } public void GenerateAndSaveStrips(string path, string outDirName) { FileInfo stripFile; LoadRakurseFiles(); Bitmap RakurseBmp = RakurseBmps[0]; ImageHeightPix = RakurseBmp.Height; ImageWidthPix = RakurseBmp.Width; int decimate = ImageWidthPix / 200; if (decimate <= 0) decimate = 1; //!!!!Nick _strips = new Strip[ImageHeightPix]; for (int nRow = 0; nRow < ImageHeightPix; nRow += decimate) { stripFile = getFileName(nRow, path); _strips[nRow] = GenerateAndSaveStrip(nRow, stripFile.FullName, outDirName, decimate); } } public Strip GenerateStrip(int nStrip, int nVoxelStart, int nVoxelEnd) { Strip strip = new Strip(nStrip, this); // rakurseFiles); strip.GenerateStrip(nStrip, nVoxelStart, nVoxelEnd); return strip; } // Load rakurse files and initialize bitmap array public void LoadRakurseFiles() { if (RakurseBmps != null) foreach (Bitmap rakurseBmp in RakurseBmps) rakurseBmp.Dispose(); RakurseBmps = new Bitmap[_nRakurses]; for (int i = 0; i < NRakurses; i++) { try { RakurseBmps[i] = (Bitmap)Image.FromFile(RakurseFiles[i]); } catch (Exception exception) { MessageBox.Show(exception.Message, exception.GetType().FullName); } } } private FileInfo getFileName(int nRow, string path) { string dir = Path.GetDirectoryName(path); string fileName = Path.GetFileNameWithoutExtension(path); string _prefix = GetUntilOrEmpty(fileName, "_"); _prefix = "nika"; string fileExt = ".png"; // Path.GetExtension(path); path = Path.Combine(dir, _prefix + "_" + nRow + fileExt); return new FileInfo(path); } public string GetUntilOrEmpty(string text, string stopAt = "_") { if (!String.IsNullOrWhiteSpace(text)) { int charLocation = text.IndexOf(stopAt, StringComparison.Ordinal); if (charLocation > 0) { return text.Substring(0, charLocation); } } return String.Empty; } public void DrawOnImage(Image imgTreko3D, int _mmToPixelsCoeff) { //imgTreko3D.Refresh(); foreach (Strip strip in _strips) { if (strip != null) { //strip.MmToPixelsCoeff = MmToPixelsCoeff; strip.DrawOnPictureBox(imgTreko3D, _mmToPixelsCoeff); } } } public void DrawAnimation(Image imgTreko3D, int angPreview, int parallaxAng, int mmToPixelsCoeffPreview) { foreach (Strip strip in _strips) { if (strip != null) { strip.DrawAnimation(imgTreko3D, angPreview, parallaxAng, mmToPixelsCoeffPreview); } } } //public void GenerateFrames() //{ // generateFrameGroups(); //} //public void SaveFramesToFiles() //{ // int i = 0; // foreach (FrameGroup fg in _frameGroups) // { // if (fg.IntersectArcs != null && fg.IntersectArcs.Count > 0) // { // fg.DrawBitmapByArcs(); // fg.SaveGroupToFiles(_outDirName, i); // fg.FrameGroupBmp.Dispose(); // } // i++; // } //} } }