/// Copyright (c) 2021 Iiro Iivanainen, Harri Linna, Jere Pakkanen, Riikka Vilavaara /// /// Permission is hereby granted, free of charge, to any person obtaining /// a copy of this software and associated documentation files (the /// "Software"), to deal in the Software without restriction, including /// without limitation the rights to use, copy, modify, merge, publish, /// distribute, sublicense, and/or sell copies of the Software, and to /// permit persons to whom the Software is furnished to do so, subject to /// the following conditions: /// /// The above copyright notice and this permission notice shall be included /// in all copies or substantial portions of the Software. /// /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, /// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF /// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. /// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY /// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, /// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE /// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /// using System.Collections.Generic; using System.IO; using System.Text.Json.Serialization; namespace CoreLibrary { /// /// Sample class that contains map, attached datas and meta data that is connected to sample. /// Is responsible for interaction between map data and attached data. Is also the only class /// that directly interacts with GUI. /// public class Sample { public string Name { get; set; } [JsonIgnore] public string Filepath { get; set; } public Map Map { get; set; } public Attachments AttDataList { get; set; } public Metas MetaList { get; set; } /// /// Constructor for JSON serialization and deserialization. Note that the /// parameter names must match the attribute names (non case sensitive) /// /// Name of the file /// Map containing all stacks /// List of attached datas /// List of sample metadata [JsonConstructor] public Sample(string name, Map map, Attachments attdatalist, Metas metalist) { Name = name; Map = map; AttDataList = attdatalist; MetaList = metalist; } /// /// Getting Slice X as byte array. /// /// Slice X as byte array public byte[] GetSliceX() { return Map.StackX.GetAsByteArray(); } /// /// Getting Slice Y as byte array. /// /// Slice Y as byte array public byte[] GetSliceY() { return Map.StackY.GetAsByteArray(); } /// /// Getting Slice Z as byte array. /// /// Slice Z as byte array public byte[] GetSliceZ() { return Map.StackZ.GetAsByteArray(); } /// /// Updating stack Z when depth changes /// /// Depth of slice public void UpdateStackZ(int depth) { Map.UpdateStackZ(depth); } /// /// Updating stack X when depth changes /// /// Depth of slice public void UpdateStackX(int depth) { Map.UpdateStackX(depth); } /// /// Updating stack Y when depth changes /// /// Depth of slice public void UpdateStackY(int depth) { Map.UpdateStackY(depth); } /// /// Setting Filepath for Stack Z. /// /// File path for Stack Z public void SetFilepathZ(string path) { Map.StackZ.SetFilepath(path); } /// /// Get file path for stack Z. /// /// Stack Z filepath. public string GetFilepathZ() { return Map.StackZ.GetFilepath(); } /// /// Setting Filepath for Stack X /// /// File path for Stack X public void SetFilepathX(string path) { Map.StackX.SetFilepath(path); } /// /// Get file path for stack X. /// /// Stack X filepath. public string GetFilepathX() { return Map.StackX.GetFilepath(); } /// /// Setting Filepath for Stack Y /// /// File path for Stack Y public void SetFilepathY(string path) { Map.StackY.SetFilepath(path); } /// /// Get file path for stack Y. /// /// Stack Y filepath. public string GetFilepathY() { return Map.StackY.GetFilepath(); } /// /// Setting template for Z stack. Only used for Image Sequence. /// /// Template public void SetMapTemplateZ(string template) { Map.StackZ.Template = template; } /// /// Setting template for X stack. Only used for Image Sequence. /// /// Template public void SetMapTemplateX(string template) { Map.StackX.Template = template; } /// /// Setting template for Y stack. Only used for Image Sequence. /// /// Template public void SetMapTemplateY(string template) { Map.StackY.Template = template; } /// /// Sets sample relations according to the given filepath /// /// Filepath that all others are /// relative to public void SetSampleRelations(string relativeTo) { Map.SetMapRelation(relativeTo); AttDataList.SetAttachmentRelation(relativeTo); } /// /// Gets the Mark amount from specified dimension /// 1 = X depth, 2 = Y depth, 3 = Z depth /// TODO: use enum instead of an integer? /// /// /// public int[] GetMarkCount(int depth) { int[] markCount = System.Array.Empty(); switch (depth) { case 0: markCount = new int[Map.SlicesX]; break; case 1: markCount = new int[Map.SlicesY]; break; case 2: markCount = new int[Map.SlicesZ]; break; default: break; } if (markCount.Length == 0) return markCount; int[][] markCountAll = AttDataList.AttachementCount(Map.SlicesX, Map.SlicesY, Map.SlicesZ); for (int i = 0; i < markCount.Length; i++) { markCount[i] = markCountAll[depth][i]; } return markCount; } /// /// Setting the depth of Z. /// /// File path public void SetSlicesZ(string path) { switch (Map.MapType) { case Map.FileType.ImageSequence: Map.SlicesZ = MapReader.SequenceSlices(path, Map.StackZ.Template); break; case Map.FileType.Tiff3D: Map.SlicesZ = MapReader.ThreeDTifSlices(path); break; case Map.FileType.Raw: Map.SlicesZ = MapReader.RawSlices(path, Map.SlicesX, Map.SlicesY, Map.ByteDepth); break; default: break; } } /// /// Sets the Map file type as image sequence. /// public void SetImageSequence() { Map.MapType = Map.FileType.ImageSequence; } /// /// Sets the Map file type as multiframe tiff. /// public void SetTiff3D() { Map.MapType = Map.FileType.Tiff3D; } /// /// Sets the Map file type as Raw. /// public void SetRaw() { Map.MapType = Map.FileType.Raw; } /// /// Sets byte depth for Map. Used for Raw files. /// /// Byte depth. public void SetByteDepth(int byteDepth) { Map.ByteDepth = byteDepth; } /// /// Sets width of Map. /// /// Width of Map. public void SetMapWidth(int mapWidth) { Map.SlicesX = mapWidth; } /// /// Sets height for Map. /// /// Height of Map. public void SetMapHeight(int mapHeight) { Map.SlicesY = mapHeight; } /// /// Sets how many images the Map has in Z-axis. /// /// Number of images. public void SetMapDepth(int mapDepth) { Map.SlicesZ = mapDepth; } /// /// Sets little endian for Map. Used for Raw files. /// /// True if little endian, false if big endian. public void SetLittleEndian(bool littleEndian) { Map.LittleEndian = littleEndian; } /// /// Returns Attached Data list. /// /// Returns all attached datas public Attachments GetAttachements() { return AttDataList; } /// /// New Sample object. /// public Sample() { Map = new(); MetaList = new(); AttDataList = new(); } /// /// Search attachments that have specific Z coordinate. /// /// Z coordinate. /// List of Attachments. public List AttachmentsByZCoordinate(int z) { return AttDataList.AttByZCoordinate(z); } /// /// Search attachments that have specific X coordinate. /// /// X coordinate. /// List of Attachments. public List AttachmentsByXCoordinate(int x) { return AttDataList.AttByXCoordinate(x); } /// /// Search attachments that have specific Y coordinate. /// /// Y coordinate. /// List of Attachments. public List AttachmentsByYCoordinate(int y) { return AttDataList.AttByYCoordinate(y); } /// /// Search Attachment by name. /// /// Searched name. /// Attachment with specified name. public AttachedData GetAttachment(string name) { return AttDataList.GetAttachment(name); } /// /// Get Map's file type. /// /// File type extension of Map's file name. public string GetMapFileType() { return Map.GetMapFileType(); } /// /// Get Map's bit depth. /// /// Bit depth of map. public int GetBitDepth() { return Map.GetBitDepth(); } /// /// Get sample's filepath. /// /// Sample's filepath. public string GetFilepath() { return Filepath; } /// /// Adjust Level of Stack Z. /// /// Black point in percentage. /// White point in percentage. public void AdjustLevelZ(double blackPoint, double whitePoint) { Map.StackZ.AdjustLevel(blackPoint, whitePoint); } /// /// Adjust Level of Stack X. /// /// Black point in percentage. /// White point in percentage. public void AdjustLevelX(double blackPoint, double whitePoint) { Map.StackX.AdjustLevel(blackPoint, whitePoint); } /// /// Adjust Level of Stack Y. /// /// Black point in percentage. /// White point in percentage. public void AdjustLevelY(double blackPoint, double whitePoint) { Map.StackY.AdjustLevel(blackPoint, whitePoint); } /// /// Removes filepath, template and stack image from X stack. /// public void CleanXStack() { Map.StackX.Filepath = null; Map.StackX.Template = null; Map.StackX.Stack = null; } /// /// Removes filepath, template and stack image from Y stack. /// public void CleanYStack() { Map.StackY.Filepath = null; Map.StackY.Filepath = null; Map.StackY.Filepath = null; } } }