Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

geometry/topology.hh
Go to the documentation of this file.
00001 /* Topology.
00002  * how to subdivide
00003  */
00004 
00005 #ifndef topology_hh
00006 #define topology_hh
00007 
00008 #include <memory>
00009 #include <map>
00010 #include "basics/typedefs.hh"
00011 #include "basics/Zm.hh"
00012 #include "basics/debug.hh"
00013 #include "toolbox/scannerConnectors.hh"
00014 #include "connector.hh"
00015 #include "quadsubdiv.hh"
00016 #include "strategyChange.hh"
00017 
00018 #define VertexConstr_D 0
00019 
00020 namespace concepts {
00021 
00022   // ***************************************************************** match **
00023 
00028   int match(const Connector1& edg0, const Connector1& edg1, int idx[]);
00029 
00030 
00031   // **************************************************************** Vertex **
00032 
00037   class Vertex : public Connector0 {
00038   public:
00040     Vertex(const Attribute attrib = Attribute()) : Connector0(attrib) {
00041       DEBUGL(VertexConstr_D, key());
00042     }
00043 
00044     virtual ~Vertex();
00045 
00046     virtual Vertex* child(uint i, bool mode = 0) { return this; }
00047     virtual const Vertex* child(uint) const { return this; }
00048 
00052     inline Vertex* clone() const;
00053   protected:
00054     virtual std::ostream& info(std::ostream& os) const;
00055   private:
00057     Vertex(const Attribute attrib, const Key& key) : Connector0(attrib, key) {}
00058   };
00059 
00060   Vertex* Vertex::clone() const {
00061     return new Vertex(attrib(), key());
00062   }
00063 
00064   // ****************************************************************** Edge **
00065 
00070   class Edge : public Connector1 {
00071 
00072   public:
00078     Edge(Vertex& vtx0, Vertex& vtx1, const Attribute attrib = Attribute());
00080     Edge(Edge& edg0, Edge& edg1);
00081     virtual ~Edge();
00082 
00096     virtual Edge* child(uint i, bool mode = 0);
00097     virtual const Edge* child(uint i) const;
00098 
00099     Vertex* vertex(uint i) const { return i < 2 ? vtx_[i] : 0; }
00100 
00104     inline Edge* clone(Vertex& vtx0, Vertex& vtx1) const;
00105   protected:
00107     Edge(Vertex& vtx0, Vertex& vtx1, const Attribute attrib, const Key& key);
00108 
00109     virtual std::ostream& info(std::ostream& os) const;
00111     Edge* lnk_;
00112 
00116     Edge* chld_;
00117 
00119     Vertex* vtx_[2];
00120 
00125     bool regular_;
00126   };
00127 
00128   Edge* Edge::clone(Vertex& vtx0, Vertex& vtx1) const {
00129     return new Edge(vtx0, vtx1, attrib(), key());
00130   }
00131 
00132   // ********************************************************** InfiniteEdge **
00133 
00139   class InfiniteEdge : public Connector1 {
00140 
00141   public:
00146     InfiniteEdge(Vertex& vtx, const Attribute attrib = Attribute());
00147     virtual ~InfiniteEdge();
00148 
00160     virtual Connector1* child(uint i, bool mode = 0);
00161     virtual const Connector1* child(uint i) const;
00162 
00163     Vertex* vertex(uint i = 0) const { return i < 1 ? vtx_ : 0; }
00164   protected:
00165     virtual std::ostream& info(std::ostream& os) const;
00167     Edge* lnk_;
00168 
00172     InfiniteEdge* chld_;
00173 
00175     Vertex* vtx_;
00176   };
00177 
00178   // ************************************************************** Triangle **
00179 
00188   class Triangle : public Connector2 {
00189   public:
00201     Triangle(Edge& edg0, Edge& edg1, Edge& edg2, 
00202        const Attribute attrib = Attribute());
00203     virtual ~Triangle();
00204 
00216     virtual Triangle* child(uint i, bool mode = 0);
00217     virtual const Triangle* child(uint i) const;
00218 
00219     Edge* edge(uint i) const { return i < 3 ? edg_[i] : 0; }
00220     Vertex* vertex(uint i) const { return i<3 ? edg_[i]->vertex(rho_[i]) : 0; }
00221 
00225     Z2 rho(int i) const { return rho_[i]; }
00226 
00230     inline Triangle* clone(Edge& edg0, Edge& edg1, Edge& edg2) const;
00231   protected:
00232     virtual std::ostream& info(std::ostream& os) const;
00233   private:
00235     Triangle(Edge& edg0, Edge& edg1, Edge& edg2,
00236        const Attribute attrib, const Key& key, const Z2 rho[]);
00237 
00239     Triangle* lnk_;
00240 
00244     Triangle* chld_;
00245 
00247     Edge* edg_[3];
00248 
00250     Z2 rho_[3];
00251   };
00252 
00253   Triangle* Triangle::clone(Edge& edg0, Edge& edg1, Edge& edg2) const {
00254     return new Triangle(edg0, edg1, edg2, attrib(), key(), rho_);
00255   }
00256 
00257   // ****************************************************************** Quad **
00258 
00267   class Quad : public Connector2 {
00268     friend class QuadSubdiv4;
00269     friend class QuadSubdiv2H;
00270     friend class QuadSubdiv2V;
00271   public:
00285     Quad(Edge& edg0, Edge& edg1, Edge& edg2, Edge& edg3, 
00286    const Attribute attrib = Attribute());
00293     Quad(const Quad& quad, uint i);
00295     virtual ~Quad();
00296 
00309     virtual Quad* child(uint i, bool mode = 0);
00310     virtual const Quad* child(uint i) const;
00311 
00312     Edge* edge(uint i) const { return i < 4 ? edg_[i] : 0; }
00313     Vertex* vertex(uint i) const { return i<4 ? edg_[i]->vertex(rho_[i]) : 0; }
00314 
00315     int numVertices() const {
00316       return 4;
00317     }
00318 
00319     int numEdges() const {
00320       return 4;
00321     }
00322 
00330     Z2 rho(int i) const { return rho_[i]; }
00331 
00332     bool regular() const { return regular_; }
00333 
00337     inline Quad* clone(Edge& edg0, Edge& edg1, Edge& edg2, Edge& edg3) const;
00338 
00350     void setStrategy(const QuadSubdivision* strategy = 0)
00351       throw(StrategyChange);
00352 
00358     const QuadSubdivision* getStrategy() const { return subdivStrategy_; }
00359   protected:
00360     virtual std::ostream& info(std::ostream& os) const;
00361 
00363     Quad(Edge& edg0, Edge& edg1, Edge& edg2, Edge& edg3,
00364    const Attribute attrib, const Key& key, const Z2 rho[]);
00365 
00367     concepts::Joiner<Quad*, 1>* chld_;
00368 
00370     bool regular_;
00371 
00373     Edge* edg_[4];
00374 
00376     Z2 rho_[4];
00377 
00379     static std::map<Key, Z2> rhoTriv_;
00380 
00382     const QuadSubdivision* subdivStrategy_;
00383 
00385     inline Scan<Quad>* children_() const {
00386       return new concepts::PListScan<Quad>(*chld_);
00387     }
00388 
00390     void edgeAssertion_() const;
00391 };
00392 
00393   Quad* Quad::clone(Edge& edg0, Edge& edg1, Edge& edg2, Edge& edg3) const {
00394     return new Quad(edg0, edg1, edg2, edg3, attrib(), key(), rho_);
00395   }
00396 
00397 
00398   // ********************************************************** InfiniteQuad **
00399 
00419   class InfiniteQuad : public Connector2 {
00420     friend class InfQuadSubdiv2V;
00421   public:
00433     InfiniteQuad(InfiniteEdge& edg0, Edge& edg1, InfiniteEdge& edg2,
00434    const Attribute attrib = Attribute());
00436     virtual ~InfiniteQuad();
00437 
00450     virtual Connector2* child(uint i, bool mode = 0);
00451     virtual const Connector2* child(uint i) const;
00452 
00453     Connector1* edge(uint i) const;
00454     Vertex* vertex(uint i) const { return i<2 ? infEdg_[i]->vertex() : 0; }
00455 
00456     int numVertices() const {
00457       return 2;
00458     }
00459 
00460     int numEdges() const {
00461       return 3;
00462     }
00463 
00469     Z2 rho() const { return rho_; }
00470 
00474     inline InfiniteQuad* clone(InfiniteEdge& edg0, Edge& edg1,
00475              InfiniteEdge& edg2) const;
00476 
00488     void setStrategy(const InfQuadSubdivision* strategy = 0)
00489       throw(StrategyChange);
00490 
00496     const InfQuadSubdivision* getStrategy() const { return subdivStrategy_; }
00497   protected:
00498     virtual std::ostream& info(std::ostream& os) const;
00499 
00501     InfiniteQuad(InfiniteEdge& edg0, Edge& edg1, InfiniteEdge& edg2, 
00502      const Attribute attrib, const Key& key, const Z2 rho);
00503 
00505     concepts::Joiner<Connector2*, 1>* chld_;
00506 
00508     Edge* edg_;
00509 
00511     InfiniteEdge* infEdg_[2];
00512 
00514     Z2 rho_;
00515 
00517     const InfQuadSubdivision* subdivStrategy_;
00518 
00520     inline Scan<Connector2>* children_() const {
00521       return new concepts::PListScan<Connector2>(*chld_);
00522     }
00523 
00525     void edgeAssertion_() const;
00526 };
00527 
00528   InfiniteQuad* InfiniteQuad::clone(InfiniteEdge& edg0, Edge& edg1,
00529             InfiniteEdge& edg2) const {
00530     return new InfiniteQuad(edg0, edg1, edg2, attrib(), key(), rho_);
00531   }
00532 
00533 } // namespace concepts
00534 
00535 #endif

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)