Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • adfc2e5
  • /
  • topo-blend
  • /
  • correspondence-manager.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:4ffd2f55032994a5f88d9d3676e72a54d7259db8
directory badge Iframe embedding
swh:1:dir:4cd23d1e54634cfb4ba85fc907bddef6128f3245

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
correspondence-manager.cpp
#include "correspondence-manager.h"
#include "StructureGraph.h"
#include "GraphCorresponder.h"

using namespace Structure;

GraphCorresponder* CorrespondenceManager::makeCorresponder()
{
	if (tb->graphs.size() < 2)
	{
		qDebug() << "Please load at least two graphs.";
		return NULL;
	}

	Structure::Graph *sg = tb->graphs[0];
	Structure::Graph *tg = tb->graphs[1];

	tb->gcoor = new GraphCorresponder(sg, tg);

	return tb->gcoor;
}

void CorrespondenceManager::assignCorrespondence()
{
	Graph * sourceGraph = tb->graphs.front();
	Graph * targetGraph = tb->graphs.back();

	QVector<QString> sParts, tParts;

	// Source
	foreach(Node * n, sourceGraph->nodes){
		if( n->property["nodeSelected"].toBool() ){
			sParts << n->id;
			n->property["nodeSelected"] = false;
			n->vis_property["meshColor"].setValue( QColor(180,180,180) );
		}
	}

	// Target
	foreach(Node * n, targetGraph->nodes){
		if( n->property["nodeSelected"].toBool() ){
			tParts << n->id;
			n->property["nodeSelected"] = false;
			n->vis_property["meshColor"].setValue( QColor(180,180,180) );
		}
	}

	QColor curColor = qRandomColor3(0, 0.25);

	if(!tb->gcoor) tb->gcoor = makeCorresponder();

	// Correspondence specified
	if(sParts.size() > 0 && tParts.size() > 0)
	{
		tb->gcoor->addLandmarks(sParts, tParts);

		// Assign colors
		foreach(QString nodeID, sParts)
			sourceGraph->getNode( nodeID )->vis_property["meshColor"].setValue( curColor );
		
		foreach(QString nodeID, tParts)	
			targetGraph->getNode( nodeID )->vis_property["meshColor"].setValue( curColor );
	}
	else
	{
		if(tParts.size() == 0)
		{
			foreach(QString nodeID, sParts){
				tb->gcoor->setNonCorresSource( nodeID );
				sourceGraph->getNode( nodeID )->vis_property["meshColor"].setValue( curColor );
			}
		}
		else
		{
			foreach(QString nodeID, tParts){
				tb->gcoor->setNonCorresTarget( nodeID );
				targetGraph->getNode( nodeID )->vis_property["meshColor"].setValue( curColor );
			}
		}
	}

	tb->gcoor->isReady = false;
}

void CorrespondenceManager::exitCorrespondenceMode(bool isChangeVisualization)
{
	tb->drawArea()->setMouseBinding(Qt::LeftButton, QGLViewer::CAMERA, QGLViewer::ROTATE);
	tb->drawArea()->setMouseBinding(Qt::SHIFT | Qt::LeftButton, QGLViewer::SELECT);

	// Reset mesh visualization
	if( isChangeVisualization )
	{
		foreach(Graph * g, tb->graphs){
			foreach(Node * n, g->nodes){
				n->vis_property["meshSolid"] = false;
				n->vis_property["meshColor"].setValue( QColor(200,200,200,8) );
			}
		}
	}

	tb->property["correspondenceMode"] = false;

	tb->drawArea()->updateGL(); 
}

void CorrespondenceManager::visualizeAsSolids()
{
	// mesh visualization - set to solid gray
	foreach(Graph * g, tb->graphs){
		foreach(Node * n, g->nodes){
			n->vis_property["meshSolid"] = true;
			n->vis_property["meshColor"].setValue( QColor(180,180,180) );
		}
	}
}

void CorrespondenceManager::correspondenceMode()
{
	// Enter / exit correspondence mode
	tb->property["correspondenceMode"] = !tb->property["correspondenceMode"].toBool();

	if(!tb->property["correspondenceMode"].toBool()) 
	{ 
		exitCorrespondenceMode(true);
		return; 
	}

	tb->drawArea()->setMouseBinding(Qt::LeftButton, QGLViewer::SELECT);
	tb->drawArea()->setMouseBinding(Qt::SHIFT | Qt::LeftButton, QGLViewer::CAMERA, QGLViewer::ROTATE);

	this->visualizeAsSolids();

	// Color previously assigned correspondences
	if( tb->gcoor ) {
		Graph * sourceGraph = tb->graphs.front();
		Graph * targetGraph = tb->graphs.back();

		foreach (PART_LANDMARK vector2vector, tb->gcoor->correspondences){
			QColor curColor = qRandomColor3(0, 0.25);

			foreach (QString strID, vector2vector.first){
				sourceGraph->getNode( strID )->vis_property["meshColor"].setValue( curColor );
				sourceGraph->getNode( strID )->property["is_corresponded"] = true;
			}

			foreach (QString strID, vector2vector.second){
				targetGraph->getNode( strID )->vis_property["meshColor"].setValue( curColor );
				targetGraph->getNode( strID )->property["is_corresponded"] = true;
			}
		}

		foreach (PART_LANDMARK vector2vector, tb->gcoor->landmarks){
			QColor curColor = qRandomColor3(0, 0.25);

			foreach (QString strID, vector2vector.first){
				sourceGraph->getNode( strID )->vis_property["meshColor"].setValue( curColor );
				sourceGraph->getNode( strID )->property["is_corresponded"] = true;
			}

			foreach (QString strID, vector2vector.second){
				targetGraph->getNode( strID )->vis_property["meshColor"].setValue( curColor );
				targetGraph->getNode( strID )->property["is_corresponded"] = true;
			}
		}
	}
}

void CorrespondenceManager::clearCorrespondence()
{
	foreach(Graph * g, tb->graphs){
		foreach(Node * n, g->nodes){
			n->vis_property["meshColor"].setValue( QColor(180,180,180) );
			n->property["is_corresponded"] = false;
		}
	}

	if(tb->gcoor) tb->gcoor->clear();
}

void CorrespondenceManager::drawWithNames()
{
	int offset = 0;

	for(int gID = 0; gID < (int) tb->graphs.size(); gID++)
	{
		Structure::Graph *g = tb->graphs[gID];

		glPushMatrix();
		glTranslated(g->property["posX"].toDouble(), 0, 0);
		g->drawNodeMeshNames( offset );
		glPopMatrix();
	}
}

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API