├── .gitattributes ├── src ├── RepoCore ├── RepoLogger ├── Repo3DDiff ├── RepoAPIKey ├── RepoCSV ├── RepoPCA ├── RepoBSON ├── RepoCoreGlobal ├── RepoEigen ├── RepoGridFS ├── RepoImage ├── RepoRole ├── RepoUser ├── RepoWrapperAssimp ├── RepoBinary ├── RepoGraphScene ├── RepoNodeMesh ├── RepoNodeTypes ├── RepoWrapperMongo ├── RepoCollStats ├── RepoGraphHistory ├── RepoNodeAbstract ├── RepoNodeMetadata ├── RepoNodeRevision ├── RepoGraphAbstract ├── RepoGraphOptimizer ├── RepoNodeReference ├── RepoAbstractListener ├── RepoAbstractNotifier ├── RepoProjectSettings ├── RepoTranscoderBSON ├── RepoNodeTransformation ├── RepoTranscoderString ├── repocore.cpp ├── primitives │ ├── repoabstractlistener.cpp │ ├── reporole.cpp │ ├── repoabstractnotifier.cpp │ ├── repoimage.cpp │ ├── reposeverity.cpp │ ├── repostreambuffer.cpp │ ├── reporole.h │ ├── repoimage.h │ ├── repoabstractlistener.h │ ├── repoabstractnotifier.h │ ├── repocollstats.cpp │ ├── repostreambuffer.h │ ├── repo_binary.h │ ├── repocollstats.h │ ├── repo_binary.cpp │ ├── repobson.h │ ├── repobson.cpp │ ├── reposeverity.h │ └── repoprojectsettings.h ├── api │ ├── repo_apikey.cpp │ └── repo_apikey.h ├── repocore.h ├── compute │ ├── render.h │ ├── repographoptimizer.h │ ├── repocsv.cpp │ ├── repocsv.h │ └── repographoptimizer.cpp ├── sha256 │ ├── LICENSE.txt │ ├── sha256.h │ └── sha256.cpp ├── graph │ ├── sha256 │ │ ├── LICENSE.txt │ │ ├── sha256.h │ │ └── sha256.cpp │ ├── repo_node_types.h │ ├── repo_graph_history.cpp │ ├── repo_graph_history.h │ ├── repo_bounding_box.cpp │ ├── repo_bounding_box.h │ ├── repo_node_texture.h │ ├── repo_node_metadata.h │ ├── repo_node_reference.cpp │ ├── repo_graph_abstract.h │ ├── repo_node_texture.cpp │ └── repo_node_camera.h ├── diff │ ├── repo3ddiff.h │ └── repo3ddiff.cpp ├── conversion │ ├── repo_transcoder_string.cpp │ ├── repo_transcoder_string.h │ └── repo_transcoder_bson.cpp ├── mongo │ ├── repogridfs.h │ └── repogridfs.cpp ├── repologger.h ├── repocoreglobal.h ├── cli.cpp └── repologger.cpp ├── submodules ├── mongo-cxx-driver.creator ├── mongo-cxx-driver.config ├── make_mongo.bat └── mongo-cxx-driver.includes ├── .gitignore ├── .gitmodules ├── header.pri ├── assimp.pri ├── boost.pri ├── mongo.pri ├── 3drepocli.pro ├── 3drepocore.pro └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/RepoCore: -------------------------------------------------------------------------------- 1 | #include "repocore.h" 2 | -------------------------------------------------------------------------------- /src/RepoLogger: -------------------------------------------------------------------------------- 1 | #include "repologger.h" 2 | -------------------------------------------------------------------------------- /src/Repo3DDiff: -------------------------------------------------------------------------------- 1 | #include "diff/repo3ddiff.h" 2 | -------------------------------------------------------------------------------- /src/RepoAPIKey: -------------------------------------------------------------------------------- 1 | #include "api/repo_apikey.h" 2 | -------------------------------------------------------------------------------- /src/RepoCSV: -------------------------------------------------------------------------------- 1 | #include "compute/repocsv.h" 2 | -------------------------------------------------------------------------------- /src/RepoPCA: -------------------------------------------------------------------------------- 1 | #include "compute/repo_pca.h" 2 | -------------------------------------------------------------------------------- /src/RepoBSON: -------------------------------------------------------------------------------- 1 | #include "primitives/repobson.h" 2 | -------------------------------------------------------------------------------- /src/RepoCoreGlobal: -------------------------------------------------------------------------------- 1 | #include "repocoreglobal.h" 2 | -------------------------------------------------------------------------------- /src/RepoEigen: -------------------------------------------------------------------------------- 1 | #include "compute/repo_eigen.h" 2 | -------------------------------------------------------------------------------- /src/RepoGridFS: -------------------------------------------------------------------------------- 1 | #include "mongo/repogridfs.h" 2 | -------------------------------------------------------------------------------- /src/RepoImage: -------------------------------------------------------------------------------- 1 | #include "primitives/repoimage.h" 2 | -------------------------------------------------------------------------------- /src/RepoRole: -------------------------------------------------------------------------------- 1 | #include "primitives/reporole.h" 2 | -------------------------------------------------------------------------------- /src/RepoUser: -------------------------------------------------------------------------------- 1 | #include "primitives/repo_user.h" 2 | -------------------------------------------------------------------------------- /src/RepoWrapperAssimp: -------------------------------------------------------------------------------- 1 | #include "assimpwrapper.h" 2 | -------------------------------------------------------------------------------- /submodules/mongo-cxx-driver.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /src/RepoBinary: -------------------------------------------------------------------------------- 1 | #include "primitives/repo_binary.h" 2 | -------------------------------------------------------------------------------- /src/RepoGraphScene: -------------------------------------------------------------------------------- 1 | #include "graph/repo_graph_scene.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeMesh: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_mesh.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeTypes: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_types.h" 2 | -------------------------------------------------------------------------------- /src/RepoWrapperMongo: -------------------------------------------------------------------------------- 1 | #include "mongoclientwrapper.h" 2 | -------------------------------------------------------------------------------- /src/RepoCollStats: -------------------------------------------------------------------------------- 1 | #include "primitives/RepoCollStats.h" 2 | -------------------------------------------------------------------------------- /src/RepoGraphHistory: -------------------------------------------------------------------------------- 1 | #include "graph/repo_graph_history.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeAbstract: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_abstract.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeMetadata: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_metadata.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeRevision: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_revision.h" 2 | -------------------------------------------------------------------------------- /src/RepoGraphAbstract: -------------------------------------------------------------------------------- 1 | #include "graph/repo_graph_abstract.h" 2 | -------------------------------------------------------------------------------- /src/RepoGraphOptimizer: -------------------------------------------------------------------------------- 1 | #include "compute/repographoptimizer.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeReference: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_reference.h" 2 | -------------------------------------------------------------------------------- /src/RepoAbstractListener: -------------------------------------------------------------------------------- 1 | #include "primitives/repoabstractlistener.h" 2 | -------------------------------------------------------------------------------- /src/RepoAbstractNotifier: -------------------------------------------------------------------------------- 1 | #include "primitives/repoabstractnotifier.h" 2 | -------------------------------------------------------------------------------- /src/RepoProjectSettings: -------------------------------------------------------------------------------- 1 | #include "primitives/repoprojectsettings.h" 2 | -------------------------------------------------------------------------------- /src/RepoTranscoderBSON: -------------------------------------------------------------------------------- 1 | #include "conversion/repo_transcoder_bson.h" 2 | -------------------------------------------------------------------------------- /src/RepoNodeTransformation: -------------------------------------------------------------------------------- 1 | #include "graph/repo_node_transformation.h" 2 | -------------------------------------------------------------------------------- /src/RepoTranscoderString: -------------------------------------------------------------------------------- 1 | #include "conversion/repo_transcoder_string.h" 2 | -------------------------------------------------------------------------------- /submodules/mongo-cxx-driver.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define _CRT_SECURE_NO_WARNINGS 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*.user 2 | lib3drepocore.so 3 | lib3drepocore.so.1 4 | lib3drepocore.so.1.0 5 | lib3drepocore.so.1.0.0 6 | *.o 7 | Makefile 8 | Makefile.* 9 | repo_cli 10 | repo_cli_debug 11 | *.obj 12 | *.mtl 13 | 14 | /lib 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "submodules/assimp"] 2 | path = submodules/assimp 3 | url = https://github.com/3drepo/assimp/ 4 | [submodule "submodules/mongo-cxx-driver"] 5 | path = submodules/mongo-cxx-driver 6 | url = https://github.com/mongodb/mongo-cxx-driver 7 | -------------------------------------------------------------------------------- /submodules/make_mongo.bat: -------------------------------------------------------------------------------- 1 | cd mongo-cxx-driver 2 | scons -j2 --full --64 --mute --sharedclient --dynamic-windows --use-system-boost --extrapath=c:\local\boost_1_56_0 --cpppath=c:\local\boost_1_56_0 --libpath=c:\local\boost_1_56_0\lib64-msvc-12.0 install-mongoclient 3 | -------------------------------------------------------------------------------- /src/repocore.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repocore.h" 19 | #include "repologger.h" 20 | 21 | repo::core::RepoCore::RepoCore() 22 | { 23 | } 24 | 25 | repo::core::RepoCore::~RepoCore() 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /src/primitives/repoabstractlistener.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repoabstractlistener.h" 19 | 20 | //------------------------------------------------------------------------------ 21 | repo::core::RepoAbstractListener::~RepoAbstractListener() {} 22 | -------------------------------------------------------------------------------- /header.pri: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 3D Repo Ltd 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU Affero General Public License as 5 | # published by the Free Software Foundation, either version 3 of the 6 | # License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU Affero General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Affero General Public License 14 | # along with this program. If not, see . 15 | 16 | # http://qt-project.org/doc/qt-5/qmake-variable-reference.html 17 | # http://google-styleguide.googlecode.com/svn/trunk/cppguide.html 18 | 19 | unix:QMAKE_CXXFLAGS += -fpermissive -std=c++11 20 | unix:QMAKE_CXXFLAGS_DEBUG -= -O1 21 | unix:QMAKE_CXXFLAGS_DEBUG += -O0 22 | 23 | macx{ 24 | CONFIG += c++11 25 | } -------------------------------------------------------------------------------- /src/primitives/reporole.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "reporole.h" 20 | 21 | repo::core::RepoRole::RepoRole() : RepoBSON() {} 22 | 23 | repo::core::RepoRole::RepoRole(const mongo::BSONObj &obj) : RepoBSON(obj) {} 24 | 25 | repo::core::RepoRole::~RepoRole() {} 26 | 27 | std::string repo::core::RepoRole::getName() const 28 | { 29 | return getField(REPO_LABEL_ROLE).str(); 30 | } 31 | -------------------------------------------------------------------------------- /submodules/mongo-cxx-driver.includes: -------------------------------------------------------------------------------- 1 | mongo-cxx-driver/src/mongo 2 | mongo-cxx-driver/src/mongo/base 3 | mongo-cxx-driver/src/mongo/bson 4 | mongo-cxx-driver/src/mongo/bson/util 5 | mongo-cxx-driver/src/mongo/client 6 | mongo-cxx-driver/src/mongo/db 7 | mongo-cxx-driver/src/mongo/dbtests/mock 8 | mongo-cxx-driver/src/mongo/logger 9 | mongo-cxx-driver/src/mongo/platform 10 | mongo-cxx-driver/src/mongo/s 11 | mongo-cxx-driver/src/mongo/unittest 12 | mongo-cxx-driver/src/mongo/util 13 | mongo-cxx-driver/src/mongo/util/concurrency 14 | mongo-cxx-driver/src/mongo/util/mongoutils 15 | mongo-cxx-driver/src/mongo/util/net 16 | mongo-cxx-driver/src/third_party/gtest-1.7.0/fused-src/gtest 17 | mongo-cxx-driver/src/third_party/gtest-1.7.0/include/gtest 18 | mongo-cxx-driver/src/third_party/gtest-1.7.0/include/gtest/internal 19 | mongo-cxx-driver/src/third_party/gtest-1.7.0/samples 20 | mongo-cxx-driver/src/third_party/gtest-1.7.0/src 21 | mongo-cxx-driver/src/third_party/gtest-1.7.0/test 22 | mongo-cxx-driver/src/third_party/gtest-1.7.0/xcode/Samples/FrameworkSample 23 | mongo-cxx-driver/src/third_party/murmurhash3 24 | mongo-cxx-driver/src/third_party/tz 25 | -------------------------------------------------------------------------------- /assimp.pri: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 3D Repo Ltd 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU Affero General Public License as 5 | # published by the Free Software Foundation, either version 3 of the 6 | # License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU Affero General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Affero General Public License 14 | # along with this program. If not, see . 15 | 16 | #------------------------------------------------------------------------------- 17 | # Assimp 18 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lassimp 19 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lassimpd 20 | else:unix: LIBS += -L$$PWD/submodules/assimp/build/code -lassimp 21 | 22 | INCLUDEPATH += $$PWD/submodules/assimp/include 23 | DEPENDPATH += $$PWD/submodules/assimp/include 24 | -------------------------------------------------------------------------------- /boost.pri: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 3D Repo Ltd 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU Affero General Public License as 5 | # published by the Free Software Foundation, either version 3 of the 6 | # License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU Affero General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Affero General Public License 14 | # along with this program. If not, see . 15 | 16 | #------------------------------------------------------------------------------- 17 | # Boost 18 | win32: LIBS += -LC:/local/boost_1_56_0/lib64-msvc-12.0/ 19 | win32:INCLUDEPATH += C:/local/boost_1_56_0/ 20 | win32:DEPENDPATH += C:/local/boost_1_56_0/ 21 | 22 | macx { 23 | _BOOST_PATH = /usr/local/Cellar/boost/1.56.0 24 | INCLUDEPATH += "$${_BOOST_PATH}/include/" 25 | LIBS += -L$${_BOOST_PATH}/lib 26 | LIBS += -lboost_chrono-mt -lboost_system -lboost_filesystem 27 | } 28 | -------------------------------------------------------------------------------- /src/api/repo_apikey.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repo_apikey.h" 20 | 21 | repo::core::RepoAPIKey::RepoAPIKey() 22 | : uuid(boost::uuids::random_generator()()) 23 | { 24 | } 25 | 26 | repo::core::RepoAPIKey::~RepoAPIKey() 27 | { 28 | } 29 | 30 | std::string repo::core::RepoAPIKey::toString() const 31 | { 32 | std::string str = to_string(uuid); 33 | str.erase(std::remove(str.begin(), str.end(), '-'), str.end()); // remove hyphens 34 | return str; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/repocore.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_CORE_H 20 | #define REPO_CORE_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "repocoreglobal.h" 24 | //------------------------------------------------------------------------------ 25 | 26 | namespace repo { 27 | namespace core { 28 | 29 | //------------------------------------------------------------------------------ 30 | class REPO_CORE_EXPORT RepoCore 31 | { 32 | 33 | public: 34 | RepoCore(); 35 | 36 | ~RepoCore(); 37 | 38 | }; // end class 39 | 40 | } // end namespace core 41 | } // end namespace repo 42 | 43 | #endif // REPO_CORE_H 44 | -------------------------------------------------------------------------------- /mongo.pri: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 3D Repo Ltd 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU Affero General Public License as 5 | # published by the Free Software Foundation, either version 3 of the 6 | # License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU Affero General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Affero General Public License 14 | # along with this program. If not, see . 15 | 16 | #------------------------------------------------------------------------------- 17 | # MongoDB C++ Driver 18 | 19 | win32:DEFINES += WIN32_LEAN_AND_MEAN VC_EXTRALEAN 20 | win32:LIBS += -lws2_32 21 | 22 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lmongoclient 23 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lmongoclientd 24 | else:unix:!macx: LIBS += -L$$PWD/submodules/mongo-cxx-driver/lib -lmongoclient 25 | else:macx: LIBS += -L$$PWD/submodules/mongo-cxx-driver/build/darwin/64/osx-version-min_10.9/use-system-boost -lmongoclient 26 | 27 | unix:INCLUDEPATH += $$PWD/submodules/mongo-cxx-driver/include 28 | else:INCLUDEPATH += $$PWD/submodules/mongo-cxx-driver/src 29 | 30 | DEPENDPATH += $$PWD/submodules/mongo-cxx-driver/src 31 | -------------------------------------------------------------------------------- /src/primitives/repoabstractnotifier.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repoabstractnotifier.h" 19 | 20 | //------------------------------------------------------------------------------ 21 | repo::core::RepoAbstractNotifier::~RepoAbstractNotifier() {} 22 | 23 | void repo::core::RepoAbstractNotifier::addListener( 24 | RepoAbstractListener *l) 25 | { 26 | listeners.insert(l); 27 | } 28 | 29 | void repo::core::RepoAbstractNotifier::removeListener( 30 | RepoAbstractListener *l) 31 | { 32 | listeners.erase(l); 33 | } 34 | 35 | void repo::core::RepoAbstractNotifier::notifyListeners(const std::string &msg) 36 | { 37 | std::set::iterator it; 38 | for (it = listeners.begin(); it != listeners.end(); ++it) 39 | { 40 | RepoAbstractListener *l = *it; 41 | l->messageGenerated(msg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/compute/render.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef RENDER_H 19 | #define RENDER_H 20 | 21 | #include "../mongoclientwrapper.h" 22 | #include "../graph/repo_graph_scene.h" 23 | #include "../graph/repo_node_abstract.h" 24 | #include "../graph/repo_node_mesh.h" 25 | #include "../conversion/repo_transcoder_bson.h" 26 | #include "mongo/bson/bsontypes.h" 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #include "../repocoreglobal.h" 39 | 40 | #include 41 | 42 | namespace repo { 43 | namespace core { 44 | 45 | class REPO_CORE_EXPORT Renderer 46 | { 47 | private: 48 | RepoGraphScene *scene; 49 | 50 | public: 51 | Renderer(RepoGraphScene *scene) : scene(scene) {} 52 | 53 | void renderToBSONs(std::vector &out); 54 | }; 55 | 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /3drepocli.pro: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 3D Repo Ltd 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU Affero General Public License as 5 | # published by the Free Software Foundation, either version 3 of the 6 | # License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU Affero General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Affero General Public License 14 | # along with this program. If not, see . 15 | 16 | # http://qt-project.org/doc/qt-5/qmake-variable-reference.html 17 | # http://google-styleguide.googlecode.com/svn/trunk/cppguide.html 18 | 19 | include(header.pri) 20 | include(boost.pri) 21 | include(assimp.pri) 22 | include(mongo.pri) 23 | 24 | TEMPLATE = app 25 | #CONFIG += debug_and_release 26 | #release: TARGET = repo_cli 27 | #debug: TARGET = repo_cli_debug 28 | 29 | QT += core gui # TODO: remove Qt dependencies, ie it should be -= 30 | 31 | #------------------------------------------------------------------------------- 32 | # 3drepocore 33 | 34 | win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/release/ -l3drepocore 35 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/debug/ -l3drepocore 36 | else:unix: LIBS += -L$$OUT_PWD/ -lboost_system -l3drepocore 37 | 38 | INCLUDEPATH += $$PWD/src 39 | DEPENDPATH += $$PWD/src 40 | 41 | #------------------------------------------------------------------------------- 42 | # Input 43 | #HEADERS += 44 | SOURCES += src/cli.cpp 45 | #------------------------------------------------------------------------------- 46 | -------------------------------------------------------------------------------- /src/api/repo_apikey.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_API_KEY_H 20 | #define REPO_API_KEY_H 21 | 22 | #include 23 | #include 24 | //------------------------------------------------------------------------------ 25 | #include "../repocoreglobal.h" 26 | //------------------------------------------------------------------------------ 27 | #include // uuid class 28 | #include // generators 29 | #include // streaming operators etc 30 | //------------------------------------------------------------------------------ 31 | 32 | namespace repo { 33 | namespace core { 34 | 35 | 36 | class REPO_CORE_EXPORT RepoAPIKey 37 | { 38 | 39 | public: 40 | 41 | RepoAPIKey(); 42 | 43 | ~RepoAPIKey(); 44 | 45 | std::string toString() const; 46 | 47 | private : 48 | 49 | boost::uuids::uuid uuid; 50 | 51 | }; // end class 52 | 53 | } // end namespace core 54 | } // end namespace repo 55 | 56 | #endif // REPO_API_KEY_H 57 | -------------------------------------------------------------------------------- /src/primitives/repoimage.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public Listd::cerrnse as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repoimage.h" 20 | 21 | repo::core::RepoImage::RepoImage(const unsigned char *bytes, 22 | unsigned int bytesLength, 23 | unsigned int width, 24 | unsigned int height, 25 | const string &mediaType) 26 | : RepoBinary(bytes, bytesLength, mediaType) 27 | { 28 | mongo::BSONObjBuilder builder; 29 | builder.appendElements(*this); 30 | 31 | //-------------------------------------------------------------------------- 32 | // Width 33 | if (width) 34 | builder << REPO_LABEL_WIDTH << width; 35 | 36 | //-------------------------------------------------------------------------- 37 | // Height 38 | if (height) 39 | builder << REPO_LABEL_HEIGHT << height; 40 | 41 | //-------------------------------------------------------------------------- 42 | // Add to the parent object 43 | *this = builder.obj(); 44 | } 45 | -------------------------------------------------------------------------------- /src/sha256/LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Updated to C++, zedwood.com 2012 3 | * Based on Olivier Gay's version 4 | * See Modified BSD License below: 5 | * 6 | * FIPS 180-2 SHA-224/256/384/512 implementation 7 | * Issue date: 04/30/2005 8 | * http://www.ouah.org/ogay/sha2/ 9 | * 10 | * Copyright (C) 2005, 2007 Olivier Gay 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 3. Neither the name of the project nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | -------------------------------------------------------------------------------- /src/graph/sha256/LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Updated to C++, zedwood.com 2012 3 | * Based on Olivier Gay's version 4 | * See Modified BSD License below: 5 | * 6 | * FIPS 180-2 SHA-224/256/384/512 implementation 7 | * Issue date: 04/30/2005 8 | * http://www.ouah.org/ogay/sha2/ 9 | * 10 | * Copyright (C) 2005, 2007 Olivier Gay 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 3. Neither the name of the project nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | -------------------------------------------------------------------------------- /src/graph/repo_node_types.h: -------------------------------------------------------------------------------- 1 | #ifndef REPO_NODE_TYPES 2 | #define REPO_NODE_TYPES 3 | 4 | //----------------------------------------------------------------------------- 5 | // 6 | // Required fields 7 | // 8 | //----------------------------------------------------------------------------- 9 | #define REPO_NODE_LABEL_ID "_id" //!< required 10 | #define REPO_NODE_LABEL_SHARED_ID "shared_id" //!< required 11 | #define REPO_NODE_LABEL_TYPE "type" //!< required 12 | #define REPO_NODE_LABEL_API "api" //!< required 13 | #define REPO_NODE_LABEL_PATHS "paths" //!< required 14 | //----------------------------------------------------------------------------- 15 | #define REPO_NODE_API_LEVEL_0 0 //!< unknown api level 16 | #define REPO_NODE_API_LEVEL_1 1 //!< original api level 17 | #define REPO_NODE_API_LEVEL_2 2 //!< triangles only api level 18 | #define REPO_NODE_API_LEVEL_3 3 //!< compressed api level 19 | 20 | //----------------------------------------------------------------------------- 21 | // 22 | // Optional nevertheless common fields 23 | // 24 | //----------------------------------------------------------------------------- 25 | #define REPO_NODE_LABEL_NAME "name" //!< optional bson field label 26 | #define REPO_NODE_LABEL_PARENTS "parents" //!< optional field label 27 | //----------------------------------------------------------------------------- 28 | #define REPO_NODE_TYPE_ANIMATION "animation" 29 | #define REPO_NODE_TYPE_BONE "bone" 30 | #define REPO_NODE_TYPE_CAMERA "camera" 31 | #define REPO_NODE_TYPE_COMMENT "comment" 32 | #define REPO_NODE_TYPE_LIGHT "light" 33 | #define REPO_NODE_TYPE_LOCK "lock" 34 | #define REPO_NODE_TYPE_METADATA "meta" 35 | #define REPO_NODE_TYPE_REVISION "revision" 36 | #define REPO_NODE_TYPE_SHADER "shader" 37 | #define REPO_NODE_TYPE_TEXTURE "texture" 38 | #define REPO_NODE_TYPE_TRANSFORMATION "transformation" 39 | #define REPO_NODE_TYPE_UNKNOWN "unknown" // reserved UUID ext 00 40 | //----------------------------------------------------------------------------- 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/sha256/sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256_H 2 | #define SHA256_H 3 | #include 4 | 5 | class SHA256 6 | { 7 | protected: 8 | typedef unsigned char uint8; 9 | typedef unsigned int uint32; 10 | typedef unsigned long long uint64; 11 | 12 | const static uint32 sha256_k[]; 13 | static const unsigned int SHA224_256_BLOCK_SIZE = (512/8); 14 | public: 15 | void init(); 16 | void update(const unsigned char *message, unsigned int len); 17 | void final(unsigned char *digest); 18 | static const unsigned int DIGEST_SIZE = ( 256 / 8); 19 | 20 | protected: 21 | void transform(const unsigned char *message, unsigned int block_nb); 22 | unsigned int m_tot_len; 23 | unsigned int m_len; 24 | unsigned char m_block[2*SHA224_256_BLOCK_SIZE]; 25 | uint32 m_h[8]; 26 | }; 27 | 28 | std::string sha256(std::string input); 29 | 30 | #define SHA2_SHFR(x, n) (x >> n) 31 | #define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) 32 | #define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) 33 | #define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) 34 | #define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) 35 | #define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) 36 | #define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) 37 | #define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) 38 | #define SHA256_F4(x) (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10)) 39 | #define SHA2_UNPACK32(x, str) \ 40 | { \ 41 | *((str) + 3) = (uint8) ((x) ); \ 42 | *((str) + 2) = (uint8) ((x) >> 8); \ 43 | *((str) + 1) = (uint8) ((x) >> 16); \ 44 | *((str) + 0) = (uint8) ((x) >> 24); \ 45 | } 46 | #define SHA2_PACK32(str, x) \ 47 | { \ 48 | *(x) = ((uint32) *((str) + 3) ) \ 49 | | ((uint32) *((str) + 2) << 8) \ 50 | | ((uint32) *((str) + 1) << 16) \ 51 | | ((uint32) *((str) + 0) << 24); \ 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /src/graph/sha256/sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256_H 2 | #define SHA256_H 3 | #include 4 | 5 | class SHA256 6 | { 7 | protected: 8 | typedef unsigned char uint8; 9 | typedef unsigned int uint32; 10 | typedef unsigned long long uint64; 11 | 12 | const static uint32 sha256_k[]; 13 | static const unsigned int SHA224_256_BLOCK_SIZE = (512/8); 14 | public: 15 | void init(); 16 | void update(const unsigned char *message, unsigned int len); 17 | void final(unsigned char *digest); 18 | static const unsigned int DIGEST_SIZE = ( 256 / 8); 19 | 20 | protected: 21 | void transform(const unsigned char *message, unsigned int block_nb); 22 | unsigned int m_tot_len; 23 | unsigned int m_len; 24 | unsigned char m_block[2*SHA224_256_BLOCK_SIZE]; 25 | uint32 m_h[8]; 26 | }; 27 | 28 | std::string sha256(std::string input); 29 | 30 | #define SHA2_SHFR(x, n) (x >> n) 31 | #define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) 32 | #define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) 33 | #define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) 34 | #define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) 35 | #define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) 36 | #define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) 37 | #define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) 38 | #define SHA256_F4(x) (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10)) 39 | #define SHA2_UNPACK32(x, str) \ 40 | { \ 41 | *((str) + 3) = (uint8) ((x) ); \ 42 | *((str) + 2) = (uint8) ((x) >> 8); \ 43 | *((str) + 1) = (uint8) ((x) >> 16); \ 44 | *((str) + 0) = (uint8) ((x) >> 24); \ 45 | } 46 | #define SHA2_PACK32(str, x) \ 47 | { \ 48 | *(x) = ((uint32) *((str) + 3) ) \ 49 | | ((uint32) *((str) + 2) << 8) \ 50 | | ((uint32) *((str) + 1) << 16) \ 51 | | ((uint32) *((str) + 0) << 24); \ 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /src/primitives/reposeverity.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "reposeverity.h" 19 | 20 | using namespace repo::core; 21 | 22 | RepoSeverity::RepoSeverity( 23 | const std::string &color, 24 | const std::string &level, 25 | int value) 26 | : color(color) 27 | , level(level) 28 | , value(value) {} 29 | 30 | RepoSeverity::RepoSeverity() 31 | : color("green") 32 | , level("INFO") 33 | , value(REPO_INFO_NUM) {} 34 | 35 | const RepoSeverity RepoSeverity::REPO_PANIC = 36 | RepoSeverity("red", "PANIC", REPO_PANIC_NUM); 37 | 38 | const RepoSeverity RepoSeverity::REPO_ALERT = 39 | RepoSeverity("red", "ALERT", REPO_ALERT_NUM); 40 | 41 | const RepoSeverity RepoSeverity::REPO_CRITICAL = 42 | RepoSeverity("red", "CRITICAL", REPO_CRITICAL_NUM); 43 | 44 | const RepoSeverity RepoSeverity::REPO_ERROR = 45 | RepoSeverity("red", "ERROR", REPO_ERROR_NUM); 46 | 47 | const RepoSeverity RepoSeverity::REPO_WARNING = 48 | RepoSeverity("orange", "WARNING", REPO_WARNING_NUM); 49 | 50 | const RepoSeverity RepoSeverity::REPO_NOTICE = 51 | RepoSeverity("blue", "NOTICE", REPO_NOTICE_NUM); 52 | 53 | const RepoSeverity RepoSeverity::REPO_INFO = 54 | RepoSeverity("green", "INFO", REPO_INFO_NUM); 55 | 56 | const RepoSeverity RepoSeverity::REPO_DEBUG = 57 | RepoSeverity("purple", "DEBUG", REPO_DEBUG_NUM); 58 | -------------------------------------------------------------------------------- /src/primitives/repostreambuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repostreambuffer.h" 19 | 20 | repo::core::RepoStreamBuffer::RepoStreamBuffer( 21 | RepoAbstractListener *interceptor, 22 | std::ostream &stream) 23 | : listener(interceptor) 24 | , originalBuffer(0) 25 | , originalStream(stream) 26 | , redirectStream(0) 27 | { 28 | originalBuffer = originalStream.rdbuf(this); 29 | redirectStream = new std::ostream(originalBuffer); 30 | } 31 | 32 | 33 | repo::core::RepoStreamBuffer::~RepoStreamBuffer() 34 | { 35 | // Revert back as it was originally 36 | originalStream.rdbuf(originalBuffer); 37 | 38 | // Delete redundant stream 39 | delete redirectStream; 40 | } 41 | 42 | std::ostream &repo::core::RepoStreamBuffer::getRedirectStream() const 43 | { 44 | return *(redirectStream); 45 | } 46 | 47 | //------------------------------------------------------------------------------ 48 | // 49 | // Protected 50 | // 51 | //------------------------------------------------------------------------------ 52 | 53 | int repo::core::RepoStreamBuffer::overflow(int_type c) 54 | { 55 | return c; 56 | } 57 | 58 | std::streamsize repo::core::RepoStreamBuffer::xsputn( 59 | const char *msg, 60 | std::streamsize count) 61 | { 62 | std::string message(msg, count); 63 | 64 | //-------------------------------------------------------------------------- 65 | listener->messageGenerated(&originalStream, message); 66 | 67 | return count; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/primitives/reporole.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_ROLE_H 19 | #define REPO_ROLE_H 20 | 21 | //------------------------------------------------------------------------------ 22 | #include // the MongoDB driver 23 | //------------------------------------------------------------------------------ 24 | #include "../conversion/repo_transcoder_bson.h" 25 | #include "../conversion/repo_transcoder_string.h" 26 | //------------------------------------------------------------------------------ 27 | #include "../repocoreglobal.h" 28 | #include "repobson.h" 29 | 30 | namespace repo { 31 | namespace core { 32 | 33 | //------------------------------------------------------------------------------ 34 | // 35 | // Fields specific to role only 36 | // 37 | //------------------------------------------------------------------------------ 38 | 39 | 40 | class REPO_CORE_EXPORT RepoRole : public RepoBSON 41 | { 42 | 43 | public : 44 | 45 | //! Default empty constructor. 46 | RepoRole(); 47 | 48 | //! Constructor from Mongo BSON objects. 49 | RepoRole(const mongo::BSONObj &obj); 50 | 51 | //! Default empty destructor. 52 | ~RepoRole(); 53 | 54 | //! Returns a new full (and owned) copy of the object. 55 | inline RepoRole copy() const { return RepoRole(RepoBSON::copy()); } 56 | 57 | //! Returns the name of the role if any. 58 | std::string getName() const; 59 | 60 | }; // end class 61 | 62 | } // end namespace core 63 | } // end namespace repo 64 | 65 | #endif // end REPO_ROLE_H 66 | 67 | -------------------------------------------------------------------------------- /src/compute/repographoptimizer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_GRAPH_OPTIMIZER_H 20 | #define REPO_GRAPH_OPTIMIZER_H 21 | 22 | #include "../repocoreglobal.h" 23 | #include "../graph/repo_graph_scene.h" 24 | #include "../graph/repo_node_mesh.h" 25 | #include "../graph/repo_node_metadata.h" 26 | #include "../graph/repo_node_transformation.h" 27 | 28 | //------------------------------------------------------------------------------ 29 | 30 | namespace repo { 31 | namespace core { 32 | 33 | class REPO_CORE_EXPORT RepoGraphOptimizer 34 | { 35 | 36 | public: 37 | 38 | RepoGraphOptimizer(RepoGraphScene* scene); 39 | 40 | ~RepoGraphOptimizer() {} 41 | 42 | //! Collapses all single mesh transformations in a scene graph. 43 | void collapseSingleMeshTransformations(); 44 | 45 | //! Recursive collapse until not more possible. 46 | void collapseSingleMeshTransformations(RepoNodeMesh* mesh); 47 | 48 | //! Resursive collapse of transformations that have no meshes as children. Disregards 49 | void collapseZeroMeshTransformations(); 50 | 51 | //! Returns processed scene. 52 | RepoGraphScene* getScene() const { return scene; } 53 | 54 | //! Returns a transformation if it is a single parent, NULL otherwise. 55 | static RepoNodeTransformation* getSingleParentTransformation(RepoNodeAbstract *node); 56 | 57 | private : 58 | 59 | RepoGraphScene* scene; 60 | 61 | }; // end class 62 | 63 | } // end namespace core 64 | } // end namespace repo 65 | 66 | #endif // REPOGRAPHOPTIMIZER_H 67 | -------------------------------------------------------------------------------- /src/primitives/repoimage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_IMAGE_H 20 | #define REPO_IMAGE_H 21 | 22 | 23 | //------------------------------------------------------------------------------ 24 | #include "../repocoreglobal.h" 25 | #include "repo_binary.h" 26 | //------------------------------------------------------------------------------ 27 | 28 | namespace repo { 29 | namespace core { 30 | 31 | /*! 32 | * See http://www.iana.org/assignments/media-types/media-types.xhtml#image 33 | */ 34 | class REPO_CORE_EXPORT RepoImage : public RepoBinary 35 | { 36 | 37 | public: 38 | 39 | RepoImage() : RepoBinary() {} 40 | 41 | RepoImage(const mongo::BSONObj &obj) : RepoBinary(obj) {} 42 | 43 | RepoImage(const unsigned char* bytes, 44 | unsigned int bytesLength, 45 | unsigned int width, 46 | unsigned int height, 47 | const string &mediaType); 48 | 49 | ~RepoImage() {} 50 | 51 | //-------------------------------------------------------------------------- 52 | 53 | //! Returns a new full (and owned) copy of the object. 54 | inline RepoImage copy() const { return RepoImage(RepoBinary::copy()); } 55 | 56 | //! Returns the height of the image if set. 57 | int getHeight() const 58 | { return getField(REPO_LABEL_HEIGHT).Int(); } 59 | 60 | //! Returns the width of the image if set. 61 | int getWidth() const 62 | { return getField(REPO_LABEL_WIDTH).Int(); } 63 | 64 | 65 | }; // end class 66 | 67 | } // end namespace core 68 | } // end namespace repo 69 | 70 | #endif // REPO_IMAGE_H 71 | -------------------------------------------------------------------------------- /src/primitives/repoabstractlistener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_ABSTRACT_LISTENER_H 20 | #define REPO_ABSTRACT_LISTENER_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "../repocoreglobal.h" 24 | //------------------------------------------------------------------------------ 25 | 26 | #include 27 | 28 | 29 | namespace repo { 30 | namespace core { 31 | 32 | //------------------------------------------------------------------------------ 33 | //! Pure abstract class that provides intercept call for standard messages. 34 | class REPO_CORE_EXPORT RepoAbstractListener 35 | { 36 | 37 | public: 38 | 39 | //-------------------------------------------------------------------------- 40 | // 41 | // Constructor 42 | // 43 | //-------------------------------------------------------------------------- 44 | 45 | //! Default empty constructor. 46 | inline RepoAbstractListener() {} 47 | 48 | //-------------------------------------------------------------------------- 49 | // 50 | // Destructor 51 | // 52 | //-------------------------------------------------------------------------- 53 | 54 | //! Empty pure virtual destructor for proper cleanup. 55 | /*! 56 | * \sa RepoInterceptor() 57 | */ 58 | virtual ~RepoAbstractListener() = 0; 59 | 60 | virtual void messageGenerated(const std::string &) {} 61 | 62 | virtual void messageGenerated(const std::ostream *, const std::string &) {} 63 | 64 | }; // end class 65 | 66 | } // end namespace core 67 | } // end namespace repo 68 | 69 | #endif // REPO_ABSTRACT_LISTENER_H 70 | -------------------------------------------------------------------------------- /src/primitives/repoabstractnotifier.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_ABSTRACT_NOTIFIER_H 20 | #define REPO_ABSTRACT_NOTIFIER_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "../repocoreglobal.h" 24 | #include "repoabstractlistener.h" 25 | //------------------------------------------------------------------------------ 26 | #include 27 | 28 | namespace repo { 29 | namespace core { 30 | 31 | //------------------------------------------------------------------------------ 32 | 33 | class REPO_CORE_EXPORT RepoAbstractNotifier 34 | { 35 | 36 | public: 37 | 38 | //-------------------------------------------------------------------------- 39 | // 40 | // Constructor 41 | // 42 | //-------------------------------------------------------------------------- 43 | 44 | //! Default empty constructor. 45 | inline RepoAbstractNotifier() {} 46 | 47 | //-------------------------------------------------------------------------- 48 | // 49 | // Destructor 50 | // 51 | //-------------------------------------------------------------------------- 52 | 53 | //! Empty pure virtual destructor for proper cleanup. 54 | /*! 55 | * \sa RepoAbstractNotifier() 56 | */ 57 | virtual ~RepoAbstractNotifier() = 0; 58 | 59 | virtual void addListener(RepoAbstractListener *); 60 | 61 | virtual void removeListener(RepoAbstractListener *); 62 | 63 | virtual void notifyListeners(const std::string &); 64 | 65 | private: 66 | 67 | std::set listeners; 68 | 69 | 70 | }; // end class 71 | 72 | } // end namespace core 73 | } // end namespace repo 74 | 75 | #endif // REPO_ABSTRACT_NOTIFIER_H 76 | 77 | -------------------------------------------------------------------------------- /src/diff/repo3ddiff.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_3D_DIFF_H 19 | #define REPO_3D_DIFF_H 20 | 21 | #include 22 | #include 23 | 24 | #include "../repocoreglobal.h" 25 | 26 | #include "../graph/repo_node_abstract.h" 27 | #include "../graph/repo_node_revision.h" 28 | #include "../graph/repo_graph_abstract.h" 29 | #include "../graph/repo_graph_scene.h" 30 | 31 | namespace repo { 32 | namespace core { 33 | 34 | typedef std::multimap RepoSelfSimilarSet; 35 | 36 | class REPO_CORE_EXPORT Repo3DDiff 37 | { 38 | 39 | public: 40 | 41 | //! Default empty constructor. 42 | Repo3DDiff(const RepoGraphScene* A, 43 | const RepoGraphScene* B); 44 | 45 | //! Default empty destructor. 46 | ~Repo3DDiff() {} 47 | 48 | RepoNodeRevision diff() const; 49 | 50 | RepoSelfSimilarSet getSelfSimilarSetA() const 51 | { return toSelfSimilarSet(A->getMeshes()); } 52 | 53 | RepoSelfSimilarSet getSelfSimilarSetB() const 54 | { return toSelfSimilarSet(B->getMeshes()); } 55 | 56 | 57 | public : 58 | 59 | //! Set difference (A - B) 60 | static RepoNodeAbstractSet setDifference( 61 | const RepoNodeAbstractSet &a, 62 | const RepoNodeAbstractSet &b); 63 | 64 | //! Set intersection (A intersect B) 65 | static RepoNodeAbstractSet setIntersection( 66 | const RepoNodeAbstractSet &a, 67 | const RepoNodeAbstractSet &b); 68 | 69 | 70 | static void printSet(const RepoNodeAbstractSet &x, 71 | const std::string& label = std::string()); 72 | 73 | static RepoSelfSimilarSet toSelfSimilarSet(const RepoNodeAbstractSet &x); 74 | 75 | private : 76 | 77 | const RepoGraphScene* A; 78 | const RepoGraphScene* B; 79 | 80 | }; // end class 81 | 82 | } // end namespace core 83 | } // end namespace repo 84 | 85 | #endif // REPO_3D_DIFF_H 86 | -------------------------------------------------------------------------------- /src/conversion/repo_transcoder_string.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_transcoder_string.h" 19 | 20 | 21 | 22 | boost::uuids::uuid repo::core::RepoTranscoderString::stringToUUID( 23 | const std::string text, 24 | const std::string suffix) 25 | { 26 | boost::uuids::uuid uuid; 27 | if (text.empty()) 28 | uuid = boost::uuids::random_generator()(); 29 | else 30 | { 31 | try 32 | { 33 | boost::uuids::string_generator gen; 34 | // if ((text.find("{")) == std::string::npos) 35 | if (text.substr(0,1) != "{") 36 | uuid = gen("{" + text + "}"); 37 | else 38 | uuid = gen(text); 39 | } 40 | catch (std::runtime_error e) 41 | { 42 | // uniformly distributed hash 43 | boost::hash string_hash; 44 | std::string hashedUUID; 45 | std::stringstream str; 46 | str << string_hash(text); 47 | str >> hashedUUID; 48 | 49 | // uuid: 8 + 4 + 4 + 4 + 12 = 32 50 | // pad with zero, leave last places empty for suffix 51 | while (hashedUUID.size() < 32 - suffix.size()) 52 | hashedUUID.append("0"); 53 | hashedUUID.append(suffix); 54 | uuid = stringToUUID(hashedUUID, suffix); 55 | } 56 | } 57 | return uuid; 58 | } 59 | 60 | //------------------------------------------------------------------------------ 61 | // 62 | // To string conversion 63 | // 64 | //------------------------------------------------------------------------------ 65 | std::string repo::core::RepoTranscoderString::toString(const aiFace &f) 66 | { 67 | std::string str; 68 | unsigned int mNumIndices = f.mNumIndices; 69 | 70 | str += "["; 71 | for (unsigned int i = 0; i < mNumIndices; i++) 72 | { 73 | str += toString(f.mIndices[i]); 74 | if (i != mNumIndices - 1) 75 | str += ", "; 76 | } 77 | str += "]"; 78 | return str; 79 | } 80 | 81 | std::string repo::core::RepoTranscoderString::toString(const boost::uuids::uuid &u) 82 | { 83 | std::stringstream stream; 84 | stream << u; 85 | return stream.str(); 86 | } 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/primitives/repocollstats.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repocollstats.h" 19 | 20 | repo::core::RepoCollStats::~RepoCollStats() {} 21 | 22 | long long repo::core::RepoCollStats::getActualSizeOnDisk() const 23 | { 24 | return getSize() + 16 * getCount() + getTotalIndexSize(); 25 | } 26 | 27 | std::string repo::core::RepoCollStats::getDatabase() const 28 | { 29 | return getDatabase(getNs()); 30 | } 31 | 32 | std::string repo::core::RepoCollStats::getDatabase(const std::string& ns) 33 | { 34 | std::string database = ns; 35 | const char *str = ns.c_str(); 36 | const char *p; 37 | if (ns.find('.') != std::string::npos && (p = strchr(str, '.'))) 38 | database = std::string(str, p - str); 39 | return database; 40 | } 41 | 42 | long long repo::core::RepoCollStats::getCount() const 43 | { 44 | return getSize("count"); 45 | } 46 | 47 | std::string repo::core::RepoCollStats::getCollection() const 48 | { 49 | return getCollection(getNs()); 50 | } 51 | 52 | std::string repo::core::RepoCollStats::getCollection(const std::string& ns) 53 | { 54 | std::string collection = ns; 55 | const char *p; 56 | if (ns.find('.') != std::string::npos && (p = strchr(ns.c_str(), '.'))) 57 | collection = p + 1; 58 | return collection; 59 | } 60 | 61 | std::string repo::core::RepoCollStats::getNs() const 62 | { 63 | std::string ns; 64 | if(isOk()) 65 | ns = getField("ns").String(); 66 | return ns; 67 | } 68 | 69 | long long repo::core::RepoCollStats::getSize(const std::string& name) const 70 | { 71 | long long size = 0; 72 | if (isOk()) 73 | size = getField(name).safeNumberLong(); 74 | return size; 75 | } 76 | 77 | long long repo::core::RepoCollStats::getSize() const 78 | { 79 | return getSize("size"); 80 | } 81 | 82 | long long repo::core::RepoCollStats::getStorageSize() const 83 | { 84 | return getSize("storageSize"); 85 | } 86 | 87 | long long repo::core::RepoCollStats::getTotalIndexSize() const 88 | { 89 | return getSize("totalIndexSize"); 90 | } 91 | -------------------------------------------------------------------------------- /src/compute/repocsv.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repocsv.h" 20 | 21 | 22 | istream& repo::core::RepoCSV::readLine( 23 | istream& stream, 24 | std::list& tokenizedLine) 25 | { 26 | tokenizedLine.clear(); 27 | std::string line; 28 | getline(stream, line); 29 | std::stringstream ss(line); 30 | std::string field; 31 | while (std::getline(ss, field, delimiter)) 32 | tokenizedLine.push_back(field); 33 | return stream; 34 | } 35 | 36 | istream& repo::core::RepoCSV::readFile(istream& stream, 37 | std::list >& data) 38 | { 39 | data.clear(); 40 | std::list tokenizedLine; 41 | while(readLine(stream, tokenizedLine)) 42 | data.push_back(tokenizedLine); 43 | return stream; 44 | } 45 | 46 | repo::core::RepoNodeAbstractSet repo::core::RepoCSV::readMetadata( 47 | const std::string& path, 48 | std::list& headers, 49 | const char delimeter) 50 | { 51 | RepoNodeAbstractSet metadata; 52 | ifstream file(path); 53 | 54 | setDelimiter(delimeter); 55 | 56 | std::list tokens; 57 | while(file.good() && readLine(file, tokens)) 58 | { 59 | if (headers.empty()) 60 | headers = tokens; 61 | else if (!tokens.empty()) 62 | metadata.insert(new RepoNodeMetadata(headers, tokens, *tokens.begin())); 63 | } 64 | file.close(); 65 | return metadata; 66 | } 67 | 68 | void repo::core::RepoCSV::print(std::list > &matrix) 69 | { 70 | for (std::list line : matrix) 71 | { 72 | for (std::string token : line) 73 | std::cerr << token << ", "; 74 | std::cerr << std::endl; 75 | } 76 | } 77 | 78 | void repo::core::RepoCSV::print(RepoNodeAbstractSet& set) 79 | { 80 | for (const RepoNodeAbstract* node : set) 81 | { 82 | const RepoNodeMetadata* meta = dynamic_cast(node); 83 | std::cerr << (meta ? meta->toString(", ") : node->toString()) << std::endl; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/primitives/repostreambuffer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_STREAM_BUFFER_H 20 | #define REPO_STREAM_BUFFER_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "../repocoreglobal.h" 24 | #include "repoabstractlistener.h" 25 | //------------------------------------------------------------------------------ 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace repo { 32 | namespace core { 33 | 34 | 35 | //------------------------------------------------------------------------------ 36 | /*! 37 | * Basic logger buffer which redirects std::cout and std::cerr to a file 38 | * See: http://stackoverflow.com/questions/533038/redirect-stdcout-to-a-custom-writer 39 | * and http://www.mr-edd.co.uk/blog/beginners_guide_streambuf 40 | */ 41 | class REPO_CORE_EXPORT RepoStreamBuffer : public std::streambuf 42 | { 43 | 44 | public: 45 | 46 | /*! 47 | * Given a stream such as std::cout, std::cerr, std::clog, etc. reroutes 48 | * all messages to itself (this). 49 | */ 50 | RepoStreamBuffer( 51 | RepoAbstractListener *listener, 52 | std::ostream &stream); 53 | 54 | //! Resets the original buffer to the original stream and deletes detour. 55 | ~RepoStreamBuffer(); 56 | 57 | //! Returns redirected stream that replaces the original in the constructor. 58 | std::ostream &getRedirectStream() const; 59 | 60 | protected : 61 | 62 | //! Required override to enable capturing of the stream messages. 63 | virtual int overflow(int_type); 64 | 65 | //! Actual capture of the buffer plus any redirects. 66 | virtual std::streamsize xsputn(const char *msg, std::streamsize count); 67 | 68 | private : 69 | 70 | RepoAbstractListener *listener; 71 | 72 | //! Original buffer to reset on deconstructor. 73 | std::streambuf *originalBuffer; 74 | 75 | //! Original stream such as std::cout, std::cerr, std::clog, etc. 76 | std::ostream &originalStream; 77 | 78 | //! Replacement stream to push messages to the original output if desired. 79 | std::ostream *redirectStream; 80 | 81 | }; // end class 82 | 83 | } // end namespace core 84 | } // end namespace repo 85 | 86 | #endif // REPO_STREAM_BUFFER_H 87 | -------------------------------------------------------------------------------- /src/primitives/repo_binary.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_BINARY_H 20 | #define REPO_BINARY_H 21 | 22 | 23 | //------------------------------------------------------------------------------ 24 | #include "../repocoreglobal.h" 25 | #include "repobson.h" 26 | //------------------------------------------------------------------------------ 27 | 28 | #include 29 | #include 30 | 31 | namespace repo { 32 | namespace core { 33 | 34 | /*! 35 | * See http://www.iana.org/assignments/media-types/media-types.xhtml#image 36 | */ 37 | class REPO_CORE_EXPORT RepoBinary : public RepoBSON 38 | { 39 | 40 | public: 41 | 42 | RepoBinary() : RepoBSON() {} 43 | 44 | RepoBinary(const mongo::BSONObj &obj) : RepoBSON(obj) {} 45 | 46 | RepoBinary(const unsigned char* bytes, 47 | unsigned int bytesLength, 48 | const string &mediaType); 49 | 50 | RepoBinary(const std::string &fullFilePath, const std::string &mediaType); 51 | 52 | ~RepoBinary() {} 53 | 54 | //-------------------------------------------------------------------------- 55 | 56 | //! Returns a new full (and owned) copy of the object. 57 | inline RepoBinary copy() const { return RepoBinary(RepoBSON::copy()); } 58 | 59 | //-------------------------------------------------------------------------- 60 | 61 | //! Returns image data as a vector of bytes. 62 | std::vector getData() const; 63 | 64 | //! Returns the raw byte array pointer as well as the size of the array. 65 | const char* getData(int &length) const; 66 | 67 | //! Returns the media type of the image if set. 68 | std::string getMediaType() const 69 | { return getField(REPO_LABEL_MEDIA_TYPE).String(); } 70 | 71 | //! Returns a raw array pointer from a given vector. 72 | template 73 | static const T* toArray(const std::vector &vector) 74 | { return (const T*) &(vector.at(0)); } 75 | 76 | protected : 77 | 78 | bool populate(const unsigned char* bytes, 79 | unsigned int bytesLength, 80 | const string &mediaType); 81 | 82 | }; // end class 83 | 84 | } // end namespace core 85 | } // end namespace repo 86 | 87 | #endif // REPO_BINARY_H 88 | -------------------------------------------------------------------------------- /src/graph/repo_graph_history.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_graph_history.h" 19 | 20 | //------------------------------------------------------------------------------ 21 | // 22 | // Constructors 23 | // 24 | //------------------------------------------------------------------------------ 25 | 26 | repo::core::RepoGraphHistory::RepoGraphHistory( 27 | const std::vector& collection) : RepoGraphAbstract() 28 | { 29 | std::map nodesBySharedID; 30 | std::vector::const_iterator it; 31 | 32 | for (it = collection.begin(); it != collection.end(); ++it) 33 | { 34 | const mongo::BSONObj obj = *it; 35 | // for each (const mongo::BSONObj obj in collection) 36 | // { 37 | RepoNodeAbstract* node = NULL; 38 | 39 | std::string nodeType = obj.getField(REPO_NODE_LABEL_TYPE).str(); 40 | if (REPO_NODE_TYPE_REVISION == nodeType) 41 | { 42 | node = new RepoNodeRevision(obj); 43 | revisions.push_back(node); 44 | 45 | //------------------------------------------------------------------ 46 | // Root node has no parents. 47 | if (!obj.hasField(REPO_NODE_LABEL_PARENTS)) 48 | rootNode = node; 49 | } 50 | 51 | //---------------------------------------------------------------------- 52 | // Skips objects of unrecognized type 53 | if (NULL != node) 54 | { 55 | nodesByUniqueID.insert(std::make_pair(node->getUniqueID(), node)); 56 | nodesBySharedID.insert(std::make_pair(node->getSharedID(), node)); 57 | } 58 | } 59 | 60 | //-------------------------------------------------------------------------- 61 | // Build the parental graph. 62 | buildGraph(nodesBySharedID); 63 | } 64 | 65 | //------------------------------------------------------------------------------ 66 | // 67 | // Destructor 68 | // 69 | //------------------------------------------------------------------------------ 70 | 71 | repo::core::RepoGraphHistory::~RepoGraphHistory() 72 | { 73 | 74 | } 75 | 76 | //------------------------------------------------------------------------------ 77 | // 78 | // Export 79 | // 80 | //------------------------------------------------------------------------------ 81 | 82 | //------------------------------------------------------------------------------ 83 | // 84 | // Getters 85 | // 86 | //------------------------------------------------------------------------------ 87 | -------------------------------------------------------------------------------- /src/mongo/repogridfs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_GRID_FS 20 | #define REPO_GRID_FS 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "../repocoreglobal.h" 24 | #include "../conversion/repo_transcoder_bson.h" 25 | //------------------------------------------------------------------------------ 26 | #include // mongo c++ driver 27 | #include 28 | //------------------------------------------------------------------------------ 29 | #include // uuid class 30 | #include // generators 31 | #include // streaming operators etc 32 | //------------------------------------------------------------------------------ 33 | 34 | namespace repo { 35 | namespace core { 36 | 37 | /*! 38 | * Custom GridFS implementation to enable _id fields to be recorded as UUIDs 39 | * instead of Mongo's default ObjectIDs. 40 | * 41 | * See 42 | * http://docs.mongodb.org/manual/core/gridfs/ 43 | * 44 | * http://api.mongodb.org/cxx/current/classmongo_1_1_grid_f_s.html#aeec36f2e47a2f410cf6ea06589a8d1ad 45 | * 46 | * \brief The RepoGridFS class 47 | */ 48 | class REPO_CORE_EXPORT RepoGridFS : public mongo::GridFS 49 | { 50 | 51 | public: 52 | 53 | RepoGridFS(mongo::DBClientBase &clientConnection, 54 | const std::string &database, 55 | const std::string &project); 56 | 57 | ~RepoGridFS(); 58 | 59 | mongo::BSONObj storeFile( 60 | const std::string &fullFilePath, 61 | const boost::uuids::uuid &uuid = boost::uuids::random_generator()(), 62 | const std::string &remoteName = "", 63 | const std::string &contentType = ""); 64 | 65 | //! Returns chunks namespace as "database.project.chunks" 66 | static std::string getChunksNS(const std::string &database, 67 | const std::string &project); 68 | 69 | //! Returns files namespace as "database.project.files" 70 | static std::string getFilesNS(const std::string &database, 71 | const std::string &project); 72 | 73 | 74 | protected : 75 | 76 | //! client connection 77 | mongo::DBClientBase& clientConnection; 78 | 79 | //! database.project.chunks 80 | std::string chunksNS; 81 | 82 | //! database.project.files 83 | std::string filesNS; 84 | 85 | }; // end class 86 | 87 | } // end namespace core 88 | } // end namespace repo 89 | 90 | #endif // REPO_GRID_FS 91 | -------------------------------------------------------------------------------- /src/primitives/repocollstats.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_COLL_STATS_H 20 | #define REPO_COLL_STATS_H 21 | 22 | #include "../repocoreglobal.h" 23 | #include "repobson.h" 24 | 25 | namespace repo { 26 | namespace core { 27 | 28 | //! http://docs.mongodb.org/manual/reference/command/collStats/ 29 | class REPO_CORE_EXPORT RepoCollStats : public RepoBSON 30 | { 31 | 32 | public: 33 | 34 | //! Default constructor. 35 | RepoCollStats() : RepoBSON() {} 36 | 37 | //! Constructor from given bson document. 38 | RepoCollStats(const mongo::BSONObj &obj) : RepoBSON(obj) {} 39 | 40 | //! Empty destructor. 41 | ~RepoCollStats(); 42 | 43 | //-------------------------------------------------------------------------- 44 | 45 | //! Actual size on disk. 46 | long long getActualSizeOnDisk() const; 47 | 48 | //! Returns database from given namespace. 49 | static std::string getDatabase(const std::string& ns); 50 | 51 | //! Returns database. 52 | std::string getDatabase() const; 53 | 54 | //! Returns the number of objects or documents in this collection. 55 | long long getCount() const; 56 | 57 | //! Returns collection. 58 | std::string getCollection() const; 59 | 60 | //! Returns collection from given namespace. 61 | static std::string getCollection(const string &ns); 62 | 63 | //! Returns namespace. 64 | std::string getNs() const; 65 | 66 | //! Returns different sizes depending on name. 67 | long long getSize(const std::string& name) const; 68 | 69 | /*! 70 | * Returns the total size of all records in a collection. This value does 71 | * not include the record header, which is 16 bytes per record, but does 72 | * include the record’s padding. Additionally, size does not include 73 | * the size of any indexes associated with the collection, which the 74 | * totalIndexSize field reports. 75 | * 76 | * See http://docs.mongodb.org/manual/reference/command/collStats/#collStats.size 77 | */ 78 | long long getSize() const; 79 | 80 | /*! 81 | * Returns the total amount of storage allocated to this collection for 82 | * document storage. 83 | * 84 | * See: http://docs.mongodb.org/manual/reference/command/collStats/#collStats.storageSize 85 | */ 86 | long long getStorageSize() const; 87 | 88 | /*! 89 | * Returns the total size of all indexes. 90 | */ 91 | long long getTotalIndexSize() const; 92 | 93 | 94 | }; // end class 95 | 96 | } // end namespace core 97 | } // end namespace repo 98 | 99 | #endif // REPO_COLL_STATS_H 100 | -------------------------------------------------------------------------------- /src/graph/repo_graph_history.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_GRAPH_HISTORY_H 19 | #define REPO_GRAPH_HISTORY_H 20 | 21 | //------------------------------------------------------------------------------ 22 | #include "repo_graph_abstract.h" 23 | #include "repo_node_abstract.h" 24 | #include "repo_node_revision.h" 25 | //------------------------------------------------------------------------------ 26 | 27 | namespace repo { 28 | namespace core { 29 | 30 | //! 3D Repo scene graph as directed acyclic graph with single root node. 31 | class REPO_CORE_EXPORT RepoGraphHistory : public RepoGraphAbstract 32 | { 33 | 34 | public : 35 | 36 | //-------------------------------------------------------------------------- 37 | // 38 | // Constructors 39 | // 40 | //-------------------------------------------------------------------------- 41 | 42 | //! Empty default constructor so that it can be registered as a qmetatype. 43 | RepoGraphHistory() : RepoGraphAbstract() {} 44 | 45 | /*! 46 | * Constructs a graph from a collection of BSON objects. 47 | * 48 | * \sa RepoGraphScene(), ~RepoGraphScene() 49 | */ 50 | RepoGraphHistory(const std::vector &collection); 51 | 52 | //! Destructor for proper cleanup. 53 | /*! 54 | * \sa RepoGraphScene() 55 | */ 56 | ~RepoGraphHistory(); 57 | 58 | //-------------------------------------------------------------------------- 59 | // 60 | // Export 61 | // 62 | //-------------------------------------------------------------------------- 63 | 64 | 65 | //-------------------------------------------------------------------------- 66 | // 67 | // Getters 68 | // 69 | //-------------------------------------------------------------------------- 70 | 71 | //! Returns a vector of revision nodes. 72 | std::vector getRevisions() const { return revisions; } 73 | 74 | //! Returns the revision that is the be committed. 75 | RepoNodeRevision *getCommitRevision() const { return commitRevision; } 76 | 77 | //-------------------------------------------------------------------------- 78 | // 79 | // Setters 80 | // 81 | //-------------------------------------------------------------------------- 82 | 83 | //! Sets the revision that is to be committed. 84 | void setCommitRevision(RepoNodeRevision *commitRevision) 85 | { this->commitRevision = commitRevision; } 86 | 87 | protected : 88 | 89 | //! A vector of all revisions from all branches. 90 | std::vector revisions; 91 | 92 | //! Revision node that is to be committed. 93 | RepoNodeRevision *commitRevision; 94 | 95 | }; // end class 96 | 97 | } // end namespace core 98 | } // end namespace repo 99 | 100 | #endif // end REPO_GRAPH_HISTORY_H 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/compute/repocsv.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_CSV_H 20 | #define REPO_CSV_H 21 | 22 | #include 23 | #include 24 | #include // std::cout 25 | #include // std::ifstream 26 | #include 27 | #include 28 | //------------------------------------------------------------------------------ 29 | #include "../graph/repo_graph_scene.h" 30 | #include "../graph/repo_node_abstract.h" 31 | #include "../graph/repo_node_metadata.h" 32 | #include "../repocoreglobal.h" 33 | 34 | namespace repo { 35 | namespace core { 36 | 37 | 38 | //! Based on http://www.cplusplus.com/forum/general/17771/#msg89751 39 | class REPO_CORE_EXPORT RepoCSV 40 | { 41 | 42 | public: 43 | 44 | RepoCSV(char delimiter = ',') : delimiter(delimiter) {} 45 | 46 | ~RepoCSV() {} 47 | 48 | //-------------------------------------------------------------------------- 49 | 50 | //! Reads a single line. Same as operator>> but with class members access. 51 | istream& readLine(istream& stream, 52 | std::list &tokenizedLine); 53 | 54 | //! Reads the entire file. Same as operator>> but with class members access. 55 | istream& readFile( 56 | istream& stream, 57 | std::list >& data); 58 | 59 | //-------------------------------------------------------------------------- 60 | 61 | /*! 62 | * Load meta data from file 63 | */ 64 | 65 | RepoNodeAbstractSet readMetadata( 66 | const std::string& path, 67 | std::list& headers, 68 | const char delimeter = ','); 69 | 70 | /*! 71 | * if given headers list is empty, takes the first line as the headers. 72 | */ 73 | RepoNodeAbstractSet readMetadata( 74 | const std::string& path, 75 | const char delimeter = ',') 76 | { 77 | std::list tmp; 78 | return readMetadata(path, tmp, delimeter); 79 | } 80 | 81 | //! Returns the delimiter. 82 | char getDelimiter() const { return delimiter; } 83 | 84 | //! Sets the delimiter 85 | void setDelimiter(char delimiter) { this->delimiter = delimiter; } 86 | 87 | //-------------------------------------------------------------------------- 88 | // 89 | // Static helpers 90 | // 91 | //-------------------------------------------------------------------------- 92 | 93 | //! Debugging printing. 94 | static void print(std::list > &matrix); 95 | 96 | //! Debugging printing. 97 | static void print(RepoNodeAbstractSet& set); 98 | 99 | private : 100 | 101 | char delimiter; 102 | 103 | }; // end class 104 | 105 | 106 | } // end namespace core 107 | } // end namespace repo 108 | 109 | #endif // REPO_CSV_H 110 | -------------------------------------------------------------------------------- /src/mongo/repogridfs.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repogridfs.h" 20 | 21 | repo::core::RepoGridFS::RepoGridFS(mongo::DBClientBase &clientConnection, 22 | const std::string &database, 23 | const std::string &project) 24 | : GridFS(clientConnection, database, project) 25 | , clientConnection(clientConnection) 26 | , chunksNS(getChunksNS(database, project)) 27 | , filesNS(getFilesNS(database, project)) 28 | { 29 | // Force index 30 | // See http://docs.mongodb.org/manual/core/gridfs/#gridfs-index 31 | //-------------------------------------------------------------------------- 32 | // db.fs.chunks.createIndex( { files_id: 1, n: 1 }, { unique: true } ); 33 | clientConnection.ensureIndex(chunksNS, 34 | BSON("files_id" << 1 << "n" << 1), 35 | true, "files_id_1_n_1"); 36 | } 37 | 38 | repo::core::RepoGridFS::~RepoGridFS(){} 39 | 40 | mongo::BSONObj repo::core::RepoGridFS::storeFile( 41 | const std::string &fullFilePath, 42 | const boost::uuids::uuid &uuid, 43 | const std::string &remoteName, 44 | const std::string &contentType) 45 | { 46 | mongo::BSONObj originalOBJ = mongo::GridFS::storeFile(fullFilePath); 47 | 48 | //-------------------------------------------------------------------------- 49 | // Cannot update ID field in place, so reinsert and remove 50 | // See http://stackoverflow.com/questions/4012855/how-update-the-id-of-one-mongodb-document 51 | mongo::OID originalID = originalOBJ["_id"].OID(); 52 | 53 | //-------------------------------------------------------------------------- 54 | mongo::BSONObjBuilder b; 55 | RepoTranscoderBSON::append("_id", uuid, b); 56 | b.appendElementsUnique(originalOBJ); 57 | mongo::BSONObj newOBJ = b.obj(); 58 | clientConnection.insert(filesNS, 59 | newOBJ); 60 | clientConnection.remove(filesNS, 61 | QUERY("_id" << originalID)); 62 | 63 | //-------------------------------------------------------------------------- 64 | // Multi update chunks to represent new ID field 65 | clientConnection.update(chunksNS, 66 | QUERY("files_id" << originalID), 67 | BSON("$set" << RepoTranscoderBSON::uuidBSON("files_id", uuid)), 68 | false, // upsert 69 | true); // multi 70 | 71 | return newOBJ; 72 | } 73 | 74 | //------------------------------------------------------------------------------ 75 | // 76 | // Static helpers 77 | // 78 | //------------------------------------------------------------------------------ 79 | 80 | std::string repo::core::RepoGridFS::getChunksNS( 81 | const std::string &database, 82 | const std::string &project) 83 | { 84 | return "" + database + "." + project + ".chunks"; 85 | } 86 | 87 | std::string repo::core::RepoGridFS::getFilesNS( 88 | const std::string &database, 89 | const std::string &project) 90 | { 91 | return "" + database + "." + project + ".files"; 92 | } 93 | -------------------------------------------------------------------------------- /src/primitives/repo_binary.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_binary.h" 19 | 20 | repo::core::RepoBinary::RepoBinary(const unsigned char *bytes, 21 | unsigned int bytesLength, 22 | const string &mediaType) 23 | : RepoBSON() 24 | { 25 | populate(bytes, bytesLength, mediaType); 26 | } 27 | 28 | repo::core::RepoBinary::RepoBinary( 29 | const std::string &fullFilePath, 30 | const std::string &mediaType) 31 | { 32 | streampos size; 33 | char *memblock; 34 | 35 | ifstream file(fullFilePath, ios::in|ios::binary|ios::ate); 36 | if (file.is_open()) 37 | { 38 | size = file.tellg(); 39 | memblock = new char[size]; 40 | file.seekg (0, ios::beg); 41 | file.read(memblock, size); 42 | file.close(); 43 | 44 | //---------------------------------------------------------------------- 45 | // Write the data to this bson object 46 | populate((unsigned char *)(memblock), size, mediaType); 47 | 48 | delete[] memblock; 49 | } 50 | else 51 | std::cerr << "Unable to open file " << fullFilePath << std::endl; 52 | 53 | } 54 | 55 | 56 | std::vector repo::core::RepoBinary::getData() const 57 | { 58 | std::vector ret; 59 | int length = 0; 60 | const char* data = getData(length); 61 | if (data) 62 | ret = std::vector(data, data + length); 63 | return ret; 64 | } 65 | 66 | const char *repo::core::RepoBinary::getData(int &length) const 67 | { 68 | mongo::BSONElement bse; 69 | const char* data; 70 | if (hasField(REPO_LABEL_DATA) && 71 | mongo::BSONType::BinData == (bse = getField(REPO_LABEL_DATA)).type()) 72 | data = bse.binData(length); 73 | return data; 74 | } 75 | 76 | bool repo::core::RepoBinary::populate( 77 | const unsigned char* bytes, 78 | unsigned int bytesLength, 79 | const string &mediaType) 80 | { 81 | mongo::BSONObjBuilder builder; 82 | //-------------------------------------------------------------------------- 83 | // ID 84 | RepoTranscoderBSON::append( 85 | REPO_LABEL_ID, 86 | boost::uuids::random_generator()(), 87 | builder); 88 | 89 | //-------------------------------------------------------------------------- 90 | // Binary data 91 | if (bytes && bytesLength) 92 | builder.appendBinData( 93 | REPO_LABEL_DATA, 94 | bytesLength, 95 | mongo::BinDataGeneral, 96 | bytes); 97 | 98 | //-------------------------------------------------------------------------- 99 | // Media Type 100 | if (!mediaType.empty()) 101 | builder << REPO_LABEL_MEDIA_TYPE << mediaType; 102 | 103 | //-------------------------------------------------------------------------- 104 | // Add to the parent object 105 | mongo::BSONObj builtObj = builder.obj(); 106 | return (bool)(RepoBSON::addFields(builtObj)); 107 | } 108 | 109 | 110 | -------------------------------------------------------------------------------- /src/graph/repo_bounding_box.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_bounding_box.h" 19 | 20 | #include 21 | 22 | repo::core::RepoBoundingBox::RepoBoundingBox(const aiMesh * mesh) 23 | { 24 | if (mesh->mNumVertices) 25 | { 26 | min = RepoVertex(mesh->mVertices[0]); 27 | max = RepoVertex(mesh->mVertices[0]); 28 | } 29 | 30 | for (unsigned int i = 0; i < mesh->mNumVertices; ++i) 31 | { 32 | RepoVertex tmp = RepoVertex(mesh->mVertices[i]); 33 | 34 | min.x = std::min(min.x,tmp.x); 35 | min.y = std::min(min.y,tmp.y); 36 | min.z = std::min(min.z,tmp.z); 37 | 38 | max.x = std::max(max.x,tmp.x); 39 | max.y = std::max(max.y,tmp.y); 40 | max.z = std::max(max.z,tmp.z); 41 | } 42 | } 43 | 44 | repo::core::RepoBoundingBox::RepoBoundingBox(const std::vector &vertices) 45 | { 46 | if (vertices.size()) 47 | { 48 | min = vertices[0]; 49 | max = vertices[0]; 50 | } 51 | 52 | for (unsigned int i = 0; i < vertices.size(); ++i) 53 | { 54 | aiVector3D tmp = vertices[i]; 55 | 56 | min.x = std::min(min.x,tmp.x); 57 | min.y = std::min(min.y,tmp.y); 58 | min.z = std::min(min.z,tmp.z); 59 | 60 | max.x = std::max(max.x,tmp.x); 61 | max.y = std::max(max.y,tmp.y); 62 | max.z = std::max(max.z,tmp.z); 63 | } 64 | } 65 | 66 | bool repo::core::RepoBoundingBox::operator==(const RepoBoundingBox& other) const 67 | { 68 | return this->getMin() == other.getMin() && 69 | this->getMax() == other.getMax(); 70 | } 71 | 72 | std::vector repo::core::RepoBoundingBox::toVector() const 73 | { 74 | std::vector vec; 75 | vec.push_back(min); 76 | vec.push_back(max); 77 | return vec; 78 | } 79 | 80 | 81 | void repo::core::RepoBoundingBox::toOutline( 82 | std::vector> * vec) const 83 | { 84 | vec->push_back(aiVector2t(min.x, min.y)); 85 | vec->push_back(aiVector2t(max.x, min.y)); 86 | vec->push_back(aiVector2t(max.x, max.y)); 87 | vec->push_back(aiVector2t(min.x, max.y)); 88 | } 89 | 90 | 91 | std::vector repo::core::RepoBoundingBox::getTransformationMatrix() const 92 | { 93 | std::vector transformation(16); 94 | 95 | RepoVertex centroid = RepoVertex(max+min); 96 | 97 | transformation[0] = 1; 98 | transformation[1] = 0; 99 | transformation[2] = 0; 100 | transformation[3] = 0; 101 | 102 | transformation[4] = 0; 103 | transformation[5] = 1; 104 | transformation[6] = 0; 105 | transformation[7] = 0; 106 | 107 | transformation[8] = 0; 108 | transformation[9] = 0; 109 | transformation[10] = 1; 110 | transformation[11] = 0; 111 | 112 | transformation[12] = centroid.x/2; 113 | transformation[13] = centroid.y/2; 114 | transformation[14] = centroid.z/2; 115 | transformation[15] = 1; 116 | 117 | return transformation; 118 | } 119 | 120 | aiMatrix4x4 repo::core::RepoBoundingBox::getTranslationMatrix() const 121 | { 122 | RepoVertex centroid = RepoVertex(max+min); 123 | aiMatrix4x4 tmp; 124 | 125 | return aiMatrix4x4::Translation(aiVector3D(centroid.x/2, centroid.y/2, centroid.z/2), tmp); 126 | } 127 | -------------------------------------------------------------------------------- /src/primitives/repobson.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_BSON_H 20 | #define REPO_BSON_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include // the MongoDB driver 24 | //------------------------------------------------------------------------------ 25 | #include "../conversion/repo_transcoder_bson.h" 26 | #include "../conversion/repo_transcoder_string.h" 27 | //------------------------------------------------------------------------------ 28 | #include "../repocoreglobal.h" 29 | 30 | namespace repo { 31 | namespace core { 32 | 33 | //! Available commands. 34 | enum REPO_CORE_EXPORT RepoBSONCommands { CREATE, DROP, UPDATE }; 35 | 36 | class REPO_CORE_EXPORT RepoBSON : public mongo::BSONObj 37 | { 38 | 39 | public: 40 | 41 | //! Default empty constructor. 42 | RepoBSON() : mongo::BSONObj() {} 43 | 44 | //! Constructor from Mongo BSON object. 45 | RepoBSON(const mongo::BSONObj &obj) : mongo::BSONObj(obj) {} 46 | 47 | //! Constructor from Mongo BSON object builder. 48 | RepoBSON(mongo::BSONObjBuilder &builder) : mongo::BSONObj(builder.obj()) {} 49 | 50 | //! Default empty destructor. 51 | ~RepoBSON() {} 52 | 53 | //-------------------------------------------------------------------------- 54 | 55 | /*! 56 | * Adds all fields from the given object to this bson if empty. Returns 57 | * true if successful, and false otherwise (eg when non-empty or not owned). 58 | */ 59 | int addFields(mongo::BSONObj &obj); 60 | 61 | //! Returns a new full (and owned) copy of the object. 62 | inline RepoBSON copy() const { return RepoBSON(mongo::BSONObj::copy()); } 63 | 64 | /*! 65 | * Returns a drop db.runCommand bson object by _id field. If _id is not set, 66 | * returns empty object. 67 | * 68 | * See http://docs.mongodb.org/manual/reference/command/delete/#dbcmd.delete 69 | */ 70 | virtual RepoBSON drop(const std::string &collection) const; 71 | 72 | //-------------------------------------------------------------------------- 73 | // 74 | // Getters 75 | // 76 | //-------------------------------------------------------------------------- 77 | 78 | //! Given an array, returns a list of pairs stored as given labels if any. 79 | static std::list > getArrayStringPairs( 80 | const mongo::BSONElement &arrayElement, 81 | const std::string &fstLabel, 82 | const std::string &sndLabel); 83 | 84 | //! Returns an embedded element by label, EOO if not present. 85 | mongo::BSONElement getEmbeddedElement( 86 | const std::string &fstLevelLabel, 87 | const std::string &sndLevelLabel) const; 88 | 89 | //! Returns true if it is valid and not empty, false otherwise. 90 | bool isOk() const { return isValid() && !isEmpty(); } 91 | 92 | static mongo::BSONArray toArray(const std::list > &list, 93 | const std::string &fstLabel, 94 | const std::string &sndLabel); 95 | 96 | }; // end class 97 | 98 | } // end namespace core 99 | } // end namespace repo 100 | 101 | #endif // REPO_BSON_H 102 | -------------------------------------------------------------------------------- /src/repologger.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_LOGGER_H 20 | #define REPO_LOGGER_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "repocoreglobal.h" 24 | #include "primitives/repoabstractlistener.h" 25 | #include "primitives/repoabstractnotifier.h" 26 | #include "primitives/repostreambuffer.h" 27 | #include "primitives/reposeverity.h" 28 | 29 | //------------------------------------------------------------------------------ 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | namespace repo { 40 | namespace core { 41 | 42 | //------------------------------------------------------------------------------ 43 | /*! 44 | * Singleton logger which redirects std::cout and std::cerr to a file. 45 | * See: http://stackoverflow.com/questions/533038/redirect-stdcout-to-a-custom-writer 46 | */ 47 | class REPO_CORE_EXPORT RepoLogger 48 | : public RepoAbstractListener 49 | , public RepoAbstractNotifier 50 | { 51 | 52 | private : 53 | 54 | //! Singleton constructor redirects std::cout and std::cerr to itself. 55 | RepoLogger(); 56 | 57 | //! Singleton destructor removes all stream buffers. 58 | ~RepoLogger(); 59 | 60 | //! Singleton copy constructor. 61 | RepoLogger(const RepoLogger &); 62 | 63 | //! Singleton comparator. 64 | void operator = (RepoLogger const&); 65 | 66 | public : 67 | 68 | //! Returns a singleton instance of the logger class. 69 | static RepoLogger &instance(); 70 | 71 | //! Returns a formatted log message. 72 | std::string getHtmlFormattedMessage( 73 | const std::string &message, 74 | const RepoSeverity &severity) const; 75 | 76 | //! Returns a log filename based on the current date. 77 | std::string getFilename( 78 | const std::string &extension = DEFAULT_LOG_EXTENSION); 79 | 80 | //! Returns a full cannonical path to the log file. 81 | std::string getFullFilePath(); 82 | 83 | //! Returns a current working directory where the log file is located. 84 | std::string getWorkingDirectory(); 85 | 86 | //! Intercepts stream messages such as from std::cout 87 | void messageGenerated( 88 | const std::ostream *sender, 89 | const std::string &message); 90 | 91 | //! Logs a message using given severity level. 92 | void log(const std::string &message, 93 | const RepoSeverity &severity = RepoSeverity::REPO_INFO); 94 | 95 | //! Returns a 2-digit representation of a number by pre-pending 0 if needed. 96 | static std::string normalize(int); 97 | 98 | private: 99 | 100 | //! Name of the currently set filename together with the extension 101 | std::string filename; 102 | 103 | //! Log file 104 | std::ofstream logFile; 105 | 106 | //! Default log file extension ".log" 107 | static const std::string DEFAULT_LOG_EXTENSION; 108 | 109 | //! Cout stream buffer that is being redirected by the logger. 110 | RepoStreamBuffer * coutStreamBuffer; 111 | 112 | //! Cerr stream buffer that is being redirected by the logger. 113 | RepoStreamBuffer * cerrStreamBuffer; 114 | 115 | 116 | }; // end class 117 | 118 | } // end namespace core 119 | } // end namespace repo 120 | 121 | #endif // REPO_LOGGER_H 122 | -------------------------------------------------------------------------------- /src/primitives/repobson.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repobson.h" 20 | 21 | //------------------------------------------------------------------------------ 22 | 23 | int repo::core::RepoBSON::addFields(mongo::BSONObj &obj) 24 | { 25 | int success = 0; 26 | if (isEmpty() && !isOwned()) 27 | { 28 | std::set fields; 29 | obj.getFieldNames(fields); 30 | success = mongo::BSONObj::addFields(obj, fields); 31 | } 32 | return success; 33 | } 34 | 35 | repo::core::RepoBSON repo::core::RepoBSON::drop(const std::string &collection) const 36 | { 37 | mongo::BSONObjBuilder builder; 38 | 39 | if (hasField(REPO_LABEL_ID)) 40 | { 41 | //---------------------------------------------------------------------- 42 | // Delete 43 | builder << REPO_COMMAND_DELETE << collection; 44 | 45 | //---------------------------------------------------------------------- 46 | // Deletes 47 | mongo::BSONObjBuilder deletesBuilder; 48 | deletesBuilder << REPO_COMMAND_Q << BSON(REPO_LABEL_ID << this->getField(REPO_LABEL_ID)); 49 | deletesBuilder << REPO_COMMAND_LIMIT << 1; 50 | builder << REPO_COMMAND_DELETES << BSON_ARRAY(deletesBuilder.obj()); 51 | } 52 | return builder.obj(); 53 | } 54 | 55 | std::list > repo::core::RepoBSON::getArrayStringPairs( 56 | const mongo::BSONElement &arrayElement, 57 | const std::string &fstLabel, 58 | const std::string &sndLabel) 59 | { 60 | std::list > list; 61 | if (!arrayElement.eoo()) 62 | { 63 | std::vector array = arrayElement.Array(); 64 | for (unsigned int i = 0; i < array.size(); ++i) 65 | { 66 | if (array[i].type() == mongo::BSONType::Object) 67 | { 68 | mongo::BSONObj obj = array[i].embeddedObject(); 69 | if (obj.hasField(fstLabel) && obj.hasField(sndLabel)) 70 | { 71 | std::string field1 = obj.getField(fstLabel).String(); 72 | std::string field2 = obj.getField(sndLabel).String(); 73 | list.push_back(std::make_pair(field1, field2)); 74 | } 75 | } 76 | } 77 | } 78 | return list; 79 | } 80 | 81 | mongo::BSONElement repo::core::RepoBSON::getEmbeddedElement( 82 | const std::string &fstLevelLabel, 83 | const std::string &sndLevelLabel) const 84 | { 85 | mongo::BSONElement element; 86 | if (this->hasField(fstLevelLabel)) 87 | { 88 | mongo::BSONObj embeddedData = this->getObjectField(fstLevelLabel); 89 | if (embeddedData.hasField(sndLevelLabel)) 90 | element = embeddedData.getField(sndLevelLabel); 91 | } 92 | return element; 93 | } 94 | 95 | mongo::BSONArray repo::core::RepoBSON::toArray( 96 | const std::list > &list, 97 | const std::string &fstLabel, 98 | const std::string &sndLabel) 99 | { 100 | mongo::BSONArrayBuilder builder; 101 | std::list >::const_iterator i; 102 | for (i = list.begin(); i != list.end(); ++i) 103 | { 104 | mongo::BSONObjBuilder innerBuilder; 105 | innerBuilder << fstLabel << i->first; 106 | innerBuilder << sndLabel << i->second; 107 | builder.append(innerBuilder.obj()); 108 | } 109 | return builder.arr(); 110 | } 111 | -------------------------------------------------------------------------------- /src/primitives/reposeverity.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_SEVERITY_H 20 | #define REPO_SEVERITY_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "../repocoreglobal.h" 24 | 25 | //------------------------------------------------------------------------------ 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace repo { 33 | namespace core { 34 | 35 | /*! 36 | * Repo severity levels according to RFC 5424, the SysLog protocol. 37 | * See http://tools.ietf.org/html/rfc5424 38 | */ 39 | class REPO_CORE_EXPORT RepoSeverity 40 | { 41 | 42 | 43 | public : 44 | 45 | typedef enum 46 | { 47 | REPO_PANIC_NUM = 7, 48 | REPO_ALERT_NUM = 6, 49 | REPO_CRITICAL_NUM = 5, 50 | REPO_ERROR_NUM = 4, 51 | REPO_WARNING_NUM = 3, 52 | REPO_NOTICE_NUM = 2, 53 | REPO_INFO_NUM = 1, 54 | REPO_DEBUG_NUM = 0 55 | } Level; 56 | 57 | private: 58 | 59 | //! Private constructor. 60 | RepoSeverity(const std::string &color, const std::string &level, int); 61 | 62 | public : 63 | 64 | //! Default constructor creates INFO-level severity. 65 | RepoSeverity(); 66 | 67 | //! Equality comparison based on the underlying severity level strings. 68 | inline bool operator==(const RepoSeverity &s) const 69 | { return 70 | this->color == s.color && 71 | this->level == s.level && 72 | this->value == s.value; } 73 | 74 | //! Orders severity levels in descending order from PANIC to DEBUG 75 | inline bool operator<(const RepoSeverity &s) const 76 | { return this->value < s.value; } 77 | 78 | //! Enable streaming of the severity level string representation. 79 | friend std::ostream& operator<<(std::ostream& os, const RepoSeverity &s) 80 | { os << s.toString(); return os; } 81 | 82 | //! Returns a string representation of the severity level. 83 | std::string toString() const { return level; } 84 | 85 | //! Returns the color associated with this severity level. 86 | std::string getColor() const { return color;} 87 | 88 | //! Returns numerical value of the severity. 89 | int getValue() const { return value; } 90 | 91 | /*! 92 | * Returns an integer representation of the severity level to use with 93 | * swtich statements. \sa Level 94 | */ 95 | operator int() const { return value; } 96 | 97 | //! System is unusable. 98 | static const RepoSeverity REPO_PANIC; 99 | 100 | //! Action must be taken immediately. 101 | static const RepoSeverity REPO_ALERT; 102 | 103 | //! Critical conditions. 104 | static const RepoSeverity REPO_CRITICAL; 105 | 106 | //! Error conditions. 107 | static const RepoSeverity REPO_ERROR; 108 | 109 | //! Warning conditions. 110 | static const RepoSeverity REPO_WARNING; 111 | 112 | //! Normal but significant conditions. 113 | static const RepoSeverity REPO_NOTICE; 114 | 115 | //! Informational message. 116 | static const RepoSeverity REPO_INFO; 117 | 118 | //! Debug-level message. 119 | static const RepoSeverity REPO_DEBUG; 120 | 121 | private: 122 | 123 | //! Color assigned to the severity level. 124 | std::string color; 125 | 126 | //! String representation of the severity level. 127 | std::string level; 128 | 129 | //! Integer representation of the severity level. 130 | int value; 131 | 132 | }; // end class 133 | 134 | } // end namespace core 135 | } // end namespace repo 136 | 137 | #endif // REPO_SEVERITY_H 138 | -------------------------------------------------------------------------------- /src/conversion/repo_transcoder_string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_TRANSCODER_STRING_H 20 | #define REPO_TRANSCODER_STRING_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | //----------------------------------------------------------------------------- 29 | #include 30 | #include 31 | #include // streaming operators etc 32 | #include 33 | //----------------------------------------------------------------------------- 34 | #include "assimp/scene.h" 35 | //----------------------------------------------------------------------------- 36 | 37 | 38 | #include "../repocoreglobal.h" 39 | 40 | namespace repo { 41 | namespace core { 42 | 43 | class REPO_CORE_EXPORT RepoTranscoderString 44 | { 45 | 46 | public : 47 | 48 | //! Returns a valid uuid out of a string. 49 | /*! 50 | * Returns a valid uuid representation of a given string. If empty, returns 51 | * a randomly generated uuid. If the string is not a uuid representation, 52 | * the string is hashed and appended with given suffix to prevent 53 | * uuid clashes in cases where two objects such as a mesh and a 54 | * transformation share the same name. 55 | * 56 | * \param text Can be any string including a valid UUID representation 57 | * without '{' and '}'. 58 | * \param suffix Numerical suffix to prevent name clashes, eg "01". 59 | * \return valid uuid 60 | */ 61 | static boost::uuids::uuid stringToUUID( 62 | const std::string text, 63 | const std::string suffix = std::string()); 64 | 65 | //------------------------------------------------------------------------- 66 | // 67 | // To string conversion 68 | // 69 | //------------------------------------------------------------------------- 70 | 71 | //! Returns a string representation of a given value. 72 | template 73 | static std::string toString(T value) 74 | { 75 | std::stringstream sstr; 76 | sstr << value; 77 | return sstr.str(); 78 | } 79 | 80 | //! Returns a compact string representation of a given vector. 81 | /*! 82 | * Returns a compacted string representation of a given vector 83 | * as [toString(0) ... toString(n)] where only the very first and the very 84 | * last elements are displayed. 85 | * \sa toString() 86 | */ 87 | template 88 | static std::string toString(const std::vector & vec) 89 | { 90 | std::string str; 91 | if (vec.size() > 0) 92 | { 93 | str += "[" + toString(vec.at(0)); 94 | if (vec.size() > 1) 95 | str += ", ..., " + toString(vec.at(vec.size()-1)); 96 | str += "]"; 97 | } 98 | return str; 99 | } 100 | 101 | //! Returns a string "[x, y]" of a given float vertex. 102 | template 103 | static std::string toString(const aiVector2t &v) 104 | { 105 | return "[" + toString(v.x) + ", " + toString(v.y) + "]"; 106 | } 107 | 108 | //! Returns a string "[x, y, z]" of a given float vertex. 109 | template 110 | static std::string toString(const aiVector3t &v) 111 | { 112 | return "[" + toString(v.x) + ", " + toString(v.y) + ", " + 113 | toString(v.z) + "]"; 114 | } 115 | 116 | //! Returns a string "[a, b, ..., z]" of a given face. 117 | static std::string toString(const aiFace &f); 118 | 119 | //! Converts uuid to string. 120 | static std::string toString(const boost::uuids::uuid &uuid); 121 | 122 | }; // end class 123 | 124 | } // end namespace core 125 | } // end namespace repo 126 | 127 | #endif // end REPO_TRANSCODER_STRING_H 128 | -------------------------------------------------------------------------------- /src/graph/repo_bounding_box.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_BOUNDING_BOX_H 19 | #define REPO_BOUNDING_BOX_H 20 | //----------------------------------------------------------------------------- 21 | #include 22 | #include 23 | //----------------------------------------------------------------------------- 24 | #include "assimp/scene.h" 25 | #include "../repocoreglobal.h" 26 | #include "../primitives/repo_vertex.h" 27 | 28 | namespace repo { 29 | namespace core { 30 | 31 | 32 | //! Axis-aligned bounding box represented as a min and max vertices 33 | class REPO_CORE_EXPORT RepoBoundingBox 34 | { 35 | 36 | public : 37 | 38 | //! Basic constructor, initialized with max float for min and vice versa. 39 | inline RepoBoundingBox() : 40 | min(std::numeric_limits::max(), 41 | std::numeric_limits::max(), 42 | std::numeric_limits::max()), 43 | max(- std::numeric_limits::max(), 44 | - std::numeric_limits::max(), 45 | - std::numeric_limits::max()) {} 46 | 47 | /*! 48 | * Constructs a bounding box out of a mesh as the most min and most max 49 | * vertices. 50 | */ 51 | RepoBoundingBox(const aiMesh *); 52 | 53 | /*! 54 | * Constructs a bounding box from given vector of vertices. 55 | */ 56 | RepoBoundingBox(const std::vector &vertices); 57 | 58 | RepoBoundingBox(const RepoVertex& min, const RepoVertex& max) 59 | : min(min) 60 | , max(max) {} 61 | 62 | //! Empty destructor 63 | inline ~RepoBoundingBox() {} 64 | 65 | //-------------------------------------------------------------------------- 66 | // 67 | // Operators 68 | // 69 | //-------------------------------------------------------------------------- 70 | 71 | //! Returns true if the given bounding box is identical, false otherwise. 72 | virtual bool operator==(const RepoBoundingBox&) const; 73 | 74 | friend std::ostream& operator<<(std::ostream& os, const RepoBoundingBox &b) 75 | { 76 | os << RepoVertex(b.min) << ", " << RepoVertex(b.max); 77 | return os; 78 | } 79 | 80 | //-------------------------------------------------------------------------- 81 | 82 | //! Returns a vector representation as [min, max]. 83 | std::vector toVector() const; 84 | 85 | //! Returns a polygon outline as a bounding rectangle in XY plane. 86 | void toOutline(std::vector > * vec) const; 87 | 88 | 89 | //-------------------------------------------------------------------------- 90 | // 91 | // Setters 92 | // 93 | //-------------------------------------------------------------------------- 94 | 95 | void setMin(const RepoVertex &min) { this->min = min; } 96 | 97 | void setMin(const aiVector3D& min) { setMin(RepoVertex(min)); } 98 | 99 | void setMax(const RepoVertex &max) { this->max = max; } 100 | 101 | void setMax(const aiVector3D& max) { setMax(RepoVertex(max)); } 102 | 103 | //-------------------------------------------------------------------------- 104 | // 105 | // Getters 106 | // 107 | //-------------------------------------------------------------------------- 108 | 109 | 110 | aiVector3D getMin() const { return min; } 111 | 112 | aiVector3D getMax() const { return max; } 113 | 114 | double getLengthX() const { return max.x - min.x; } 115 | 116 | double getLengthY() const { return max.y - min.y; } 117 | 118 | double getLengthZ() const { return max.z - min.z; } 119 | 120 | //! Returns transformation matrix suitable for GLC Lib. 121 | std::vector getTransformationMatrix() const; 122 | 123 | aiMatrix4x4 getTranslationMatrix() const; 124 | 125 | private : 126 | 127 | aiVector3D min; //!< min bounding box vertex 128 | 129 | aiVector3D max; //!< max bounding box vertex 130 | 131 | }; // end class 132 | 133 | } // end namespace core 134 | } // end namespace repo 135 | 136 | #endif // end REPO_BOUNDING_BOX_H 137 | -------------------------------------------------------------------------------- /src/sha256/sha256.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sha256.h" 4 | 5 | const unsigned int SHA256::sha256_k[64] = //UL = uint32 6 | {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 7 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 8 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 9 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 10 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 11 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 12 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 13 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 14 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 15 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 16 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 17 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 18 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 19 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 20 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 21 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; 22 | 23 | void SHA256::transform(const unsigned char *message, unsigned int block_nb) 24 | { 25 | uint32 w[64]; 26 | uint32 wv[8]; 27 | uint32 t1, t2; 28 | const unsigned char *sub_block; 29 | int i; 30 | int j; 31 | for (i = 0; i < (int) block_nb; i++) { 32 | sub_block = message + (i << 6); 33 | for (j = 0; j < 16; j++) { 34 | SHA2_PACK32(&sub_block[j << 2], &w[j]); 35 | } 36 | for (j = 16; j < 64; j++) { 37 | w[j] = SHA256_F4(w[j - 2]) + w[j - 7] + SHA256_F3(w[j - 15]) + w[j - 16]; 38 | } 39 | for (j = 0; j < 8; j++) { 40 | wv[j] = m_h[j]; 41 | } 42 | for (j = 0; j < 64; j++) { 43 | t1 = wv[7] + SHA256_F2(wv[4]) + SHA2_CH(wv[4], wv[5], wv[6]) 44 | + sha256_k[j] + w[j]; 45 | t2 = SHA256_F1(wv[0]) + SHA2_MAJ(wv[0], wv[1], wv[2]); 46 | wv[7] = wv[6]; 47 | wv[6] = wv[5]; 48 | wv[5] = wv[4]; 49 | wv[4] = wv[3] + t1; 50 | wv[3] = wv[2]; 51 | wv[2] = wv[1]; 52 | wv[1] = wv[0]; 53 | wv[0] = t1 + t2; 54 | } 55 | for (j = 0; j < 8; j++) { 56 | m_h[j] += wv[j]; 57 | } 58 | } 59 | } 60 | 61 | void SHA256::init() 62 | { 63 | m_h[0] = 0x6a09e667; 64 | m_h[1] = 0xbb67ae85; 65 | m_h[2] = 0x3c6ef372; 66 | m_h[3] = 0xa54ff53a; 67 | m_h[4] = 0x510e527f; 68 | m_h[5] = 0x9b05688c; 69 | m_h[6] = 0x1f83d9ab; 70 | m_h[7] = 0x5be0cd19; 71 | m_len = 0; 72 | m_tot_len = 0; 73 | } 74 | 75 | void SHA256::update(const unsigned char *message, unsigned int len) 76 | { 77 | unsigned int block_nb; 78 | unsigned int new_len, rem_len, tmp_len; 79 | const unsigned char *shifted_message; 80 | tmp_len = SHA224_256_BLOCK_SIZE - m_len; 81 | rem_len = len < tmp_len ? len : tmp_len; 82 | memcpy(&m_block[m_len], message, rem_len); 83 | if (m_len + len < SHA224_256_BLOCK_SIZE) { 84 | m_len += len; 85 | return; 86 | } 87 | new_len = len - rem_len; 88 | block_nb = new_len / SHA224_256_BLOCK_SIZE; 89 | shifted_message = message + rem_len; 90 | transform(m_block, 1); 91 | transform(shifted_message, block_nb); 92 | rem_len = new_len % SHA224_256_BLOCK_SIZE; 93 | memcpy(m_block, &shifted_message[block_nb << 6], rem_len); 94 | m_len = rem_len; 95 | m_tot_len += (block_nb + 1) << 6; 96 | } 97 | 98 | void SHA256::final(unsigned char *digest) 99 | { 100 | unsigned int block_nb; 101 | unsigned int pm_len; 102 | unsigned int len_b; 103 | int i; 104 | block_nb = (1 + ((SHA224_256_BLOCK_SIZE - 9) 105 | < (m_len % SHA224_256_BLOCK_SIZE))); 106 | len_b = (m_tot_len + m_len) << 3; 107 | pm_len = block_nb << 6; 108 | memset(m_block + m_len, 0, pm_len - m_len); 109 | m_block[m_len] = 0x80; 110 | SHA2_UNPACK32(len_b, m_block + pm_len - 4); 111 | transform(m_block, block_nb); 112 | for (i = 0 ; i < 8; i++) { 113 | SHA2_UNPACK32(m_h[i], &digest[i << 2]); 114 | } 115 | } 116 | 117 | std::string sha256(std::string input) 118 | { 119 | unsigned char digest[SHA256::DIGEST_SIZE]; 120 | memset(digest,0,SHA256::DIGEST_SIZE); 121 | 122 | SHA256 ctx = SHA256(); 123 | ctx.init(); 124 | ctx.update( (unsigned char*)input.c_str(), input.length()); 125 | ctx.final(digest); 126 | 127 | char buf[2*SHA256::DIGEST_SIZE+1]; 128 | buf[2*SHA256::DIGEST_SIZE] = 0; 129 | for (int i = 0; i < SHA256::DIGEST_SIZE; i++) 130 | sprintf(buf+i*2, "%02x", digest[i]); 131 | return std::string(buf); 132 | } 133 | -------------------------------------------------------------------------------- /src/graph/sha256/sha256.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sha256.h" 4 | 5 | const unsigned int SHA256::sha256_k[64] = //UL = uint32 6 | {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 7 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 8 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 9 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 10 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 11 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 12 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 13 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 14 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 15 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 16 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 17 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 18 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 19 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 20 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 21 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; 22 | 23 | void SHA256::transform(const unsigned char *message, unsigned int block_nb) 24 | { 25 | uint32 w[64]; 26 | uint32 wv[8]; 27 | uint32 t1, t2; 28 | const unsigned char *sub_block; 29 | int i; 30 | int j; 31 | for (i = 0; i < (int) block_nb; i++) { 32 | sub_block = message + (i << 6); 33 | for (j = 0; j < 16; j++) { 34 | SHA2_PACK32(&sub_block[j << 2], &w[j]); 35 | } 36 | for (j = 16; j < 64; j++) { 37 | w[j] = SHA256_F4(w[j - 2]) + w[j - 7] + SHA256_F3(w[j - 15]) + w[j - 16]; 38 | } 39 | for (j = 0; j < 8; j++) { 40 | wv[j] = m_h[j]; 41 | } 42 | for (j = 0; j < 64; j++) { 43 | t1 = wv[7] + SHA256_F2(wv[4]) + SHA2_CH(wv[4], wv[5], wv[6]) 44 | + sha256_k[j] + w[j]; 45 | t2 = SHA256_F1(wv[0]) + SHA2_MAJ(wv[0], wv[1], wv[2]); 46 | wv[7] = wv[6]; 47 | wv[6] = wv[5]; 48 | wv[5] = wv[4]; 49 | wv[4] = wv[3] + t1; 50 | wv[3] = wv[2]; 51 | wv[2] = wv[1]; 52 | wv[1] = wv[0]; 53 | wv[0] = t1 + t2; 54 | } 55 | for (j = 0; j < 8; j++) { 56 | m_h[j] += wv[j]; 57 | } 58 | } 59 | } 60 | 61 | void SHA256::init() 62 | { 63 | m_h[0] = 0x6a09e667; 64 | m_h[1] = 0xbb67ae85; 65 | m_h[2] = 0x3c6ef372; 66 | m_h[3] = 0xa54ff53a; 67 | m_h[4] = 0x510e527f; 68 | m_h[5] = 0x9b05688c; 69 | m_h[6] = 0x1f83d9ab; 70 | m_h[7] = 0x5be0cd19; 71 | m_len = 0; 72 | m_tot_len = 0; 73 | } 74 | 75 | void SHA256::update(const unsigned char *message, unsigned int len) 76 | { 77 | unsigned int block_nb; 78 | unsigned int new_len, rem_len, tmp_len; 79 | const unsigned char *shifted_message; 80 | tmp_len = SHA224_256_BLOCK_SIZE - m_len; 81 | rem_len = len < tmp_len ? len : tmp_len; 82 | memcpy(&m_block[m_len], message, rem_len); 83 | if (m_len + len < SHA224_256_BLOCK_SIZE) { 84 | m_len += len; 85 | return; 86 | } 87 | new_len = len - rem_len; 88 | block_nb = new_len / SHA224_256_BLOCK_SIZE; 89 | shifted_message = message + rem_len; 90 | transform(m_block, 1); 91 | transform(shifted_message, block_nb); 92 | rem_len = new_len % SHA224_256_BLOCK_SIZE; 93 | memcpy(m_block, &shifted_message[block_nb << 6], rem_len); 94 | m_len = rem_len; 95 | m_tot_len += (block_nb + 1) << 6; 96 | } 97 | 98 | void SHA256::final(unsigned char *digest) 99 | { 100 | unsigned int block_nb; 101 | unsigned int pm_len; 102 | unsigned int len_b; 103 | int i; 104 | block_nb = (1 + ((SHA224_256_BLOCK_SIZE - 9) 105 | < (m_len % SHA224_256_BLOCK_SIZE))); 106 | len_b = (m_tot_len + m_len) << 3; 107 | pm_len = block_nb << 6; 108 | memset(m_block + m_len, 0, pm_len - m_len); 109 | m_block[m_len] = 0x80; 110 | SHA2_UNPACK32(len_b, m_block + pm_len - 4); 111 | transform(m_block, block_nb); 112 | for (i = 0 ; i < 8; i++) { 113 | SHA2_UNPACK32(m_h[i], &digest[i << 2]); 114 | } 115 | } 116 | 117 | std::string sha256(std::string input) 118 | { 119 | unsigned char digest[SHA256::DIGEST_SIZE]; 120 | memset(digest,0,SHA256::DIGEST_SIZE); 121 | 122 | SHA256 ctx = SHA256(); 123 | ctx.init(); 124 | ctx.update( (unsigned char*)input.c_str(), input.length()); 125 | ctx.final(digest); 126 | 127 | char buf[2*SHA256::DIGEST_SIZE+1]; 128 | buf[2*SHA256::DIGEST_SIZE] = 0; 129 | for (int i = 0; i < SHA256::DIGEST_SIZE; i++) 130 | sprintf(buf+i*2, "%02x", digest[i]); 131 | return std::string(buf); 132 | } 133 | -------------------------------------------------------------------------------- /src/compute/repographoptimizer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repographoptimizer.h" 20 | 21 | repo::core::RepoGraphOptimizer::RepoGraphOptimizer(RepoGraphScene *scene) 22 | : scene(scene) 23 | {} 24 | 25 | void repo::core::RepoGraphOptimizer::collapseSingleMeshTransformations() 26 | { 27 | for (RepoNodeAbstract* node : scene->getMeshes()) 28 | { 29 | RepoNodeMesh* mesh = dynamic_cast(node); 30 | if (mesh) 31 | collapseSingleMeshTransformations(mesh); 32 | } 33 | } 34 | 35 | void repo::core::RepoGraphOptimizer::collapseSingleMeshTransformations( 36 | RepoNodeMesh* mesh) 37 | { 38 | RepoNodeTransformation* parentTransformation = getSingleParentTransformation(mesh); 39 | if (parentTransformation && !parentTransformation->isRoot() && parentTransformation->isIdentity()) 40 | { 41 | std::set siblingMeshes = parentTransformation->getChildren(); 42 | std::set siblingTransformations = parentTransformation->getChildren(); 43 | 44 | 45 | RepoNodeTransformation* grandParentTransformation = getSingleParentTransformation(parentTransformation); 46 | if (1 == (siblingMeshes.size() + siblingTransformations.size()) && grandParentTransformation) 47 | { 48 | 49 | std::cerr << "Reparenting " << mesh->getName() << " from " << parentTransformation->getName() << " to " << grandParentTransformation->getName() << std::endl; 50 | 51 | 52 | mesh->setName(parentTransformation->getName()); 53 | 54 | 55 | grandParentTransformation->removeChild(parentTransformation); 56 | parentTransformation->removeParent(grandParentTransformation); 57 | 58 | for (const RepoNodeAbstract* n : parentTransformation->getChildren()) 59 | { 60 | RepoNodeAbstract* node = const_cast(n); 61 | parentTransformation->removeChild(node); 62 | node->removeParent(parentTransformation); 63 | 64 | if (dynamic_cast(node)) 65 | { 66 | mesh->addChild(node); 67 | node->addParent(mesh); 68 | } 69 | else 70 | { 71 | grandParentTransformation->addChild(node); 72 | node->addParent(grandParentTransformation); 73 | } 74 | } 75 | 76 | // TODO: remove from transformations set in SceneGraph... 77 | scene->removeNodeRecursively(parentTransformation); 78 | 79 | 80 | // Recursive call 81 | collapseSingleMeshTransformations(mesh); 82 | } 83 | } 84 | } 85 | 86 | 87 | repo::core::RepoNodeTransformation* repo::core::RepoGraphOptimizer::getSingleParentTransformation( 88 | RepoNodeAbstract* node) 89 | { 90 | RepoNodeTransformation* parentTransformation = 0; 91 | std::set parents = node->getParents(); 92 | if (1 == parents.size()) 93 | parentTransformation = const_cast(*(parents.begin())); 94 | return parentTransformation; 95 | } 96 | 97 | void repo::core::RepoGraphOptimizer::collapseZeroMeshTransformations() 98 | { 99 | unsigned int originalCount = scene->getTransformations().size(); 100 | for (RepoNodeAbstract* node : scene->getTransformations()) 101 | { 102 | if (node 103 | && !node->isRoot() 104 | && 0 == node->getChildren().size() 105 | && 0 == node->getChildren().size()) 106 | scene->removeNodeRecursively(node); 107 | } 108 | 109 | // Recursive call 110 | if (originalCount != scene->getTransformations().size()) 111 | collapseZeroMeshTransformations(); 112 | } 113 | -------------------------------------------------------------------------------- /src/diff/repo3ddiff.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "repo3ddiff.h" 20 | 21 | repo::core::Repo3DDiff::Repo3DDiff( 22 | const RepoGraphScene* A, 23 | const RepoGraphScene* B) 24 | : A(A) 25 | , B(B) {} 26 | 27 | 28 | repo::core::RepoNodeRevision repo::core::Repo3DDiff::diff() const 29 | { 30 | RepoNodeAbstractSet meshesA = A->getMeshes(); 31 | RepoNodeAbstractSet meshesB = B->getMeshes(); 32 | 33 | 34 | RepoNodeAbstractSet meshIntersection = setIntersection(meshesA, meshesB); 35 | // printSet(meshIntersection, "Matching Meshes"); 36 | 37 | 38 | 39 | // RepoSelfSimilarSet hasMultiSet = toSelfSimilarSet(oldMeshes); 40 | // std::cerr << "Hash set:" << std::endl; 41 | // for (const core::RepoNodeAbstract* x: hasMultiSet) 42 | // std::cerr << ((core::RepoNodeMesh*)(x))->getVertexHash() << std::endl; 43 | 44 | 45 | 46 | // // A - B 47 | // RepoNodeAbstractSet deletedMeshes = this->setDifference(oldMeshes, newMeshes); 48 | 49 | // // B - A 50 | // RepoNodeAbstractSet addedMeshes = this->setDifference(newMeshes, oldMeshes); 51 | 52 | // // A intersection B (meshes in common between A and B) 53 | // // This is list of modified and unmodified meshes 54 | // RepoNodeAbstractSet commonMeshes = this->setDifference(oldMeshes, deletedMeshes); 55 | 56 | 57 | 58 | 59 | 60 | RepoNodeAbstractSet oldTransformations = A->getTransformations(); 61 | RepoNodeAbstractSet newTransformations = B->getTransformations(); 62 | RepoNodeAbstractSet intersect = setIntersection(oldTransformations, newTransformations); 63 | // printSet(intersect, "Matching Transformations"); 64 | 65 | // A - B 66 | // RepoNodeAbstractSet deletedTransformations = this->setDifference(oldTransformations, newTransformations); 67 | 68 | // // B - A 69 | // RepoNodeAbstractSet addedTransformations = this->setDifference(newTransformations, oldTransformations); 70 | 71 | // // A intersection B 72 | // RepoNodeAbstractSet matchingTransformations = this->setDifference(oldTransformations, deletedTransformations); 73 | 74 | 75 | return RepoNodeRevision(); 76 | } 77 | 78 | //------------------------------------------------------------------------------ 79 | // 80 | // Static helpers 81 | // 82 | //------------------------------------------------------------------------------ 83 | 84 | repo::core::RepoNodeAbstractSet repo::core::Repo3DDiff::setDifference(const RepoNodeAbstractSet& a, 85 | const RepoNodeAbstractSet& b) 86 | { 87 | RepoNodeAbstractSet aMinusB; 88 | std::set_difference(a.begin(), a.end(), 89 | b.begin(), b.end(), 90 | std::inserter(aMinusB, aMinusB.end()), 91 | RepoNodeAbstractComparator()); 92 | return aMinusB; 93 | } 94 | 95 | repo::core::RepoNodeAbstractSet repo::core::Repo3DDiff::setIntersection(const RepoNodeAbstractSet& a, 96 | const RepoNodeAbstractSet& b) 97 | { 98 | RepoNodeAbstractSet aIntersectB; 99 | std::set_intersection(a.begin(), a.end(), 100 | b.begin(), b.end(), 101 | std::inserter(aIntersectB, aIntersectB.end()), 102 | RepoNodeAbstractComparator()); 103 | return aIntersectB; 104 | } 105 | 106 | 107 | void repo::core::Repo3DDiff::printSet(const RepoNodeAbstractSet &x, 108 | const std::string& label) 109 | { 110 | std::cerr << label << std::endl; 111 | RepoNodeAbstractSet::iterator it; 112 | for (it = x.begin(); it != x.end(); ++it) 113 | std::cerr << (*it)->getName() << "\t\t\t" << (*it)->getSharedIDString() << std::endl; 114 | } 115 | 116 | repo::core::RepoSelfSimilarSet repo::core::Repo3DDiff::toSelfSimilarSet(const RepoNodeAbstractSet &x) 117 | { 118 | RepoSelfSimilarSet rsss; 119 | for (auto n = x.begin(); n != x.end(); ++n) 120 | { 121 | RepoNodeMesh *mesh = dynamic_cast(*n); 122 | rsss.insert(std::make_pair(mesh->getVertexHash(), *n)); 123 | } 124 | return rsss; 125 | } 126 | -------------------------------------------------------------------------------- /src/repocoreglobal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | // http://qt-project.org/doc/qt-5/sharedlibrary.html 19 | 20 | #ifndef REPO_CORE_GLOBAL_H 21 | #define REPO_CORE_GLOBAL_H 22 | 23 | #pragma warning( disable : 4996 ) 24 | #pragma warning( disable : 4267 ) 25 | #pragma warning( disable : 4251 ) 26 | #pragma warning( disable : 4244 ) 27 | #pragma warning( disable : 4100 ) 28 | #pragma warning( disable : 4005 ) 29 | 30 | //------------------------------------------------------------------------------ 31 | #if defined(_WIN32) || defined(_WIN64) 32 | # define Q_DECL_EXPORT __declspec(dllexport) 33 | # define Q_DECL_IMPORT __declspec(dllimport) 34 | #else 35 | # define Q_DECL_EXPORT 36 | # define Q_DECL_IMPORT 37 | #endif 38 | 39 | //------------------------------------------------------------------------------ 40 | #if defined(REPO_CORE_LIBRARY) 41 | # define REPO_CORE_EXPORT Q_DECL_EXPORT 42 | #else 43 | # define REPO_CORE_EXPORT Q_DECL_IMPORT 44 | #endif 45 | 46 | //------------------------------------------------------------------------------ 47 | // Constants 48 | #define REPO_ADMIN "admin" //!< Admin database 49 | #define REPO_SYSTEM_USERS "system.users" //!< Users collection 50 | #define REPO_SYSTEM_ROLES "system.roles" //!< Roles collection 51 | 52 | #define REPO_LABEL_ID "_id" 53 | #define REPO_LABEL_AVATAR "avatar" 54 | #define REPO_LABEL_DATA "data" 55 | #define REPO_LABEL_HEIGHT "height" 56 | #define REPO_LABEL_MEDIA_TYPE "mime" //!< Media Type (mime type) 57 | #define REPO_LABEL_ROLE "role" 58 | #define REPO_LABEL_ROLES "roles" 59 | #define REPO_LABEL_USER "user" 60 | #define REPO_LABEL_WIDTH "width" 61 | #define REPO_LABEL_TYPE "type" 62 | 63 | #define REPO_LABEL_DESCRIPTION "desc" 64 | #define REPO_LABEL_OWNER "owner" 65 | #define REPO_LABEL_GROUP "group" 66 | #define REPO_LABEL_PERMISSIONS "permissions" 67 | #define REPO_LABEL_USERS "users" 68 | 69 | #define REPO_COMMAND_UPDATE "update" 70 | #define REPO_COMMAND_UPDATES "updates" 71 | #define REPO_COMMAND_DELETE "delete" 72 | #define REPO_COMMAND_DELETES "deletes" 73 | #define REPO_COMMAND_UPSERT "upsert" 74 | #define REPO_COMMAND_LIMIT "limit" 75 | #define REPO_COMMAND_Q "q" 76 | #define REPO_COMMAND_U "u" 77 | 78 | #define REPO_COLLECTION_HISTORY "history" 79 | #define REPO_COLLECTION_SCENE "scene" 80 | #define REPO_COLLECTION_SETTINGS "settings" 81 | 82 | #define REPO_PROJECT_TYPE_ARCHITECTURAL "architectural" 83 | 84 | //------------------------------------------------------------------------------ 85 | // Media Types a.k.a. as Multipurpose Internet Mail Extensions (MIME) Types 86 | // http://www.iana.org/assignments/media-types/media-types.xhtml#image 87 | // http://doc.qt.io/qt-5/qimagereader.html 88 | 89 | #define REPO_MEDIA_TYPE_BMP "image/bmp" //!< Windows Bitmap 90 | #define REPO_MEDIA_TYPE_GIF "image/gif" //!< Graphic Interchange Format 91 | #define REPO_MEDIA_TYPE_JPG "image/jpeg" //!< Joint Photographic Experts Group 92 | #define REPO_MEDIA_TYPE_PNG "image/png" //!< Portable Network Graphics 93 | #define REPO_MEDIA_TYPE_PBM "image/x-portable-bitmap" //!< Portable Bitmap 94 | #define REPO_MEDIA_TYPE_PGM "image/x-portable-graymap" //!< Portable Graymap 95 | #define REPO_MEDIA_TYPE_PPM "image/x-portable-pixmap" //!< Portable Pixmap 96 | #define REPO_MEDIA_TYPE_XBM "image/x-xbitmap" //!< X11 Bitmap 97 | #define REPO_MEDIA_TYPE_XPM "image/x-xpixmap" //!< X11 Pixmap 98 | #define REPO_MEDIA_TYPE_SVG "image/svg+xml" //!< Scalable Vector Graphics 99 | 100 | #define REPO_MEDIA_TYPE_PDF "application/pdf" //!< Portable Document Format 101 | #define REPO_MEDIA_TYPE_JSON "application/json" //!< JavaScript Object Notation 102 | 103 | //------------------------------------------------------------------------------ 104 | 105 | #endif // REPO_CORE_GLOBAL_H 106 | -------------------------------------------------------------------------------- /src/primitives/repoprojectsettings.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_PROJECT_SETTINGS_H 20 | #define REPO_PROJECT_SETTINGS_H 21 | 22 | #include "repobson.h" 23 | #include "../repocoreglobal.h" 24 | 25 | namespace repo { 26 | namespace core { 27 | 28 | enum RepoPermissionsBitMask : unsigned short 29 | { 30 | UID_BIT = 0x4000, 31 | GID_BIT = 0x2000, 32 | STICKY_BIT = 0x1000, 33 | OWNER_READ = 0x0400, 34 | OWNER_WRITE = 0x0200, 35 | OWNER_EXECUTE = 0x0100, 36 | GROUP_READ = 0x0040, 37 | GROUP_WRITE = 0x0020, 38 | GROUP_EXECUTE = 0x0010, 39 | PUBLIC_READ = 0x0004, 40 | PUBLIC_WRITE = 0x0002, 41 | PUBLIC_EXECUTE = 0x0001 42 | }; 43 | 44 | enum RepoRWXPermissionsBitMask { READ = 4, WRITE = 2, EXECUTE = 1 }; 45 | 46 | class REPO_CORE_EXPORT RepoProjectSettings : public RepoBSON 47 | { 48 | 49 | public: 50 | 51 | RepoProjectSettings() : RepoBSON() {} 52 | 53 | RepoProjectSettings(const mongo::BSONObj &obj) : RepoBSON(obj) {} 54 | 55 | RepoProjectSettings( 56 | const std::string &uniqueProjectName, 57 | const std::string &owner, 58 | const std::string &group = std::string(), 59 | const std::string &type = REPO_PROJECT_TYPE_ARCHITECTURAL, 60 | const std::string &description = std::string(), 61 | unsigned short ownerPermissionsOctal = 7, 62 | unsigned short groupPermissionsOctal = 0, 63 | unsigned short publicPermissionsOctal = 0); 64 | 65 | 66 | ~RepoProjectSettings(); 67 | 68 | //-------------------------------------------------------------------------- 69 | 70 | //! Returns a new full (and owned) copy of the object. 71 | inline RepoProjectSettings copy() const { return RepoProjectSettings(RepoBSON::copy()); } 72 | 73 | //! Updates or inserts this document in "db.settings" collection based on matching "_id" value. 74 | RepoBSON upsert() const; 75 | 76 | //! See http://docs.mongodb.org/manual/reference/command/delete/#dbcmd.delete 77 | RepoBSON drop() const; 78 | 79 | //-------------------------------------------------------------------------- 80 | // 81 | // Getters 82 | // 83 | //-------------------------------------------------------------------------- 84 | 85 | //! Returns the project name. 86 | std::string getProject() const 87 | { return hasField(REPO_LABEL_ID) ? getField(REPO_LABEL_ID).String() : std::string(); } 88 | 89 | //! Returns description of the project. 90 | std::string getDescription() const 91 | { return hasField(REPO_LABEL_DESCRIPTION) ? getField(REPO_LABEL_DESCRIPTION).String() : std::string(); } 92 | 93 | //! Returns owner of the project. 94 | std::string getOwner() const 95 | { return hasField(REPO_LABEL_OWNER) ? getField(REPO_LABEL_OWNER).String() : std::string(); } 96 | 97 | //! Returns group of the project. 98 | std::string getGroup() const 99 | { return hasField(REPO_LABEL_GROUP) ? getField(REPO_LABEL_GROUP).String() : std::string(); } 100 | 101 | //! Returns unix-style rwxrwxrwx permissions of the project. 102 | std::string getPermissionsString() const; 103 | 104 | //! Returns unix-style permissions of the project, eg "0x0777". 105 | std::string getPermissionsOctalString() const; 106 | 107 | //! Returns unix-style permissions of the project, qg "0x0777". 108 | unsigned short getPermissionsOctal() const; 109 | 110 | //! Returns type of the project. 111 | std::string getType() const 112 | { return hasField(REPO_LABEL_TYPE) ? getField(REPO_LABEL_TYPE).String() : std::string(); } 113 | 114 | //! Returns users of the project. 115 | std::vector getUsers() const; 116 | 117 | //! Turns string in form of "0x7777" to unsigned short. 118 | static unsigned short stringToOctal(const std::string &); 119 | 120 | static std::string getRWX(unsigned short octal, 121 | unsigned short rMask, 122 | unsigned short wMask, 123 | unsigned short xMask); 124 | 125 | }; // end class 126 | 127 | } // end namespace core 128 | } // end namespace repo 129 | 130 | #endif // REPO_PROJECT_SETTINGS_H 131 | -------------------------------------------------------------------------------- /src/graph/repo_node_texture.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_NODE_TEXTURE_H 19 | #define REPO_NODE_TEXTURE_H 20 | 21 | #include 22 | //------------------------------------------------------------------------------ 23 | #include "repo_node_abstract.h" 24 | //------------------------------------------------------------------------------ 25 | 26 | namespace repo { 27 | namespace core { 28 | 29 | //------------------------------------------------------------------------------ 30 | // 31 | // Fields specific to texture only 32 | // 33 | //------------------------------------------------------------------------------ 34 | #define REPO_NODE_TYPE_TEXTURE "texture" 35 | #define REPO_NODE_LABEL_BIT_DEPTH "bit_depth" 36 | #define REPO_NODE_LABEL_EXTENSION "extension" 37 | #define REPO_NODE_LABEL_DATA_BYTE_COUNT "data_byte_count" 38 | #define REPO_NODE_UUID_SUFFIX_TEXTURE "11" //!< uuid suffix 39 | //------------------------------------------------------------------------------ 40 | 41 | 42 | 43 | class REPO_CORE_EXPORT RepoNodeTexture : public RepoNodeAbstract 44 | { 45 | 46 | public : 47 | 48 | //-------------------------------------------------------------------------- 49 | // 50 | // Constructors 51 | // 52 | //-------------------------------------------------------------------------- 53 | //! Basic constructor, uuid will be randomly generated. 54 | inline RepoNodeTexture() : 55 | RepoNodeAbstract( 56 | REPO_NODE_TYPE_TEXTURE, 57 | REPO_NODE_API_LEVEL_1) {} 58 | 59 | RepoNodeTexture( 60 | const std::string &name, 61 | const char *data, 62 | const unsigned int byteCount, 63 | const unsigned int width, 64 | const unsigned int height); 65 | //const unsigned int bitDepth, 66 | //const std::string format); 67 | 68 | RepoNodeTexture(const mongo::BSONObj &obj); 69 | 70 | //-------------------------------------------------------------------------- 71 | // 72 | // Destructor 73 | // 74 | //-------------------------------------------------------------------------- 75 | 76 | //! Empty destructor. 77 | ~RepoNodeTexture(); 78 | 79 | //-------------------------------------------------------------------------- 80 | // 81 | // Operators 82 | // 83 | //-------------------------------------------------------------------------- 84 | 85 | //! Returns true if the given node is identical to this, false otherwise. 86 | virtual bool operator==(const RepoNodeAbstract&) const; 87 | 88 | 89 | //-------------------------------------------------------------------------- 90 | // 91 | // Export 92 | // 93 | //-------------------------------------------------------------------------- 94 | 95 | 96 | //! BSONObj representation. 97 | /*! 98 | * Returns a BSON representation of this repository object suitable for a 99 | * direct MongoDB storage. 100 | * 101 | * \return BSON representation 102 | */ 103 | mongo::BSONObj toBSONObj() const; 104 | 105 | const std::vector* getData() const { return data; } 106 | 107 | //! Returns a pointer to the internal raw data of the texture. 108 | inline const char * getRawData() const { return &(data->at(0)); } 109 | 110 | //! Returns the number of bytes of the raw data. 111 | inline unsigned int getRawDataSize() const { return data->size(); } 112 | 113 | //! Returns width of the texture if set. 114 | unsigned int getWidth() const { return width; } 115 | 116 | //! Returns height of the texture if set. 117 | unsigned int getHeight() const { return height; } 118 | 119 | //! Returns extension of the texture if set. 120 | std::string getExtension() const { return extension; } 121 | 122 | 123 | protected : 124 | 125 | unsigned int width; //!< Width of the texture. 126 | 127 | unsigned int height; //!< Height of the texture. 128 | 129 | // unsigned int bitDepth; //!< Bit depth of the texture, 1 (mono), 8, 16... 130 | 131 | // TODO: change this mime type 132 | std::string extension; //!< Format of the texture, such as "png". 133 | 134 | std::vector * data; //!< copy of the pixel data 135 | 136 | }; // end class 137 | 138 | } // end namespace core 139 | } // end namespace repo 140 | 141 | #endif // end REPO_NODE_TEXTURE_H 142 | -------------------------------------------------------------------------------- /3drepocore.pro: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 3D Repo Ltd 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU Affero General Public License as 5 | # published by the Free Software Foundation, either version 3 of the 6 | # License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU Affero General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU Affero General Public License 14 | # along with this program. If not, see . 15 | 16 | # http://qt-project.org/doc/qt-5/qmake-variable-reference.html 17 | # http://google-styleguide.googlecode.com/svn/trunk/cppguide.html 18 | 19 | include(header.pri) 20 | include(boost.pri) 21 | include(assimp.pri) 22 | include(mongo.pri) 23 | 24 | #------------------------------------------------------------------------------- 25 | 26 | QT -= core gui 27 | 28 | TEMPLATE = lib 29 | 30 | CONFIG += build_all #debug_and_release 31 | CONFIG += c++11 32 | 33 | DEFINES += REPO_CORE_LIBRARY 34 | win32:DEFINES += _WIN32 35 | 36 | unix { 37 | target.path = /usr/lib 38 | INSTALLS += target 39 | LIBS += -lboost_system -lboost_thread -lboost_filesystem 40 | } 41 | 42 | HEADERS += src/repocore.h\ 43 | src/repologger.h \ 44 | src/repocoreglobal.h \ 45 | src/assimpwrapper.h \ 46 | src/mongoclientwrapper.h \ 47 | src/graph/repo_bounding_box.h \ 48 | src/graph/repo_graph_abstract.h \ 49 | src/graph/repo_graph_history.h \ 50 | src/graph/repo_graph_scene.h \ 51 | src/graph/repo_node_abstract.h \ 52 | src/graph/repo_node_camera.h \ 53 | src/graph/repo_node_material.h \ 54 | src/graph/repo_node_mesh.h \ 55 | src/graph/repo_node_revision.h \ 56 | src/graph/repo_node_reference.h \ 57 | src/graph/repo_node_metadata.h \ 58 | src/graph/repo_node_texture.h \ 59 | src/graph/repo_node_transformation.h \ 60 | src/primitives/repo_user.h \ 61 | src/primitives/repo_vertex.h \ 62 | src/primitives/repostreambuffer.h \ 63 | src/primitives/repoabstractlistener.h \ 64 | src/primitives/repoabstractnotifier.h \ 65 | src/primitives/reposeverity.h \ 66 | src/primitives/repobson.h \ 67 | src/primitives/reporole.h \ 68 | src/conversion/repo_transcoder_bson.h \ 69 | src/conversion/repo_transcoder_string.h \ 70 | src/compute/render.h \ 71 | src/primitives/repoimage.h \ 72 | src/diff/repo3ddiff.h \ 73 | src/sha256/sha256.h \ 74 | src/compute/repo_pca.h \ 75 | src/compute/repo_eigen.h \ 76 | src/compute/repocsv.h \ 77 | src/compute/repographoptimizer.h \ 78 | src/graph/repo_node_types.h \ 79 | src/primitives/repocollstats.h \ 80 | src/primitives/repoprojectsettings.h \ 81 | src/mongo/repogridfs.h \ 82 | src/api/repo_apikey.h \ 83 | src/primitives/repo_binary.h 84 | 85 | SOURCES += src/repocore.cpp \ 86 | src/repologger.cpp \ 87 | src/assimpwrapper.cpp \ 88 | src/mongoclientwrapper.cpp \ 89 | src/graph/repo_bounding_box.cpp \ 90 | src/graph/repo_graph_abstract.cpp \ 91 | src/graph/repo_graph_history.cpp \ 92 | src/graph/repo_graph_scene.cpp \ 93 | src/graph/repo_node_abstract.cpp \ 94 | src/graph/repo_node_camera.cpp \ 95 | src/graph/repo_node_material.cpp \ 96 | src/graph/repo_node_mesh.cpp \ 97 | src/graph/repo_node_revision.cpp \ 98 | src/graph/repo_node_reference.cpp \ 99 | src/graph/repo_node_metadata.cpp \ 100 | src/graph/repo_node_texture.cpp \ 101 | src/graph/repo_node_transformation.cpp \ 102 | src/primitives/repo_user.cpp \ 103 | src/primitives/repo_vertex.cpp \ 104 | src/primitives/repostreambuffer.cpp \ 105 | src/primitives/repoabstractlistener.cpp \ 106 | src/primitives/repoabstractnotifier.cpp \ 107 | src/primitives/reposeverity.cpp \ 108 | src/primitives/repobson.cpp \ 109 | src/primitives/reporole.cpp \ 110 | src/conversion/repo_transcoder_bson.cpp \ 111 | src/conversion/repo_transcoder_string.cpp \ 112 | src/compute/render.cpp \ 113 | src/sha256/sha256.cpp \ 114 | src/primitives/repoimage.cpp \ 115 | src/diff/repo3ddiff.cpp \ 116 | src/compute/repo_pca.cpp \ 117 | src/compute/repo_eigen.cpp \ 118 | src/compute/repocsv.cpp \ 119 | src/compute/repographoptimizer.cpp \ 120 | src/primitives/repocollstats.cpp \ 121 | src/primitives/repoprojectsettings.cpp \ 122 | src/mongo/repogridfs.cpp \ 123 | src/api/repo_apikey.cpp \ 124 | src/primitives/repo_binary.cpp 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /src/graph/repo_node_metadata.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_NODE_METADATA_H 19 | #define REPO_NODE_METADATA_H 20 | 21 | //------------------------------------------------------------------------------ 22 | #include "repo_node_abstract.h" 23 | //------------------------------------------------------------------------------ 24 | 25 | 26 | namespace repo { 27 | namespace core { 28 | 29 | //------------------------------------------------------------------------------ 30 | // 31 | // Fields specific to metadata only 32 | // 33 | //------------------------------------------------------------------------------ 34 | #define REPO_NODE_LABEL_METADATA "metadata" 35 | #define REPO_NODE_UUID_SUFFIX_METADATA "14" //!< uuid suffix 36 | //------------------------------------------------------------------------------ 37 | 38 | /*! 39 | * 3D Repo referenece for model federation. Reference can point to a specific 40 | * revision by its unique ID or to a head of a branch by its shared ID. 41 | */ 42 | class REPO_CORE_EXPORT RepoNodeMetadata : public RepoNodeAbstract 43 | { 44 | 45 | public : 46 | 47 | //-------------------------------------------------------------------------- 48 | // 49 | // Constructors 50 | // 51 | //-------------------------------------------------------------------------- 52 | 53 | //! Basic constructor, uuid will be randomly generated. 54 | inline RepoNodeMetadata() : 55 | RepoNodeAbstract(REPO_NODE_TYPE_METADATA, REPO_NODE_API_LEVEL_1) {} 56 | 57 | RepoNodeMetadata(const std::list& keys, 58 | const std::list& values, 59 | const string& name); 60 | 61 | //! Constructs Metadata scene graph node from Assimp's aiMetaData. 62 | /*! 63 | * Same as all other components, it has to have a uuid, type, api 64 | * and optional name. 65 | * 66 | * \param metadata aiMetadata metadata object 67 | * \sa RepoNodeMetadata() 68 | */ 69 | RepoNodeMetadata(const aiMetadata *metadata, const std::string &name); 70 | 71 | //! Constructs metadata scene graph component from a BSON object. 72 | /*! 73 | * Same as all other components, it has to have a uuid, type, api 74 | * and optional name. 75 | * 76 | * \param obj BSON representation 77 | * \sa RepoNodeMetadata() 78 | */ 79 | RepoNodeMetadata(const mongo::BSONObj &obj); 80 | 81 | RepoNodeMetadata( 82 | const mongo::BSONObj &metadata, 83 | const string &name, 84 | const std::string &mime = REPO_MEDIA_TYPE_JSON); 85 | 86 | //-------------------------------------------------------------------------- 87 | // 88 | // Destructor 89 | // 90 | //-------------------------------------------------------------------------- 91 | 92 | //! Destructor 93 | ~RepoNodeMetadata() {} 94 | 95 | //-------------------------------------------------------------------------- 96 | // 97 | // Operators 98 | // 99 | //-------------------------------------------------------------------------- 100 | 101 | //! Returns true if the given node is identical to this, false otherwise. 102 | virtual bool operator==(const RepoNodeAbstract&) const; 103 | 104 | //-------------------------------------------------------------------------- 105 | // 106 | // Export 107 | // 108 | //-------------------------------------------------------------------------- 109 | 110 | //! Returns metadata subobject. 111 | mongo::BSONObj getMetadata() const { return metadata; } 112 | 113 | //! BSONObj representation. 114 | /*! 115 | * Returns a BSON representation of this metadata object suitable for a 116 | * direct MongoDB storage. 117 | * 118 | * \return BSON representation 119 | */ 120 | mongo::BSONObj toBSONObj() const; 121 | 122 | //! Returns string representation of the metadata object separated by new lines. 123 | std::string toString() const { return toString("\n"); } 124 | 125 | //! Returns string representation of the metadata object. 126 | std::string toString(std::string separator) const; 127 | 128 | protected : 129 | 130 | //-------------------------------------------------------------------------- 131 | // 132 | // Protected variables 133 | // 134 | //-------------------------------------------------------------------------- 135 | 136 | mongo::BSONObj metadata; //!< Metadata subobject 137 | 138 | std::string mime; //! Media type (mime type) of the metadata 139 | 140 | }; // end class 141 | 142 | } // end namespace core 143 | } // end namespace repo 144 | 145 | #endif // end REPO_NODE_METADATA_H 146 | 147 | -------------------------------------------------------------------------------- /src/graph/repo_node_reference.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_node_reference.h" 19 | 20 | //------------------------------------------------------------------------------ 21 | // 22 | // Constructors 23 | // 24 | //------------------------------------------------------------------------------ 25 | repo::core::RepoNodeReference::RepoNodeReference( 26 | const std::string &database, 27 | const std::string &project) 28 | : RepoNodeAbstract ( 29 | REPO_NODE_TYPE_REFERENCE, 30 | REPO_NODE_API_LEVEL_1, 31 | boost::uuids::random_generator()(), 32 | database + "." + project) 33 | , database(database) 34 | , project(project) 35 | , revisionID(boost::uuids::uuid()) 36 | , isUniqueID(false) 37 | {} 38 | 39 | repo::core::RepoNodeReference::RepoNodeReference( 40 | const std::string &database, 41 | const std::string &project, 42 | const boost::uuids::uuid &revisionID, 43 | bool isUniqueID, 44 | const std::string &name) 45 | : RepoNodeAbstract ( 46 | REPO_NODE_TYPE_REFERENCE, 47 | REPO_NODE_API_LEVEL_1, 48 | boost::uuids::random_generator()(), 49 | name) 50 | , project(project) 51 | , database(database) 52 | , revisionID(revisionID) 53 | , isUniqueID(isUniqueID) 54 | {} 55 | 56 | repo::core::RepoNodeReference::RepoNodeReference( 57 | const mongo::BSONObj &obj) 58 | : RepoNodeAbstract(obj) 59 | , revisionID(boost::uuids::uuid()) 60 | , isUniqueID(false) 61 | { 62 | //-------------------------------------------------------------------------- 63 | // Owner 64 | if (obj.hasField(REPO_NODE_LABEL_OWNER)) 65 | database = obj.getField(REPO_NODE_LABEL_OWNER).String(); 66 | 67 | //-------------------------------------------------------------------------- 68 | // Project 69 | if (obj.hasField(REPO_NODE_LABEL_PROJECT)) 70 | project = obj.getField(REPO_NODE_LABEL_PROJECT).String(); 71 | 72 | //-------------------------------------------------------------------------- 73 | // Revision ID (specific revision if UID, branch if SID) 74 | if (obj.hasField(REPO_NODE_LABEL_REFERENCE_ID)) 75 | { 76 | revisionID = RepoTranscoderBSON::retrieve( 77 | obj.getField(REPO_NODE_LABEL_REFERENCE_ID)); 78 | } 79 | 80 | //-------------------------------------------------------------------------- 81 | // Unique 82 | if (obj.hasField(REPO_NODE_LABEL_UNIQUE)) 83 | { 84 | isUniqueID = obj.getField(REPO_NODE_LABEL_UNIQUE).Bool(); 85 | } 86 | } 87 | 88 | //------------------------------------------------------------------------------ 89 | // 90 | // Operators 91 | // 92 | //------------------------------------------------------------------------------ 93 | 94 | bool repo::core::RepoNodeReference::operator==(const RepoNodeAbstract& other) const 95 | { 96 | const RepoNodeReference *otherReference = dynamic_cast(&other); 97 | return otherReference && 98 | RepoNodeAbstract::operator==(other) && 99 | this->getProject() == otherReference->getProject() && 100 | this->getOwner() == otherReference->getOwner() && 101 | this->getRevisionID() == otherReference->getRevisionID() && 102 | this->getIsUniqueID() == otherReference->getIsUniqueID(); 103 | } 104 | 105 | mongo::BSONObj repo::core::RepoNodeReference::toBSONObj() const 106 | { 107 | mongo::BSONObjBuilder builder; 108 | 109 | //-------------------------------------------------------------------------- 110 | // Compulsory fields such as _id, type, api as well as path 111 | // and optional name 112 | appendDefaultFields(builder); 113 | 114 | //-------------------------------------------------------------------------- 115 | // Project owner (company or individual) 116 | if (!database.empty()) 117 | builder << REPO_NODE_LABEL_OWNER << database; 118 | 119 | //-------------------------------------------------------------------------- 120 | // Project name 121 | if (!project.empty()) 122 | builder << REPO_NODE_LABEL_PROJECT << project; 123 | 124 | //-------------------------------------------------------------------------- 125 | // Revision ID (specific revision if UID, branch if SID) 126 | RepoTranscoderBSON::append( 127 | REPO_NODE_LABEL_REFERENCE_ID, 128 | revisionID, 129 | builder); 130 | 131 | //-------------------------------------------------------------------------- 132 | // Unique set if the revisionID is UID, not set if SID (branch) 133 | if (isUniqueID) 134 | builder << REPO_NODE_LABEL_UNIQUE << isUniqueID; 135 | 136 | return builder.obj(); 137 | } 138 | -------------------------------------------------------------------------------- /src/graph/repo_graph_abstract.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef REPO_GRAPH_ABSTRACT_H 19 | #define REPO_GRAPH_ABSTRACT_H 20 | 21 | //------------------------------------------------------------------------------ 22 | #include // the MongoDB driver 23 | //------------------------------------------------------------------------------ 24 | #include "assimp/scene.h" 25 | #include "repo_node_abstract.h" 26 | 27 | #include "../repocoreglobal.h" 28 | 29 | 30 | namespace repo { 31 | namespace core { 32 | 33 | //! Abstract directed acyclic graph (DAG). 34 | /*! 35 | * 3D Repo directed acyclic graph is assumed to have a single root node only. 36 | */ 37 | class REPO_CORE_EXPORT RepoGraphAbstract 38 | { 39 | 40 | public : 41 | 42 | //-------------------------------------------------------------------------- 43 | // 44 | // Constructor 45 | // 46 | //-------------------------------------------------------------------------- 47 | 48 | //! Default empty constructor. 49 | inline RepoGraphAbstract(RepoNodeAbstract *root = 0) : rootNode(root) {} 50 | 51 | //-------------------------------------------------------------------------- 52 | // 53 | // Destructor 54 | // 55 | //-------------------------------------------------------------------------- 56 | 57 | //! Empty pure virtual destructor for proper cleanup. 58 | /*! 59 | * \sa RepoGraphAbstract() 60 | */ 61 | virtual ~RepoGraphAbstract() = 0; 62 | 63 | /*! Appends a given graph to a given node by copying over pointers. 64 | * Removes all of the pointers from the given scene graph (so that it can be 65 | * safely deleted without losing the scene node objects from the memory). 66 | */ 67 | void append(RepoNodeAbstract *thisNode, RepoGraphAbstract *thatGraph); 68 | 69 | //-------------------------------------------------------------------------- 70 | // 71 | // Getters 72 | // 73 | //-------------------------------------------------------------------------- 74 | 75 | //! Returns the root node of the graph. 76 | virtual RepoNodeAbstract* getRoot() const { return rootNode; } 77 | 78 | //! Returns a set of all unique nodes that make up the graph hierarchy. 79 | virtual std::set getNodesRecursively() const; 80 | 81 | //! Returns a set of nodes as values from nodesByUniqueID stl map. 82 | virtual RepoNodeAbstractSet getNodes() const; 83 | 84 | //! Returns a set of all unique IDs. 85 | virtual std::set getUniqueIDs() const; 86 | 87 | //! Returns a graph node by UID, NULL if not present. 88 | virtual RepoNodeAbstract* getNodeByUniqueID(const boost::uuids::uuid &uid) const; 89 | 90 | //-------------------------------------------------------------------------- 91 | // 92 | // Setters 93 | // 94 | //-------------------------------------------------------------------------- 95 | 96 | //! Sets the root node of the graph and deletes any previously stored root. 97 | virtual void setRootNode(RepoNodeAbstract *root); 98 | 99 | //-------------------------------------------------------------------------- 100 | // 101 | // Adders 102 | // 103 | //-------------------------------------------------------------------------- 104 | 105 | /*! 106 | * Adds a node by its unique ID. Returns the node that had to be replaced, 107 | * NULL if a new entry was inserted. 108 | */ 109 | virtual RepoNodeAbstract* addNodeByUniqueID(RepoNodeAbstract*); 110 | 111 | //-------------------------------------------------------------------------- 112 | // 113 | // Helpers 114 | // 115 | //-------------------------------------------------------------------------- 116 | 117 | //! Recursively prints out a representation of the entire DAG hierarchy. 118 | static void printDAG( 119 | const RepoNodeAbstract *node, 120 | std::string delimiter = std::string()); 121 | 122 | virtual void printDAG() const; 123 | 124 | /*! 125 | * Clears all containers and root node. Warning: does not deallocate memory! 126 | */ 127 | void clear(); 128 | 129 | protected : 130 | 131 | /*! 132 | * Populates parental information in given nodes based on the uuid mapping. 133 | * Efficiency is (n log n). 134 | */ 135 | virtual void buildGraph( 136 | const std::map &idMapping) const; 137 | 138 | protected : 139 | 140 | //-------------------------------------------------------------------------- 141 | // 142 | // Var 143 | // 144 | //-------------------------------------------------------------------------- 145 | 146 | //!< A root node of the graph. 147 | RepoNodeAbstract *rootNode; 148 | 149 | //! A lookup map for the all nodes the graph contains. 150 | std::map nodesByUniqueID; 151 | 152 | }; // end class 153 | 154 | } // end namespace core 155 | } // end namespace repo 156 | 157 | #endif // end REPO_GRAPH_ABSTRACT_H 158 | -------------------------------------------------------------------------------- /src/conversion/repo_transcoder_bson.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_transcoder_bson.h" 19 | 20 | mongo::BSONObj repo::core::RepoTranscoderBSON::uuidBSON( 21 | const string &label, 22 | const boost::uuids::uuid &uuid) 23 | { 24 | mongo::BSONObjBuilder b; 25 | append(label, uuid, b); 26 | return b.obj(); 27 | } 28 | 29 | void repo::core::RepoTranscoderBSON::append( 30 | const std::string &label, 31 | const boost::uuids::uuid &uuid, 32 | mongo::BSONObjBuilder &builder) 33 | { 34 | // see http://api.mongodb.org/cplusplus/1.9.0/bsontypes_8h_source.html 35 | // http://docs.mongodb.org/manual/reference/method/UUID/ 36 | builder.appendBinData( 37 | label, 38 | uuid.size(), 39 | mongo::bdtUUID, 40 | (char*) uuid.data); 41 | } 42 | 43 | void repo::core::RepoTranscoderBSON::append( 44 | const std::string &label, 45 | const aiColor3D &color, 46 | mongo::BSONObjBuilder &builder) 47 | { 48 | std::vector vec; 49 | vec.push_back(color.r); 50 | vec.push_back(color.g); 51 | vec.push_back(color.b); 52 | append(label, vec, builder); 53 | } 54 | 55 | void repo::core::RepoTranscoderBSON::append( 56 | const std::string &label, 57 | const aiColor4D &color, 58 | mongo::BSONObjBuilder &builder) 59 | { 60 | std::vector vec; 61 | vec.push_back(color.r); 62 | vec.push_back(color.g); 63 | vec.push_back(color.b); 64 | vec.push_back(color.a); 65 | append(label, vec, builder); 66 | } 67 | 68 | 69 | boost::uuids::uuid repo::core::RepoTranscoderBSON::retrieve( 70 | const mongo::BSONElement &bse) 71 | { 72 | // TODO: convert to mongo::newUUID 73 | boost::uuids::uuid uuid; 74 | if (bse.binDataType() == mongo::bdtUUID || 75 | bse.binDataType() == mongo::newUUID) 76 | { 77 | int len = static_cast(bse.size() * sizeof(boost::uint8_t)); 78 | const char *binData = bse.binData(len); 79 | memcpy(uuid.data, binData, len); 80 | } 81 | else 82 | uuid = boost::uuids::random_generator()(); // failsafe 83 | return uuid; 84 | } 85 | 86 | std::vector repo::core::RepoTranscoderBSON:: 87 | retrieveUUIDs(const mongo::BSONElement &bse) 88 | { 89 | std::vector uuids; 90 | mongo::BSONObj array = bse.embeddedObject(); 91 | 92 | std::set fields; 93 | array.getFieldNames(fields); 94 | 95 | std::set::iterator it; 96 | for (it = fields.begin(); it != fields.end(); ++it) 97 | uuids.push_back(retrieve(array.getField(*it))); 98 | // for each (std::string field in fields) 99 | // uuids.push_back(retrieve(array.getField(field))); 100 | return uuids; 101 | } 102 | 103 | std::set repo::core::RepoTranscoderBSON:: 104 | retrieveUUIDsSet(const mongo::BSONElement &bse) 105 | { 106 | std::set uuids; 107 | mongo::BSONObj array = bse.embeddedObject(); 108 | 109 | std::set fields; 110 | array.getFieldNames(fields); 111 | 112 | std::set::iterator it; 113 | 114 | for (it = fields.begin(); it != fields.end(); ++it) 115 | //uuids.push_back(retrieve(array.getField(*it))); 116 | // for each (std::string field in fields) 117 | uuids.insert(retrieve(array.getField(*it))); 118 | return uuids; 119 | } 120 | 121 | aiColor3D repo::core::RepoTranscoderBSON:: 122 | retrieveRGB(const mongo::BSONElement &bse) 123 | { 124 | mongo::BSONObj color = bse.embeddedObject(); 125 | return aiColor3D( 126 | (float) color.getField("0").numberDouble(), // R 127 | (float) color.getField("1").numberDouble(), // G 128 | (float) color.getField("2").numberDouble()); // B 129 | } 130 | 131 | aiColor4D repo::core::RepoTranscoderBSON:: 132 | retrieveRGBA(const mongo::BSONElement &bse) 133 | { 134 | mongo::BSONObj color = bse.embeddedObject(); 135 | return aiColor4D( 136 | (float) color.getField("0").numberDouble(), // R 137 | (float) color.getField("1").numberDouble(), // G 138 | (float) color.getField("2").numberDouble(), // B 139 | (float) color.getField("3").numberDouble()); // A 140 | } 141 | 142 | aiVector3D repo::core::RepoTranscoderBSON:: 143 | retrieveVector3D(const mongo::BSONElement &bse) 144 | { 145 | mongo::BSONObj vector = bse.embeddedObject(); 146 | return aiVector3D( 147 | (float) vector.getField("0").numberDouble(), // X 148 | (float) vector.getField("1").numberDouble(), // Y 149 | (float) vector.getField("2").numberDouble()); // Z 150 | } 151 | 152 | std::pair repo::core::RepoTranscoderBSON:: 153 | retrieveBBox(const mongo::BSONElement &bse) 154 | { 155 | std::vector subArr = bse.Array(); 156 | 157 | aiVector3D min, max; 158 | 159 | 160 | // Minimum 161 | mongo::BSONObj min_obj = subArr[0].embeddedObject(); 162 | 163 | min.x = min_obj.getField("0").numberDouble(); 164 | min.y = min_obj.getField("1").numberDouble(); 165 | min.z = min_obj.getField("2").numberDouble(); 166 | 167 | // Maximum 168 | mongo::BSONObj max_obj = subArr[1].embeddedObject(); 169 | 170 | max.x = max_obj.getField("0").numberDouble(); 171 | max.y = max_obj.getField("1").numberDouble(); 172 | max.z = max_obj.getField("2").numberDouble(); 173 | 174 | return std::make_pair(min, max); 175 | } 176 | -------------------------------------------------------------------------------- /src/graph/repo_node_texture.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repo_node_texture.h" 19 | #include 20 | 21 | //------------------------------------------------------------------------------ 22 | repo::core::RepoNodeTexture::RepoNodeTexture( 23 | const std::string &name, 24 | const char *data, 25 | const unsigned int byteCount, 26 | const unsigned int width, 27 | const unsigned int height) 28 | : RepoNodeAbstract ( 29 | REPO_NODE_TYPE_TEXTURE, 30 | REPO_NODE_API_LEVEL_1, 31 | boost::uuids::random_generator()(), 32 | name) 33 | , width(width) 34 | , height(height) /*, 35 | bitDepth(bitDepth), 36 | format(format) */ 37 | { 38 | // Vector is now guaranteed to be continuous block of memory, hence it is 39 | // used as a convenient way of keep track of the number of bytes pointed 40 | // by the data pointer. 41 | this->data = new std::vector(byteCount); 42 | if (!this->data) 43 | std::cerr << "Memory allocation for texture " << name << " failed." << std::endl; 44 | else 45 | memcpy(&(this->data->at(0)), data, byteCount); 46 | 47 | this->name = boost::filesystem::path(name).stem().string(); 48 | this->extension = boost::filesystem::extension(name); 49 | 50 | // remove leading dot 51 | this->extension = this->extension.substr(1, this->extension.size()); 52 | } 53 | 54 | //------------------------------------------------------------------------------ 55 | 56 | repo::core::RepoNodeTexture::RepoNodeTexture(const mongo::BSONObj &obj) 57 | : RepoNodeAbstract(obj) 58 | , data(NULL) 59 | { 60 | // 61 | // Width 62 | // 63 | if (obj.hasField(REPO_LABEL_WIDTH)) 64 | width = obj.getField(REPO_LABEL_WIDTH).numberInt(); 65 | 66 | // 67 | // Height 68 | // 69 | if (obj.hasField(REPO_LABEL_HEIGHT)) 70 | height = obj.getField(REPO_LABEL_HEIGHT).numberInt(); 71 | 72 | // 73 | // Format 74 | // 75 | if (obj.hasField(REPO_NODE_LABEL_EXTENSION)) { 76 | extension = obj.getField(REPO_NODE_LABEL_EXTENSION).str(); 77 | name += "." + extension; // assimp needs full names with extension 78 | } 79 | 80 | // 81 | // Bit depth 82 | // 83 | //if (obj.hasField(REPO_NODE_LABEL_BIT_DEPTH)) 84 | // bitDepth = obj.getField(REPO_NODE_LABEL_BIT_DEPTH).numberInt(); 85 | 86 | // 87 | // Data 88 | // 89 | if (obj.hasField(REPO_LABEL_DATA) && 90 | obj.hasField(REPO_NODE_LABEL_DATA_BYTE_COUNT)) 91 | { 92 | 93 | std::cerr << "Texture" << std::endl; 94 | data = new std::vector(); 95 | RepoTranscoderBSON::retrieve( 96 | obj.getField(REPO_LABEL_DATA), 97 | obj.getField(REPO_NODE_LABEL_DATA_BYTE_COUNT).numberInt(), 98 | data); 99 | } 100 | } 101 | 102 | //------------------------------------------------------------------------------ 103 | // 104 | // Destructor 105 | // 106 | //------------------------------------------------------------------------------ 107 | repo::core::RepoNodeTexture::~RepoNodeTexture() 108 | { 109 | if (NULL != data) 110 | { 111 | data->clear(); 112 | delete data; 113 | data = NULL; 114 | } 115 | } 116 | 117 | //------------------------------------------------------------------------------ 118 | // 119 | // Operators 120 | // 121 | //------------------------------------------------------------------------------ 122 | 123 | bool repo::core::RepoNodeTexture::operator==(const RepoNodeAbstract& other) const 124 | { 125 | const RepoNodeTexture *otherTexture = dynamic_cast(&other); 126 | return otherTexture && 127 | RepoNodeAbstract::operator==(other) && 128 | this->getWidth() == otherTexture->getWidth() && 129 | this->getHeight() == otherTexture->getHeight() && 130 | this->getExtension() == otherTexture->getExtension() && 131 | std::equal(this->getData()->begin(), 132 | this->getData()->end(), 133 | otherTexture->getData()->begin()); 134 | } 135 | 136 | 137 | //------------------------------------------------------------------------------ 138 | // 139 | // Export 140 | // 141 | //------------------------------------------------------------------------------ 142 | mongo::BSONObj repo::core::RepoNodeTexture::toBSONObj() const 143 | { 144 | mongo::BSONObjBuilder builder; 145 | 146 | // Compulsory fields such as _id, type, api as well as path 147 | // and optional name 148 | appendDefaultFields(builder); 149 | 150 | // 151 | // Width 152 | // 153 | builder << REPO_LABEL_WIDTH << width; 154 | 155 | // 156 | // Height 157 | // 158 | builder << REPO_LABEL_HEIGHT << height; 159 | 160 | // 161 | // Format 162 | // 163 | builder << REPO_NODE_LABEL_EXTENSION << extension; 164 | 165 | // 166 | // Bit depth 167 | // 168 | //builder << REPO_NODE_LABEL_BIT_DEPTH << bitDepth; 169 | 170 | // 171 | // Data 172 | // 173 | if (NULL != data && data->size() > 0) 174 | RepoTranscoderBSON::append( 175 | REPO_LABEL_DATA, 176 | data, 177 | builder, 178 | REPO_NODE_LABEL_DATA_BYTE_COUNT); 179 | 180 | return builder.obj(); 181 | } 182 | -------------------------------------------------------------------------------- /src/cli.cpp: -------------------------------------------------------------------------------- 1 | #include "mongoclientwrapper.h" 2 | #include "graph/repo_node_types.h" 3 | #include "graph/repo_node_revision.h" 4 | #include "graph/repo_graph_scene.h" 5 | #include "graph/repo_node_texture.h" 6 | 7 | #include "compute/render.h" 8 | 9 | #include "repocore.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "assimpwrapper.h" 22 | 23 | const std::string HelpStr("help"); 24 | const std::string CacheStr("cache"); 25 | const std::string DBListStr("dblist"); 26 | const std::string ExportStr("export"); 27 | 28 | std::string prog_name; 29 | 30 | void print_usage() 31 | { 32 | std::cout << prog_name << " [" << HelpStr << "|" << CacheStr << "|" << DBListStr << "|" << ExportStr << "] [db_name] [export_filename]" << std::endl; 33 | } 34 | 35 | void getHeadRevision(repo::core::MongoClientWrapper &mongo, std::string dbname, repo::core::RepoGraphScene *& sceneLoader) 36 | { 37 | // Read Head Revision 38 | std::vector data; 39 | //unsigned long long retrieved = 0; 40 | 41 | std::list fieldsToReturn; 42 | fieldsToReturn.push_back(REPO_NODE_LABEL_CURRENT_UNIQUE_IDS); 43 | 44 | std::cout << "Loading full collection .... "; 45 | repo::core::RepoCore core; 46 | mongo.fetchEntireCollection(dbname, "scene", data); 47 | std::cout << "done." << std::endl; 48 | 49 | sceneLoader = new repo::core::RepoGraphScene(data); 50 | } 51 | 52 | enum Params 53 | { 54 | ProgName, HostParam, PortParam, UsernameParam, PasswordParam, OperationParam, DBNameParam, ExportNameParam 55 | }; 56 | 57 | // Very basic loader 58 | int main(int argc, char **argv) 59 | { 60 | prog_name = std::string(argv[ProgName]); 61 | 62 | if (argc < (OperationParam + 1)) 63 | { 64 | print_usage(); 65 | return -1; 66 | } 67 | 68 | std::string host = std::string(argv[HostParam]); 69 | int port = atoi(argv[PortParam]); 70 | std::string username = std::string(argv[UsernameParam]); 71 | std::string password = std::string(argv[PasswordParam]); 72 | std::string operation = std::string(argv[OperationParam]); 73 | 74 | if (!operation.compare(HelpStr)) 75 | { 76 | print_usage(); 77 | return 0; 78 | } 79 | 80 | repo::core::MongoClientWrapper mongo; 81 | std::cout << "Connecting to " << host << " " << port << std::endl; 82 | if(mongo.connect(host.c_str(), port)) 83 | { 84 | mongo.authenticate(username, password); 85 | } else { 86 | std::cout << "Could not connect to the database" << std::endl; 87 | return -1; 88 | } 89 | 90 | if (!operation.compare(DBListStr)) { 91 | std::list databases = mongo.getDatabases(true); 92 | 93 | for(std::list::iterator db = databases.begin(); db != databases.end(); ++db) 94 | { 95 | std::cerr << (*db) << std::endl; 96 | } 97 | 98 | return 0; 99 | 100 | } else if (!operation.compare(ExportStr)) { 101 | if (argc < (ExportNameParam + 1)) 102 | { 103 | print_usage(); 104 | return -1; 105 | } 106 | 107 | std::string dbname = std::string(argv[DBNameParam]); 108 | std::string exportname = std::string(argv[ExportNameParam]); 109 | 110 | repo::core::RepoGraphScene *sceneLoader; 111 | getHeadRevision(mongo, dbname, sceneLoader); 112 | 113 | aiScene *scene = new aiScene(); 114 | sceneLoader->toAssimp(scene); 115 | 116 | std::map nameTextures; 117 | std::vector textures = sceneLoader->getTextures(); 118 | 119 | for(unsigned int i = 0; i < textures.size(); i++) 120 | { 121 | repo::core::RepoNodeTexture *repoTex = textures[i]; 122 | const unsigned char* data = (unsigned char*) repoTex->getData(); 123 | QImage image = QImage::fromData(data, repoTex->getRawDataSize()); 124 | nameTextures.insert(std::make_pair(repoTex->getName(), image)); 125 | } 126 | 127 | QFileInfo fileInfo(QString::fromStdString(exportname)); 128 | QDir directory = fileInfo.absoluteDir(); 129 | QString fileExtension = fileInfo.completeSuffix(); 130 | 131 | repo::core::AssimpWrapper exporter; 132 | std::string embeddedTextureExtension = ".jpg"; 133 | 134 | bool success = exporter.exportModel(scene, 135 | repo::core::AssimpWrapper::getExportFormatID(fileExtension.toStdString()), 136 | exportname, 137 | embeddedTextureExtension); 138 | 139 | if (!success) 140 | { 141 | std::cout << "Error exporting model" << std::endl; 142 | return -1; 143 | } else { 144 | const std::vector &texs = sceneLoader->getTextures(); 145 | 146 | for (std::vector::const_iterator it = texs.begin(); it != texs.begin(); ++it) 147 | { 148 | repo::core::RepoNodeTexture* tex = (*it); 149 | const unsigned char* data = (unsigned char*) tex->getData(); 150 | QImage image = QImage::fromData(data, tex->getRawDataSize()); 151 | QString filename = QString::fromStdString(tex->getName()); 152 | 153 | if (scene->HasTextures()) 154 | { 155 | std::string name = tex->getName(); 156 | name = name.substr(1, name.size()); 157 | filename = QString::fromStdString(name + embeddedTextureExtension); 158 | } 159 | 160 | QFileInfo fi(directory, filename); 161 | image.save(fi.absoluteFilePath()); 162 | } 163 | } 164 | 165 | } else if (!operation.compare(CacheStr)) { 166 | if (argc < (DBNameParam + 1)) 167 | { 168 | print_usage(); 169 | return -1; 170 | } 171 | 172 | std::string dbname = std::string(argv[DBNameParam]); 173 | repo::core::RepoGraphScene *sceneLoader = NULL; 174 | 175 | getHeadRevision(mongo, dbname, sceneLoader); 176 | repo::core::Renderer rend(sceneLoader); 177 | std::vector out; 178 | rend.renderToBSONs(out); 179 | 180 | mongo.deleteAllRecords(dbname, "repo.cache"); 181 | 182 | for(std::vector::iterator it = out.begin(); it != out.end(); ++it) 183 | { 184 | mongo.insertRecord(dbname, "repo.cache", (*it)); 185 | } 186 | 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/graph/repo_node_camera.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | 19 | #ifndef REPO_NODE_CAMERA_H 20 | #define REPO_NODE_CAMERA_H 21 | 22 | //------------------------------------------------------------------------------ 23 | #include "repo_node_abstract.h" 24 | //------------------------------------------------------------------------------ 25 | #include "assimp/scene.h" 26 | //------------------------------------------------------------------------------ 27 | 28 | namespace repo { 29 | namespace core { 30 | 31 | //------------------------------------------------------------------------------ 32 | // 33 | // Fields specific to camera only 34 | // 35 | //------------------------------------------------------------------------------ 36 | #define REPO_NODE_TYPE_CAMERA "camera" 37 | #define REPO_NODE_LABEL_ASPECT_RATIO "aspect_ratio" 38 | #define REPO_NODE_LABEL_FAR "far" 39 | #define REPO_NODE_LABEL_NEAR "near" 40 | #define REPO_NODE_LABEL_FOV "fov" 41 | #define REPO_NODE_LABEL_LOOK_AT "look_at" 42 | #define REPO_NODE_LABEL_POSITION "position" 43 | #define REPO_NODE_LABEL_UP "up" 44 | #define REPO_NODE_UUID_SUFFIX_CAMERA "04" //!< uuid suffix 45 | //------------------------------------------------------------------------------ 46 | 47 | class REPO_CORE_EXPORT RepoNodeCamera : public RepoNodeAbstract 48 | { 49 | 50 | public : 51 | 52 | //-------------------------------------------------------------------------- 53 | // 54 | // Constructors 55 | // 56 | //-------------------------------------------------------------------------- 57 | //! Basic constructor, uuid will be randomly generated. 58 | inline RepoNodeCamera() : 59 | RepoNodeAbstract(REPO_NODE_TYPE_CAMERA, REPO_NODE_API_LEVEL_1), 60 | aspectRatio(0), 61 | farClippingPlane(1000), 62 | nearClippingPlane(0.1), 63 | fieldOfView(1/4 * 3.14), 64 | lookAt(0,0,1), 65 | position(0,0,0), 66 | up(0,1,0) {} 67 | 68 | //! Constructs camera scene graph node from Assimp's aiCamera. 69 | /*! 70 | * If camera has a name, it is hashed into a uuid, otherwise a random 71 | * uuid is created. 72 | * 73 | * \param camera Assimp camera 74 | * 75 | * \sa RepoNodeCamera() 76 | */ 77 | RepoNodeCamera(const aiCamera *camera); 78 | 79 | //! Constructs camera scene graph component from a BSON object. 80 | /*! 81 | * Same as all other components, it has to have a uuid, type, api 82 | * and optional name. 83 | * 84 | * \param obj BSON representation 85 | * \sa RepoNodeCamera() 86 | */ 87 | RepoNodeCamera(const mongo::BSONObj &obj); 88 | 89 | //-------------------------------------------------------------------------- 90 | // 91 | // Destructor 92 | // 93 | //-------------------------------------------------------------------------- 94 | 95 | //! Empty destructor. 96 | ~RepoNodeCamera() {} 97 | 98 | //-------------------------------------------------------------------------- 99 | // 100 | // Operators 101 | // 102 | //-------------------------------------------------------------------------- 103 | 104 | //! Returns true if the given node is identical to this, false otherwise. 105 | virtual bool operator==(const RepoNodeAbstract&) const; 106 | 107 | //-------------------------------------------------------------------------- 108 | // 109 | // Export 110 | // 111 | //-------------------------------------------------------------------------- 112 | 113 | //! BSONObj representation. 114 | /*! 115 | * Returns a BSON representation of this repository object suitable for a 116 | * direct MongoDB storage. 117 | * 118 | * \return BSON representation 119 | */ 120 | mongo::BSONObj toBSONObj() const; 121 | 122 | //! Assimp's aiCamera representation 123 | /*! 124 | * Populates given Assimp's aiCamera with values stored in this camera. 125 | * Transformation node shares name with the camera in Assimp. 126 | */ 127 | void toAssimp(aiCamera *camera) const; 128 | 129 | //-------------------------------------------------------------------------- 130 | // 131 | // Accessors 132 | // 133 | //-------------------------------------------------------------------------- 134 | 135 | //! Aspect ratio accessor 136 | float getAspectRatio() const; 137 | 138 | //! Far clipping plane accessor 139 | float getFarClippingPlane() const; 140 | 141 | //! Near clipping plane accessor 142 | float getNearClippingPlane() const; 143 | 144 | //! Field of view accessor 145 | float getFieldOfView() const; 146 | 147 | //! Lookat vector accessor 148 | aiVector3D getLookAt() const; 149 | 150 | //! Position vector accessor 151 | aiVector3D getPosition() const; 152 | 153 | //! Up vector accessor 154 | aiVector3D getUp() const; 155 | 156 | //! Camera matrix computation 157 | aiMatrix4x4 getCameraMatrix() const; 158 | 159 | protected : 160 | 161 | float aspectRatio; //!< Aspect ratio. 162 | 163 | float farClippingPlane; //!< Far clipping plane. 164 | 165 | float nearClippingPlane; //!< Near clipping plane. Should not be 0 to avoid division by 0. 166 | 167 | float fieldOfView; //!< Field of view. 168 | 169 | aiVector3D lookAt; //!< LookAt vector relative to parent transformations. 170 | 171 | aiVector3D position; //! Position relative to parent transformations. 172 | 173 | aiVector3D up; //! Up vector relative to parent transformations. 174 | 175 | }; // end class 176 | 177 | } // end namespace core 178 | } // end namespace repo 179 | 180 | #endif // end REPO_NODE_CAMERA_H 181 | -------------------------------------------------------------------------------- /src/repologger.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 3D Repo Ltd 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as 6 | * published by the Free Software Foundation, either version 3 of the 7 | * License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "repologger.h" 19 | //------------------------------------------------------------------------------ 20 | #include 21 | #include 22 | //------------------------------------------------------------------------------ 23 | #if defined(_WIN32) || defined(_WIN64) 24 | # include 25 | # define getcwd _getcwd 26 | # define PATH_SEPARATOR "\\" 27 | #else 28 | # include 29 | # define PATH_SEPARATOR "/" 30 | #endif 31 | 32 | //------------------------------------------------------------------------------ 33 | 34 | const std::string repo::core::RepoLogger::DEFAULT_LOG_EXTENSION = ".log"; 35 | 36 | //------------------------------------------------------------------------------ 37 | // 38 | // Private 39 | // 40 | //------------------------------------------------------------------------------ 41 | 42 | repo::core::RepoLogger::RepoLogger() 43 | : coutStreamBuffer(0) 44 | , cerrStreamBuffer(0) 45 | { 46 | // coutStreamBuffer = new RepoStreamBuffer(this, std::cout); 47 | //freopen(getFilename().c_str(), "a", stdout); 48 | 49 | // cerrStreamBuffer = new RepoStreamBuffer(this, std::cerr); 50 | //freopen(getFilename().c_str(), "a", stderr); 51 | } 52 | 53 | repo::core::RepoLogger::~RepoLogger() 54 | { 55 | // Clean up allocated memory 56 | if (coutStreamBuffer) 57 | delete coutStreamBuffer; 58 | //fclose(stdout); 59 | 60 | if (cerrStreamBuffer) 61 | delete cerrStreamBuffer; 62 | //fclose(stderr); 63 | } 64 | 65 | //------------------------------------------------------------------------------ 66 | // 67 | // Public 68 | // 69 | //------------------------------------------------------------------------------ 70 | 71 | repo::core::RepoLogger &repo::core::RepoLogger::instance() 72 | { 73 | // Static variable is created and destroyed only once. 74 | static RepoLogger instance; 75 | return instance; 76 | } 77 | 78 | std::string repo::core::RepoLogger::getHtmlFormattedMessage( 79 | const std::string &message, 80 | const RepoSeverity &severity) const 81 | { 82 | std::stringstream formatted; 83 | 84 | //-------------------------------------------------------------------------- 85 | // Retrieve current time 86 | time_t t = time(0); // get time now 87 | const struct tm *now = localtime(&t); 88 | formatted << normalize(now->tm_hour); 89 | formatted << ":"; 90 | formatted << normalize(now->tm_min); 91 | formatted << ":"; 92 | formatted << normalize(now->tm_sec); 93 | formatted << " - "; 94 | 95 | //------------------------------------------------------------------------- 96 | // HTML formatting 97 | formatted << ""; 100 | formatted << severity; 101 | formatted << " - "; 102 | 103 | //-------------------------------------------------------------------------- 104 | // Code formatting for debug severity level only 105 | if (severity.getValue() == RepoSeverity::REPO_DEBUG_NUM) 106 | formatted << "" << message << ""; 107 | else 108 | formatted << message; 109 | 110 | formatted << "
"; 111 | return formatted.str(); 112 | } 113 | 114 | std::string repo::core::RepoLogger::getFilename( 115 | const std::string &extension) 116 | { 117 | std::stringstream fileNameStream; 118 | time_t t = time(0); 119 | const struct tm *now = localtime(&t); 120 | fileNameStream << (now->tm_year + 1900); 121 | fileNameStream << "-"; 122 | fileNameStream << normalize(now->tm_mon + 1); 123 | fileNameStream << "-"; 124 | fileNameStream << normalize(now->tm_mday); 125 | fileNameStream << extension; 126 | 127 | std::string generated = fileNameStream.str(); 128 | if (generated != filename) 129 | { 130 | filename = generated; 131 | log("Log: " + getFullFilePath(), 132 | RepoSeverity::REPO_NOTICE); 133 | } 134 | return filename; 135 | } 136 | 137 | std::string repo::core::RepoLogger::getFullFilePath() 138 | { 139 | return getWorkingDirectory() + PATH_SEPARATOR + getFilename(); 140 | } 141 | 142 | std::string repo::core::RepoLogger::getWorkingDirectory() 143 | { 144 | char temp[FILENAME_MAX]; 145 | return (getcwd(temp, FILENAME_MAX) ? std::string(temp) : std::string()); 146 | } 147 | 148 | void repo::core::RepoLogger::log( 149 | const std::string &msg, 150 | const RepoSeverity &severity) 151 | { 152 | std::string filename = getFilename(); 153 | std::string formattedMessage = getHtmlFormattedMessage(msg, severity); 154 | 155 | notifyListeners(formattedMessage); 156 | 157 | std::ofstream file(filename, std::ios::app); 158 | if (!file.is_open()) 159 | { 160 | notifyListeners( 161 | getHtmlFormattedMessage( 162 | "Cannot write to log file: " + getFullFilePath(), 163 | RepoSeverity::REPO_CRITICAL)); 164 | } 165 | else 166 | { 167 | file << formattedMessage << std::endl; 168 | file.close(); 169 | } 170 | } 171 | 172 | void repo::core::RepoLogger::messageGenerated( 173 | const std::ostream *sender, 174 | const std::string &message) 175 | { 176 | log(message, sender == &(std::cerr) 177 | ? RepoSeverity::REPO_ERROR 178 | : RepoSeverity::REPO_INFO); 179 | } 180 | 181 | std::string repo::core::RepoLogger::normalize(int n) 182 | { 183 | std::stringstream str; 184 | if (n < 10) 185 | str << "0"; 186 | str << n; 187 | return str.str(); 188 | } 189 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 3D Repo Core (DEPRECATED) 2 | ======== 3 | 4 | This library is deprecated and has been replaced by [3drepobouncer](https://github.com/3drepo/3drepobouncer). 5 | 6 | 7 | ``` 8 | > C++ library providing 3D Repo Scene Graph definition and repository management logic. 9 | 10 | > ## Licenses 11 | > This project is Copyright of [3D Repo Ltd](http://3drepo.org), a company registered in England and Wales No. 09014101, and is released under the open source [GNU Affero General Public License v3](http://www.gnu.org/licenses/agpl-3.0.en.html). Should you require a commercial license, please contact [support@3drepo.org](mailto:support@3drepo.org). All contributors are required to sign either the [3D Repo Individual](https://gist.github.com/jozefdobos/e177af804c9bcd217b73) or the [3D Repo Entity](https://gist.github.com/jozefdobos/c7c4c1c18cfb211c45d2) [Contributor License Agreement (CLA)](https://en.wikipedia.org/wiki/Contributor_License_Agreement). 12 | 13 | > ### Contributing 14 | > We very much encourage contributions to the 3D Repo project. Firstly, fork the desired repository and commit your modifications there. Once happy with the changes, you can generate a [pull request](https://help.github.com/articles/using-pull-requests/) and our team will integrate it upstream after a review. 15 | 16 | > Your pull requests should: 17 | 18 | > 1. Follow the style of the existing code 19 | > 2. One commit should just do one thing, and one thing only 20 | > 3. Work in a branch assigned to a specific issue number, e.g. branch called "ISSUE_138" 21 | > 4. Each commit message should be prefixed with the issue number, e.g. "#138 Fixing bug xyz..." 22 | > 5. Rebase your branch against [upstream's master](https://help.github.com/articles/merging-an-upstream-repository-into-your-fork/) so that we don't pull redundant commits 23 | > 6. Sign our [3D Repo Individual CLA](https://gist.github.com/jozefdobos/e177af804c9bcd217b73) or if you are representing a legal entity, sign the [3D Repo Entity CLA](https://gist.github.com/jozefdobos/c7c4c1c18cfb211c45d2) 24 | 25 | > ## Dependencies 26 | 27 | > - [Boost 1.56.0](https://github.com/boostorg/boost/tree/boost-1.56.0) 28 | > - [MongoDB 2.6 Compatible C++ Driver 2.6.4](https://github.com/mongodb/mongo-cxx-driver/tree/legacy-0.0-26compat-2.6.4) 29 | > - [Assimp v3.1.1](https://github.com/assimp/assimp/tree/v3.1.1) 30 | 31 | > Both MongoDB and Assimp make use of Boost, so make sure this is installed first. 32 | 33 | > ## Compiling on Windows 34 | 35 | > ### Boost 36 | 37 | > For Windows, download pre-built binaries [http://sourceforge.net/projects/boost/files/boost-binaries/](http://sourceforge.net/projects/boost/files/boost-binaries/) 38 | 39 | > There is also a GitHub transition taking place: 40 | > [https://svn.boost.org/trac/boost/wiki/ModularBoost](https://svn.boost.org/trac/boost/wiki/ModularBoost) 41 | > If using Modular Boost, make sure to recursively update submodules since each boost library within the super projec is in itself a submodule. 42 | 43 | > ### MongoDB 44 | 45 | > Assuming you've installed the 64-bit pre-built boost libraries for VC120 (MSVS2013) 46 | 47 | > - Install [Python2x (32-bit)](https://www.python.org/download) and add Python to your PATH variable, e.g. C:\Python27; 48 | > - Install [Scons](http://www.scons.org/download.php) and add Scons to your PATH variable, e.g. C:\Python27\Scripts 49 | > - Optionally, you can also install [Pywin32](http://sourceforge.net/projects/pywin32/files/pywin32/) to enable parallel compile (the -j2 flag below). 50 | 51 | > Then compile MongoDB running the following from within the mongo-cxx-driver folder (modify the boost path to match your setup): 52 | 53 | > scons -j2 --full --64 --mute --sharedclient --dynamic-windows --use-system-boost --extrapath=c:\local\boost_1_56_0 --cpppath=c:\local\boost_1_56_0 --libpath=c:\local\boost_1_56_0\lib64-msvc-12.0 install-mongoclient 54 | > Add --dbg=on --opt=on flags to build a debug version of the library. 55 | 56 | > Alternatively, you can include [SCons in your IDE](http://www.scons.org/wiki/IDEIntegration). 57 | 58 | > Include the WinSock library in your application: Linker > Input > Additional Dependencies. Add ws2_32.lib. 59 | 60 | > If you want to build a Qt project, first you need to generate MongoDB error codes using Python: 61 | 62 | > cd submodules/mongo-cxx-driver/src/mongo/base 63 | > python generate_error_codes.py error_codes.err error_codes.h error_codes.cpp 64 | 65 | > ### Assimp 66 | 67 | > When building using CMake GUI, make sure to disable ASSIMP_ENABLE_BOOST_WORKAROUND variable and instead use +Add Entry button on the right-hand side to include a path to your boost installation as BOOST_ROOT variable. 68 | > See also [http://assimp.sourceforge.net/lib_html/cmake_build.html](http://assimp.sourceforge.net/lib_html/cmake_build.html) 69 | 70 | > To be able to compile Assimp Tools, you also need to install [DirectX SDK](http://www.microsoft.com/en-gb/download/details.aspx?id=6812). If you have Microsoft Visual C++ 2010 Redistributable, make sure to uninstall it from Programs and Features first. 71 | 72 | > ### 3drepocore 73 | 74 | > Finally to compile the library itself, open the build.pro project from qtcreator and build. 75 | 76 | > ## Compiling on Mac 77 | 78 | > The following instructions explain how to compile the 3drepocore library on Yosemite. 79 | 80 | > You will need boost, scons and cmake installed on your machine. You can get them from homebrew: 81 | > brew install boost 82 | > brew install scons 83 | > brew install cmake 84 | 85 | > ### MongoDB 86 | 87 | > To compile MongoDB, run the following command: 88 | > scons -j2 --full --64 --mute --sharedclient --osx-version-min=10.9 --use-system-boost install-mongoclient 89 | 90 | > ### Assimp 91 | 92 | > Assimp uses cmake. Make a folder named **build** at the root of the assimp submodule directly. Then, run the following commands: 93 | 94 | > cd build 95 | > ccmake .. 96 | 97 | > Choose the following options: 98 | 99 | > ASSIMP_ENABLE_BOOST_WORKAROUND -> off 100 | > ASSIMP_BUILD_TESTS -> off 101 | 102 | > Generate the project, and finally run: 103 | 104 | > make -j8 105 | 106 | > ### 3drepocore 107 | 108 | > Finally to compile the library itself, open the build.pro project from qtcreator and build. 109 | 110 | > ## Compiling on Linux 111 | 112 | > ## Contributing 113 | > We encourage continuous development of 3D Repo by the community and welcome any fixes and improvements. By sending a pull request, you agree that the modifications are solely your work and assign the copyright to 3D Repo Ltd 114 | 115 | ``` 116 | --------------------------------------------------------------------------------