Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
EdgeExtractor.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef EdgeExtractor_INCLUDE_ONCE
33 #define EdgeExtractor_INCLUDE_ONCE
34 
35 #include <vlCore/Object.hpp>
36 #include <vlCore/Vector3.hpp>
38 #include <vector>
39 #include <set>
40 
41 namespace vl
42 {
43  class SceneManager;
44  class Rendering;
45  class Actor;
46  class ActorCollection;
47  class Geometry;
48 
74  {
76 
77  public:
79  class Edge
80  {
81  public:
82  Edge(): mIsCrease(false) {}
83  Edge(const fvec3& v1, const fvec3& v2)
84  {
85  mIsCrease = false;
86  if (v1<v2)
87  {
88  mVertex1 = v1;
89  mVertex2 = v2;
90  }
91  else
92  {
93  mVertex1 = v2;
94  mVertex2 = v1;
95  }
96  }
97 
98  void setVertex1(const fvec3& v) { mVertex1 = v; }
99  const fvec3& vertex1() const { return mVertex1; }
100 
101  void setVertex2(const fvec3& v) { mVertex2 = v; }
102  const fvec3& vertex2() const { return mVertex2; }
103 
104  void setNormal1(const fvec3& v) { mNormal1 = v; }
105  const fvec3& normal1() const { return mNormal1; }
106 
107  void setNormal2(const fvec3& v) { mNormal2 = v; }
108  const fvec3& normal2() const { return mNormal2; }
109 
110  bool isCrease() const { return mIsCrease; }
111  void setIsCrease(bool iscrease) { mIsCrease = iscrease; }
112 
113  bool operator<(const Edge& other) const
114  {
115  if (vertex1() != other.vertex1())
116  return vertex1() < other.vertex1();
117  else
118  return vertex2() < other.vertex2();
119  }
120 
121  bool operator==(const Edge& other) const
122  {
123  return (vertex1() == other.vertex1() && vertex2() == other.vertex2()) ||
124  (vertex1() == other.vertex2() && vertex2() == other.vertex1());
125  }
126 
127  protected:
132  bool mIsCrease;
133  };
134 
135  public:
136  EdgeExtractor(): mCreaseAngle(45.0f), mWarnNonManifold(false)
137  {
138  VL_DEBUG_SET_OBJECT_NAME()
139  }
140 
141  void extractEdges(Geometry* geom);
142  bool extractEdges(Actor* actor);
143  void extractEdges(ActorCollection* actors);
144  void extractEdges(SceneManager* scenemanager);
145  void extractEdges(Rendering* rendering);
146 
147  ref<Geometry> generateEdgeGeometry() const;
148 
149  const std::vector<Edge>& edges() const { return mEdges; }
150  std::vector<Edge>& edges() { return mEdges; }
151 
152  void reset() { mEdges.clear(); }
153 
155  float creaseAngle() const { return mCreaseAngle; }
157  void setCreaseAngle(float a) { mCreaseAngle = a; }
158 
159  bool warnNonManifold() const { return mWarnNonManifold; }
160  void setWarnNonManifold(bool warn_on) { mWarnNonManifold = warn_on; }
161 
162  protected:
163  void addEdge(std::set<EdgeExtractor::Edge>& edges, const EdgeExtractor::Edge& e, const fvec3& n);
164 
165  protected:
166  std::vector<Edge> mEdges;
169  };
170 }
171 
172 #endif
bool operator<(const Edge &other) const
const fvec3 & normal2() const
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
const fvec3 & normal1() const
bool warnNonManifold() const
void setNormal2(const fvec3 &v)
const fvec3 & vertex2() const
The EdgeExtractor class extracts the edges from one or more Geometry objects.
float creaseAngle() const
The minimum angle (in degrees) considered to generate crease-edges.
const fvec3 & vertex1() const
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
void setWarnNonManifold(bool warn_on)
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Definition: Geometry.hpp:66
Visualization Library main namespace.
void setIsCrease(bool iscrease)
The base class for all the reference counted objects.
Definition: Object.hpp:158
void setVertex1(const fvec3 &v)
void setNormal1(const fvec3 &v)
The SceneManager class is the base class for all the scene managers.
bool operator==(const Edge &other) const
A single edge as extracted from the EdgeExtractor class.
The Rendering class collects all the information to perform the rendering of a scene.
Definition: Rendering.hpp:69
std::vector< Edge > & edges()
Defined as a simple subclass of Collection<Actor>, see Collection for more information.
Definition: Actor.hpp:479
const std::vector< Edge > & edges() const
std::vector< Edge > mEdges
void setCreaseAngle(float a)
The minimum angle (in degrees) considered to generate crease-edges.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
void setVertex2(const fvec3 &v)
Edge(const fvec3 &v1, const fvec3 &v2)