PeriDyno 0.9.2
Loading...
Searching...
No Matches
StaticBoundary.cpp
Go to the documentation of this file.
1#include "StaticBoundary.h"
2#include "Log.h"
3#include "Node.h"
4
6
8#include "Topology/TriangleSet.h"
9
10namespace dyno
11{
12 IMPLEMENT_TCLASS(StaticBoundary, TDataType)
13
14 template<typename TDataType>
16 : Node()
17 {
18 this->varNormalFriction()->setValue(0.95);
19 this->varTangentialFriction()->setValue(0.0);
20 }
21
22 template<typename TDataType>
26
27// template<typename TDataType>
28// bool StaticBoundary<TDataType>::addRigidBody(std::shared_ptr<RigidBody<TDataType>> child)
29// {
30// this->addChild(child);
31// m_rigids.push_back(child);
32// return true;
33// }
34
35// template<typename TDataType>
36// bool StaticBoundary<TDataType>::addParticleSystem(std::shared_ptr<ParticleSystem<TDataType>> child)
37// {
38// this->addChild(child);
39// m_particleSystems.push_back(child);
40//
41// this->inportParticleSystems()->addNode(child);
42//
43// return true;
44// }
45
46 template<typename TDataType>
48 {
49
50
51 Real dt = this->stateTimeStep()->getData();
52
53 auto pSys = this->getParticleSystems();
54
55 for (size_t t = 0; t < m_obstacles.size(); t++)
56 {
57 for (int i = 0; i < pSys.size(); i++)
58 {
59 auto posFd = pSys[i]->statePosition();
60 auto velFd = pSys[i]->stateVelocity();
61 if (!posFd->isEmpty() && !velFd->isEmpty())
62 {
63 m_obstacles[t]->varNormalFriction()->setValue(this->varNormalFriction()->getValue());
64 m_obstacles[t]->varTangentialFriction()->setValue(this->varTangentialFriction()->getValue());
65 m_obstacles[t]->constrain(posFd->getData(), velFd->getData(), dt);
66 }
67
68 }
69 }
70 }
71
72 template<typename TDataType>
74 {
75 auto boundary = std::make_shared<BoundaryConstraint<TDataType>>();
77
78 this->varNormalFriction()->connect(boundary->varNormalFriction());
79 this->varTangentialFriction()->connect(boundary->varTangentialFriction());
80
81 m_obstacles.push_back(boundary);
82 }
83
84
85 template<typename TDataType>
86 std::shared_ptr<Node> StaticBoundary<TDataType>::loadCube(Coord lo, Coord hi, Real distance, bool bOutBoundary /*= false*/)
87 {
88 auto boundary = std::make_shared<BoundaryConstraint<TDataType>>();
89 boundary->setCube(lo, hi, distance, bOutBoundary);
90
91 this->varNormalFriction()->connect(boundary->varNormalFriction());
92 this->varTangentialFriction()->connect(boundary->varTangentialFriction());
93
94 m_obstacles.push_back(boundary);
95
96 //Note: the size of standard cube is 2m*2m*2m
97 Coord scale = (hi - lo) / 2;
98 Coord center = (hi + lo) / 2;
99
100 return nullptr;
101 }
102
103 template<typename TDataType>
104 void StaticBoundary<TDataType>::loadShpere(Coord center, Real r, Real distance, bool bOutBoundary /*= false*/, bool bVisible)
105 {
106 auto boundary = std::make_shared<BoundaryConstraint<TDataType>>();
107 boundary->setSphere(center, r, distance, bOutBoundary);
108
109 this->varNormalFriction()->connect(boundary->varNormalFriction());
110 this->varTangentialFriction()->connect(boundary->varTangentialFriction());
111
112 m_obstacles.push_back(boundary);
113 }
114
115
116 template<typename TDataType>
118 {
119 for (int i = 0; i < m_obstacles.size(); i++)
120 {
121 m_obstacles[i]->m_cSDF->scale(s);
122 }
123 }
124
125 template<typename TDataType>
127 {
128 for (int i = 0; i < m_obstacles.size(); i++)
129 {
130 m_obstacles[i]->m_cSDF->translate(t);
131 }
132 }
133
134
135
136 template<typename TDataType>
138 {
139 auto filename = this->varFileName()->getData();
140 }
141
143}
GPU supported signed distance field.
#define DEFINE_CLASS(name)
Definition Object.h:140
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
TDataType::Coord Coord
void loadShpere(Coord center, Real r, Real distance=0.005f, bool bOutBoundary=false, bool bVisible=false)
void loadSDF(std::string filename, bool bOutBoundary=false)
TDataType::Real Real
void updateStates() override
std::shared_ptr< Node > loadCube(Coord lo, Coord hi, Real distance=0.005f, bool bOutBoundary=false)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:24
ArrayMap< T, DeviceType::GPU > DArrayMap
Definition ArrayMap.inl:80