19#define FARWAY_DISTANCE 10^6
21 template<
typename TDataType>
24 typedef typename TDataType::Real
Real;
25 typedef typename TDataType::Coord
Coord;
78 void loadSDF(std::string filename,
bool inverted =
false);
121 return (1.0f - alpha)*a + alpha *b;
145 template<
typename TDataType>
150 const int i = (int)floor(fp[0]);
151 const int j = (int)floor(fp[1]);
152 const int k = (int)floor(fp[2]);
161 Coord alphav = fp - ip;
162 Real alpha = alphav[0];
163 Real beta = alphav[1];
164 Real gamma = alphav[2];
175 Real dx00 =
lerp(d000, d100, alpha);
176 Real dx10 =
lerp(d010, d110, alpha);
179 Real dx01 =
lerp(d001, d101, alpha);
180 Real dx11 =
lerp(d011, d111, alpha);
185 Real d0yz =
lerp(d0y0, d0y1, gamma);
189 Real d1yz =
lerp(d1y0, d1y1, gamma);
191 Real dx0z =
lerp(dx00, dx01, gamma);
192 Real dx1z =
lerp(dx10, dx11, gamma);
194 normal[0] = d0yz - d1yz;
195 normal[1] = dx0z - dx1z;
196 normal[2] = dxy0 - dxy1;
198 Real l = normal.norm();
199 if (l < 0.0001f) normal =
Coord(0);
200 else normal = normal.normalize();
202 d = (1.0f - gamma) * dxy0 + gamma * dxy1;
void loadSphere(Coord ¢er, Real radius, bool inverted=false)
void loadSDF(std::string filename, bool inverted=false)
load signed distance field from a file
void translate(const Coord &t)
Translate the distance field with a displacement.
void loadCylinder(Coord ¢er, Real radius, Real height, int axis, bool inverted=false)
void setDistance(CArray3D< Real > distance)
DArray3D< Real > & distances()
GPU_FUNC void getDistance(const Coord &p, Real &d, Coord &normal)
Query the signed distance for p.
~DistanceField3D()
Should not release data here, call release() explicitly.
void loadBox(Coord &lo, Coord &hi, bool inverted=false)
load signed distance field from a Box (lo, hi)
Coord mOrigin
Lower left corner.
void assign(DistanceField3D< TDataType > &sdf)
void setSpace(const Coord p0, const Coord p1, Real h)
void release()
Release m_distance Should be explicitly called before destruction to avoid GPU memory leak.
DArray3D< Real > mDistances
Storing the signed distance field as a 3D array.
void invertSDF()
Invert the signed distance field.
DistanceField3D(std::string filename)
GPU_FUNC Real lerp(Real a, Real b, Real alpha) const
void scale(const Real s)
Scale the distance field.
This is an implementation of AdditiveCCD based on peridyno.
DYN_FUNC T lerp(Array< T, deviceType > &array1d, float x, LerpMode mode=LerpMode::REPEAT)
Array3D< T, DeviceType::GPU > DArray3D
Array3D< T, DeviceType::CPU > CArray3D