Cloth.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. //This source code is about a ground filtering algorithm for airborn LiDAR data
  30. //based on physical process simulations, specifically cloth simulation.
  31. //
  32. //This code is based on a Cloth Simulation Tutorial at the cg.alexandra.dk blog.
  33. //Thanks to Jesper Mosegaard (clothTutorial@jespermosegaard.dk)
  34. //
  35. //When applying the cloth simulation to LIDAR point filtering. A lot of features
  36. //have been added to the original source code, including
  37. //* configuration file management
  38. //* point cloud data read/write
  39. //* point-to-point collsion detection
  40. //* nearest point search structure from CGAL
  41. //* addding a terrain class
  42. //using discrete steps (drop and pull) to approximate the physical process
  43. //Finding the max height value in nearest N points aroud every particles, as the lowest position where the particles can get.在每个不料点周围找最邻近的N个点,以高程最大值作为所能到达的最低点。
  44. //local
  45. #include "Vec3.h"
  46. #include "Particle.h"
  47. //system
  48. #include <vector>
  49. class ccMesh;
  50. class Cloth
  51. {
  52. private:
  53. // total number of particles is num_particles_width*num_particles_height
  54. int constraint_iterations;
  55. //double time_step;
  56. std::vector<Particle> particles; // all particles that are part of this cloth
  57. // std::vector<Constraint> constraints; // alle constraints between particles as part of this cloth
  58. //parameters of slope postpocessing
  59. double smoothThreshold;
  60. double heightThreshold;
  61. //heightvalues
  62. std::vector<double> heightvals;
  63. //movable particle index
  64. std::vector<int> movableIndex;
  65. std::vector< std::vector<int> > particle_edges;
  66. //record
  67. inline void addConstraint(Particle *p1, Particle *p2)
  68. { /*constraints.push_back(Constraint(p1, p2));*/
  69. p1->neighborsList.push_back(p2); //record the neighbor for each particle
  70. p2->neighborsList.push_back(p1);
  71. }
  72. public:
  73. inline Particle& getParticle(int x, int y) { return particles[y*num_particles_width + x]; }
  74. inline const Particle& getParticle(int x, int y) const { return particles[y*num_particles_width + x]; }
  75. inline Particle& getParticleByIndex(int index) { return particles[index]; }
  76. inline const Particle& getParticleByIndex(int index) const { return particles[index]; }
  77. int num_particles_width; // number of particles in "width" direction
  78. int num_particles_height; // number of particles in "height" direction
  79. Vec3 origin_pos;
  80. double step_x, step_y;
  81. inline int getSize() const { return num_particles_width * num_particles_height; }
  82. inline std::vector<double>& getHeightvals() { return heightvals; }
  83. public:
  84. /* This is a important constructor for the entire system of particles and constraints */
  85. Cloth( const Vec3& origin_pos,
  86. int num_particles_width,
  87. int num_particles_height,
  88. double step_x,
  89. double step_y,
  90. double smoothThreshold,
  91. double heightThreshold,
  92. int rigidness/*,
  93. double time_step*/);
  94. void setheightvals(const std::vector<double>& heightvals)
  95. {
  96. this->heightvals = heightvals;
  97. }
  98. /** This is an important method where the time is progressed one time step for the entire cloth.
  99. This includes calling satisfyConstraint() for every constraint, and calling timeStep() for all particles
  100. **/
  101. double timeStep();
  102. /* used to add gravity to all particles */
  103. void addForce(double f);
  104. //detecting collision of cloth and terrain
  105. void terrainCollision();
  106. //implementing postpocessing to movable particles
  107. void movableFilter();
  108. struct XY
  109. {
  110. XY(int x1, int y1)
  111. : x(x1)
  112. , y(y1)
  113. {}
  114. int x;
  115. int y;
  116. };
  117. void findUnmovablePoint(const std::vector<XY>& connected,
  118. const std::vector<double>& heightvals,
  119. std::vector<int>& edgePoints);
  120. void handle_slop_connected( const std::vector<int>& edgePoints,
  121. const std::vector<XY>& connected,
  122. const std::vector< std::vector<int> >& neighbors,
  123. const std::vector<double> &heightvals);
  124. //! Converts the cloth to a CC mesh structure
  125. ccMesh* toMesh() const;
  126. };