File size: 1,938 Bytes
4559903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include "DiffKMLNetOutput.h"
#include "StarLink.h"
#include "StarNetwork.h"

#include <sstream>
#include <limits>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <cassert>

DiffKMLNetOutput::DiffKMLNetOutput(StarNetwork* net, const std::vector<FPType>& flowDiff,
					FPType tolerance) : 
					KMLNetOutput(net), flowDiff_(flowDiff), scaleFactor_(1),
					tolerance_(tolerance) {
	calcScalingFactor();
};

void DiffKMLNetOutput::calcScalingFactor(){
	FPType maxDiff = 0.0;
	FPType minDiff = std::numeric_limits<FPType>::infinity();
	for (size_t i = 0; i < flowDiff_.size(); ++i){
		FPType absDiff = fabs(flowDiff_[i]);
		if (absDiff > maxDiff) maxDiff = absDiff;
		if (absDiff < minDiff) minDiff = absDiff;
	}
	std::cout << "maxDiff = " << maxDiff << " minDiff = " << minDiff << std::endl;
	scaleFactor_ = maxDiff / maxLength_;
	assert(scaleFactor_ != 0);
};

DiffKMLNetOutput::DiffKMLNetOutput(StarNetwork* net, const std::string& logFileForMissingIDs,
					const std::vector<FPType>& flowDiff, FPType tolerance) : 
					KMLNetOutput(net, logFileForMissingIDs),
					flowDiff_(flowDiff), tolerance_(tolerance) {

};

DiffKMLNetOutput::~DiffKMLNetOutput(){

};

FPType DiffKMLNetOutput::calcLineWidth(StarLink* link){
	return flowDiff_[link->getIndex()] / scaleFactor_;
};

std::string DiffKMLNetOutput::createColorFromLineWidth(FPType lineWidth){
	if (lineWidth == 0) return getGreenColor();
	if (lineWidth < 0.0) return "50F0C814";//getBlueColor();
	return "501478FF";//getRedColor();
};

std::string DiffKMLNetOutput::createLineWidth(FPType lineWidth){
	if (lineWidth == 0) lineWidth = 3;
	std::stringstream ss;
    ss << fabs(lineWidth);
    return ss.str();
};

bool DiffKMLNetOutput::shouldCreatePlacemark(StarLink* link) {
	return true;
};

std::string DiffKMLNetOutput::createDescriptionString(StarLink* link) {

	std::stringstream ss;
	ss << "difference: " << flowDiff_[link->getIndex()];
	return ss.str();
};