Particle.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. //#######################################################################################
  3. //# #
  4. //# CLOUDCOMPARE PLUGIN: qCSF #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# Please cite the following paper, If you use this plugin in your work. #
  16. //# #
  17. //# Zhang W, Qi J, Wan P, Wang H, Xie D, Wang X, Yan G. An Easy-to-Use Airborne LiDAR #
  18. //# Data Filtering Method Based on Cloth Simulation. Remote Sensing. 2016; 8(6):501. #
  19. //# #
  20. //# Copyright © #
  21. //# RAMM laboratory, School of Geography, Beijing Normal University #
  22. //# (http://ramm.bnu.edu.cn/) #
  23. //# #
  24. //# Wuming Zhang; Jianbo Qi; Peng Wan; Hongtao Wang #
  25. //# #
  26. //# contact us: 2009zwm@gmail.com; wpqjbzwm@126.com #
  27. //# #
  28. //#######################################################################################
  29. #include <vector>
  30. #include <limits>
  31. #include "Vec3.h"
  32. /* The particle class represents a particle that can move around in 3D space*/
  33. class Particle
  34. {
  35. private:
  36. bool movable; // can the particle move or not ? used to pin parts of the cloth
  37. //double mass; // the mass of the particle (is always 1 in this example)
  38. double acceleration; // the current acceleration of the particle (along Y) - DGM: already multiplied by dt^²
  39. //double time_step2; // square time step
  40. Vec3 pos; // the current position of the particle in 3D space
  41. double old_pos_y; // the altitude of the particle at the previous time step, used as part of the verlet numerical integration scheme
  42. public:
  43. //these members are used in the process of edge smoothing after the cloth simulation step.
  44. bool isVisited;
  45. int pos_x; // X position in the cloth grid
  46. int pos_y; // Y position in the cloth grid
  47. int c_pos; // position in the group of movable points
  48. //for constraint computation
  49. std::vector<Particle*> neighborsList; //record all the neighbors in cloth grid
  50. //for rasterization
  51. //std::vector<int> correspondingLidarPointList; // the correspoinding lidar point list (DGM: not used)
  52. //std::size_t nearestPointIndex; // nearest lidar point (DGM: not used)
  53. double nearestPointHeight; // the height(y) of the nearest lidar point
  54. double nearestPointDist; // only for internal computation
  55. public:
  56. Particle()
  57. : movable(true)
  58. //, mass(1.0)
  59. , acceleration(0)
  60. //, time_step2(0)
  61. , isVisited(false)
  62. , pos_x(0)
  63. , pos_y(0)
  64. , c_pos(0)
  65. , pos(0, 0, 0)
  66. , old_pos_y(0)
  67. , nearestPointHeight(std::numeric_limits<double>::lowest())
  68. , nearestPointDist(std::numeric_limits<double>::max())
  69. {}
  70. Particle(const Vec3& posVec/*, double squareTimeStep*/)
  71. : Particle()
  72. {
  73. pos = posVec;
  74. old_pos_y = posVec.y;
  75. //time_step2 = squareTimeStep;
  76. }
  77. inline const Vec3& getPos() const { return pos; }
  78. inline double getPreviousY() const { return old_pos_y; }
  79. /* This is one of the important methods, where the time is progressed a single step size (TIME_STEPSIZE)
  80. The method is called by Cloth.time_step()*/
  81. void timeStep();
  82. inline bool isMovable() const { return movable; }
  83. inline void addForce(double f) { acceleration += f/*/ mass*/; }
  84. inline void resetAcceleration() { acceleration = 0; }
  85. inline void offsetPos(double dy)
  86. {
  87. if (movable)
  88. {
  89. pos.y += dy;
  90. }
  91. }
  92. inline void makeUnmovable() { movable = false; }
  93. //do constraint
  94. void satisfyConstraintSelf(int constraintTimes);
  95. };