28 #include "iesDataset.h" 30 #ifndef _USE_MATH_DEFINES 31 #define _USE_MATH_DEFINES 35 NotifyCategoryDef(iesdataset,
"")
51 nassertv(vertical_angles.size() > 0);
52 _vertical_angles = vertical_angles;
62 nassertv(horizontal_angles.size() > 0);
63 _horizontal_angles = horizontal_angles;
74 nassertv(candela_values.size() == _horizontal_angles.size() * _vertical_angles.size());
75 _candela_values = candela_values;
90 size_t index = vertical_angle_idx + horizontal_angle_idx * _vertical_angles.size();
91 nassertr(index >= 0 && index < _candela_values.size(), 0.0);
92 return _candela_values[index];
109 if (_horizontal_angles.size() == 1) {
113 float max_angle = _horizontal_angles[_horizontal_angles.size() - 1];
118 horizontal_angle = fmod(horizontal_angle, 2.0f * max_angle);
119 if (horizontal_angle > max_angle) {
120 horizontal_angle = 2.0 * max_angle - horizontal_angle;
126 for (
size_t horizontal_index = 1; horizontal_index < _horizontal_angles.size(); ++horizontal_index) {
127 float curr_angle = _horizontal_angles[horizontal_index];
129 if (curr_angle >= horizontal_angle) {
132 float prev_angle = _horizontal_angles[horizontal_index - 1];
137 float lerp = (horizontal_angle - prev_angle) / (curr_angle - prev_angle);
140 if (lerp < 0.0 || lerp > 1.0) {
141 iesdataset_cat.error() <<
"Invalid horizontal lerp: " << lerp
142 <<
", requested angle was " << horizontal_angle
143 <<
", prev = " << prev_angle <<
", cur = " << curr_angle
147 return curr_value * lerp + prev_value * (1-lerp);
167 nassertr(horizontal_angle_idx >= 0 && horizontal_angle_idx < _horizontal_angles.size(), 0.0);
170 if (vertical_angle < 0.0)
return 0.0;
173 if (vertical_angle > _vertical_angles[_vertical_angles.size() - 1] )
return 0.0;
176 for (
size_t vertical_index = 1; vertical_index < _vertical_angles.size(); ++vertical_index) {
177 float curr_angle = _vertical_angles[vertical_index];
180 if (curr_angle > vertical_angle) {
183 float prev_angle = _vertical_angles[vertical_index - 1];
188 float lerp = (vertical_angle - prev_angle) / (curr_angle - prev_angle);
191 if (lerp < 0.0 || lerp > 1.0) {
192 iesdataset_cat.error() <<
"ERROR: Invalid vertical lerp: " << lerp
193 <<
", requested angle was " << vertical_angle
194 <<
", prev = " << prev_angle <<
", cur = " << curr_angle
198 return curr_value * lerp + prev_value * (1-lerp);
216 size_t resolution_vertical = dest_tex->
get_y_size();
217 size_t resolution_horizontal = dest_tex->
get_x_size();
221 PNMImage dest =
PNMImage(resolution_vertical, resolution_horizontal, 1, 65535);
223 for (
size_t vert = 0; vert < resolution_vertical; ++vert) {
224 for (
size_t horiz = 0; horiz < resolution_horizontal; ++horiz) {
225 float vert_angle = (float)vert / (
float)(resolution_vertical-1);
226 vert_angle = cos(vert_angle * M_PI) * 90.0 + 90.0;
227 float horiz_angle = (float)horiz / (
float)(resolution_horizontal-1) * 360.0;
229 dest.
set_xel(vert, horiz, candela);
234 dest_tex->
load(dest, z, 0);
get_y_size
Returns the height of the texture image in texels.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
void set_vertical_angles(const PTA_float &vertical_angles)
Sets the vertical angles of the dataset.
void set_horizontal_angles(const PTA_float &horizontal_angles)
Sets the horizontal angles of the dataset.
This class generates a LUT from IES data.
void generate_dataset_texture_into(Texture *dest_tex, size_t z) const
Generates the IES LUT.
float get_vertical_candela_value(size_t horizontal_angle_idx, float vertical_angle) const
Fetches a vertical candela value.
bool load(const PNMImage &pnmimage, const LoaderOptions &options=LoaderOptions())
Replaces the texture with the indicated image.
float get_candela_value_from_index(size_t vertical_angle_idx, size_t horizontal_angle_idx) const
Internal method to access the candela data.
float get_candela_value(float vertical_angle, float horizontal_angle) const
Samples the dataset at the given position.
void set_xel(int x, int y, const LRGBColorf &value)
Changes the RGB color at the indicated pixel.
get_x_size
Returns the width of the texture image in texels.
void set_candela_values(const PTA_float &candela_values)
Sets the candela values.