+//=======================================================================
+//function : ClearEntry
+//=======================================================================
+void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) {
+ TSizeMap::iterator it = _sizeMap.find(entry);
+ if (it != _sizeMap.end()) {
+ _sizeMap.erase(it);
+ NotifySubMeshesHypothesisModification();
+ } else {
+ TSizeMap::iterator itAt = _attractors.find(entry);
+ if (itAt != _attractors.end()) {
+ _attractors.erase(itAt);
+ NotifySubMeshesHypothesisModification();
+ } else
+ std::cout << "No_Such_Entry" << std::endl;
+ }
+}
+
+//=======================================================================
+//function : ClearSizeMaps
+//=======================================================================
+void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
+ _sizeMap.clear();
+ _attractors.clear();
+}
+
+//=======================================================================
+//function : SetEnforcedVertex
+//=======================================================================
+bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
+ TEnfGroupName theGroupName, double x, double y, double z) {
+
+ MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
+ << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
+
+ // TEnfVertexList::iterator it;
+ bool toNotify = false;
+ bool toCreate = true;
+
+ TEnfVertex *oldEnVertex;
+ TEnfVertex *newEnfVertex = new TEnfVertex();
+ newEnfVertex->name = theVertexName;
+ newEnfVertex->geomEntry = theVertexEntry;
+ newEnfVertex->coords.clear();
+ if (theVertexEntry == "") {
+ newEnfVertex->coords.push_back(x);
+ newEnfVertex->coords.push_back(y);
+ newEnfVertex->coords.push_back(z);
+ }
+ newEnfVertex->grpName = theGroupName;
+ newEnfVertex->faceEntries.clear();
+ newEnfVertex->faceEntries.insert(theFaceEntry);
+
+
+ // update _enfVertexList
+ TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
+ if (it != _enfVertexList.end()) {
+ toCreate = false;
+ oldEnVertex = (*it);
+ MESSAGE("Enforced Vertex was found => Update");
+ if (oldEnVertex->name != theVertexName) {
+ MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
+ oldEnVertex->name = theVertexName;
+ toNotify = true;
+ }
+ if (oldEnVertex->grpName != theGroupName) {
+ MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
+ oldEnVertex->grpName = theGroupName;
+ toNotify = true;
+ }
+ TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
+ if (it_faceEntries == oldEnVertex->faceEntries.end()) {
+ MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
+ oldEnVertex->faceEntries.insert(theFaceEntry);
+ _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
+ toNotify = true;
+ }
+ if (toNotify) {
+ // update map coords / enf vertex if needed
+ if (oldEnVertex->coords.size()) {
+ _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
+ _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
+ }
+
+ // update map geom entry / enf vertex if needed
+ if (oldEnVertex->geomEntry != "") {
+ _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
+ _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
+ }
+ }
+ }
+
+// //////// CREATE ////////////
+ if (toCreate) {
+ toNotify = true;
+ MESSAGE("Creating new enforced vertex");
+ _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
+ _enfVertexList.insert(newEnfVertex);
+ if (theVertexEntry == "") {
+ _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
+ _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
+ }
+ else {
+ _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
+ _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
+ }
+ }
+
+ if (toNotify)
+ NotifySubMeshesHypothesisModification();
+
+ MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
+ return toNotify;
+}
+
+
+//=======================================================================
+//function : GetEnforcedVertices
+//=======================================================================
+
+BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
+ throw (std::invalid_argument) {
+
+ if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
+ return _faceEntryEnfVertexListMap[theFaceEntry];
+ else
+ return GetDefaultEnfVertexList();
+
+ std::ostringstream msg;
+ msg << "No enforced vertex for face entry " << theFaceEntry;
+ throw std::invalid_argument(msg.str());
+}
+
+//=======================================================================
+//function : GetEnfVertexCoordsList
+//=======================================================================
+
+BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
+ const TEntry& theFaceEntry) throw (std::invalid_argument) {
+
+ if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
+ return _faceEntryCoordsListMap[theFaceEntry];
+
+ std::ostringstream msg;
+ msg << "No enforced vertex coords for face entry " << theFaceEntry;
+ throw std::invalid_argument(msg.str());
+}
+
+//=======================================================================
+//function : GetEnfVertexEntryList
+//=======================================================================
+
+BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
+ throw (std::invalid_argument) {
+
+ if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
+ return _faceEntryEnfVertexEntryListMap[theFaceEntry];
+
+ std::ostringstream msg;
+ msg << "No enforced vertex entry for face entry " << theFaceEntry;
+ throw std::invalid_argument(msg.str());
+}
+
+//=======================================================================
+//function : GetEnfVertex(TEnfVertexCoords coords)
+//=======================================================================
+
+BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
+ throw (std::invalid_argument) {
+
+ if (_coordsEnfVertexMap.count(coords) > 0)
+ return _coordsEnfVertexMap[coords];
+
+ std::ostringstream msg;
+ msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
+ throw std::invalid_argument(msg.str());
+}
+
+//=======================================================================
+//function : GetEnfVertex(const TEntry& theEnfVertexEntry)
+//=======================================================================
+
+BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
+ throw (std::invalid_argument) {
+
+ if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
+ return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
+
+ std::ostringstream msg;
+ msg << "No enforced vertex with entry " << theEnfVertexEntry;
+ throw std::invalid_argument(msg.str());
+}
+
+//=======================================================================
+//function : ClearEnforcedVertex
+//=======================================================================
+
+bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
+ const TEntry& theVertexEntry) throw (std::invalid_argument) {
+
+ bool toNotify = false;
+ std::ostringstream msg;
+ TEnfVertex *oldEnfVertex;
+ TEnfVertexCoords coords;
+ coords.clear();
+ coords.push_back(x);
+ coords.push_back(y);
+ coords.push_back(z);
+
+ // check that enf vertex with given enf vertex entry exists
+ TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
+ if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
+ // Success
+ MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
+ oldEnfVertex = it_enfVertexEntry->second;
+
+ _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
+
+ TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
+ enfVertexEntryList.erase(theVertexEntry);
+ if (enfVertexEntryList.size() == 0)
+ _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
+ // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
+ // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
+ // it_entry_entry->second.erase(it_entryList);
+ // if (it_entry_entry->second.size() == 0)
+ // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
+ } else {
+ // Fail
+ MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
+ msg << "No enforced vertex with geom entry " << theVertexEntry;
+ // check that enf vertex with given coords exists
+ TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
+ if (it_coords_enf != _coordsEnfVertexMap.end()) {
+ // Success
+ MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
+ oldEnfVertex = it_coords_enf->second;
+
+ _coordsEnfVertexMap.erase(it_coords_enf);
+
+ TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
+ enfVertexCoordsList.erase(coords);
+ if (enfVertexCoordsList.size() == 0)
+ _faceEntryCoordsListMap.erase(theFaceEntry);
+ // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
+ // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
+ // it_entry_coords->second.erase(it_coordsList);
+ // if (it_entry_coords->second.size() == 0)
+ // _faceEntryCoordsListMap.erase(it_entry_coords);
+ } else {
+ // Fail
+ MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
+ msg << std::endl;
+ msg << "No enforced vertex at " << x << ", " << y << ", " << z;
+ throw std::invalid_argument(msg.str());
+ }
+ }
+
+ MESSAGE("Remove enf vertex from _enfVertexList");
+
+ // update _enfVertexList
+ TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
+ if (it != _enfVertexList.end()) {
+ (*it)->faceEntries.erase(theFaceEntry);
+ if ((*it)->faceEntries.size() == 0){
+ _enfVertexList.erase(it);
+ toNotify = true;
+ }
+ MESSAGE("Done");
+ }
+
+ // update _faceEntryEnfVertexListMap
+ TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
+ currentEnfVertexList.erase(oldEnfVertex);
+
+ if (currentEnfVertexList.size() == 0) {
+ MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
+ _faceEntryEnfVertexListMap.erase(theFaceEntry);
+ MESSAGE("Done");
+ }
+
+ if (toNotify)
+ NotifySubMeshesHypothesisModification();
+
+ return toNotify;
+}
+
+//=======================================================================
+//function : ClearEnforcedVertices
+//=======================================================================
+
+bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
+
+ bool toNotify = false;
+ TEnfVertex *oldEnfVertex;
+
+ TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
+ if (it_entry_coords != _faceEntryCoordsListMap.end()) {
+ toNotify = true;
+ TEnfVertexCoordsList coordsList = it_entry_coords->second;
+ TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
+ for (; it_coordsList != coordsList.end(); ++it_coordsList) {
+ TEnfVertexCoords coords = (*it_coordsList);
+ oldEnfVertex = _coordsEnfVertexMap[coords];
+ _coordsEnfVertexMap.erase(coords);
+ // update _enfVertexList
+ TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
+ if (it != _enfVertexList.end()) {
+ (*it)->faceEntries.erase(theFaceEntry);
+ if ((*it)->faceEntries.size() == 0){
+ _enfVertexList.erase(it);
+ toNotify = true;
+ }
+ MESSAGE("Done");
+ }
+ }
+ _faceEntryCoordsListMap.erase(it_entry_coords);
+ _faceEntryEnfVertexListMap.erase(theFaceEntry);
+ }
+
+ TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
+ if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
+ toNotify = true;
+ TEntryList enfVertexEntryList = it_entry_entry->second;
+ TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
+ for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
+ TEntry enfVertexEntry = (*it_enfVertexEntryList);
+ oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
+ _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
+ // update _enfVertexList
+ TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
+ if (it != _enfVertexList.end()) {
+ (*it)->faceEntries.erase(theFaceEntry);
+ if ((*it)->faceEntries.size() == 0){
+ _enfVertexList.erase(it);
+ toNotify = true;
+ }
+ MESSAGE("Done");
+ }
+ }
+ _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
+ _faceEntryEnfVertexListMap.erase(theFaceEntry);
+ }
+
+ if (toNotify)
+ NotifySubMeshesHypothesisModification();
+
+ return toNotify;
+ // std::ostringstream msg;
+ // msg << "No enforced vertex for " << theFaceEntry;
+ // throw std::invalid_argument(msg.str());
+}
+
+//=======================================================================
+//function : ClearAllEnforcedVertices
+//=======================================================================
+void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
+ _faceEntryEnfVertexListMap.clear();
+ _enfVertexList.clear();
+ _faceEntryCoordsListMap.clear();
+ _coordsEnfVertexMap.clear();
+ _faceEntryEnfVertexEntryListMap.clear();
+ _enfVertexEntryEnfVertexMap.clear();
+ NotifySubMeshesHypothesisModification();
+}
+
+//================================================================================