25 #include "ContourBSplineData.hh"
33 const std::vector<unsigned int>& mPnts){
37 res=LookUpData_(order, bType, mPnts);
38 cout<<
"Lookup data:"<<endl;
45 cout<<
"before RegisterPeriodicBSpline"<<endl;
54 cout<<
"RegisterPeriodicBSpline"<<endl;
63 cout<<
"ComputeAreaCoefficientMatrix:"<<endl;
66 cout<<
"already registerd:"<<endl;
73 const std::vector<ContourBSplineData*>& bSplinesData){
84 for (i=1; i<bSplinesData.size(); i++){
85 if ((bSplinesData[i])->order_!= (bSplinesData[0])->order_ ){
86 BIASERR(
"Clustered ContourBSplines have to be of same order.\r\n");
89 res->
order_=(bSplinesData[0])->order_;
96 std::vector<unsigned int> mPnts;
97 std::vector<BIAS::Matrix<double> > placedSpanMatrices;
98 unsigned int numBasePolynoms=0;
99 unsigned int numSpans=0;
102 for(i=0; i<bSplinesData.size(); i++){
103 for(j=0; j<((bSplinesData[i])->mPnts_).size(); j++){
104 mPnts.push_back(((bSplinesData[i])->mPnts_)[j]);
106 numBasePolynoms+=(bSplinesData[i])->numBasePolynoms_;
107 numSpans+=(bSplinesData[i])->numSpans_;
108 res->
numSpansVec_.push_back((bSplinesData[i])->numSpans_);
115 unsigned int numBasePolynomsTmp = 0;
116 for(i=0;i<bSplinesData.size(); i++){
117 for(j=0;j<((bSplinesData[i])->placedSpanMatrices_).size();j++){
120 for(k=0;k<res->
order_;k++){
121 for(l=numBasePolynomsTmp;
122 l<((
unsigned int)(((bSplinesData[i])->placedSpanMatrices_)[j]
123 ).num_cols()+numBasePolynomsTmp);l++){
124 newPlacedSpan[k][l]=((bSplinesData[i])->placedSpanMatrices_
125 )[j][k][l-numBasePolynomsTmp];
128 placedSpanMatrices.push_back(newPlacedSpan);
130 numBasePolynomsTmp+=(bSplinesData[i])->numBasePolynoms_;
141 pntr_.push_back(res);
148 const std::vector<unsigned int>& mPnts,
149 const unsigned int numBasePolynoms,
150 const unsigned int numSpans,
151 const std::vector<unsigned int>& numSpansVec,
169 pntr_.push_back(res);
180 const std::vector<unsigned int>& mPnts){
183 std::list<ContourBSplineData*>::iterator it;
184 for(it=pntr_.begin(); it!=pntr_.end() ;it++){
185 if( ((*it)->order_==order) && ((*it)->bType_==bType) &&
186 ((*it)->mPnts_==mPnts) ){
187 ((*it)->reference_)++;
198 unsigned int multipleKnotCount=0;
199 for(i=0;i<numBasePolynoms_;i++){
200 multipleKnotCount+=mPnts_[i]-1;
202 numSpans_ = numBasePolynoms_ - multipleKnotCount;
218 std::vector<unsigned int> kMultTmp(numSpans_+1,1);
220 unsigned int j=multipleKnotCount-(order_-2);
221 unsigned int periodicOffset=0;
222 for(i=mPnts_.size();i>0;i--){
224 if( (mPnts_.size()-(i-1)) < (order_-1) ){
229 periodicOffset=(i-1)+(order_-1)-mPnts_.size();
231 kMultTmp[(i-1)-j-periodicOffset]=order_-1;
237 kMultTmp.back()=kMultTmp.front();
241 periodicOffset-=order_-2;
244 cout<<
"In RegisterPeriodicBSpline 1"<<endl;
251 std::vector<unsigned int> kMult;
257 kMult.push_back(order_);
263 unsigned int multiplicity = kMultTmp[kMultTmp.size()-2];
264 kMult.push_back(multiplicity);
265 periodicOffset-=multiplicity;
267 cout<<
"In RegisterPeriodicBSpline 2"<<endl;
272 for(i=0;i<kMultTmp.size();i++){
273 kMult.push_back(kMultTmp[i]);
275 periodicOffset-=kMultTmp[0];
282 kMult.push_back(kMultTmp[1]);
284 kMult.push_back(order_);
289 for(i=0;i<kMult.size();i++){
290 for(j=0;j<kMult[i];j++){
295 cout<<
"In RegisterPeriodicBSpline 3"<<endl;
297 for(i=2;i<numSpans_+2;i++){
298 ComputeSpan_(i,periodicOffset,kMult,k);
300 cout<<
"In RegisterPeriodicBSpline 4"<<endl;
307 unsigned int multipleKnotCount=0;
308 for(i=1;i<numBasePolynoms_-1;i++){
309 multipleKnotCount+=mPnts_[i]-1;
311 numSpans_ = numBasePolynoms_ - order_+1 - multipleKnotCount;
325 std::vector<unsigned int> kMult(numSpans_+1,1);
326 kMult.front()=order_;
327 unsigned int j=order_-2;
328 for(i=order_-1;i<numBasePolynoms_-1;i++){
330 kMult[i-j]=mPnts_[i];
339 for(i=0;i<=numSpans_;i++){
340 for(j=0;j<kMult[i];j++){
348 for(i=0;i<numSpans_;i++){
349 ComputeSpan_(i, 0, kMult, k);
354 const unsigned int knotIndex,
355 const unsigned int order,
356 const std::vector<int>& breakpoints){
360 p[0]=(span>=(
unsigned int)breakpoints[knotIndex] &&
361 span<(
unsigned int)breakpoints[knotIndex+1]) ? 1. : 0.;
366 int denominator = breakpoints[knotIndex+order-1] - breakpoints[knotIndex];
371 pTmp[1]=1.; pTmp[0]=(double)span-(
double)breakpoints[knotIndex];
373 pTmp2 = ComputeBasePolynomRecursive_(span, knotIndex, order-1, breakpoints);
378 p1 *= (1./(double)denominator);
380 denominator = breakpoints[knotIndex+order] - breakpoints[knotIndex+1];
385 pTmp[1]=-1.; pTmp[0]=(double)breakpoints[knotIndex+order]-(
double)span;
387 pTmp2 = ComputeBasePolynomRecursive_(span, knotIndex+1, order-1, breakpoints);
389 p2 = p2 * (1./(double)denominator);
400 const std::vector<unsigned int>& kMult,
401 const std::vector<int>& k){
403 cout<<
"In ComputeSpan 1"<<endl;
406 for(i=0; i<=span;i++){
407 bIndex+=(int) kMult[i];
410 cout<<
"In ComputeSpan 2"<<endl;
417 for(i=0;i<order_;i++){
418 cout<<
"In ComputeSpan 2."<<i<<endl;
419 basePolynom=ComputeBasePolynomRecursive_(span, (
unsigned int)bIndex+i,
421 cout<<
"In ComputeSpan 2."<<i<<endl;
423 for(j=0;j<order_;j++){
424 spanMatrix[j][i]=basePolynom[j];
428 for(j=0;j<numBasePolynoms_;j++){
431 placementMatrix[i][j]= i+bIndex==j ? 1.:0.;
437 placementMatrix[i][j]=((int)i+bIndex+placeOff+(
int)numBasePolynoms_)
438 % numBasePolynoms_ == j ? 1.:0.;
443 cout<<
"In ComputeSpan 3"<<endl;
444 placementMatrix.
MultLeft(spanMatrix);
445 placedSpanMatrices_.push_back(placementMatrix);
454 for(i=1;i<=order_;i++)
455 for(j=1;j<=order_;j++)
456 hilbert[i-1][j-1]=1./(
double)(i+j-1);
464 splineMetricMatrix_.
newsize(numBasePolynoms_,numBasePolynoms_);
465 splineMetricMatrix_.SetZero();
467 for(i=0;i<numSpans_;i++){
469 tmpMat.
MultLeft(placedSpanMatrices_[i]);
471 tmpMat.
MultLeft(placedSpanMatrices_[i].Transpose());
472 splineMetricMatrix_+=tmpMat;
474 splineMetricMatrix_.
MultiplyIP(1./(
double)numSpans_);
484 splineMetricMatrixParametric_.newsize(2*numBasePolynoms_,2*numBasePolynoms_);
485 splineMetricMatrixParametric_.SetZero();
488 for(i=0;i<numBasePolynoms_;i++){
489 for(j=0;j<numBasePolynoms_;j++){
490 splineMetricMatrixParametric_[i][j]=splineMetricMatrix_[i][j];
494 for(i=numBasePolynoms_;i<2*numBasePolynoms_;i++){
495 for(j=numBasePolynoms_;j<2*numBasePolynoms_;j++){
496 splineMetricMatrixParametric_[i][j]=
497 splineMetricMatrix_[i-numBasePolynoms_][j-numBasePolynoms_];
511 for(i=1;i<=order_;i++)
512 for(j=1;j<=order_;j++)
513 pQuote[i-1][j-1] = ((i==1) && (j==1))? 0. : (double)(j-1)/(double)(i+j-2);
524 for(i=0;i<numSpans_;i++){
525 tmpMat=placedSpanMatrices_[i];
527 tmpMat.
MultLeft(placedSpanMatrices_[i].Transpose());
533 areaCoefficientMatrix_.newsize(2*numBasePolynoms_,2*numBasePolynoms_);
534 areaCoefficientMatrix_.SetZero();
536 for(i=0;i<numBasePolynoms_;i++){
537 for(j=0;j<numBasePolynoms_;j++){
539 areaCoefficientMatrix_[i][j]=bQuote[i][j];
541 areaCoefficientMatrix_[i+numBasePolynoms_][j+numBasePolynoms_]=-bQuote[i][j];
class for Polynoms of arbitary order
void RegisterPeriodicBSpline_()
inits class variables for a closed B-Spline curve
Matrix< T > & newsize(Subscript M, Subscript N)
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
void SetZero()
Sets all values to zero.
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 SetIdentity()
Converts matrix to identity matrix.
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 >1 when curve is clustered ...
void SetOrder(unsigned int i)
sets the order of polynom to i new generated coefficients are 0
std::vector< unsigned int > mPnts_
vector of multiplicities - determines in which control points edges are modelled
unsigned int order_
order of B-Spline curve
void MultiplyIP(const T &scalar)
in place multiplication function
void MultLeft(const Matrix< T > &arg)
in Place matrix multiplication this is equal to M = arg*M, but faster
static std::list< ContourBSplineData * > pntr_
list of all pointers to ContourBSplineData objects
unsigned int numSpans_
number of spans of curve
void ComputeAreaCoefficientMatrix_()
computes the area coefficient matrix of the B-Spline curve