3D Repo Bouncer  1.4
repo_scene.h
1 
22 #pragma once
23 
24 #include <unordered_map>
25 
26 #include "../../handler/repo_database_handler_abstract.h"
27 #include "../bson/repo_node.h"
28 #include "../bson/repo_node_revision.h"
29 #include "repo_graph_abstract.h"
30 
31 typedef std::unordered_map<repoUUID, std::vector<repo::core::model::RepoNode*>, RepoUUIDHasher > ParentMap;
32 
33 namespace repo{
34  namespace core{
35  namespace model{
37  {
38  std::size_t operator()(const repoUUID& uid) const
39  {
40  return boost::hash<boost::uuids::uuid>()(uid);
41  }
42  };
43 
44  class REPO_API_EXPORT RepoScene : public AbstractGraph
45  {
46  //FIXME: unsure as to whether i should make the graph a differen class.. struct for now.
47  struct repoGraphInstance
48  {
49  RepoNodeSet cameras;
50  RepoNodeSet meshes;
51  RepoNodeSet materials;
52  RepoNodeSet maps;
53  RepoNodeSet metadata;
54  RepoNodeSet references;
55  RepoNodeSet textures;
56  RepoNodeSet transformations;
57  RepoNodeSet unknowns;
58 
59  RepoNode *rootNode;
61  std::unordered_map<repoUUID, RepoNode*, RepoUUIDHasher > nodesByUniqueID;
62  std::unordered_map<repoUUID, repoUUID, RepoUUIDHasher > sharedIDtoUniqueID; //** mapping of shared ID to Unique ID
63  ParentMap parentToChildren; //** mapping of shared id to its children's shared id
64  std::unordered_map<repoUUID, RepoScene*, RepoUUIDHasher > referenceToScene; //** mapping of reference ID to it's scene graph
65  };
66 
67  static const std::vector<std::string> collectionsInProject;
68  static const uint16_t REPO_SCENE_TEXTURE_BIT = 0x0001;
69  public:
70 
75  enum class GraphType { DEFAULT, OPTIMIZED };
76 
92  RepoScene(
93  const std::string &database = std::string(),
94  const std::string &projectName = std::string(),
95  const std::string &sceneExt = REPO_COLLECTION_SCENE,
96  const std::string &revExt = REPO_COLLECTION_HISTORY,
97  const std::string &stashExt = REPO_COLLECTION_STASH_REPO,
98  const std::string &rawExt = REPO_COLLECTION_RAW,
99  const std::string &issuesExt = REPO_COLLECTION_ISSUES,
100  const std::string &srcExt = REPO_COLLECTION_STASH_SRC,
101  const std::string &gltfExt = REPO_COLLECTION_STASH_GLTF,
102  const std::string &x3dExt = REPO_COLLECTION_STASH_X3D,
103  const std::string &jsonExt = REPO_COLLECTION_STASH_JSON);
104 
126  RepoScene(
127  const std::vector<std::string> &refFiles,
128  const RepoNodeSet &cameras,
129  const RepoNodeSet &meshes,
130  const RepoNodeSet &materials,
131  const RepoNodeSet &metadata,
132  const RepoNodeSet &textures,
133  const RepoNodeSet &transformations,
134  const RepoNodeSet &references = RepoNodeSet(),
135  const RepoNodeSet &maps = RepoNodeSet(),
136  const RepoNodeSet &unknowns = RepoNodeSet(),
137  const std::string &sceneExt = REPO_COLLECTION_SCENE,
138  const std::string &revExt = REPO_COLLECTION_HISTORY,
139  const std::string &stashExt = REPO_COLLECTION_STASH_REPO,
140  const std::string &rawExt = REPO_COLLECTION_RAW,
141  const std::string &issuesExt = REPO_COLLECTION_ISSUES,
142  const std::string &srcExt = REPO_COLLECTION_STASH_SRC,
143  const std::string &gltfExt = REPO_COLLECTION_STASH_GLTF,
144  const std::string &x3dExt = REPO_COLLECTION_STASH_X3D,
145  const std::string &jsonExt = REPO_COLLECTION_STASH_JSON);
146 
153  ~RepoScene();
154 
155  static std::vector<RepoNode*> filterNodesByType(
156  const std::vector<RepoNode*> nodes,
157  const NodeType filter);
158 
163  bool isOK() const{
164  return !status;
165  }
166 
171  bool isMissingTexture() const{
172  return status & REPO_SCENE_TEXTURE_BIT;
173  }
178  status |= REPO_SCENE_TEXTURE_BIT;
179  }
180 
187  void addMetadata(
188  RepoNodeSet &metadata,
189  const bool &exactMatch,
190  const bool &propagateData = true);
191 
200  void addStashGraph(
201  const RepoNodeSet &cameras,
202  const RepoNodeSet &meshes,
203  const RepoNodeSet &materials,
204  const RepoNodeSet &textures,
205  const RepoNodeSet &transformations);
206 
210  void clearStash();
211 
222  bool commit(
224  std::string &errMsg,
225  const std::string &userName,
226  const std::string &message = std::string(),
227  const std::string &tag = std::string());
228 
236  bool commitStash(
238  std::string &errMsg);
239 
244  repoUUID getBranchID() const
245  {
246  return branch;
247  }
248 
253  std::string getDatabaseName() const
254  {
255  return databaseName;
256  }
257 
262  std::string getStashExtension() const
263  {
264  return stashExt;
265  }
266 
271  std::string getRawExtension() const
272  {
273  return rawExt;
274  }
275 
280  std::string getSRCExtension() const
281  {
282  return srcExt;
283  }
284 
289  std::string getGLTFExtension() const
290  {
291  return gltfExt;
292  }
293 
298  std::string getX3DExtension() const
299  {
300  return x3dExt;
301  }
302 
307  std::string getJSONExtension() const
308  {
309  return jsonExt;
310  }
311 
316  repoUUID getRevisionID() const
317  {
318  if (revNode)
319  return revNode->getUniqueID();
320  else
321  return revision;
322  }
323 
330  std::string getOwner() const
331  {
332  if (revNode)
333  return revNode->getAuthor();
334  else
335  return "";
336  }
337 
338  static std::vector<std::string> getProjectExtensions()
339  {
340  return collectionsInProject;
341  }
342 
347  std::string getProjectName() const
348  {
349  return projectName;
350  }
351 
356  std::vector<double> getWorldOffset() const
357  {
358  return worldOffset.size() ? worldOffset : std::vector<double>({ 0, 0, 0 });
359  }
360 
365  bool isHeadRevision() const
366  {
367  return headRevision;
368  }
369 
374  bool isRevisioned() const
375  {
376  return !unRevisioned;
377  }
378 
384  void setDatabaseAndProjectName(std::string newDatabaseName, std::string newProjectName)
385  {
386  databaseName = sanitizeName(newDatabaseName);
387  projectName = sanitizeName(newProjectName);
388  }
389 
394  void setRevision(repoUUID revisionID)
395  {
396  headRevision = false;
397  revision = revisionID;
398  }
399 
404  void setBranch(repoUUID branchID){ branch = branchID; }
405 
410  void setCommitMessage(const std::string &msg) { commitMsg = msg; }
411 
418  void setWorldOffset(
419  const std::vector<double> &offset);
420 
426  std::string getBranchName() const;
427 
434  {
435  if (stashGraph.rootNode)
436  return GraphType::OPTIMIZED;
437  else
438  return GraphType::DEFAULT;
439  }
440 
449  bool loadRevision(
451  std::string &errMsg);
452 
460  bool loadScene(
462  std::string &errMsg);
463 
470  bool loadStash(
472  std::string &errMsg);
473 
480  void updateRevisionStatus(
482  const RevisionNode::UploadStatus &status);
483 
490  void printStatistics(std::iostream &output);
491 
504  const GraphType &gType,
505  const repoUUID &parent,
506  const repoUUID &child,
507  const bool &modifyParent = true,
508  const bool &modifyChild = true)
509  {
510  return abandonChild(gType, parent, getNodeBySharedID(gType, child), modifyParent, modifyChild);
511  }
512 
519  void abandonChild(
520  const GraphType &gType,
521  const repoUUID &parent,
522  RepoNode *child,
523  const bool &modifyParent = true,
524  const bool &modifyChild = true);
525 
537  const GraphType &gType,
538  const repoUUID &parent,
539  const repoUUID &child,
540  const bool &noUpdate = false)
541  {
542  addInheritance(gType, getNodeByUniqueID(gType, parent), getNodeByUniqueID(gType, child), noUpdate);
543  }
544 
555  void addInheritance(
556  const GraphType &gType,
557  const RepoNode *parent,
558  RepoNode *child,
559  const bool &noUpdate = false);
560 
567  std::vector<RepoNode*>
568  getChildrenAsNodes(
569  const GraphType &g,
570  const repoUUID &parent) const;
571 
579  std::vector<RepoNode*>
580  getChildrenNodesFiltered(
581  const GraphType &g,
582  const repoUUID &parent,
583  const NodeType &type) const;
584 
592  std::vector<RepoNode*> getParentNodesFiltered(
593  const GraphType &gType,
594  const RepoNode *node,
595  const NodeType &type) const;
596 
601  const GraphType &gType,
602  const repoUUID &reference) const
603  {
604  const repoGraphInstance &g = gType == GraphType::OPTIMIZED ? stashGraph : graph;
605  RepoScene* refScene = nullptr;
606 
607  std::unordered_map<repoUUID, RepoScene*, boost::hash<boost::uuids::uuid> >::const_iterator it = g.referenceToScene.find(reference);
608  if (it != g.referenceToScene.end())
609  refScene = it->second;
610  return refScene;
611  }
612 
620  std::string getTextureIDForMesh(
621  const GraphType &gType,
622  const repoUUID &sharedID) const;
623 
632  RepoNodeSet getAllCameras(
633  const GraphType &gType) const
634  {
635  return gType == GraphType::OPTIMIZED ? stashGraph.cameras : graph.cameras;
636  }
637 
642  RepoNodeSet getAllMaterials(
643  const GraphType &gType) const
644  {
645  return gType == GraphType::OPTIMIZED ? stashGraph.materials : graph.materials;
646  }
647 
652  RepoNodeSet getAllMaps(
653  const GraphType &gType = GraphType::DEFAULT) const
654  {
655  return gType == GraphType::OPTIMIZED ? stashGraph.maps : graph.maps;
656  }
657 
662  RepoNodeSet getAllMeshes(
663  const GraphType &gType) const
664  {
665  return gType == GraphType::OPTIMIZED ? stashGraph.meshes : graph.meshes;
666  }
667 
672  RepoNodeSet getAllMetadata(
673  const GraphType &gType) const
674  {
675  return gType == GraphType::OPTIMIZED ? stashGraph.metadata : graph.metadata;
676  }
677 
682  RepoNodeSet getAllReferences(
683  const GraphType &gType) const
684  {
685  return gType == GraphType::OPTIMIZED ? stashGraph.references : graph.references;
686  }
687 
692  RepoNodeSet getAllTextures(
693  const GraphType &gType) const
694  {
695  return gType == GraphType::OPTIMIZED ? stashGraph.textures : graph.textures;
696  }
697 
703  const GraphType &gType) const
704  {
705  return gType == GraphType::OPTIMIZED ? stashGraph.transformations : graph.transformations;
706  }
707 
712  std::vector<repoUUID> getAddedNodesID() const
713  {
714  return std::vector<repoUUID>(newAdded.begin(), newAdded.end());
715  }
716 
717  std::set<repoUUID> getAllSharedIDs(
718  const GraphType &gType) const;
719 
726  std::vector<RepoNode*> getAllDescendantsByType(
727  const GraphType &gType,
728  const repoUUID &sharedID,
729  const NodeType &type) const;
730 
735  std::vector<repoUUID> getModifiedNodesID() const
736  {
737  return std::vector<repoUUID>(newModified.begin(), newModified.end());
738  }
739 
744  std::vector<repoUUID> getRemovedNodesID() const
745  {
746  return std::vector<repoUUID>(newRemoved.begin(), newRemoved.end());
747  }
748 
753  std::vector<RepoNode*> getRemovedNodes() const
754  {
755  return toRemove;
756  }
757 
762  std::vector<repo_vector_t> getSceneBoundingBox() const;
763 
764  size_t getTotalNodesChanged() const
765  {
766  return newRemoved.size() + newAdded.size() + newModified.size();
767  }
768 
776  const GraphType &gType,
777  const repoUUID &sharedID) const
778  {
779  const repoGraphInstance &g = gType == GraphType::OPTIMIZED ? stashGraph : graph;
780  auto it = g.sharedIDtoUniqueID.find(sharedID);
781 
782  if (it == g.sharedIDtoUniqueID.end()) return nullptr;
783 
784  return getNodeByUniqueID(gType, it->second);
785  }
786 
794  const GraphType &gType,
795  const repoUUID &uniqueID) const
796  {
797  const repoGraphInstance &g = gType == GraphType::OPTIMIZED ? stashGraph : graph;
798  auto it = g.nodesByUniqueID.find(uniqueID);
799 
800  if (it == g.nodesByUniqueID.end()) return nullptr;
801 
802  return it->second;
803  }
804 
809  bool hasRoot(const GraphType &gType) const {
810  const repoGraphInstance &g = gType == GraphType::OPTIMIZED ? stashGraph : graph;
811  return (bool)g.rootNode;
812  }
813  RepoNode* getRoot(const GraphType &gType) const {
814  const repoGraphInstance &g = gType == GraphType::OPTIMIZED ? stashGraph : graph;
815  return g.rootNode;
816  }
817 
823  uint32_t getItemsInCurrentGraph(const GraphType &gType) {
824  const repoGraphInstance &g = gType == GraphType::OPTIMIZED ? stashGraph : graph;
825  return g.nodesByUniqueID.size();
826  }
827 
832  std::vector<std::string> getOriginalFiles() const;
833 
843  void addNodes(const std::vector<RepoNode *> &nodes);
844 
856  const GraphType &gtype,
857  const repoUUID &sharedID,
858  RepoNode *newNode,
859  const bool &overwrite = false)
860  {
861  modifyNode(gtype, getNodeBySharedID(gtype, sharedID), newNode, overwrite);
862  }
863 
875  void modifyNode(
876  const GraphType &gtype,
877  RepoNode *node,
878  RepoNode *newNode,
879  const bool &overwrite = false);
880 
890  void removeNode(
891  const GraphType &gtype,
892  const repoUUID &sharedID);
893 
898  void reorientateDirectXModel();
899 
904  protected:
913  bool addNodeToScene(
914  const GraphType &gType,
915  const RepoNodeSet nodes,
916  std::string &errMsg,
917  RepoNodeSet *collection);
918 
928  bool addNodeToMaps(
929  const GraphType &gType,
930  RepoNode *node,
931  std::string &errMsg);
932 
941  bool commitNodes(
943  const std::vector<repoUUID> &nodesToCommit,
944  const GraphType &gType,
945  std::string &errMsg);
946 
954  bool commitProjectSettings(
956  std::string &errMsg,
957  const std::string &userName);
958 
969  bool commitRevisionNode(
971  std::string &errMsg,
972  RevisionNode *&newRevNode,
973  const std::string &userName,
974  const std::string &message,
975  const std::string &tag);
976 
983  bool commitSceneChanges(
985  std::string &errMsg);
986 
994  void getSceneBoundingBoxInternal(
995  const GraphType &gType,
996  const RepoNode *node,
997  const std::vector<float> &mat,
998  std::vector<repo_vector_t> &bbox) const;
999 
1008  bool populate(
1009  const GraphType &gtype,
1011  std::vector<RepoBSON> nodes,
1012  std::string &errMsg);
1013 
1027  void populateAndUpdate(
1028  const GraphType &gType,
1029  const RepoNodeSet &cameras,
1030  const RepoNodeSet &meshes,
1031  const RepoNodeSet &materials,
1032  const RepoNodeSet &metadata,
1033  const RepoNodeSet &textures,
1034  const RepoNodeSet &transformations,
1035  const RepoNodeSet &references,
1036  const RepoNodeSet &maps,
1037  const RepoNodeSet &unknowns);
1038 
1044  void shiftModel(
1045  const std::vector<double> &offset);
1046 
1047  /*
1048  * ---------------- Scene Graph settings ----------------
1049  */
1050 
1051  std::string sceneExt;
1052  std::string revExt;
1053  std::string stashExt;
1054  std::string rawExt;
1055  std::string issuesExt;
1056  std::string srcExt;
1057  std::string gltfExt;
1058  std::string x3dExt;
1059  std::string jsonExt;
1060  std::vector<std::string> refFiles; //Original Files that created this scene
1061  std::vector<RepoNode*> toRemove;
1062  std::vector<double> worldOffset;
1063  repoUUID revision;
1064  repoUUID branch;
1065  std::string commitMsg;
1066  bool headRevision;
1067  bool unRevisioned;
1070 
1071  /*
1072  * ---------------- Scene Graph Details ----------------
1073  */
1074 
1075  //Change trackers
1076  std::set<repoUUID> newCurrent; //new list of current (unique IDs)
1077  std::set<repoUUID> newAdded; //list of nodes added to the new revision (shared ID)
1078  std::set<repoUUID> newRemoved; //list of nodes removed for this revision (shared ID)
1079  std::set<repoUUID> newModified; // list of nodes modified during this revision (shared ID)
1080 
1081  repoGraphInstance graph; //current state of the graph, given the branch/revision
1082  repoGraphInstance stashGraph; //current state of the optimized graph, given the branch/revision
1083  uint16_t status; //health of the scene, 0 denotes healthy
1084  };
1085  }//namespace graph
1086  }//namespace manipulator
1087 }//namespace repo
RevisionNode * revNode
Definition: repo_scene.h:1069
bool hasRoot(const GraphType &gType) const
Definition: repo_scene.h:809
uint32_t getItemsInCurrentGraph(const GraphType &gType)
Definition: repo_scene.h:823
Definition: repo_node_revision.h:49
std::string issuesExt
Definition: repo_scene.h:1055
void setBranch(repoUUID branchID)
Definition: repo_scene.h:404
std::string getDatabaseName() const
Definition: repo_scene.h:253
void abandonChild(const GraphType &gType, const repoUUID &parent, const repoUUID &child, const bool &modifyParent=true, const bool &modifyChild=true)
Definition: repo_scene.h:503
std::string stashExt
Definition: repo_scene.h:1053
RepoNodeSet getAllMeshes(const GraphType &gType) const
Definition: repo_scene.h:662
repoUUID getBranchID() const
Definition: repo_scene.h:244
RepoScene * getSceneFromReference(const GraphType &gType, const repoUUID &reference) const
Definition: repo_scene.h:600
bool isRevisioned() const
Definition: repo_scene.h:374
bool isHeadRevision() const
Definition: repo_scene.h:365
Definition: repo_connection_pool_mongo.h:32
void setMissingTexture()
Definition: repo_scene.h:177
std::string getX3DExtension() const
Definition: repo_scene.h:298
RepoNodeSet getAllTransformations(const GraphType &gType) const
Definition: repo_scene.h:702
std::string jsonExt
Definition: repo_scene.h:1059
void setCommitMessage(const std::string &msg)
Definition: repo_scene.h:410
RepoNodeSet getAllCameras(const GraphType &gType) const
Definition: repo_scene.h:632
RepoNodeSet getAllTextures(const GraphType &gType) const
Definition: repo_scene.h:692
RepoNodeSet getAllReferences(const GraphType &gType) const
Definition: repo_scene.h:682
Definition: repo_scene.h:44
Definition: repo_database_handler_abstract.h:37
std::vector< repoUUID > getRemovedNodesID() const
Definition: repo_scene.h:744
RepoNodeSet getAllMaps(const GraphType &gType=GraphType::DEFAULT) const
Definition: repo_scene.h:652
std::string getSRCExtension() const
Definition: repo_scene.h:280
RepoNode * getNodeBySharedID(const GraphType &gType, const repoUUID &sharedID) const
Definition: repo_scene.h:775
std::string getStashExtension() const
Definition: repo_scene.h:262
void setDatabaseAndProjectName(std::string newDatabaseName, std::string newProjectName)
Definition: repo_scene.h:384
std::vector< std::string > refFiles
Definition: repo_scene.h:1060
std::vector< RepoNode * > getRemovedNodes() const
Definition: repo_scene.h:753
std::string revExt
Definition: repo_scene.h:1052
Definition: repo_node_utils.h:40
std::string getProjectName() const
Definition: repo_scene.h:347
RepoNodeSet getAllMaterials(const GraphType &gType) const
Definition: repo_scene.h:642
RepoNode * getNodeByUniqueID(const GraphType &gType, const repoUUID &uniqueID) const
Definition: repo_scene.h:793
std::string srcExt
Definition: repo_scene.h:1056
std::string rawExt
Definition: repo_scene.h:1054
GraphType getViewGraph() const
Definition: repo_scene.h:433
std::vector< double > getWorldOffset() const
Definition: repo_scene.h:356
bool isMissingTexture() const
Definition: repo_scene.h:171
std::string getGLTFExtension() const
Definition: repo_scene.h:289
Definition: repo_node.h:33
std::string getOwner() const
Definition: repo_scene.h:330
void modifyNode(const GraphType &gtype, const repoUUID &sharedID, RepoNode *newNode, const bool &overwrite=false)
Definition: repo_scene.h:855
std::vector< repoUUID > getModifiedNodesID() const
Definition: repo_scene.h:735
repoUUID getRevisionID() const
Definition: repo_scene.h:316
std::string getRawExtension() const
Definition: repo_scene.h:271
bool isOK() const
Definition: repo_scene.h:163
std::string x3dExt
Definition: repo_scene.h:1058
Definition: repo_scene.h:36
RepoNodeSet getAllMetadata(const GraphType &gType) const
Definition: repo_scene.h:672
std::vector< repoUUID > getAddedNodesID() const
Definition: repo_scene.h:712
GraphType
Definition: repo_scene.h:75
std::string getJSONExtension() const
Definition: repo_scene.h:307
Definition: repo_graph_abstract.h:32
std::string gltfExt
Definition: repo_scene.h:1057
void setRevision(repoUUID revisionID)
Definition: repo_scene.h:394
void addInheritance(const GraphType &gType, const repoUUID &parent, const repoUUID &child, const bool &noUpdate=false)
Definition: repo_scene.h:536