Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_curve_fitter.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_curve_fitter.cpp
r4271 r8127 247 247 public: 248 248 PrivateData(): 249 tolerance( 1.0 ) 249 tolerance( 1.0 ), 250 chunkSize( 0 ) 250 251 { 251 252 } 252 253 253 254 double tolerance; 255 uint chunkSize; 254 256 }; 255 257 … … 288 290 Assign the tolerance 289 291 290 The tolerance is the maximum distance, that is acc aptable292 The tolerance is the maximum distance, that is acceptable 291 293 between the original curve and the smoothed curve. 292 294 … … 313 315 314 316 /*! 317 Limit the number of points passed to a run of the algorithm 318 319 The runtime of the Douglas Peucker algorithm increases non linear 320 with the number of points. For a chunk size > 0 the polygon 321 is split into pieces passed to the algorithm one by one. 322 323 \param numPoints Maximum for the number of points passed to the algorithm 324 325 \sa chunkSize() 326 */ 327 void QwtWeedingCurveFitter::setChunkSize( uint numPoints ) 328 { 329 if ( numPoints > 0 ) 330 numPoints = qMax( numPoints, 3U ); 331 332 d_data->chunkSize = numPoints; 333 } 334 335 /*! 336 337 \return Maximum for the number of points passed to a run 338 of the algorithm - or 0, when unlimited 339 \sa setChunkSize() 340 */ 341 uint QwtWeedingCurveFitter::chunkSize() const 342 { 343 return d_data->chunkSize; 344 } 345 346 /*! 315 347 \param points Series of data points 316 348 \return Curve points … … 318 350 QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const 319 351 { 352 QPolygonF fittedPoints; 353 354 if ( d_data->chunkSize == 0 ) 355 { 356 fittedPoints = simplify( points ); 357 } 358 else 359 { 360 for ( int i = 0; i < points.size(); i += d_data->chunkSize ) 361 { 362 const QPolygonF p = points.mid( i, d_data->chunkSize ); 363 fittedPoints += simplify( p ); 364 } 365 } 366 367 return fittedPoints; 368 } 369 370 QPolygonF QwtWeedingCurveFitter::simplify( const QPolygonF &points ) const 371 { 372 const double toleranceSqr = d_data->tolerance * d_data->tolerance; 373 320 374 QStack<Line> stack; 321 375 stack.reserve( 500 ); … … 325 379 326 380 QVector<bool> usePoint( nPoints, false ); 327 328 double distToSegment;329 381 330 382 stack.push( Line( 0, nPoints - 1 ) ); … … 343 395 const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0; 344 396 345 double maxDist = 0.0;397 double maxDistSqr = 0.0; 346 398 int nVertexIndexMaxDistance = r.from + 1; 347 399 for ( int i = r.from + 1; i < r.to; i++ ) … … 350 402 const double fromVecX = p[i].x() - p[r.from].x(); 351 403 const double fromVecY = p[i].y() - p[r.from].y(); 352 const double fromVecLength = 353 qSqrt( fromVecX * fromVecX + fromVecY * fromVecY ); 354 404 405 double distToSegmentSqr; 355 406 if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) 356 407 { 357 distToSegment = fromVecLength; 358 } 359 if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) 360 { 361 distToSegment = fromVecLength; 408 distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY; 362 409 } 363 410 else … … 365 412 const double toVecX = p[i].x() - p[r.to].x(); 366 413 const double toVecY = p[i].y() - p[r.to].y(); 367 const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY ); 414 const double toVecLength = toVecX * toVecX + toVecY * toVecY; 415 368 416 const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY ); 369 417 if ( s < 0.0 ) 370 distToSegment = toVecLength; 418 { 419 distToSegmentSqr = toVecLength; 420 } 371 421 else 372 422 { 373 distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ));423 distToSegmentSqr = qFabs( toVecLength - s * s ); 374 424 } 375 425 } 376 426 377 if ( maxDist < distToSegment)427 if ( maxDistSqr < distToSegmentSqr ) 378 428 { 379 maxDist = distToSegment;429 maxDistSqr = distToSegmentSqr; 380 430 nVertexIndexMaxDistance = i; 381 431 } 382 432 } 383 if ( maxDist <= d_data->tolerance)433 if ( maxDistSqr <= toleranceSqr ) 384 434 { 385 435 usePoint[r.from] = true; … … 393 443 } 394 444 395 int cnt = 0; 396 397 QPolygonF stripped( nPoints ); 445 QPolygonF stripped; 398 446 for ( int i = 0; i < nPoints; i++ ) 399 447 { 400 448 if ( usePoint[i] ) 401 stripped [cnt++]= p[i];402 } 403 stripped.resize( cnt ); 449 stripped += p[i]; 450 } 451 404 452 return stripped; 405 453 }
Note:
See TracChangeset
for help on using the changeset viewer.