I write the sphere radius interpolation for katana plugin that can transfer attributes,render attributes ,render velocity motion blur directly.

--GLY_MATH header source:

  1. //
  2. // Created by gearslogy on 4/13/16.
  3. //
  4.  
  5. #ifndef GLY_POINTSINTERPOLATION_GLY_COMMON_MATH_H
  6. #define GLY_POINTSINTERPOLATION_GLY_COMMON_MATH_H
  7.  
  8. #include <stdlib.h>
  9. #include <string>
  10. #include <vector>
  11. #include <sstream>
  12. #define gly_rand_01 double(rand()) / double(RAND_MAX)
  13.  
  14. namespace GLY_MATH
  15. {
  16. template <typename T>
  17. T min(T a,T b)
  18. {
  19. if(a>b)
  20. {
  21. return b;
  22. }
  23. else
  24. {
  25. return a;
  26. }
  27. }
  28. template <typename T>
  29. T max(T a,T b)
  30. {
  31. if(a>b)
  32. {
  33. return a;
  34. }
  35. else
  36. {
  37. return b;
  38. }
  39. }
  40.  
  41. template <typename T>
  42. int zero_compare(T a, double tol=0.00001)
  43. {
  44. return a >= -tol && a <= tol;
  45. }
  46.  
  47. // DO NOT USE THIS FIT TO FIT VECTOR VALUE
  48. template <typename T>
  49. T fit(T var, T omin, T omax,T nmin, T nmax)
  50. {
  51. T d = omax-omin;
  52. if(zero_compare(d))
  53. {
  54. return (nmin+nmax)*0.5;
  55. }
  56. if(omin<omax)
  57. {
  58. if (var < omin) return nmin;
  59. if (var > omax) return nmax;
  60. }
  61. else
  62. {
  63. if (var < omax) return nmax;
  64. if (var > omin) return nmin;
  65. }
  66. return nmin + (nmax-nmin)*(var-omin)/d;
  67. }
  68.  
  69. //return -1 to 1
  70. template <typename T>
  71. T fit_negate(T var,T omin,T omax)
  72. {
  73. return fit(var,omin,omax,-1.0,1.0);
  74. }
  75. // fast random 01 var
  76. double random_01_value(int seed)
  77. {
  78. srand(seed);
  79. return gly_rand_01;
  80. }
  81.  
  82. //string split
  83. std::vector <std::string> split_string(std::string &inputString, char &split_char)
  84. {
  85. std::stringstream ss(inputString);
  86. std::string sub_str;
  87. std::vector <std::string> sp_strPath;
  88. sp_strPath.clear();
  89. while(getline(ss,sub_str,split_char))
  90. {
  91. sp_strPath.push_back(sub_str);
  92. }
  93. return sp_strPath;
  94. }
  95.  
  96. //value to string
  97. template <typename T>
  98. // T must be a value int/float/double
  99. std::string value_to_str(T &value)
  100. {
  101. std::ostringstream os;
  102. os<< value;
  103. return os.str();
  104. }
  105.  
  106. }
  107.  
  108. #endif //GLY_POINTSINTERPOLATION_GLY_COMMON_MATH_H

--Arnold Source Code:

  1. #include <ai.h>
  2. #include <stdio.h>
  3. #include <cstring>
  4. #include "GLY_common_math.h"
  5. #include <vector>
  6. #include <string>
  7. #include <omp.h>
  8. #include <assert.h>
  9. using namespace std;
  10. #define RAND_NORMALIZE float(rand()) / float(RAND_MAX)
  11.  
  12. // global variables for read data
  13.  
  14. //@pt_radius = point radius
  15. float pt_radius;
  16. //@pt_list_num = point interpolation num
  17. AtUInt32 pt_list_num;
  18.  
  19. //
  20. float replicate_radius;
  21. AtArray *offset_vec;
  22. AtArray *frequency_vec;
  23.  
  24. //motion blur param
  25. //@pt_use_vel_mb choose should use motion blur
  26.  
  27. int pt_use_vel_mb;
  28. float shuffer_open_val;
  29. float shuffer_close_val;
  30.  
  31. //exist attribute
  32. AtArray *id_array_list; //Katana particles id ->define named "ins_id" from houdini abc
  33. AtArray *pos_array_list; // Katana particles P ->define named "P" from houdini abc
  34. AtArray *vel_array_list;
  35.  
  36. // other attribute
  37. string attribute_list;
  38. struct katana_attribute_map
  39. {
  40. string name;
  41. AtArray *map_array;
  42. //@map_array type = AI_TYPE_BYTE ->0
  43. //@map_array type = AI_TYPE_INT ->1
  44. //@map_array type = AI_TYPE_FLOAT ->4
  45. //@map_array type = AI_TYPE_POINT ->8
  46.  
  47. };
  48.  
  49. vector <katana_attribute_map> att_maps;
  50.  
  51. //get shuffer open pos
  52. AtVector get_shuffer_open_pos(AtVector &curl_v,AtVector &curl_p,
  53. float shuffer_open_val)
  54. {
  55. return curl_p+curl_v*shuffer_open_val;
  56. }
  57. // get shuffer close pos
  58. AtVector get_shuffer_close_pos(AtVector &curl_v,AtVector &curl_p,
  59. float shuffer_close_val)
  60. {
  61. return curl_p+curl_v*shuffer_close_val;
  62. }
  63.  
  64. // this is set the constant radius
  65. static void setConstantRadius(AtArray *radius_array , float &rad)
  66. {
  67. #pragma omp parallel for
  68. for(int i=;i<radius_array->nelements;i++)
  69. {
  70. AiArraySetFlt(radius_array,i,rad);
  71. }
  72. }
  73.  
  74. //@shuffer_value may be open or close value
  75. //@cur_pos_array is the new pos from the interpolation array
  76. //@orig_velocity_array is from katana
  77.  
  78. static AtArray* createMotionBlurOpenPoints(AtArray *orig_velocity_array,
  79. AtArray *cur_pos_array,float shuffer_value,AtUInt32 &iter_num)
  80. {
  81.  
  82. AtInt32 num_pt = orig_velocity_array->nelements/;
  83. printf("motion open ->get the num_pt is %d \n",num_pt);
  84. AtArray *_motion_points = AiArrayAllocate(cur_pos_array->nelements,,AI_TYPE_POINT);
  85.  
  86. vector <AtVector> large_vel_list;
  87.  
  88. // THIS IS NOT SIMD PROGRAM
  89. /*
  90. for(AtUInt32 i=0;i<num_pt;i++)
  91. {
  92.  
  93. AtVector __vel;
  94. __vel.x = AiArrayGetFlt(orig_velocity_array,i*3 + 0);
  95. __vel.y = AiArrayGetFlt(orig_velocity_array,i*3 + 1);
  96. __vel.z = AiArrayGetFlt(orig_velocity_array,i*3 + 2);
  97.  
  98. for(int j=0;j<iter_num;j++)
  99. {
  100. large_vel_list.push_back(__vel);
  101. }
  102.  
  103. }
  104. printf("motion open ->get the large vel array size is %d\n",large_vel_list.size());
  105. printf("motion open ->get the pos array size is %d\n",cur_pos_array->nelements);
  106. */
  107. large_vel_list.resize(iter_num * num_pt); // TELL THE GCC SIZE ,INDEX THE THREAD
  108. #pragma omp parallel for
  109. for(AtUInt32 i=;i<num_pt;i++)
  110. {
  111.  
  112. AtVector __vel;
  113. __vel.x = AiArrayGetFlt(orig_velocity_array,i* + );
  114. __vel.y = AiArrayGetFlt(orig_velocity_array,i* + );
  115. __vel.z = AiArrayGetFlt(orig_velocity_array,i* + );
  116.  
  117. for(int j=;j<iter_num;j++)
  118. {
  119. large_vel_list[i * iter_num + j ] = __vel;
  120. }
  121.  
  122. }
  123.  
  124. #pragma omp parallel for
  125. for(int i=; i<large_vel_list.size();i++)
  126. {
  127. AtVector __vel = large_vel_list[i];
  128. AtVector __pos = AiArrayGetPnt(cur_pos_array,i);
  129. AtVector __open_pos = get_shuffer_open_pos(__vel,__pos,shuffer_value);
  130. AiArraySetPnt(_motion_points,i,__open_pos);
  131. }
  132. return _motion_points;
  133. printf("motion open -> end\n ");
  134. }
  135.  
  136. static AtArray* createMotionBlurClosePoints(AtArray *orig_velocity_array,
  137. AtArray *cur_pos_array,float shuffer_value,AtUInt32 &iter_num)
  138. {
  139.  
  140. AtInt32 num_pt = orig_velocity_array->nelements/;
  141. printf("motion open ->get the num_pt is %d \n",num_pt);
  142. AtArray *_motion_points = AiArrayAllocate(cur_pos_array->nelements,,AI_TYPE_POINT);
  143.  
  144. vector <AtVector> large_vel_list;
  145. /*
  146. for(AtUInt32 i=0;i<num_pt;i++)
  147. {
  148.  
  149. AtVector __vel;
  150. __vel.x = AiArrayGetFlt(orig_velocity_array,i*3 + 0);
  151. __vel.y = AiArrayGetFlt(orig_velocity_array,i*3 + 1);
  152. __vel.z = AiArrayGetFlt(orig_velocity_array,i*3 + 2);
  153.  
  154. for(int j=0;j<iter_num;j++)
  155. {
  156. large_vel_list.push_back(__vel);
  157. }
  158.  
  159. }*/
  160.  
  161. //SIMD METHOD
  162. large_vel_list.resize(iter_num*num_pt);
  163. #pragma omp parallel for
  164. for(AtUInt32 i=;i<num_pt;i++)
  165. {
  166.  
  167. AtVector __vel;
  168. __vel.x = AiArrayGetFlt(orig_velocity_array,i* + );
  169. __vel.y = AiArrayGetFlt(orig_velocity_array,i* + );
  170. __vel.z = AiArrayGetFlt(orig_velocity_array,i* + );
  171.  
  172. for(int j=;j<iter_num;j++)
  173. {
  174. large_vel_list[i * iter_num + j] = __vel;
  175. }
  176.  
  177. }
  178.  
  179. #pragma omp parallel for
  180. for(int i=; i<large_vel_list.size();i++)
  181. {
  182. AtVector __vel = large_vel_list[i];
  183. AtVector __pos = AiArrayGetPnt(cur_pos_array,i);
  184. AtVector __close_pos = get_shuffer_close_pos(__vel,__pos,shuffer_value);
  185. AiArraySetPnt(_motion_points,i,__close_pos);
  186. }
  187. return _motion_points;
  188. printf("motion close -> end\n ");
  189. }
  190.  
  191. //transfer the vector attribute to the replicate points
  192. static void fork_vector_attribute(AtArray *src_vector_array,AtArray *des_vector_array,AtUInt32 &iter_num)
  193. {
  194. float *src_vec_data = static_cast<float *> (src_vector_array->data);
  195. AtUInt32 src_num_pt = src_vector_array->nelements/;// divide 3 because from Katana is a float array..
  196.  
  197. vector <AtRGBA> src_vec_list;
  198. src_vec_list.resize(src_num_pt * iter_num);
  199. #pragma omp parallel for
  200. for(AtUInt32 i=; i<src_num_pt; i++)
  201. {
  202. AtRGBA __vec;
  203. __vec.r = src_vec_data[i* + ];
  204. __vec.g = src_vec_data[i* + ];
  205. __vec.b = src_vec_data[i* + ];
  206. __vec.a = 1.0f;
  207. for(int j=;j<iter_num;j++)
  208. {
  209. //src_vec_list.push_back(__vec);
  210. src_vec_list[i*iter_num + j] = __vec;
  211. }
  212. }
  213. assert(src_vec_list.size() == des_vector_array->nelements);
  214. #pragma omp parallel for
  215. for(AtUInt32 i=;i<src_vec_list.size();i++)
  216. {
  217. AiArraySetRGBA(des_vector_array,i,src_vec_list[i]);
  218. }
  219. }
  220.  
  221. //transfer the float attribute to the replicate points
  222.  
  223. static void fork_float_attribute(AtArray *src_float_array,AtArray *des_vector_array,AtUInt32 &iter_num)
  224. {
  225. float *src_flt_data = static_cast<float *>(src_float_array->data);
  226. AtUInt32 src_num_pt = src_float_array->nelements;
  227.  
  228. vector <AtRGBA> src_vec_list;
  229. src_vec_list.resize(src_num_pt * iter_num);
  230.  
  231. #pragma omp parallel for
  232. for(AtUInt32 i=;i<src_num_pt; i++)
  233. {
  234. // convert float to the RGBA,"use_data_rgb/user_data_rgba" node get attribute in katana
  235. AtRGBA __vec;
  236. __vec.r = src_flt_data[i];
  237. __vec.g = src_flt_data[i];
  238. __vec.b = src_flt_data[i];
  239. __vec.a = 1.0f;
  240. for(int j=;j<iter_num;j++)
  241. {
  242. src_vec_list[i*iter_num + j] = __vec;
  243. }
  244.  
  245. }
  246. assert(src_vec_list.size() == des_vector_array->nelements);
  247. #pragma omp parallel for
  248. for(int j=;j<src_vec_list.size();j++)
  249. {
  250. AiArraySetRGBA(des_vector_array,j,src_vec_list[j]);
  251. }
  252.  
  253. }
  254.  
  255. //create point replicate
  256. static AtArray * makeSpherePoints(AtInt32 iter_num,AtInt32 orig_num_pt,AtArray *orig_pos_array,AtArray *orig_id_array)
  257. {
  258.  
  259. AtVector _offset;
  260. _offset.x = AiArrayGetFlt(offset_vec,);
  261. _offset.y = AiArrayGetFlt(offset_vec,);
  262. _offset.z = AiArrayGetFlt(offset_vec,);
  263.  
  264. AtVector _frequency;
  265. _frequency.x = AiArrayGetFlt(frequency_vec,);
  266. _frequency.y = AiArrayGetFlt(frequency_vec,);
  267. _frequency.z = AiArrayGetFlt(frequency_vec,);
  268.  
  269. AtInt32 num_pt = iter_num * orig_num_pt;
  270. AtArray *_sphere_pos_array = AiArrayAllocate(num_pt,,AI_TYPE_POINT);
  271.  
  272. assert(orig_pos_array->type==); // 4 is the AI_TYPE_FLOAT,because from katana P data is Array Float....
  273. assert(orig_id_array->type==); // 1 is the AI_TYPE_INT
  274.  
  275. vector <AtVector> child_pt_pos_list;
  276.  
  277. for(AtUInt32 i=;i<orig_id_array->nelements;i++)
  278. {
  279. int _id = AiArrayGetInt(orig_id_array,i);
  280. AtVector orig_pos;
  281. orig_pos.x = AiArrayGetFlt(orig_pos_array,i* + );
  282. orig_pos.y = AiArrayGetFlt(orig_pos_array,i* + );
  283. orig_pos.z = AiArrayGetFlt(orig_pos_array,i* + );
  284.  
  285. //printf("orig_pos_x -> : %f \n",orig_pos.x);
  286. //printf("orig_pos_y -> : %f \n",orig_pos.y);
  287. //printf("orig_pos_z -> : %f \n",orig_pos.z);
  288. for(int k=;k<iter_num;k++)
  289. {
  290. AtVector pt;
  291. srand(_id * + k*+);
  292. pt.x=GLY_MATH::fit(RAND_NORMALIZE,0.0f,1.0f,-1.0f,1.0f);
  293. srand(_id * + k*+);
  294. pt.y=GLY_MATH::fit(RAND_NORMALIZE,0.0f,1.0f,-1.0f,1.0f);
  295. srand(_id * + k*+);
  296. pt.z=GLY_MATH::fit(RAND_NORMALIZE,0.0f,1.0f,-1.0f,1.0f);
  297.  
  298. //get offst
  299.  
  300. //get frequency
  301.  
  302. AtVector new_pt = AiVNoise3(pt*_frequency +_offset,,0.0f,1.90f)*replicate_radius;
  303.  
  304. //printf("the father %d,the child %d,noise_pos_x -> : %f \n",i,k,pt.x);
  305. //printf("the father %d,the child %d,noise_pos_y -> : %f \n",i,k,pt.y);
  306. //printf("the father %d,the child %d,noise_pos_z -> : %f \n",i,k,pt.z);
  307.  
  308. child_pt_pos_list.push_back(new_pt + orig_pos);
  309.  
  310. }
  311.  
  312. }
  313. assert(child_pt_pos_list.size()==num_pt);
  314. #pragma omp parallel for
  315. for(AtUInt32 child=;child<num_pt;child++)
  316. {
  317. AiArraySetPnt(_sphere_pos_array,child,child_pt_pos_list[child]);
  318. }
  319. return _sphere_pos_array;
  320.  
  321. }
  322.  
  323. static int pt_init(AtNode *node,void **user_ptr)
  324. {
  325. *user_ptr = node;// make a copy of the parent procudural
  326. //AtArray *pt_data_array = AiNodeGetArray(node,"point_data");
  327.  
  328. pt_list_num = AiNodeGetInt(node,"interpolationNum");
  329. pt_radius = AiNodeGetFlt(node,"pointRadius");
  330. pt_use_vel_mb = AiNodeGetInt(node,"use_vel_motion_blur");
  331. shuffer_open_val = AiNodeGetFlt(node,"shuffer_open");
  332. shuffer_close_val = AiNodeGetFlt(node,"shuffer_close");
  333. // shape control
  334. replicate_radius = AiNodeGetFlt(node,"replicate_radius");
  335.  
  336. // Get id/pos list ...
  337. id_array_list = AiNodeGetArray(node,"ins_id");
  338. pos_array_list = AiNodeGetArray(node,"P");
  339. vel_array_list = AiNodeGetArray(node,"v");
  340. offset_vec = AiNodeGetArray(node,"offset");
  341. frequency_vec = AiNodeGetArray(node,"frequency");
  342. attribute_list = AiNodeGetStr(node,"attributeTransferList");
  343. /*
  344. for(int i=0;i<offset_vec->nelements;i++)
  345. {
  346. printf("get the offset val %f \n",AiArrayGetFlt(offset_vec,i));
  347. }
  348. */
  349. //printf("pt_init get the attribtue list is %s \n",attribute_list.c_str());
  350. /*
  351. printf("get the type is %d \n",vel_array_list->type);
  352. for(int i=0;i<vel_array_list->nelements;i++) {
  353. printf("get the array is %f\n", AiArrayGetFlt(vel_array_list, i));
  354. }
  355.  
  356. */
  357. char split_char = ',';
  358. vector <string > _attrib_list = GLY_MATH::split_string(attribute_list,split_char);
  359. att_maps.resize( _attrib_list.size() );
  360. // SIMD SET ARRAY...
  361. #pragma omp parallel for
  362. for(int i=; i<_attrib_list.size();i++)
  363. {
  364. string _curl_attrib_name = _attrib_list[i];
  365. katana_attribute_map _map;
  366. _map.name = _curl_attrib_name;
  367. _map.map_array = AiNodeGetArray(node,_curl_attrib_name.c_str());
  368. att_maps[i] = _map;
  369. }
  370.  
  371. printf("pt_init get iter num particles is %d \n",pt_list_num);
  372. printf("pt_init get particles radius is %f \n",pt_radius);
  373. printf("pt_init get shuffer_open is %f \n", shuffer_open_val);
  374. printf("pt_init get shuffer close is %f \n", shuffer_close_val);
  375. printf("pt_init get the use_motion_blur is %d \n",pt_use_vel_mb);
  376. return true;
  377. }
  378. static int pt_cleanup(void *user_ptr)
  379. {
  380. return true;
  381. }
  382. static int pt_numnodes(void *user_ptr)
  383. {
  384. return ;
  385. }
  386. static AtNode *MyGetNode(void *user_ptr,int i)
  387. {
  388.  
  389. printf("create node\n");
  390. AtNode *node = AiNode("points");
  391.  
  392. AtInt32 orig_num_pt = id_array_list->nelements; // from Houdini have num_pt
  393. AtInt32 iter_num_pt = orig_num_pt * pt_list_num; // every point have-> orig num pt * iterNum
  394.  
  395. AtArray *pointArray = AiArrayAllocate(iter_num_pt,,AI_TYPE_POINT);
  396. if(pt_use_vel_mb)
  397. {
  398. pointArray = AiArrayAllocate(iter_num_pt,,AI_TYPE_POINT);
  399. }
  400. else
  401. {
  402. pointArray = AiArrayAllocate(iter_num_pt,,AI_TYPE_POINT);
  403. }
  404.  
  405. printf("start create pt\n");
  406. AtArray *curl_pos_array = AiArrayAllocate(iter_num_pt,,AI_TYPE_POINT);
  407. curl_pos_array=makeSpherePoints(pt_list_num,orig_num_pt,pos_array_list,id_array_list);
  408.  
  409. if(pt_use_vel_mb)
  410. {
  411. printf("start create motion blur points\n");
  412. AtArray *__open_pos_array = createMotionBlurOpenPoints(vel_array_list,curl_pos_array,shuffer_open_val,pt_list_num);
  413. AtArray *__close_pos_array = createMotionBlurClosePoints(vel_array_list,curl_pos_array,shuffer_close_val,pt_list_num);
  414.  
  415. float *__open_pos_array_data = static_cast<float *> (__open_pos_array->data);
  416. float *__close_pos_array_data = static_cast<float *> (__close_pos_array->data);
  417.  
  418. printf("setting motion blur points\n");
  419. AiArraySetKey(pointArray,,__open_pos_array_data);
  420. AiArraySetKey(pointArray,,__close_pos_array_data);
  421. printf("setting motion blur points compelte\n");
  422. }
  423. else
  424. {
  425. pointArray = curl_pos_array;
  426. }
  427.  
  428. //Radius setttings
  429. //printf("starting create radius array\n");
  430. AtArray *radiusArray = AiArrayAllocate(iter_num_pt,,AI_TYPE_FLOAT);
  431. setConstantRadius(radiusArray,pt_radius);
  432.  
  433. // transfer v attribute that can use "use_data_rgb/use_data_rgba" to render channel.
  434. AtArray *channel_v = AiArrayAllocate(iter_num_pt,,AI_TYPE_RGBA);
  435. fork_vector_attribute(vel_array_list,channel_v,pt_list_num);
  436. AiNodeDeclare(node, "v", "uniform RGBA");
  437. AiNodeSetArray(node,"v",channel_v);
  438.  
  439. // transfer other transfer attribute
  440. for(int i=; i<att_maps.size() ;i++)
  441. {
  442. katana_attribute_map map_attrib = att_maps[i];
  443. string att_name = map_attrib.name;
  444. AtArray *array = map_attrib.map_array;
  445.  
  446. AtArray *_channel = AiArrayAllocate(iter_num_pt,,AI_TYPE_RGBA);
  447. AiNodeDeclare(node,att_name.c_str(),"uniform RGBA");
  448.  
  449. if(array->nelements == orig_num_pt) // not vector attrib
  450. {
  451. printf("fork other float/int attribute name is %s \n",att_name.c_str());
  452. fork_float_attribute(array,_channel,pt_list_num);
  453. AiNodeSetArray(node,att_name.c_str(),_channel);
  454.  
  455. }
  456. if(array->nelements == orig_num_pt * ) // vector attrib
  457. {
  458. printf("fork other vector attribute name is %s \n",att_name.c_str());
  459. fork_vector_attribute(array,_channel,pt_list_num);
  460. AiNodeSetArray(node,att_name.c_str(),_channel);
  461. }
  462.  
  463. }
  464.  
  465. AiNodeSetArray(node,"points",pointArray);
  466. AiNodeSetArray(node,"radius",radiusArray);
  467. AiNodeSetStr(node, "mode", "sphere");
  468. printf("complete the procedural points\n");
  469. return node;
  470. }
  471. proc_loader
  472. {
  473. vtable->Init = pt_init;
  474. vtable->Cleanup = pt_cleanup;
  475. vtable->NumNodes = pt_numnodes;
  476. vtable->GetNode = MyGetNode;
  477. strcpy(vtable->version,AI_VERSION);
  478. return true;
  479. }

--KATANA Source code:

---header

  1. //
  2. // Created by GearsLogy on 4/11/16.
  3. // this file connect the procedural points create ...
  4. //
  5.  
  6. #ifndef GLY_INTERPOLATIONPARTICLES_GLY_INTERPOLATIONOP_H
  7. #define GLY_INTERPOLATIONPARTICLES_GLY_INTERPOLATIONOP_H
  8.  
  9. #include <FnRenderOutputUtils/FnRenderOutputUtils.h>
  10. #include <FnGeolib/op/FnGeolibOp.h>
  11. #include <FnPluginSystem/FnPlugin.h>
  12. #include <FnAttribute/FnAttribute.h>
  13. #include <FnAttribute/FnGroupBuilder.h>
  14. #include <FnGeolib/util/Path.h>
  15. #include <FnGeolibServices/FnGeolibCookInterfaceUtilsService.h>
  16.  
  17. class GLY_InterpolationOP : public Foundry::Katana::GeolibOp
  18. {
  19. public:
  20. static void setup(Foundry::Katana::GeolibSetupInterface &interface)
  21. {
  22. interface.setThreading(Foundry::Katana::GeolibSetupInterface::ThreadModeConcurrent);
  23. }
  24. static void cook(Foundry::Katana::GeolibCookInterface &interface);
  25.  
  26. };
  27.  
  28. #endif //GLY_INTERPOLATIONPARTICLES_GLY_INTERPOLATIONOP_H

---source

  1. /
  2. // Created by gearslogy on 4/11/16.
  3. //
  4.  
  5. #include "GLY_InterpolationOP.h"
  6. #include <stdio.h>
  7. #include <string>
  8. #include <vector>
  9. #include <sstream>
  10. using namespace std;
  11. void GLY_InterpolationOP::cook(Foundry::Katana::GeolibCookInterface &interface)
  12. {
  13. FnAttribute::StringAttribute get_par_loc = interface.getOpArg("particle_path");
  14. FnAttribute::StringAttribute get_procedural_loc = interface.getOpArg("procedural_path");
  15.  
  16. if(!get_procedural_loc.isValid() || get_procedural_loc.getValue("",false).empty()) return;
  17. // next create a location just for the rendering...
  18. string procedural_loc_str = get_procedural_loc.getValue("",false);
  19. Foundry::Katana::CreateLocationInfo createLocationInfo;
  20. Foundry::Katana::CreateLocation(createLocationInfo,interface,procedural_loc_str);
  21.  
  22. if(!get_par_loc.isValid()) {
  23. printf("%s not found the attribute",get_par_loc.getValue("", false));
  24. return;
  25. }
  26. /*
  27. int ex = interface.doesLocationExist(get_par_loc.getValue("",false));
  28. if(!ex) {
  29. printf("%s do not exist in the location\n",get_par_loc.getValue("", false));
  30. return;
  31. }*/
  32. string par_loc_str = get_par_loc.getValue("",false);
  33. FnAttribute::FloatAttribute get_par_radius_att = interface.getOpArg("pointRadius");
  34. FnAttribute::IntAttribute get_par_num_att = interface.getOpArg("interpolationNum");
  35. FnAttribute::IntAttribute get_use_motion_blur = interface.getOpArg("use_vel_motion_blur");
  36. FnAttribute::FloatAttribute get_shuffer_open = interface.getOpArg("shuffer_open");
  37. FnAttribute::FloatAttribute get_shuffer_close = interface.getOpArg("shuffer_close");
  38. FnAttribute::FloatAttribute get_replicate_radius = interface.getOpArg("replicate_radius");
  39. FnAttribute::FloatAttribute get_noise_fre = interface.getOpArg("frequency");
  40. FnAttribute::FloatAttribute get_noise_offset = interface.getOpArg("offset");
  41. FnAttribute::StringAttribute get_attribute_list = interface.getOpArg("attributeTransferList");
  42.  
  43. //printf("oparg check\n");
  44. if(!get_par_radius_att.isValid()) return;
  45. if(!get_par_num_att.isValid()) return;
  46. if(!get_shuffer_open.isValid()) return;
  47. if(!get_use_motion_blur.isValid()) return;
  48. if(!get_shuffer_close.isValid()) return;
  49. if(!get_replicate_radius.isValid()) return;
  50. if(!get_attribute_list.isValid()) return;
  51. if(!get_noise_fre.isValid()) {printf("not found frequency arg\n");return;}
  52. if(!get_noise_offset.isValid()) {printf("not found offset arg\n");return;}
  53. //float pt_radius = get_par_radius_att.getValue(0.0f,false);
  54. //int pt_num = get_par_num_att.getValue(0,false);
  55. //printf("transfer data\n");
  56. //get id and p attribute
  57. FnAttribute::IntAttribute id_attribute = interface.getAttr("geometry.arbitrary.ins_id.value",par_loc_str);
  58. FnAttribute::FloatAttribute pos_attribute = interface.getAttr("geometry.point.P",par_loc_str);
  59. FnAttribute::FloatAttribute vel_attribute = interface.getAttr("geometry.point.v",par_loc_str);
  60.  
  61. if(!id_attribute.isValid()){
  62. Foundry::Katana::ReportError(interface,"No ins_id attribute in particles location\n");
  63. return;
  64. }
  65. if(!pos_attribute.isValid()){
  66. Foundry::Katana::ReportError(interface,"No P attribute in particles");
  67. return;
  68. }
  69. if(!vel_attribute.isValid()){
  70. Foundry::Katana::ReportError(interface,"No v attribute in particles");
  71. return;
  72. }
  73.  
  74. string fullName = interface.getOutputLocationPath();
  75. FnGeolibUtil::Path::FnMatchInfo fnMatchInfo;
  76. FnGeolibUtil::Path::FnMatch(fnMatchInfo, fullName,procedural_loc_str);
  77. if (!fnMatchInfo.match) return;
  78.  
  79. //attribute transfer list checking
  80. string attr_list = get_attribute_list.getValue("", false);
  81. //printf("current attribute list is %s \n",attr_list.c_str());
  82. stringstream ss(attr_list);
  83. string sub_str;
  84. vector <string> sp_strPath;
  85. sp_strPath.clear();
  86. while(getline(ss,sub_str,','))
  87. {
  88. sp_strPath.push_back(sub_str);
  89. }
  90.  
  91. if(sp_strPath.size()!= && attr_list!="")
  92. {
  93.  
  94. interface.setAttr("rendererProcedural.args.attributeTransferList",get_attribute_list);
  95. for(int i=;i<sp_strPath.size();i++)
  96. {
  97. string __attri_base_name = sp_strPath[i];
  98. string __prefix = "geometry.arbitrary.";
  99. string __endfix = ".value";
  100. string __attri_des_name = __prefix + __attri_base_name + __endfix;
  101. //printf("checking the %s attribute\n",__attri_des_name.c_str());
  102. FnAttribute::Attribute __att__handle = interface.getAttr(__attri_des_name,par_loc_str);
  103. int __att__type = __att__handle.getType();
  104. // printf("the type is %d\n",__att__type);
  105. if(__att__handle.isValid())
  106. {
  107. //printf("found attribute in particles %s\n",__attri_des_name.c_str());
  108. if (__att__type == ) // int
  109. {
  110. //printf("set to the int\n");
  111. FnAttribute::IntAttribute __int_handle = FnAttribute::IntAttribute(__att__handle);
  112. interface.setAttr(string("rendererProcedural.args.")+ __attri_base_name , __int_handle);
  113. }
  114. if(__att__type == ) // float
  115. {
  116. //printf("set to the float\n");
  117. FnAttribute::FloatAttribute __float_handle = FnAttribute::FloatAttribute(__att__handle);
  118. interface.setAttr(string("rendererProcedural.args.")+ __attri_base_name , __float_handle);
  119. }
  120. }
  121. else
  122. {
  123. string error_msg = "please check the error attribute :" + __attri_base_name + " do not exist\n";
  124. Foundry::Katana::ReportError(interface,error_msg);
  125. return;
  126. }
  127.  
  128. }
  129. }
  130.  
  131. // set our procedural attribute
  132. interface.setAttr("type",FnAttribute::StringAttribute("renderer procedural"));
  133. interface.setAttr("rendererProcedural.procedural",FnAttribute::StringAttribute("libArnoldGLY_PointInterpolation"));
  134. interface.setAttr("rendererProcedural.args.__outputStyle",FnAttribute::StringAttribute("typedArguments"));
  135. interface.setAttr("rendererProcedural.args.interpolationNum",get_par_num_att);
  136. interface.setAttr("rendererProcedural.args.pointRadius",get_par_radius_att);
  137. interface.setAttr("rendererProcedural.args.replicate_radius",get_replicate_radius);
  138. interface.setAttr("rendererProcedural.args.frequency",get_noise_fre);
  139. interface.setAttr("rendererProcedural.args.offset",get_noise_offset);
  140. //
  141. interface.setAttr("rendererProcedural.args.use_vel_motion_blur",get_use_motion_blur);
  142. interface.setAttr("rendererProcedural.args.shuffer_open",get_shuffer_open);
  143. interface.setAttr("rendererProcedural.args.shuffer_close",get_shuffer_close);
  144.  
  145. interface.setAttr("rendererProcedural.args.ins_id",id_attribute);
  146. interface.setAttr("rendererProcedural.args.P",pos_attribute);
  147. interface.setAttr("rendererProcedural.args.v",vel_attribute);
  148.  
  149. printf("katana Interpolation Particles -> setting complete\n");
  150. }

Interpolation particles In Katana的更多相关文章

  1. 如何安装并简单的使用OwinHost——Katana

    微软OWIN的提出必然会引起一场风暴,而我们作为C#阵营中一份子,自然免不了会卷入其中.OWIN是什么东西,我在这里就不解析了,还不知道是OWIN是什么的读者请打开浏览器,然后搜索即可,中文的英文的应 ...

  2. OWIN与Katana详解

    前言 我胡汉三又回来了,!!!!, 最近忙成狗,实在没空写博文,实在对不起自己,博客园上逛了逛发现 我大微软还是很给力的 asp.net core 1.0 .net core 1.0 即将发布,虽然. ...

  3. 基于OWin的Web服务器Katana发布版本3

    当 ASP.NET 首次在 2002 年发布时,时代有所不同. 那时,Internet 仍处于起步阶段,大约有 5.69 亿用户,每个用户平均每天访问 Internet 的时间为 46 分钟,大约有 ...

  4. OPEN CASCADE BSpline Curve Interpolation

    OPEN CASCADE BSpline Curve Interpolation eryar@163.com Abstract. Global curve interpolation to point ...

  5. OpenCASCADE Interpolation - Lagrange

    OpenCASCADE Interpolation - Lagrange eryar@163.com Abstract. Power basis polynomial is the most simp ...

  6. 快刀斩乱麻之 Katana

    Katana-武士刀,寓意:快.准.狠! 按照常规,我们一般编写的 ASP.NET 应用程序会部署在 IIS 上(有点傻的描述),在 ASP.NET 应用程序中,我们会大量使用 HttpContext ...

  7. 下一代Asp.net开发规范OWIN(2)—— Katana介绍以及使用

    接上篇OWIN产生的背景以及简单介绍,在了解了OWIN规范的来龙去脉后,接下来看一下Katana这个OWIN规范的实现,并看看如何使用在我们的Web开发中. 阅读目录: 一. Katana项目的结构和 ...

  8. ASP.NET MVC随想录——锋利的KATANA

    正如上篇文章所述那样,OWIN在Web Server与Web Application之间定义了一套规范(Specs),意在解耦Web Server与Web Application,从而推进跨平台的实现 ...

  9. Interpolation in MATLAB

    Mathematics     One-Dimensional Interpolation There are two kinds of one-dimensional interpolation i ...

随机推荐

  1. linux文件数相关命令

    查看系统目前打开的文件数命令#cat /proc/slabinfo | grep ip_conn | grep -v ip_conntrack_expect | awk '{print $2}' 查看 ...

  2. 模拟jquery的$()选择器的实现

    <html> <head> </head> <body> <div id="div1">div1</div> ...

  3. oracle 常用函数【转】

    常用Oracle函数 SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数; SQL> select ascii('A') A,ascii('a') a,ascii('0') z ...

  4. AVAudioPlayer播放本地音频

    AVAudioPlayer苹果官方上说一般用于播放本地音频,不能用于播放网络上的音频. 具体的代码:先导入 #import <AVFoundation/AVFoundation.h> // ...

  5. http工作流程

    一次HTTP操作称为一个事务,其工作过程可分为四步:1)首先客户机与服务器需要建立连接.只要单击某个超级链接,HTTP的工作开始.2)建立连接后,客户机发送一个请求给服务器,请求方式的格式为:统一资源 ...

  6. 如何在Eclipse中查看JDK以及JAVA框架的源码(转载)

    原文链接:http://www.cnblogs.com/outlooking/p/5243415.html 设置步骤如下: 1.点 “window”-> "Preferences&qu ...

  7. flex布局

    一,啥是flex? 1.Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性.任何一个容器都可以指定为Flex布局. .box{ displa ...

  8. MVVM与Backbone demo

    MVVM https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel

  9. win8.1 Framework3.5安装不上的问题

    问题症状:安装的WIN8系统无法安装Framework,SQL等都有问题 解决误区:直接安装或者更新后在线安装(结果一样各种错误) 解决方法: 1.先gpedit.msc进入本地组策略管理,目录:计算 ...

  10. jfinal 解决ajax 跨域访问--jsonp

    JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象.简单地理解就是因为JavaScript同源策略的限制,a.com 域名下的 js无法操作b.com或是c.a.com域名下的对象. ...