void InitSceneTexture() { char* path = "./Cubemaps";myEnvironment.setFileRoute(path);myEnvironment.getImageSource();int sceneLength = myEnvironment.Top.width;int sceneHeight = myEnvironment.Top.height;bind2DTopTexture(sceneLength, sceneLength);bind2DBottomTexture(sceneLength, sceneLength);bind2DLeftTexture(sceneLength, sceneLength);bind2DRightTexture(sceneLength, sceneLength);bind2DFrontTexture(sceneLength, sceneLength);bind2DBackTexture(sceneLength, sceneLength);
}
最后6个函数就是绑定纹理的过程,以top面为例,其它完整的代码会放在后面
void bind2DTopTexture(int width, int height) { size_t pitch, tex_ofs;float4*arr_d = 0;cudaMallocPitch((void**)&arr_d, &pitch, width * sizeof(float4), height);cudaMemcpy2D(arr_d, pitch, myEnvironment.Top.normData, width * sizeof(float4),width * sizeof(float4), height, cudaMemcpyHostToDevice);texTopEnvironment.normalized = false;cudaBindTexture2D(&tex_ofs, &texTopEnvironment, arr_d, &texTopEnvironment.channelDesc, width, height, pitch);
}
cudaFree(arr_d )
DEVICE Color renderScene(point& viewPoint, Vector& viewVector) { //float tx, ty, tz;bool positiveX, positiveY, positiveZ;float boxBoder = 500;insideIntersect_x(viewPoint, viewVector, boxBoder, tx, positiveX);insideIntersect_y(viewPoint, viewVector, boxBoder, ty, positiveY);insideIntersect_z(viewPoint, viewVector, boxBoder, tz, positiveZ);if (tx <= ty&&tx <= tz) { if (positiveX) { viewPoint += tx*viewVector;float xPos = viewPoint.z + boxBoder;float yPos = viewPoint.y + boxBoder;float4 hagles = tex2D(texRightEnvironment, (xPos + 0.5), (yPos + 0.5));return Color(hagles.x, hagles.y, hagles.z);}else { viewPoint += tx*viewVector;float xPos = boxBoder - viewPoint.z;float yPos = viewPoint.y + boxBoder;float4 hagles = tex2D(texLeftEnvironment, (xPos + 0.5), (yPos + 0.5));return Color(hagles.x, hagles.y, hagles.z);}}else if (ty <= tx&&ty <= tz) { if (positiveY) { viewPoint += ty*viewVector;float xPos = boxBoder - viewPoint.x;float yPos = boxBoder - viewPoint.z;float4 hagles = tex2D(texTopEnvironment, (xPos + 0.5), (yPos + 0.5));return Color(hagles.x, hagles.y, hagles.z);}else { viewPoint += ty*viewVector;float xPos = boxBoder - viewPoint.x;float yPos = boxBoder + viewPoint.z;float4 hagles = tex2D(texBottomEnvironment, (xPos + 0.5), (yPos + 0.5));return Color(hagles.x, hagles.y, hagles.z);}}else if (tz <= ty&&tz <= tx) { if (positiveZ) { viewPoint += tz*viewVector;float xPos = boxBoder - viewPoint.x;float yPos = boxBoder + viewPoint.y;float4 hagles = tex2D(texBackEnvironment, (xPos + 0.5), (yPos + 0.5));return Color(hagles.x, hagles.y, hagles.z);}else { viewPoint += tz*viewVector;float xPos = viewPoint.x + boxBoder;float yPos = viewPoint.y + boxBoder;float4 hagles = tex2D(texFrontEnvironment, (xPos + 0.5), (yPos + 0.5));return Color(hagles.x, hagles.y, hagles.z);}}
}
Color, point, Vector
都是类似于cv::Point3f,不过需要基于HOST_AND_DEVICE
重构数据结构。
下面这三个函数是为了确定击中的是哪个面
insideIntersect_x(viewPoint, viewVector, boxBoder, tx, positiveX);insideIntersect_y(viewPoint, viewVector, boxBoder, ty, positiveY);insideIntersect_z(viewPoint, viewVector, boxBoder, tz, positiveZ);
//irradiance.cu
__global__ void kernel8(int range_W, int range_H, cv::cuda::PtrStepSz<vec3f> outPano)
{ point viewpoint = point(0, 0, 0);int X = blockIdx.x * blockDim.x + threadIdx.x;int Y = blockIdx.y * blockDim.y + threadIdx.y;if (X < range_W && Y < range_H) { vec3f& pixel = outPano(1000 - Y, X);float theta = 2 * PI * (float)X / (float)range_W - PI;float phi = PI * (float)Y / (float)range_H - PI / 2.0;Vector dir = Vector(sin(theta) * cos(phi), cos(phi) * cos(theta), sin(phi));Color hit_color = renderScene(viewpoint, dir);pixel[0] = hit_color.z * 255.0;pixel[1] = hit_color.y * 255.0;pixel[2] = hit_color.x * 255.0;}}cv::Mat Cube2Pano()
{ InitSceneTexture();dim3 thread(32, 32);dim3 block((2000 + thread.x - 1) / thread.x, (1000 + thread.y - 1) / thread.y);cv::cuda::GpuMat device_panorama = cv::cuda::GpuMat(1000, 2000, CV_32FC3);kernel8 << <block, thread >> > (2000, 1000, device_panorama);cudaThreadSynchronize();cv::Mat host_pano;device_panorama.download(host_pano);return host_pano;
}
//irradiance.cuh
#pragma once
#include "Enviro.cuh"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"extern "C" cv::Mat Cube2Pano();
//Enviro.cuh
#pragma once
#include "string"
#include
#include "environment.h"
#define DEVICE __device__
#define HOD __host__ __device__
using namespace xcx;texture<float4, cudaTextureType2D, cudaReadModeElementType> texBottomEnvironment;
texture<float4, cudaTextureType2D, cudaReadModeElementType> texTopEnvironment;
texture<float4, cudaTextureType2D, cudaReadModeElementType> texLeftEnvironment;
texture<float4, cudaTextureType2D, cudaReadModeElementType> texRightEnvironment;
texture<float4, cudaTextureType2D, cudaReadModeElementType> texFrontEnvironment;
texture<float4, cudaTextureType2D, cudaReadModeElementType> texBackEnvironment;void bind2DTopTexture(int width, int height);
void bind2DBottomTexture(int width, int height);
void bind2DLeftTexture(int width, int height);
void bind2DRightTexture(int width, int height);
void bind2DFrontTexture(int width, int height);
void bind2DBackTexture(int width, int height);environment myEnvironment;void InitSceneTexture() { char* path = "./Image_out/segmentation";myEnvironment.setFileRoute(path);myEnvironment.getImageSource();int sceneLength = myEnvironment.Top.width;int sceneHeight = myEnvironment.Top.height;bind2DTopTexture(sceneLength, sceneLength);bind2DBottomTexture(sceneLength, sceneLength);bind2DLeftTexture(sceneLength, sceneLength);bind2DRightTexture(sceneLength, sceneLength);bind2DFrontTexture(sceneLength, sceneLength);bind2DBackTexture(sceneLength, sceneLength);}void bind2DTopTexture(int width, int height) { size_t pitch, tex_ofs;float4*arr_d = 0;cudaMallocPitch((void**)&arr_d, &pitch, width * sizeof(float4), height);cudaMemcpy2D(arr_d, pitch, myEnvironment.Top.normData, width * sizeof(float4),width * sizeof(float4), height, cudaMemcpyHostToDevice);texTopEnvironment.normalized = false;cudaBindTexture2D(&tex_ofs, &texTopEnvironment, arr_d, &texTopEnvironment.channelDesc, width, height, pitch);
}
void bind2DBottomTexture(int width
union { float data[4]; struct { float x; float y; float z; }; };...
对于同一场景的2D全景图,如果想改变其视野中心位置,比如下图,初始情况下视野的中心位置是蓝框,如果想让红框的灯位于中心位置该怎么做呢?
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include
常量内存是NVIDIA提供的一个64KB大小的内存空间,它的处理方式和普通的全局内存和共享内存都不一样,是有cuda专门提供的。 线程束的概念:线程束是指一个包含32个线程的集合,在程序中的每一行,线程束中的每个线程都将在不同的数据上执行相同的指令。 因此,常量内存的作用是,能够将单次内存的读取操作广播到每个半线程束(即16个线程...
1、初始化,设置背景色 void glClear(int mask) 清除缓存 实參含义:GL10.GL_COLOR_BUFFER_BIT 清除颜色缓存 GL10.GL_DEPTH_BUFFER_BIT 清除深度缓存 ...
需要导入Zxing.jar包import android.graphics.Bitmap;import com.google.zxing.BarcodeFormat; import com.google.zxing.MultiFormatWriter; import com.google.zxing.WriterException;...
下面是我在博客园找到的,和我遇见的情况很相似,所以摘抄下来,原文见:http://www.cnblogs.com/charling/p/3635031.html box-sizing语法: box-sizing : content-box || border-box || inherit 参数取值: content-box...