Skip to content

Instantly share code, notes, and snippets.

View rej55's full-sized avatar

Fumiya Watanabe rej55

  • TIER IV, Inc.
  • Japan
View GitHub Profile
%% Initialize
clear
%% Set dimesion
N = 10^6;
%% Set source vectors and scalar values
src1 = ones(N, 1);
src2 = 2*ones(N, 1);
k1 = 2;
@rej55
rej55 / vec_add.cu
Last active December 3, 2017 05:36
#include "mex.h"
#include "gpu/mxGPUArray.h"
__global__
void vec_add
(
const double* src1,
const double* src2,
const double k1,
const double k2,
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
//変数の定義
const mxGPUArray *src;
mxGPUArray *dst;
const double *d_src;
double *d_dst;
//初期化
mxInitGPU();
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double* ptr;
plhs[0] = mxCreateDoubleMatrix(5, 5, mxREAL);
ptr = mxGetPr(plhs[0]);
/* ここでptrに数値データを入れていく */
}
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);
}
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// nlhs : 出力の数
// plhs[idx] : idx番目の出力が格納されているメモリのアドレス
// nrhs : 入力の数
// prhs[idx] : idx番目の入力が格納されているメモリのアドレス
/* ここに処理を書く */
}
%% 初期化
Pidx = PolygonIdx(p); % p番目のポリゴンのインデックス集合
%% ポリゴンの内部判定(Pscは頂点のスクリーン座標)
[in, on] = inpolygon(X, Y, Psc(1, Pidx), Psc(2, Pidx));
%% UV座標の代入
Uin = [];
Vin = [];
Uin = UV(1,Pidx);
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);
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];
@rej55
rej55 / world2view.m
Last active December 11, 2016 05:47
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);