IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
ModuleBase.cs
Go to the documentation of this file.
4
6
12public abstract class ModuleBase : IModule
13{
14 internal const string VersionKey = "Version";
15 internal const string EnabledKey = "Enabled";
16
20 public int Version { get; protected set; } = 1;
21
28 public virtual bool IsEnabled { get; set; } = true;
29
33 public abstract string TypeId { get; }
34
47 public virtual void Serialize(IArchive archive)
48 {
49 archive.SetBool(EnabledKey, IsEnabled);
50 archive.SetInt64(VersionKey, Version);
51 }
52
70 public virtual void Deserialize(IArchive archive)
71 {
72 var version = archive.GetInt64(VersionKey);
73 ValidateVersion(version, TypeId);
74 IsEnabled = archive.GetBool(EnabledKey);
75 }
76
78 public virtual object Process(object input)
79 {
80 if (input is not Image image)
81 {
83 $"Casting from {input.GetType().Name} to the given type {typeof(Image).Name} is not supported!");
84 }
85
86 return Process(image);
87 }
88
90 public virtual void ResetToDefault()
91 {
92 }
93
97 public abstract Image Process(Image inputImage);
98
99 internal void ValidateVersion(long version, string moduleName)
100 {
101 if (version < 1)
102 {
103 throw new IcvNotSupportedException(
104 $"The 'Version' entry {version} int the archive for " +
105 $"module {moduleName} is invalid! Must be at least 1.");
106 }
107 }
108}
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Definition Exception.cs:62
Base class for all pipeline modules.
Definition ModuleBase.cs:13
string TypeId
Gets the module type identifier used for serialization.
Definition ModuleBase.cs:33
virtual void ResetToDefault()
Resets the module to its default state.The enabled state is not reset.
Definition ModuleBase.cs:90
virtual object Process(object input)
Processes input data and returns the result.This function is called by the pipeline to process a unit...
Definition ModuleBase.cs:78
Image Process(Image inputImage)
Processes the image.
virtual void Deserialize(IArchive archive)
Restores the object's state from the provided archive.
Definition ModuleBase.cs:70
virtual void Serialize(IArchive archive)
Serializes the object's internal state into the provided archive.
Definition ModuleBase.cs:47
virtual bool IsEnabled
Get whether this module is enabled.
Definition ModuleBase.cs:28
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
Interface for a module used within a pipeline.
Definition IModule.cs:19
Represents a hierarchical, strongly-typed key-value archive.
Definition IArchive.cs:79
void SetBool(string key, bool value)
Stores a boolean value under the specified key.
long GetInt64(string key)
Retrieves a 64-bit integer value by key.
void SetInt64(string key, long value)
Stores a 64-bit integer value under the specified key.
bool GetBool(string key)
Retrieves a boolean value by key.