diff --git a/GUI/ba3d/ba3d/model/geometry.cpp b/GUI/ba3d/ba3d/model/geometry.cpp index 572ed7bafc6309305148cb8187c97a00209bd058..32505b57cad3964c70a4fe39083e3f4f61658413 100644 --- a/GUI/ba3d/ba3d/model/geometry.cpp +++ b/GUI/ba3d/ba3d/model/geometry.cpp @@ -59,32 +59,32 @@ void Geometry::Vertices::addFan(const Vertices& vs, const Indices& is) { //------------------------------------------------------------------------------ -Geometry::Geometry(geometry::key key_) : key(key_) { - using namespace geometry; +Geometry::Geometry(GeometricID::Key key_) : key(key_) { + using namespace GeometricID; switch (key.id) { - case eid::Plane: + case BaseShape::Plane: mesh = meshPlane(); break; - case eid::Box: + case BaseShape::Box: mesh = meshBox(); break; - case eid::Sphere: + case BaseShape::Sphere: mesh = meshSphere(key.p1); break; - case eid::Column: + case BaseShape::Column: mesh = meshColumn(key.p1, key.p2); break; - case eid::Icosahedron: + case BaseShape::Icosahedron: mesh = meshIcosahedron(); break; - case eid::Dodecahedron: + case BaseShape::Dodecahedron: mesh = meshDodecahedron(); break; - case eid::TruncatedBox: + case BaseShape::TruncatedBox: mesh = meshTruncBox(key.p1); break; - case eid::Cuboctahedron: + case BaseShape::Cuboctahedron: mesh = meshCuboctahedron(key.p1, key.p2); break; } @@ -127,7 +127,7 @@ Geometry::Mesh Geometry::makeMesh(const Vertices& vs, const Vertices& ns) { //------------------------------------------------------------------------------ -shGeo GeometryStore::getGeometry(geometry::key key) { +shGeo GeometryStore::getGeometry(GeometricID::Key key) { auto it = geometries.find(key); if (geometries.end() != it) { shGeo g = it->toStrongRef(); diff --git a/GUI/ba3d/ba3d/model/geometry.h b/GUI/ba3d/ba3d/model/geometry.h index 0932a15f0488e4597417034c928d099937ede230..bcdd0ca309215a7901dfa4683f81a6fea2d47150 100644 --- a/GUI/ba3d/ba3d/model/geometry.h +++ b/GUI/ba3d/ba3d/model/geometry.h @@ -46,21 +46,22 @@ public: using QVector::QVector; void addVertex(const Vector3D&, int n = 1); // add a vertex, possibly multiple copies - void addTriangle(const Vector3D&, const Vector3D&, const Vector3D&); // triangle - void addQuad(const Vector3D&, const Vector3D&, const Vector3D&, const Vector3D&); // quad as 2 triangles + void addTriangle(const Vector3D&, const Vector3D&, const Vector3D&); // triangle + void addQuad(const Vector3D&, const Vector3D&, + const Vector3D&, const Vector3D&); // quad as 2 triangles void addQuad(const Vertices&, idx, idx, idx, idx); - void addStrip(const Vertices&, const Indices&); // triangle strip - void addFan(const Vertices&, const Indices&); // triangle fan + void addStrip(const Vertices&, const Indices&); // triangle strip + void addFan(const Vertices&, const Indices&); // triangle fan }; // vertex/normal mesh using Mesh = QVector<Vert_Normal>; - Geometry(geometry::key); + Geometry(GeometricID::Key); virtual ~Geometry(); private: - geometry::key key; + GeometricID::Key key; Mesh mesh; // make a mesh from vectors of vertices on (optionally) normals @@ -87,13 +88,13 @@ class GeometryStore : public QObject { Q_OBJECT friend class Geometry; public: - shGeo getGeometry(geometry::key); + shGeo getGeometry(GeometricID::Key); signals: void deletingGeometry(Geometry const*); // signal to canvases private: - QHash<geometry::key,wkGeo> geometries; + QHash<GeometricID::Key,wkGeo> geometries; void geometryDeleted(Geometry const&); // ~Geometry() calls this }; diff --git a/GUI/ba3d/ba3d/model/geometry_inc.cpp b/GUI/ba3d/ba3d/model/geometry_inc.cpp index 2ee4d2503c5d3a213eea2ca590c4cf8ec2b1b7ac..76f2da2a64f39cb4fc1053ed2a49eabc431298ad 100644 --- a/GUI/ba3d/ba3d/model/geometry_inc.cpp +++ b/GUI/ba3d/ba3d/model/geometry_inc.cpp @@ -24,24 +24,24 @@ const float DodecahedronL2R = float(4 / qSqrt(3) / (1+qSqrt(5))); //------------------------------------------------------------------------------ -geometry::key::key(geometry::eid id) : key(id, 0, 0) {} +GeometricID::Key::Key(GeometricID::BaseShape id) : Key(id, 0, 0) {} -geometry::key::key(geometry::eid id, float p1) : key(id, p1, 0) {} +GeometricID::Key::Key(GeometricID::BaseShape id, float p1) : Key(id, p1, 0) {} -geometry::key::key(eid id_, float p1_, float p2_) +GeometricID::Key::Key(BaseShape id_, float p1_, float p2_) : id(id_), p1(p1_), p2(p2_) { } -bool geometry::key::operator==(key const& that) const { +bool GeometricID::Key::operator==(Key const& that) const { return id == that.id && p1 == that.p1 && p2 == that.p2; } -uint geometry::qHash(geometry::key const& key) { +uint GeometricID::qHash(GeometricID::Key const& key) { // the hash is simply a bitwise superposition of id, p1, p2 union { float f; quint32 u; - geometry::eid i; + GeometricID::BaseShape i; } id, p1, p2; id.i = key.id; p1.f = key.p1; p2.f = key.p2; diff --git a/GUI/ba3d/ba3d/model/geometry_inc.h b/GUI/ba3d/ba3d/model/geometry_inc.h index d13e8f109df9a8143dfc07c76642b1cdcd55b0ae..a8067303415d900c02346d2f0f5cc2ed7660ed04 100644 --- a/GUI/ba3d/ba3d/model/geometry_inc.h +++ b/GUI/ba3d/ba3d/model/geometry_inc.h @@ -33,27 +33,27 @@ extern const float GoldenRatio; extern const float IcosahedronL2R; // L/R conversion extern const float DodecahedronL2R; -namespace geometry { +namespace GeometricID { // geometry enumerated id -enum class eid { Plane, Box, Sphere, Column, +enum class BaseShape { Plane, Box, Sphere, Column, Icosahedron, Dodecahedron, TruncatedBox, Cuboctahedron }; // geometries may have 1 or 2 float parameters; together with eid -> hash key -struct key { - key(eid); - key(eid, float); - key(eid, float, float); +struct Key { + Key(BaseShape); + Key(BaseShape, float); + Key(BaseShape, float, float); - eid id; + BaseShape id; float p1, p2; - bool operator==(key const&) const; + bool operator==(Key const&) const; }; -uint qHash(key const&); +uint qHash(Key const&); } diff --git a/GUI/ba3d/ba3d/model/layer.cpp b/GUI/ba3d/ba3d/model/layer.cpp index 5e70b061053f21e8acbba251c50400d95175e5d9..d8b9fc667ecef99141333291b6f0bb59cd11173d 100644 --- a/GUI/ba3d/ba3d/model/layer.cpp +++ b/GUI/ba3d/ba3d/model/layer.cpp @@ -16,7 +16,7 @@ namespace RealSpace { -Layer::Layer(VectorRange d) : Object(geometry::key(geometry::eid::Box)) { +Layer::Layer(VectorRange d) : Object(GeometricID::Key(GeometricID::BaseShape::Box)) { transform(d.size(), Vector3D::_0, d.mid()); } diff --git a/GUI/ba3d/ba3d/model/object.cpp b/GUI/ba3d/ba3d/model/object.cpp index d43532f0b4707249dc6e1170870bbd07d3748f02..a329bd46e398b7c92623052fe88b597130fff773 100644 --- a/GUI/ba3d/ba3d/model/object.cpp +++ b/GUI/ba3d/ba3d/model/object.cpp @@ -26,7 +26,7 @@ QColor const clrObject = Qt::lightGray; QColor const clrObject = Qt::black; #endif -Object::Object(geometry::key gky_) : color(clrObject) +Object::Object(GeometricID::Key gky_) : color(clrObject) , isNull(false), model(nullptr), gky(gky_) { } diff --git a/GUI/ba3d/ba3d/model/object.h b/GUI/ba3d/ba3d/model/object.h index 1184ec47b90ff6213d85367b5f7d0d74770e1d9b..00def6fa0f257d9dd85f4b2aa0d6d96af40dfc8b 100644 --- a/GUI/ba3d/ba3d/model/object.h +++ b/GUI/ba3d/ba3d/model/object.h @@ -29,7 +29,7 @@ class Canvas; class Object { friend class Model; public: - Object(geometry::key); + Object(GeometricID::Key); virtual ~Object(); QColor color; @@ -45,7 +45,7 @@ protected: private: Model *model; - geometry::key gky; + GeometricID::Key gky; shGeo geo; // retrieved on demand void releaseGeometry(); // can be released whenever diff --git a/GUI/ba3d/ba3d/model/particles.cpp b/GUI/ba3d/ba3d/model/particles.cpp index 8a7c43b16b9f92871c496b3d0ab5c42f2fdb14c6..0fcf406be4508281c33bce9214a75c55e18ffe2c 100644 --- a/GUI/ba3d/ba3d/model/particles.cpp +++ b/GUI/ba3d/ba3d/model/particles.cpp @@ -32,9 +32,9 @@ QString const& name(EShape k) { //------------------------------------------------------------------------------ -using namespace geometry; +using namespace GeometricID; -Particle::Particle(key key) : Object(key), scale(Vector3D::_1) {} +Particle::Particle(Key key) : Object(key), scale(Vector3D::_1) {} void Particle::set() { transform(Vector3D::_0, Vector3D::_0); @@ -56,120 +56,120 @@ static float const sqrt2f = float(qSqrt(2)); static float const sqrt3f = float(qSqrt(3)); FullSphere::FullSphere(float R) -: Particle(key(eid::Sphere, 0)) { +: Particle(Key(BaseShape::Sphere, 0)) { isNull = (R <= 0); scale = Vector3D(R*2); offset = Vector3D(0, 0, R); set(); } FullSpheroid::FullSpheroid(float R, float H) -: Particle(key(eid::Sphere, 0)) { +: Particle(Key(BaseShape::Sphere, 0)) { isNull = (R <= 0 || H <= 0); scale = Vector3D(R*2, R*2, H); offset = Vector3D(0, 0, H/2); set(); } Cylinder::Cylinder(float R, float H) -: Particle(key(eid::Column, pi2f, 0)) { +: Particle(Key(BaseShape::Column, pi2f, 0)) { isNull = (R <= 0 || H <= 0); scale = Vector3D(R*2, R*2, H); offset = Vector3D(0, 0, H/2); set(); } TruncatedSphere::TruncatedSphere(float R, float H) -: Particle(key(eid::Sphere, 1 - H/R/2)) { +: Particle(Key(BaseShape::Sphere, 1 - H/R/2)) { isNull = (R <= 0 || H <= 0); scale = Vector3D(R*2); offset = Vector3D(0, 0, H-R); set(); } TruncatedSpheroid::TruncatedSpheroid(float R, float H, float fp) -: Particle(key(eid::Sphere, 1 - H/fp/R/2)) { +: Particle(Key(BaseShape::Sphere, 1 - H/fp/R/2)) { isNull = (R <= 0 || H <= 0 || fp <= 0); scale = Vector3D(R*2, R*2, fp*R*2); offset = Vector3D(0, 0, H-fp*R); set(); } Cone::Cone(float R, float H, float alpha) -: Particle(key(eid::Column, alpha, 0)) { +: Particle(Key(BaseShape::Column, alpha, 0)) { isNull = (R <= 0 || H <= 0 || alpha <= 0); scale = Vector3D(R*2, R*2, H); offset = Vector3D(0, 0, H/2); set(); } Icosahedron::Icosahedron(float L) -: Particle(key(eid::Icosahedron)) { +: Particle(Key(BaseShape::Icosahedron)) { isNull = (L <= 0); float R = L / IcosahedronL2R; scale = Vector3D(R*2, R*2, R*2); offset = Vector3D(0, 0, R); set(); } Dodecahedron::Dodecahedron(float L) -: Particle(key(eid::Dodecahedron)) { +: Particle(Key(BaseShape::Dodecahedron)) { isNull = (L <= 0); float R = L / DodecahedronL2R; scale = Vector3D(R*2, R*2, R*2); offset = Vector3D(0, 0, R); set(); } TruncatedCube::TruncatedCube(float L, float t) -: Particle(key(eid::TruncatedBox, 2*t/L)) { +: Particle(Key(BaseShape::TruncatedBox, 2*t/L)) { isNull = (L <= 0); scale = Vector3D(L,L,L); offset = Vector3D(0, 0, L/2); set(); } Prism6::Prism6(float R, float H) -: Particle(key(eid::Column, pi2f, 6)) { +: Particle(Key(BaseShape::Column, pi2f, 6)) { isNull = (R <= 0 || H <= 0); scale = Vector3D(R*2, R*2, H); offset = Vector3D(0, 0, H/2); set(); } Cone6::Cone6(float R, float H, float alpha) -: Particle(key(eid::Column, alpha, 6)) { +: Particle(Key(BaseShape::Column, alpha, 6)) { isNull = (R <= 0 || H <= 0 || alpha <= 0); scale = Vector3D(R*2, R*2, H); offset = Vector3D(0, 0, H/2); set(); } Pyramid::Pyramid(float L, float H, float alpha) -: Particle(key(eid::Column, alpha, 4)) { +: Particle(Key(BaseShape::Column, alpha, 4)) { isNull = (L <= 0 || H <= 0 || alpha <= 0); float L2 = L * sqrt2f; turn = Vector3D(0,0,45); scale = Vector3D(L2, L2, H); offset = Vector3D(0, 0, H/2); set(); } Cuboctahedron::Cuboctahedron(float L, float H, float rH, float alpha) -: Particle(key(eid::Cuboctahedron, rH, alpha)) { +: Particle(Key(BaseShape::Cuboctahedron, rH, alpha)) { isNull = (L <= 0 || H <= 0 || rH <= 0 || alpha <= pi2f); scale = Vector3D(L, L, L); offset = Vector3D(0, 0, L/2); set(); } Prism3::Prism3(float L, float H) -: Particle(key(eid::Column, pi2f, 3)) { +: Particle(Key(BaseShape::Column, pi2f, 3)) { isNull = (L <= 0 || H <= 0); float D = L*2 / sqrt3f; scale = Vector3D(D*2, D*2, H); offset = Vector3D(0, 0, H/2); set(); } Tetrahedron::Tetrahedron(float L, float H, float alpha) -: Particle(key(eid::Column, alpha, 3)) { +: Particle(Key(BaseShape::Column, alpha, 3)) { isNull = (L <= 0 || H <= 0 || alpha <= 0); float D = L*2 / sqrt3f; scale = Vector3D(D*2, D*2, H); offset = Vector3D(0, 0, H/2); set(); } EllipsoidalCylinder::EllipsoidalCylinder(float Ra, float Rb, float H) -: Particle(key(eid::Column, pi2f, 0)) { +: Particle(Key(BaseShape::Column, pi2f, 0)) { isNull = (Ra <= 0 || Rb <= 0 || H <= 0); scale = Vector3D(Ra*2, Rb*2, H); offset = Vector3D(0, 0, H/2); set(); } Box::Box(float L, float W, float H) -: Particle(key(eid::Column, pi2f, 4)) { +: Particle(Key(BaseShape::Column, pi2f, 4)) { isNull = (L < 0 || W < 0 || H < 0) || (L <= 0 && W <= 0 && H <= 0); turn = Vector3D(0,0,45); scale = Vector3D(L*sqrt2f, W*sqrt2f, H); offset = Vector3D(0, 0, H/2); set(); } HemiEllipsoid::HemiEllipsoid(float Ra, float Rb, float H) -: Particle(key(eid::Sphere, .5f)) { +: Particle(Key(BaseShape::Sphere, .5f)) { isNull = (Ra <= 0 || Rb <= 0 || H <= 0); scale = Vector3D(Ra*2, Rb*2, H*2); set(); } AnisoPyramid::AnisoPyramid(float L, float W, float H, float alpha) -: Particle(key(eid::Column, alpha, 4)) { +: Particle(Key(BaseShape::Column, alpha, 4)) { isNull = (L <= 0 || W <= 0 || H <= 0 || alpha <= 0); turn = Vector3D(0,0,45); scale = Vector3D(L*sqrt2f, W*sqrt2f, H); offset = Vector3D(0, 0, H/2); set(); } diff --git a/GUI/ba3d/ba3d/model/particles.h b/GUI/ba3d/ba3d/model/particles.h index 8e8a43613dc9e9434f109a10dd166a24b6f8897e..ab4f1f2e5aeecd2e963218802441044ebf2d3358 100644 --- a/GUI/ba3d/ba3d/model/particles.h +++ b/GUI/ba3d/ba3d/model/particles.h @@ -35,17 +35,17 @@ QString const& name(EShape); class Particle : public Object { protected: - Particle(geometry::key); - Vector3D turn, // turn before scale - scale, // geometries are of 1-size (box 1x1x1, sphere D=1), need scaling - offset, // geometries centered around origin; particles stand on z=0 plane - rotate, translate; // remembered + Particle(GeometricID::Key); + Vector3D turn; // turn before scale + Vector3D scale; // geometries are of 1-size (box 1x1x1, sphere D=1), need scaling + Vector3D offset; // geometries centered around origin; particles stand on z=0 plane + Vector3D rotate, translate; // remembered void set(); public: - static EShape const firstKind = EShape::None, - lastKind = EShape::AnisoPyramid; + static EShape const firstKind = EShape::None; + static EShape const lastKind = EShape::AnisoPyramid; void transform(Vector3D rotate, Vector3D translate); void fancy(Vector3D rotate, float r); diff --git a/GUI/ba3d/showcase/modelShowcase.cpp b/GUI/ba3d/showcase/modelShowcase.cpp index 73727865aeb6c082fb2117d77e92cca871255058..1ba05e38660fa2038572d945b0766456d3639094 100644 --- a/GUI/ba3d/showcase/modelShowcase.cpp +++ b/GUI/ba3d/showcase/modelShowcase.cpp @@ -27,12 +27,12 @@ ModelShowcase::ModelShowcase() : p(nullptr) { Object *o; // bounding box - addBlend(o = new Object(geometry::key(geometry::eid::Box))); + addBlend(o = new Object(GeometricID::Key(GeometricID::BaseShape::Box))); o->color = QColor(0, 255, 0, 50); o->transform(2*R, Vector3D::_0, Vector3D(0,0,R)); // bounding sphere - addBlend(o = new Object(geometry::key(geometry::eid::Sphere))); + addBlend(o = new Object(GeometricID::Key(GeometricID::BaseShape::Sphere))); o->color = QColor(0, 255, 255, 50); o->transform(2*R, Vector3D::_0, Vector3D(0,0,R)); }