NDEVR
API Documentation
Cloth.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: NDEVRPCH
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32/*
33 * This source code is about a ground filtering algorithm for airborn LiDAR data
34 * based on physical process simulations, specifically cloth simulation.
35 *
36 * this code is based on a Cloth Simulation Tutorial at the cg.alexandra.dk blog.
37 * Thanks to Jesper Mosegaard (clothTutorial@jespermosegaard.dk)
38 *
39 *
40 *
41 * When applying the cloth simulation to LIDAR point filtering. A lot of features
42 * have been added to the original source code, including
43 * configuration file management
44 * point cloud data read/write
45 * point-to-point collsion detection
46 * nearest point search structure from CGAL
47 * addding a terrain class
48 *
49 *
50 */
51// using discrete steps (drop and pull) to approximate the physical process
52
53#pragma once
54#include "Particle.h"
55#include "Base/Headers/Vertex.hpp"
56#include "Base/Headers/BaseValues.hpp"
57#include "Base/Headers/Buffer.hpp"
58#include "Base/Headers/RGBColor.h"
59// post processing is only for connected component which is large than 50
60#define MAX_PARTICLE_FOR_POSTPROCESSIN 50
61
62
63namespace NDEVR
64{
68 class Cloth
69 {
70 private:
71
72 // total number of particles is num_particles_width * num_particles_height
73 uint04 constraint_iterations;
74
75 fltp04 time_step;
76
77 Buffer<Particle> particles;
78
79 fltp04 smoothThreshold;
80 fltp04 heightThreshold;
81 Vector<3, fltp04> m_acceleration;
82 Buffer<RGBColor> m_colors;
83 public:
85 fltp04 step_x, step_y;
88 Particle& getParticle(uint04 x, uint04 y) {
89 return particles[y * size[X] + x];
90 }
91 const Particle& getParticle(uint04 x, uint04 y) const {
92 return particles[y * size[X] + x];
93 }
94 const RGBColor& getColor(uint04 index)
95 {
96 return m_colors[index];
97 }
98 void setColor(uint04 index, RGBColor color)
99 {
100 m_colors[index] = color;
101 }
102 uint04 get1DIndex(uint04 x, uint04 y) const
103 {
104 return y * size[X] + x;
105 }
106 Vector<2, uint04> get2DIndex(uint04 index) const
107 {
108 return Vector<2, uint04>(index % size[X], index / size[X]);
109 }
110 Vector<3, fltp04> getNormalAt(const Vector<2, uint04>& index) const;
111 public:
112
113 uint04 getSize() {
114 return size[X] * size[Y];
115 }
116
117
118 inline Buffer<fltp04>& getHeightvals() {
119 return heightvals;
120 }
121
122 Particle& getParticle1d(uint04 index) {
123 return particles[index];
124 }
125 [[nodiscard]] const Buffer<Particle>& getParticles() const
126 {
127 return particles;
128 }
129 public:
130 Cloth(const Vector<3, fltp04>& origin_pos, const Vector<2, uint04>& size, const Vector<2, fltp04>& step, fltp04 smoothThreshold
131 , fltp04 heightThreshold, uint04 rigidness, fltp04 time_step, bool use_colors);
132 void adjustParticleByNeighbor(Particle& p1, Particle& p2);
133
134 /* this is an important methods where the time is progressed one
135 * time step for the entire cloth. This includes calling
136 * satisfyConstraint() for every constraint, and calling
137 * timeStep() for all particles
138 */
139 void timeStep();
140
141 /* used to add gravity (or any other arbitrary vector) to all
142 * particles */
143 void addForce(const Vector<3, fltp04> direction);
144
145 void terrCollision();
146
147 void movableFilter();
148
149 void fillHoles();
150 Buffer<uint04> findUnmovablePoint(Buffer<Vector<2, uint04>> connected);
151
152 void handle_slop_connected(const Buffer<uint04>& edgePoints, const Buffer<Vector<2, uint04>>& connected, const Buffer<Buffer<uint04>>& neibors);
153 };
154
155
156}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Vertex< 3, fltp04 > origin_pos
Origin position of the cloth in world space.
Definition Cloth.h:84
Buffer< fltp04 > heightvals
Height values from the terrain rasterization.
Definition Cloth.h:86
Vector< 2, uint04 > size
Number of particles in X and Y dimensions.
Definition Cloth.h:87
fltp04 step_y
Step size between particles in X and Y directions.
Definition Cloth.h:85
Used with CSF Cloth, The particle class represents a particle of mass that can move around in 3D spac...
Definition Particle.h:69
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...