1 /**************************************************************************/
2 /*  Copyright 2009 Tim Day                                                */
3 /*                                                                        */
4 /*  This file is part of Fracplanet                                       */
5 /*                                                                        */
6 /*  Fracplanet is free software: you can redistribute it and/or modify    */
7 /*  it under the terms of the GNU General Public License as published by  */
8 /*  the Free Software Foundation, either version 3 of the License, or     */
9 /*  (at your option) any later version.                                   */
10 /*                                                                        */
11 /*  Fracplanet is distributed in the hope that it will be useful,         */
12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
14 /*  GNU General Public License for more details.                          */
15 /*                                                                        */
16 /*  You should have received a copy of the GNU General Public License     */
17 /*  along with Fracplanet.  If not, see <http://www.gnu.org/licenses/>.   */
18 /**************************************************************************/
19 
20 /*! \file
21   \brief Interface for classes for scan conversion.
22 */
23 
24 #ifndef _scan_h_
25 #define _scan_h_
26 
27 #include "common.h"
28 #include "xyz.h"
29 
30 //! Encapsulates information needed for scan conversion.
31 /*! We want to be independent of what quantity the client is going to interpolate over,
32   so the best we can do is identify (by index in given triangle) the vertices delimiting an edge and give the weights.
33 */
34 class ScanEdge
35 {
36  public:
37 
ScanEdge()38   ScanEdge()
39     {}
40 
ScanEdge(float vx,uint v0,uint v1,float l)41   ScanEdge(float vx,uint v0,uint v1,float l)
42     :x(vx)
43     ,vertex0(v0)
44     ,vertex1(v1)
45     ,lambda(l)
46     {}
47 
48   float x;
49   uint vertex0;
50   uint vertex1;
51   float lambda;
52 };
53 
54 class ScanConvertBackend;
55 
56 class ScanConverter
57 {
58  public:
59 
ScanConverter()60   ScanConverter()
61     {}
62 
~ScanConverter()63   virtual ~ScanConverter()
64     {}
65 
66   //! Set-up for scan conversion of given vertices to the given map.
67   /* Scan conversion output is a series of [,) open intervals with vertex identifiers and weightings for each end.
68    */
69   virtual void scan_convert
70     (
71      const boost::array<XYZ,3>& v,
72      const ScanConvertBackend&
73      ) const
74     =0;
75 };
76 
77 class ScanConvertBackend
78 {
79  public:
80 
ScanConvertBackend(int w,int h)81   ScanConvertBackend(int w,int h)
82     :_width(w)
83     ,_height(h)
84     {}
85 
~ScanConvertBackend()86   virtual ~ScanConvertBackend()
87     {}
88 
width()89   int width() const
90     {
91       return _width;
92     }
93 
height()94   int height() const
95     {
96       return _height;
97     }
98 
99   virtual void scan_convert_backend(uint y,const ScanEdge& edge0,const ScanEdge& edge1) const
100     =0;
101 
102   virtual void subdivide(const boost::array<XYZ,3>&,const XYZ&,const ScanConverter&) const
103     =0;
104 
105  private:
106 
107   const int _width;
108 
109   const int _height;
110 };
111 
112 #endif
113