25 #ifndef __CONTOURDETECTORBSPLINE_HH_
26 #define __CONTOURDETECTORBSPLINE_HH_
33 #include <Base/Debug/Debug.hh>
34 #include <Base/Math/Vector.hh>
35 #include <Base/Math/Vector2.hh>
36 #include <Base/Image/Image.hh>
38 #include "ContourBSplineData.hh"
39 #include "ContourBSplineShapeMatrix.hh"
40 #include "ContourBSplineType.hh"
41 #include "ContourDetectorBase.hh"
44 #define D_CONTOURBSPLINE_DEBUG 1<<0
45 #define D_CONTOURBSPLINE_INIT 1<<1
46 #define D_CONTOURBSPLINE_INITFIT 1<<2
47 #define D_CONTOURBSPLINE_FIT 1<<3
48 #define D_CONTOURBSPLINE_BOUNDINGBOX 1<<4
102 template <
class StorageType>
142 std::vector<BIAS::BIASContour>& contour);
177 void Init(
const unsigned int order,
213 void Init(
const unsigned int order,
215 const std::vector<unsigned int> &mPnts,
231 void Init(
const unsigned int order,
270 void Init(
const unsigned int order,
272 const std::vector<unsigned int>& mPnts,
303 const unsigned int normalWidth);
337 const unsigned int normalWidth,
const double& minClip);
363 const unsigned int normalWidth);
393 const unsigned int normalWidth,
const double& minClip);
400 bool Save(
const std::string& filename);
407 bool Load(
const std::string& filename);
415 inline void SetControlPoints(
432 inline void Displace(
const double& x,
const double&y);
441 inline void Scale(
const double& scale);
450 inline void ScaleX(
const double& scale);
459 inline void ScaleY(
const double& scale);
468 void Rotate(
const double& angle);
474 inline void CenterOverControlPoints();
490 inline void SetShapeSpaceIdentity();
498 inline void SetShapeSpaceEuclidian();
506 inline void SetShapeSpacePlanarAffin();
521 inline void SetSubShapeSpaceIdentity();
529 inline void SetSubShapeSpaceEuclidian();
537 inline void SetSubShapeSpacePlanarAffin();
547 inline void SetSubShapeSpaceZero();
566 inline void ComputeRegularisationMatrix();
580 inline void SetFitSampleWidth(
double width);
594 inline void SetFitSamples(
unsigned int samples);
608 inline void SetDrawSampleWidth(
double width);
621 inline void SetDrawSamples(
unsigned int samples);
643 inline unsigned int GetOrder();
655 inline std::vector<unsigned int> GetMultiplePoints();
701 const double& t,
const unsigned int normalWidth,
729 const double& t,
const unsigned int normalWidth,
730 const double& minClip,
750 const double& t,
const unsigned int normalWidth,
774 const double& t,
const unsigned int normalWidth,
775 const double& minClip,
800 const unsigned int normalWidth,
830 const unsigned int normalWidth,
833 const double& minClip,
854 const unsigned int normalWidth,
880 const unsigned int normalWidth,
883 const double& minClip,
893 void GetBoundingBox(
int& minX,
int& minY,
int& maxX,
int& maxY);
903 const StorageType color[3]);
916 const StorageType color[3]);
939 void DrawNormals(
const unsigned int normalWidth,
941 const StorageType color[3]);
1012 void GetPointAndParamVec_(
const unsigned int numSpan,
const double& s,
1026 inline void GetPoint_(
const unsigned int numSpan,
const double& s,
1040 void GetNormal_(
const unsigned int numSpan,
const double& s,
1059 const unsigned int normalWidth);
1078 const unsigned int normalWidth);
1099 const unsigned int normalWidth,
const double& minClip);
1117 void TestInit_(
const unsigned int order,
1119 const std::vector<unsigned int>& mPnts,
1166 (pData_->reference_)++;
1168 curveInitialised_=
false;
1170 if(pShapeSpaceMatrix_!=NULL){
1171 (pShapeSpaceMatrix_->reference_)++;
1174 if(pSubShapeSpaceMatrix_!=NULL){
1175 (pSubShapeSpaceMatrix_->reference_)++;
1178 if(pRegMatrix_!=NULL){
1179 (pRegMatrix_->reference_)++;
1189 template <
class StorageType>
void
1193 CPntsToQ_(controlPoints);
1194 curveInitialised_=
false;
1198 template <
class StorageType>
void
1202 curveInitialised_=
false;
1206 template <
class StorageType>
void
1210 for(i=0;i<(pData_->numBasePolynoms_);i++){
1212 Q_[i+(pData_->numBasePolynoms_)]+=y;
1214 curveInitialised_=
false;
1217 template <
class StorageType>
void
1222 for(i=0;i<Q_.size();i++){
1227 template <
class StorageType>
void
1232 for(i=0;i<(Q_.size()/2);i++){
1237 template <
class StorageType>
void
1242 for(i=(Q_.size()/2);i<Q_.size();i++){
1247 template <
class StorageType>
void
1253 for(i=0; i<pData_->numBasePolynoms_; i++){
1255 y+=Q_[i+pData_->numBasePolynoms_];
1257 x/=(double) pData_->numBasePolynoms_;
1258 y/=(
double) pData_->numBasePolynoms_;
1262 template <
class StorageType>
void
1268 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"shapeSpaceMatrix: " <<
1273 template <
class StorageType>
void
1277 pData_->numBasePolynoms_);
1278 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"shapeSpaceMatrix: " <<
1283 template <
class StorageType>
void
1287 pData_->numBasePolynoms_,Q_);
1288 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"shapeSpaceMatrix: " <<
1293 template <
class StorageType>
void
1297 (pData_->numBasePolynoms_,Q_);
1298 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"shapeSpaceMatrix: " <<
1303 template <
class StorageType>
void
1309 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"subShapeSpaceMatrix: " <<
1314 template <
class StorageType>
void
1318 (pData_->numBasePolynoms_);
1319 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"subShapeSpaceMatrix: " <<
1324 template <
class StorageType>
void
1329 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"subShapeSpaceMatrix: " <<
1334 template <
class StorageType>
void
1339 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"subShapeSpaceMatrix: " <<
1344 template <
class StorageType>
void
1347 pSubShapeSpaceMatrix_ =
1349 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"subShapeSpaceMatrix: " <<
1354 template <
class StorageType>
void
1358 BIASERR(
"ComputeRegularisationMatrix: pData_ NULL pointer\r\n");
1359 if(pShapeSpaceMatrix_==NULL)
1360 BIASERR(
"ComputeRegularisationMatrix: "<<
1361 "pShapeSpaceMatrix_ NULL pointer\r\n");
1362 if(pSubShapeSpaceMatrix_==NULL)
1363 BIASERR(
"ComputeRegularisationMatrix: "<<
1364 "pSubShapeSpaceMatrix_ NULL pointer\r\n");
1366 pData_, pShapeSpaceMatrix_, pSubShapeSpaceMatrix_ );
1367 BIASCDOUT(D_CONTOURBSPLINE_INITFIT,
"regMatrix: " <<
1371 template <
class StorageType>
void
1374 if(fitSampleWidth_==NULL){
1375 fitSampleWidth_=
new double;
1377 fitSamples_=(
unsigned int)(1./width);
1378 *fitSampleWidth_=1./(double)fitSamples_;
1381 template <
class StorageType>
void
1384 if(fitSampleWidth_==NULL){
1385 fitSampleWidth_=
new double;
1387 fitSamples_=samples;
1388 *fitSampleWidth_=1./(double)fitSamples_;
1391 template <
class StorageType>
void
1394 if(drawSampleWidth_==NULL){
1395 drawSampleWidth_=
new double;
1397 drawSamples_=(
unsigned int)(1./width);
1398 *drawSampleWidth_=1./(double)drawSamples_;
1401 template <
class StorageType>
void
1404 if(drawSampleWidth_==NULL){
1405 drawSampleWidth_=
new double;
1407 drawSamples_=samples;
1408 *drawSampleWidth_=1./(double)drawSamples_;
1411 template <
class StorageType>
unsigned int
1413 BIASASSERT(pData_!=NULL);
1414 return pData_->order_;
1419 BIASASSERT(pData_!=NULL);
1420 return pData_->bType_;
1423 template <
class StorageType> std::vector<unsigned int>
1425 BIASASSERT(pData_!=NULL);
1426 return pData_->mPnts_;
1429 template <
class StorageType>
void
1432 const unsigned int normalWidth,
1437 GetFeatImage_(greyImg, featImg, normalWidth);
1438 GetFeature(featImg,normalWidth,curvePnt,normal,res);
1441 template <
class StorageType>
void
1444 const unsigned int normalWidth,
1447 const double& minClip,
1450 GetFeatImage_(greyImg, featImg, normalWidth);
1451 GetFeature(featImg,normalWidth,curvePnt,normal,minClip,res);
1454 template <
class StorageType>
void
1460 GetPointAndParamVec_(numSpan, s, param, res);
1464 #endif//__CONTOURDETECTORBSPLINE_HH_
void Scale(const double &scale)
scales curve isotropic
void GetFeature(BIAS::Image< StorageType > &greyImg, const double &t, const unsigned int normalWidth, BIAS::Vector2< double > &res)
returns the feature point with highest gradient along the normal in curve point located at "t" ...
void SetFitSampleWidth(double width)
sets the amount of samples used to search features along the curve in fitting algorithm.
void GetControlPoints(std::vector< BIAS::Vector2< double > > &cPnts)
returns a vector of control points in x,y-coordinates
void SetSubShapeSpaceIdentity()
set invariant shape-space for regularised fitting to identity
ContourBSplineData * pData_
pointer to data of B-Spline curve initialised by call of Init(...)
data object which holds a shape matrix or regularisation matrix for a b-spline curve; could be shared...
void GetPoint_(const unsigned int numSpan, const double &s, BIAS::Vector2< double > &res)
computes a point on curve
unsigned int drawSamples_
amount of samples used in drawing algorithm
void ScaleY(const double &scale)
scales curve in y-direction (vertically)
void SetShapeSpaceIdentity()
sets spape-space for regularised fitting to identity
ContourDetectorBSpline & operator=(const ContourDetectorBSpline< StorageType > &toCopy)
copy operator
data object which holds all infomations of a B-Spline curve (ContourBSpline); its shared by B-Spline ...
ContourBSplineType::Type GetBType()
returns type of B-Spline curve - possible values are Open, Closed or Cluster.
double * fitSampleWidth_
distance of sample points in basis used in fitting algorithm
ContourBSplineShapeMatrix * pSubShapeSpaceMatrix_
pointer to invariant shape-space matrix object
bool curveInitialised_
bool to indicate a change of control points
static ContourBSplineShapeMatrix * ComputeRegularisationMatrix(ContourBSplineData *data, ContourBSplineShapeMatrix *shapeSpace, ContourBSplineShapeMatrix *subShapeSpace)
generates a new regularisation matrix as ContourBSplineShapeMatrix object and returns pointer to it ...
static ContourBSplineShapeMatrix * SetShapeSpacePlanarAffin(const unsigned int numBasePolynoms, const BIAS::Vector< double > &Q)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
void SetShapeSpaceEuclidian()
sets spape-space for regularised fitting to euclidian similarities
void SetShapeSpacePlanarAffin()
sets spape-space for regularised fitting to planar affine transformations
void SetFitSamples(unsigned int samples)
sets the amount of samples used to search features along the curve in fitting algorithm.
BIAS::Vector< double > Q_
vector of control points; first entries are x-coordinates; last entries are y-coordinates ...
double * drawSampleWidth_
distance of sample points in basis used in drawing algorithm
std::vector< unsigned int > GetMultiplePoints()
returns vector of multiple points; indicates which control points are modelled as edges ...
void SetSubShapeSpacePlanarAffin()
set invariant shape-space for regularised fitting to planar affine transformation ...
void SetDrawSamples(unsigned int samples)
sets the amount of sample points used to draw the B-Spline curve.
void SetDrawSampleWidth(double width)
sets the amount of sample points used to draw the B-Spline curve.
static ContourBSplineShapeMatrix * SetShapeSpaceMatrix(const BIAS::Matrix< double > &matrix)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
The image template class for specific storage types.
void GetControlPoints(BIAS::Vector< double > &Q)
returns a vector of control points; first entries are x-coordinates; last entries are y-coordinates ...
represents a special B-Spline and holds functions to handle fitting
void ScaleX(const double &scale)
scales curve in x-direction (horizontally)
unsigned int GetOrder()
returns order of B-Spline curve
void SetSubShapeSpaceZero()
set invariant shape-space for regularised fitting to zero
void SetControlPoints(const std::vector< BIAS::Vector2< double > > &controlPoints)
sets new control points
static ContourBSplineShapeMatrix * SetShapeSpaceIdentity(const unsigned int numBasePolynoms)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
void SetSubShapeSpaceEuclidian()
set invariant shape-space for regularised fitting to euclidian similarities
std::vector< std::vector< BIAS::Vector< double > > > curveVectors_
vectors needed to draw curve (determined by InitCurve_)
static ContourBSplineShapeMatrix * SetSubShapeSpaceZero(ContourBSplineShapeMatrix *shapeSpace)
generates a new invariant shape-matrix as ContourBSplineShapeMatrix object and returns a pointer to i...
unsigned int fitSamples_
amount of samples used in fitting algorithm
void Displace(const double &x, const double &y)
displace all control points
void SetSubShapeSpaceMatrix(BIAS::Matrix< double > &subShapeSpace)
set invariant shape-space for regularised fitting
void SetShapeSpaceMatrix(BIAS::Matrix< double > &shapeSpace)
sets spape-space for regularised fitting
static ContourBSplineShapeMatrix * SetShapeSpaceEuclidian(const unsigned int numBasePolynoms, const BIAS::Vector< double > &Q)
generates a new shape-matrix (invariant as well) as ContourBSplineShapeMatrix object and returns a po...
ContourBSplineShapeMatrix * pRegMatrix_
pointer to regularisation matrix object
ContourBSplineShapeMatrix * pShapeSpaceMatrix_
pointer to shape-space matrix object
ContourDetectorBSpline(const ContourDetectorBSpline< StorageType > &toCopy)
copy constructor
purely virtual interface defining class for contour detectors
void CenterOverControlPoints()
centers the curve by computing center over control points (not accurate!)
void ComputeRegularisationMatrix()
computes the regularisation matrix needed for fitting algorithm.