Exemplo n.º 1
0
std::vector<RepoNode*> RepoScene::getParentNodesFiltered(
	const GraphType &gType,
	const RepoNode* node,
	const NodeType &type) const
{
	std::vector<RepoNode*> results;
	if (node)
	{
		std::vector<repoUUID> parentIDs = node->getParentIDs();

		for (const repoUUID &id : parentIDs)
		{
			RepoNode* node = getNodeBySharedID(gType, id);
			if (node && node->getTypeAsEnum() == type)
			{
				results.push_back(node);
			}
		}
	}
	else
	{
		repoError << "Trying to retrieve parent nodes from a null ptr child node";
	}

	return results;
}
Exemplo n.º 2
0
bool RepoScene::addNodeToScene(
	const GraphType &gType,
	const RepoNodeSet nodes,
	std::string &errMsg,
	RepoNodeSet *collection)
{
	bool success = true;
	RepoNodeSet::iterator nodeIterator;
	if (nodes.size() > 0)
	{
		collection->insert(nodes.begin(), nodes.end());
		for (nodeIterator = nodes.begin(); nodeIterator != nodes.end(); ++nodeIterator)
		{
			RepoNode * node = *nodeIterator;
			if (node)
			{
				if (!addNodeToMaps(gType, node, errMsg))
				{
					repoError << "failed to add node (" << node->getUniqueID() << " to scene graph: " << errMsg;
					success = false;
				}
			}
			if (gType == GraphType::DEFAULT)
				newAdded.insert(node->getSharedID());
		}
	}

	return success;
}
Exemplo n.º 3
0
bool MapNode::sEqual(const RepoNode &other) const
{
	if (other.getTypeAsEnum() != NodeType::MAP || other.getParentIDs().size() != getParentIDs().size())
	{
		return false;
	}

	//TODO:
	repoError << "Semantic comparison of map nodes are currently not supported!";
	return false;
}
Exemplo n.º 4
0
bool CameraNode::sEqual(const RepoNode &other) const
{
	if (other.getTypeAsEnum() != NodeType::CAMERA || other.getParentIDs().size() != getParentIDs().size())
	{
		return false;
	}

	const CameraNode otherCam = CameraNode(other);


	std::vector<float> mat = getCameraMatrix();
	std::vector<float> otherMat = otherCam.getCameraMatrix();


	return !memcmp(mat.data(), otherMat.data(), mat.size() *sizeof(*mat.data()));

}
TEST(RepoBSONTest, AppendDefaultsTest)
{
	RepoBSONBuilder builder;

	RepoBSONFactory::appendDefaults(
		builder, "test");

	RepoNode n = builder.obj();

	EXPECT_FALSE(n.isEmpty());

	EXPECT_EQ(4, n.nFields()); 

	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_ID));
	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_SHARED_ID));
	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_API));
	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_TYPE));

	//Ensure existing fields doesnt' disappear

	RepoBSONBuilder builderWithFields;

	builderWithFields << "Number" << 1023;
	builderWithFields << "doll" << "Kitty";

	RepoBSONFactory::appendDefaults(
		builderWithFields, "test");

}
Exemplo n.º 6
0
void RepoScene::modifyNode(
	const GraphType                   &gtype,
	RepoNode                          *nodeToChange,
	RepoNode                          *newNode,
	const bool						  &overwrite)
{
	if (!nodeToChange || !newNode)
	{
		repoError << "Failed to modify node in scene (node is nullptr)";
		return;
	}
	repoGraphInstance &g = gtype == GraphType::OPTIMIZED ? stashGraph : graph;

	repoUUID sharedID = nodeToChange->getSharedID();

	RepoNode updatedNode;

	//generate new UUID if it  is not in list, otherwise use the current one.
	bool isInList = gtype == GraphType::OPTIMIZED ||
		(newAdded.find(sharedID) != newAdded.end() || newModified.find(sharedID) != newModified.end());
	updatedNode = overwrite ? *newNode : RepoNode(nodeToChange->cloneAndAddFields(newNode, !isInList));

	repoUUID newUniqueID = updatedNode.getUniqueID();

	if (gtype == GraphType::DEFAULT && !isInList)
	{
		newModified.insert(sharedID);
		newCurrent.erase(nodeToChange->getUniqueID());
		newCurrent.insert(newUniqueID);
	}

	//update shared to unique ID  and uniqueID to node mapping
	g.sharedIDtoUniqueID[sharedID] = newUniqueID;
	g.nodesByUniqueID.erase(nodeToChange->getUniqueID());
	g.nodesByUniqueID[newUniqueID] = nodeToChange;

	nodeToChange->swap(updatedNode);
}
Exemplo n.º 7
0
bool RepoScene::commitNodes(
	repo::core::handler::AbstractDatabaseHandler *handler,
	const std::vector<repoUUID> &nodesToCommit,
	const GraphType &gType,
	std::string &errMsg)
{
	bool success = true;

	bool isStashGraph = gType == GraphType::OPTIMIZED;
	repoGraphInstance &g = isStashGraph ? stashGraph : graph;
	std::string ext = isStashGraph ? stashExt : sceneExt;

	size_t count = 0;
	size_t total = nodesToCommit.size();

	repoInfo << "Committing " << total << " nodes...";

	for (const repoUUID &id : nodesToCommit)
	{
		if (++count % 500 == 0 || count == total - 1)
		{
			repoInfo << "Committing " << count << " of " << total;
		}

		const repoUUID uniqueID = gType == GraphType::OPTIMIZED ? id : g.sharedIDtoUniqueID[id];
		RepoNode *node = g.nodesByUniqueID[uniqueID];
		if (node->objsize() > handler->documentSizeLimit())
		{
			//Try to extract binary data out of the bson to shrink it.
			RepoNode shrunkNode = node->cloneAndShrink();
			if (shrunkNode.objsize() > handler->documentSizeLimit())
			{
				success = false;
				errMsg += "Node '" + UUIDtoString(node->getUniqueID()) + "' over 16MB in size is not committed.";
			}
			else
			{
				node->swap(shrunkNode);
				success &= handler->insertDocument(databaseName, projectName + "." + ext, *node, errMsg);
			}
		}
		else
			success &= handler->insertDocument(databaseName, projectName + "." + ext, *node, errMsg);
	}

	return success;
}
Exemplo n.º 8
0
bool MeshNode::sEqual(const RepoNode &other) const
{
	if (other.getTypeAsEnum() != NodeType::MESH || other.getParentIDs().size() != getParentIDs().size())
	{
		return false;
	}

	MeshNode otherMesh = MeshNode(other);

	std::vector<repo_vector_t> vertices, vertices2, normals, normals2;
	std::vector<repo_vector2d_t> uvChannels, uvChannels2;
	std::vector<uint32_t> facesSerialized, facesSerialized2;
	std::vector<repo_color4d_t> colors, colors2;

	vertices = getVertices();
	vertices2 = otherMesh.getVertices();

	normals = getNormals();
	normals2 = otherMesh.getNormals();

	uvChannels = getUVChannels();
	uvChannels2 = otherMesh.getUVChannels();

	facesSerialized = getFacesSerialized();
	facesSerialized2 = otherMesh.getFacesSerialized();

	colors = getColors();
	colors2 = otherMesh.getColors();

	//check all the sizes match first, as comparing the content will be costly
	bool success = vertices.size() == vertices2.size()
		&& normals.size() == normals2.size()
		&& uvChannels.size() == uvChannels2.size()
		&& facesSerialized.size() == facesSerialized2.size()
		&& colors.size() == colors2.size();

	if (success)
	{
		if (vertices.size())
		{
			success &= !memcmp(vertices.data(), vertices2.data(), vertices.size() * sizeof(*vertices.data()));
		}

		if (success && normals.size())
		{
			success &= !memcmp(normals.data(), normals2.data(), normals.size() * sizeof(*normals.data()));
		}

		if (success && uvChannels.size())
		{
			success &= !memcmp(uvChannels.data(), uvChannels2.data(), uvChannels.size() * sizeof(*uvChannels.data()));
		}

		if (success && colors.size())
		{
			success &= !memcmp(colors.data(), colors2.data(), colors.size() * sizeof(*colors.data()));
		}

		if (success && facesSerialized.size())
		{
			success &= !memcmp(facesSerialized.data(), facesSerialized.data(), facesSerialized.size() * sizeof(*facesSerialized.data()));
		}
	}

	return success;
}
Exemplo n.º 9
0
TEST(RepoBSONFactoryTest, AppendDefaultsTest)
{
	RepoBSONBuilder builder;

	auto defaults = RepoBSONFactory::appendDefaults("test");
	builder.appendElements(defaults);

	RepoNode n = builder.obj();

	EXPECT_FALSE(n.isEmpty());

	EXPECT_EQ(4, n.nFields());

	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_ID));
	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_SHARED_ID));
	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_API));
	EXPECT_TRUE(n.hasField(REPO_NODE_LABEL_TYPE));

	//Ensure existing fields doesnt' disappear

	RepoBSONBuilder builderWithFields;

	builderWithFields << "Number" << 1023;
	builderWithFields << "doll" << "Kitty";

	auto defaults2 = RepoBSONFactory::appendDefaults("test");
	builderWithFields.appendElements(defaults2);

	RepoNode nWithExists = builderWithFields.obj();
	EXPECT_FALSE(nWithExists.isEmpty());

	EXPECT_EQ(6, nWithExists.nFields());

	EXPECT_TRUE(nWithExists.hasField(REPO_NODE_LABEL_ID));
	EXPECT_TRUE(nWithExists.hasField(REPO_NODE_LABEL_SHARED_ID));
	EXPECT_TRUE(nWithExists.hasField(REPO_NODE_LABEL_API));
	EXPECT_TRUE(nWithExists.hasField(REPO_NODE_LABEL_TYPE));

	EXPECT_TRUE(nWithExists.hasField("doll"));
	EXPECT_EQ("Kitty", std::string(nWithExists.getStringField("doll")));
	EXPECT_TRUE(nWithExists.hasField("Number"));
	EXPECT_EQ(nWithExists.getField("Number").Int(), 1023);
}
Exemplo n.º 10
0
void RepoScene::removeNode(
	const GraphType                   &gtype,
	const repoUUID                    &sharedID
	)
{
	repoGraphInstance &g = gtype == GraphType::OPTIMIZED ? stashGraph : graph;
	RepoNode *node = getNodeBySharedID(gtype, sharedID);
	if (node)
	{
		//Remove entry from everything.
		g.nodesByUniqueID.erase(node->getUniqueID());
		g.sharedIDtoUniqueID.erase(sharedID);
		g.parentToChildren.erase(sharedID);

		bool keepNode = false;
		if (gtype == GraphType::DEFAULT)
		{
			//If this node was in newAdded or newModified, remove it
			std::set<repoUUID>::iterator iterator;
			if ((iterator = newAdded.find(sharedID)) != newAdded.end())
			{
				newAdded.erase(iterator);
			}
			else
			{
				if ((iterator = newModified.find(sharedID)) != newModified.end())
				{
					newModified.erase(iterator);
				}

				newRemoved.insert(sharedID);
				keepNode = true;
			}
		}

		//remove from the nodes sets
		switch (node->getTypeAsEnum())
		{
		case NodeType::CAMERA:
			g.cameras.erase(node);
			break;
		case NodeType::MATERIAL:
			g.materials.erase(node);
			break;
		case NodeType::MESH:
			g.meshes.erase(node);
			break;
		case NodeType::METADATA:
			g.metadata.erase(node);
			break;
		case NodeType::REFERENCE:
		{
			g.references.erase(node);
			//Since it's reference node, also delete the referenced scene
			RepoScene *s = g.referenceToScene[sharedID];
			delete s;
			g.referenceToScene.erase(sharedID);
		}
		break;
		case NodeType::TEXTURE:
			g.textures.erase(node);
			break;
		case NodeType::TRANSFORMATION:
			g.transformations.erase(node);
			break;
		case NodeType::UNKNOWN:
			g.unknowns.erase(node);
			break;
		default:
			repoError << "Unexpected node type: " << (int)node->getTypeAsEnum();
		}

		if (keepNode)
		{
			//add node onto the toRemove list
			toRemove.push_back(node);
		}
		else
			delete node;
	}
	else
	{
		repoError << "Trying to delete a node that doesn't exist!";
	}
}