Image Component Library (ICL)
PhysicsPaper3 (copy).h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <ICLCore/Img.h>
5 #include <ICLGeom/Camera.h>
6 #include <ICLUtils/Array2D.h>
9 #include <ICLGeom/ViewRay.h>
10 #include <ICLUtils/Function.h>
12 
13 
14 #include <map>
15 #include <set>
16 
18 class btSoftBody;
21 namespace icl{
22 
23 namespace physics{
24 
26  class PhysicsWorld;
29  class PhysicsPaper3 : public SoftObject{
30  protected:
31  struct Data;
32  Data *m_data;
33 
34  struct LinkState{
35  LinkState(bool isFirstOrder=true, bool isFold=false,
36  bool hasMemorizedRestDist=false):
40  bool isFold;
42  LinkState *p() const { return new LinkState(*this); }
43  static bool is_first_order(void *tag){
44  return ((LinkState*)tag)->isFirstOrder;
45  }
46  static bool is_fold(void *tag){
47  return ((LinkState*)tag)->isFold;
48  }
49  static bool has_memorized_rest_dist(void *tag){
50  return ((LinkState*)tag)->hasMemorizedRestDist;
51  }
52  };
53 
54  public:
55 
56  typedef std::pair<utils::Point32f,utils::Point32f> LinkCoords;
57 
58  void updateSceneObject(btSoftBody *soft);
59 
61  bool enableSelfCollision,
62  const utils::Size &cellsInit,
63  const geom::Vec corners[4]=0,
64  const core::Img8u *front_texture=0,
65  const core::Img8u *back_texture=0,
66  float initialStiffness=-1,
67  float initialMaxLinkDistnace=0.5);
68 
69  virtual ~PhysicsPaper3();
70 
71  void splitAlongLine(const utils::Point32f &a, const utils::Point32f &b, const geom::Camera &currCam);
72 
74 
76  utils::Point32f hit(const geom::ViewRay &ray) const;
77 
78  void movePosition(const utils::Point32f &coords, const geom::Vec &target, float streangth=1, float radius=0.1);
79 
80  virtual void customRender();
81 
82  SceneObject *approximateSurface(int nx=100, int ny=150) const;
83 
85 
87  void createBendingConstraints(float maxDistance, float fixedStiffness=-1);
88 
89  void setLinksVisible(bool visible);
90 
91  void simulateSelfCollision();
92 
93  static inline void free_link_state(void *p) { delete (LinkState*)p; }
94 
95  const core::Img32f &getFoldMap() const;
96 
98 
99  void setFacesVisible(bool visible);
100 
101  virtual void lock();
102 
103  virtual void unlock();
104 
105  const std::vector<utils::Point32f> getTexCoords() const;
106 
109 
111  void adaptFoldStiffness(const LinkCoords &coords, float stiffness, bool memorize=false);
112 
115  const geom::Camera &currCam) const;
116 
118  void setStraightenFolds(bool enabled);
119 
121  void setDoubleFolds(bool enabled);
122 
123 
124  struct Structure{
125  struct Face { int a,b,c; };
126  std::vector<utils::Point32f> texCoords;
127  std::vector<geom::Vec> vertices;
128  std::vector<Face> faces;
130 
131  void deserializeFrom(std::istream &str);
132  void updateToSceneObject(SceneObject *obj);
133  utils::Point32f hit(const geom::ViewRay &ray) const;
134  };
135 
136  void serializeStructureTo(std::ostream &str);
137 
138 
139 
140  protected:
141 
142 
143 
144 
146 
147  void updateNodeAreas();
148  //void updateConstants();
149 
150  bool hitLink(btSoftBody::Link *l, const utils::Point32f &a, const utils::Point32f &b);
151 
152  bool hitTriangle(btSoftBody::Face *f, const utils::Point32f &a, const utils::Point32f &b);
153 
154  void addTriangle(int a, int b, int c);
155 
156  void addLink(int a, int b, float stiffness=1.0f, const LinkState &state=LinkState());
157 
158  void addVertexOrReuseOldOne(utils::Point32f &t, btVector3 &v, int &idx);
159 
160  bool replaceTriangle(btSoftBody::Face *f, const utils::Point32f &a, const utils::Point32f &b);
161 
162  void lockWorld();
163 
164  void unlockWorld();
165 
167 
168  void computeSmoothNormals();
169  };
170 } // end of namespace physics
171 } // end of namespace icl
The General Function Template.
Definition: Function.h:284
static bool is_first_order(void *tag)
Definition: PhysicsPaper3 (copy).h:43
bool hitTriangle(btSoftBody::Face *f, const utils::Point32f &a, const utils::Point32f &b)
void setFacesVisible(bool visible)
int b
Definition: PhysicsPaper3 (copy).h:125
undocument this line if you encounter any issues!
Definition: Any.h:37
bool isFold
Definition: PhysicsPaper3 (copy).h:40
A physical world that handles physical objects.
Definition: PhysicsWorld.h:56
void updateToSceneObject(SceneObject *obj)
void movePosition(const utils::Point32f &coords, const geom::Vec &target, float streangth=1, float radius=0.1)
std::vector< geom::Vec > vertices
Definition: PhysicsPaper3 (copy).h:127
utils::Point32f hit(const geom::ViewRay &ray) const
static bool has_memorized_rest_dist(void *tag)
Definition: PhysicsPaper3 (copy).h:49
Definition: PhysicsPaper3 (copy).h:29
const core::Img32f & getFoldMap() const
void addTriangle(int a, int b, int c)
Camera class.
Definition: Camera.h:132
void adaptFoldStiffness(const LinkCoords &coords, float stiffness, bool memorize=false)
adapts the stiffness of a given fold (optionally memorizes deformation)
utils::Point32f hit(const geom::ViewRay &ray) const
returns paper coordinates of given (or Point(-1,-1) in case of no hit)
std::pair< utils::Point32f, utils::Point32f > LinkCoords
Definition: PhysicsPaper3 (copy).h:56
const std::vector< utils::Point32f > getTexCoords() const
void serializeStructureTo(std::ostream &str)
geom::Vec interpolatePosition(const utils::Point32f &p) const
std::vector< utils::Point32f > texCoords
Definition: PhysicsPaper3 (copy).h:126
SceneObject * approximateSurface(int nx=100, int ny=150) const
Definition: PhysicsPaper3 (copy).h:124
LinkState * p() const
Definition: PhysicsPaper3 (copy).h:42
LinkState(bool isFirstOrder=true, bool isFold=false, bool hasMemorizedRestDist=false)
Definition: PhysicsPaper3 (copy).h:35
Definition: PhysicsPaper3 (copy).h:125
void setStraightenFolds(bool enabled)
sets whether folds are always straightened
void createBendingConstraints(float maxDistance, float fixedStiffness=-1)
if fixedStiffness is in ]0,1], it is use for all links
Size class of the ICL.
Definition: Size.h:61
bool replaceTriangle(btSoftBody::Face *f, const utils::Point32f &a, const utils::Point32f &b)
virtual void updateSceneObject()
this method is used to update the visualization object from the physical object
utils::SmartPtr< LinkCoords > getLinkCoords(const utils::Point32f &pix, const geom::Camera &cam) const
returns the possible paper coords of link at given camera pixel
geom::Vec interpolatePosition(const utils::Point32f &p) const
bool isFirstOrder
Definition: PhysicsPaper3 (copy).h:39
int a
Definition: PhysicsPaper3 (copy).h:125
ICLQt_API void pix(ImgQ &image, int x, int y)
draw a single pixel into an image
int c
Definition: PhysicsPaper3 (copy).h:125
void addVertexOrReuseOldOne(utils::Point32f &t, btVector3 &v, int &idx)
PhysicsPaper3(PhysicsWorld *world, bool enableSelfCollision, const utils::Size &cellsInit, const geom::Vec corners[4]=0, const core::Img8u *front_texture=0, const core::Img8u *back_texture=0, float initialStiffness=-1, float initialMaxLinkDistnace=0.5)
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
Abstract class for visualization tasks.
Definition: VisualizationDescription.h:73
core::Img32f paperCoordinateTest(const geom::Camera &cam) const
This is a view-ray's line equation in parameter form.
Definition: ViewRay.h:49
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
This class combines a soft-body physics object and it's graphical representation in ICL.
Definition: SoftObject.h:46
static bool is_fold(void *tag)
Definition: PhysicsPaper3 (copy).h:46
bool hitLink(btSoftBody::Link *l, const utils::Point32f &a, const utils::Point32f &b)
std::vector< Face > faces
Definition: PhysicsPaper3 (copy).h:128
void addLink(int a, int b, float stiffness=1.0f, const LinkState &state=LinkState())
virtual void customRender()
this function is called when an object is rendered
void setLinksVisible(bool visible)
utils::VisualizationDescription getFoldLineHighlight(const LinkCoords &coords, const geom::Camera &currCam) const
highlights all folds colliniear with line ab in paper space
static void free_link_state(void *p)
Definition: PhysicsPaper3 (copy).h:93
bool hasMemorizedRestDist
Definition: PhysicsPaper3 (copy).h:41
void splitAlongLine(const utils::Point32f &a, const utils::Point32f &b, const geom::Camera &currCam)
void setDoubleFolds(bool enabled)
sets whether folds are automatically inserted doubled
Data * m_data
Definition: PhysicsPaper3 (copy).h:31
Specialization of the SmartPtrBase class for Pointers.
Definition: SmartPtr.h:75
Definition: PhysicsPaper3 (copy).h:34
void setFoldMapChangedCallback(utils::Function< void, const core::Img32f & > cb)
void deserializeFrom(std::istream &str)
ICLGeom_API SceneObject()
create an object