This file is indexed.

/usr/include/magics/Histogram.cc is in libmagics++-dev 2.18.15-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
/******************************** LICENSE ********************************

 Copyright 2007 European Centre for Medium-Range Weather Forecasts (ECMWF)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 ******************************** LICENSE ********************************/

/*! \file Histogram.cc
    \brief Implementation of the Template class Histogram.
    
    Magics Team - ECMWF 2004
    
    Started: Tue 18-May-2004
    
    Changes:
    
*/



#include "Histogram.h"
#include "Layout.h"
#include "PointsHandler.h"
#include "IntervalMap.h"
#include "CartesianTransformation.h"

using namespace magics;



Histogram::Histogram()
{
}


Histogram::~Histogram()
{
}

/*!
 Class information are given to the output-stream.
*/		

void Histogram::print(ostream& out)  const
{
	out << "Histogram[";
	HistogramAttributes::print(out);
	out << "]";
}


void Histogram::bean(PointsHandler& points)
{
	points.setToFirst();
	mean_ = 0;
	population_ = 0;
	while (points.more()) {
		try {
			double val = points.current().value();						
			IntervalMap<int>::iterator count = counter_.get(val);
			mean_ += val;
			population_++;
			count->second++;
		}
		catch (...)
		{
			//MagLog::debug() <<  points.current().value() << " is not in range..." << endl;
		}

		points.advance();
	}
	mean_ /= population_;

}



void Histogram::prepare(PointsHandler& points)
{
		levels_->set(*this);
		levels_->calculate(points.min(), points.max(), false);
	
		
		double delta=0;
		LevelSelection::const_iterator min = levels_->begin();
		LevelSelection::const_iterator max = levels_->begin();
		++max;
		while ( max != levels_->end())
		{
			if(levels_->end()-max != 1 || !same(*min,*max))
			{			  
		  		counter_.insert(make_pair(Interval(*min, *max), 0));
			}
			
			//If it is the last interval and the min and max are the same 
			//we just increase max by the size of the previous interval to
			//have a proper bin.
			else
			{
			  	counter_.insert(make_pair(Interval(*min, (*max)+delta), 0));
			}
			
			delta=(*max)-(*min);
			
			min++;
			max++;			  	
			
		}
		bean(points);
}


static double xmin_;
static double xmax_;
static double ymin_;
static double ymax_;
//static double width_;
static double height_;


IntervalMap<int>& Histogram::histogram(const IntervalMap<Colour>& beans, PointsHandler& points)
{

	for ( IntervalMap<Colour>::const_iterator entry = beans.begin(); entry != beans.end(); ++entry) {
		counter_.insert(make_pair(Interval(entry->first.min_, entry->first.max_), 0));
	}
	bean(points);
	return counter_;
}


void Histogram::visit(const IntervalMap<Colour>& beans, Data& data, PointsHandler& points, HistoVisitor& visitor)
{
	MagLog::dev() << *this << endl;
	CartesianTransformation* cartesian = new CartesianTransformation();

	ostringstream mins;
	ostringstream maxs;
	ostringstream vals;
	ostringstream cols;

	if ( beans.empty() ) {
		prepare(points);
	}

	else {
		for ( IntervalMap<Colour>::const_iterator entry = beans.begin(); entry != beans.end(); ++entry) {
				counter_.insert(make_pair(Interval(entry->first.min_, entry->first.max_), 0));
		}
		bean(points);
	}

	if ( points.empty() || counter_.empty() )
		return;
		 vector<int> y;
				   vector<double> x;
				   for ( IntervalMap<int>::const_iterator count = counter_.begin(); count != counter_.end(); ++count) {
					   y.push_back(count->second );
					   x.push_back(count->first.min_ )	;
					   x.push_back(count->first.max_ )	;
					   MagLog::dev() << "[" << count->first.min_ << "-" <<  count->first.max_ << "]-->" <<  count->second << endl;
				   }

				   MagLog::dev()<< "minx=" << *std::min_element(x.begin(), x.end()) << endl;
				   MagLog::dev()<<  "maxx=" << *std::max_element(x.begin(), x.end()) << endl;
				   xmin_ = *std::min_element(x.begin(), x.end());
				   ymin_ = 0;
				   xmax_ = *std::max_element(x.begin(), x.end());
				   ymax_ = *std::max_element(y.begin(), y.end());

				   if ( xmin_ == xmax_ ) xmax_ = xmin_ +1;
				   if ( ymin_ == ymax_ ) ymax_ = ymin_ +1;


				   double step = (ymax_ - ymin_)/5;

				   	double log = log10(step);
				   	double ws = pow(10., int(log));
				   	double inc = ceil(step/ws)*ws;
				   	vector<double> ticks;
				   	for (double x = ymin_; x <= ymax_ +inc; x+=inc)
				   		ticks.push_back(x);
				   	ymax_ = ticks.back();
				   	cartesian->setAutomaticX(true);
				   	cartesian->setAutomaticY(true);
				   	cartesian->setMinX(xmin_-width_*0.1);
				   cartesian->setMinX(xmin_-width_*0.1);
				   cartesian->setMaxX(xmax_+width_*0.1);
				   cartesian->setMinY(-height_*0.1);
				   MagLog::dev()<<  "maxy=" << *std::max_element(y.begin(), y.end()) << endl;
				   cartesian->setMaxY(ymax_+height_*0.1);
				   visitor.transformation(cartesian);
	Polyline* frame = new Polyline();
	frame->setColour(Colour("navy"));
	frame->setThickness(1);
	frame->setLineStyle(M_SOLID);
	frame->push_back(PaperPoint(xmin_, ymin_));
	frame->push_back(PaperPoint(xmax_, ymin_));
	frame->push_back(PaperPoint(xmax_, ymax_));
	frame->push_back(PaperPoint(xmin_, ymax_));
	frame->push_back(PaperPoint(xmin_, ymin_));


	double left = xmin_ - (width_*0.05);
	double bottom = ymin_ - height_ *0.1;

	double font_size =0.12;
	for (vector<double>::iterator tick = ticks.begin(); tick!=ticks.end(); ++tick){
		Text* val = new Text();
		val->addText(*tick, Colour("navy"), font_size);
		val->push_back(PaperPoint(left, *tick));
		val->setVerticalAlign(MHALF);
		val->setJustification(MRIGHT);
		visitor.push_back(val);
		Polyline* grid = new Polyline();
			grid->setColour(Colour("grey"));
			grid->setThickness(1);
			grid->setLineStyle(M_DOT);
			grid->push_back(PaperPoint(xmin_, *tick));
			grid->push_back(PaperPoint(xmax_, *tick));
			visitor.push_back(grid);
		grid = new Polyline();
			grid->setColour(Colour("navy"));
			grid->setThickness(1);
			grid->setLineStyle(M_SOLID);
			grid->push_back(PaperPoint(xmin_-(width_*0.025), *tick));
			grid->push_back(PaperPoint(xmin_, *tick));
			visitor.push_back(grid);
	}


	double last=0.;
	string sep;
	Polyline* bar = 0;
	int barCnt=0;
	int barLabelFreq=1+(counter_.size()/10) - ((counter_.size()%10 == 0)?1:0);
	
	for ( IntervalMap<int>::const_iterator count = counter_.begin(); count != counter_.end(); ++count, barCnt++) {
		Polyline* grid = new Polyline();
					grid->setColour(Colour("grey"));
					grid->setThickness(1);
					grid->setLineStyle(M_DOT);
					grid->push_back(PaperPoint(count->first.min_, ymin_));
					grid->push_back(PaperPoint(count->first.min_, ymax_));
					visitor.push_back(grid);
		Colour colour = beans.find(count->first.min_, *colour_);
		if (bar)
			visitor.push_back(bar);

		bar = new Polyline();
		bar->setColour(Colour("navy"));
		bar->setThickness(1);
		bar->setLineStyle(M_SOLID);
		
		bar->setFilled(true);
	    bar->setFillColour(colour);

	    mins << sep << count->first.min_;
	    maxs << sep << count->first.max_;
	    vals << sep << count->second;
	    cols << sep << colour.red() << ":" << colour.green() << ":"  << colour.blue(); 	
	    
	    sep = "/";

		FillShadingProperties* shading = new FillShadingProperties();
          
		bar->setShading(shading);
		bar->push_back(PaperPoint(count->first.min_, 0));
		bar->push_back(PaperPoint(count->first.min_, count->second));
		bar->push_back(PaperPoint(count->first.max_, count->second));
		bar->push_back(PaperPoint(count->first.max_, 0));
		bar->push_back(PaperPoint(count->first.min_, 0));

		
		if(barCnt % barLabelFreq ==0)
		{
			Text* from = new Text();
			from->addText(count->first.min_, Colour("navy"), font_size);
			from->setVerticalAlign(MTOP);
			from->setJustification(MLEFT);
			from->setAngle(45.);
			from->push_back(PaperPoint(count->first.min_, bottom));
		
			/*Text* to = new Text();
			to->addText(count->first.min_, Colour("navy"), font_size);
			to->setVerticalAlign(MTOP);
			to->push_back(PaperPoint(count->first.max_, bottom));*/

			visitor.push_back(from);
		}
		//visitor.push_back(to);
		/*grid = new Polyline();
		grid->setColour(Colour("navy"));
		grid->setThickness(1);
		grid->setLineStyle(M_DASH);
		grid->push_back(PaperPoint(xmin_, count->second));
		grid->push_back(PaperPoint(count->first.min_, count->second));
		visitor.push_back(grid);*/

		Polyline* vert = new Polyline();
			vert->setColour(Colour("navy"));
			vert->setThickness(1);
			vert->setLineStyle(M_SOLID);
			vert->push_back(PaperPoint(count->first.min_, ymin_));
			vert->push_back(PaperPoint(count->first.min_, ymin_ - (height_*0.025)));
			visitor.push_back(vert);

		last = count->first.max_;
	}

	Polyline* vert = new Polyline();
				vert->setColour(Colour("navy"));
				vert->setThickness(1);
				vert->setLineStyle(M_SOLID);
				vert->push_back(PaperPoint(last, ymin_));
				vert->push_back(PaperPoint(last, ymin_ - (height_*0.025)));
				visitor.push_back(vert);

	if (bar)
			visitor.push_back(bar);
	data.setInfo("histogram_min", mins.str());
	data.setInfo("histogram_max", maxs.str());
	data.setInfo("histogram_val", vals.str());
	data.setInfo("histogram_col", cols.str());

	visitor.push_back(frame);
}


void Histogram::visit(LegendVisitor& legend)
{
}