转:怎样高效的使用RiProcedure
2011-03-30 23:07
232 查看
http://cid-a6597afda81373ba.spaces.live.com/blog/cns!A6597AFDA81373BA!295.entry如何更加高效的使用RiProcedure
A traditional procedural primitive calls Subdivide() function to create RIB stream as soon as its bounding box is hit. But in this example, Subdivide() does not create any RIB stream. It invokes another procedural for several times instead. We call it Proxy. We call the procedural invoked by Proxy is called Real.
The idea is to divide large data set into a number of smaller fragments, each has its own smaller bounding box. Real procedural will not trigger RIB stream until it’s bounding box is hit. And RenderMan will release memory allocated to a Real as soon as it has been rendered. This method uses memory a lot more efficiently than emitting all RIB stream in one piece.
#include <stdio.h>
#include <stdlib.h>
#include "DProxy.h"
#include "DReal.h"
#ifdef _WIN32
#define export __declspec(dllexport)
#define strtok_r(str,delim,saveptr) strtok((str),(delim))
#else
#define export
#endif
extern "C" {
/* Declarations */
export RtPointer ConvertParameters(RtString paramstr);
export RtVoid Subdivide(RtPointer data, float detail);
export RtVoid Free(RtPointer data);
export RtVoid Subdivide_real(RtPointer data, float detail);
export RtVoid Free_real(RtPointer data);
}
export RtPointer ConvertParameters(RtString paramstr)
{
export RtVoid Subdivide(RtPointer blinddata, RtFloat detailsize)
{
export RtVoid Subdivide_real(RtPointer blinddata, RtFloat detailsize)
{
export RtVoid Free(RtPointer blinddata)
{
export RtVoid Free_real(RtPointer blinddata)
{
A traditional procedural primitive calls Subdivide() function to create RIB stream as soon as its bounding box is hit. But in this example, Subdivide() does not create any RIB stream. It invokes another procedural for several times instead. We call it Proxy. We call the procedural invoked by Proxy is called Real.
The idea is to divide large data set into a number of smaller fragments, each has its own smaller bounding box. Real procedural will not trigger RIB stream until it’s bounding box is hit. And RenderMan will release memory allocated to a Real as soon as it has been rendered. This method uses memory a lot more efficiently than emitting all RIB stream in one piece.
#include <stdio.h>
#include <stdlib.h>
#include "DProxy.h"
#include "DReal.h"
#ifdef _WIN32
#define export __declspec(dllexport)
#define strtok_r(str,delim,saveptr) strtok((str),(delim))
#else
#define export
#endif
extern "C" {
/* Declarations */
export RtPointer ConvertParameters(RtString paramstr);
export RtVoid Subdivide(RtPointer data, float detail);
export RtVoid Free(RtPointer data);
export RtVoid Subdivide_real(RtPointer data, float detail);
export RtVoid Free_real(RtPointer data);
}
export RtPointer ConvertParameters(RtString paramstr)
{
DProxy *data = new DProxy(paramstr);
return data;
}return data;
export RtVoid Subdivide(RtPointer blinddata, RtFloat detailsize)
{
DProxy *data = static_cast< DProxy*>(blinddata);
data->init();
DReal* realdata;
RtBound bound = {-.5, .5, -.5, .5, -.5, .5};
for(unsigned i=0; i< data->getNumData(); i++) {
realdata = new DReal();
float noi = float(random()%131)/262.f+0.03;
realdata->setRadius( noi);
RiTransformBegin();
float noix = (0.5 - float(random()%271)/271.f)*5;
float noiy = (0.5 - float(random()%219)/219.f)*5;
float noiz = (0.5 - float(random()%253)/253.f)*5;
RiTranslate(noix, noiy, noiz);
bound[0] = -noi; bound[1] = noi;
bound[2] = -noi; bound[3] = noi;
bound[4] = -noi; bound[5] = noi;
RiProcedural(realdata, bound, Subdivide_real, Free_real);
RiTransformEnd();
}
}data->init();
DReal* realdata;
RtBound bound = {-.5, .5, -.5, .5, -.5, .5};
for(unsigned i=0; i< data->getNumData(); i++) {
realdata = new DReal();
float noi = float(random()%131)/262.f+0.03;
realdata->setRadius( noi);
RiTransformBegin();
float noix = (0.5 - float(random()%271)/271.f)*5;
float noiy = (0.5 - float(random()%219)/219.f)*5;
float noiz = (0.5 - float(random()%253)/253.f)*5;
RiTranslate(noix, noiy, noiz);
bound[0] = -noi; bound[1] = noi;
bound[2] = -noi; bound[3] = noi;
bound[4] = -noi; bound[5] = noi;
RiProcedural(realdata, bound, Subdivide_real, Free_real);
RiTransformEnd();
}
export RtVoid Subdivide_real(RtPointer blinddata, RtFloat detailsize)
{
DReal *data = static_cast< DReal*>(blinddata);
data->emit();
}data->emit();
export RtVoid Free(RtPointer blinddata)
{
DProxy *data = static_cast< DProxy*>(blinddata);
delete data;
}delete data;
export RtVoid Free_real(RtPointer blinddata)
{
DReal *data = static_cast< DReal*>(blinddata);
delete data;
}
delete data;
相关文章推荐
- 怎样高效的使用JavaEE ORM框架
- 怎样高效的使用一种语言?
- 怎样使用Mendeley高效地管理中文文献
- 怎样才能高效地使用JQuery
- 怎样才能高效地使用JQuery
- 怎样才能高效地使用JQuery
- C++ 位运算:怎样使用位运算简洁高效的完成计算
- 怎样高效的使用mysql一些示例
- 在编写R语言代码时,怎样高效使用Sublime Text等编辑器
- 怎样高效的使用JavaEE ORM框架
- 使用PHP+Sphinx建立高效的站内搜索引擎
- 使用FindBugs改善你的代码质量—为什么使用以及怎样使用
- Android 5.0 怎样正确启用isLoggable(一)__使用具体解释
- 演示事件(Event)怎样使用以及怎样为用户控件添加一个事件(示例代码下载)
- 怎样使用VSS
- 论怎样高效编程
- Linux高效使用的七个好习惯
- 【Android】【缓存】Andrid高效显示Bitmap( 使用缓存技术)
- Android Studio 结合 ButterKnife Zelezny 高效使用 Butterknife(黄油刀)
- SQLServer2005里怎样对使用with encryption选项创建的存储过程解密