MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseWall.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef BASEWALL_H
27 #define BASEWALL_H
28 
29 #include "BaseInteractable.h"
31 
32 class WallHandler;
33 
34 class BaseParticle;
35 
37 {
38  std::vector<Vec3D> points;
39  std::vector<std::vector<double>> triangleStrips;
40 };
41 
47 class BaseWall : public BaseInteractable
48 {
49 public:
53  BaseWall();
54 
58  BaseWall(const BaseWall& w);
59 
63  ~BaseWall() override;
64 
69  virtual BaseWall* copy() const = 0;
70 
74  void read(std::istream& is) override;
75 
79  void write(std::ostream& os) const override;
80 
89  virtual bool getDistanceAndNormal(const BaseParticle& P, Mdouble& distance, Vec3D& normal_return) const = 0;
90 
91 
92  virtual bool
93  getDistanceNormalOverlap(const BaseParticle& P, Mdouble& distance, Vec3D& normal_return, Mdouble& overlap) const;
94 
95  virtual bool getDistanceNormalOverlapSuperquadric(const SuperQuadricParticle& p, Mdouble& distance, Vec3D& normal_return,
96  Mdouble& overlap) const;
97 
98  virtual Vec3D
99  getFurthestPointSuperQuadric(const Vec3D& normalBodyFixed, const Vec3D& axes, Mdouble eps1, Mdouble eps2) const;
100 
104  virtual void setHandler(WallHandler* handler);
105 
109  WallHandler* getHandler() const;
110 
115  void setIndSpecies(unsigned int indSpecies) override;
116 
121  void setSpecies(const ParticleSpecies* species);
122 
127  bool isFixed() const override;
128 
132  void setForceControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity={0,0,0});
133 
137  virtual bool isLocal(Vec3D& min, Vec3D& max) const
138  { return false; }
139 
140  // returns the point intersecting a wall (x-p).n=0 and a line x=p0+t(p1-p0)
141  bool getLinePlaneIntersect(Vec3D& intersect, const Vec3D& p0, const Vec3D& p1, const Vec3D& n, const Vec3D& p);
142  bool isInsideWallVTK(const Vec3D& point, const Vec3D& normal, const Vec3D& position) const;
146 
150  void projectOntoWallVTK(Vec3D& point0, const Vec3D& point1, const Vec3D& normal, const Vec3D& position) const;
151 
156  void intersectVTK(std::vector<Vec3D>& points, Vec3D normal, Vec3D position) const;
157 
158 
159  virtual BaseInteraction*
160  getInteractionWithSuperQuad(SuperQuadricParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler);
161 
167  virtual void writeVTK(VTKContainer& vtk) const;
168 
169  void getVTK(std::vector<Vec3D>& points, std::vector<std::vector<double>>& triangleStrips)
170  {}
171 
172  const Vec3D getAxis() const;
173 
176  getInteractionWith(BaseParticle* p, unsigned timeStamp, InteractionHandler* interactionHandler) override;
177 
178  bool getVTKVisibility() const;
179 
180  void setVTKVisibility(bool vtkVisibility);
181 
185  static void addToVTK(const std::vector<Vec3D>& points, VTKContainer& vtk);
186 
187  //todo how do i write a copy and add function?
188  void addRenderedWall(BaseWall* w);
189 
190  BaseWall* getRenderedWall(size_t i) const;
191 
192  void removeRenderedWalls();
193 
194  void renderWall(VTKContainer& vtk);
195 
196  void addParticlesAtWall(unsigned numElements = 50);
197 
198  void setVelocityControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity);
199 
200 private:
205 
206  bool vtkVisibility_ = true;
207 
211  std::vector<BaseWall*> renderedWalls_;
212 
213 };
214 
215 #endif
const Vec3D getAxis() const
Definition: BaseWall.cc:503
virtual Vec3D getFurthestPointSuperQuadric(const Vec3D &normalBodyFixed, const Vec3D &axes, Mdouble eps1, Mdouble eps2) const
Definition: BaseWall.cc:547
void intersectVTK(std::vector< Vec3D > &points, Vec3D normal, Vec3D position) const
Definition: BaseWall.cc:243
virtual void writeVTK(VTKContainer &vtk) const
Definition: BaseWall.cc:466
double Mdouble
Definition: GeneralDefine.h:34
void renderWall(VTKContainer &vtk)
Definition: BaseWall.cc:570
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
virtual bool isLocal(Vec3D &min, Vec3D &max) const
Definition: BaseWall.h:137
virtual void setHandler(WallHandler *handler)
A function which sets the WallHandler for this BaseWall.
Definition: BaseWall.cc:127
bool isFixed() const override
Definition: BaseWall.cc:188
static void addToVTK(const std::vector< Vec3D > &points, VTKContainer &vtk)
Takes the points provided and adds a triangle strip connecting these points to the vtk container...
Definition: BaseWall.cc:471
void write(std::ostream &os) const override
Function that writes a BaseWall to an output stream, usually a restart file.
Definition: BaseWall.cc:102
WallHandler * handler_
Definition: BaseWall.h:204
void setVelocityControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity)
Definition: BaseWall.cc:591
BaseInteraction * getInteractionWith(BaseParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler) override
Returns the interaction between this wall and a given particle, nullptr if there is no interaction...
Definition: BaseWall.cc:369
Stores information about interactions between two interactable objects; often particles but could be ...
WallHandler * getHandler() const
A function which returns the WallHandler that handles this BaseWall.
Definition: BaseWall.cc:136
virtual bool getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const =0
Pure virtual function that computes the distance of a BaseParticle to this wall and returns the norma...
std::vector< std::vector< double > > triangleStrips
Definition: BaseWall.h:39
Container to store Interaction objects.
bool getVTKVisibility() const
Definition: BaseWall.cc:513
bool isInsideWallVTK(const Vec3D &point, const Vec3D &normal, const Vec3D &position) const
Definition: BaseWall.cc:222
virtual bool getDistanceNormalOverlapSuperquadric(const SuperQuadricParticle &p, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
Definition: BaseWall.cc:540
BaseWall()
Default constructor.
Definition: BaseWall.cc:36
Basic class for walls.
Definition: BaseWall.h:47
void setVTKVisibility(bool vtkVisibility)
Definition: BaseWall.cc:518
BaseWall * getRenderedWall(size_t i) const
Definition: BaseWall.cc:565
void read(std::istream &is) override
Function that reads a BaseWall from an input stream, usually a restart file.
Definition: BaseWall.cc:80
~BaseWall() override
Default destructor.
Definition: BaseWall.cc:66
virtual BaseInteraction * getInteractionWithSuperQuad(SuperQuadricParticle *p, unsigned timeStamp, InteractionHandler *interactionHandler)
Definition: BaseWall.cc:494
void getVTK(std::vector< Vec3D > &points, std::vector< std::vector< double >> &triangleStrips)
Definition: BaseWall.h:169
std::vector< BaseWall * > renderedWalls_
Definition: BaseWall.h:211
Container to store all BaseWall.
Definition: WallHandler.h:42
bool vtkVisibility_
Definition: BaseWall.h:206
std::vector< Vec3D > points
Definition: BaseWall.h:38
void setForceControl(Vec3D forceGoal, Vec3D gainFactor, Vec3D baseVelocity={0, 0, 0})
Slowly adjusts the force on a wall towards a specified goal, by adjusting (prescribing) the velocity ...
Definition: BaseWall.cc:198
void setIndSpecies(unsigned int indSpecies) override
Define the species of this wall using the index of the species in the SpeciesHandler in this DPMBase...
Definition: BaseWall.cc:144
Defines the basic properties that a interactable object can have.
void removeRenderedWalls()
Definition: BaseWall.cc:559
Definition: Vector.h:49
void projectOntoWallVTK(Vec3D &point0, const Vec3D &point1, const Vec3D &normal, const Vec3D &position) const
Definition: BaseWall.cc:233
bool getLinePlaneIntersect(Vec3D &intersect, const Vec3D &p0, const Vec3D &p1, const Vec3D &n, const Vec3D &p)
Definition: BaseWall.cc:206
virtual BaseWall * copy() const =0
Pure virtual function that can be overwritten in inherited classes in order to copy a BaseWall...
virtual bool getDistanceNormalOverlap(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return, Mdouble &overlap) const
Definition: BaseWall.cc:523
void addParticlesAtWall(unsigned numElements=50)
Definition: BaseWall.cc:598
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:171
void addRenderedWall(BaseWall *w)
Definition: BaseWall.cc:554