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
cHyperplaneBodyFull.h
Go to the documentation of this file.
1 /**
2  * @file cHyperplaneBodyFull
3  * file name: cHyperplaneBodyFull.h
4  * @author Betti Oesterholz
5  * @date 28.01.2011
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This header specifies a class for a body with hyperplanes as its borders.
11  * @pattern strategy
12  *
13  * Copyright (C) @c GPL3 2010 Betti Oesterholz
14  *
15  * This program is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License (GPL) as
17  * published by the Free Software Foundation, either version 3 of the
18  * License, or any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27  *
28  *
29  * This header specifies a class for a body with hyperplanes as its borders.
30  * This body is defined by inequiations, all points wich fulfill the
31  * inequiations are part of the body.
32  * For the body all its hyperplane borders are stored and evalued.
33  *
34  * Beware of the curse of dimensions! The complexity of the body will
35  * grow exponential with the number of dimensions. For example, just the
36  * number of border points of a newly created body will be 2^uiDimensions .
37  *
38  * @see cHyperplaneBodyFull
39  * @see cHyperplane
40  * @see cInequation
41  */
42 /*
43 History:
44 28.01.2011 Oesterholz created
45 27.02.2011 Oesterholz method getNumberOfBorderPoints() added
46 */
47 
48 #ifndef ___C_HYPERPLANE_BODY_FULL_H__
49 #define ___C_HYPERPLANE_BODY_FULL_H__
50 
51 
52 #include "version.h"
53 
54 #include "cHyperplaneBody.h"
55 
56 #include <vector>
57 #include <set>
58 #include <list>
59 #include <ostream>
60 
61 
62 
63 
64 namespace fib{
65 
66 namespace algorithms{
67 
68 namespace nDn{
69 
70 /**
71  * Namespace for helperclasses for the cHyperplaneBodyFull class.
72  */
73 namespace nHyperplaneBodyFull{
74  //classes for the hyperplane
75 
76  template < class tFactors > class cInequationData;
77 
78 
79  /**
80  * @class cHyperplaneData
81  * The data for a hyperplane.
82  */
83  template <class tFactors> class cHyperplaneData{
84  public:
85  friend class cHyperplaneBodyFull;
86 
87  /**
88  * The typs for the list with hyperplane references.
89  */
90  typedef set< cHyperplaneData< tFactors > * > typeSetPHyperplanes;
91 
92  typedef typename typeSetPHyperplanes::iterator typeItrSetPHyperplanes;
93 
94  /**
95  * A list with the pointers to the point, which are contained
96  * directly or indirectly in this hyperplane. (They have 0 direction
97  * vectors.)
98  * This is for faster evaluation of @see isPart()
99  * @see bUpdateContainedPoints and @see setContainingBorders
100  */
102 
103  /**
104  * A list with the pointers to the hyperplanes borders, which contain directly or
105  * indirectly in this hyperplane. (They are not contained in any
106  * other hyperplane.)
107  * This is for faster evaluation of @see isPart()
108  * @see bUpdateContainedPoints and @see setContainedPoints
109  */
111 
112  /**
113  * This boolean indicates if the setContainedPoints should be updated.
114  * If false setContainedPoints contains all point hyperplanes, wich are
115  * directly or indirectly contained in this hyperplane.
116  * @see setContainedPoints and @see setContainingBorders
117  */
119 
120  public:
121 
122  /**
123  * The hyperplane, for which this data is.
124  * (It has d directions vectors.)
125  */
127 
128  /**
129  * A list with the pointers to the hyperplanes, which contain
130  * directly this hyperplane. (They have d + 1 direction vectors.)
131  */
133 
134  /**
135  * A list with the pointers to the hyperplanes, which are directly
136  * contained in this hyperplane. (They have d - 1 direction vectors.)
137  */
139 
140  /**
141  * If existing, a pointer to the inequiation which created this
142  * hyperplane.
143  */
145 
146 
147  /**
148  * standard constructor
149  */
150  cHyperplaneData();
151 
152  /**
153  * parameter constructor
154  *
155  * @param inInequiation the inequiation from which to create the hyperplane
156  * @param uiDimensions the number of dimensions of the space for the hyperplane
157  */
159  unsigned int uiDimensions );
160 
161  /**
162  * destructor
163  */
165 
166  /**
167  * This method adds the given hyperplane (pointer) as a contained
168  * hyperplane. It will also add the pointer to this hyperplane as
169  * the containing hyperplane in the given hyperplane
170  * pContainedHyperplane.
171  * @see setContainedHyperplanes and @see setContainingHyperplanes
172  *
173  * @param pContainedHyperplane a pointer to the hyperplane to add as
174  * the contained hyperplane
175  */
176  void addContainedHyperplane( cHyperplaneData< tFactors > * pContainedHyperplane );
177 
178  /**
179  * @return if the given hyperplane is part of this hyperplane true,
180  * else false; @see setContainedHyperplanes
181  */
182  bool isPart( const cHyperplaneData< tFactors > * pHyperplane );
183 
184  };//cHyperplaneData
185 
186 
187 
188  /**
189  * @class cInequationData
190  * The data for a inequiation.
191  */
192  template <class tFactors> class cInequationData{
193  public:
194 
195  /**
196  * The inequiation, for which this data is.
197  */
199 
200  /**
201  * A pointer to the hyperplane which this inequiation has created.
202  */
204 
205 
206  /**
207  * standardconstructor
208  */
209  cInequationData();
210 
211  /**
212  * parameterconstructor
213  *
214  * @param inInequiation the inequiation for the inequiation data
215  * @param pInHyperplane the pointer to the hyperplane for the inequiation
216  */
217  cInequationData( const cInequation< tFactors > & inInequiation,
218  cHyperplaneData< tFactors > * pInHyperplane = NULL );
219 
220  /**
221  * destructor
222  */
224 
225  };//cInequationData
226 
227 
228  /**
229  * This function compares vectors correspondending to the number
230  * associated with them.
231  *
232  * @param paFirst the first pair to compare
233  * @param paSecond the second pair to compare
234  * @return true if the first element of the first pair is lower than
235  * the second, else false
236  */
237  template <class tFactors>
238  bool sortLowerFirst( const pair< unsigned int, vector< tFactors > > & paFirst,
239  const pair< unsigned int, vector< tFactors > > & paSecond );
240 
241 
242 };//nHyperplaneBodyFull
243 
244 
245 using namespace nHyperplaneBodyFull;
246 
247 template <class tFactors>
248 class cHyperplaneBodyFull: public cHyperplaneBody< tFactors >{
249 protected:
250 
251  /**
252  * A vector with the borders of this body.
253  * The index of the vector is the dimensionality of the borders of the
254  * list to the vectorelement. (e. g. vecBorders[0] contains the
255  * borderpoints of the body)
256  */
257  vector< list< cHyperplaneData< tFactors > * > > vecBorders;
258 
259  /**
260  * The list with the inequiations which constrain this body.
261  * (Ther are equivallent to the border hyperplanes, with the highest
262  * dimensionality.)
263  */
264  list< cInequationData< tFactors > * > liInequiations;
265 
266 
267 public:
268  /**
269  * standard constructor
270  *
271  * @param uiInDimensions the dimensions of the space for the hyperbody;
272  * all added inequiations should have this much factors
273  * @see uiDimensions
274  * @param maxValue the maximum possible value in all directions
275  * the evalued hyperbody will allways inside a hypercubus of all
276  * vectors = (x_0,..., x_uiDimensions)^T, with
277  * -1 * maxValue <= x_i <= maxValue for 0 <= i <= uiDimensions
278  */
279  cHyperplaneBodyFull( unsigned int uiInDimensions,
280  const tFactors maxValue = 1E+36 );
281 
282 
283  /**
284  * copy constructor
285  *
286  * @param hyperplaneBody the body to copy
287  */
288  cHyperplaneBodyFull( const cHyperplaneBodyFull< tFactors > & hyperplaneBody );
289 
290  /**
291  * standard destructor
292  */
293  virtual ~cHyperplaneBodyFull();
294 
295  /**
296  * With this method the hyperplane body can be restricted by the given
297  * inequiation, if the inequiation dosn't remove the body.
298  * If ther are points in this hyperplane body exists wich fulfill the
299  * inequiation, an hyperplane for the inequiation is created and added
300  * to this hyperplane body.
301  *
302  * @see addInequiations()
303  * @see cInequation
304  * @see cInequation::cHyperplane( const cInequation & inequation )
305  *
306  * @return if true this body was restricted by the given inequiation,
307  * else the inequiation would remove this body
308  */
309  virtual bool addInequiation( const cInequation< tFactors > & inequiation );
310 
311  /**
312  * @return the number of border points of the body
313  */
314  virtual unsigned long getNumberOfBorderPoints() const;
315 
316  /**
317  * @return a vector with the border points of the body
318  */
319  virtual vector< vector< tFactors > > getBorderPoints() const;
320 
321  /**
322  * This method checks if the given point is part of the hyperbody.
323  * If the point is on one of the borders of the hyperbody or inside it,
324  * it is part of the hyperbody.
325  *
326  * @param vecPoint the point to check
327  * @return true if the point vecPoint is part of the hyperbody, else false
328  */
329  virtual bool isPart( const vector< tFactors > & vecPoint ) const;
330 
331  /**
332  * This method print the hyperplane in a readebel form to the given
333  * output stream outputSream.
334  *
335  * @param outputSream the stream wher to print this inequation to
336  */
337  virtual void print( ostream & outputStream ) const;
338 
339  /**
340  * This method duplicates this whole hyperplane body.
341  *
342  * @return the cloned/ duplicates hyperplane body
343  */
344  virtual cHyperplaneBodyFull<tFactors> * clone() const;
345 
346 protected:
347 
348  /**
349  * This method evalues and inserts the intersections for the given
350  * hyperplanes liHyperplanes into this body.
351  * The hyperplanes of liHyperplanes should be allready in this body.
352  * The hyperplanes of liHyperplanes should also have the same
353  * dimensionality (number of directions) uiDimensionality.
354  * The containing hyperplanes of the hyperplanes in liHyperplanes, should
355  * be allready evalued.
356  *
357  * @param liHyperplanes the list with the hyperplanes, for which to evalue
358  * the intersections with this body
359  * @param uiDimensionality the dimensionality (number of directions) of
360  * the hyperplanes in liHyperplanes;
361  * because the containing hyperplanes of the liHyperplanes should be
362  * allready evalued, it should be uiDimensionality <= iDimensions - 2
363  * @return a list with the pointers of the new created intersection hyperplanes
364  */
365  list< cHyperplaneData< tFactors > * > addIntersectionsFor(
366  list< cHyperplaneData< tFactors > * > & liHyperplanes,
367  const unsigned int uiDimensionality );
368 };
369 
370 
371 };//end namespace nDn
372 };//end namespace algorithms
373 };//end namespace fib
374 
375 //include template implementation
376 #include "../src/cHyperplaneBodyFull.cpp"
377 
378 
379 #endif //___C_HYPERPLANE_BODY_FULL_H__