The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cHyperplane.h
Go to the documentation of this file.
1 /**
2  * @file cHyperplane
3  * file name: cHyperplane.h
4  * @author Betti Oesterholz
5  * @date 31.12.2010
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This header specifies a class for a hyperplane.
11  * Copyright (C) @c GPL3 2010 Betti Oesterholz
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License (GPL) as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  *
26  *
27  * This class represents an hyperplane.
28  * It is represented in the form:
29  * Y = B + D_1 * x_1 + D_2 * x_2 + ... + D_d * x_d
30  * - Y is the output vector
31  * - B point on the hyperplane as the base vector
32  * - D_i are the (independent) hyperplane direction vectors
33  * - x_i are the scalar input factors
34  * - d is the dimensionality of the hyperplane
35  *
36  * Of this formular only the direction vectors D_i and the base vector B
37  * are stored in this class.
38  *
39  */
40 /*
41 History:
42 31.12.2010 Oesterholz created
43 */
44 
45 #ifndef ___C_HYPERPLANE_H__
46 #define ___C_HYPERPLANE_H__
47 
48 #include "version.h"
49 
50 #include "cInequation.h"
51 
52 #include <vector>
53 #include <ostream>
54 
55 using namespace std;
56 
57 
58 namespace fib{
59 
60 namespace algorithms{
61 
62 namespace nDn{
63 
64 
65 template <class tFactors>
67 protected:
68 
69  /**
70  * The type for the direction vectors.
71  * @see vecDirections
72  */
73  typedef vector< vector< tFactors > > typeDirection;
74 
75  /**
76  * The type for iterators for the direction vectors.
77  * @see typeDirection
78  * @see vecDirections
79  */
80  typedef typename typeDirection::iterator typeItrDirection;
81 
82  /**
83  * The type for const iterators for the direction vectors.
84  * @see typeDirection
85  * @see vecDirections
86  */
87  typedef typename typeDirection::const_iterator typeConstItrDirection;
88 
89  /**
90  * A point on the hyperplane as the base vector (B).
91  */
92  vector< tFactors > vecBase;
93 
94  /**
95  * The (independent) direction vectors (D_i) for the hyperplane.
96  */
98 
99  /**
100  * This type specifies how much the hyperplane fills of the dimensions.
101  *
102  * Values:
103  * - ALL: the hyperplane fills the whool space
104  * - NONE: the hyperplane fills nothing of the space (it didn't exists)
105  * - SOME: the hyperplane fills some of the space
106  */
107  enum typeFillType{ ALL, NONE, SOME };
108 
109  /**
110  * This object specifies how much the hyperplane fills of the dimensions.
111  * @see typeFillType
112  */
114 
115 
116  /**
117  * The directions of this hyperplane are linear independent.
118  */
120 
121  /**
122  * The the hyperplane is in form One.
123  * Form One is a special hyperplane form, wich is uniqe and simpler to handle.
124  * Hyperplane form: Y = B + D_1 * x_1 + D_2 * x_2 + ... + D_d * x_d
125  * In form One:
126  * - B point on the hyperplane as the base vector, with |B| minimal
127  * - D_i are the independent hyperplane direction vectors
128  * D_i = ( h_i.1, ..., h_i.{o_i}, ..., h_i.d )^T
129  * with h_i.1= ...= h_i.o_i - 1} = 0, h_i.{o_i} = 1 and
130  * o_{i-1} < o_i, for 1 < i (o_{i-1} is for D_{i-1} )
131  */
133 
134 public:
135 
136  /**
137  * standardconstructor
138  */
139  cHyperplane();
140 
141  /**
142  * parameterconstructor
143  *
144  * @param vecInBase the base vector (B) for the hyperplane @see vecBase
145  * @param vecInDirections the direction vectors (D_i) for the
146  * hyperplane @see vecDirections
147  */
148  cHyperplane( const vector< tFactors > & vecInBase,
149  const vector< vector< tFactors > > & vecInDirections );
150 
151  /**
152  * parameterconstructor
153  * The number of dimensions will be the number of factors in the
154  * inequation.
155  *
156  * @param inequation the inequiation which defines this hyperplane;
157  * if the inequal sign of the inequation would be replaced by an
158  * equal sign, all points which fulfill the equiation are on the
159  * hyperplane
160  */
162 
163  /**
164  * parameterconstructor
165  *
166  * @param inequation the inequiation which defines this hyperplane;
167  * if the inequal sign of the inequation would be replaced by an
168  * equal sign, all points which fulfill the equiation are on the
169  * hyperplane
170  * @param uiNumberOfDimensions the number of dimensions the hyperplane
171  * should be placed in
172  */
174  unsigned int uiNumberOfDimensions );
175 
176  /**
177  * @return the base of this hyperplane (@see vecBase)
178  */
179  vector< tFactors > getBase() const;
180 
181  /**
182  * This method sets the base of this hyperplane to the given vecInBase.
183  * @see vecBase
184  *
185  * @param vecInBase the base this hyperplane should have
186  */
187  void setBase( const vector< tFactors > & vecInBase );
188 
189  /**
190  * This method returns the uiDirection'th direction vector of this hyperplane.
191  * @see vecDirections
192  *
193  * @param uiDirection the number of the direction vector to return
194  * (counting begins with 1)
195  * @return the uiDirection'th direction vector of this hyperplane or
196  * a vector with no elements, if no such direction exists
197  */
198  vector< tFactors > getDirection( const unsigned int uiDirection ) const;
199 
200  /**
201  * @return a vector with all direction vectors of this hyperplane
202  * (@see vecDirections)
203  */
204  vector< vector< tFactors > > getDirections() const;
205 
206  /**
207  * @return the number of direction vectors of this hyperplane
208  * (@see vecDirections); if the direction vectors are linear
209  * independent the returned value is also the dimensionality of
210  * this hyperplane
211  */
212  unsigned int getNumberOfDirections() const;
213 
214  /**
215  * This method adds the given direction vector vecInDirection to this
216  * hyperplane.
217  * @see vecDirections
218  *
219  * @param vecInDirection the direction vector to add
220  * @return true if the direction was added else false
221  */
222  bool addDirection( const vector< tFactors > & vecInDirection );
223 
224  /**
225  * This method adds the given direction vectors vecInDirections to this
226  * hyperplane.
227  * @see vecDirections
228  *
229  * @param vecInDirections the direction vectors to add
230  * @return the number of inserted direction vectors
231  */
232  unsigned int addDirections( vector< vector< tFactors > > vecInDirections );
233 
234  /**
235  * This method deletes the uiDirection'th direction vector of this hyperplane.
236  * @see vecDirections
237  *
238  * @param uiDirection the number of the direction vector to delete
239  * (counting begins with 1)
240  * @return true if the uiDirection'th direction vector of this hyperplane
241  * was deleted, else false
242  */
243  bool deleteDirection( unsigned int uiDirection );
244 
245  /**
246  * @return the number of dimensions this hyperplane is contained in
247  * (@see vecDirections, @see vecBase);
248  * the number of dimensions of this hyperplane are the numbers of elements
249  * in its vectors
250  */
251  unsigned int getNumberOfDimensions() const;
252 
253  /**
254  * This method sets the number of dimensions this hyperplane is contained in.
255  * (@see vecDirections, @see vecBase);
256  * The number of dimensions of this hyperplane are the numbers of elements in
257  * its vectors.
258  *
259  * @param uiDimensionality the number of dimensions of this hyperplane
260  * @return the number of dimensions of this hyperplane
261  */
262  unsigned int setNumberOfDimensions( unsigned int uiDimensionality );
263 
264  /**
265  * This method will remove all not independent vectors from the
266  * direction vectors (a_i). So that the remaining direction vectors
267  * are linear undependent.
268  */
269  void makeDirectionsIndependent();
270 
271  /**
272  * This method will convert the given hyperplane into the form One form.
273  * Form One is a special hyperplane form, wich is uniqe and simpler to handle.
274  * Hyperplane form: Y = B + D_1 * x_1 + D_2 * x_2 + ... + D_d * x_d
275  * In form One:
276  * - B point on the hyperplane as the base vector, with |B| minimal
277  * - D_i are the independent hyperplane direction vectors
278  * D_i = ( h_i.1, ..., h_i.{o_i}, ..., h_i.d )^T
279  * with h_i.1= ...= h_i.o_i - 1} = 0, h_i.{o_i} = 1 and
280  * o_{i-1} < o_i, for 1 < i (o_{i-1} is for D_{i-1} )
281  */
282  void convertToFormOne();
283 
284  /**
285  * This method evalues the intersection of the given hyperplane with
286  * this hyperplan.
287  * If no intersection exists NULL is returned.
288  * Attention: You have to care, that the returned object is deleted.
289  *
290  * @param hyperplane the hyperplane, with wich this hyperplane should
291  * be intersected
292  * @return the intersection hyperplane of this and the given hyperplane
293  * or NULL, if no intersection exists
294  */
295  cHyperplane< tFactors > * evalueIntersection(
296  const cHyperplane< tFactors > & hyperplane ) const;
297 
298  /**
299  * This method checks if this hyperplane is equal to the given
300  * hyperplane.
301  * Two hyperplanes are equal, if thy contain the same points.
302  *
303  * @param hyperplane the hyperplane , for wich to check if its equal to
304  * this hyperplane
305  * @return true if the given hyperplane is equal to this hyperplane
306  * else false
307  */
308  bool equal( const cHyperplane< tFactors > & hyperplane ) const;
309 
310 
311  /**
312  * This method print the hyperplane in a readebel form to the given
313  * output stream outputSream.
314  *
315  * @param outputSream the stream wher to print this inequation to
316  */
317  void print( ostream & outputStream ) const;
318 
319 protected:
320 
321 
322  /**
323  * This functions compares two vectors of vectors with double numbers.
324  * Realy small differences betwean the vector element numbers will be ignored.
325  *
326  * @param vector1 the first vector of vectors to compare
327  * @param vector2 the second vector of vectors to compare
328  * @return true if the first vector of vectors is equal to the second, else false
329  */
330  bool compareVectorVectorDouble( const vector< vector< tFactors > > & vector1,
331  const vector< vector< tFactors > > & vector2 ) const;
332 
333  /**
334  * This method recreates this hyperplane from the given inequation.
335  *
336  * @param inequation the inequiation which defines this hyperplane;
337  * if the inequal sign of the inequation would be replaced by an
338  * equal sign, all points which fulfill the equiation are on the
339  * hyperplane
340  * @param uiInNumberOfDimensions the number of dimensions the hyperplane
341  * should be placed in
342  */
343  bool createHyperplaneFromInequiation(
345  unsigned int uiInNumberOfDimensions );
346 };//class cHyperplane
347 
348 
349 };//end namespace nDn
350 };//end namespace algorithms
351 };//end namespace fib
352 
353 //include template implementation
354 #include "../src/cHyperplane.cpp"
355 
356 
357 #endif //___C_HYPERPLANE_H__