Page MenuHome

custom_map.patch

File Metadata

Author
Daniel M. Basso (dmbasso)
Created
Nov 13 2013, 5:09 PM

custom_map.patch

Index: release/scripts/startup/bl_ui/properties_data_camera.py
===================================================================
--- release/scripts/startup/bl_ui/properties_data_camera.py (revision 56903)
+++ release/scripts/startup/bl_ui/properties_data_camera.py (working copy)
@@ -98,6 +98,10 @@
row = layout.row()
row.prop(ccam, "fisheye_lens", text="Lens")
row.prop(ccam, "fisheye_fov")
+ elif ccam.panorama_type == 'CUSTOM_MAP':
+ row = layout.row()
+ row.prop(ccam, "custom_map", text="Custom Map")
+
elif engine == 'BLENDER_RENDER':
row = col.row()
if cam.lens_unit == 'MILLIMETERS':
Index: intern/cycles/render/camera.cpp
===================================================================
--- intern/cycles/render/camera.cpp (revision 56903)
+++ intern/cycles/render/camera.cpp (working copy)
@@ -16,6 +16,9 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <iostream>
+#include <fstream>
+
#include "camera.h"
#include "scene.h"
@@ -46,6 +49,8 @@
fisheye_lens = 10.5f;
fov = M_PI_4_F;
+ cmap_grid = NULL;
+
sensorwidth = 0.036;
sensorheight = 0.024;
@@ -77,6 +82,10 @@
Camera::~Camera()
{
+ if (cmap_grid) {
+ delete [] cmap_grid;
+ cmap_grid = NULL;
+ }
}
void Camera::update()
@@ -142,6 +151,30 @@
dx = transform_direction(&cameratoworld, dx);
dy = transform_direction(&cameratoworld, dy);
+ /* panorama - custom map */
+ if (cmap_grid) {
+ delete [] cmap_grid;
+ cmap_grid = NULL;
+ cmap_rows = cmap_cols = 0;
+ }
+ if (!custom_map.empty()) {
+ // load custom map file
+ std::ifstream infile(custom_map.c_str()); // TODO: handle relative paths
+ if (infile.is_open()) {
+ infile >> cmap_rows;
+ infile >> cmap_cols;
+ // make sure it has enough coordinates
+ if (cmap_cols < 2 || cmap_rows < 2) {
+ cmap_rows = cmap_cols = 0;
+ } else {
+ int tot = cmap_rows * cmap_cols * 2;
+ cmap_grid = new float[tot];
+ for (int i=0; i < tot; i++)
+ infile >> cmap_grid[i];
+ }
+ }
+ }
+
need_update = false;
need_device_update = true;
}
@@ -229,6 +262,10 @@
kcam->fisheye_fov = fisheye_fov;
kcam->fisheye_lens = fisheye_lens;
+ kcam->cmap_grid = cmap_grid; // TODO: make it work for non-CPU device
+ kcam->cmap_rows = cmap_rows;
+ kcam->cmap_cols = cmap_cols;
+
/* sensor size */
kcam->sensorwidth = sensorwidth;
kcam->sensorheight = sensorheight;
@@ -276,7 +313,8 @@
(matrix == cam.matrix) &&
(panorama_type == cam.panorama_type) &&
(fisheye_fov == cam.fisheye_fov) &&
- (fisheye_lens == cam.fisheye_lens));
+ (fisheye_lens == cam.fisheye_lens) &&
+ (custom_map == cam.custom_map)); // should also check file atime
}
bool Camera::motion_modified(const Camera& cam)
Index: intern/cycles/render/camera.h
===================================================================
--- intern/cycles/render/camera.h (revision 56903)
+++ intern/cycles/render/camera.h (working copy)
@@ -23,6 +23,7 @@
#include "util_boundbox.h"
#include "util_transform.h"
+#include "util_string.h"
#include "util_types.h"
CCL_NAMESPACE_BEGIN
@@ -55,6 +56,11 @@
PanoramaType panorama_type;
float fisheye_fov;
float fisheye_lens;
+
+ /* panorama - custom map */
+ string custom_map;
+ float *cmap_grid;
+ int cmap_rows, cmap_cols;
/* sensor */
float sensorwidth;
Index: intern/cycles/app/cycles_xml.cpp
===================================================================
--- intern/cycles/app/cycles_xml.cpp (revision 56903)
+++ intern/cycles/app/cycles_xml.cpp (working copy)
@@ -311,6 +311,8 @@
cam->panorama_type = PANORAMA_FISHEYE_EQUIDISTANT;
else if(xml_equal_string(node, "panorama_type", "fisheye_equisolid"))
cam->panorama_type = PANORAMA_FISHEYE_EQUISOLID;
+ else if(xml_equal_string(node, "panorama_type", "custom_map"))
+ cam->panorama_type = PANORAMA_CUSTOM_MAP;
xml_read_float(&cam->fisheye_fov, node, "fisheye_fov");
xml_read_float(&cam->fisheye_lens, node, "fisheye_lens");
@@ -318,6 +320,7 @@
xml_read_float(&cam->sensorwidth, node, "sensorwidth");
xml_read_float(&cam->sensorheight, node, "sensorheight");
+ xml_read_string(&cam->custom_map, node, "custom_map");
cam->matrix = state.tfm;
Index: intern/cycles/kernel/kernel_types.h
===================================================================
--- intern/cycles/kernel/kernel_types.h (revision 56903)
+++ intern/cycles/kernel/kernel_types.h (working copy)
@@ -323,7 +323,8 @@
enum PanoramaType {
PANORAMA_EQUIRECTANGULAR,
PANORAMA_FISHEYE_EQUIDISTANT,
- PANORAMA_FISHEYE_EQUISOLID
+ PANORAMA_FISHEYE_EQUISOLID,
+ PANORAMA_CUSTOM_MAP
};
/* Differential */
@@ -555,6 +556,10 @@
float fisheye_fov;
float fisheye_lens;
+ /* panorama - custom map */
+ float *cmap_grid;
+ int cmap_rows, cmap_cols;
+
/* matrices */
Transform cameratoworld;
Transform rastertocamera;
Index: intern/cycles/kernel/kernel_projection.h
===================================================================
--- intern/cycles/kernel/kernel_projection.h (revision 56903)
+++ intern/cycles/kernel/kernel_projection.h (working copy)
@@ -144,6 +144,45 @@
);
}
+__device float3 custom_map_to_direction(KernelGlobals *kg, float u, float v)
+{
+ // in case the custom map couldn't be loaded,
+ // perform the regular equirectangular mapping
+ if (!kernel_data.cam.cmap_grid)
+ return equirectangular_to_direction(u, v);
+ float2 *grid = (float2*) kernel_data.cam.cmap_grid;
+ // map u, v to grid cell (col, row) and fractionary offset
+ // for interpolation (col_frac, row_frac)
+ int rows = kernel_data.cam.cmap_rows;
+ int cols = kernel_data.cam.cmap_cols;
+ float col_frac = u * (rows - 1);
+ int col = (int) col_frac;
+ col_frac -= col;
+ float row_frac = v * (cols - 1);
+ int row = (int) row_frac;
+ row_frac -= row;
+ // linearly interpolate the coordinates in the cells
+ float2 p11 = grid[row * cols + col];
+ float2 p12, p21, p22;
+ p12 = p21 = p22 = make_float2(0, 0);
+ if (col_frac) p12 = grid[row * cols + col + 1];
+ if (row_frac) p21 = grid[(row + 1) * cols + col];
+ if (col_frac && row_frac)
+ p22 = grid[(row + 1) * cols + col + 1];
+ if (col_frac) {
+ p11.x = (1 - col_frac) * p11.x + col_frac * p12.x;
+ p11.y = (1 - col_frac) * p11.y + col_frac * p12.y;
+ p21.x = (1 - col_frac) * p21.x + col_frac * p22.x;
+ p21.y = (1 - col_frac) * p21.y + col_frac * p22.y;
+ }
+ if (row_frac) {
+ p11.x = (1 - row_frac) * p11.x + row_frac * p21.x;
+ p11.y = (1 - row_frac) * p11.y + row_frac * p21.y;
+ }
+ // return the direction for the mapped coordinates
+ return equirectangular_to_direction(p11.x, p11.y);
+}
+
/* Mirror Ball <-> Cartesion direction */
__device float3 mirrorball_to_direction(float u, float v)
@@ -183,6 +222,8 @@
return equirectangular_to_direction(u, v);
case PANORAMA_FISHEYE_EQUIDISTANT:
return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov);
+ case PANORAMA_CUSTOM_MAP:
+ return custom_map_to_direction(kg, u, v);
case PANORAMA_FISHEYE_EQUISOLID:
default:
return fisheye_equisolid_to_direction(u, v, kernel_data.cam.fisheye_lens,
Index: intern/cycles/blender/blender_camera.cpp
===================================================================
--- intern/cycles/blender/blender_camera.cpp (revision 56903)
+++ intern/cycles/blender/blender_camera.cpp (working copy)
@@ -51,6 +51,7 @@
PanoramaType panorama_type;
float fisheye_fov;
float fisheye_lens;
+ char custom_map[1024];
enum { AUTO, HORIZONTAL, VERTICAL } sensor_fit;
float sensor_width;
@@ -137,6 +138,9 @@
case 2:
bcam->panorama_type = PANORAMA_FISHEYE_EQUISOLID;
break;
+ case 3:
+ bcam->panorama_type = PANORAMA_CUSTOM_MAP;
+ break;
case 0:
default:
bcam->panorama_type = PANORAMA_EQUIRECTANGULAR;
@@ -145,6 +149,7 @@
bcam->fisheye_fov = RNA_float_get(&ccamera, "fisheye_fov");
bcam->fisheye_lens = RNA_float_get(&ccamera, "fisheye_lens");
+ RNA_string_get(&ccamera, "custom_map", bcam->custom_map);
bcam->ortho_scale = b_camera.ortho_scale();
@@ -329,6 +334,7 @@
cam->panorama_type = bcam->panorama_type;
cam->fisheye_fov = bcam->fisheye_fov;
cam->fisheye_lens = bcam->fisheye_lens;
+ cam->custom_map = bcam->custom_map;
/* perspective */
cam->fov = 2.0f * atanf((0.5f * sensor_size) / bcam->lens / aspectratio);
Index: intern/cycles/blender/addon/properties.py
===================================================================
--- intern/cycles/blender/addon/properties.py (revision 56903)
+++ intern/cycles/blender/addon/properties.py (working copy)
@@ -23,7 +23,8 @@
EnumProperty,
FloatProperty,
IntProperty,
- PointerProperty)
+ PointerProperty,
+ StringProperty)
# enums
@@ -62,6 +63,8 @@
('FISHEYE_EQUIDISTANT', "Fisheye Equidistant", "Ideal for fulldomes, ignore the sensor dimensions"),
('FISHEYE_EQUISOLID', "Fisheye Equisolid",
"Similar to most fisheye modern lens, takes sensor dimensions into consideration"),
+ ('CUSTOM_MAP', "Custom Map",
+ "Allows arbitrary distortions based on a mapping file"),
)
enum_curve_presets = (
@@ -471,6 +474,12 @@
min=0.01, soft_max=15.0, max=100.0,
default=10.5,
)
+ cls.custom_map = StringProperty(
+ name="Custom Map",
+ maxlen=1024,
+ description="Path to the mapping file",
+ subtype='FILE_PATH',
+ )
@classmethod
def unregister(cls):

Event Timeline