HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PolyRaster.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_PolyRaster.h ( UT Library, C++)
7  *
8  * COMMENTS: Rasterize a polygon. The following class is a virtual class
9  * which will "rasterize" a polygon. For each pixel that the
10  * polygon covers, a filter weight will be computed and a callback
11  * will be invoked to process the pixel. This can be used to
12  * render polygons to an image raster or to sample texture etc.
13  *
14  * Currently, only triangles are supported.
15  *
16  * If a sample table is set, then the sample table will be used
17  * for computation, otherwise "perfect" filtering will be done.
18  * "perfect" filtering is more expensive than sample table
19  * evaluation.
20  */
21 
22 #ifndef __UT_PolyRaster__
23 #define __UT_PolyRaster__
24 
25 #include "UT_API.h"
26 #include <SYS/SYS_Floor.h>
27 #include "UT_VectorTypes.h"
28 class UT_prEdge;
29 class UT_Filter;
30 class UT_FilterSampleTable;
31 
33 public:
34  UT_PolyRaster();
35  virtual ~UT_PolyRaster();
36 
37 #if 0
38  void setSampleTable(UT_FilterSampleTable *table)
39  {
40  mySampleTable = table;
41  }
42 #endif
44  {
45  myXSFilter = x * 0.5F;
46  myYSFilter = y * 0.5F;
47  }
48  void setWindow(fpreal xl, fpreal xr, fpreal yb, fpreal yt)
49  {
50  myXMin = xl; myXMax = xr;
51  myYMin = yb; myYMax = yt;
52  }
53  void setResolution(int xsamp, int ysamp)
54  {
55  myXres = xsamp;
56  myYres = ysamp;
57  }
58 
59  // After all the variables are set, please call initialize.
60  void initialize();
61 
62  // The sample() method is a callback which will simply return the pixel
63  // position and the weight.
64  virtual void sample(int x, int y, fpreal weight);
65 
66  // Rasterize the polygon and call the sample() method for each pixel
67  // covered. If the cliptowindow variable is 0, pixel values outside of the
68  // resolution may be generated.
69  void rasterize(const float v0[2], const float v1[2],
70  const float v2[2], int cliptowindow = 1);
71 
72 protected:
73  float myXFilter, myYFilter;
74  float myIXFilter, myIYFilter;
75  float myXSFilter, myYSFilter;
76  float myXMin, myXMax, myYMin, myYMax;
77  int myXres, myYres;
78 
79 private:
80  void rasterize(UT_prEdge *head, int clipx) const;
81  fpreal filterWeight(const float v0[2], const float v1[2],
82  const float v2[2]) const;
83 
84  // This clipOneEdge will generate a polygon for the filter region
85  int clipOneEdge(fpreal xl, fpreal xr, fpreal yb, fpreal yt,
86  float vtx[][2],
87  const UT_prEdge &edge) const;
88  int genericClip(const float vtx[][2], int nvtx,
89  float result[][2],
90  const UT_prEdge &e0) const;
91  fpreal genericWeight(float vtx[][2],
92  int nvtx) const
93  {
94  if (nvtx < 3) return nvtx == -1;
95  return computeWeight(vtx, nvtx);
96  }
97  int toScreenX(fpreal sx) const
98  { return (int)((sx-myXMin)*myIXSinc); }
99  int floorScreenX(fpreal sx) const
100  { return (int)SYSfloor((sx-myXMin)*myIXSinc); }
101  int ceilScreenX(fpreal sx) const
102  { return (int)SYSceil((sx-myXMin)*myIXSinc); }
103 
104  fpreal computeWeight(float vtx[][2], int nvtx) const;
105 
106  // clipOneEdge returns the filter weight for a single edge clip
107  fpreal clipOneEdge(fpreal xl, fpreal xr, fpreal yb, fpreal yt,
108  const UT_prEdge &edge) const;
109  float myXSinc, myIXSinc;
110  float myYSinc, myIYSinc;
111  float myBoxWeight;
112 #if 0
113  UT_FilterSample *mySampleTable;
114 #endif
115 };
116 
117 #endif
#define UT_API
Definition: UT_API.h:12
GLint y
Definition: glcorearb.h:102
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
SYS_API fpreal32 SYSfloor(fpreal32 val)
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
GLfloat v0
Definition: glcorearb.h:815
void setFilterWidth(fpreal x=1, fpreal y=1)
Definition: UT_PolyRaster.h:43
double fpreal
Definition: SYS_Types.h:269
GLint GLenum GLint x
Definition: glcorearb.h:408
GLfloat GLfloat v1
Definition: glcorearb.h:816
void setWindow(fpreal xl, fpreal xr, fpreal yb, fpreal yt)
Definition: UT_PolyRaster.h:48
void setResolution(int xsamp, int ysamp)
Definition: UT_PolyRaster.h:53
SYS_API fpreal32 SYSceil(fpreal32 val)