ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Particle.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 #include <vector>
10 
11 #include "Vec3.h"
12 
13 /* Some physics constants */
14 #define DAMPING 0.01 // how much to damp the cloth simulation each frame
15 #define MAX_INF 9999999999
16 #define MIN_INF -9999999999
17 
18 /* The particle class represents a particle that can move around in 3D space*/
19 class Particle {
20 private:
21  bool movable; // can the particle move or not ? used to pin parts of the
22  // cloth
23  // double mass; // the mass of the particle (is always 1 in this example)
24  Vec3 acceleration; // a vector representing the current acceleration of the
25  // particle
26  // Vec3 accumulated_normal; // an accumulated normal (i.e. non normalized),
27  // used for OpenGL soft shading
28  double time_step2;
29 
30 public:
31  // this two memeber is used in the process of edge smoothing after the cloth
32  // simulation step.
33  bool isVisited;
34  // int neibor_count;
35  int pos_x; // position in the cloth grid
36  int pos_y;
37  int c_pos; // position in the group of movable points
38  Vec3 pos; // the current position of the particle in 3D space
39  Vec3 old_pos; // the position of the particle in the previous time step,
40  // used as part of the verlet numerical integration scheme
41 
42  // for constraint computation
43  std::vector<Particle*>
44  neighborsList; // record all the neighbors in cloth grid
45 
46  // for rasterlization
47  std::vector<int>
48  correspondingLidarPointList; // 每个布料节点对应的Lidar点的列表 the
49  // correspoinding lidar point list
50  std::size_t nearestPointIndex; // 对应的lidar点最临近点的索引 index nearest
51  // lidar point
52  double nearestPointHeight; // 该点的y轴值 the height(y) of the nearest
53  // lidar point
54  double tmpDist; // 临时变量,用于计算lidar点再水平面上距离布料点直接的距离
55  // only for inner computation
56 
57 public:
59  : movable(true)
60  //, mass(1)
61  ,
62  acceleration(0, 0, 0)
63  //, accumulated_normal(0, 0, 0)
64  ,
65  time_step2(0.0),
66  isVisited(false)
67  //, neibor_count(0)
68  ,
69  pos_x(0),
70  pos_y(0),
71  c_pos(0)
72  //, pos()
73  //, old_pos(pos)
74  ,
76  tmpDist(MAX_INF) {}
77 
78  Particle(Vec3 posVec, double time_step) : Particle() {
79  pos = posVec;
80  old_pos = posVec;
81  time_step2 = time_step;
82  }
83 
84  /* This is one of the important methods, where the time is progressed a
85  single step size (TIME_STEPSIZE) The method is called by Cloth.time_step()*/
86  void timeStep();
87 
88  inline bool isMovable() const { return movable; }
89 
90  inline void addForce(const Vec3& f) { acceleration += f /*/ mass*/; }
91 
92  inline void resetAcceleration() { acceleration = Vec3(0, 0, 0); }
93 
94  inline void offsetPos(const Vec3 v) {
95  if (movable) pos += v;
96  }
97 
98  inline void makeUnmovable() { movable = false; }
99 
100  // do constraint
101  void satisfyConstraintSelf(int constraintTimes);
102 
103  // inline void addToNormal(Vec3 normal) { accumulated_normal +=
104  // normal.normalized(); }
105 
106  // inline const Vec3& getNormal() const { return accumulated_normal; } //
107  // notice, the normal is not unit length
108 
109  // inline void resetNormal() { accumulated_normal = Vec3(0, 0, 0); }
110 };
#define MIN_INF
Definition: Particle.h:16
#define MAX_INF
Definition: Particle.h:15
int pos_x
Definition: Particle.h:35
void addForce(const Vec3 &f)
Definition: Particle.h:90
double nearestPointHeight
Definition: Particle.h:52
double tmpDist
Definition: Particle.h:54
int pos_y
Definition: Particle.h:36
Particle()
Definition: Particle.h:58
void resetAcceleration()
Definition: Particle.h:92
void makeUnmovable()
Definition: Particle.h:98
bool isMovable() const
Definition: Particle.h:88
std::vector< int > correspondingLidarPointList
Definition: Particle.h:48
std::size_t nearestPointIndex
Definition: Particle.h:50
bool isVisited
Definition: Particle.h:33
void timeStep()
Definition: Particle.cpp:13
int c_pos
Definition: Particle.h:37
Vec3 old_pos
Definition: Particle.h:39
Particle(Vec3 posVec, double time_step)
Definition: Particle.h:78
void satisfyConstraintSelf(int constraintTimes)
Definition: Particle.cpp:39
void offsetPos(const Vec3 v)
Definition: Particle.h:94
Vec3 pos
Definition: Particle.h:38
std::vector< Particle * > neighborsList
Definition: Particle.h:44
Definition: Vec3.h:14