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

zcross_path.H

Go to the documentation of this file.
00001 /**********************************************************************
00002  * zcross_path.H:
00003  **********************************************************************/
00004 #ifndef ZCROSS_PATH_H_IS_INCLUDED
00005 #define ZCROSS_PATH_H_IS_INCLUDED
00006 
00007 #include "bvert.H"
00008 #include "bsimplex.H"
00009 
00010 /*!
00011  *  \brief A segment of a zero crossing line on a surface.
00012  *
00013  *  This is meant to be part of a sequence (like an ARRAY or vector) of ZXseg's
00014  *  that form one of more zero crossing lines.  Each ZXseg doesn't actually hold
00015  *  a segment, it just has a point that should be connected (to form segments) to
00016  *  the points in the ZXseg's before and after it in the sequence.  Some ZXseg's
00017  *  can also be marked with an end flag.  The point in a ZXseg marked with the
00018  *  end flag is the last point in a zero crossing line.  A ZXseg after one marked
00019  *  with the end flag in a sequence is the beginning of a new zero crossing line.
00020  *
00021  *  \note This class is mainly geared towards representing zero crossing lines of
00022  *  N dot V (silhouettes) on a mesh (and has some things specific to that purpose
00023  *  built in).  However it has also been used (in a somewhat hackish fashion) to
00024  *  represent other types of zero crossing lines.
00025  *
00026  */
00027 class ZXseg {
00028    
00029    protected:
00030    
00031       //! \brief Starting point(location) of the segment.
00032       //! 
00033       //! This will be connected to the point in the next ZXseg in the sequence
00034       //! to form a segment.  Likewise, the point in the previous ZXseg in the
00035       //! the sequence (if there is one) will be connect to this to form a segment.
00036       Wpt  _p;
00037       
00038       //! \brief Ether a segment or a face a segment lies on.
00039       //!
00040       //! In general this is the face that the segment starting at \p _p will
00041       //! pass through.  Sometimes it might be an edge instead (though it unclear
00042       //! at the time of this writing if or when this occurs).
00043       Bsimplex*  _s;
00044       
00045       //! \brief Starting vertex of the segment
00046       //!
00047       //! \question What is this used for?
00048       //! \question Is this a hold over from the older edge representation of
00049       //! silhouettes that this was derived from?
00050       Bvert*     _v;
00051       
00052       //! \brief Confidence of point
00053       //!
00054       //! The confidence of the point on the zero crossing line between 0.0 and
00055       //! 1.0.  0.0 indicates the point isn't very important (which usually means
00056       //! it shouldn't be drawn).  1.0 indicates the point is very important
00057       //! which usually means to always draw it.
00058       //!
00059       //! \note Used to be "Direction of gradiant"
00060       double     _g;
00061       
00062       //! \brief Barycentric coordinates
00063       //!
00064       //! Barycentric coordinates of the point on the Bsimplex \p _s.
00065       Wvec _bc;
00066       
00067       //! \brief Stroke Type
00068       //!
00069       //! The type of the stroke.  Used at some point in the rendering process
00070       //! to determine the style of the stroke to draw for the zero crossing
00071       //! line containing this ZXseg.
00072       int        _type;
00073       
00074       //! \brief Termination Deliminter
00075       //!
00076       //! Flags this ZXseg as the end of a contiguous zero crossing line.
00077       bool       _end;
00078       
00079    public:
00080    
00081       //! \name Constructors
00082       //@{
00083       
00084       ZXseg(Bsimplex* s, CWpt &pt, Bvert * v, bool grad, mlib::CWvec& bc,
00085             int type = 0, bool end = 0)
00086          : _p(pt),
00087            _s(s),
00088            _v(v),
00089            _g(grad ? 1.0 : 0.0),
00090            _bc(bc),
00091            _type(type),
00092            _end(end)
00093       {}
00094    
00095       ZXseg(Bsimplex* s, CWpt &pt, Bvert * v, double conf, mlib::CWvec& bc,
00096             int type = 0, bool end = 0)
00097          : _p(pt),
00098            _s(s),
00099            _v(v),
00100            _g(conf),
00101            _bc(bc),
00102            _type(type),
00103            _end(end)
00104       {}
00105 
00106       //! \brief Constructor for case of null face.
00107       ZXseg(Bsimplex* s, CWpt &pt, Bvert * v, bool grad, Bsimplex* bary_s,
00108             int type = 0, bool end = 0)
00109          : _p(pt),
00110            _s(s),
00111            _v(v),
00112            _g(grad ? 1.0 : 0.0),
00113            _type(type),
00114            _end(end)
00115       {
00116          // this is a slow calc for now, but needed when we
00117          // don't know what face we're on
00118    
00119          // Project_barycentric is a vertual function so the
00120          // correct definition will be called depending if bary_s
00121          // is edge of face
00122          if (bary_s)
00123             bary_s->project_barycentric ( _p, _bc );
00124       }   
00125 
00126       ZXseg ()
00127       {
00128          _s = NULL;
00129          _v = NULL;
00130          _g = false;
00131    
00132       }
00133       
00134       //@}
00135       
00136       //! \name Accessor Functions
00137       //@{
00138       
00139       bool       end()    const { return _end; }
00140       Wpt& p()            { return _p; }  
00141       Bsimplex*  s()      const { return _s; }
00142       //! if we really really want the face we can get it
00143       //! if no face is there you will get a NULL
00144       Bface*     f()      const { return get_bface(_s); }
00145       Bvert*     v()      const { return _v; }
00146       bool       g()      const { return _g > 0.0; }
00147       double     conf()   const { return _g; }
00148       int        type()   const { return _type; }
00149       CWvec& bc()   const { return _bc; }
00150    
00151       
00152       void set_end()          { _end = true; }
00153       void setf(Bsimplex* s)  { _s = s; }                             
00154       void setv(Bvert* v)     { _v = v; }
00155       void setg(bool g)       { _g = g ? 1.0 : 0.0; }
00156       void setg(double g)     { _g = g; }
00157       void settype(int t)     { _type = t;}
00158       void set_bary( Bsimplex* s )
00159          { if(s) s->project_barycentric ( _p, _bc); }
00160       
00161       //@}
00162       
00163       //! \name Overloaded Operators
00164       //@{
00165          
00166       bool operator ==( const ZXseg& z) const
00167          {return _p==z._p && _s==z._s && _v==z._v && _g==z._g;}
00168       
00169       //@}
00170 
00171 };
00172 
00173 #define CZXseg const ZXseg
00174 
00175 class ZcrossCB;
00176 /**********************************************************************
00177  * class to define zero crossing silhouettes on a mesh.
00178  **********************************************************************/
00179 #define CZcrossPath const ZcrossPath
00180 class ZcrossPath
00181 {
00182 public:
00183    //******** MANAGERS ********
00184 
00185    // Create an empty strip:
00186    ZcrossPath() : _patch(0), _index(-1) {}
00187 
00188    // Given a list of edges to search, build a strip of
00189    // edges that satisfy a given property.
00190    ZcrossPath(CBface_list& list) :
00191          _patch(0),
00192          _index(-1)
00193    {
00194 
00195       build(list);
00196    }
00197 
00198    virtual ~ZcrossPath() {}
00199 
00200    //******** BUILDING ********
00201 
00202    void build(CBface_list& list);
00203 
00204    bool has_sil(Bface* f); // is it a silhouette face?
00205 
00206    void start_sil(Bface * f); //find legal face, build silpaths
00207    void get_g(Bface*f , double g[3], int& ex1, int& ex2);
00208 
00209    Bface* sil_walk_search ( Bface * f , Bvert* vert[3], double g[3] ); //better search algorithm
00210    Bface* sil_search (Bface * last , Bface *f); //continue on a good build
00211    Bface* sil_finish (Bface * last , Bface *f); //find the far point (at breaks)
00212 
00213    // bool has_sil(Bface* f, double& g1, double& g2, double& g3, Wpt& x1, mlib::Wpt&x2);
00214 
00215    // Continue building the strip from a given edge type,
00216    // starting at the given edge and one of its vertices.
00217    // If the vertex is nil a vertex is chosen from the edge
00218    // arbitrarily.
00219 
00220 
00221    // Add another segment to the strip:
00222    //void add(Bface* f, CWpt& pt, bool grad) { _faces += f; _points += pt; _grads += grad; }
00223    //void add_vert(Bvert* v ) { _verts += v; }
00224 
00225    void add_seg ( Bface* f , CWpt& pt, Bvert* v, bool grad, mlib::CWvec& bc)
00226    {
00227       bool end = (f) ? false : true;      
00228       _segs += ZXseg ( f, pt, v, grad, bc, 0, end );
00229    }
00230    void add_seg ( const ZXseg& seg) { _segs += seg;  }
00231 
00232    void add_seg ( Bface* f , CWpt& pt, Bvert* v, bool grad, Bface * bary_f)
00233    {
00234       bool end = (f) ? false : true;       
00235       _segs += ZXseg ( f, pt, v, grad, bary_f, 0 ,end);
00236    } 
00237 
00238    // Clear the strip:
00239    virtual void reset() { _segs.clear(); }
00240 
00241    //******** ACCESSORS ********
00242    Patch*         patch()        const { return _patch; }
00243    CARRAY<ZXseg>& segs()         const { return _segs; }
00244    ARRAY<ZXseg>&  segs()         { return _segs; }
00245 
00246 
00247 
00248    Bface* face(int i)            const { return _segs[i].f(); }
00249    CWpt& point(int i)            const { return _segs[i].p(); }
00250    Bvert* vert(int i )           const { return _segs[i].v(); }
00251    bool grad(int i)              const { return _segs[i].g(); }
00252    CWvec& bc(int i)              const { return _segs[i].bc();}
00253    int type(int i)               const { return _segs[i].type();}
00254 
00255    ZXseg&  seg(int i )                 { return _segs[i]; }
00256    void set_eye(CWpt& eye )     { _eye = eye; }
00257    CWpt& eye()                  const   { return _eye; }
00258    CWpt& first()                const { return _segs[0].p(); }
00259    CWpt& last()                 const { return _segs[num()-1].p(); }
00260 
00261    //bool   empty()               const { return _points.empty(); }
00262    bool   empty()               const { return _segs.empty(); }
00263    //int    num()                 const { return _points.num(); }
00264    int    num()               const { return _segs.num(); }
00265 
00266    BMESH* mesh() const
00267    {
00268       return empty() ? (BMESH*)0 : _segs[0].f()->mesh();
00269    }
00270 
00271    //******** THE MAIN JOB ********
00272 
00273 
00274 protected:
00275    friend class Patch;
00276    //******** DATA ******** 
00277    ARRAY <ZXseg>        _segs;  
00278    Patch*               _patch;       // patch this is assigned to
00279    int                  _index;       // index in patch's list
00280    Wpt                  _eye;         // eye_local ( set by bmesh )
00281    //******** PROTECTED METHODS ********
00282 
00283    // used internally when generating
00284    // strips of edges of a given type:
00285 
00286    // setting the Patch -- nobody's bizness but the Patch's:
00287    // (to set it call Patch::add(ZcrossPath*))
00288    void   set_patch(Patch* p)           { _patch = p; }
00289    void   set_patch_index(int k)        { _index = k; }
00290    int    patch_index() const           { return _index; }
00291 };
00292 
00293 // XXX - transplanted from npr/zxedge_stroke_texture.H 7/10/2005:
00294 // TYPES of LINES  that zxedge_stroke ( and thus sil&crease) may encounter
00295 enum { STYPE_SIL=0, STYPE_BF_SIL, STYPE_BORDER, STYPE_CREASE, STYPE_SUGLINE, STYPE_WPATH, STYPE_POLYLINE, STYPE_NUM } ;
00296 
00297 #endif // ZCROSS_PATH_H_IS_INCLUDED
00298 
00299 /* end of file zcross_path.H */

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