Visualization LibraryA lightweight C++ OpenGL middleware for 2D/3D graphics |
[Home] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://www.visualizationlibrary.com */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef EdgeExtractor_INCLUDE_ONCE 00033 #define EdgeExtractor_INCLUDE_ONCE 00034 00035 #include <vlCore/Object.hpp> 00036 #include <vlCore/Vector3.hpp> 00037 #include <vlGraphics/link_config.hpp> 00038 #include <vector> 00039 #include <set> 00040 00041 namespace vl 00042 { 00043 class SceneManager; 00044 class Rendering; 00045 class Actor; 00046 class ActorCollection; 00047 class Geometry; 00048 00073 class VLGRAPHICS_EXPORT EdgeExtractor: public Object 00074 { 00075 public: 00077 class Edge 00078 { 00079 public: 00080 Edge(): mIsCrease(false) {} 00081 Edge(const fvec3& v1, const fvec3& v2) 00082 { 00083 mIsCrease = false; 00084 if (v1<v2) 00085 { 00086 mVertex1 = v1; 00087 mVertex2 = v2; 00088 } 00089 else 00090 { 00091 mVertex1 = v2; 00092 mVertex2 = v1; 00093 } 00094 } 00095 00096 void setVertex1(const fvec3& v) { mVertex1 = v; } 00097 const fvec3& vertex1() const { return mVertex1; } 00098 00099 void setVertex2(const fvec3& v) { mVertex2 = v; } 00100 const fvec3& vertex2() const { return mVertex2; } 00101 00102 void setNormal1(const fvec3& v) { mNormal1 = v; } 00103 const fvec3& normal1() const { return mNormal1; } 00104 00105 void setNormal2(const fvec3& v) { mNormal2 = v; } 00106 const fvec3& normal2() const { return mNormal2; } 00107 00108 bool isCrease() const { return mIsCrease; } 00109 void setIsCrease(bool iscrease) { mIsCrease = iscrease; } 00110 00111 bool operator<(const Edge& other) const 00112 { 00113 if (vertex1() != other.vertex1()) 00114 return vertex1() < other.vertex1(); 00115 else 00116 return vertex2() < other.vertex2(); 00117 } 00118 00119 bool operator==(const Edge& other) const 00120 { 00121 return (vertex1() == other.vertex1() && vertex2() == other.vertex2()) || 00122 (vertex1() == other.vertex2() && vertex2() == other.vertex1()); 00123 } 00124 00125 protected: 00126 fvec3 mVertex1; 00127 fvec3 mVertex2; 00128 fvec3 mNormal1; 00129 fvec3 mNormal2; 00130 bool mIsCrease; 00131 }; 00132 00133 public: 00134 virtual const char* className() { return "vl::EdgeExtractor"; } 00135 EdgeExtractor(): mCreaseAngle(45.0f), mWarnNonManifold(false) 00136 { 00137 VL_DEBUG_SET_OBJECT_NAME() 00138 } 00139 00140 void extractEdges(Geometry* geom); 00141 bool extractEdges(Actor* actor); 00142 void extractEdges(ActorCollection* actors); 00143 void extractEdges(SceneManager* scenemanager); 00144 void extractEdges(Rendering* rendering); 00145 00146 ref<Geometry> generateEdgeGeometry() const; 00147 00148 const std::vector<Edge>& edges() const { return mEdges; } 00149 std::vector<Edge>& edges() { return mEdges; } 00150 00151 void reset() { mEdges.clear(); } 00152 00154 float creaseAngle() const { return mCreaseAngle; } 00156 void setCreaseAngle(float a) { mCreaseAngle = a; } 00157 00158 bool warnNonManifold() const { return mWarnNonManifold; } 00159 void setWarnNonManifold(bool warn_on) { mWarnNonManifold = warn_on; } 00160 00161 protected: 00162 void addEdge(std::set<EdgeExtractor::Edge>& edges, const EdgeExtractor::Edge& e, const fvec3& n); 00163 00164 protected: 00165 std::vector<Edge> mEdges; 00166 float mCreaseAngle; 00167 bool mWarnNonManifold; 00168 }; 00169 } 00170 00171 #endif