Changeset 0eb8f4


Ignore:
Timestamp:
Sep 26, 2012, 5:24:33 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
6f0507e
Parents:
52575c
git-author:
Gregor Bollerhey <bollerhe@…> (06/18/12 14:43:14)
git-committer:
Frederik Heber <heber@…> (09/26/12 17:24:33)
Message:

Cylinder implementation.

Taken from somehow broken branch, so rebase was not possible,
unfortunately.

The cylinder shape is centered on (0 0 0) and its height (z-Axis)
ranges from -1 to 1. Different scalings can be applied with the special
constructor.

Location:
src/Shapes
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Shapes/BaseShapes.cpp

    r52575c r0eb8f4  
    2929#include "CodePatterns/Assert.hpp"
    3030#include "LinearAlgebra/Vector.hpp"
     31#include "LinearAlgebra/RealSpaceMatrix.hpp"
    3132#include "LinearAlgebra/Line.hpp"
    3233#include "LinearAlgebra/Plane.hpp"
     
    3637#include <cmath>
    3738#include <algorithm>
     39
     40// CYLINDER CODE
     41// ----------------------------------------------------------------------------
     42bool Cylinder_impl::isInside(const Vector &point) const {
     43  return (Vector(point[0], point[1], 0.0).NormSquared() < 1.0+MYEPSILON) &&
     44      (point[2] > -1.0-MYEPSILON) && (point[2] < 1.0+MYEPSILON);
     45}
     46
     47bool Cylinder_impl::isOnSurface(const Vector &point) const {
     48  return fabs(Vector(point[0], point[1], 0.0).NormSquared()-1.0)<MYEPSILON &&
     49      (point[2] > -1.0-MYEPSILON) && (point[2] < 1.0+MYEPSILON);
     50
     51}
     52
     53Vector Cylinder_impl::getNormal(const Vector &point) const throw(NotOnSurfaceException) {
     54  if(!isOnSurface(point)){
     55    throw NotOnSurfaceException() << ShapeVector(&point);
     56  }
     57
     58  if ((fabs(point[2]-1)<MYEPSILON) || (fabs(point[2])<MYEPSILON))
     59      return Vector(0.0, 0.0, point[2]);
     60  else
     61    return Vector(point[0], point[1], 0.0);
     62}
     63
     64Vector Cylinder_impl::getCenter() const
     65{
     66  return Vector(0.0, 0.0, 0.0);
     67}
     68
     69double Cylinder_impl::getRadius() const
     70{
     71    return 1.0;
     72}
     73
     74double Cylinder_impl::getVolume() const
     75{
     76        return M_PI*2.0; // pi r^2 h
     77}
     78
     79double Cylinder_impl::getSurfaceArea() const
     80{
     81        return 2.0*M_PI*2.0; // 2 pi r h
     82}
     83
     84LineSegmentSet Cylinder_impl::getLineIntersections(const Line &line) const {
     85    // TODO
     86        ASSERT(0, "Cylinder_impl::getLineIntersections - not implemented.");
     87}
     88
     89std::string Cylinder_impl::toString() const
     90{
     91  return "Cylinder()";
     92}
     93
     94enum ShapeType Cylinder_impl::getType() const
     95{
     96        return CylinderType;
     97}
     98
     99std::vector<Vector> Cylinder_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     100    // TODO
     101    ASSERT(0, "Cylinder_impl::getHomogeneousPointsOnSurface - not implemented.");
     102}
     103
     104std::vector<Vector> Cylinder_impl::getHomogeneousPointsInVolume(const size_t N) const {
     105    // TODO
     106    ASSERT(0, "Cylinder_impl::getHomogeneousPointsInVolume - not implemented.");
     107}
     108
     109Shape Cylinder() {
     110  Shape::impl_ptr impl = Shape::impl_ptr(new Cylinder_impl());
     111  return Shape(impl);
     112}
     113
     114Shape Cylinder(const Vector &center, const double xrot, const double yrot,
     115        const double height, const double radius)
     116{
     117    RealSpaceMatrix rot;
     118    rot.setRotation(xrot, yrot, 0.0);
     119
     120    return translate(
     121                transform(
     122                    stretch(
     123                        Cylinder(),
     124                    Vector(radius, radius, height*0.5)),
     125                rot),
     126            center);
     127}
     128// ----------------------------------------------------------------------------
    38129
    39130bool Sphere_impl::isInside(const Vector &point) const{
  • TabularUnified src/Shapes/BaseShapes.hpp

    r52575c r0eb8f4  
    1717#include "Shapes/Shape.hpp"
    1818
     19Shape Cylinder();
     20Shape Cylinder(const Vector &center, const double xrot, const double yrot,
     21        const double height, const double radius);
    1922Shape Sphere();
    2023Shape Sphere(const Vector &center,double radius);
  • TabularUnified src/Shapes/BaseShapes_impl.hpp

    r52575c r0eb8f4  
    2121#include "Shapes/ShapeExceptions.hpp"
    2222#include "Shapes/ShapeType.hpp"
     23
     24class Cylinder_impl : public Shape_impl {
     25  virtual bool isInside(const Vector &point) const;
     26  virtual bool isOnSurface(const Vector &point) const;
     27  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     28  virtual Vector getCenter() const;
     29  virtual double getRadius() const;
     30  virtual double getVolume() const;
     31  virtual double getSurfaceArea() const;
     32  virtual LineSegmentSet getLineIntersections(const Line&) const;
     33  virtual std::string toString() const;
     34  virtual enum ShapeType getType() const;
     35  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
     36  virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
     37};
    2338
    2439class Sphere_impl : public Shape_impl {
  • TabularUnified src/Shapes/ShapeType.hpp

    r52575c r0eb8f4  
    2222        PolygonType,
    2323        CombinedType,
    24         MAX_ShapeType
     24        MAX_ShapeType,
     25    CylinderType
    2526};
    2627
  • TabularUnified src/Shapes/unittests/BaseShapesUnitTest.cpp

    r52575c r0eb8f4  
    7878{}
    7979
     80void BaseShapesTest::cylinderTest()
     81{
     82    Shape s = Cylinder();
     83    // z = 0
     84    // Quadrant 1 1
     85    CPPUNIT_ASSERT( s.isInside(v000));
     86    CPPUNIT_ASSERT( s.isInside(v100));
     87    CPPUNIT_ASSERT(!s.isInside(v110));
     88    CPPUNIT_ASSERT( s.isInside(v010));
     89    // Quadrant 0 1
     90    CPPUNIT_ASSERT(!s.isInside(v210));
     91    CPPUNIT_ASSERT( s.isInside(v200));
     92    // Quadrant 0 0
     93    CPPUNIT_ASSERT(!s.isInside(v220));
     94    CPPUNIT_ASSERT( s.isInside(v020));
     95    // Quadrant 1 0
     96    CPPUNIT_ASSERT(!s.isInside(v120));
     97   
     98    // z = 1
     99    // Quadrant 1 1
     100    CPPUNIT_ASSERT( s.isInside(v001));
     101    CPPUNIT_ASSERT( s.isInside(v101));
     102    CPPUNIT_ASSERT(!s.isInside(v111));
     103    CPPUNIT_ASSERT( s.isInside(v011));
     104    // Quadrant 0 1
     105    CPPUNIT_ASSERT(!s.isInside(v211));
     106    CPPUNIT_ASSERT( s.isInside(v201));
     107    // Quadrant 0 0
     108    CPPUNIT_ASSERT(!s.isInside(v221));
     109    CPPUNIT_ASSERT( s.isInside(v021));
     110    // Quadrant 1 0
     111    CPPUNIT_ASSERT(!s.isInside(v121));
     112   
     113    // z = 2
     114    // Quadrant 1 1
     115    CPPUNIT_ASSERT( s.isInside(v002));
     116    CPPUNIT_ASSERT( s.isInside(v102));
     117    CPPUNIT_ASSERT(!s.isInside(v112));
     118    CPPUNIT_ASSERT( s.isInside(v012));
     119    // Quadrant 0 1
     120    CPPUNIT_ASSERT(!s.isInside(v212));
     121    CPPUNIT_ASSERT( s.isInside(v202));
     122    // Quadrant 0 0
     123    CPPUNIT_ASSERT(!s.isInside(v222));
     124    CPPUNIT_ASSERT( s.isInside(v022));
     125    // Quadrant 1 0
     126    CPPUNIT_ASSERT(!s.isInside(v122));
     127
     128
     129    // More special cylinder
     130    s = Cylinder(Vector(0.5, 0.5, 0.0), 0.0, 30.0/180.0*M_PI, 4.0, 1.5);
     131
     132    CPPUNIT_ASSERT(!s.isInside(v222));
     133    CPPUNIT_ASSERT(!s.isInside(v022));
     134    CPPUNIT_ASSERT(!s.isInside(v122));
     135    CPPUNIT_ASSERT( s.isInside(v202));
     136    CPPUNIT_ASSERT( s.isInside(v002));
     137    CPPUNIT_ASSERT( s.isInside(v102));
     138    CPPUNIT_ASSERT( s.isInside(v212));
     139    CPPUNIT_ASSERT( s.isInside(v012));
     140    CPPUNIT_ASSERT( s.isInside(v112));
     141   
     142    CPPUNIT_ASSERT(!s.isInside(v220));
     143    CPPUNIT_ASSERT(!s.isInside(v020));
     144    CPPUNIT_ASSERT(!s.isInside(v120));
     145    CPPUNIT_ASSERT( s.isInside(v200));
     146    CPPUNIT_ASSERT( s.isInside(v000));
     147    CPPUNIT_ASSERT( s.isInside(v100));
     148    CPPUNIT_ASSERT( s.isInside(v210));
     149    CPPUNIT_ASSERT( s.isInside(v010));
     150    CPPUNIT_ASSERT( s.isInside(v110));
     151   
     152    CPPUNIT_ASSERT(!s.isInside(v221));
     153    CPPUNIT_ASSERT(!s.isInside(v021));
     154    CPPUNIT_ASSERT(!s.isInside(v121));
     155    CPPUNIT_ASSERT(!s.isInside(v201));
     156    CPPUNIT_ASSERT( s.isInside(v001));
     157    CPPUNIT_ASSERT( s.isInside(v101));
     158    CPPUNIT_ASSERT(!s.isInside(v211));
     159    CPPUNIT_ASSERT( s.isInside(v011));
     160    CPPUNIT_ASSERT( s.isInside(v111));
     161}
    80162
    81163void BaseShapesTest::baseShapesTest(){
  • TabularUnified src/Shapes/unittests/BaseShapesUnitTest.hpp

    r52575c r0eb8f4  
    3030  CPPUNIT_TEST ( operatorTest );
    3131  CPPUNIT_TEST ( PointsOnSurfaceTest );
     32  CPPUNIT_TEST ( cylinderTest );
    3233  CPPUNIT_TEST_SUITE_END();
    3334
     
    4142  void operatorTest();
    4243  void PointsOnSurfaceTest();
     44  void cylinderTest();
    4345
    4446  // a lot of vectors.
Note: See TracChangeset for help on using the changeset viewer.