Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
EmbreeTargetManager.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include <QtGlobal>
9#include <QCoreApplication>
10
11#include "FileName.h"
12#include "IException.h"
13
14#include "EmbreeTargetManager.h"
15
16using namespace std;
17
18namespace Isis {
19
24
25
31 : m_maxCacheSize(10) {
32 // This ensures this singleton is shut down when the application exists
33 qAddPostRoutine(DieAtExit);
34 return;
35 }
36
37
42 QList<QString> targetFiles = m_targeCache.keys();
43 for (int i = 0; i < targetFiles.size(); i++) {
44 removeTargetShape(targetFiles[i]);
45 }
46 }
47
48
61 delete m_maker;
62 m_maker = 0;
63 return;
64 }
65
66
83
84
94 QString EmbreeTargetManager::fullFilePath(const QString &filePath) const {
95 FileName fileName(filePath);
96 return fileName.expanded();
97 }
98
99
130 // Get the full path to the file
131 QString fullPath = fullFilePath(shapeFile);
132
133 // If the an EmbreeTargetShape already exists, increment its reference count
134 // and return a pointer.
135 if ( inCache(fullPath) ) {
136 ++(m_targeCache[fullPath].m_referenceCount);
137 return ( m_targeCache[fullPath].m_targetShape );
138 }
139
140 // Otherwise, make a new EmbreeTargetShape
141
142 // First check how many already exist
143 if ( m_targeCache.size() >= maxCacheSize() ) {
144 QString msg = "Failed creating EmbreeTargetShape for [" + shapeFile
145 + "] Too many EmbreeTargetShapes are already open.";
146 throw IException(IException::Programmer, msg, _FILEINFO_);
147 }
148
149 // If there's still space make a new one
150 EmbreeTargetShape *targetShape = new EmbreeTargetShape(fullPath);
151 EmbreeTargetShapeContainer targetShapeContainer(fullPath, targetShape);
152 ++(targetShapeContainer.m_referenceCount);
153 m_targeCache.insert(fullPath, targetShapeContainer);
154 return ( targetShapeContainer.m_targetShape );
155 }
156
157
173 void EmbreeTargetManager::free(const QString &shapeFile) {
174 // Get the full path to the file
175 QString fullPath = fullFilePath(shapeFile);
176
177 // Sanity check
178 if ( !inCache(fullPath) ) {
179 QString msg = "Cannot free EmbreeTargetShape for file ["
180 + fullPath + "] because it is not stored in the cache.";
181 throw IException(IException::Programmer, msg, _FILEINFO_);
182 }
183
184 // Get the container for the shapeFile
185 EmbreeTargetShapeContainer targetContainer = m_targeCache[fullPath];
186
187 // Decrement the reference count
188 int newCount = --(m_targeCache[fullPath].m_referenceCount);
189
190 // if the EmbreeTargetShape is no longer in use, delete it
191 if ( newCount < 1 ) {
192 removeTargetShape(fullPath);
193 }
194 }
195
196
210 void EmbreeTargetManager::removeTargetShape(const QString &shapeFile) {
211 // Get the full path to the file
212 QString fullPath = fullFilePath(shapeFile);
213
214 // Sanity check
215 if ( !inCache(fullPath) ) {
216 QString msg = "Cannot free EmbreeTargetShape for file ["
217 + fullPath + "] because it is not stored in the cache.";
218 throw IException(IException::Programmer, msg, _FILEINFO_);
219 }
220
221 // Get the container for the shapeFile
222 EmbreeTargetShapeContainer targetContainer = m_targeCache[fullPath];
223 delete targetContainer.m_targetShape;
224 m_targeCache.remove(fullPath);
225 }
226
227
234 return m_targeCache.size();
235 }
236
237
244 return m_maxCacheSize;
245 }
246
247
256 void EmbreeTargetManager::setMaxCacheSize(const int &numShapes) {
257 m_maxCacheSize = numShapes;
258 }
259
260
266 bool EmbreeTargetManager::inCache(const QString &shapeFile) const{
267 return m_targeCache.contains( fullFilePath(shapeFile) );
268 }
269}
Class for managing the construction and destruction of EmbreeTargetShapes.
int maxCacheSize() const
Return the maximum number of stored EmbreeTargetShapes.
void removeTargetShape(const QString &shapeFile)
Method for removing an EmbreeTargetShape from the internal cache.
EmbreeTargetShape * create(const QString &shapeFile)
Get a pointer to an EmbreeTargetShape containing the information from a shape file.
static void DieAtExit()
Exit termination routine.
EmbreeTargetManager()
This constructor will initialize the EmbreeTargetManager object to default values.
QString fullFilePath(const QString &filePath) const
Helper function that takes a file path and returns the full file path.
bool inCache(const QString &shapeFile) const
Check if there is an already created EmbreeTargetShape for a file.
void free(const QString &shapeFile)
Notify the manager that an EmbreeTargetShape is no longer in use.
int m_maxCacheSize
!< The cache of created target shapes.
void setMaxCacheSize(const int &numShapes)
Set the maximum number of stored EmbreeTargetShapes.
static EmbreeTargetManager * getInstance()
Retrieve reference to Singleton instance of this object.
int currentCacheSize() const
Return the number of currently stored EmbreeTargetShapes.
static EmbreeTargetManager * m_maker
Initialize the singleton factory pointer.
QMap< QString, EmbreeTargetShapeContainer > m_targeCache
!< Pointer to the singleton factory.
~EmbreeTargetManager()
Destructor that frees all of the EmbreeTargetShapes managed by this object.
Embree Target Shape for planetary bodies.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
Namespace for the standard library.
Reference counting container for EmbreeTargetShapes.
EmbreeTargetShape * m_targetShape
!< The full path to the file used to construct the EmbreeTargetShape.