geolib2
Shape.h
Go to the documentation of this file.
1 #ifndef GEOLIB_SHAPE_H_
2 #define GEOLIB_SHAPE_H_
3 
4 #include "datatypes.h"
5 #include "Mesh.h"
6 #include "Ray.h"
7 #include "Triangle.h"
8 
9 namespace geo {
10 
11 class Box;
12 
19 class Shape {
20 
21  friend class Importer;
22 
23 public:
24 
25  Shape();
26 
27  virtual ~Shape();
28 
29  virtual Shape* clone() const;
30 
39  virtual bool intersect(const Ray& r, float t0, float t1, double& distance) const;
40 
47  virtual bool intersect(const Vector3& p, const double radius) const;
48 
54  virtual bool contains(const Vector3& p) const;
55 
60  virtual double getMaxRadius() const;
61 
67  virtual Box getBoundingBox() const;
68 
73  virtual const Mesh& getMesh() const;
74 
80  virtual void setMesh(const Mesh& mesh);
81 
89  virtual bool write(std::ostream& output) const;
90 
96  static ShapePtr read(std::istream& input);
97 
98  static const std::string TYPE;
99 
104  inline virtual bool empty() const { return mesh_.empty(); }
105 
106 protected:
107 
113 
114 private:
115 
116  mutable bool bounding_box_cache_valid_; // keeps track if the cached values of the bounding box are valid
117  mutable Vector3 bounding_box_min_cache_; // cached value of the min corner of a bounding box
118  mutable Vector3 bounding_box_max_cache_; // cached value of the max corner of a bounding box
119 };
120 
121 }
122 
123 
124 #endif
geo::Shape::intersect
virtual bool intersect(const Ray &r, float t0, float t1, double &distance) const
intersect: currently always throws a logic error
Definition: Shape.cpp:149
geo::Shape::setMesh
virtual void setMesh(const Mesh &mesh)
set the Mesh Any child classes should throw a std::logic_error in case the mesh should not be changed...
Definition: Shape.cpp:429
geo::Shape::bounding_box_max_cache_
Vector3 bounding_box_max_cache_
Definition: Shape.h:118
geo::Mesh::empty
bool empty() const
Definition: Mesh.h:67
std::string
std::shared_ptr
geo
Definition: Box.h:6
geo::Shape::empty
virtual bool empty() const
empty Test whether the shape(mesh) is empty.
Definition: Shape.h:104
geo::Box
Definition: Box.h:15
geo::Shape::read
static ShapePtr read(std::istream &input)
read serialised data from an input stream and create a shape
Definition: Shape.cpp:471
geo::Shape::getMesh
virtual const Mesh & getMesh() const
return the mesh defining the shape
Definition: Shape.cpp:425
datatypes.h
geo::Shape::write
virtual bool write(std::ostream &output) const
write, serialise the shape
Definition: Shape.cpp:439
geo::Shape::getMaxRadius
virtual double getMaxRadius() const
Calculate the maximum distance from the origin of the shape to any point of the shape.
Definition: Shape.cpp:434
std::ostream
geo::Shape::TYPE
static const std::string TYPE
Definition: Shape.h:98
Triangle.h
geo::Shape::Importer
friend class Importer
Definition: Shape.h:21
geo::Ray
Definition: Ray.h:10
geo::Vector3
Definition: matrix.h:12
geo::Shape::getBoundingBox
virtual Box getBoundingBox() const
Returns the smallest box which includes all mesh points. Box is not rotated, but matches the axis of ...
Definition: Shape.cpp:402
Mesh.h
geo::Shape::bounding_box_min_cache_
Vector3 bounding_box_min_cache_
Definition: Shape.h:117
geo::Shape::contains
virtual bool contains(const Vector3 &p) const
Determines whether a point p lies within the shape.
Definition: Shape.cpp:229
geo::Shape::mesh_
Mesh mesh_
Should not be read or written to directly in general. Use setMesh and getMesh to write respectively r...
Definition: Shape.h:112
geo::Shape::bounding_box_cache_valid_
bool bounding_box_cache_valid_
Definition: Shape.h:116
geo::Shape::Shape
Shape()
Definition: Shape.cpp:139
std::istream
geo::Mesh
Definition: Mesh.h:25
geo::Shape::~Shape
virtual ~Shape()
Definition: Shape.cpp:142
Ray.h
geo::Shape
A geometric description of a shape.
Definition: Shape.h:19
geo::Shape::clone
virtual Shape * clone() const
Definition: Shape.cpp:145