Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

lpatch.H

Go to the documentation of this file.
00001 #ifndef LPATCH_H_HAS_BEEN_INCLUDED
00002 #define LPATCH_H_HAS_BEEN_INCLUDED
00003 
00004 #include "patch.H"
00005 #include "lmesh.H"
00006 
00007 /**********************************************************************
00008  * Lpatch:
00009  *
00010  *   Specialized kind of Patch that deals with subdivision hierarchy.
00011  *   Each Lpatch has a child patch at the next finer level in the
00012  *   hierarchy. It may also have a parent. When it has no parent, it
00013  *   is the "control patch." The control patch is responsible for
00014  *   keeping a list of GTextures (like a normal Patch). Child patches
00015  *   don't bother with GTextures. Instead, the GTextures of the
00016  *   control patch are used to render the child patches (according to
00017  *   the "current" subdivision level).
00018  *
00019  *   Soon (as of 9/2002), there will be the notion of a control patch
00020  *   that is NOT in the control mesh. This will be used to represent a
00021  *   piece of mesh that is added to a subdivision mesh at level k > 0.
00022  *
00023  **********************************************************************/
00024 class Lpatch : public Patch {
00025    friend class LMESH;
00026  public:
00027    //******** MANAGERS ********
00028    virtual ~Lpatch();
00029 
00030    //******** ACCESSORS ********
00031 
00032    // Owning mesh, conveniently upcast to LMESH:
00033    LMESH*  lmesh()       const { return (LMESH*)_mesh; }
00034    
00035    // Parent and child patches in the subdivision hierarchy:
00036    Patch* parent()       const { return (Patch*)_parent; }
00037    Patch* child()        const { return (Patch*)_child; }
00038 
00039    // More upcasts (convenience):
00040    Lface*  lface(int i)  const { return (Lface*)_faces[i]; }
00041    Lstrip* lstrip(int i) const { return (Lstrip*)_tri_strips[i]; }
00042 
00043    //******** SUBDIVISION HIERARCHY ********
00044 
00045    // Control mesh for the subdivision hierarchy:
00046    LMESH* control_mesh() const { return _mesh ? lmesh()->control_mesh() : 0; }
00047 
00048    // Level of the currently drawn mesh in the hierarchy:
00049    int cur_level()       const { return _mesh ? lmesh()->cur_level() : 0; }
00050 
00051    // Returns the child patch at the given subdivision level
00052    // RELATIVE to this patch. E.g.:
00053    //
00054    //     k | returned Patch
00055    // ---------------------
00056    //    -1 | _parent
00057    //     0 | this
00058    //     1 | _child
00059    //     2 | _child->_child
00060    //      ...
00061    //
00062    Lpatch* sub_patch(int k);
00063 
00064    void delete_child() { delete _child; _child = 0;}
00065    
00066 
00067    //******** Patch VIRTUAL METHODS ********
00068 
00069    // Returns the corresponding patch at the "current"
00070    // subdivision level:
00071    virtual Patch* cur_patch() {
00072       return sub_patch(cur_level() - subdiv_level());
00073    }
00074 
00075    // Produces (if needed) and returns a child patch
00076    // at the next subdivision level:
00077    virtual Patch* get_child();
00078 
00079    // enters into child relationship w/ given patch,
00080    // if it's legal. returns true on success
00081    bool set_parent(Patch* p);
00082 
00083    // Returns the highest-level parent Patch of this one.
00084    // NB. the control patch may not belong to the control mesh,
00085    // in the case that a patch has been added at a level > 0.
00086    virtual Patch* ctrl_patch() const {
00087       return _parent ? _parent->ctrl_patch() : (Patch*)this;
00088    }
00089 
00090    bool is_ctrl_patch() const { return _parent == NULL; }
00091 
00092    // The level of this Patch relative to its control Patch:
00093    virtual int rel_subdiv_level() {
00094       return subdiv_level() - ctrl_patch()->subdiv_level();
00095    }
00096 
00097    // Returns mesh elements at current subdivision level:
00098    virtual CBface_list& cur_faces()     const;
00099    virtual Bvert_list   cur_verts()     const;
00100    virtual Bedge_list   cur_edges()     const;
00101 
00102    bool faces_at_level ( int l, Bface_list& faces );
00103 
00104    // Returns number of faces at current subdiv level:
00105    virtual int num_faces() const;
00106 
00107    // Diagnostic:
00108    virtual double tris_per_strip() const;
00109 
00110    virtual int  draw_tri_strips(StripCB*);
00111    virtual int  draw_sil_strips(StripCB*);
00112 
00113    //******** VERSIONING/CACHING ********
00114    virtual void triangulation_changed();
00115 
00116    // used by textures to tell if they are up-to-date
00117    // (e.g., display lists may be out of date):
00118    virtual void changed() { ctrl_patch()->Patch::changed(); }
00119    virtual uint stamp()   { return ctrl_patch()->Patch::stamp(); }
00120 
00121    //******** BMESHdrawable METHODS ********
00122    virtual int draw(CVIEWptr&);
00123 
00124    //**************** DATA_ITEM methods ****************
00125 
00126    virtual CTAGlist &tags  () const;
00127    virtual DATA_ITEM   *dup()  const;
00128 
00129    static TAGlist *_lpatch_tags;
00130    virtual void   put_parent_patch      (TAGformat &)  const;
00131    virtual void   get_parent_patch      (TAGformat &);
00132 
00133 
00134 
00135    //***********Protected**********************************
00136  protected:
00137 
00138    Lpatch*      _parent;        // parent patch in subdivision hierarchy
00139    Lpatch*      _child;         // child patch in subdivision hierarchy
00140 
00141    //******** INTERNAL METHODS ********
00142 
00143    // Normal people can't make these --
00144    // get yours from an LMESH:
00145    Lpatch(LMESH *mesh) : Patch(mesh), _parent(0), _child(0) {}
00146 
00147    // Clear subdivision strips down to given level:
00148    void clear_subdiv_strips(int level);
00149 };
00150 
00151 #endif  // LPATCH_H_HAS_BEEN_INCLUDED
00152 
00153 /* end of file lpatch.H */
00154 

Generated on Mon Sep 18 11:39:32 2006 for jot by  doxygen 1.4.4