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
cHyperplaneBodySimple.h
Go to the documentation of this file.
1 /**
2  * @file cHyperplaneBodySimple
3  * file name: cHyperplaneBodySimple.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  * This implementation of the hyperplane body is simple with just points,
33  * lines and hyperplanes of the maximal dimensionality. It is fast
34  * but it dosn't work correct on big bodies.
35  *
36  * Beware of the curse of dimensions! The complexity of the body will
37  * grow exponential with the number of dimensions. For example, just the
38  * number of border points of a newly created body will be 2^uiDimensions .
39  *
40  * @see cHyperplaneBody
41  * @see cHyperplane
42  * @see cInequation
43  */
44 /*
45 History:
46 28.01.2011 Oesterholz created
47 27.02.2011 Oesterholz method getNumberOfBorderPoints() added
48 03.04.2011 Oesterholz reimplemented with optimized algorithm
49 */
50 
51 #ifndef ___C_HYPERPLANE_BODY_SIMPLE_H__
52 #define ___C_HYPERPLANE_BODY_SIMPLE_H__
53 
54 
55 #include "version.h"
56 
57 #include "cHyperplaneBody.h"
58 
59 
60 #include <vector>
61 #include <set>
62 #include <list>
63 #include <ostream>
64 
65 
66 
67 using namespace std;
68 using namespace fib::algorithms::nLinearInequation;
69 
70 
71 namespace fib{
72 
73 namespace algorithms{
74 
75 namespace nDn{
76 
77 /**
78  * Namespace for helperclasses for the cHyperplaneBodySimple class.
79  */
80 namespace nHyperplaneBodySimple{
81 namespace nBorder{
82  //classes for the hyperplane
83 
84  template < class tFactors > class cInequationData;
85  template < class tFactors > class cLine;
86  template < class tFactors > class cPoint;
87 
88 
89  /**
90  * @class cHyperplaneData
91  * The data for a border hyperplane.
92  */
93  template <class tFactors> class cHyperplaneData{
94  public:
95 
96  /**
97  * The hyperplane, for which this data is.
98  * (It has d directions vectors.)
99  */
101 
102  /**
103  * A set with the pointers to the lines, which are contained
104  * in this hyperplane. (They have 1 direction vector.)
105  */
106  set< nBorder::cLine< tFactors > * > setContainedLines;
107 
108  /**
109  * If existing, a pointer to the inequiation which created this
110  * hyperplane.
111  */
113 
114  /**
115  * If existing, a pointer to the inequiation which has as the
116  * hyperplane this hyperplane.
117  */
119 
120  /**
121  * standard constructor
122  */
123  cHyperplaneData();
124 
125  /**
126  * parameter constructor
127  *
128  * @param inInequiation the inequiation from which to create the hyperplane
129  * @param uiDimensions the number of dimensions of the space for the hyperplane
130  */
132  unsigned int uiDimensions );
133 
134  /**
135  * destructor
136  */
137  ~cHyperplaneData();
138 
139  /**
140  * This method adds the given line (pointer) as a contained
141  * line. It will also add the pointer to this hyperplane as
142  * the containing hyperplane in the given line pContainedLine.
143  * @see setContainedLines
144  *
145  * @param pContainedLine a pointer to the line to add as
146  * the contained line
147  */
148  void addContainedLine( nBorder::cLine< tFactors > * pContainedLine );
149 
150 
151  };//cHyperplaneData
152 
153  /**
154  * @class cLine
155  * The data for a border line.
156  */
157  template <class tFactors> class cLine{
158  public:
159 
160  /**
161  * The hyperplane, for which this data is.
162  * (It has d directions vectors.)
163  */
165 
166  /**
167  * A set with the pointers to the points, which are contained
168  * in this line. (They have 0 direction vector.)
169  */
170  set< nBorder::cPoint< tFactors > * > setContainedPoints;
171 
172  /**
173  * A set with the pointers to the hyperplanes, which contain
174  * in this line.
175  */
176  set< nBorder::cHyperplaneData< tFactors > * > setContainingHyperplanes;
177 
178 
179  /**
180  * standard constructor
181  */
182  cLine();
183 
184  /**
185  * parameter constructor
186  *
187  * @param point1 a reference to the first point which creats this line
188  * @param point2 a reference to the second point which creats this line
189  */
191  nBorder::cPoint< tFactors > & point2 );
192 
193  /**
194  * destructor
195  */
196  ~cLine();
197 
198  /**
199  * This method adds the given point (pointer) as a contained
200  * point. It will also add the pointer to this line as
201  * the containing line in the given line pContainedPoint.
202  * @see setContainedPoints
203  *
204  * @param pContainedPoint a pointer to the point to add as
205  * the contained point
206  */
207  void addContainedPoint( nBorder::cPoint< tFactors > * pContainedPoint );
208 
209  };//cLine
210 
211  /**
212  * @class cPoint
213  * The data for a border point.
214  */
215  template <class tFactors> class cPoint{
216  public:
217 
218  /**
219  * A vector for the position of this point.
220  */
221  vector< tFactors > vecPointPosition;
222 
223  /**
224  * A set with the pointers to the hyperplanes, which contain
225  * in this line.
226  */
227  set< nBorder::cLine< tFactors > * > setContainingLines;
228 
229  /**
230  * parameter constructor
231  *
232  * @param inVecPointPosition a vector for the position of this point
233  */
234  cPoint( const vector< tFactors > & inVecPointPosition );
235 
236  /**
237  * destructor
238  */
239  ~cPoint();
240 
241  };//cPoint
242 
243 
244  /**
245  * @class cInequationData
246  * The data for a inequiation.
247  */
248  template <class tFactors> class cInequationData{
249  public:
250 
251  /**
252  * The inequiation, for which this data is.
253  */
255 
256  /**
257  * A pointer to the hyperplane which this inequiation has created.
258  */
260 
261 
262  /**
263  * standardconstructor
264  */
265  cInequationData();
266 
267  /**
268  * parameterconstructor
269  *
270  * @param inInequiation the inequiation for the inequiation data
271  * @param pInHyperplane the pointer to the hyperplane for the inequiation
272  */
273  cInequationData( const cInequation< tFactors > & inInequiation,
274  cHyperplaneData< tFactors > * pInHyperplane = NULL );
275 
276  /**
277  * destructor
278  */
279  ~cInequationData();
280 
281  };//cInequationData
282 
283 
284  /**
285  * Class to compare two cPoint classes via pointers to them.
286  * Compared are just the position vectors of the two given points.
287  */
288  template< class tFactors >
290  public:
291  bool operator() ( const cPoint< tFactors > * pPoint1,
292  const cPoint< tFactors > * pPoint2 ) const{
293 
294  return ( pPoint1->vecPointPosition < pPoint2->vecPointPosition );
295  }
296  };
297 
298 
299 };//nBorder
300 };//nHyperplaneBodySimple
301 
302 
303 using namespace nHyperplaneBodySimple;
304 
305 template <class tFactors>
306 class cHyperplaneBodySimple: public cHyperplaneBody< tFactors >{
307 protected:
308 
309  /**
310  * A set with the border hyperplanes of this body.
311  */
312  set< nBorder::cHyperplaneData< tFactors > * > setBorders;
313 
314  /**
315  * A set with the border lines of this body.
316  */
317  set< nBorder::cLine< tFactors > * > setBorderLines;
318 
319  /**
320  * A set with the border points of this body.
321  */
322  typedef set< nBorder::cPoint< tFactors > *, nBorder::cPointPositionPointerCompare< tFactors > >
325 
326  /**
327  * The list with the inequiations which constrain this body.
328  * (Ther are equivallent to the border hyperplanes, with the highest
329  * dimensionality.)
330  */
331  list< nBorder::cInequationData< tFactors > * > liInequiations;
332 
333 
334 public:
335  /**
336  * standard constructor
337  *
338  * @param uiInDimensions the dimensions of the space for the hyperbody;
339  * all added inequiations should have this much factors
340  * @see uiDimensions
341  * @param maxValue the maximum possible value in all directions
342  * the evalued hyperbody will allways inside a hypercubus of all
343  * vectors = (x_0,..., x_uiDimensions)^T, with
344  * -1 * maxValue <= x_i <= maxValue for 0 <= i <= uiDimensions
345  */
346  cHyperplaneBodySimple( unsigned int uiInDimensions,
347  const tFactors maxValue = 256 * 256 * 256 );
348 
349 
350  /**
351  * copy constructor
352  *
353  * @param hyperplaneBody the body to copy
354  */
356 
357  /**
358  * standard destructor
359  */
360  virtual ~cHyperplaneBodySimple();
361 
362  /**
363  * With this method the hyperplane body can be restricted by the given
364  * inequiation, if the inequiation dosn't remove the body.
365  * If ther are points in this hyperplane body exists wich fulfill the
366  * inequiation, an hyperplane for the inequiation is created and added
367  * to this hyperplane body.
368  *
369  * @see addInequiations()
370  * @see cInequation
371  * @see cInequation::cHyperplane( const cInequation & inequation )
372  *
373  * @return if true this body was restricted by the given inequiation,
374  * else the inequiation would remove this body
375  */
376  virtual bool addInequiation( const cInequation< tFactors > & inequiation );
377 
378 
379  /**
380  * @return the number of border points of the body
381  */
382  virtual unsigned long getNumberOfBorderPoints() const;
383 
384  /**
385  * @return a vector with the border points of the body
386  */
387  virtual vector< vector< tFactors > > getBorderPoints() const;
388 
389  /**
390  * This method checks if the given point is part of the hyperbody.
391  * If the point is on one of the borders of the hyperbody or inside it,
392  * it is part of the hyperbody.
393  *
394  * @param vecPoint the point to check
395  * @return true if the point vecPoint is part of the hyperbody, else false
396  */
397  virtual bool isPart( const vector< tFactors > & vecPoint ) const;
398 
399  /**
400  * This method print the hyperplane in a readebel form to the given
401  * output stream outputSream.
402  *
403  * @param outputSream the stream wher to print this inequation to
404  */
405  virtual void print( ostream & outputStream ) const;
406 
407  /**
408  * This method duplicates this whole hyperplane body.
409  *
410  * @return the cloned/ duplicates hyperplane body
411  */
412  virtual cHyperplaneBodySimple<tFactors> * clone() const;
413 
414 };
415 
416 
417 };//end namespace nDn
418 };//end namespace algorithms
419 };//end namespace fib
420 
421 //include template implementation
422 #include "../src/cHyperplaneBodySimple.cpp"
423 
424 
425 #endif //___C_HYPERPLANE_BODY_SIMPLE_H__