1
2
3
4
5
6
7#ifndef pdomain_h
8#define pdomain_h
9
10#include "Particle/pDeclarations.h"
11#include "Particle/pError.h"
12#include "Particle/pVec.h"
13
14#include <string>
15#include <vector>
16
18
19#define P_PLANAR_EPSILON 1e-3f
20
21
35};
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
56public:
57#define P_N_FLOATS_IN_DOMAIN 30
61 virtual float Size()
const = 0;
62
64};
65
66namespace {
67
69{
71
72 float det = 1.0f /
74
79}
80};
81
82
83
84
85
86
87
88
89
90
91
92
96
98 {
101 }
102
104 {
109 }
110
112 {
118 }
119
120
121
122
124 {
127 for (std::vector<std::shared_ptr<
pDomain>>::const_iterator it = DomList.begin(); it != DomList.end(); it++) {
130 }
131 }
132
133
135 {
138 for (std::vector<std::shared_ptr<
pDomain>>::const_iterator it = P
.Doms.begin(); it != P
.Doms.end(); it++) {
141 }
142 }
143
144
146 {
149 }
150
152 {
153 for (std::vector<std::shared_ptr<
pDomain>>::const_iterator it =
Doms.begin(); it !=
Doms.end(); it++)
154 if ((*it)->
Within(pos
))
return true;
155 return false;
156 }
157
159 {
161 for (std::vector<std::shared_ptr<
pDomain>>::const_iterator it =
Doms.begin(); it !=
Doms.end(); it++) {
162 PastProb += (*it)->
Size();
163 if (Choose <= PastProb)
return (*it)->
Generate();
164 }
166 }
167
169
171};
172
173
174
175
178
180 {
183 }
184
186
188 {
190 }
191
193 {
195 }
196
198
200};
201
202
203
204
205
206
210
212 {
215 }
216
218 {
225 }
226
228 {
232 return dif < 1e-7f;
233 }
234
236 {
238 }
239
241
243};
244
245
246
247
248
249
250
251
255
257 {
260 }
261
263 {
267
272
275
277
279
280
284 }
285
287 {
290
292
293
294
297
298
299 return !(upos < 0 || vpos < 0 || (upos + vpos) > 1);
300 }
301
303 {
307 if (r1 + r2 < 1.0f)
309 else
310 pos =
p + u * (1.0f - r1)
+ v * (1.0f - r2);
311
312 return pos;
313 }
314
316
318};
319
320
321
322
323
324
328
330 {
333 }
334
336 {
340
345
348
350
352
353
357 }
358
360 {
363
365
366
367
370
371
372 return !(upos < 0 || upos > 1 || vpos < 0 || vpos > 1);
373 }
374
376 {
378 return pos;
379 }
380
382
384};
385
386
387
388
389
390
391
395
397 {
398 if (InnerRadius < 0 || OuterRadius < 0)
throw PErrInvalidValue("Can't have negative radius.");
399
402 }
403
405 {
409
410 if (OuterRadius > InnerRadius) {
413 } else {
416 }
417
421
422
425
426
427
432
435 else
437 }
438
440 {
443
445
448 }
449
451 {
452
454
456
457 float x = r * cosf(theta);
458 float y = r * sinf(theta);
459
461 return pos;
462 }
463
465 {
466 return 1.0f;
467 }
468
470};
471
472
473
474
475
476
477
481
483 {
486 }
487
489 {
494 }
495
496
497
500 {
502 }
503
504
506 {
508 }
509
511 {
512 return 1.0f;
513 }
514
516};
517
518
519
520
521
522
524
527
529 {
532 }
533
535 {
541 }
545 }
549 }
550
553 }
554
556 {
558 }
559
561 {
562
564 }
565
567
569};
570
571
572
573
574
575
576
581
583 {
584 if (InnerRadius < 0 || OuterRadius < 0)
throw PErrInvalidValue("Can't have negative radius.");
585
588 }
589
591 {
594
595 if (OuterRadius < InnerRadius) {
598 } else {
601 }
602
605
608
609
610
613 float len = sqrtf(axisLenSqr);
616
617
619 if (fabsf(
dot(basis
, n
)) > 0.999f) basis =
pVec(0.0f
, 1.0f
, 0.0f
);
620
621
622
626
630 else
631 vol = EndCapArea * len;
632 }
633
635 {
636
637
638
639
640
641
642
643
644
646
647
649 if (dist < 0.0f || dist > 1.0f) return false;
650
651
654
656 }
657
659 {
662
664
665
666 float x = r * cosf(theta);
667 float y = r * sinf(theta);
668
670 return pos;
671 }
672
674 {
676 }
677
679};
680
681
682
683
684
685
686
687
688
689
694
696 {
697 if (InnerRadius < 0 || OuterRadius < 0)
throw PErrInvalidValue("Can't have negative radius.");
698
701 }
702
704 {
707
708 if (OuterRadius < InnerRadius) {
711 } else {
714 }
715
718
721
722
723
726 float len = sqrtf(axisLenSqr);
729
730
732 if (fabsf(
dot(basis
, n
)) > 0.999f) basis =
pVec(0.0f
, 1.0f
, 0.0f
);
733
734
735
739
742 else {
745 vol = OuterVol - InnerVol;
746 }
747 }
748
750 {
751
752
753
754
755
756
757
758
759
760
762
763
764
766 if (dist < 0.0f || dist > 1.0f) return false;
767
768
771
773 }
774
776 {
779
781
782
783 float x = r * cosf(theta);
784 float y = r * sinf(theta);
785
786
787 x *= dist;
788 y *= dist;
789
791 return pos;
792 }
793
795 {
797 }
798
800};
801
802
803
804
805
806
807
812
814 {
815 if (InnerRadius < 0 || OuterRadius < 0)
throw PErrInvalidValue("Can't have negative radius.");
816
819 }
820
822 {
824
825 if (OuterRadius < InnerRadius) {
828 } else {
831 }
832
835
838
841 else {
844 vol = OuterVol - InnerVol;
845 }
846 }
847
849 {
853 }
854
856 {
858
859 do {
863
864
867 else
869
870 return pos;
871 }
872
874 {
876 }
877
879};
880
881
882
883
884
885
886
890
892 {
895 }
896
898 {
901 float oneOverSigma = 1.0f / (
stdev + 0.000000000001f);
904 }
905
907 {
911 }
912
914 {
916 }
917
919 {
920 return 1.0f;
921 }
922
924};
925};
926
927#endif
A representation of a region of space.
Definition: pDomain.h:55
virtual float Size() const =0
Returns the size of the domain (length, area, or volume).
virtual pVec Generate() const =0
Returns a random point in the domain.
pDomainType_E Which
Definition: pDomain.h:58
virtual bool Within(const pVec &) const =0
Returns true if the given point is within the domain.
virtual std::shared_ptr< pDomain > copy() const =0
A single-precision floating point three-vector.
Definition: pVec.h:63
friend pVec CompMult(const pVec &a, const pVec &b)
Definition: pVec.h:159
float normalize(const float toLen=1.f)
Definition: pVec.h:84
pVec(float ax, float ay, float az)
Definition: pVec.h:67
pVec operator+(const pVec &a) const
Definition: pVec.h:106
pVec operator*(const float s) const
Definition: pVec.h:98
friend float dot(const pVec &a, const pVec &b)
Definition: pVec.h:95
const float & x() const
Definition: pVec.h:72
float & y()
Definition: pVec.h:77
pVec operator-(const pVec &a) const
Definition: pVec.h:108
bool operator==(const pVec &a) const
Definition: pVec.h:110
pVec & operator*=(const float a)
Definition: pVec.h:136
float & x()
Definition: pVec.h:76
float length() const
Definition: pVec.h:80
const float & y() const
Definition: pVec.h:73
float lenSqr() const
Definition: pVec.h:82
pVec operator/(const float s) const
Definition: pVec.h:100
const float & z() const
Definition: pVec.h:74
float & z()
Definition: pVec.h:78
friend pVec Cross(const pVec &a, const pVec &b)
Definition: pVec.h:161
PAPIClasses.h.
Definition: pAPIContext.h:16
float pRandf()
Definition: pVec.h:34
pDomainType_E
Enums for the different types of domains that can be stored in a pDomain.
Definition: pDomain.h:22
@ PDCylinder_e
Definition: pDomain.h:31
@ PDPlane_e
Definition: pDomain.h:29
@ PDBlob_e
Definition: pDomain.h:34
@ PDCone_e
Definition: pDomain.h:32
@ PDTriangle_e
Definition: pDomain.h:26
@ PDPoint_e
Definition: pDomain.h:24
@ PDDisc_e
Definition: pDomain.h:28
@ PDSphere_e
Definition: pDomain.h:33
@ PDRectangle_e
Definition: pDomain.h:27
@ PDBox_e
Definition: pDomain.h:30
@ PDLine_e
Definition: pDomain.h:25
@ PDUnion_e
Definition: pDomain.h:23
pVec pNRandVec(float sigma)
Definition: pVec.h:179
const float P_ONEOVERSQRT2PI
Definition: pVec.h:25
float fsqr(float f)
Definition: pVec.h:27
pVec pRandVec()
Definition: pVec.h:177
#define P_PLANAR_EPSILON
< How small the dot product must be to declare that a point is in a plane for Within().
Definition: pDomain.h:19
#define PINLINE
Definition: pVec.h:20
#define M_PI
PVec.h - yet another 3D vector class.
Definition: pVec.h:14
Gaussian blob.
Definition: pDomain.h:887
float Scale2
Definition: pDomain.h:889
PDBlob(const pVec &Center, const float StandardDev)
Definition: pDomain.h:891
void PDBlob_Cons(const pVec &Center, const float StandardDev)
Definition: pDomain.h:897
float Size() const
Returns the probability density integral, which is 1.0.
Definition: pDomain.h:918
float Scale1
Definition: pDomain.h:889
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:923
float stdev
Definition: pDomain.h:889
pVec ctr
Definition: pDomain.h:888
bool Within(const pVec &pos) const
Has a probability of returning true equal to the probability density at the specified point.
Definition: pDomain.h:906
pVec Generate() const
Returns a point with normal probability density.
Definition: pDomain.h:913
Axis-aligned bounding box (AABB)
Definition: pDomain.h:523
void PDBox_Cons(const pVec &e0, const pVec &e1)
Definition: pDomain.h:534
pVec dif
Definition: pDomain.h:525
pVec p0
Definition: pDomain.h:525
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:566
float vol
Definition: pDomain.h:526
PDBox(const pVec &e0, const pVec &e1)
Definition: pDomain.h:528
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:568
pVec p1
Definition: pDomain.h:525
bool Within(const pVec &pos) const
Returns true if the point is in the box.
Definition: pDomain.h:555
pVec Generate() const
Returns a random point in this box.
Definition: pDomain.h:560
Cone.
Definition: pDomain.h:690
float radInSqr
Definition: pDomain.h:692
float radOutSqr
Definition: pDomain.h:692
bool ThinShell
Definition: pDomain.h:693
float radIn
Definition: pDomain.h:692
float radOut
Definition: pDomain.h:692
void PDCone_Cons(const pVec &e0, const pVec &e1, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:703
pVec u
Definition: pDomain.h:691
float axisLenInvSqr
Definition: pDomain.h:692
float Size() const
Returns the thick conical shell volume or the thin conical shell area if OuterRadius==InnerRadius.
Definition: pDomain.h:794
pVec v
Definition: pDomain.h:691
float vol
Definition: pDomain.h:692
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:799
PDCone(const pVec &e0, const pVec &e1, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:695
pVec axis
Definition: pDomain.h:691
pVec apex
Definition: pDomain.h:691
float radDif
Definition: pDomain.h:692
bool Within(const pVec &pos) const
Returns true if the point is within the conical shell.
Definition: pDomain.h:749
pVec Generate() const
Returns a random point in the conical shell.
Definition: pDomain.h:775
Cylinder.
Definition: pDomain.h:577
float radInSqr
Definition: pDomain.h:579
float radOutSqr
Definition: pDomain.h:579
bool ThinShell
Definition: pDomain.h:580
float radIn
Definition: pDomain.h:579
float radOut
Definition: pDomain.h:579
pVec u
Definition: pDomain.h:578
float axisLenInvSqr
Definition: pDomain.h:579
float Size() const
Returns the thick cylindrical shell volume or the thin cylindrical shell area if OuterRadius==InnerRa...
Definition: pDomain.h:673
pVec v
Definition: pDomain.h:578
float vol
Definition: pDomain.h:579
void PDCylinder_Cons(const pVec &e0, const pVec &e1, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:590
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:678
pVec axis
Definition: pDomain.h:578
pVec apex
Definition: pDomain.h:578
PDCylinder(const pVec &e0, const pVec &e1, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:582
float radDif
Definition: pDomain.h:579
bool Within(const pVec &pos) const
Returns true if the point is within the cylindrical shell.
Definition: pDomain.h:634
pVec Generate() const
Returns a random point in the cylindrical shell.
Definition: pDomain.h:658
Arbitrarily-oriented disc.
Definition: pDomain.h:392
PDDisc(const pVec &Center, const pVec Normal, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:396
float radInSqr
Definition: pDomain.h:394
float radOutSqr
Definition: pDomain.h:394
float radIn
Definition: pDomain.h:394
float radOut
Definition: pDomain.h:394
pVec p
Definition: pDomain.h:393
float dif
Definition: pDomain.h:394
pVec u
Definition: pDomain.h:393
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:464
pVec v
Definition: pDomain.h:393
float area
Definition: pDomain.h:394
float D
Definition: pDomain.h:394
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:469
void PDDisc_Cons(const pVec &Center, const pVec Normal, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:404
pVec nrm
Definition: pDomain.h:393
bool Within(const pVec &pos) const
Returns true for points within epsilon of the disc.
Definition: pDomain.h:439
pVec Generate() const
Returns a point inside the disc shell.
Definition: pDomain.h:450
A line segment.
Definition: pDomain.h:207
pVec vecNrm
Definition: pDomain.h:208
pVec p0
Definition: pDomain.h:208
pVec vec
Definition: pDomain.h:208
void PDLine_Cons(const pVec &e0, const pVec &e1)
Definition: pDomain.h:217
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:240
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:242
pVec p1
Definition: pDomain.h:208
PDLine(const pVec &e0, const pVec &e1)
Definition: pDomain.h:211
float len
Definition: pDomain.h:209
bool Within(const pVec &pos) const
Returns true for points within epsilon of the line segment.
Definition: pDomain.h:227
pVec Generate() const
Returns a random point on this segment.
Definition: pDomain.h:235
Arbitrarily-oriented plane.
Definition: pDomain.h:478
pVec p
Definition: pDomain.h:479
void PDPlane_Cons(const pVec &p0, const pVec &Normal)
Definition: pDomain.h:488
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:510
float D
Definition: pDomain.h:480
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:515
pVec nrm
Definition: pDomain.h:479
PDPlane(const pVec &p0, const pVec &Normal)
Definition: pDomain.h:482
bool Within(const pVec &pos) const
Returns true if the point is in the positive half-space of the plane (in the plane or on the side tha...
Definition: pDomain.h:499
pVec Generate() const
Returns the point p0.
Definition: pDomain.h:505
A single point.
Definition: pDomain.h:176
void PDPoint_Cons(const pVec &p0)
Definition: pDomain.h:185
pVec p
Definition: pDomain.h:177
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:197
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:199
PDPoint(const pVec &p0)
Definition: pDomain.h:179
bool Within(const pVec &pos) const
Returns true if the point is exactly equal.
Definition: pDomain.h:187
pVec Generate() const
Returns the point.
Definition: pDomain.h:192
Rhombus-shaped planar region.
Definition: pDomain.h:325
float uLen
Definition: pDomain.h:327
void PDRectangle_Cons(const pVec &p0, const pVec &u0, const pVec &v0)
Definition: pDomain.h:335
pVec uNrm
Definition: pDomain.h:326
pVec p
Definition: pDomain.h:326
pVec vNrm
Definition: pDomain.h:326
pVec u
Definition: pDomain.h:326
float vLen
Definition: pDomain.h:327
PDRectangle(const pVec &p0, const pVec &u0, const pVec &v0)
Definition: pDomain.h:329
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:381
pVec v
Definition: pDomain.h:326
float area
Definition: pDomain.h:327
float D
Definition: pDomain.h:327
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:383
pVec nrm
Definition: pDomain.h:326
pVec s1
Definition: pDomain.h:326
pVec s2
Definition: pDomain.h:326
bool Within(const pVec &pos) const
Returns true for points within epsilon of the patch.
Definition: pDomain.h:359
pVec Generate() const
Returns a random point in the diamond-shaped patch whose corners are o, o+u, o+u+v,...
Definition: pDomain.h:375
Sphere.
Definition: pDomain.h:808
float radInSqr
Definition: pDomain.h:810
float radOutSqr
Definition: pDomain.h:810
bool ThinShell
Definition: pDomain.h:811
float radIn
Definition: pDomain.h:810
float radOut
Definition: pDomain.h:810
void PDSphere_Cons(const pVec &Center, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:821
float Size() const
Returns the thick spherical shell volume or the thin spherical shell area if OuterRadius==InnerRadius...
Definition: pDomain.h:873
float vol
Definition: pDomain.h:810
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:878
PDSphere(const pVec &Center, const float OuterRadius, const float InnerRadius=0.0f)
Definition: pDomain.h:813
float radDif
Definition: pDomain.h:810
pVec ctr
Definition: pDomain.h:809
bool Within(const pVec &pos) const
Returns true if the point lies within the thick shell.
Definition: pDomain.h:848
pVec Generate() const
Returns a random point in the thick spherical shell.
Definition: pDomain.h:855
A Triangle.
Definition: pDomain.h:252
float uLen
Definition: pDomain.h:254
PDTriangle(const pVec &p0, const pVec &p1, const pVec &p2)
Definition: pDomain.h:256
pVec uNrm
Definition: pDomain.h:253
pVec p
Definition: pDomain.h:253
pVec vNrm
Definition: pDomain.h:253
pVec u
Definition: pDomain.h:253
float vLen
Definition: pDomain.h:254
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:315
pVec v
Definition: pDomain.h:253
float area
Definition: pDomain.h:254
float D
Definition: pDomain.h:254
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:317
pVec nrm
Definition: pDomain.h:253
pVec s1
Definition: pDomain.h:253
pVec s2
Definition: pDomain.h:253
bool Within(const pVec &pos) const
Returns true for points within epsilon of the triangle.
Definition: pDomain.h:286
pVec Generate() const
Returns a random point in the triangle.
Definition: pDomain.h:302
void PDTriangle_Cons(const pVec &p0, const pVec &p1, const pVec &p2)
Definition: pDomain.h:262
A CSG union of multiple domains.
Definition: pDomain.h:93
PDUnion(const std::vector< std::shared_ptr< pDomain > > &DomList)
Makes a copy of all the subdomains and point to the copies.
Definition: pDomain.h:123
PDUnion()
Use this one to create an empty PDUnion then call .insert() to add each item to it.
Definition: pDomain.h:97
PDUnion(const pDomain &A, const pDomain &B, const pDomain &C)
Definition: pDomain.h:111
PDUnion(const pDomain &A, const pDomain &B)
Definition: pDomain.h:103
std::vector< std::shared_ptr< pDomain > > Doms
Definition: pDomain.h:94
float Size() const
Returns the size of the domain (length, area, or volume).
Definition: pDomain.h:168
std::shared_ptr< pDomain > copy() const
Definition: pDomain.h:170
void insert(const pDomain &A)
Insert another domain into this PDUnion.
Definition: pDomain.h:145
PDUnion(const PDUnion &P)
Makes a copy of all the subdomains and point to the copies.
Definition: pDomain.h:134
float TotalSize
Definition: pDomain.h:95
bool Within(const pVec &pos) const
Returns true if pos is within any of the domains.
Definition: pDomain.h:151
pVec Generate() const
Generate a point in any subdomain, chosen by the ratio of their sizes.
Definition: pDomain.h:158
Internal API error (a PASSERT failed)
Definition: pError.h:28
PErrInternalError(const std::string Er)
Definition: pError.h:29
An invalid value was passed to an API call.
Definition: pError.h:40
PErrInvalidValue(const std::string Er)
Definition: pError.h:41