资源简介
基于c++的图像拼接的源代码
代码片段和文件信息
/* Standard Includes */
#include
#include
#include
#include
/* Custom Includes */
#include “sampler.h“
#include “stb_image.h“
#include “stb_image_write.h“
#include “cube2sphere-converter.h“
/* Standard Namespace */
using namespace std;
Cube2SphereConverter::Cube2SphereConverter(vector source int numSamples bool useJitter bool &valid)
{
/* Read in RGB Data and Fields */
samplingType = useJitter; N = numSamples;
for(int i = 0; i < 6; i++){
rgb_data[i] = stbi_load(source[i].c_str() &input_width &input_height &input_bpp 3);
}
/* Error Checking */
valid = true;
for(int i = 0; i < 6; i++) {
if(rgb_data[i] == NULL) {
valid = false;
}
}
}
Cube2SphereConverter::~Cube2SphereConverter()
{
for(int i = 0; i < 6; i++) stbi_image_free(rgb_data[i]);
}
void Cube2SphereConverter::generateRayOctahedron(Point3D &p_out bool ypos Point2D p_in)
{
double x = (2 * p_in.x)/output_width - 1;
double z = (2 * p_in.y)/output_height - 1;
if(ypos) {
p_out.x = (z + x) / (2.0);
p_out.z = (z - x) / (2.0);
p_out.y = 1 - (abs(p_out.x) + abs(p_out.z));
} else {
p_out.x = (z - x) / (2.0);
p_out.z = (z + x) / (2.0);
p_out.y = (abs(p_out.x) + abs(p_out.z)) - 1;
}
double mag = sqrt((p_out.x * p_out.x) + (p_out.y * p_out.y) + (p_out.z * p_out.z));
p_out.x = p_out.x/mag; p_out.y = p_out.y/mag; p_out.z = p_out.z/mag;
}
void Cube2SphereConverter::generateRayParaboloid(Point3D &p_out bool zpos Point2D p_in)
{
p_out.x = p_in.x;
p_out.y = p_in.y;
if(zpos) {
p_out.z = 0.5 - 0.5*((p_out.x * p_out.x) + (p_out.y * p_out.y));
} else {
p_out.z = -0.5 + 0.5*((p_out.x * p_out.x) + (p_out.y * p_out.y));
}
double mag = sqrt((p_out.x * p_out.x) + (p_out.y * p_out.y) + (p_out.z * p_out.z));
p_out.x = p_out.x/mag; p_out.y = p_out.y/mag; p_out.z = p_out.z/mag;
}
void Cube2SphereConverter::generateRaySpherical(Point3D &p_out Point2D p_in)
{
double x = (2 * p_in.x)/output_width - 1;
double y = (2 * p_in.y)/output_height - 1;
double theta = M_PI * x;
double phi = (M_PI * y)/2;
p_out.x = cos(phi) * cos(theta);
p_out.y = sin(phi);
p_out.z = cos(phi) * sin(theta);
}
void Cube2SphereConverter::readVals(byte *ptr int &i int &j byte &r byte &g byte &b)
{
if(i == input_width) i = input_width-1;
if(j == input_height) j = input_height-1;
size_t offset = 3*(i + (j*input_width));
r = *(ptr + offset);
g = *(ptr + offset + 1);
b = *(ptr + offset + 2);
}
void Cube2SphereConverter::getRgbFromPoint(Point2D p_in byte &r byte &g byte &b bool pos int tex)
{
/* Texture Selection */
Point3D p; int i j n;
if(tex == 0) {
generateRaySpherical(p p_in);
} else if(tex == 1) {
p_in.x = (2 * p_in.x)/output_width - 1;
p_in.y = (2 * p_in.y)/output_height - 1;
double rad = sqrt((p_in.x * p_in.x) + (p_in.y * p_in.y));
if(rad >= 1.01) {r = 255; g = 255; b = 255; return;}
generateRayParaboloid(p pos p_in);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-08-25 20:08 cubemap-stitch-master\
文件 2015 2016-08-25 20:08 cubemap-stitch-master\README.md
文件 75 2016-08-25 20:08 cubemap-stitch-master\byte.h
文件 315 2016-08-25 20:08 cubemap-stitch-master\compile.sh
文件 6136 2016-08-25 20:08 cubemap-stitch-master\cube2sphere-converter.cpp
文件 1223 2016-08-25 20:08 cubemap-stitch-master\cube2sphere-converter.h
文件 3360 2016-08-25 20:08 cubemap-stitch-master\hev-mapConverter.cpp
文件 270 2016-08-25 20:08 cubemap-stitch-master\point.h
文件 1949 2016-08-25 20:08 cubemap-stitch-master\sampler.cpp
文件 1228 2016-08-25 20:08 cubemap-stitch-master\sampler.h
文件 5150 2016-08-25 20:08 cubemap-stitch-master\sphere2cube-converter.cpp
文件 1409 2016-08-25 20:08 cubemap-stitch-master\sphere2cube-converter.h
文件 227413 2016-08-25 20:08 cubemap-stitch-master\stb_image.h
文件 119888 2016-08-25 20:08 cubemap-stitch-master\stb_image.o
文件 37508 2016-08-25 20:08 cubemap-stitch-master\stb_image_write.h
文件 31808 2016-08-25 20:08 cubemap-stitch-master\stb_image_write.o
评论
共有 条评论