Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 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 VL_INSTRUMENT_CLASS(vl::EdgeExtractor, Object) 00076 00077 public: 00079 class Edge 00080 { 00081 public: 00082 Edge(): mIsCrease(false) {} 00083 Edge(const fvec3& v1, const fvec3& v2) 00084 { 00085 mIsCrease = false; 00086 if (v1<v2) 00087 { 00088 mVertex1 = v1; 00089 mVertex2 = v2; 00090 } 00091 else 00092 { 00093 mVertex1 = v2; 00094 mVertex2 = v1; 00095 } 00096 } 00097 00098 void setVertex1(const fvec3& v) { mVertex1 = v; } 00099 const fvec3& vertex1() const { return mVertex1; } 00100 00101 void setVertex2(const fvec3& v) { mVertex2 = v; } 00102 const fvec3& vertex2() const { return mVertex2; } 00103 00104 void setNormal1(const fvec3& v) { mNormal1 = v; } 00105 const fvec3& normal1() const { return mNormal1; } 00106 00107 void setNormal2(const fvec3& v) { mNormal2 = v; } 00108 const fvec3& normal2() const { return mNormal2; } 00109 00110 bool isCrease() const { return mIsCrease; } 00111 void setIsCrease(bool iscrease) { mIsCrease = iscrease; } 00112 00113 bool operator<(const Edge& other) const 00114 { 00115 if (vertex1() != other.vertex1()) 00116 return vertex1() < other.vertex1(); 00117 else 00118 return vertex2() < other.vertex2(); 00119 } 00120 00121 bool operator==(const Edge& other) const 00122 { 00123 return (vertex1() == other.vertex1() && vertex2() == other.vertex2()) || 00124 (vertex1() == other.vertex2() && vertex2() == other.vertex1()); 00125 } 00126 00127 protected: 00128 fvec3 mVertex1; 00129 fvec3 mVertex2; 00130 fvec3 mNormal1; 00131 fvec3 mNormal2; 00132 bool mIsCrease; 00133 }; 00134 00135 public: 00136 EdgeExtractor(): mCreaseAngle(45.0f), mWarnNonManifold(false) 00137 { 00138 VL_DEBUG_SET_OBJECT_NAME() 00139 } 00140 00141 void extractEdges(Geometry* geom); 00142 bool extractEdges(Actor* actor); 00143 void extractEdges(ActorCollection* actors); 00144 void extractEdges(SceneManager* scenemanager); 00145 void extractEdges(Rendering* rendering); 00146 00147 ref<Geometry> generateEdgeGeometry() const; 00148 00149 const std::vector<Edge>& edges() const { return mEdges; } 00150 std::vector<Edge>& edges() { return mEdges; } 00151 00152 void reset() { mEdges.clear(); } 00153 00155 float creaseAngle() const { return mCreaseAngle; } 00157 void setCreaseAngle(float a) { mCreaseAngle = a; } 00158 00159 bool warnNonManifold() const { return mWarnNonManifold; } 00160 void setWarnNonManifold(bool warn_on) { mWarnNonManifold = warn_on; } 00161 00162 protected: 00163 void addEdge(std::set<EdgeExtractor::Edge>& edges, const EdgeExtractor::Edge& e, const fvec3& n); 00164 00165 protected: 00166 std::vector<Edge> mEdges; 00167 float mCreaseAngle; 00168 bool mWarnNonManifold; 00169 }; 00170 } 00171 00172 #endif