Easy3D 2.6.1
Loading...
Searching...
No Matches
model.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_CORE_MODEL_H
28#define EASY3D_CORE_MODEL_H
29
30
31#include <string>
32#include <vector>
33#include <memory>
34
35#include <easy3d/core/types.h>
36
37
38namespace easy3d {
39
40 class Renderer;
41 class Manipulator;
42
49 class Model
50 {
51 public:
54 explicit Model(const std::string& name = "unknown");
55 virtual ~Model();
56
59 void set_name(const std::string& n) { name_ = n; }
61 const std::string& name() const { return name_; }
62
70 const Box3& bounding_box(bool recompute = false) const;
71
77
79 virtual std::vector<vec3>& points() = 0;
81 virtual const std::vector<vec3>& points() const = 0;
82
84 bool empty() const { return points().empty(); };
85
87 virtual void property_stats(std::ostream &output) const {}
88
93 void set_renderer(std::shared_ptr<Renderer> r) { renderer_ = r; }
97 const Renderer* renderer() const;
98
103 void set_manipulator(std::shared_ptr<Manipulator> manip) { manipulator_ = manip; }
104
106 Manipulator* manipulator() { return manipulator_.get(); }
108 const Manipulator* manipulator() const { return manipulator_.get(); }
109
110 protected:
111 std::string name_;
112
113 Box3 bbox_;
114 bool bbox_known_;
115
116 std::shared_ptr<Renderer> renderer_; // for rendering
117 std::shared_ptr<Manipulator> manipulator_; // for manipulation
118 };
119}
120
121#endif // EASY3D_CORE_MODEL_H
A manipulator is for manipulation of an object.
Definition manipulator.h:58
virtual std::vector< vec3 > & points()=0
The vertices of the model.
Manipulator * manipulator()
Gets the manipulator attached to this model.
Definition model.h:106
const std::string & name() const
The name of a model.
Definition model.h:61
void set_manipulator(std::shared_ptr< Manipulator > manip)
Attaches a manipulator to this model.
Definition model.h:103
bool empty() const
Tests if the model is empty.
Definition model.h:84
void invalidate_bounding_box()
Invalidates the bounding box of the model. So when bounding_box() is called, the bounding box will be...
Definition model.cpp:60
const Manipulator * manipulator() const
Gets the manipulator attached to this model.
Definition model.h:108
virtual void property_stats(std::ostream &output) const
Prints the names of all properties to an output stream (e.g., std::cout).
Definition model.h:87
void set_renderer(std::shared_ptr< Renderer > r)
Sets the renderer of this model.
Definition model.h:93
Renderer * renderer()
Gets the renderer of this model.
Definition model.cpp:66
Model(const std::string &name="unknown")
Default constructor. The parameter name is optional, but it is useful for handling multiple models wi...
Definition model.cpp:33
virtual const std::vector< vec3 > & points() const =0
The vertices of the model.
const Box3 & bounding_box(bool recompute=false) const
The bounding box of the model.
Definition model.cpp:44
void set_name(const std::string &n)
Sets/Changes the name of a model. Assigning a name to a model is optional, but it is useful for handl...
Definition model.h:59
A Renderer manages the drawables (and thus the rendering) of a model.
Definition renderer.h:58
Definition collider.cpp:182
GenericBox< 3, float > Box3
A 3D axis-aligned bounding box of float type.
Definition types.h:108