/* This file is part of Lemma, a geophysical modelling and inversion API. * More information is available at http://lemmasoftware.org */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * @file * @date 06/16/2016 02:11:21 PM * @version $Id$ * @author Trevor Irons (ti) * @email tirons@egi.utah.edu * @copyright Copyright (c) 2016, University of Utah * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC */ #include "DEMGrain.h" namespace Lemma { // ==================== FRIEND METHODS ===================== std::ostream &operator << (std::ostream &stream, const DEMGrain &ob) { stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy return stream; } // ==================== LIFECYCLE ======================= //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: DEMGrain // Description: constructor (protected) //-------------------------------------------------------------------------------------- DEMGrain::DEMGrain ( ) : DEMParticle( ) { } // ----- end of method DEMGrain::DEMGrain (constructor) ----- //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: DEMGrain // Description: DeSerializing constructor (protected) //-------------------------------------------------------------------------------------- DEMGrain::DEMGrain (const YAML::Node& node) : DEMParticle(node) { Points = node["Points"].as( ); } // ----- end of method DEMGrain::DEMGrain (constructor) ----- //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: NewSP() // Description: public constructor returing a shared_ptr //-------------------------------------------------------------------------------------- std::shared_ptr< DEMGrain > DEMGrain::NewSP() { std::shared_ptr< DEMGrain > sp(new DEMGrain( ), LemmaObjectDeleter() ); return sp; } //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: ~DEMGrain // Description: destructor (protected) //-------------------------------------------------------------------------------------- DEMGrain::~DEMGrain () { } // ----- end of method DEMGrain::~DEMGrain (destructor) ----- //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: Serialize //-------------------------------------------------------------------------------------- YAML::Node DEMGrain::Serialize ( ) const { YAML::Node node = DEMParticle::Serialize(); node.SetTag( GetName() ); // FILL IN CLASS SPECIFICS HERE node["Points"] = Points; return node; } // ----- end of method DEMGrain::Serialize ----- //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: DeSerialize //-------------------------------------------------------------------------------------- std::shared_ptr DEMGrain::DeSerialize ( const YAML::Node& node ) { if (node.Tag() != "DEMGrain" ) { throw DeSerializeTypeMismatch( "DEMGrain", node.Tag()); } std::shared_ptr< DEMGrain > Object(new DEMGrain(node), LemmaObjectDeleter() ); return Object ; } // ----- end of method DEMGrain::DeSerialize ----- //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: RandomPointBuild //-------------------------------------------------------------------------------------- void DEMGrain::RandomPointCloud ( const int& npoints, const Real& sigma ) { Points.resize( Eigen::NoChange, npoints ); std::mt19937 eng(time(NULL)); std::normal_distribution normalx(GetCentreMass(0), sigma); std::normal_distribution normaly(GetCentreMass(1), sigma); std::normal_distribution normalz(GetCentreMass(2), sigma); std::cout.precision(12); for(int i=0; i < npoints; ++i) { Points(0, i) = normalx(eng); Points(1, i) = normaly(eng); Points(2, i) = normalz(eng); } ConvexHull(); return ; } // ----- end of method DEMGrain::RandomPoints ----- //-------------------------------------------------------------------------------------- // Class: DEMGrain // Method: ConvexHull //-------------------------------------------------------------------------------------- void DEMGrain::ConvexHull ( ) { //for ( auto point : Points.rowwise() ) { // Brute force algorithm (O(n^3)) for (int icol=0; icol