STP_BV.h
Go to the documentation of this file.
1 #ifndef __STP_BV_H
2 # define __STP_BV_H
3 
4 # pragma once
5 # include <list>
6 # include <map>
7 # include <sch/STP-BV/STP_Feature.h>
9 # include <sch/sch_api.h>
10 # include <vector>
11 
12 # ifdef WITH_BOOST_1_36
14 # endif
15 # include <boost/serialization/split_member.hpp>
16 
17 namespace sch
18 {
19 
21 {
24 };
25 
26 struct Geometry
27 {
29  {
33  };
34 
37  Scalar radius; // for spheres only
40  std::vector<Vector3> vertex;
41  std::vector<Vector3> normal;
42 
43  Geometry(GeometryType t) : type(t), color(0, 0, 0), radius(0), center(0, 0, 0), rotation(1, 0, 0, 0, 1, 0, 0, 0, 1) {}
44 };
45 
51 typedef struct s_toruslinkedBV
52 {
53  int buffer[4];
54  template<class Archive>
55  void serialize(Archive & ar, const unsigned int /*version*/)
56  {
57  ar & buffer;
58  }
60 
66 typedef struct s_Triangle
67 {
78  s_Triangle(const Point3 & vertex1, const Point3 & vertex2, const Point3 & vertex3);
79 
80  template<class Archive>
81  void serialize(Archive & ar, const unsigned int /*version*/)
82  {
83  ar & m_vertex1 & m_vertex2 & m_vertex3;
84  }
85 
89 } Triangle;
90 
98 typedef struct s_SphereApproxim
99 {
107  s_SphereApproxim(std::vector<Point3> & vertices, int step, const Point3 & sphereCenter, double sphereRadius);
108 
114  void operator()(const Triangle & vertices, const int & currentStep) const;
115 
116  template<class Archive>
117  void serialize(Archive & ar, const unsigned int /*version*/)
118  {
120  }
121 
122  std::vector<Point3> & m_vertices;
123  int m_step;
127 
135 typedef struct s_PointsComparator
136 {
141 
147  void setData(const Point3 & axis, const std::vector<Point3> & points);
148 
154  bool operator()(unsigned int id1, unsigned int id2) const;
155 
156  template<class Archive>
157  void serialize(Archive & ar, const unsigned int /*version*/)
158  {
159  ar & m_axis & m_points;
160  }
161 
163  std::vector<Point3> m_points;
165 
167 {
168 public:
169  SCH_API STP_BV(void);
170  SCH_API STP_BV(const STP_BV &);
171 
172  SCH_API virtual ~STP_BV(void);
173 
174  SCH_API virtual STP_BV & operator=(const STP_BV &);
175 
176  SCH_API virtual STP_BV * clone() const;
177 
178  SCH_API virtual Point3 l_Support(const Vector3 & v, int & lastFeature) const;
179 
180  SCH_API virtual S_ObjectType getType() const;
181 
187  SCH_API virtual void constructFromFile(const std::string & filename);
188  SCH_API virtual void constructFromFileWithGL(const std::string & filename)
189  {
190  constructFromFile(filename);
191  }
192 
197  SCH_API virtual void loadFromBinary(const std::string & filename);
198 
203  SCH_API virtual void saveToBinary(const std::string & filename);
204 
211  SCH_API void saveTreeInFile(const std::string & treefilename, ArchiveType type = TEXT_ARCHIVE);
212 
217  SCH_API void addPatch(STP_Feature * patch);
218 
223  SCH_API void printSupportTree(std::string filename) const;
224 
229  SCH_API virtual Scalar supportH(const Vector3 & v) const;
230 
235  SCH_API virtual Point3 supportNaive(const Vector3 & v) const;
240  SCH_API virtual Point3 supportFarthestNeighbour(const Vector3 & v, int & lastFeature) const;
246  SCH_API virtual Point3 supportFarthestNeighbourPrime(const Vector3 & v, int & lastFeature) const;
252  SCH_API virtual Point3 supportHybrid(const Vector3 & v, int & lastFeature) const;
258  SCH_API virtual Point3 supportFirstNeighbour(const Vector3 & v, int & lastFeature) const;
264  SCH_API virtual Point3 supportFirstNeighbourPrime(const Vector3 & v, int & lastFeature) const;
265 
273  SCH_API virtual bool ray_cast(const Point3 & source, const Point3 & target, Scalar & param, Vector3 & normal) const;
274 
279  SCH_API int getFeaturesNumber() const;
280 
281  const std::vector<sch::Geometry> & getGeometries() const;
282 
283  template<class Archive>
284  void load(Archive & ar, const unsigned int /*version*/)
285  {
286  ar & boost::serialization::base_object<S_ObjectNormalized>(*this);
287  ar & m_patches;
288  ar & m_patchesSize;
290  }
291 
292  template<class Archive>
293  void save(Archive & ar, const unsigned int /*version*/) const
294  {
295  ar & boost::serialization::base_object<S_ObjectNormalized>(*this);
296  ar & m_patches;
297  ar & m_patchesSize;
298  }
299 
301  {
302  return _R;
303  }
304 
306  {
307  return _r;
308  }
309 
310  BOOST_SERIALIZATION_SPLIT_MEMBER()
311 
312 protected:
319  SCH_API void loadTreeFromFile(const std::string & treefilename, ArchiveType type = TEXT_ARCHIVE);
320 
329  SCH_API void computeArcPointsBetween(const Point3 & p1,
330  const Point3 & p2,
331  const Point3 & center,
332  int step,
333  std::vector<Point3> & res) const;
334 
344  SCH_API void computeConePointsBetween(const Point3 & p1,
345  const Point3 & p2,
346  Vector3 axis,
347  int step,
348  std::vector<Point3> & res,
349  Matrix3x3 & homo);
350 
360  const Point3 & l1p2,
361  const Point3 & l2p1,
362  const Point3 & l2p2) const;
363 
369  SCH_API Point3 computeCenter(const std::vector<Point3> & points);
370 
375  SCH_API void updateFastPatches();
376 
377  std::vector<STP_Feature *> m_patches;
378 
383 
384  std::vector<Geometry> geometries_;
385 };
386 } // namespace sch
387 
388 #endif
389 
sch::BINARY_ARCHIVE
@ BINARY_ARCHIVE
Definition: STP_BV.h:22
sch::STP_BV::load
void load(Archive &ar, const unsigned int)
Definition: STP_BV.h:284
oserializer.hpp
sch::SphereApproxim
struct sch::s_SphereApproxim SphereApproxim
sch::PointsComparator
struct sch::s_PointsComparator PointsComparator
sch::Geometry::vertex
std::vector< Vector3 > vertex
Definition: STP_BV.h:40
sch
Definition: CD_Pair.h:11
sch::STP_BV::_r
Scalar _r
Definition: STP_BV.h:382
sch::s_Triangle::serialize
void serialize(Archive &ar, const unsigned int)
Definition: STP_BV.h:81
sch::s_PointsComparator::serialize
void serialize(Archive &ar, const unsigned int)
Definition: STP_BV.h:157
sch::STP_BV::computeArcPointsBetween
SCH_API void computeArcPointsBetween(const Point3 &p1, const Point3 &p2, const Point3 &center, int step, std::vector< Point3 > &res) const
Computes the points of an arc.
sch::Geometry::LINE
@ LINE
Definition: STP_BV.h:30
sch::STP_BV::m_patchesSize
int m_patchesSize
Definition: STP_BV.h:381
sch::s_PointsComparator::m_axis
Point3 m_axis
Definition: STP_BV.h:162
sch::s_SphereApproxim::m_sphereRadius
Scalar m_sphereRadius
Definition: STP_BV.h:125
sch::s_SphereApproxim::m_step
int m_step
Definition: STP_BV.h:123
sch::S_Object::S_ObjectType
S_ObjectType
type of a solid object. Don't use it to cast !
Definition: S_Object.h:233
SCH_API
#define SCH_API
Definition: sch_api.h:13
sch::STP_BV::computeLinesCommonPoint
SCH_API Point3 computeLinesCommonPoint(const Point3 &l1p1, const Point3 &l1p2, const Point3 &l2p1, const Point3 &l2p2) const
Computes the intersection of two segments.
sch::STP_BV::save
void save(Archive &ar, const unsigned int) const
Definition: STP_BV.h:293
sch::s_PointsComparator
Functor.
Definition: STP_BV.h:135
sch::s_SphereApproxim::m_vertices
std::vector< Point3 > & m_vertices
Definition: STP_BV.h:122
sch::s_SphereApproxim::operator()
void operator()(const Triangle &vertices, const int &currentStep) const
operator parenthesis
sch::Geometry::type
GeometryType type
Definition: STP_BV.h:35
sch::s_SphereApproxim::s_SphereApproxim
s_SphereApproxim(std::vector< Point3 > &vertices, int step, const Point3 &sphereCenter, double sphereRadius)
Constructor.
sch::s_Triangle::m_vertex3
Point3 m_vertex3
Definition: STP_BV.h:88
sch::STP_BV::loadFromBinary
virtual SCH_API void loadFromBinary(const std::string &filename)
Load the object from a binary archive.
sch::STP_BV::supportFirstNeighbourPrime
virtual SCH_API Point3 supportFirstNeighbourPrime(const Vector3 &v, int &lastFeature) const
gives the support for a vector using the First neighbour method.
sch::Triangle
struct sch::s_Triangle Triangle
sch::STP_BV::operator=
virtual SCH_API STP_BV & operator=(const STP_BV &)
sch::STP_BV::supportHybrid
virtual SCH_API Point3 supportHybrid(const Vector3 &v, int &lastFeature) const
sch::Geometry::Geometry
Geometry(GeometryType t)
Definition: STP_BV.h:43
sch::STP_BV::getSmallRadius
Scalar getSmallRadius() const
Definition: STP_BV.h:305
sch::toruslinkedBV
struct sch::s_toruslinkedBV toruslinkedBV
sch::STP_BV::loadTreeFromFile
SCH_API void loadTreeFromFile(const std::string &treefilename, ArchiveType type=TEXT_ARCHIVE)
Load the tree structure of the object from a file.
sch::Geometry
Definition: STP_BV.h:26
sch::STP_BV::supportNaive
virtual SCH_API Point3 supportNaive(const Vector3 &v) const
sch::STP_BV::addPatch
SCH_API void addPatch(STP_Feature *patch)
Adds a bouding volume to the object.
sch::Geometry::center
Point3 center
Definition: STP_BV.h:38
sch::STP_BV::clone
virtual SCH_API STP_BV * clone() const
Returns a copy of this S_Object.
sch::STP_BV::computeCenter
SCH_API Point3 computeCenter(const std::vector< Point3 > &points)
Computes the center of a surface defined by a list of points.
sch::STP_BV::l_Support
virtual SCH_API Point3 l_Support(const Vector3 &v, int &lastFeature) const
gives the support point for a given vector in local cordinates and a given last feature....
sch::s_toruslinkedBV::buffer
int buffer[4]
Definition: STP_BV.h:53
sch::STP_BV::geometries_
std::vector< Geometry > geometries_
Definition: STP_BV.h:384
sch::s_PointsComparator::operator()
bool operator()(unsigned int id1, unsigned int id2) const
operator parenthesis
sch::STP_BV::supportFirstNeighbour
virtual SCH_API Point3 supportFirstNeighbour(const Vector3 &v, int &lastFeature) const
sch::STP_BV::printSupportTree
SCH_API void printSupportTree(std::string filename) const
Print the support tree in a file.
sch::STP_BV::computeConePointsBetween
SCH_API void computeConePointsBetween(const Point3 &p1, const Point3 &p2, Vector3 axis, int step, std::vector< Point3 > &res, Matrix3x3 &homo)
Computes the points of.
sch::Geometry::color
Point3 color
Definition: STP_BV.h:36
sch::Geometry::normal
std::vector< Vector3 > normal
Definition: STP_BV.h:41
sch::STP_BV::constructFromFileWithGL
virtual SCH_API void constructFromFileWithGL(const std::string &filename)
Definition: STP_BV.h:188
sch::s_SphereApproxim::serialize
void serialize(Archive &ar, const unsigned int)
Definition: STP_BV.h:117
sch::STP_BV::ray_cast
virtual SCH_API bool ray_cast(const Point3 &source, const Point3 &target, Scalar &param, Vector3 &normal) const
I don't know.
sch::STP_BV::supportFarthestNeighbour
virtual SCH_API Point3 supportFarthestNeighbour(const Vector3 &v, int &lastFeature) const
sch::s_SphereApproxim::m_sphereCenter
Point3 m_sphereCenter
Definition: STP_BV.h:124
sch::STP_BV::STP_BV
SCH_API STP_BV(void)
sch::STP_BV::supportFarthestNeighbourPrime
virtual SCH_API Point3 supportFarthestNeighbourPrime(const Vector3 &v, int &lastFeature) const
sch::Geometry::radius
Scalar radius
Definition: STP_BV.h:37
sch::Geometry::TRIANGLE
@ TRIANGLE
Definition: STP_BV.h:31
sch::Geometry::rotation
Matrix3x3 rotation
Definition: STP_BV.h:39
sch::s_PointsComparator::m_points
std::vector< Point3 > m_points
Definition: STP_BV.h:163
sch_api.h
S_ObjectNormalized.h
sch::s_PointsComparator::setData
void setData(const Point3 &axis, const std::vector< Point3 > &points)
Constructor.
sch::STP_BV::constructFromFile
virtual SCH_API void constructFromFile(const std::string &filename)
Constructs the object from a file describing its STP_BV decomposition.
sch::S_ObjectNormalized
Definition: S_ObjectNormalized.h:15
STP_Feature.h
sch::s_PointsComparator::s_PointsComparator
s_PointsComparator()
Default constructor.
sch::ArchiveType
ArchiveType
Definition: STP_BV.h:20
sch::STP_BV::saveToBinary
virtual SCH_API void saveToBinary(const std::string &filename)
Save the object to a binary archive.
sch::STP_BV::getBigRadius
Scalar getBigRadius() const
Definition: STP_BV.h:300
CD_Matrix::Vector3T< Scalar, false >
sch::s_Triangle::m_vertex1
Point3 m_vertex1
Definition: STP_BV.h:86
sch::STP_BV::getGeometries
const std::vector< sch::Geometry > & getGeometries() const
sch::STP_BV::getFeaturesNumber
SCH_API int getFeaturesNumber() const
returns the vertex number in the STP-BV
sch::s_SphereApproxim
Functor.
Definition: STP_BV.h:98
sch::s_toruslinkedBV::serialize
void serialize(Archive &ar, const unsigned int)
Definition: STP_BV.h:55
sch::STP_BV::saveTreeInFile
SCH_API void saveTreeInFile(const std::string &treefilename, ArchiveType type=TEXT_ARCHIVE)
sch::Geometry::SPHERE
@ SPHERE
Definition: STP_BV.h:32
sch::s_toruslinkedBV
Stores the IDs of the BV to which a torus is linked.
Definition: STP_BV.h:51
sch::STP_BV::~STP_BV
virtual SCH_API ~STP_BV(void)
sch::STP_BV::_R
Scalar _R
Definition: STP_BV.h:382
sch::Scalar
double Scalar
Definition: SCH_Types.h:23
sch::STP_BV::supportH
virtual SCH_API Scalar supportH(const Vector3 &v) const
CD_Matrix::Matrix3x3T< Scalar >
sch::TEXT_ARCHIVE
@ TEXT_ARCHIVE
Definition: STP_BV.h:23
sch::Geometry::GeometryType
GeometryType
Definition: STP_BV.h:28
sch::s_Triangle::s_Triangle
s_Triangle()
Default constructor.
Definition: STP_BV.h:71
sch::STP_BV::m_patches
std::vector< STP_Feature * > m_patches
Definition: STP_BV.h:377
sch::STP_BV::getType
virtual SCH_API S_ObjectType getType() const
must be overloaded to return the type
sch::STP_BV
Definition: STP_BV.h:166
sch::STP_BV::m_lastPatches
STP_Feature ** m_lastPatches
Definition: STP_BV.h:380
sch::s_Triangle
Defines a triangle.
Definition: STP_BV.h:66
sch::STP_BV::updateFastPatches
SCH_API void updateFastPatches()
Updates the dynamical array fastPatches. Must be called after each patches modification.
sch::STP_Feature
Definition: STP_Feature.h:102
sch::s_Triangle::m_vertex2
Point3 m_vertex2
Definition: STP_BV.h:87
sch::STP_BV::m_fastPatches
STP_Feature ** m_fastPatches
Definition: STP_BV.h:379