HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RAY_DemoEdgeDetectFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * This is a sample pixel filter to do edge detection
27  */
28 
29 #pragma once
30 
31 #ifndef __RAY_DemoEdgeDetectFilter__
32 #define __RAY_DemoEdgeDetectFilter__
33 
34 #include <RAY/RAY_PixelFilter.h>
35 
36 namespace HDK_Sample {
37 
39 public:
41  virtual ~RAY_DemoEdgeDetectFilter();
42 
43  virtual RAY_PixelFilter *clone() const;
44 
45  /// setArgs is called with the options specified after the pixel filter
46  /// name in the Pixel Filter parameter on the Mantra ROP.
47  /// This filter accepts 5 options:
48  /// -c 0.1 Consider a colour gradient of 0.1 colour units / pixel
49  /// to be an edge. Make -1 to disable colour gradient check.
50  /// -w 3.0 Make the width of the region to fit lines to for the
51  /// colour gradient 3.0 pixels, i.e. each pixel may depend on
52  /// samples 1.5 pixels from its centre. It gets clamped to
53  /// a minimum width of 1.0.
54  /// -z 0.005 Consider a z-depth gradient of a factor of 0.005 change
55  /// in the z-depth per pixel to be an edge. For example,
56  /// a gradient of 0.51 distance units per pixel at a depth
57  /// of 100 units would be considered an edge. Make -1 to
58  /// disable z-depth gradient check.
59  /// -s 3.0 Make the width of the region to fit lines to for the
60  /// z-depth gradient 3.0 pixels, i.e. each pixel may depend on
61  /// samples 1.5 pixels from its centre. It gets clamped to
62  /// a minimum width of 1.0.
63  /// -o 3.0 Make the width of the region to search for varying Op IDs
64  /// 3.0 pixels, i.e. each pixel may depend on
65  /// samples 1.5 pixels from its centre. It gets clamped to
66  /// a minimum width of 1.0. Make -1 to disable Op ID check.
67  virtual void setArgs(int argc, const char *const argv[]);
68 
69  /// getFilterWidth is called after setArgs when Mantra needs to know
70  /// how far to expand the render region.
71  virtual void getFilterWidth(float &x, float &y) const;
72 
73  /// addNeededSpecialChannels is called after setArgs so that this filter
74  /// can indicate that it depends on having special channels like z-depths
75  /// or Op IDs.
76  virtual void addNeededSpecialChannels(RAY_Imager &imager);
77 
78  /// prepFilter is called after setArgs so that this filter can
79  /// precompute data structures or values for use in filtering that
80  /// depend on the number of samples per pixel in the x or y directions.
81  virtual void prepFilter(int samplesperpixelx, int samplesperpixely);
82 
83  /// filter is called for each destination tile region with a source
84  /// that is at least as large as is needed by this filter, based on
85  /// the filter widths returned by getFilterWidth.
86  virtual void filter(
87  float *destination,
88  int vectorsize,
89  const RAY_SampleBuffer &source,
90  int channel,
91  int sourcewidth,
92  int sourceheight,
93  int destwidth,
94  int destheight,
95  int destxoffsetinsource,
96  int destyoffsetinsource,
97  const RAY_Imager &imager) const;
98 
99 private:
100  /// These must be saved in prepFilter.
101  /// Each pixel has mySamplesPerPixelX*mySamplesPerPixelY samples.
102  /// @{
103  int mySamplesPerPixelX;
104  int mySamplesPerPixelY;
105  /// @}
106 
107  /// true iff detecting edges using the magnitude of the colour gradient
108  bool myUseColourGradient;
109 
110  /// true iff detecting edges using the magnitude of the z-depth gradient
111  bool myUseZGradient;
112 
113  /// true iff detecting edges using changes in the Operator ID
114  bool myUseOpID;
115 
116  /// Min magnitude of the colour gradient that will be considered an edge
117  /// Units are: colour units / pixel
118  float myColourGradientThreshold;
119 
120  /// Min magnitude of the z-depth gradient that will be considered an edge
121  /// Units are: distance units / pixel
122  float myZGradientThreshold;
123 
124  /// Width in pixels of filter to determine colour gradient
125  float myColourGradientWidth;
126 
127  /// Width in pixels of filter to determine z-depth gradient
128  float myZGradientWidth;
129 
130  /// Width in pixels of filter to check for different Operator IDs
131  float myOpIDWidth;
132 
133  /// Normalizing coefficients computed in prepFilter
134  /// @{
135  float myColourSumX2;
136  float myColourSumY2;
137  float myZSumX2;
138  float myZSumY2;
139  /// @}
140 
141  /// Filter half-widths (rounded down) in sample counts
142  /// @{
143  int myColourSamplesHalfX;
144  int myColourSamplesHalfY;
145  int myZSamplesHalfX;
146  int myZSamplesHalfY;
147  int myOpIDSamplesHalfX;
148  int myOpIDSamplesHalfY;
149  /// @}
150 };
151 
152 } // End HDK_Sample namespace
153 
154 #endif
virtual void filter(float *destination, int vectorsize, const RAY_SampleBuffer &source, int channel, int sourcewidth, int sourceheight, int destwidth, int destheight, int destxoffsetinsource, int destyoffsetinsource, const RAY_Imager &imager) const
virtual void setArgs(int argc, const char *const argv[])
GLint y
Definition: glcorearb.h:102
virtual void addNeededSpecialChannels(RAY_Imager &imager)
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual void prepFilter(int samplesperpixelx, int samplesperpixely)
GLint GLenum GLint x
Definition: glcorearb.h:408
virtual void getFilterWidth(float &x, float &y) const
virtual RAY_PixelFilter * clone() const