/// 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.Text.Json.Serialization; namespace CoreLibrary { /// /// Map class contains one map slice from each axel from specified depth /// public class Map { public Slice StackX { get; set; } public Slice StackY { get; set; } public Slice StackZ { get; set; } public int SlicesX { get; set; } public int SlicesY { get; set; } public int SlicesZ { get; set; } /// /// File type of Map /// public enum FileType { ImageSequence, Tiff3D, Raw } /// /// Axis of slice. /// public enum Axis { X, Y, Z } public FileType MapType { get; set; } public bool LittleEndian { get; set; } public int ByteDepth { get; set; } /// /// Constructor for JSON serialization and deserialization. Note that the /// parameter names must match the attribute names (non case sensitive) /// /// Stack in X-axel perspective /// Stack in Y-axel perspective /// Stack in Z-axel perspective /// Amount of slices in X stack /// Amount of slices in Y stack /// Amount of slices in Z stack /// Type of the map /// Is the raw file in little endian /// How many bytes reperesent 1 pixel in raw files [JsonConstructor] public Map(Slice stackx, Slice stacky, Slice stackz, int slicesx, int slicesy, int slicesz, FileType maptype, bool littleendian, int bytedepth) { StackX = stackx; StackY = stacky; StackZ = stackz; SlicesX = slicesx; SlicesY = slicesy; SlicesZ = slicesz; MapType = maptype; LittleEndian = littleendian; ByteDepth = bytedepth; } /// /// Constructor for Map. /// public Map() { StackX = new(); StackY = new(); StackZ = new(); } /// /// Returns width of Z stack. /// /// Width of Z stack images. public int GetZWidth() { return StackZ.Stack.Width; } /// /// Returns Z stack's height. /// /// Height of Z stack images. public int GetZHeigth() { return StackZ.Stack.Height; } /// /// Returns how many slices Z stack has. /// /// Amount of slices in stack Z. public int GetZDepth() { return SlicesZ; } /// /// Updates stack Z. /// /// New depth of stack. internal void UpdateStackZ(int depth) { UpdateStack(depth, SlicesX, SlicesY, StackZ); } /// /// Updates stack X. /// /// New depth of stack. internal void UpdateStackX(int depth) { UpdateStack(depth, SlicesZ, SlicesY, StackX); } /// /// Updates stack Y. /// /// New depth of stack. internal void UpdateStackY(int depth) { UpdateStack(depth, SlicesX, SlicesZ, StackY); } /// /// Updates specified slice accordingly. /// /// New depth of slice. /// Width of stack. /// Height of stack. /// Slice to be updated. internal void UpdateStack(int depth, int width, int height, Slice slice) { switch (MapType) { case FileType.ImageSequence: slice.UpdateImgSeq(depth); break; case FileType.Tiff3D: slice.Update3DTiff(depth); break; case FileType.Raw: slice.UpdateRaw(depth, width, height, ByteDepth, LittleEndian); break; default: break; } } /// /// Returns bit depth of Map. /// /// Map's bit depth. internal int GetBitDepth() { if (StackZ.Stack != null) return StackZ.Stack.Depth; else return 0; } /// /// Returns Map's file type extension from filepath. /// /// Map's file type. internal string GetMapFileType() { string path = StackZ.Filepath.GetPath(); return path[path.LastIndexOf(".")..]; } /// /// Sets filepaths to be in relation of given file /// /// Path that the the filepaths are relative to internal void SetMapRelation(string relativeTo) { if (StackX.Filepath != null) StackX.SetSliceRelation(relativeTo); if (StackY.Filepath != null) StackY.SetSliceRelation(relativeTo); if (StackZ.Filepath != null) StackZ.SetSliceRelation(relativeTo); } } }