File: vertex.cpp

package info (click to toggle)
socnetv 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,028 kB
  • sloc: cpp: 12,953; makefile: 75
file content (422 lines) | stat: -rwxr-xr-x 10,206 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/***************************************************************************
 SocNetV: Social Networks Visualizer 
 version: 0.90
 Written in Qt 4.4 
 
                         vertex.cpp  -  description
                             -------------------
    copyright            : (C) 2005-2010 by Dimitris B. Kalamaras
    email                : dimitris.kalamaras@gmail.com
 ***************************************************************************/

/*******************************************************************************
*     This program is free software: you can redistribute it and/or modify     *
*     it under the terms of the GNU 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 General Public License for more details.                             *
*                                                                              *
*     You should have received a copy of the GNU General Public License        *
*     along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
********************************************************************************/

#include "vertex.h"


#include <QtDebug>		//used for qDebug messages
#include <QPointF>
#include "graph.h"

Vertex::Vertex(	Graph* parent, 
				int v1,  int val, int size, QString color, 
				QString numColor, int numSize, 
				QString label, QString labelColor, int labelSize,
				QPointF p, 
				QString shape): parentGraph (parent)  
{ 
	m_name=v1; 
	m_value=val;
	m_size=size;
	m_color=color;
	m_numberColor=numColor;
	m_numberSize=numSize;
	m_label=label;
	m_labelColor=labelColor;
	m_labelSize=labelSize;
	m_shape=shape;
	m_x=p.x();
	m_y=p.y();
	//FIXME outLinkColors list need update when we remove vertices/edges
//	outLinkColors=new  QString[1500];
	//Q_CHECK_PTR(outLinkColors);
	outLinkColors.reserve(1600);	
	m_outLinks=0;
	m_inLinks=0;
	m_ODC=0; m_SODC=0; m_IDC=0; m_SIDC=0; m_CC=0; m_SCC=0; m_BC=0; m_SBC=0; m_GC=0; m_SGC=0; m_SC=0; m_SSC=0;
	m_CLC=0; m_hasCLC=FALSE;
	
	m_inLinked=FALSE;
	m_outLinked=FALSE;
	m_reciprocalLinked=FALSE;
	m_enabled = TRUE;
	connect (this, SIGNAL (setEdgeVisibility ( int, int, bool) ), parent, SLOT (slotSetEdgeVisibility ( int, int, bool)) );
}

Vertex::Vertex(int v1) { 
	m_name=v1; 
	m_value=1;
	m_size=9;
	m_color="black";
	m_label="";
	m_labelColor="black";
	m_shape="circle";
	m_outLinks=0;
	m_inLinks=0;

	m_ODC=0; m_SODC=0; m_IDC=0; m_SIDC=0; m_CC=0; m_SCC=0; m_BC=0; m_SBC=0; m_GC=0; m_SGC=0; m_SC=0; m_SSC=0;
	m_inLinked=FALSE;
	m_outLinked=FALSE;
	m_reciprocalLinked=FALSE;
}




void Vertex::addLinkTo (long int v2, float weight) {
	//qDebug() <<"Vertex: "<< name() << " addLinkTo() "<< v2 << " of weight "<< weight;
	m_outEdges[v2]=weight;
	m_enabled_outEdges [v2]=1;
	m_outLinks++;
}



void Vertex::addLinkFrom (long int source, float weight) {
	//qDebug() <<"Vertex: "<< name() << " addLinkFrom() "<< source;
	m_inEdges[source]=weight;
	m_inLinks++;

}

void Vertex::changeLinkWeightTo(long int target, float weight){
	qDebug() << "Vertex: changeEdgeWeightTo " << target;
	m_outEdges[target]=weight;
	m_enabled_outEdges[target] = 1;
}


//finds and removes a link to vertice v2
void Vertex::removeLinkTo (long int v2) {
	qDebug() << "Vertex: removeLinkTo() vertex " << m_name << " has " <<outDegree() << " edges. RemovingEdgeTo "<< v2 ;
	if (outDegree()>0) {
		m_outLinks--;
		imap_f::iterator it=m_outEdges.find(v2);
		if ( it != m_outEdges.end() ) {
			qDebug("Vertex: edge exists. Removing it");
			m_outEdges.erase(it);
			m_enabled_outEdges[ it->first ] = 0;
			if ( m_outLinks == 0 ) setOutLinked(FALSE);
		}
		else {
			qDebug("Vertex: edge doesnt exist.");
		}
		qDebug() << "Vertex: vertex " <<  m_name << " now has " <<  outDegree() << " edges";
	}
	else {
		qDebug() << "Vertex: vertex " <<  m_name << " has no edges" ;
	}
}


void Vertex::removeLinkFrom(long int v2){
	qDebug() << "Vertex: removeLinkFrom() vertex " << m_name << " has " <<  outDegree() << "  edges. RemovingEdgeFrom " << v2 ;
	if (outDegree()>0) {
		m_inLinks--;
		imap_f::iterator i=m_inEdges.find(v2);
		if ( i != m_inEdges.end() ) {
			qDebug("Vertex: edge exists. Removing it");
			m_inEdges.erase(i);
			if ( m_inLinks == 0 ) setInLinked(FALSE);
		}
		else {
			qDebug() << "Vertex: edge doesnt exist.";
		}
		qDebug() << "Vertex: vertex " << m_name << " now has " << inDegree() << "  edges"  ;
	}
	else {
		qDebug() << "Vertex: vertex " << m_name << " has no edges";
	}
}



/**
	Called from Graph parent 
	to filter edges over or under a specified weight (m_threshold)
*/
void Vertex::filterEdgesByWeight(float m_threshold, bool overThreshold){
	qDebug() << "Vertex::filterEdgesByWeight of vertex " << this->m_name;
	imap_f::iterator it1;
	int target=0;
	float m_weight=0; 
	for( it1 =  m_outEdges.begin(); it1 !=  m_outEdges.end(); it1++ ) {
		target=it1->first;
		m_weight = it1->second; 
		if (overThreshold) {
			if ( m_weight >= m_threshold ) {
				qDebug() << "Vertex::filterEdgesByWeight(). Edge  to " << target 
				<< " has weight " << m_weight << ". It will be disabled. Emitting signal to Graph....";
				m_enabled_outEdges[target] = 0;
				emit setEdgeVisibility ( m_name, target, false ); 
			}
			else {
				qDebug() << "Vertex::filterEdgesByWeight(). Edge to " << target 
				<< " has weight " << m_weight << ". It will be enabled. Emitting signal to Graph....";
				m_enabled_outEdges[target] = 1;
				emit setEdgeVisibility ( m_name, target, true );
			}
		}
		else {
			 if ( m_weight <= m_threshold ) {
				qDebug() << "Vertex::filterEdgesByWeight(). Edge  to " << target 
				<< " has weight " << m_weight << ". It will be disabled. Emitting signal to Graph....";
				m_enabled_outEdges[target] = 0;
				emit setEdgeVisibility ( m_name, target, false );
			}
			else {
				qDebug() << "Vertex::filterEdgesByWeight(). Edge  to " << target 
				<< " has weight " << m_weight << ". It will be enabled. Emitting signal to Graph....";
				m_enabled_outEdges[target] = 1;
				emit setEdgeVisibility ( m_name, target, true );
			}	
		} 
	}
}









//Returns the numbers of links from this vertice
long int Vertex::outDegree() {
	//return m_outLinks;
	return m_outEdges.size();		//FIXME: What if the user has filtered out links? 
}



//Returns the numbers of links to this vertice
long int Vertex::inDegree() {
	return m_inLinks; 			//FIXME: What if the user has filtered out links?
}



/**
 	localDegree is the outDegree + inDegree minus the edges counted twice.
*/
long int Vertex::localDegree(){
	imap_f::iterator it1;
	long int v2=0;
	long int m_localDegree = (outDegree() + inDegree() );
	for( it1 =  m_outEdges.begin(); it1 !=  m_outEdges.end(); it1++ ) {
		v2=it1->first;		
		if (this->isLinkedFrom (v2) ) m_localDegree--; 
	}
	qDebug() << "Vertex:: localDegree() for " << this->name()  << "is " << m_localDegree;
	return m_localDegree;
}


//Checks if this vertex is outlinked to v2 and returns the weight of the link
float Vertex::isLinkedTo(long int v2){
	imap_f::iterator weight=m_outEdges.find(v2);
	if (weight  != m_outEdges.end()) {
		if  ( m_enabled_outEdges[ (*weight).first ] == 1) {
			qDebug()<< "Vertex::isLinkedTo() - a ("  <<  this->name()  << ", " << v2 << ") = "<<(*weight).second;
			return (*weight).second;			
		}
		else {
			qDebug()<< "Vertex::isLinkedTo() - a ("  <<  this->name()  << ", " << v2 << ") = "<<(*weight).second << " but not in enabled_outEdges";
			return 0;
		}
	}
	qDebug()<< "Vertex::isLinkedTo() - a ("  <<  this->name()  << ", " << v2 << ") = 0 ";
	return 0;
}



float Vertex::isLinkedFrom(long int v2){
	imap_f::iterator weight=m_inEdges.find(v2);
	if (weight  != m_inEdges.end()) {
		//	qDebug()<< "link to " << v2 << " weight "<<(*weight).second;
		return (*weight).second;
	}
	else 
		return 0;
}


long int Vertex::name() {
	return m_name;
}


void Vertex::setName (long int v1) {
	m_name=v1; 
}




void Vertex::setEnabled (bool flag ){
	m_enabled=flag;
}

bool Vertex::isEnabled (){
	return m_enabled;
}



void Vertex::setSize(int size) {
	m_size=size;
}

int  Vertex::size(){
	return m_size;
}


void Vertex::setShape(QString shape){
	m_shape=shape;
}

QString Vertex::shape(){
	return m_shape;	
}


void Vertex::setColor(QString color){
	m_color=color;
}

QString Vertex::color(){
	return m_color;	
}




void Vertex::setNumberColor (QString color) {
	m_numberColor = color;
}


QString Vertex::numberColor(){
	return m_numberColor;
}


void Vertex::setNumberSize (int size){
	m_numberSize=size;
}


int Vertex::numberSize(){
	return m_numberSize;
}



void Vertex::setLabel(QString label){
	m_label=label;
}

QString Vertex::label(){
	return m_label;	
}

void Vertex::setLabelColor(QString labelColor){
	m_labelColor=labelColor;
}

QString Vertex::labelColor(){
	return m_labelColor;	
}


void Vertex::setLabelSize(int newSize){
	m_labelSize=newSize;
}

int Vertex::labelSize(){
	return m_labelSize;
}


void Vertex::setX(float  x){
//	qDebug("Vertex setX with %f",x);
	m_x=x;
}

float Vertex::x(){
	return m_x;	
}


void Vertex::setY(float y){
//	qDebug("Vertex setY with %f", y);
	m_y=y;
}

float	Vertex::y(){
	return m_y;	
}


QPointF Vertex::pos () { 
	return QPointF ( x(), y() ); 
}



void Vertex::setOutLinkColor(long int target, QString color){
	qDebug()<<"Vertex: update linkColor to vertex "<< target<< " color: "<< color;
	outLinkColors[target]=color;
}

//FIXME: See MW line 1965
QString Vertex::outLinkColor(int target){
	if (outLinkColors.contains(target))
		return outLinkColors.value(target);	
	else return "black";
}


void Vertex::clearPs()	{  
	myPs.clear();
}
	
void Vertex::appendToPs(long  int vertex ) {
	qDebug() << "adding " <<  vertex << " to myPs"; 
	myPs.append(vertex); 
}


ilist Vertex::Ps(void) {
	 return myPs;
}

Vertex::~Vertex() {
	m_outEdges.clear();
}