Easy3D 2.5.3
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
34#include <easy3d/core/types.h>
35
36
37namespace easy3d {
38
39 class Renderer;
40 class Manipulator;
41
48 class Model
49 {
50 public:
53 explicit Model(const std::string& name = "unknown");
54 virtual ~Model() = default;
55
58 void set_name(const std::string& n) { name_ = n; }
60 const std::string& name() const { return name_; }
61
69 const Box3& bounding_box(bool recompute = false) const;
70
76
78 virtual std::vector<vec3>& points() = 0;
80 virtual const std::vector<vec3>& points() const = 0;
81
83 bool empty() const { return points().empty(); };
84
86 virtual void property_stats(std::ostream &output) const {}
87
92 void set_renderer(Renderer* r) { renderer_ = r; }
94 Renderer* renderer() { return renderer_; }
96 const Renderer* renderer() const { return renderer_; }
97
102 void set_manipulator(Manipulator* manip) { manipulator_ = manip; }
103
105 Manipulator* manipulator() { return manipulator_; }
107 const Manipulator* manipulator() const { return manipulator_; }
108
109 protected:
110 std::string name_;
111
112 Box3 bbox_;
113 bool bbox_known_;
114
115 Renderer* renderer_; // for rendering
116 Manipulator* manipulator_; // for manipulation
117 };
118}
119
120#endif // EASY3D_CORE_MODEL_H
A manipulator is for manipulation of an object.
Definition: manipulator.h:62
The base class of renderable 3D models.
Definition: model.h:49
virtual std::vector< vec3 > & points()=0
The vertices of the model.
Manipulator * manipulator()
Gets the manipulator attached to this model.
Definition: model.h:105
void set_renderer(Renderer *r)
Sets the renderer of this model.
Definition: model.h:92
const std::string & name() const
The name of a model.
Definition: model.h:60
const Renderer * renderer() const
Gets the constant renderer of this model.
Definition: model.h:96
void set_manipulator(Manipulator *manip)
Attaches a manipulator to this model.
Definition: model.h:102
bool empty() const
Tests if the model is empty.
Definition: model.h:83
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:57
const Manipulator * manipulator() const
Gets the manipulator attached to this model.
Definition: model.h:107
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:86
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
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:32
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:41
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:58
A Renderer manages the drawables (and thus the rendering) of a model.
Definition: renderer.h:61
Definition: collider.cpp:182