<commit_before>/**
 *  Copyright (C) 2015 3D Repo Ltd
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "repo_3ddiffrenderer.h"

repo::gui::Repo3DDiffRenderer::Repo3DDiffRenderer(
	repo::RepoController *controller,
	const repo::RepoToken *token,
        RepoGLCWidget *widgetA,
        RepoGLCWidget *widgetB)
    : 
	controller(controller),
	token(token),
	widgetA(widgetA),
    widgetB(widgetB)
{

	repo::core::model::RepoScene *sceneA = widgetA->getRepoScene();
	repo::core::model::RepoScene *sceneB = widgetB->getRepoScene();

	std::vector<repoUUID> added, deleted, modified;
	controller->compareScenesByIDs(token, sceneA, sceneB, added, deleted, modified);

	for (const repoUUID id : added)
	{
		
		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneB->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH)
			widgetB->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
				0.9, Qt::green);
	}

	for (const repoUUID id : deleted)
	{

		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneA->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH )
			widgetA->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
				0.9, Qt::red);
	}

	for (const repoUUID id : modified)
	{

		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneB->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH)
			widgetB->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
				0.9, Qt::blue);	

	}

	widgetB->repaintCurrent();
//
//	//================================================= OLD CODE
//
//    
//
//        std::pair<core::RepoSelfSimilarSet::iterator, core::RepoSelfSimilarSet::iterator> keyRange = selfSimilarSetA.equal_range(key);
//        // Iterate over all map elements with key == key
//        for (valuesIt = keyRange.first;  valuesIt != keyRange.second;  ++valuesIt)
//        {
//            cout << "    value = " << (*valuesIt).second << " : " << (*valuesIt).second->getName() << endl;
//
////                    QMetaObject::invokeMethod(
////                                widgetA, "setGLCOccurrenceOpacity", Qt::QueuedConnection,
////                                Q_ARG(QString, QString::fromStdString((*valuesIt).second->getName())),
////                                Q_ARG(qreal, 0.9),
////                                Q_ARG(QColor, color));
//
//                    widgetA->setGLCOccurrenceOpacity(QString::fromStdString((*valuesIt).second->getName()),
//                                                     0.9, color);
//        }
//    }
//
//    std::string currentKey("");
//    RepoColor color;
//
//    for (auto it = selfSimilarSetA.begin(); it != selfSimilarSetA.end(); ++it)
//    {
//
//        core::RepoPCA pca = ((core::RepoNodeMesh*)(it->second))->getPCA();
//        const double lx = pca.getPrincipalComponent(core::RepoPCA::U).magnitude;
//        const double ly = pca.getPrincipalComponent(core::RepoPCA::V).magnitude;
//        const double lz = pca.getPrincipalComponent(core::RepoPCA::W).magnitude;
//
//        //                widgetA->addBoundingBox(
//        //                            pca.getUVWBoundingBox().getLengthX(),
//        //                            pca.getUVWBoundingBox().getLengthY(),
//        //                            pca.getUVWBoundingBox().getLengthZ(),
//        //                            pca.getXYZTransformationMatrix());
//
//        core::RepoNodeMesh* mesh = (core::RepoNodeMesh*)(it->second);
//        widgetA->addBoundingBox(mesh->getBoundingBox().getLengthX(),
//                                mesh->getBoundingBox().getLengthY(),
//                                mesh->getBoundingBox().getLengthZ(),
//                                core::RepoNodeTransformation::matrixToVector(mesh->getBoundingBoxTransformation()));
//    }
//    widgetA->updateGL();
//
//
//    //------------------------------------------------------------------
//
//    core::RepoSelfSimilarSet selfSimilarSetB = diff->getSelfSimilarSetB();
//    for (auto it = selfSimilarSetB.begin(); it != selfSimilarSetB.end(); ++it)
//    {
//        if(currentKey.compare(it->first))
//        {
//            currentKey = it->first;
//            color = RepoColor::getNext();
//        }
//
//        //				QMetaObject::invokeMethod(
//        //					widgetB, "setGLCOccurrenceOpacity", Qt::QueuedConnection,
//        //					Q_ARG(QString, QString::fromStdString(it->second->getName())),
//        //					Q_ARG(qreal, 0.9),
//        //					Q_ARG(QColor, color));
//
//        core::RepoNodeMesh* mesh = (core::RepoNodeMesh*)(it->second);
//        widgetB->addBoundingBox(mesh->getBoundingBox().getLengthX(),
//                                mesh->getBoundingBox().getLengthY(),
//                                mesh->getBoundingBox().getLengthZ(),
//                                core::RepoNodeTransformation::matrixToVector(mesh->getBoundingBoxTransformation()));
//    }
//    widgetB->paintGL();
}

repo::gui::Repo3DDiffRenderer::~Repo3DDiffRenderer()
{
    //delete diff;
}<commit_msg>#23 reflect changes on bouncer<commit_after>/**
 *  Copyright (C) 2015 3D Repo Ltd
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "repo_3ddiffrenderer.h"

repo::gui::Repo3DDiffRenderer::Repo3DDiffRenderer(
	repo::RepoController *controller,
	const repo::RepoToken *token,
        RepoGLCWidget *widgetA,
        RepoGLCWidget *widgetB)
    : 
	controller(controller),
	token(token),
	widgetA(widgetA),
    widgetB(widgetB)
{

	repo::core::model::RepoScene *sceneA = widgetA->getRepoScene();
	repo::core::model::RepoScene *sceneB = widgetB->getRepoScene();

	repo::manipulator::diff::DiffResult aRes, bRes;
	//FIXME : Probably should move this out, this class should purely be about rendering differences
	controller->compareScenesByIDs(token, sceneA, sceneB, aRes, bRes);
	//TODO: If it is a modification of a transformation or a transformation has been added, it needs to 
	// highlight the entire subtree as everything is moved.

	for (const repoUUID id : bRes.added)
	{
		
		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneB->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH)
			widgetB->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
				0.9, Qt::green);

		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::TRANSFORMATION)
			repoLogError("Transformation difference isn't yet supported by the renderer yet.");
	}


	for (const repoUUID id : bRes.modified)
	{

		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneB->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH)
			widgetB->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
			0.9, Qt::cyan);

		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::TRANSFORMATION)
			repoLogError("Transformation difference isn't yet supported by the renderer yet.");
	}

	for (const repoUUID id : aRes.added)
	{

		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneA->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH )
			widgetA->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
				0.9, Qt::red);

		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::TRANSFORMATION)
			repoLogError("Transformation difference isn't yet supported by the renderer yet.");
	}

	for (const repoUUID id : aRes.modified)
	{

		//colour widgetB's graph to reflect the comparison
		repo::core::model::RepoNode* node = sceneA->getNodeBySharedID(id);
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::MESH)
			widgetA->setGLCOccurrenceOpacity(QString::fromStdString(node->getName()),
				0.9, Qt::cyan);	
		if (node && node->getTypeAsEnum() == repo::core::model::NodeType::TRANSFORMATION)
			repoLogError("Transformation difference isn't yet supported by the renderer yet.");
	}


	widgetA->repaintCurrent();
	widgetB->repaintCurrent();
}

repo::gui::Repo3DDiffRenderer::~Repo3DDiffRenderer()
{
    //delete diff;
}
{'fraction_non_alphanumeric': 0.15757889291257113, 'fraction_numerical': 0.004552509053285049, 'mean_word_length': 3.0275, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '351442', 'n_tokens_mistral': 3031, 'n_tokens_neox': 2916, 'n_words': 649}