2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FBaseFloatMatrix.h
19 * @brief This is the header file for the %FloatMatrix class.
21 * This header file contains the declarations of the %FloatMatrix class.
24 #ifndef _FBASE_FLOAT_MATRIX_H_
25 #define _FBASE_FLOAT_MATRIX_H_
28 #include <FBaseTypes.h>
29 #include <FBaseObject.h>
31 namespace Tizen { namespace Base
35 * @brief This class encapsulates a two-dimensional matrix.
39 * The %FloatMatrix class provides a @c float precision, two-dimensional matrix.
42 class _OSP_EXPORT_ FloatMatrix
43 : public Tizen::Base::Object
47 * Copying of objects using this copy constructor is allowed.
51 * @param[in] rhs An instance of %FloatMatrix to copy
53 FloatMatrix(const FloatMatrix& rhs);
56 * Constructs a row by column null matrix in which all the elements are zero.
60 * @param[in] rowCount The number of rows in the current instance
61 * @param[in] columnCount The number of columns in the current instance
63 FloatMatrix(int rowCount, int columnCount);
66 * Constructs a row by column matrix initialized to the values in the specified array.
70 * @param[in] rowCount The number of rows in the current instance
71 * @param[in] columnCount The number of columns in the current instance
72 * @param[in] pArray The one-dimensional array @n
73 * The array must be at least row * column in length.
74 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
75 * else @c copy in column-major order
77 FloatMatrix(int rowCount, int columnCount, const float* pArray, bool rowMajor = true);
80 * Constructs a row by column matrix initialized to the values in the specified array.
84 * @param[in] rowCount The number of rows in the current instance
85 * @param[in] columnCount The number of columns in the current instance
86 * @param[in] pArray[] The two-dimensional array @n
87 * The array must be at least row * column in length.
89 FloatMatrix(int rowCount, int columnCount, const float* pArray[]);
92 * This destructor overrides Tizen::Base::Object::~Object().
96 virtual ~FloatMatrix(void);
99 * Checks whether the current instance and the specified instance of %FloatMatrix are equal.
103 * @return @c true if all the matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
105 * @param[in] rhs An instance of %FloatMatrix
107 bool operator ==(const FloatMatrix& rhs) const;
110 * Checks whether the current instance and the specified instance of %FloatMatrix are not equal.
114 * @return @c true if all the matrix members of the current instance are not equal to the corresponding matrix members in the specified instance, @n
116 * @param[in] rhs An instance of %FloatMatrix
118 bool operator !=(const FloatMatrix& rhs) const;
121 * Copying of objects using this copy assignment operator is allowed.
125 * @return A reference to this instance
126 * @param[in] rhs An instance of %FloatMatrix
127 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
129 * - The specific error code can be accessed using the GetLastResult() method.
130 * - If either the row or the column count of the current instance is not same as that of the specified instance,
131 * this method returns the reference to this instance without assigning.
133 FloatMatrix& operator =(const FloatMatrix& rhs);
136 * Checks whether the current instance of %FloatMatrix equals the specified instance of %FloatMatrix.
140 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
142 * @param[in] obj An instance of %FloatMatrix
144 * - This method overrides Tizen::Base::Object::Equals().
145 * - This method uses the values of the Matrix components to compare the two instances.
147 virtual bool Equals(const Tizen::Base::Object& obj) const;
150 * Gets the hash value of the current instance of %FloatMatrix.
154 * @return The hash value of the current instance
155 * @remarks Two equal instances must return the same hash value. @n
156 * For better performance, the used hash function must generate a random distribution for all the inputs.
158 virtual int GetHashCode(void) const;
161 * Adds the value of the specified instance to the current instance of %FloatMatrix.
165 * @return An error code
166 * @param[in] matrix An instance of %FloatMatrix
167 * @exception E_SUCCESS The method is successful.
168 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
170 result Add(const FloatMatrix& matrix);
173 * Adds the value to each matrix member of the current instance of %FloatMatrix.
177 * @param[in] value The @c float value to add
179 void AddToEachElement(float value);
182 * Gets the number of columns in the current instance of %FloatMatrix.
186 * @return The number of columns in the current instance
188 int GetColumnCount(void) const;
191 * Gets a new array that includes the values of the specified column in the current instance of %FloatMatrix.
195 * @return A pointer to the float array
196 * @param[in] columnIndex The target column number in the current instance
197 * @exception E_INVALID_ARG The specified @c columnIndex is larger than the column count of the current instance.
198 * @remarks The specific error code can be accessed using the GetLastResult() method.
200 float* GetColumnN(int columnIndex) const;
203 * Gets the determinant of the current instance of %FloatMatrix.
207 * @return The determinant value of the current instance
208 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
210 * - The specific error code can be accessed using the GetLastResult() method.
211 * - If the current instance is not a square matrix, it returns zero.
213 float GetDeterminant(void) const;
216 * Gets the value at the specified row and column of the current instance of %FloatMatrix.
220 * @return The value at the specified row and column of the current instance
221 * @param[in] rowIndex The target row number in the current instance
222 * @param[in] columnIndex The target column number in the current instance
223 * @exception E_INVALID_ARG The specified @c columnIndex or the specified @c rowIndex is larger than that of the current instance.
224 * @remarks The specific error code can be accessed using the GetLastResult() method.
226 float GetElement(int rowIndex, int columnIndex) const;
229 * Gets the inverse matrix of the current instance of %FloatMatrix.
233 * @return A pointer to the instance of %FloatMatrix that contains the resulting value of the operation
234 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
235 * @remarks The specific error code can be accessed using the GetLastResult() method.
237 FloatMatrix* GetInverseN(void) const;
240 * Gets the number of rows in the current instance of %FloatMatrix.
244 * @return The number of rows in the current instance
246 int GetRowCount(void) const;
249 * Gets a new array that includes the values of the specified row in the current instance of %FloatMatrix.
253 * @return A pointer to the @c float array
254 * @param[in] rowIndex The target row number in the current instance
255 * @exception E_INVALID_ARG The specified @c rowIndex is larger than the row count of the current instance.
256 * @remarks The specific error code can be accessed using the GetLastResult() method.
258 float* GetRowN(int rowIndex) const;
261 * Gets the trace of the current instance of %FloatMatrix.
265 * @return An error code
266 * @param[out] value The @c float value
267 * @exception E_SUCCESS The method is successful.
268 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
270 result GetTrace(float& value) const;
273 * Gets the transpose matrix of the current instance of %FloatMatrix.
277 * @return A pointer to the instance of %FloatMatrix that contains the resulting value of the operation
278 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
279 * @remarks The specific error code can be accessed using the GetLastResult() method.
281 FloatMatrix* GetTransposeN(void) const;
284 * Checks whether the current instance is an identity matrix.
288 * @return @c true if the matrix is an identity matrix, @n
291 bool IsIdentity(void) const;
294 * Checks whether the current matrix is invertible.
298 * @return @c true if the matrix is invertible, @n
301 bool IsInvertible(void) const;
304 * Multiplies the value of the specified instance with the current instance of %FloatMatrix.
308 * @return An error code
309 * @param[in] matrix An instance of %FloatMatrix
310 * @exception E_SUCCESS The method is successful.
311 * @exception E_INVALID_ARG The column count of the current instance is not same as the row count of the specified instance.
313 result Multiply(const FloatMatrix& matrix);
316 * Multiplies the value to each matrix member of the current instance of %FloatMatrix.
320 * @param[in] value The @c float value to multiply
322 void Multiply(float value);
325 * Negates the matrix members of the current instance of %FloatMatrix.
332 * Sets the value of the current instance of %FloatMatrix to its identity.
336 * @return An error code
337 * @exception E_SUCCESS The method is successful.
338 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
340 result SetAsIdentity(void);
343 * Sets the value of the current instance of %FloatMatrix to its inverse.
347 * @return An error code
348 * @exception E_SUCCESS The method is successful.
349 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
354 * Sets the value of the current instance of %FloatMatrix to its transpose.
358 * @return An error code
359 * @exception E_SUCCESS The method is successful.
360 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
362 result Transpose(void);
365 * Sets the values of the specified array to the specified column of the current instance of %FloatMatrix.
369 * @return An error code
370 * @param[in] columnIndex The target column number in the current instance
371 * @param[in] pArray The array which includes the values @n
372 * The array must be at least row in length.
373 * @exception E_SUCCESS The method is successful.
374 * @exception E_INVALID_ARG Either of the following conditions has occurred:
375 * - The specified @c pArray is @c null.
376 * - The specified @c columnIndex is larger than the column count of the current instance.
378 result SetColumn(int columnIndex, const float* pArray);
381 * Sets the values of the specified array to the specified row of the current instance of %FloatMatrix.
385 * @return An error code
386 * @param[in] rowIndex The target row number in the current instance
387 * @param[in] pArray The array which includes the values @n
388 * The array must be at least column in length.
389 * @exception E_SUCCESS The method is successful.
390 * @exception E_INVALID_ARG Either of the following conditions has occurred:
391 * - The specified @c pArray is @c null.
392 * - The specified @c rowIndex is larger than the row count of the current instance.
394 result SetRow(int rowIndex, const float* pArray);
397 * Sets the value to the specified row and column of the current instance of %FloatMatrix.
401 * @return An error code
402 * @param[in] rowIndex The target row number in the current instance
403 * @param[in] columnIndex The target column number in the current instance
404 * @param[in] value The @c float value
405 * @exception E_SUCCESS The method is successful.
406 * @exception E_INVALID_ARG Either of the following conditions has occurred:
407 * - The specified @c pArray is @c null.
408 * - The specified @c rowIndex is larger than the row count of the current instance.
409 * - The specified @c columnIndex is larger than the column count of the current instance.
411 result SetElement(int rowIndex, int columnIndex, float value);
414 * Sets the values to the current instance of %FloatMatrix in either the row-major or column-major order.
418 * @return An error code
419 * @param[in] pArray The one-dimensional array @n
420 * The array must be at least row * column in length.
421 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
422 * else @c false to copy in column-major order
423 * @exception E_SUCCESS The method is successful.
424 * @exception E_INVALID_ARG The specified @c pArray is @c null.
426 result SetValue(const float* pArray, bool rowMajor = true);
429 * Sets the matrix members of the current instance of %FloatMatrix to zero.
433 void SetAsNull(void);
436 * Subtracts the value of the specified instance from the current instance of %FloatMatrix.
440 * @return An error code
441 * @param[in] matrix An instance of %FloatMatrix
442 * @exception E_SUCCESS The method is successful.
443 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
445 result Subtract(const FloatMatrix& matrix);
448 * Subtracts the value from each matrix member of the current instance of %FloatMatrix.
452 * @param[in] value The @c float value to subtract
454 void SubtractToEachElement(float value);
458 * This default constructor is intentionally declared as private so that only the platform can create an instance.
464 bool AllocateCapacity(int rowCount, int columnCount);
465 void GetMinor(float** pSrc, float** pDest, int rowIndex, int columnIndex, int order) const;
466 float CalculateDeterminant(float** pMatrix, int order) const;
468 friend class _FloatMatrixImpl;
469 class _FloatMatrixImpl* __pImpl;
479 #endif //_FBASE_FLOAT_MATRIX_H_