Isis 3 Programmer Reference
|
Class for managing the construction and destruction of EmbreeTargetShapes. More...
#include <EmbreeTargetManager.h>
Classes | |
struct | EmbreeTargetShapeContainer |
Reference counting container for EmbreeTargetShapes. More... | |
Public Member Functions | |
EmbreeTargetShape * | create (const QString &shapeFile) |
Get a pointer to an EmbreeTargetShape containing the information from a shape file. More... | |
void | free (const QString &shapeFile) |
Notify the manager that an EmbreeTargetShape is no longer in use. More... | |
int | currentCacheSize () const |
Return the number of currently stored EmbreeTargetShapes. More... | |
int | maxCacheSize () const |
Return the maximum number of stored EmbreeTargetShapes. More... | |
bool | inCache (const QString &shapeFile) const |
Check if there is an already created EmbreeTargetShape for a file. More... | |
void | setMaxCacheSize (const int &numShapes) |
Set the maximum number of stored EmbreeTargetShapes. More... | |
Static Public Member Functions | |
static EmbreeTargetManager * | getInstance () |
Retrieve reference to Singleton instance of this object. More... | |
Private Member Functions | |
EmbreeTargetManager () | |
This constructor will initialize the EmbreeTargetManager object to default values. More... | |
~EmbreeTargetManager () | |
Destructor that frees all of the EmbreeTargetShapes managed by this object. More... | |
QString | fullFilePath (const QString &filePath) const |
Helper function that takes a file path and returns the full file path. More... | |
void | removeTargetShape (const QString &shapeFile) |
Method for removing an EmbreeTargetShape from the internal cache. More... | |
Static Private Member Functions | |
static void | DieAtExit () |
Exit termination routine. More... | |
Private Attributes | |
QMap< QString, EmbreeTargetShapeContainer > | m_targeCache |
!< Pointer to the singleton factory. More... | |
int | m_maxCacheSize |
!< The cache of created target shapes. More... | |
Static Private Attributes | |
static EmbreeTargetManager * | m_maker = 0 |
Initialize the singleton factory pointer. More... | |
Class for managing the construction and destruction of EmbreeTargetShapes.
This class is a singleton that constructs and holds EmbreeTargetShape. Due to the time required to construct a new EmbreeTargetShape and the large memory requirements, this class limits their creation and the number that can be held in memory at one time.
When an EmbreeTargetShape is requested the EmbreeTargetManager will first check if an EmbreeTargetShape for that file already exists. If one does, a pointer to the existing EmbreeTargetShape is given and the reference count is incremented. If one does not exist yet, a new EmbreeTargetShape is created on the heap. When an EmbreeTargetShape is no longer used, the EmbreeTargetManager should be notified and it will decrement the reference count on that EmbreeTargetShape. If the EmbreeTargetShape is no longer used by anything, then it is deleted.
Definition at line 53 of file EmbreeTargetManager.h.
|
private |
This constructor will initialize the EmbreeTargetManager object to default values.
The default maximum number of shape models held in memory is 10
Definition at line 47 of file EmbreeTargetManager.cpp.
References DieAtExit().
Referenced by getInstance().
|
private |
Destructor that frees all of the EmbreeTargetShapes managed by this object.
Definition at line 58 of file EmbreeTargetManager.cpp.
References m_targeCache, and removeTargetShape().
EmbreeTargetShape * Isis::EmbreeTargetManager::create | ( | const QString & | shapeFile | ) |
Get a pointer to an EmbreeTargetShape containing the information from a shape file.
If the shape file has already been stored in an EmbreeTargetShape then a pointer to that is returned. If the shape file has not been loaded yet, then it is loaded and a pointer to the EmbreeTargetShape is returned.
In both cases, ownership of the pointer is not passed. Use EmbreeTargetManager::free to notify the EmbreeTargetManager that the pointer is no longer in use.
The EmbreeTargetShapes take a large amount of time to create and memory to store, so the manager limits the number that can be opened at one time. If the limit is reached and a new one is requested, an error is thrown. Use EmbreeTargetManager::setMaxCacheSize to change the maximum number of EmbreeTargetShapes.
shapeFile | The path to the file to create an EmbreeTargetShape from |
IException::Programmer |
Definition at line 146 of file EmbreeTargetManager.cpp.
References _FILEINFO_, fullFilePath(), inCache(), Isis::EmbreeTargetManager::EmbreeTargetShapeContainer::m_referenceCount, m_targeCache, Isis::EmbreeTargetManager::EmbreeTargetShapeContainer::m_targetShape, maxCacheSize(), and Isis::IException::Programmer.
Referenced by Isis::EmbreeShapeModel::EmbreeShapeModel().
int Isis::EmbreeTargetManager::currentCacheSize | ( | ) | const |
Return the number of currently stored EmbreeTargetShapes.
Definition at line 250 of file EmbreeTargetManager.cpp.
References m_targeCache.
|
staticprivate |
Exit termination routine.
This (static) method ensure this object is destroyed when Qt exits.
Note that it is error to add this to the system _atexit() routine because this object utilizes Qt classes. At the time the atexit call stack is executed, Qt is long gone resulting in Very Bad Things. Fortunately, Qt has an exit stack function as well. This method is added to the Qt exit call stack.
Definition at line 77 of file EmbreeTargetManager.cpp.
References m_maker.
Referenced by EmbreeTargetManager().
void Isis::EmbreeTargetManager::free | ( | const QString & | shapeFile | ) |
Notify the manager that an EmbreeTargetShape is no longer in use.
This method will decrease the internal reference count for the target shape. Then if there are not more references. the EmbreeTargetShape is destroyed to free up memory.
shapeFile | The path to the file used to create the EmbreeTargetShape. This should be the same as the parameter used with EmbreeTargetManager::create to get a pointer to the EmbreeTargetShape. |
IException::Programmer |
Definition at line 190 of file EmbreeTargetManager.cpp.
References _FILEINFO_, fullFilePath(), inCache(), m_targeCache, Isis::IException::Programmer, and removeTargetShape().
Referenced by Isis::EmbreeShapeModel::~EmbreeShapeModel().
|
private |
Helper function that takes a file path and returns the full file path.
filePath | The file path to expand. |
Definition at line 111 of file EmbreeTargetManager.cpp.
References Isis::FileName::expanded().
Referenced by create(), free(), inCache(), and removeTargetShape().
|
static |
Retrieve reference to Singleton instance of this object.
The only access provided for Singleton instance of this object. All method access is made through the pointer returned by this method. The object is created upon the first call to this method. The object is deleted when Qt shuts down.
Definition at line 94 of file EmbreeTargetManager.cpp.
References EmbreeTargetManager(), and m_maker.
bool Isis::EmbreeTargetManager::inCache | ( | const QString & | shapeFile | ) | const |
Check if there is an already created EmbreeTargetShape for a file.
shapeFile | The path to the file to check for |
Definition at line 283 of file EmbreeTargetManager.cpp.
References fullFilePath(), and m_targeCache.
Referenced by create(), free(), and removeTargetShape().
int Isis::EmbreeTargetManager::maxCacheSize | ( | ) | const |
Return the maximum number of stored EmbreeTargetShapes.
Definition at line 260 of file EmbreeTargetManager.cpp.
References m_maxCacheSize.
Referenced by create().
|
private |
Method for removing an EmbreeTargetShape from the internal cache.
The EmbreeTargetShapeContainer destructor does not delete the EmbreeTargetShape, so this should be used to free delete anything from the cache.
shapeFile | The path to the shape file used to create the EmbreeTargetShape that will be removed. |
IException::Programmer |
Definition at line 227 of file EmbreeTargetManager.cpp.
References _FILEINFO_, fullFilePath(), inCache(), m_targeCache, Isis::EmbreeTargetManager::EmbreeTargetShapeContainer::m_targetShape, and Isis::IException::Programmer.
Referenced by free(), and ~EmbreeTargetManager().
void Isis::EmbreeTargetManager::setMaxCacheSize | ( | const int & | numShapes | ) |
Set the maximum number of stored EmbreeTargetShapes.
This does not apply retroactively. If there are more stored EmbreeTargetShapes than the new maximum, then they will remain and new EmbreeTargetShapes cannot be created until the number currently open goes below the maximum.
numShapes | The new maximum number of stored EmbreeTargetShapes. |
Definition at line 273 of file EmbreeTargetManager.cpp.
References m_maxCacheSize.
|
staticprivate |
Initialize the singleton factory pointer.
Definition at line 112 of file EmbreeTargetManager.h.
Referenced by DieAtExit(), and getInstance().
|
private |
!< The cache of created target shapes.
Definition at line 115 of file EmbreeTargetManager.h.
Referenced by maxCacheSize(), and setMaxCacheSize().
|
private |
!< Pointer to the singleton factory.
Definition at line 113 of file EmbreeTargetManager.h.
Referenced by create(), currentCacheSize(), free(), inCache(), removeTargetShape(), and ~EmbreeTargetManager().