This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Initialize | |
clear | |
%% Set dimesion | |
N = 10^6; | |
%% Set source vectors and scalar values | |
src1 = ones(N, 1); | |
src2 = 2*ones(N, 1); | |
k1 = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mex.h" | |
#include "gpu/mxGPUArray.h" | |
__global__ | |
void vec_add | |
( | |
const double* src1, | |
const double* src2, | |
const double k1, | |
const double k2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | |
{ | |
//変数の定義 | |
const mxGPUArray *src; | |
mxGPUArray *dst; | |
const double *d_src; | |
double *d_dst; | |
//初期化 | |
mxInitGPU(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | |
{ | |
double* ptr; | |
plhs[0] = mxCreateDoubleMatrix(5, 5, mxREAL); | |
ptr = mxGetPr(plhs[0]); | |
/* ここでptrに数値データを入れていく */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | |
{ | |
double* ptr; | |
ptr = mxCalloc(5*5, sizeof(double)); | |
/* ここでptrに数値データを入れていく */ | |
plhs[0] = mxCreateDoubleMatrix(5, 5, mxREAL); | |
mxSetPr(plhs[0], ptr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mex.h" | |
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | |
{ | |
// nlhs : 出力の数 | |
// plhs[idx] : idx番目の出力が格納されているメモリのアドレス | |
// nrhs : 入力の数 | |
// prhs[idx] : idx番目の入力が格納されているメモリのアドレス | |
/* ここに処理を書く */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 初期化 | |
Pidx = PolygonIdx(p); % p番目のポリゴンのインデックス集合 | |
%% ポリゴンの内部判定(Pscは頂点のスクリーン座標) | |
[in, on] = inpolygon(X, Y, Psc(1, Pidx), Psc(2, Pidx)); | |
%% UV座標の代入 | |
Uin = []; | |
Vin = []; | |
Uin = UV(1,Pidx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Img_dst = TextureFetch(Img_src, Mask, U, V, Texture, Alpha) | |
[ly, lx] = size(Texture(:,:,1)); | |
%% UV座標からピクセル座標に変換 | |
I = round((lx-1) .* U) + 1; | |
J = round((ly-1) .* V) + 1; | |
%% フェッチする部分のインデックスを計算 | |
IND = sub2ind([ly lx], J, I); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function P_sc = pinhole(P_view, f) | |
%% 同次座標表現 | |
[ly, lx] = size(P_view); | |
p_affine = [P_view;ones(1,lx)]; | |
%% 射影変換行列 | |
A = [-f 0 0 0; | |
0 -f 0 0; | |
0 0 1 0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function P_view = world2view(P_world, CameraTarget, CameraPosition, CameraUpVector) | |
%% 同次座標表現 | |
[ly, lx] = size(P_world); | |
p_affine = [P_world;ones(1,lx)]; | |
%% カメラ位置による座標変換 | |
% ビュー変換行列の生成 | |
t = (CameraPosition' - CameraTarget'); | |
t = t ./ norm(t); | |
r = cross(CameraUpVector', t); |