[Tizen.Multimedia] Fix XML Doc warnings
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Vision / MediaVision / ImageTrackingModel.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.IO;
19 using InteropModel = Interop.MediaVision.ImageTrackingModel;
20
21 namespace Tizen.Multimedia.Vision
22 {
23     /// <summary>
24     /// Represents the image tracking model interface.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class ImageTrackingModel : IDisposable
28     {
29         private IntPtr _handle = IntPtr.Zero;
30         private bool _disposed = false;
31
32         /// <summary>
33         /// Initializes a new instance of the <see cref="ImageTrackingModel"/> class.
34         /// </summary>
35         /// <exception cref="NotSupportedException">The feature is not supported.</exception>
36         /// <since_tizen> 3 </since_tizen>
37         public ImageTrackingModel()
38         {
39             InteropModel.Create(out _handle).Validate("Failed to create FaceTrackingModel");
40         }
41
42         /// <summary>
43         /// Initializes a new instance of the <see cref="ImageTrackingModel"/> class with the specified path.
44         /// </summary>
45         /// <remarks>
46         /// Model saved by <see cref="Save(string)"/> can be loaded.
47         /// </remarks>
48         /// <param name="modelPath">Path to the model to load.</param>
49         /// <exception cref="ArgumentNullException"><paramref name="modelPath"/> is null.</exception>
50         /// <exception cref="FileNotFoundException"><paramref name="modelPath"/> is invalid.</exception>
51         /// <exception cref="NotSupportedException">
52         ///     The feature is not supported.\n
53         ///     -or-\n
54         ///     <paramref name="modelPath"/> is not supported format.
55         /// </exception>
56         /// <exception cref="UnauthorizedAccessException">No permission to access the specified file.</exception>
57         /// <seealso cref="Save(string)"/>
58         /// <since_tizen> 3 </since_tizen>
59         public ImageTrackingModel(string modelPath)
60         {
61             if (modelPath == null)
62             {
63                 throw new ArgumentNullException(nameof(modelPath));
64             }
65             InteropModel.Load(modelPath, out _handle).Validate("Failed to load ImageTrackingModel from file");
66         }
67
68         /// <summary>
69         /// Finalizes an instance of the ImageTrackingModel class.
70         /// </summary>
71         ~ImageTrackingModel()
72         {
73             Dispose(false);
74         }
75
76         /// <summary>
77         /// Sets the target of the image tracking model.\n
78         /// Sets the image object which will be tracked by using tracking functionality with this tracking model.
79         /// </summary>
80         /// <param name="imageObject">Image object which will be set as the target for tracking.</param>
81         /// <exception cref="ArgumentNullException"><paramref name="imageObject"/> is null.</exception>
82         /// <exception cref="ObjectDisposedException">
83         ///     The <see cref="ImageTrackingModel"/> has already been disposed of.\n
84         ///     -or-\n
85         ///     <paramref name="imageObject"/> has already been disposed of.
86         /// </exception>
87         /// <since_tizen> 3 </since_tizen>
88         public void SetTarget(ImageObject imageObject)
89         {
90             if (imageObject == null)
91             {
92                 throw new ArgumentNullException(nameof(imageObject));
93             }
94
95             InteropModel.SetTarget(imageObject.Handle, Handle).
96                 Validate("Failed to set target of image tracking model");
97         }
98
99         /// <summary>
100         /// Refreshes the state of image tracking model.\n
101         /// Clears the moving history and change state to undetected. It is usually called each time before tracking is started
102         /// for the new sequence of sources, which is not the direct continuation of the sequence for which tracking has been performed before.
103         /// Tracking algorithm will try to find image by itself.
104         /// </summary>
105         /// <exception cref="ObjectDisposedException">The <see cref="ImageTrackingModel"/> has already been disposed of.</exception>
106         /// <since_tizen> 3 </since_tizen>
107         public void Refresh()
108         {
109             InteropModel.Refresh(Handle, IntPtr.Zero).Validate("Failed to refresh state");
110         }
111
112         /// <summary>
113         /// Saves the tracking model to the file.
114         /// </summary>
115         /// <param name="path">Path to the file to save the model.</param>
116         /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
117         /// <exception cref="UnauthorizedAccessException">No permission to write to the specified path.</exception>
118         /// <exception cref="ObjectDisposedException">The <see cref="ImageTrackingModel"/> has already been disposed of.</exception>
119         /// <exception cref="DirectoryNotFoundException">The directory for <paramref name="path"/> does not exist.</exception>
120         /// <since_tizen> 3 </since_tizen>
121         public void Save(string path)
122         {
123             if (path == null)
124             {
125                 throw new ArgumentNullException(path);
126             }
127
128             var ret = InteropModel.Save(path, Handle);
129
130             if (ret == MediaVisionError.InvalidPath)
131             {
132                 throw new DirectoryNotFoundException($"The directory for the path({path}) does not exist.");
133             }
134
135             ret.Validate("Failed to save tracking model to file");
136         }
137
138         /// <summary>
139         /// Releases all resources used by the <see cref="ImageTrackingModel"/> object.
140         /// </summary>
141         public void Dispose()
142         {
143             Dispose(true);
144             GC.SuppressFinalize(this);
145         }
146
147         /// <summary>
148         /// Releases the resources used by the <see cref="ImageTrackingModel"/> object.
149         /// </summary>
150         /// <param name="disposing">
151         /// true to release both managed and unmanaged resources; otherwise false to release only unmanaged resources.
152         /// </param>
153         protected virtual void Dispose(bool disposing)
154         {
155             if (_disposed)
156             {
157                 return;
158             }
159
160             InteropModel.Destroy(_handle);
161             _disposed = true;
162         }
163
164         internal IntPtr Handle
165         {
166             get
167             {
168                 if (_disposed)
169                 {
170                     throw new ObjectDisposedException(nameof(ImageTrackingModel));
171                 }
172                 return _handle;
173             }
174         }
175     }
176 }