- Timestamp:
- Sep 10, 2016, 4:14:02 PM (9 years ago)
- Branches:
- SaturateAtoms_singleDegree
- Children:
- 226860
- Parents:
- 408415
- git-author:
- Frederik Heber <heber@…> (06/05/14 17:42:39)
- git-committer:
- Frederik Heber <heber@…> (09/10/16 16:14:02)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Exporters/SphericalPointDistribution.cpp
r408415 r2cd0a0 139 139 140 140 SphericalPointDistribution::Polygon_t removeMatchingPoints( 141 const SphericalPointDistribution::Polygon_t &_returnpolygon,141 const VectorArray_t &_points, 142 142 const IndexList_t &_matchingindices 143 143 ) … … 147 147 std::sort(indices.begin(), indices.end()); 148 148 LOG(4, "DEBUG: sorted matching is " << indices); 149 IndexArray_t::const_iterator valueiter = indices.begin(); 150 SphericalPointDistribution::Polygon_t::const_iterator pointiter = 151 _returnpolygon.begin(); 152 for (unsigned int i=0; i< _returnpolygon.size(); ++i, ++pointiter) { 153 // skip all those in values 154 if (*valueiter == i) 155 ++valueiter; 156 else 157 remainingreturnpolygon.push_back(*pointiter); 149 IndexArray_t remainingindices(_points.size(), -1); 150 std::generate(remainingindices.begin(), remainingindices.end(), UniqueNumber); 151 IndexArray_t::iterator remainiter = std::set_difference( 152 remainingindices.begin(), remainingindices.end(), 153 indices.begin(), indices.end(), 154 remainingindices.begin()); 155 remainingindices.erase(remainiter, remainingindices.end()); 156 LOG(4, "DEBUG: remaining indices are " << remainingindices); 157 for (IndexArray_t::const_iterator iter = remainingindices.begin(); 158 iter != remainingindices.end(); ++iter) { 159 remainingreturnpolygon.push_back(_points[*iter]); 158 160 } 159 LOG(4, "DEBUG: remaining indices are " << remainingreturnpolygon);160 161 161 162 return remainingreturnpolygon; … … 292 293 // determine rotation angles to align the two point distributions with 293 294 // respect to bestmatching 294 SphericalPointDistribution::Polygon_t rotated_newpolygon;295 VectorArray_t rotated_newpolygon = remainingnew; 295 296 Vector oldCenter; 296 297 { … … 309 310 if ((oldCenter - newCenter).NormSquared() > std::numeric_limits<double>::epsilon()*1e4) { 310 311 // setup quaternion 311 Vector RotationAxis = newCenter; 312 RotationAxis.VectorProduct(oldCenter); 312 Vector RotationAxis = oldCenter; 313 RotationAxis.VectorProduct(newCenter); 314 Line Axis(zeroVec, RotationAxis); 313 315 RotationAxis.Normalize(); 314 const double RotationAngle = oldCenter.Angle(newCenter)/(M_PI/2.); 315 // RotationAxis.Angle(oldCenter) - RotationAxis.Angle(newCenter); 316 boost::math::quaternion<double> q 317 (RotationAngle, RotationAxis[0], RotationAxis[1], RotationAxis[2]); 318 LOG(5, "DEBUG: RotationAxis is " << RotationAxis 319 << ", RotationAngle is " << RotationAngle); 320 LOG(5, "DEBUG: Quaternion describing rotation is " << q); 316 const double RotationAngle = oldCenter.Angle(newCenter); // /(M_PI/2.); 317 LOG(5, "DEBUG: Rotate coordinate system by " << RotationAngle 318 << " around axis " << RotationAxis); 319 320 // apply rotation angles 321 for (VectorArray_t::iterator iter = rotated_newpolygon.begin(); 322 iter != rotated_newpolygon.end(); ++iter) { 323 Vector ¤t = *iter; 324 LOG(5, "DEBUG: Original point is " << current); 325 current = Axis.rotateVector(current, RotationAngle); 326 LOG(5, "DEBUG: Rotated point is " << current); 327 } 328 } 329 } 330 // rotate triangle/line/point around itself to match orientation 331 if (MCS.bestmatching.size() > 1) { 332 if (oldCenter.NormSquared() > std::numeric_limits<double>::epsilon()*1e4) { 333 // construct RotationAxis and two points on its plane, defining the angle 334 const Line RotationAxis(zeroVec, oldCenter); 335 Vector oldPosition(rotated_newpolygon[*MCS.bestmatching.begin()]); 336 oldPosition.ProjectOntoPlane(RotationAxis.getDirection()); 337 Vector newPosition(remainingold[*MCS.bestmatching.begin()]); 338 newPosition.ProjectOntoPlane(RotationAxis.getDirection()); 339 340 // construct reference vector to determine direction of rotation 341 Vector dreiBein(oldPosition); 342 dreiBein.VectorProduct(oldCenter); 343 dreiBein.Normalize(); 344 const double sign = 345 (dreiBein.ScalarProduct(newPosition) < 0.) ? -1. : +1.; 346 LOG(6, "DEBUG: oldCenter on plane is " << oldPosition 347 << ", newCenter in plane is " << newPosition 348 << ", and dreiBein is " << dreiBein); 349 const double RotationAngle = sign * oldPosition.Angle(newPosition); 350 LOG(5, "DEBUG: Rotating around self is " << RotationAngle 351 << " around axis " << RotationAxis); 352 321 353 #ifndef NDEBUG 354 // check: first bestmatching in rotated_newpolygon and remainingnew 355 // should now equal 322 356 { 323 // check that rotation works in DEBUG mode 324 boost::math::quaternion<double> p(0., newCenter[0], newCenter[1], newCenter[2]); 325 boost::math::quaternion<double> q_inverse = 326 boost::math::conj(q)/(boost::math::norm(q)); 327 p = q * p * q_inverse; 328 boost::math::quaternion<double> identity(1,0,0,0); 329 ASSERT( boost::math::norm(q*q_inverse - identity) < std::numeric_limits<double>::epsilon()*1e4, 330 "matchSphericalPointDistributions() - quaternion does not rotate newCenter " 331 +toString(q*q_inverse)+" into oldCenter "+toString(identity)+"."); 332 boost::math::quaternion<double> comparison(0., -oldCenter[0], oldCenter[1], oldCenter[2]); 333 ASSERT( boost::math::norm(p - comparison) < std::numeric_limits<double>::epsilon()*1e4, 334 "matchSphericalPointDistributions() - quaternion does not rotate newCenter " 335 +toString(p)+" into oldCenter "+toString(comparison)+"."); 357 const IndexList_t::const_iterator iter = MCS.bestmatching.begin(); 358 Vector rotatednew = RotationAxis.rotateVector( 359 rotated_newpolygon[*iter], 360 RotationAngle); 361 LOG(4, "CHECK: rotated first new bestmatching is " << rotatednew 362 << " while old was " << remainingold[*iter]); 363 ASSERT( (rotatednew - remainingold[*iter]).Norm() 364 < std::numeric_limits<double>::epsilon()*1e4, 365 "matchSphericalPointDistributions() - orientation rotation does not work as expected."); 336 366 } 337 367 #endif 338 368 339 // rotate spherical distribution 340 rotated_newpolygon = rotatePolygon(_newpolygon, q); 341 LOG(5, "DEBUG: Rotated new polygon is " << rotated_newpolygon); 342 } else { 343 rotated_newpolygon = _newpolygon; 344 } 345 } 346 // rotate triangle/line/point around itself to match orientation 347 const Line RotationAxis(zeroVec, oldCenter); 348 const double RotationAngle = 349 oldCenter.Angle(remainingold[0]) 350 - oldCenter.Angle(remainingnew[*MCS.bestmatching.begin()]); 351 LOG(5, "DEBUG: Rotate around self is " << RotationAngle 352 << " around axis " << RotationAxis); 353 354 for (SphericalPointDistribution::Polygon_t::iterator iter = rotated_newpolygon.begin(); 355 iter != rotated_newpolygon.end(); ++iter) { 356 RotationAxis.rotateVector(*iter, RotationAngle); 369 for (VectorArray_t::iterator iter = rotated_newpolygon.begin(); 370 iter != rotated_newpolygon.end(); ++iter) { 371 Vector ¤t = *iter; 372 LOG(6, "DEBUG: Original point is " << current); 373 current = RotationAxis.rotateVector(current, RotationAngle); 374 LOG(6, "DEBUG: Rotated point is " << current); 375 } 376 } 357 377 } 358 378
Note:
See TracChangeset
for help on using the changeset viewer.