Browse Source

Point cloud addition

master
Trevor Irons 5 years ago
parent
commit
f6bf222991
5 changed files with 88 additions and 8 deletions
  1. 9
    8
      examples/DEMGrain.cpp
  2. 22
    0
      include/DEMGrain.h
  3. 5
    0
      include/DEMParticle.h
  4. 42
    0
      src/DEMGrain.cpp
  5. 10
    0
      src/DEMParticle.cpp

+ 9
- 8
examples/DEMGrain.cpp View File

@@ -24,16 +24,17 @@ using namespace Lemma;
24 24
 int main()
25 25
 {
26 26
     auto Grain = DEMGrain::NewSP();
27
-    Grain->SetCentreMass( (Vector3r() << 2.254,3.14,4.).finished() );
27
+        Grain->SetCentreMass( (Vector3r() << 2.254,3.14,4.).finished() );
28
+        Grain->RandomPointCloud(5, 0.0023);
28 29
     std::cout << *Grain << std::endl;
29
-    YAML::Node ng = Grain->Serialize();
30 30
 
31
-    auto Grain3 = DEMGrain::NewSP();
32
-    std::cout << Grain3->GetName() << std::endl;
33
-    std::cout << ((DEMParticle*)(Grain3.get()))->GetName() << std::endl;
34
-
35
-    auto Grain4 = DEMParticle::NewSP();
36
-    std::cout << Grain4->GetName() << std::endl;
31
+//    YAML::Node ng = Grain->Serialize();
32
+//     auto Grain3 = DEMGrain::NewSP();
33
+//     std::cout << Grain3->GetName() << std::endl;
34
+//     std::cout << ((DEMParticle*)(Grain3.get()))->GetName() << std::endl;
35
+//
36
+//     auto Grain4 = DEMParticle::NewSP();
37
+//     std::cout << Grain4->GetName() << std::endl;
37 38
 
38 39
     //Vector3r pos; pos << 2,3,4;
39 40
 

+ 22
- 0
include/DEMGrain.h View File

@@ -23,6 +23,9 @@
23 23
 #pragma once
24 24
 #include "DEMParticle.h"
25 25
 
26
+#include <random>
27
+#include <time.h>
28
+
26 29
 namespace Lemma {
27 30
 
28 31
     /**
@@ -60,6 +63,14 @@ namespace Lemma {
60 63
 
61 64
         // ====================  OPERATIONS    =======================
62 65
 
66
+        /**
67
+         *  Constructs the DEMGrain with random angular points. The points
68
+         *  are called from normal distribution
69
+         *  @param[input] npoints the number points to build a grain out of
70
+         *  @param[input] sigma is the variance of the random distribution
71
+         */
72
+        void RandomPointCloud ( const int& npoints, const Real& sigma );
73
+
63 74
         // ====================  ACCESS        =======================
64 75
 
65 76
         // ====================  INQUIRY       =======================
@@ -70,6 +81,11 @@ namespace Lemma {
70 81
 
71 82
         protected:
72 83
 
84
+        /**
85
+         *  Performs a convex hull on the point cloud, uses a brute force approach
86
+         */
87
+        void ConvexHull();
88
+
73 89
         // ====================  LIFECYCLE     =======================
74 90
 
75 91
         /**
@@ -93,6 +109,12 @@ namespace Lemma {
93 109
 
94 110
         static constexpr auto CName = "DEMGrain";
95 111
 
112
+        /** The points defining the angular grain */
113
+        Vector3Xr    Points;
114
+
115
+        /** The connections between the points */
116
+        MatrixXi    Connections;
117
+
96 118
     }; // -----  end of class  DEMGrain  -----
97 119
 }  // -----  end of namespace Lemma ----
98 120
 

+ 5
- 0
include/DEMParticle.h View File

@@ -62,8 +62,13 @@ namespace Lemma {
62 62
 
63 63
         void SetCentreMass( const Vector3r& pos );
64 64
 
65
+        /** Accessor to centre of Mass */
65 66
         Vector3r GetCentreMass(  );
66 67
 
68
+        /** Convience accessor to  a single corrdinate of the centre of mass
69
+         */
70
+        Real  GetCentreMass( const int& icord );
71
+
67 72
         // ====================  INQUIRY       =======================
68 73
         /** Returns the name of the underlying class, similiar to Python's type */
69 74
         virtual inline std::string GetName() const {

+ 42
- 0
src/DEMGrain.cpp View File

@@ -46,6 +46,7 @@ namespace Lemma {
46 46
     // Description:  DeSerializing constructor (protected)
47 47
     //--------------------------------------------------------------------------------------
48 48
     DEMGrain::DEMGrain (const YAML::Node& node) : DEMParticle(node) {
49
+        Points = node["Points"].as<Vector3Xr>( );
49 50
 
50 51
     }  // -----  end of method DEMGrain::DEMGrain  (constructor)  -----
51 52
 
@@ -76,6 +77,7 @@ namespace Lemma {
76 77
         YAML::Node node = DEMParticle::Serialize();
77 78
         node.SetTag( GetName() );
78 79
         // FILL IN CLASS SPECIFICS HERE
80
+        node["Points"] = Points;
79 81
         return node;
80 82
     }		// -----  end of method DEMGrain::Serialize  -----
81 83
 
@@ -91,6 +93,46 @@ namespace Lemma {
91 93
         return Object ;
92 94
     }		// -----  end of method DEMGrain::DeSerialize  -----
93 95
 
96
+
97
+    //--------------------------------------------------------------------------------------
98
+    //       Class:  DEMGrain
99
+    //      Method:  RandomPointBuild
100
+    //--------------------------------------------------------------------------------------
101
+    void DEMGrain::RandomPointCloud ( const int& npoints, const Real& sigma ) {
102
+
103
+        Points.resize( Eigen::NoChange, npoints );
104
+        std::mt19937 eng(time(NULL));
105
+        std::normal_distribution<Real> normalx(GetCentreMass(0), sigma);
106
+        std::normal_distribution<Real> normaly(GetCentreMass(1), sigma);
107
+        std::normal_distribution<Real> normalz(GetCentreMass(2), sigma);
108
+        std::cout.precision(12);
109
+        for(int i=0; i < npoints; ++i) {
110
+            Points(0, i) = normalx(eng);
111
+            Points(1, i) = normaly(eng);
112
+            Points(2, i) = normalz(eng);
113
+        }
114
+        ConvexHull();
115
+        return ;
116
+    }		// -----  end of method DEMGrain::RandomPoints  -----
117
+
118
+
119
+
120
+    //--------------------------------------------------------------------------------------
121
+    //       Class:  DEMGrain
122
+    //      Method:  ConvexHull
123
+    //--------------------------------------------------------------------------------------
124
+    void DEMGrain::ConvexHull (  ) {
125
+
126
+        //for ( auto point : Points.rowwise() ) {
127
+        // Brute force algorithm (O(n^3))
128
+        for (int icol=0; icol<Points.cols(); ++icol) {
129
+            std::cout << Points.col(icol) << std::endl;
130
+        }
131
+
132
+
133
+        return ;
134
+    }		// -----  end of method DEMGrain::ConvexHull  -----
135
+
94 136
 } // ----  end of namespace Lemma  ----
95 137
 
96 138
 /* vim: set tabstop=4 expandtab: */

+ 10
- 0
src/DEMParticle.cpp View File

@@ -101,6 +101,16 @@ Vector3r DEMParticle::GetCentreMass (  ) {
101 101
 
102 102
 //--------------------------------------------------------------------------------------
103 103
 //       Class:  DEMParticle
104
+//      Method:  GetCentreMass
105
+//--------------------------------------------------------------------------------------
106
+Real DEMParticle::GetCentreMass ( const int& icoord ) {
107
+    return centreMass(icoord);
108
+}		// -----  end of method DEMParticle::get_CentreMass  -----
109
+
110
+
111
+
112
+//--------------------------------------------------------------------------------------
113
+//       Class:  DEMParticle
104 114
 //      Method:  SetCentreMass
105 115
 //--------------------------------------------------------------------------------------
106 116
 void DEMParticle::SetCentreMass ( const Vector3r& pos ) {

Loading…
Cancel
Save