Titan
v1.0
A high-performance CUDA-based physics simulation sandbox for robotics, physics, and reinforcement learning.
|
Go to the documentation of this file.
22 Vec3D(
double x,
double y,
double z);
45 double data[3] = { 0 };
89 return Vec3D(-data[0], -data[1], -data[2]);
94 return Vec3D(v1.data[0] + v2.data[0], v1.data[1] + v2.data[1], v1.data[2] + v2.data[2]);
98 return Vec3D(v1.data[0] - v2.data[0], v1.data[1] - v2.data[1], v1.data[2] - v2.data[2]);
102 return Vec3D(v.data[0] * x, v.data[1] * x, v.data[2] * x);
110 return Vec3D(v1.data[0] * v2.data[0], v1.data[1] * v2.data[1], v1.data[2] * v2.data[2]);
114 return Vec3D(v.data[0] / x, v.data[1] / x, v.data[2] / x);
118 return Vec3D(v1.data[0] / v2.data[0], v1.data[1] / v2.data[1], v1.data[2] / v2.data[2]);
122 return strm <<
"(" << v[0] <<
", " << v[1] <<
", " << v[2] <<
")";
126 if (n < 0 || n >= 3) {
127 std::cerr << std::endl <<
"Out of bounds" << std::endl;
135 if (n < 0 || n >= 3) {
136 std::cerr << std::endl <<
"Out of bounds" << std::endl;
144 return sqrt(pow(data[0], 2) + pow(data[1], 2) + pow(data[2], 2));
148 return data[0] + data[1] + data[2];
152 return (a * b).sum();
156 return Vec3D(v1[1] * v2[2] - v1[2] * v2[1], v2[0] * v1[2] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]);
190 bool inside(
const Vec3D & point,
int num_rays = 10);
194 double min[3] = {DBL_MIN};
195 double max[3] = {DBL_MIN};
198 for (
int i = 0; i < 3; i++) {
199 min[i] = fmin(t.v1[i], min[i]);
200 max[i] = fmax(t.v1[i], max[i]);
202 min[i] = fmin(t.v2[i], min[i]);
203 max[i] = fmax(t.v2[i], max[i]);
205 min[i] = fmin(t.v3[i], min[i]);
206 max[i] = fmax(t.v3[i], max[i]);
210 return BBox(
Vec3D((max[0] - min[0]) / 2 + min[0], (max[1] - min[1]) / 2 + min[1], (max[2] - min[2]) / 2 + min[2]), max[0] - min[0], max[1] - min[1], max[2] - min[2]);
217 double a =
dot(edge1, h);
221 if (a > -EPSILON && a < EPSILON)
226 double u = f *
dot(s, h);
228 if (u < 0 || u > 1.0)
234 double v = f *
dot(ray, q);
236 if (v < 0 || u + v > 1.0)
241 if (f *
dot(edge2, q) > EPSILON)
248 return min + (double) rand() / RAND_MAX * (max - min);
255 const double EPSILON = 0.000001;
257 for (
int i = 0; i < num_rays; i++) {
259 ray = ray / ray.
norm();
267 if (count % 2 == 1) {
276 double fraction = (double) ray_count / (
double) num_rays;
280 if (fraction > 0.5) {
289 file.read(triangle, 12);
290 return Vec3D(*(
float *) (triangle), *(
float *) (triangle + 4), *(
float *) (triangle + 8));
294 strm <<
"Normal : " << t.
normal << std::endl;
295 strm <<
"Vertex 1 : " << t.
v1 << std::endl;
296 strm <<
"Vertex 2 : " << t.
v2 << std::endl;
297 strm <<
"Vertex 3 : " << t.
v3 << std::endl;
302 std::ifstream file(path.c_str(), std::ios::in | std::ios::binary);
305 std::cerr <<
"ERROR: COULD NOT READ FILE." << std::endl;
308 std::cout <<
"File found. Parsing STL file." << std::endl;
312 char num_triangles[4];
313 file.read(header, 80);
314 file.read(num_triangles, 4);
317 data.
header = std::string(header);
328 file.read(properties, 2);
331 std::cout <<
"Found " << data.
num_triangles <<
" triangles. Parsing complete!" << std::endl;
333 assert((file.peek(), file.eof()));
341 #endif //STL_PARSER_H
double randDouble(double min, double max)
Definition: stlparser.h:247
friend Vec3D operator+(const Vec3D &x, const Vec3D &y)
Definition: stlparser.h:93
BBox(const Vec3D ¢er, double x, double y, double z)
Definition: stlparser.h:173
friend std::ostream & operator<<(std::ostream &, Triangle &t)
Definition: stlparser.h:293
Vec3D & operator=(const Vec3D &v)
Definition: stlparser.h:69
Definition: stlparser.h:159
friend Vec3D operator/(const Vec3D &v, const double x)
Definition: stlparser.h:113
BBox getBoundingBox()
Definition: stlparser.h:193
double & operator[](int n)
Definition: stlparser.h:125
Vec3D & operator+=(const Vec3D &v)
Definition: stlparser.h:81
std::ostream & operator<<(std::ostream &strm, const Vec3D &v)
Definition: stlparser.h:121
Vec3D v3
Definition: stlparser.h:169
Vec3D v2
Definition: stlparser.h:168
Vec3D normal
Definition: stlparser.h:166
Vec3D v1
Definition: stlparser.h:167
Triangle(const Vec3D &n, const Vec3D &vertex1, const Vec3D &vertex2, const Vec3D &vertex3)
Definition: stlparser.h:160
std::string header
Definition: stlparser.h:185
Vec3D operator*(const double x, const Vec3D &v)
Definition: stlparser.h:101
Definition: stlparser.h:184
std::vector< Triangle > triangles
Definition: stlparser.h:187
Vec3D operator-() const
Definition: stlparser.h:88
double xdim
Definition: stlparser.h:181
double norm() const
Definition: stlparser.h:143
Vec3D cross(const Vec3D &v1, const Vec3D &v2)
Definition: stlparser.h:155
Definition: stlparser.h:172
friend Vec3D operator*(const Vec3D &v, const double x)
Definition: stlparser.h:105
double dot(const Vec3D &a, const Vec3D &b)
Definition: stlparser.h:151
double ydim
Definition: stlparser.h:181
Vec3D operator+(const Vec3D &v1, const Vec3D &v2)
Definition: stlparser.h:93
Vec3D parseVec(std::ifstream &file)
Definition: stlparser.h:287
double sum() const
Definition: stlparser.h:147
Definition: stlparser.h:18
Vec3D()
Definition: stlparser.h:51
stlFile parseSTL(std::string path)
Definition: stlparser.h:301
Vec3D operator-(const Vec3D &v1, const Vec3D &v2)
Definition: stlparser.h:97
Vec3D center
Definition: stlparser.h:180
friend std::ostream & operator<<(std::ostream &, const Vec3D &)
Definition: stlparser.h:121
int num_triangles
Definition: stlparser.h:186
double zdim
Definition: stlparser.h:181
bool intersect(const Vec3D &point, const Vec3D &ray, const Triangle &t, double EPSILON)
Definition: stlparser.h:213
Vec3D operator/(const Vec3D &v, const double x)
Definition: stlparser.h:113
bool inside(const Vec3D &point, int num_rays=10)
Definition: stlparser.h:251