diff --git a/Collision/CollisionMoller.h b/Collision/CollisionMoller.h index b194dcb154f908acbed39c54979df408cf72e730..349275ca8222e4c9d305c319441b850250d41c8c 100644 --- a/Collision/CollisionMoller.h +++ b/Collision/CollisionMoller.h @@ -35,36 +35,36 @@ class CollisionMoller public: /// \brief triangle and triangle collision retursn intersection and projection points static bool tri2tri(core::Vec3d &p_tri1Point1, - core::Vec3d &p_tri1Point2, - core::Vec3d &p_tri1Point3, - core::Vec3d &p_tri2Point1, - core::Vec3d &p_tri2Point2, - core::Vec3d &p_tri2Point3, - int &coplanar, - core::Vec3d &p_intersectionPoint1, - core::Vec3d &p_intersectionPoint2, - short &p_tri1SinglePointIndex, - short &p_tri2SinglePointIndex, - core::Vec3d &p_projPoint1, - core::Vec3d &p_projPoint2); + core::Vec3d &p_tri1Point2, + core::Vec3d &p_tri1Point3, + core::Vec3d &p_tri2Point1, + core::Vec3d &p_tri2Point2, + core::Vec3d &p_tri2Point3, + int &coplanar, + core::Vec3d &p_intersectionPoint1, + core::Vec3d &p_intersectionPoint2, + short &p_tri1SinglePointIndex, + short &p_tri2SinglePointIndex, + core::Vec3d &p_projPoint1, + core::Vec3d &p_projPoint2); - static bool tri2tri( core::Vec3d &p_tri1Point1, - core::Vec3d &p_tri1Point2, - core::Vec3d &p_tri1Point3, - core::Vec3d &p_tri2Point1, - core::Vec3d &p_tri2Point2, - core::Vec3d &p_tri2Point3, - double &depth, - core::Vec3d &contactPoint, - core::Vec3d &normal); + static bool tri2tri(core::Vec3d &p_tri1Point1, + core::Vec3d &p_tri1Point2, + core::Vec3d &p_tri1Point3, + core::Vec3d &p_tri2Point1, + core::Vec3d &p_tri2Point2, + core::Vec3d &p_tri2Point3, + double &depth, + core::Vec3d &contactPoint, + core::Vec3d &normal); /// \brief checks if the two triangles intersect static bool tri2tri(core::Vec3d &p_tri1Point1, - core::Vec3d &p_tri1Point2, - core::Vec3d &p_tri1Point3, - core::Vec3d &p_tri2Point1, - core::Vec3d &p_tri2Point2, - core::Vec3d &p_tri2Point3); + core::Vec3d &p_tri1Point2, + core::Vec3d &p_tri1Point3, + core::Vec3d &p_tri2Point1, + core::Vec3d &p_tri2Point2, + core::Vec3d &p_tri2Point3); /// \brief check if the two AABB overlap returns encapsulating AABB of two static bool checkOverlapAABBAABB(AABB &aabbA, AABB &aabbB, AABB &result); @@ -77,11 +77,11 @@ public: /// \brief checks if the line intersects the tirangle. returns if it is true. the intersection is returned in p_interSection static bool checkLineTri(core::Vec3d &p_linePoint1, - core::Vec3d &p_linePoint2, - core::Vec3d &p_tri1Point1, - core::Vec3d &p_tri1Point2, - core::Vec3d &p_tri1Point3, - core::Vec3d &p_interSection); + core::Vec3d &p_linePoint2, + core::Vec3d &p_tri1Point1, + core::Vec3d &p_tri1Point2, + core::Vec3d &p_tri1Point3, + core::Vec3d &p_interSection); /// \brief checks if the triangles points are within the AABB static bool checkAABBTriangle(AABB &p_aabb, core::Vec3d &v1, core::Vec3d &v2, core::Vec3d &v3); diff --git a/Core/DataStructures.h b/Core/DataStructures.h index fb3e2cac2ee709e097400b7148a94c427bb95cdd..ed12b6a10c0f9b1ac7c19dc3ec3af9dc4c6c2883 100644 --- a/Core/DataStructures.h +++ b/Core/DataStructures.h @@ -27,80 +27,6 @@ // SimMedTK includes #include "Core/Config.h" -template<typename T> -class IndiceArrayIter; - -/// \brief inidice array for fast access to index -template<typename T> -class IndiceArray -{ -protected: - /// \brief storage - T *storage; - /// \brief check if the slot is empty - bool *isEmpty; - /// \brief indices - int *indices; - /// \brief number of elements - int nbrElements; - /// \brief maximum storage - int maxStorage; -public: - /// \brief destructor - ~IndiceArray(); - /// \brief constructor; gets maximum number of elements - inline IndiceArray(int p_maxStorage); - /// \brief add item - inline int add(T p_item); - /// \brief check if the item exists, if not add - inline int checkAndAdd(T p_item); - /// \brief remove the element from array - inline bool remove(int p_itemIndex); - - /// \brief replace the entry in p_index slot with p_item - inline bool replace(int p_index, T &p_item); - /// \brief get element by reference - inline T& getByRef(int p_index); - /// \brief get element by safe. If the element doesn't exist it will return false - inline bool getByRefSafe(int p_index, T&p_item); - /// \brief get element by reference with string - inline T& getByRef(std::string p_string); - /// \brief for iterative access - friend IndiceArrayIter<T>; - /// \brief print the elements - inline void print() const; - /// \brief operators - inline T& operator[](int p_index); - - inline int size(); - /// \brief copy from another p_array - inline bool copy(IndiceArray &p_array); -}; - -/// \brief iteration -template<class T> -class IndiceArrayIter -{ - int index; - IndiceArray<T> *arrayPtr; -public: - /// \brief constructor that require index array - IndiceArrayIter(IndiceArray<T> *p_array); - /// \brief operators for accessing and iteration - T& operator[](int p_index); - - int& operator++(); //prefix; - - int operator++(const int); //postfix; - - int& operator--(); //prefix; - - int operator--(const int); //postfix; - - inline int begin(); - - inline int end(); -}; /// \brief hash bucket size #define SIMMEDTK_HASHBUCKET_SIZE 10 /// \brief a hash entry; bucket @@ -164,6 +90,7 @@ public: long int num_prim; /// \brief table size long int tableSize; + private: /// \brief entries in the bucket inline void moveEntriesInBucket(EntryList<T> &p_Bucket, int p_entryIndex); @@ -203,33 +130,6 @@ enum StorageSlideType SIMMEDTK_STORAGESLIDING_FRONTFIRST, SIMMEDTK_STORAGESLIDING_LASTFIRST }; -/// \brief sliding storage window -template<typename T> -class StorageSlidingWindow -{ -private: - /// \brief type - StorageSlideType strorageType; -public: - /// \brief data - T *data; - /// \brief window size - unsigned int windowSize; - /// \brief constructor - ~StorageSlidingWindow(); - /// \brief siding window storage. constructor gets window size, type - StorageSlidingWindow(int p_windowSize = 10, StorageSlideType p_type = SIMMEDTK_STORAGESLIDING_LASTFIRST); - /// \brief storage type - inline StorageSlideType getStorageType(); - /// \brief resize storage - inline void resize(int p_newSize); - /// \brief add value - inline void add(T p_value); - /// \brief zero all the entries - inline void zeroed(); - /// \brief print all the elements - void print() const; -}; #include "Core/DataStructures.hpp" diff --git a/Core/DataStructures.hpp b/Core/DataStructures.hpp index 3bff1ac53ce8b248d2c5b5070a4b53df9e265710..55e6ca088d4ca96f216fbb2af875d7071add8c2f 100644 --- a/Core/DataStructures.hpp +++ b/Core/DataStructures.hpp @@ -24,223 +24,6 @@ #ifndef SMDATASTUCTURES_HPP #define SMDATASTUCTURES_HPP -template<typename T> -IndiceArray<T>::~IndiceArray() -{ - delete [] indices; - delete [] storage; - delete [] isEmpty; -} -template<typename T> -IndiceArray<T>::IndiceArray( int p_maxStorage ) -{ - maxStorage = p_maxStorage; - indices = new int[p_maxStorage]; - storage = new T[p_maxStorage]; - isEmpty = new bool[p_maxStorage]; - - for ( int i = 0; i < p_maxStorage; i++ ) - { - isEmpty[i] = true; - } - - nbrElements = 0; -} -template<typename T> int -IndiceArray<T>::add( T p_item ) -{ - int index = -1; - - if ( nbrElements < maxStorage ) - { - for ( int i = 0; i < maxStorage; i++ ) - { - if ( isEmpty[i] ) - { - index = i; - break; - } - } - - if ( index >= 0 && index < maxStorage ) - { - isEmpty[index] = false; - storage[index] = p_item; - indices[nbrElements] = index; - nbrElements++; - return index; - } - } - - return index; -} -template<typename T> int -IndiceArray<T>::checkAndAdd( T p_item ) -{ - int index = -1; - - if ( nbrElements < maxStorage ) - { - for ( int i = 0; i < nbrElements; i++ ) - if ( storage[indices[i]] == p_item ) - { - break; - } - - return add( p_item ); - } - - return index; -} -template<typename T> bool -IndiceArray<T>::remove( int p_itemIndex ) -{ - int counter = 0; - - if ( p_itemIndex >= 0 && p_itemIndex < maxStorage ) - { - for ( int i = 0; i < nbrElements; i++ ) - { - if ( i == p_itemIndex ) - { - continue; - } - - indices[counter] = indices[i]; - counter++; - } - - nbrElements--; - isEmpty[p_itemIndex] = true; - return true; - } - else - { - return false; - } -} -template<typename T> bool -IndiceArray<T>::replace( int p_index, T &p_item ) -{ - if ( isEmpty[p_index] == false ) - { - storage[p_index] = p_item; - return true; - } - - return false; -} -template<typename T> -T &IndiceArray<T>::getByRef( int p_index ) -{ - return storage[p_index]; -} -template<typename T> bool -IndiceArray<T>::getByRefSafe( int p_index, T &p_item ) -{ - if ( isEmpty[p_index] ) - { - return false; - } - else - { - p_item = storage[p_index]; - return true; - } -} -template<typename T> -T &IndiceArray<T>::getByRef( std::string p_string ) -{ - for ( int i = 0; i < nbrElements; i++ ) - { - if ( storage[indices[i]] == p_string ) - { - return storage[indices[i]]; - } - } -} -template<typename T> void -IndiceArray<T>::print() const -{ - for ( int i = 0; i < nbrElements; i++ ) - { - storage[indices[i]]->print(); - } -} -template<typename T> -T &IndiceArray<T>::operator[]( int p_index ) -{ - return storage[indices[p_index]]; -} -template<typename T> int -IndiceArray<T>::size() -{ - return nbrElements; -} -template<typename T> bool -IndiceArray<T>::copy( IndiceArray &p_array ) -{ - if ( maxStorage < p_array.maxStorage ) - { - for ( int j = 0; j < maxStorage; j++ ) - { - isEmpty[j] = true; - } - - for ( int i = 0; i < p_array.nbrElements; i++ ) - { - storage[indices[i]] = p_array.storage[p_array.indices[i]]; - indices[i] = p_array.indices[i]; - isEmpty[i] = p_array.isEmpty[p_array.indices[i]]; - } - - return true; - } - - return false; -} - -template<typename T> -IndiceArrayIter<T>::IndiceArrayIter( IndiceArray< T > *p_array ) -{ - arrayPtr = p_array; -} -template<typename T> -T &IndiceArrayIter<T>::operator[]( int p_index ) -{ - return arrayPtr->storage[ arrayPtr->indices[p_index]]; -} -template<typename T> int& -IndiceArrayIter<T>::operator++() -{ - return ++index; -} -template<typename T> int -IndiceArrayIter<T>::operator++( const int ) -{ - return index++; -} -template<typename T> int& -IndiceArrayIter<T>::operator--() -{ - return --index; -} -template<typename T> int -IndiceArrayIter<T>::operator--( const int ) -{ - return index--; -} -template<typename T> int -IndiceArrayIter<T>::begin() -{ - index = 0; - return index; -} -template<typename T> int -IndiceArrayIter<T>::end() -{ - return arrayPtr->nbrElements; -} template<typename T> EntryList<T>::EntryList() { @@ -255,7 +38,7 @@ HashIterator<T>::HashIterator() bucketStart = NULL; } template<typename T> void -HashIterator<T>::clone( HashIterator< T > &p_iterator ) +HashIterator<T>::clone( HashIterator<T> &p_iterator ) { tableIndex = p_iterator.tableIndex; currentIndex = p_iterator.currentIndex; @@ -269,13 +52,13 @@ HashIterator<T>::resetBucketIteration() iterator = bucketStart; } template<typename T> -std::ostream &operator<<( std::ostream &out, HashIterator< T > &p ) +std::ostream &operator<<( std::ostream &out, HashIterator<T> &p ) { out << "Table Index:" << p.tableIndex << " Current Bucket Index:" << p.currentIndex; return out; } template<typename T> -void Hash<T>::moveEntriesInBucket( EntryList< T > &p_Bucket, int p_entryIndex ) +void Hash<T>::moveEntriesInBucket( EntryList<T> &p_Bucket, int p_entryIndex ) { for ( unsigned int i = p_entryIndex; i < p_Bucket.totalEntries - 1; i++ ) { @@ -285,7 +68,7 @@ void Hash<T>::moveEntriesInBucket( EntryList< T > &p_Bucket, int p_entryIndex ) p_Bucket.totalEntries--; } template<typename T> -bool Hash<T>::checkIdentical( EntryList< T > &p_entry, T p_prim ) +bool Hash<T>::checkIdentical( EntryList<T> &p_entry, T p_prim ) { for ( unsigned int i = 0; i < p_entry.totalEntries; i++ ) { @@ -298,7 +81,7 @@ bool Hash<T>::checkIdentical( EntryList< T > &p_entry, T p_prim ) return false; } template<typename T> -bool Hash<T>::findandUpdateEntry( EntryList< T > &p_startEntry, T &p_prim ) +bool Hash<T>::findandUpdateEntry( EntryList<T> &p_startEntry, T &p_prim ) { EntryList<T> *currentBucket = &p_startEntry; @@ -322,7 +105,7 @@ bool Hash<T>::findandUpdateEntry( EntryList< T > &p_startEntry, T &p_prim ) } } template<typename T> -void Hash<T>::clearBuckets( EntryList< T > &p_startEntry ) +void Hash<T>::clearBuckets( EntryList<T> &p_startEntry ) { EntryList<T> *currentBucket = &p_startEntry; @@ -445,7 +228,7 @@ void Hash<T>::startIteration() currentIterationBucket = &primitiveIDs[currentTableIndex]; } template<typename T> -bool Hash<T>::next( HashIterator< T > &p_iterator ) +bool Hash<T>::next( HashIterator<T> &p_iterator ) { if ( p_iterator.tableIndex >= tableSize ) { @@ -459,7 +242,7 @@ bool Hash<T>::next( HashIterator< T > &p_iterator ) return true; } template<typename T> -bool Hash<T>::nextBucketItem( HashIterator< T > &p_iterator, T &p_prim ) +bool Hash<T>::nextBucketItem( HashIterator<T> &p_iterator, T &p_prim ) { while ( true ) { @@ -576,97 +359,5 @@ void Hash<T>::clearAll() num_prim = 0; } -template<typename T> -StorageSlidingWindow<T>::~StorageSlidingWindow() -{ - delete[] data; -} -template<typename T> -StorageSlidingWindow<T>::StorageSlidingWindow( int p_windowSize, StorageSlideType p_type ) -{ - data = new T[p_windowSize]; - windowSize = p_windowSize; - memset( data, 0, sizeof( T )*p_windowSize ); - strorageType = p_type; -} -template<typename T> -StorageSlideType StorageSlidingWindow<T>::getStorageType() -{ - return strorageType; -} -template<typename T> -void StorageSlidingWindow<T>::resize( int p_newSize ) -{ - T *tempData; - int index; - - if ( windowSize == p_newSize ) - { - return; - } - - tempData = new T[p_newSize]; - memset( tempData, 0, sizeof( T )*p_newSize ); - - if ( strorageType == SIMMEDTK_STORAGESLIDING_LASTFIRST ) - { - if ( p_newSize > windowSize ) - { - memcpy( tempData + p_newSize - windowSize, data, windowSize * sizeof( T ) ); - } - else - { - memcpy( tempData, data + p_newSize, p_newSize * sizeof( T ) ); - } - } - else - { - if ( p_newSize > windowSize ) - { - memcpy( tempData, data, windowSize * sizeof( T ) ); - } - else - { - memcpy( tempData, data, p_newSize * sizeof( T ) ); - } - } - - delete[] data; - data = tempData; - windowSize = p_newSize; -} -template<typename T> -void StorageSlidingWindow<T>::add( T p_value ) -{ - if ( strorageType == SIMMEDTK_STORAGESLIDING_LASTFIRST ) - { - memcpy( data, &data[1], ( windowSize - 1 )*sizeof( T ) ); - data[windowSize - 1] = p_value; - } - else - { - for ( int i = windowSize - 1; i > 0; i-- ) - { - data[i] = data[i - 1]; - } - - data[0] = p_value; - } -} -template<typename T> -void StorageSlidingWindow<T>::zeroed() -{ - memset( data, 0, sizeof( T )*windowSize ); -} -template<typename T> -void StorageSlidingWindow<T>::print() const -{ - for ( int i = 0; i < windowSize; i++ ) - { - std::cout << data[i] << " "; - } - - std::cout << "\n"; -} #endif diff --git a/Core/SDK.cpp b/Core/SDK.cpp index e45ce672d0e6a400ec1cd00c5fc6273a964a3fe5..b591efe828b24e0802dcd45cd1f68129a37a21d7 100644 --- a/Core/SDK.cpp +++ b/Core/SDK.cpp @@ -32,13 +32,6 @@ // std::unique_ptr<ErrorLog> SDK::errorLog; std::once_flag SDK::sdkCallOnceFlag; -IndiceArray<MeshHolder> *SDK::meshesRef; -IndiceArray<ModuleHolder> *SDK::modulesRef; -IndiceArray<ObjectSimulatorHolder> *SDK::objectSimulatorsRef; -IndiceArray<ObjectSimulatorHolder>*SDK::collisionDetectorsRef; -IndiceArray<SceneHolder>*SDK::scenesRef; -IndiceArray<SceneObjectHolder>*SDK::sceneObjectsRef; - /// \brief constructor SDK::SDK() { @@ -51,14 +44,6 @@ SDK::SDK() sceneList.clear(); errorLog = std::make_shared<ErrorLog>(); - - // TODO: Fix these! Leaking... - meshesRef = new IndiceArray<MeshHolder>(SIMMEDTK_SDK_MAXMESHES); - modulesRef = new IndiceArray<ModuleHolder>(SIMMEDTK_SDK_MAXMODULES) ; - objectSimulatorsRef = new IndiceArray<ObjectSimulatorHolder>(SIMMEDTK_SDK_MAXOBJECTSIMULATORS); - collisionDetectorsRef = new IndiceArray<ObjectSimulatorHolder>(SIMMEDTK_SDK_MAXOBJECTSIMULATORS) ; - scenesRef = new IndiceArray<SceneHolder>(SIMMEDTK_SDK_MAXSCENES); - sceneObjectsRef = new IndiceArray<SceneObjectHolder>(SIMMEDTK_SDK_MAXSCENEOBJTECTS); } SDK::~SDK() @@ -83,7 +68,7 @@ void SDK::releaseScene(std::shared_ptr<Scene> scene) std::shared_ptr<ViewerBase> SDK::createViewer() { this->viewer = Factory<CoreClass>::createDefaultAs<ViewerBase>("ViewerBase"); - if (!!this->viewer) + if (this->viewer) { this->viewer->log = this->errorLog; this->registerModule(this->viewer); @@ -112,15 +97,10 @@ std::shared_ptr<ViewerBase> SDK::getViewerInstance() /// \brief std::shared_ptr<Simulator> SDK::createSimulator() { - if (this->simulator == nullptr) + if(!this->simulator) { simulator = std::make_shared<Simulator>(errorLog); - - for (int j = 0; j < (*scenesRef).size(); j++) - { - simulator->sceneList.push_back((*scenesRef)[j].scene); - } - + simulator->sceneList = this->sceneList; registerModule(simulator); } @@ -135,12 +115,13 @@ void SDK::updateSceneListAll() /// \brief Initialize all modules registered to the SimMedTK SDK void SDK::initRegisteredModules() { - - for (int i = 0; i < modulesRef->size(); i++) - if ((*modulesRef)[i].module->getType() != core::ClassType::Viewer) + for(auto &module : this->moduleList) + { + if(module->getType() != core::ClassType::Viewer) { - (*modulesRef)[i].module->init(); + module->init(); } + } } /** \brief Run the registered modules @@ -151,36 +132,33 @@ void SDK::initRegisteredModules() * are already running or no module inherits ViewerBase. * Otherwise, the index of the last viewer module encountered * is returned. + * Note: This function assumes that there is only one viewer. */ -int SDK::runRegisteredModules() +void SDK::runRegisteredModules() { - int viewerIndex = -1; - if (isModulesStarted) { - return viewerIndex; + return; } - for (int i = 0; i < modulesRef->size(); i++) + for(auto &module : this->moduleList) { - auto view = std::dynamic_pointer_cast<ViewerBase>((*modulesRef)[i].module); - if (view) - viewerIndex = i; - else - modules.emplace_back([i]{(*modulesRef)[i].module->exec();}); + auto viewer = std::dynamic_pointer_cast<ViewerBase>(module); + if(!viewer) + { + modules.emplace_back([module]{module->exec();}); + } } isModulesStarted = true; - return viewerIndex; } ///\brief shutdowns all the modules void SDK::shutDown() { - - for (int i = 0; i < modulesRef->size(); i++) + for(auto &module : this->moduleList) { - (*modulesRef)[i].module->terminateExecution = true; + module->terminateExecution = true; } shutdown = true; } @@ -191,19 +169,23 @@ void SDK::run() updateSceneListAll(); initRegisteredModules(); - int viewer = runRegisteredModules(); - // Run the viewer in the main thread: - if (viewer >= 0) - (*modulesRef)[viewer].module->exec(); + runRegisteredModules(); + + this->viewer->exec(); + // Now wait for other modules to shut down - while (!shutdown) { + while (!shutdown) + { std::this_thread::sleep_for(std::chrono::seconds(1)); } - terminateAll(); //Tell framework threads to shutdown - //Wait for all threads to finish processing - for (size_t i = 0; i < modules.size(); ++i) + + // Tell framework threads to shutdown + terminateAll(); + + // Wait for all threads to finish processing + for (auto &module : modules) { - modules[i].join(); + module.join(); } } @@ -249,19 +231,17 @@ std::shared_ptr<SDK> SDK::getInstance() void SDK::terminateAll() { - - for(int i = 0; i < (*modulesRef).size(); i++) + for(auto &module : this->moduleList) { - (*modulesRef)[i].module->terminateExecution = true; + module->terminateExecution = true; } - for(int i = 0; i < (*modulesRef).size(); i++) + for(auto &module : this->moduleList) { bool moduleTerminated = false; - - while(true && !moduleTerminated) + while(!moduleTerminated) { - if((*modulesRef)[i].module->isTerminationDone()) + if(module->isTerminationDone()) { moduleTerminated = true; } @@ -270,56 +250,71 @@ void SDK::terminateAll() } /// \brief register functions -int SDK::registerMesh(std::shared_ptr<BaseMesh> p_mesh) +void SDK::registerMesh(std::shared_ptr<BaseMesh> newMesh) { - MeshHolder mh; - mh.mesh = p_mesh; - return meshesRef->checkAndAdd(mh); + if(std::end(this->meshList) == + std::find(std::begin(this->meshList),std::end(this->meshList),newMesh) ) + { + this->meshList.emplace_back(newMesh); + } } -int SDK::registerModule(std::shared_ptr<Module> p_mod) +void SDK::registerModule(std::shared_ptr<Module> newModule) { - ModuleHolder mh; - mh.module = p_mod; - return modulesRef->checkAndAdd(mh); + if(std::end(this->moduleList) == + std::find(std::begin(this->moduleList),std::end(this->moduleList),newModule) ) + { + this->moduleList.emplace_back(newModule); + } } -void SDK::registerObjectSim(std::shared_ptr<ObjectSimulator> p_os) +void SDK::registerObjectSimulator(std::shared_ptr<ObjectSimulator> newObjectSimulator) { - ObjectSimulatorHolder os; - os.objectSim = p_os; - objectSimulatorsRef->checkAndAdd(os); + if(std::end(this->simulatorList) == + std::find(std::begin(this->simulatorList),std::end(this->simulatorList),newObjectSimulator) ) + { + this->simulatorList.emplace_back(newObjectSimulator); + } } -void SDK::registerCollDet(std::shared_ptr<ObjectSimulator> p_col) +void SDK::registerCollisionDetection(std::shared_ptr<CollisionDetection> newCollisionDetection) { - ObjectSimulatorHolder col; - col.objectSim = p_col; - collisionDetectorsRef->checkAndAdd(col); + if(std::end(this->collisionDetectionList) == + std::find(std::begin(this->collisionDetectionList),std::end(this->collisionDetectionList),newCollisionDetection) ) + { + this->collisionDetectionList.emplace_back(newCollisionDetection); + } } -void SDK::registerScene(std::shared_ptr<Scene> p_sc) +void SDK::registerScene(std::shared_ptr<Scene> newScene) { - SceneHolder sc; - sc.scene = p_sc; - scenesRef->checkAndAdd(sc); + if(std::end(this->sceneList) == + std::find(std::begin(this->sceneList),std::end(this->sceneList),newScene) ) + { + this->sceneList.emplace_back(newScene); + } } -void SDK::registerSceneObject(std::shared_ptr<SceneObject> p_sco) +void SDK::registerSceneObject(std::shared_ptr<SceneObject> newSceneObject) { - SceneObjectHolder sh; - sh.sceneObject = p_sco; - sceneObjectsRef->checkAndAdd(sh); + if(std::end(this->sceneObjectList) == + std::find(std::begin(this->sceneObjectList),std::end(this->sceneObjectList),newSceneObject) ) + { + this->sceneObjectList.emplace_back(newSceneObject); + } } void SDK::addSceneActor(std::shared_ptr<SceneObject> p_sco, std::shared_ptr<ObjectSimulator> p_os, int p_scId) { - assert(p_os); - assert(p_sco); + if(!p_sco || !p_os) + { + std::cerr << "Empty objects" << std::endl; + return; + } p_sco->attachObjectSimulator(p_os); - this->registerObjectSim(p_os); + this->registerObjectSimulator(p_os); this->registerSceneObject(p_sco); diff --git a/Core/SDK.h b/Core/SDK.h index ec00bd1aee8d5f17ff5f0aadff64df19292f3cea..53406d0114babe974bee7c2264bf114b314b353e 100644 --- a/Core/SDK.h +++ b/Core/SDK.h @@ -44,122 +44,9 @@ template<typename T> class IndiceArray; class Scene; - -/// \brief mesh holder -struct MeshHolder -{ - - MeshHolder() - { - mesh = NULL; - } - - std::shared_ptr<BaseMesh> mesh; - - inline bool operator ==(MeshHolder &p_param) - { - return mesh == p_param.mesh; - } -}; - -/// \brief module holder -struct ModuleHolder -{ - - ModuleHolder() - { - module = NULL; - } - - std::shared_ptr<Module> module; - - inline bool operator ==(ModuleHolder &p_param) - { - return module == p_param.module; - } -}; - -/// \brief simulator holder -struct ObjectSimulatorHolder -{ - - ObjectSimulatorHolder() - { - objectSim = NULL; - } - - std::shared_ptr<ObjectSimulator> objectSim; - - inline bool operator ==(ObjectSimulatorHolder &p_param) - { - return objectSim == p_param.objectSim; - } -}; - -/// \brief scene holders -struct SceneHolder -{ - SceneHolder() - { - scene = NULL; - } - - std::shared_ptr<Scene> scene; - inline bool operator ==(SceneHolder &p_param) - { - return scene == p_param.scene; - } - -}; - -/// \brief scene object holder -struct SceneObjectHolder -{ - - SceneObjectHolder() - { - sceneObject = NULL; - } - - std::shared_ptr<SceneObject> sceneObject; - inline bool operator ==(SceneObjectHolder &p_param) - { - return sceneObject == p_param.sceneObject; - } - -}; - - /// \brief SDK class. it is a singlenton class for each machine runs the framework class SDK: public CoreClass { -private: - static std::once_flag sdkCallOnceFlag; - - bool shutdown; ///< Tells the SDK to terminate - int sceneIdCounter; ///< this id is incremented when a scene is created - int argc; - char argv; - bool isModulesStarted; - - std::shared_ptr<ErrorLog> errorLog; ///< error log - std::shared_ptr<ViewerBase> viewer; ///< Reference to the sdk viewer object - std::shared_ptr<Simulator> simulator; ///< Reference to the sdk simulator object - std::vector<std::shared_ptr<Scene>> sceneList; ///< scene list - - ///holds the references to the entities in the framework - static IndiceArray<MeshHolder> *meshesRef; - static IndiceArray<ModuleHolder> *modulesRef; - static IndiceArray<ObjectSimulatorHolder> *objectSimulatorsRef; - static IndiceArray<ObjectSimulatorHolder> *collisionDetectorsRef; - static IndiceArray<SceneHolder> *scenesRef; - static IndiceArray<SceneObjectHolder> *sceneObjectsRef; - - std::vector<std::thread> modules; ///< Stores a list of running module threads - - /// \brief constructor - SDK(); - public: /// \brief destructor ~SDK(); @@ -168,7 +55,7 @@ public: void updateSceneListAll(); void initRegisteredModules(); - int runRegisteredModules(); + void runRegisteredModules(); void shutDown(); ///for now both functions below are the same. But it maybe subject to change. @@ -202,7 +89,7 @@ public: ///SDK creates scene std::shared_ptr<Scene> getScene(size_t sceneId) { - return scenesRef->getByRef(sceneId).scene; + return sceneList.at(sceneId); } ///SDK returns logger for the system @@ -214,6 +101,9 @@ public: ///release the scene from the SDK..not implemented yet void releaseScene(std::shared_ptr<Scene> scene); + /// Prevent use of assignament operator + SDK &operator=(const SDK&) = delete; + /// \brief run the SDK void run(); @@ -224,19 +114,45 @@ public: void removeRef(std::shared_ptr<CoreClass> p_coreClass); /// \brief register functions - int registerMesh(std::shared_ptr<BaseMesh> p_mesh); + void registerMesh(std::shared_ptr<BaseMesh> p_mesh); - int registerModule(std::shared_ptr<Module> p_mod); + void registerModule(std::shared_ptr<Module> p_mod); - void registerObjectSim(std::shared_ptr<ObjectSimulator> p_os); + void registerObjectSimulator(std::shared_ptr<ObjectSimulator> p_os); - void registerCollDet(std::shared_ptr<ObjectSimulator> p_col); + void registerCollisionDetection(std::shared_ptr<CollisionDetection> p_col); void registerScene(std::shared_ptr<Scene> p_sc); void registerSceneObject(std::shared_ptr<SceneObject> p_sco); void addSceneActor(std::shared_ptr<SceneObject> p_sco, std::shared_ptr<ObjectSimulator> p_os, int p_scId=0); + +private: + static std::once_flag sdkCallOnceFlag; + + bool shutdown; ///< Tells the SDK to terminate + int sceneIdCounter; ///< this id is incremented when a scene is created + int argc; + char argv; + bool isModulesStarted; + + std::shared_ptr<ErrorLog> errorLog; ///< error log + std::shared_ptr<ViewerBase> viewer; ///< Reference to the sdk viewer object + std::shared_ptr<Simulator> simulator; ///< Reference to the sdk simulator object + + ///holds the references to the entities in the framework + std::vector<std::shared_ptr<BaseMesh>> meshList; + std::vector<std::shared_ptr<Module>> moduleList; + std::vector<std::shared_ptr<ObjectSimulator>> simulatorList; + std::vector<std::shared_ptr<CollisionDetection>> collisionDetectionList; + std::vector<std::shared_ptr<Scene>> sceneList; ///< scene list + std::vector<std::shared_ptr<SceneObject>> sceneObjectList; + + std::vector<std::thread> modules; ///< Stores a list of running module threads +private: + /// \brief constructor + SDK(); }; #endif diff --git a/Examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp b/Examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp index 4a843793724195ce1548132057e4c03ac64503ba..e39bd22e75caabbaedc3df31bfb465a5dcf054f2 100644 --- a/Examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp +++ b/Examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp @@ -54,7 +54,7 @@ CollisionDetectionBVH::CollisionDetectionBVH() // Create dummy simulator defaultSimulator = std::make_shared<DummySimulator>(sdk->getErrorLog()); - sdk->registerObjectSim(defaultSimulator); + sdk->registerObjectSimulator(defaultSimulator); // Init texture manager and specify the textures needed for the current application TextureManager::init(sdk->getErrorLog()); diff --git a/Examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp b/Examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp index 9a6e60e8eeec6fc8db30b6d6715f22ef755e3991..c18c50207c5e4d8a6432ac74fbbe8569766782dc 100644 --- a/Examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp +++ b/Examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp @@ -56,7 +56,7 @@ CollisionDetectionSpatialHashing::CollisionDetectionSpatialHashing() // Create dummy simulator defaultSimulator = std::make_shared<DummySimulator>(sdk->getErrorLog()); - sdk->registerObjectSim(defaultSimulator); + sdk->registerObjectSimulator(defaultSimulator); // Init texture manager and specify the textures needed for the current application TextureManager::init(sdk->getErrorLog()); diff --git a/Simulators/VegaFemSimulator.cpp b/Simulators/VegaFemSimulator.cpp index 93f2c481eee2790adf31aedd528fded427feeb24..da4579bbd36962beaa6ad97bf31e24745a278f49 100644 --- a/Simulators/VegaFemSimulator.cpp +++ b/Simulators/VegaFemSimulator.cpp @@ -39,7 +39,7 @@ void VegaFemSimulator::initCustom() { auto object = objectsSimulated[i]; - switch ( type ) + switch ( object->getType() ) { case core::ClassType::VegaFemSceneObject: { diff --git a/VirtualTools/CurvedGrasper.h b/VirtualTools/CurvedGrasper.h index f94f82e05507c337eb25bfde84e4b16eede066ef..59397ce3b342a067d31e536c636f51093bf46e67 100644 --- a/VirtualTools/CurvedGrasper.h +++ b/VirtualTools/CurvedGrasper.h @@ -59,9 +59,7 @@ public: SurfaceMesh *mesh_pivot; // stores the pivot mesh SurfaceMesh *mesh_lowerJaw; // stores lower jaw mesh SurfaceMesh *mesh_upperJaw; // stores upper mesh jaw -#ifdef smNIUSB6008DAQ - smPipeRegisteration NIUSB6008pipeReg; // -#endif + core::Vec3d godPos; // god object position double godMat[9]; // god object matrix int DAQdataID; // interface for DAQ