IReferenceCounted.h

本文详细介绍了Irrlicht引擎中IReferenceCounted类的作用及使用方法。该类提供了引用计数机制,通过grab()和drop()方法管理对象生命周期,确保资源适时释放。适用于引擎内部创建的对象管理。

/*

* IReferenceCounted.h

*

* Created on: 2010-10-11

* Author: Mido

* 计数统计,基类

* - 来自于大哥irrlicht

*/

 

#ifndef IREFERENCECOUNTED_H_

#define IREFERENCECOUNTED_H_

 

#include "IrrTypes.h"

 

namespace irrlight

{

 

//! Base class of most objects of the IrrLight Engine.

/** This class provides reference counting through the methods grab() and drop().

It also is able to store a debug string for every instance of an object.

Most objects of the IrrLight

Engine are derived from IReferenceCounted, and so they are reference counted.

 

When you create an object in the IrrLight engine, calling a method

which starts with 'create', an object is created, and you get a pointer

to the new object. If you no longer need the object, you have

to call drop(). This will destroy the object, if grab() was not called

in another part of you program, because this part still needs the object.

Note, that you only need to call drop() to the object, if you created it,

and the method had a 'create' in it.

 

A simple example:

 

If you want to create a texture, you may want to call an imaginable method

IDriver::createTexture. You call

ITexture* texture = driver->createTexture(dimension2d<s32>(128, 128));

If you no longer need the texture, call texture->drop().

 

If you want to load a texture, you may want to call imaginable method

IDriver::loadTexture. You do this like

ITexture* texture = driver->loadTexture("example.jpg");

You will not have to drop the pointer to the loaded texture, because

the name of the method does not start with 'create'. The texture

is stored somewhere by the driver.

*/

class IReferenceCounted

{

public:

 

//! Constructor.

IReferenceCounted()

: ReferenceCounter(1), DebugName(0)

{

}

 

//! Destructor.

virtual ~IReferenceCounted()

{

}

 

//! Grabs the object. Increments the reference counter by one.

/** Someone who calls grab() to an object, should later also

call drop() to it. If an object never gets as much drop() as

grab() calls, it will never be destroyed. The

IReferenceCounted class provides a basic reference counting

mechanism with its methods grab() and drop(). Most objects of

the IrrLight Engine are derived from IReferenceCounted, and so

they are reference counted.

 

When you create an object in the IrrLight engine, calling a

method which starts with 'create', an object is created, and

you get a pointer to the new object. If you no longer need the

object, you have to call drop(). This will destroy the object,

if grab() was not called in another part of you program,

because this part still needs the object. Note, that you only

need to call drop() to the object, if you created it, and the

method had a 'create' in it.

 

A simple example:

 

If you want to create a texture, you may want to call an

imaginable method IDriver::createTexture. You call

ITexture* texture = driver->createTexture(dimension2d<s32>(128, 128));

If you no longer need the texture, call texture->drop().

If you want to load a texture, you may want to call imaginable

method IDriver::loadTexture. You do this like

ITexture* texture = driver->loadTexture("example.jpg");

You will not have to drop the pointer to the loaded texture,

because the name of the method does not start with 'create'.

The texture is stored somewhere by the driver. */

any grab() const { ++ReferenceCounter; }

 

//! Drops the object. Decrements the reference counter by one.

/** The IReferenceCounted class provides a basic reference

counting mechanism with its methods grab() and drop(). Most

objects of the IrrLight Engine are derived from

IReferenceCounted, and so they are reference counted.

 

When you create an object in the IrrLight engine, calling a

method which starts with 'create', an object is created, and

you get a pointer to the new object. If you no longer need the

object, you have to call drop(). This will destroy the object,

if grab() was not called in another part of you program,

because this part still needs the object. Note, that you only

need to call drop() to the object, if you created it, and the

method had a 'create' in it.

 

A simple example:

 

If you want to create a texture, you may want to call an

imaginable method IDriver::createTexture. You call

ITexture* texture = driver->createTexture(dimension2d<s32>(128, 128));

If you no longer need the texture, call texture->drop().

If you want to load a texture, you may want to call imaginable

method IDriver::loadTexture. You do this like

ITexture* texture = driver->loadTexture("example.jpg");

You will not have to drop the pointer to the loaded texture,

because the name of the method does not start with 'create'.

The texture is stored somewhere by the driver.

/return True, if the object was deleted. */

bool drop() const

{

// someone is doing bad reference counting.

//_IRR_DEBUG_BREAK_IF(ReferenceCounter <= 0) // ڶ��ԡ��?����ָȡ��.Mido.2010.9.27

 

--ReferenceCounter;

if (!ReferenceCounter)

{

delete this;

return true;

}

 

return false;

}

 

//! Get the reference count.

/** /return Current value of the reference counter. */

s32 getReferenceCount() const

{

return ReferenceCounter;

}

 

//! Returns the debug name of the object.

/** The Debugname may only be set and changed by the object

itself. This method should only be used in Debug mode.

/return Returns a string, previously set by setDebugName(); */

const c8* getDebugName() const

{

return DebugName;

}

 

protected:

 

//! Sets the debug name of the object.

/** The Debugname may only be set and changed by the object

itself. This method should only be used in Debug mode.

/param newName: New debug name to set. */

any setDebugName(const c8* newName)

{

DebugName = newName;

}

 

private:

//! The reference counter. Mutable to do reference counting on const objects.

mutable s32 ReferenceCounter;

//! The debug name.

const c8* DebugName;

};

 

} // end namespace IrrLight

 

#endif /* IREFERENCECOUNTED_H_ */

 

 

 

本文来自:鬼火神灯 - irrlight.com

复杂几何的多球近似MATLAB类及多球模型的比较 MATLAB类Approxi提供了一个框架,用于使用具有迭代缩放的聚集球体模型来近似解剖体积模型,以适应目标体积和模型比较。专为骨科、生物力学和计算几何应用而开发。 MATLAB class for multi-sphere approximation of complex geometries and comparison of multi-sphere models 主要特点: 球体模型生成 1.多球体模型生成:与Sihaeri的聚集球体算法的接口 2.音量缩放 基于体素的球体模型和参考几何体的交集。 迭代缩放球体模型以匹配目标体积。 3.模型比较:不同模型体素占用率的频率分析(多个评分指标) 4.几何分析:原始曲面模型和球体模型之间的顶点到最近邻距离映射(带颜色编码结果)。 如何使用: 1.代码结构:Approxi类可以集成到相应的主脚本中。代码的关键部分被提取到单独的函数中以供重用。 2.导入:将STL(或网格)导入MATLAB,并确保所需的函数,如DEM clusteredSphere(populateSpheres)和inpolyhedron,已添加到MATLAB路径中 3.生成多球体模型:使用DEM clusteredSphere方法从输入网格创建多球体模型 4.运行体积交点:计算多球体模型和参考几何体之间的基于体素的交点,并调整多球体模型以匹配目标体积 5.比较和可视化模型:比较多个多球体模型的体素频率,并计算多球体模型与原始表面模型之间的距离,以进行2D/3D可视化 使用案例: 骨科和生物力学体积建模 复杂结构的多球模型形状近似 基于体素拟合度量的模型选择 基于距离的患者特定几何形状和近似值分析 优点: 复杂几何的多球体模型 可扩展模型(基于体素)-自动调整到目标体积 可视化就绪输出(距离图)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值