Esempio n. 1
0
TEST(RepoBSONTest, GetField)
{
	EXPECT_EQ(testBson.getField("ice"), testBson.getField("ice"));
	EXPECT_NE(testBson.getField("ice"), testBson.getField("amount"));

	EXPECT_EQ("lolly", testBson.getField("ice").str());
	EXPECT_EQ(100, testBson.getField("amount").Int());
	EXPECT_TRUE(emptyBson.getField("hello").eoo());
}
Esempio n. 2
0
std::vector<repo_mesh_mapping_t> MeshNode::getMeshMapping() const
{
	std::vector<repo_mesh_mapping_t> mappings;
	RepoBSON mapArray = getObjectField(REPO_NODE_MESH_LABEL_MERGE_MAP);
	if (!mapArray.isEmpty())
	{
		std::set<std::string> fields;
		mapArray.getFieldNames(fields);
		mappings.resize(fields.size());
		for (const auto &name : fields)
		{
			repo_mesh_mapping_t mapping;
			RepoBSON mappingObj = mapArray.getObjectField(name);

			mapping.mesh_id = mappingObj.getUUIDField(REPO_NODE_MESH_LABEL_MAP_ID);
			mapping.material_id = mappingObj.getUUIDField(REPO_NODE_MESH_LABEL_MATERIAL_ID);
			mapping.vertFrom = mappingObj.getField(REPO_NODE_MESH_LABEL_VERTEX_FROM).Int();
			mapping.vertTo = mappingObj.getField(REPO_NODE_MESH_LABEL_VERTEX_TO).Int();
			mapping.triFrom = mappingObj.getField(REPO_NODE_MESH_LABEL_TRIANGLE_FROM).Int();
			mapping.triTo = mappingObj.getField(REPO_NODE_MESH_LABEL_TRIANGLE_TO).Int();

			RepoBSON boundingBox = mappingObj.getObjectField(REPO_NODE_MESH_LABEL_BOUNDING_BOX);

			std::vector<repo_vector_t> bboxVec = getBoundingBox(boundingBox);
			mapping.min.x = bboxVec[0].x;
			mapping.min.y = bboxVec[0].y;
			mapping.min.z = bboxVec[0].z;

			mapping.max.x = bboxVec[1].x;
			mapping.max.y = bboxVec[1].y;
			mapping.max.z = bboxVec[1].z;

			mappings[std::stoi(name)] = mapping;
		}
	}
	return mappings;
}
Esempio n. 3
0
std::vector<float> RepoBSON::getFloatArray(const std::string &label) const
{
	std::vector<float> results;
	if (hasField(label))
	{
		RepoBSON array = getObjectField(label);
		if (!array.isEmpty())
		{
			std::set<std::string> fields;
			array.getFieldNames(fields);

            // Pre allocate memory to speed up copying
            results.reserve(fields.size());
			for (auto field : fields)
				results.push_back(array.getField(field).numberDouble());
		}
		else
		{
			repoError << "getFloatArray: field " << label << " is an empty bson or wrong type!";
		}

	}
	return results;
}
Esempio n. 4
0
bool RepoScene::populate(
	const GraphType &gtype,
	repo::core::handler::AbstractDatabaseHandler *handler,
	std::vector<RepoBSON> nodes,
	std::string &errMsg)
{
	bool success = true;

	repoGraphInstance &g = gtype == GraphType::OPTIMIZED ? stashGraph : graph;

	std::unordered_map<repoUUID, RepoNode *, RepoUUIDHasher> nodesBySharedID;
	for (std::vector<RepoBSON>::const_iterator it = nodes.begin();
		it != nodes.end(); ++it)
	{
		RepoBSON obj = *it;
		RepoNode *node = NULL;

		std::string nodeType = obj.getField(REPO_NODE_LABEL_TYPE).str();

		if (REPO_NODE_TYPE_TRANSFORMATION == nodeType)
		{
			node = new TransformationNode(obj);
			g.transformations.insert(node);
		}
		else if (REPO_NODE_TYPE_MESH == nodeType)
		{
			node = new MeshNode(obj);
			g.meshes.insert(node);
		}
		else if (REPO_NODE_TYPE_MATERIAL == nodeType)
		{
			node = new MaterialNode(obj);
			g.materials.insert(node);
		}
		else if (REPO_NODE_TYPE_TEXTURE == nodeType)
		{
			node = new TextureNode(obj);
			g.textures.insert(node);
		}
		else if (REPO_NODE_TYPE_CAMERA == nodeType)
		{
			node = new CameraNode(obj);
			g.cameras.insert(node);
		}
		else if (REPO_NODE_TYPE_REFERENCE == nodeType)
		{
			node = new ReferenceNode(obj);
			g.references.insert(node);
		}
		else if (REPO_NODE_TYPE_METADATA == nodeType)
		{
			node = new MetadataNode(obj);
			g.metadata.insert(node);
		}		
		else{
			//UNKNOWN TYPE - instantiate it with generic RepoNode
			node = new RepoNode(obj);
			g.unknowns.insert(node);
		}

		success &= addNodeToMaps(gtype, node, errMsg);
	} //Node Iteration

	//deal with References
	RepoNodeSet::iterator refIt;
	//Make sure it is propagated into the repoScene if it exists in revision node

	if (g.references.size()) worldOffset.clear();
	for (const auto &node : g.references)
	{
		ReferenceNode* reference = (ReferenceNode*)node;

		//construct a new RepoScene with the information from reference node and append this g to the Scene
		std::string spDbName = reference->getDatabaseName();
		if (spDbName.empty()) spDbName = databaseName;
		RepoScene *refg = new RepoScene(spDbName, reference->getProjectName(), sceneExt, revExt);
		if (reference->useSpecificRevision())
			refg->setRevision(reference->getRevisionID());
		else
			refg->setBranch(reference->getRevisionID());

		//Try to load the stash first, if fail, try scene.
		if (refg->loadStash(handler, errMsg) || refg->loadScene(handler, errMsg))
		{
			g.referenceToScene[reference->getSharedID()] = refg;
			auto refOffset = refg->getWorldOffset();
			if (!worldOffset.size())
			{
				worldOffset = refOffset;
			}
		}
		else{
			repoWarning << "Failed to load reference node for ref ID" << reference->getUniqueID() << ": " << errMsg;
		}
	}
	repoTrace << "World Offset = [" << worldOffset[0] << " , " << worldOffset[1] << ", " << worldOffset[2] << " ]";
	//Now that we know the world Offset, make sure the referenced scenes are shifted accordingly
	for (const auto &node : g.references)
	{
		ReferenceNode* reference = (ReferenceNode*)node;
		auto parent = reference->getParentIDs().at(0);
		auto refScene = g.referenceToScene[reference->getSharedID()];
		auto refOffset = refScene->getWorldOffset();
		//Back to world coord of subProject
		std::vector<std::vector<float>> backToSubWorld =
		{ { 1., 0., 0., (float)refOffset[0] },
		{ 0., 1., 0., (float)refOffset[1] },
		{ 0., 0., 1., (float)refOffset[2] },
		{ 0., 0., 0., 1 } };
		std::vector<std::vector<float>> toFedWorldTrans =
		{ { 1., 0., 0., (float)-worldOffset[0] },
		{ 0., 1., 0., (float)-worldOffset[1] },
		{ 0., 0., 1., (float)-worldOffset[2] },
		{ 0., 0., 0., 1. } };

		//parent - ref
		//Becomes: toFedWorld - parent - toSubWorld - ref

		auto parentNode = getNodeBySharedID(GraphType::DEFAULT, parent);
		auto grandParent = parentNode->getParentIDs().at(0);
		auto grandParentNode = getNodeBySharedID(GraphType::DEFAULT, grandParent);
		auto toFedWorld = new TransformationNode(RepoBSONFactory::makeTransformationNode(toFedWorldTrans, "trans", { grandParent }));
		auto toSubWorld = new TransformationNode(RepoBSONFactory::makeTransformationNode(backToSubWorld, "trans", { parent }));
		std::vector<RepoNode*> newNodes;
		newNodes.push_back(toFedWorld);
		newNodes.push_back(toSubWorld);
		addNodes(newNodes);
		addInheritance(GraphType::DEFAULT, toSubWorld, reference);
		addInheritance(GraphType::DEFAULT, toFedWorld, parentNode);
		abandonChild(GraphType::DEFAULT, grandParent, parentNode);
		abandonChild(GraphType::DEFAULT, parent, reference);
		newModified.clear(); //We're still loading the scene, there shouldn't be anything here anyway.
	}

	return success;
}