Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_BokehImageOperation.h « operations « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3cf9afda32ae7577cc634bc8f450089b34b7de06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor: 
 *		Jeroen Bakker 
 *		Monique Dewanchand
 */

#ifndef _COM_BokehImageOperation_h
#define _COM_BokehImageOperation_h
#include "COM_NodeOperation.h"

/**
 * @brief The BokehImageOperation class is an operation that creates an image useful to mimic the internals
 *of a camera.
 *
 * features:
 *  - number of flaps
 *  - angle offset of the flaps
 *  - rounding of the flaps (also used to make a circular lens)
 *  - simulate catadioptric
 *  - simulate lensshift
 *
 * Per pixel the algorithm determines the edge of the bokeh on the same line as the center of the image and the pixel
 * is evaluating.
 *
 * The edge is detected by finding the closest point on the direct line between the two nearest flap-corners.
 * this edge is interpolated with a full circle. 
 * Result of this edge detection is stored as the distance between the center of the image and the edge.
 *
 * catadioptric lenses are simulated to interpolate between the center of the image and the distance of the edge.
 * We now have three distances:
 *  - distance between the center of the image and the pixel to be evaluated
 *  - distance between the center of the image and the outer-edge
 *  - distance between the center of the image and the inner-edge
 *
 * With a simple compare it can be detected if the evaluated pixel is between the outer and inner edge.
 */
class BokehImageOperation : public NodeOperation {
private:
	/**
	 * @brief Settings of the bokeh image
	 */
	NodeBokehImage *m_data;

	/**
	 * @brief precalced center of the image
	 */
	float m_center[2];
	
	/**
	 * @brief 1.0-rounding
	 */
	float m_inverseRounding;
	
	/**
	 * @brief distance of a full circle lens
	 */
	float m_circularDistance;
	
	/**
	 * @brief radius when the first flap starts
	 */
	float m_flapRad;
	
	/**
	 * @brief radians of a single flap
	 */
	float m_flapRadAdd;
	
	/**
	 * @brief should the m_data field by deleted when this operation is finished
	 */
	bool m_deleteData;

	/**
	 * @brief determine the coordinate of a flap cornder
	 *
	 * @param r result in bokehimage space are stored [x,y]
	 * @param flapNumber the flap number to calculate
	 * @param distance the lens distance is used to simulate lens shifts
	 */
	void detemineStartPointOfFlap(float r[2], int flapNumber, float distance);
	
	/**
	 * @brief Determine if a coordinate is inside the bokeh image
	 *
	 * @param distance the distance that will be used. This parameter is modified a bit to mimic lens shifts
	 * @param x the x coordinate of the pixel to evaluate
	 * @param y the y coordinate of the pixel to evaluate
	 * @return float range 0..1 0 is completely outside
	 */
	float isInsideBokeh(float distance, float x, float y);
public:
	BokehImageOperation();

	/**
	 * @brief the inner loop of this program
	 */
	void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
	
	/**
	 * @brief Initialize the execution
	 */
	void initExecution();
	
	/**
	 * @brief Deinitialize the execution
	 */
	void deinitExecution();
	
	/**
	 * @brief determine the resolution of this operation. currently fixed at [COM_BLUR_BOKEH_PIXELS, COM_BLUR_BOKEH_PIXELS]
	 * @param resolution
	 * @param preferredResolution
	 */
	void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);

	/**
	 * @brief set the node data
	 * @param data
	 */
	void setData(NodeBokehImage *data) { this->m_data = data; }
	
	/**
	 * @brief deleteDataOnFinish
	 *
	 * There are cases that the compositor uses this operation on its own (see defocus node)
	 * the deleteDataOnFinish must only be called when the data has been created by the compositor.
	 *It should not be called when the data has been created by the node-editor/user.
	 */
	void deleteDataOnFinish() { this->m_deleteData = true; }
};
#endif