Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ContourBSplineData.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __BIAS_CONTOURBSPLINEDATA_HH_
26 #define __BIAS_CONTOURBSPLINEDATA_HH_
27 
28 
29 #include <list>
30 #include <vector>
31 
32 #include <Base/Debug/Debug.hh>
33 #include <Base/Math/Polynom.hh>
34 #include <Base/Math/Matrix.hh>
35 #include <Base/Math/Vector.hh>
36 
37 #include "ContourBSplineType.hh"
38 
39 #define D_CONTOURBSPLINEMATH_DEBUG 1<<0
40 #define D_CONTOURBSPLINEMATH_REGISTER 1<<1
41 #define D_CONTOURBSPLINEMATH_SPAN 1<<2
42 #define D_CONTOURBSPLINEMATH_PLACEMENT 1<<3
43 
44 namespace BIAS{
45  /**
46  @class ContourBSplineData
47  @brief data object which holds all infomations of a B-Spline curve
48  (ContourBSpline); its shared by B-Spline curves with same basis.
49 
50  Objects of this class save informations of a B-Spline curve
51  (ContourBSpline). If two or more ContourBSpline objects are initialised
52  with the same order, type and multiplicity vector, then they share the
53  same ContourBSplineData object.
54  (Attention: shape-space and regularisation matrices are handled by
55  class ContourBSplineShapeMatrix.)
56 
57  A ContourBSplineData object is created/registered transparently by a
58  call of a ContourBSpline objects Init(...) or Load(...) function.
59  These functions call Register(...) of this class. The Register(...)
60  function looks if it allready has the right data object. If yes, it
61  registers the ContourBSpline object by incrementing the reference counter
62  of the data object and returns the pointer to the data object. If not,
63  it uses the input parameter to create a new data object.
64  Details of creation process are documented in book "Active Contours",
65  mainly in appendix A.
66 
67  If a ContourBSpline objects gets destroyed it calls the Unregister
68  function of ContourBSplineData object. The reference counter gets
69  decremented and the data object destroyed if the reference counter is
70  zero.
71  @ingroup g_feature
72  */
74  friend class ContourBSpline;
76  public:
77  //! @brief empty standard constructor
79 
80  //! @brief destructor
82  Unregister();
83  };
84 
85  /**
86  * @brief decrements reference counter to this data object and deletes
87  * it if there is no reference to it
88  *
89  * This function is transparently called by the destructor of a
90  * ContourBSpline object.
91  */
92  inline void Unregister();
93 
94  /**
95  * @brief registers a ContourBSpline object and returns pointer to its
96  * data object
97  * @param[in] order order of B-Spline curve
98  * @param[in] bType type of B-Spline curve (Open or Closed)
99  * @param[in] mPnts vector of multiplicities (holds information in which
100  * control points edges are modelled
101  *
102  * This function is transparently called by the Init(...) function of
103  * a ContourBSpline object.
104  *
105  * Looks up if there is already a data object that fits to the calling
106  * ContourBSpline object. If yes, it returns the pointer to this
107  * ContourBSplineData object and inkrements the reference counter of the
108  * data object. If not, a new ContourBSplineData object gets created.
109  *
110  * Generation includes class variables:
111  * order (copy)
112  * bType (copy)
113  * mPnts (copy)
114  * numBasePolynoms (equal to number of control points (length of mPnts))
115  * dependent on type of BSplineCurve (handled by specific helper
116  * functions):
117  * splineMetricMatrix_ //see "Active Contours" chapter 3
118  * splineMetricMatrixParametric_
119  * areaCoefficientMatrix_ //confer to "Active Contours" chapter 3
120  * //not used for further computation at moment
121  *
122  */
123  static ContourBSplineData* Register(const unsigned int order,
124  const ContourBSplineType::Type bType,
125  const std::vector<unsigned int>& mPnts);
126 
127  /**
128  * @brief registers a clustered ContourBSpline object and returns pointer
129  * to its data object
130  * @param[in] bSplinesData vector of data objects from B-Spline curves
131  * which get clustered into one data object
132  *
133  * This function is transparently called by the Cluster(...) function of
134  * class ContourBSpline.
135  *
136  * Data object is build on basis of given B-Spline curves data objects.
137  *
138  * There is no lookup if a data object already exist. When you cluster
139  * some B-Spline curves and want a copy of the clustered curve, use
140  * operator=.
141  *
142  */
144  const std::vector<ContourBSplineData*>& bSplinesData);
145 
146  //using this for loading a clustered bspline
147  /**
148  * @brief registers a clustered ContourBSpline object and returns pointer
149  * to its data object
150  * @param[in] order order of clustered B-Spline curve
151  * @param[in] bType Type of curve (Cluster)
152  * @param[in] mPnts multiplicity vector of curve (determines in which
153  * control points edges are modelled)
154  * @param[in] numBasePolynoms number of basepolynomes of the curve
155  * (equal to number of control points)
156  * @param[in] numSpans number of spans of curve
157  * @param[in] numSpansVec vector seperates numSpans of seperate curves in
158  * cluster
159  * @param[in] placedSpanMatrices vector of all placed span-matrices of
160  * curve (see "Active Contours" appendix A)
161  *
162  * This funcion is called transparently by Load(...) function of class
163  * ContourBSpline.
164  *
165  * There is no lookup if a data object already exist. When you cluster
166  * some B-Spline curves and want a copy of the clustered curve, use
167  * operator=.
168  *
169  */
170  static ContourBSplineData* Register(const unsigned int order,
171  const ContourBSplineType::Type bType,
172  const std::vector<unsigned int>& mPnts,
173  const unsigned int numBasePolynoms,
174  const unsigned int numSpans,
175  const std::vector<unsigned int>& numSpansVec,
176  const std::vector<BIAS::Matrix<double> >&placedSpanMatrices);
177 
178  public:
179  /**
180  * @brief looks up if a ContourBSplineData object with the initial given
181  * parameter exist and returns pointer to it or NULL
182  * @param[in] order order of B-Spline curve
183  * @param[in] bType type of B-Spline curve (Open or Closed)
184  * @param[in] mPnts multiplicity vector of curve (determines in which
185  * control points edges are modelled
186  *
187  */
188  static ContourBSplineData* LookUpData_(const unsigned int order,
189  const ContourBSplineType::Type bType,
190  const std::vector<unsigned int>& mPnts);
191 
192  /**
193  * @brief inits class variables for a closed B-Spline curve
194  *
195  * computes:
196  * numSpans_ //number of spans of curve
197  * placedSpanMatrices //placed span matrices - see "Active Contours"
198  * //appendix A, p.292
199  * splineMetricMatrix_ //see "Active Contours" chapter 3
200  * splineMetricMatrixParametric_
201  * areaCoefficientMatrix_ //confer to "Active Contours" chapter 3
202  * //not used for further computation at moment
203  *
204  */
206 
207  /**
208  * @brief inits class variables for an open B-Spline curve
209  *
210  * computes:
211  * numSpans_ //number of spans of curve
212  * placedSpanMatrices //placed span matrices - see "Active Contours"
213  * //appendix A, p.292
214  * splineMetricMatrix_ //see "Active Contours" chapter 3
215  * splineMetricMatrixParametric_
216  * areaCoefficientMatrix_ //confer to "Active Contours" chapter 3
217  * //not used for further computation at moment
218  *
219  */
221 
222  /**
223  * @brief recursivly computes one base polynom for a span matrix
224  *
225  * @param[in] span index of span which includes base polynom
226  * @param[in] knotIndex index of first knot of base polynom
227  * @param[in] order order of B-Spline curve
228  * @param[in] breakpoints vector of knot values
229  *
230  * Confer to "Active Contours" appendix A p.291 for details.
231  *
232  */
233  BIAS::Polynom ComputeBasePolynomRecursive_(const unsigned int span,
234  const unsigned int knotIndex,
235  const unsigned int order,
236  const std::vector<int>& breakpoints);
237 
238  /**
239  * @brief computes the span matrix of a B-Spline curves span
240  * @param[in] span index of span whose matrix should be computed
241  * @param[in] placeOff offset used in periodic case for index of first
242  * knot of a span
243  * @param[in] kMult vector of multiplicities of knots
244  * @param[in] k vector of knots values (plain)
245  *
246  * Confer to "Active Contours" appendix A p.291 for details.
247  *
248  */
249  void ComputeSpan_(const unsigned int span,
250  const int placeOff,
251  const std::vector<unsigned int>& kMult,
252  const std::vector<int>& k);
253 
254  /**
255  * @brief computes the metric matrix (scriptB) of the B-Spline curve
256  *
257  * Confer to "Active Contours" chapter 3, p.50f; appendix A, p.293 for
258  * details.
259  *
260  */
262 
263  /**
264  * @brief computes the metrix matrix (I^2 x scriptB) of the B-Spline
265  * curve
266  *
267  * Confer to "Active Contours" chapter 3, p.59; appendix A, p.293 for
268  * details.
269  *
270  */
272 
273  /**
274  * @brief computes the area coefficient matrix of the B-Spline curve
275  *
276  * Confer to "Active Contours" chapter 3, p.65; appendix A, p.293 for
277  * details.
278  *
279  */
281 
282 
283  //class variables
284 
285 
286  //! list of all pointers to ContourBSplineData objects
287  static std::list<ContourBSplineData*> pntr_;
288 
289  //! reference counter - for handling unregister
290  unsigned int reference_;
291 
292  //! order of B-Spline curve
293  unsigned int order_;
294 
295  //! type of B-Spline curve (Open,Closed,Cluster)
297 
298  /**
299  * vector of multiplicities - determines in which control points
300  * edges are modelled
301  */
302  std::vector<unsigned int> mPnts_;
303 
304  /**
305  * number of spans for sub B-Spline curves of the B-Spline curve
306  * length >1 when curve is clustered
307  */
308  std::vector<unsigned int> numSpansVec_;
309 
310  //! number of base polynoms of curve - equal to number of control points
311  unsigned int numBasePolynoms_;
312 
313  //! number of spans of curve
314  unsigned int numSpans_;
315 
316  //! span matrices of curve (multiplied with placement matrices - p.292)
317  std::vector<BIAS::Matrix<double> > placedSpanMatrices_;
318 
319  //! metric matrix - confer to "Active Contours", chapter 3, p.50f
321 
322  //! metric matrix - confer to "Active Contours", chapter 3, p.59
324 
325  /**
326  * area coefficient matrix - confer to "Active Contours",
327  * chapter 3, p.65
328  *
329  * (currently not farther used in fitting process)
330  */
332  };//class
333 
335  reference_--;
336  if(reference_==0){
337  pntr_.remove(this);
338  delete this;
339  }
340  }
341 
342 }//namespace BIAS
343 #endif
class for Polynoms of arbitary order
Definition: Polynom.hh:46
BIAS::Matrix< double > splineMetricMatrix_
metric matrix - confer to &quot;Active Contours&quot;, chapter 3, p.50f
data object which holds a shape matrix or regularisation matrix for a b-spline curve; could be shared...
void RegisterPeriodicBSpline_()
inits class variables for a closed B-Spline curve
void ComputeSpan_(const unsigned int span, const int placeOff, const std::vector< unsigned int > &kMult, const std::vector< int > &k)
computes the span matrix of a B-Spline curves span
data object which holds all infomations of a B-Spline curve (ContourBSpline); its shared by B-Spline ...
static ContourBSplineData * LookUpData_(const unsigned int order, const ContourBSplineType::Type bType, const std::vector< unsigned int > &mPnts)
looks up if a ContourBSplineData object with the initial given parameter exist and returns pointer to...
unsigned int reference_
reference counter - for handling unregister
std::vector< BIAS::Matrix< double > > placedSpanMatrices_
span matrices of curve (multiplied with placement matrices - p.292)
unsigned int numBasePolynoms_
number of base polynoms of curve - equal to number of control points
static ContourBSplineData * Register(const unsigned int order, const ContourBSplineType::Type bType, const std::vector< unsigned int > &mPnts)
registers a ContourBSpline object and returns pointer to its data object
ContourBSplineType::Type bType_
type of B-Spline curve (Open,Closed,Cluster)
BIAS::Polynom ComputeBasePolynomRecursive_(const unsigned int span, const unsigned int knotIndex, const unsigned int order, const std::vector< int > &breakpoints)
recursivly computes one base polynom for a span matrix
void ComputeSplineMetricMatrixParametric_()
computes the metrix matrix (I^2 x scriptB) of the B-Spline curve
void Unregister()
decrements reference counter to this data object and deletes it if there is no reference to it ...
BIAS::Matrix< double > areaCoefficientMatrix_
area coefficient matrix - confer to &quot;Active Contours&quot;, chapter 3, p.65
void RegisterAperiodicBSpline_()
inits class variables for an open B-Spline curve
void ComputeSplineMetricMatrix_()
computes the metric matrix (scriptB) of the B-Spline curve
std::vector< unsigned int > numSpansVec_
number of spans for sub B-Spline curves of the B-Spline curve length &gt;1 when curve is clustered ...
std::vector< unsigned int > mPnts_
vector of multiplicities - determines in which control points edges are modelled
unsigned int order_
order of B-Spline curve
BIAS::Matrix< double > splineMetricMatrixParametric_
metric matrix - confer to &quot;Active Contours&quot;, chapter 3, p.59
static std::list< ContourBSplineData * > pntr_
list of all pointers to ContourBSplineData objects
ContourBSplineData()
empty standard constructor
unsigned int numSpans_
number of spans of curve
void ComputeAreaCoefficientMatrix_()
computes the area coefficient matrix of the B-Spline curve