HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 "UT_NonCopyable.h"
27 #include "UT_VectorTypes.h"
28 #include <SYS/SYS_Floor.h>
29 
30 class UT_prEdge;
31 class UT_Filter;
32 class UT_FilterSampleTable;
33 
35 {
36 public:
37  UT_PolyRaster();
38  virtual ~UT_PolyRaster();
39 
41 
42 #if 0
43  void setSampleTable(UT_FilterSampleTable *table)
44  {
45  mySampleTable = table;
46  }
47 #endif
49  {
50  myXSFilter = x * 0.5F;
51  myYSFilter = y * 0.5F;
52  }
53  void setWindow(fpreal xl, fpreal xr, fpreal yb, fpreal yt)
54  {
55  myXMin = xl; myXMax = xr;
56  myYMin = yb; myYMax = yt;
57  }
58  void setResolution(int xsamp, int ysamp)
59  {
60  myXres = xsamp;
61  myYres = ysamp;
62  }
63 
64  // After all the variables are set, please call initialize.
65  void initialize();
66 
67  // The sample() method is a callback which will simply return the pixel
68  // position and the weight.
69  virtual void sample(int x, int y, fpreal weight);
70 
71  // Rasterize the polygon and call the sample() method for each pixel
72  // covered. If the cliptowindow variable is 0, pixel values outside of the
73  // resolution may be generated.
74  void rasterize(const float v0[2], const float v1[2],
75  const float v2[2], int cliptowindow = 1);
76 
77 protected:
78  float myXFilter, myYFilter;
79  float myIXFilter, myIYFilter;
80  float myXSFilter, myYSFilter;
81  float myXMin, myXMax, myYMin, myYMax;
82  int myXres, myYres;
83 
84 private:
85  void rasterize(UT_prEdge *head, int clipx) const;
86  fpreal filterWeight(const float v0[2], const float v1[2],
87  const float v2[2]) const;
88 
89  // This clipOneEdge will generate a polygon for the filter region
90  int clipOneEdge(fpreal xl, fpreal xr, fpreal yb, fpreal yt,
91  float vtx[][2],
92  const UT_prEdge &edge) const;
93  int genericClip(const float vtx[][2], int nvtx,
94  float result[][2],
95  const UT_prEdge &e0) const;
96  fpreal genericWeight(float vtx[][2],
97  int nvtx) const
98  {
99  if (nvtx < 3) return nvtx == -1;
100  return computeWeight(vtx, nvtx);
101  }
102  int toScreenX(fpreal sx) const
103  { return (int)((sx-myXMin)*myIXSinc); }
104  int floorScreenX(fpreal sx) const
105  { return (int)SYSfloor((sx-myXMin)*myIXSinc); }
106  int ceilScreenX(fpreal sx) const
107  { return (int)SYSceil((sx-myXMin)*myIXSinc); }
108 
109  fpreal computeWeight(float vtx[][2], int nvtx) const;
110 
111  // clipOneEdge returns the filter weight for a single edge clip
112  fpreal clipOneEdge(fpreal xl, fpreal xr, fpreal yb, fpreal yt,
113  const UT_prEdge &edge) const;
114  float myXSinc, myIXSinc;
115  float myYSinc, myIYSinc;
116  float myBoxWeight;
117 #if 0
118  UT_FilterSample *mySampleTable;
119 #endif
120 };
121 
122 #endif
void rasterize(const PointDataTreeOrGridT &points, TransferT &transfer, const FilterT &filter=NullFilter(), InterrupterT *interrupter=nullptr)
Perform potentially complex rasterization from a user defined transfer scheme.
UT_StringArray JOINTS head
#define UT_API
Definition: UT_API.h:14
GLint y
Definition: glcorearb.h:103
**But if you need a result
Definition: thread.h:613
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
SYS_API fpreal32 SYSfloor(fpreal32 val)
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
GLint GLenum GLint x
Definition: glcorearb.h:409
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
GLfloat v0
Definition: glcorearb.h:816
void setFilterWidth(fpreal x=1, fpreal y=1)
Definition: UT_PolyRaster.h:48
fpreal64 fpreal
Definition: SYS_Types.h:277
GLfloat GLfloat v1
Definition: glcorearb.h:817
void setWindow(fpreal xl, fpreal xr, fpreal yb, fpreal yt)
Definition: UT_PolyRaster.h:53
void setResolution(int xsamp, int ysamp)
Definition: UT_PolyRaster.h:58
SYS_API fpreal32 SYSceil(fpreal32 val)