Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

vertical_segment.cpp 7.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions

   Copyright (C) 2013, 2014 Inria

   This file is part of ALTA.

   This Source Code Form is subject to the terms of the Mozilla Public
   License, v. 2.0.  If a copy of the MPL was not distributed with this
   file, You can obtain one at http://mozilla.org/MPL/2.0/.  */

11 12 13 14 15 16 17 18 19
#include "vertical_segment.h"

#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <limits>
#include <algorithm>
#include <cmath>
20
#include <cassert>
21

22
//#define RELATIVE_ERROR
23

24 25 26 27 28 29 30 31 32 33 34 35
void vertical_segment::load(const std::string& filename) 
{
	arguments args ;
	load(filename, args) ;
}
		
void vertical_segment::load(const std::string& filename, const arguments& args) 
{
	std::ifstream file(filename.c_str()) ;
	if(!file.is_open())
	{
		std::cerr << "<<ERROR>> unable to open file \"" << filename << "\"" << std::endl ;
36
		throw ;
37 38
	}

39
	vec min, max ;
40
	vec ymin, ymax;
41 42 43 44 45 46 47 48

	_nX = 0 ; _nY = 0 ;
	std::vector<int> vs ; int current_vs = 0 ;
	while(file.good())
	{
		std::string line ;
		std::getline(file, line) ;
		std::stringstream linestream(line) ;
49

50 51 52 53 54 55 56 57 58 59 60 61
		// Discard incorrect lines
		if(linestream.peek() == '#')
		{
			linestream.ignore(1) ;

			std::string comment ;
			linestream >> comment ;

			if(comment == std::string("DIM"))
			{
				linestream >> _nX >> _nY ;

62
				vs.reserve(dimY()) ;
63 64 65 66 67 68 69
				for(int k=0; k<dimY(); ++k)
				{
					vs[k] = 0 ;
				}

				_min.resize(dimX()) ;
				_max.resize(dimX()) ;
70

Laurent Belcour's avatar
Laurent Belcour committed
71 72
				min = args.get_vec("min", _nX, -std::numeric_limits<float>::max()) ;
				max = args.get_vec("max", _nX,  std::numeric_limits<float>::max()) ;
73
#ifdef DEBUG
74
				std::cout << "<<DEBUG>> data will remove outside of " << min << " -> " << max << " x-interval" << std::endl;
75
#endif
76

77 78
				ymin = args.get_vec("ymin", _nY, -std::numeric_limits<float>::max()) ;
				ymax = args.get_vec("ymax", _nY,  std::numeric_limits<float>::max()) ;
79
#ifdef DEBUG
80
				std::cout << "<<DEBUG>> data will remove outside of " << ymin << " -> " << ymax << " y-interval" << std::endl;
81
#endif
82

83 84 85 86 87 88 89 90 91 92 93 94
				for(int k=0; k<dimX(); ++k)
				{
					_min[k] =  std::numeric_limits<double>::max() ;
					_max[k] = -std::numeric_limits<double>::max() ;
				}
			}
			else if(comment == std::string("VS"))
			{
				int t ;
				linestream >> t ;
				vs[current_vs] = t ; ++current_vs ;
			}
95 96
			else if(comment == std::string("PARAM_IN"))
			{
97 98 99
				std::string param;
				linestream >> param;
				_in_param = params::parse_input(param);
100 101 102
			}
			else if(comment == std::string("PARAM_OUT"))
			{
103 104 105
				std::string param;
				linestream >> param;
				_out_param = params::parse_output(param);
106
			}
107 108 109 110 111 112
			continue ;
		} 
		else if(line.empty())
		{
			continue ;
		}
113 114
		else
		{
115
			// Read the data point x and y coordinates
116
			vec v = vec::Zero(dimX() + 3*dimY()) ;
117 118
			for(int i=0; i<dimX()+dimY(); ++i) 
			{
119
				linestream >> v[i] ;
120
			}
121

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
			// If data is not in the interval of fit
			bool is_in = true ;
			for(int i=0; i<dimX(); ++i)
			{
				if(v[i] < min[i] || v[i] > max[i])
				{
					is_in = false ;
				}
			}
			for(int i=0; i<dimY(); ++i)
			{
				if(v[dimX()+i] < ymin[i] || v[dimX()+i] > ymax[i])
				{
					is_in = false ;
				}
			}
			if(!is_in)
			{
				continue ;
			}
142

143
//			/*
144 145 146 147 148 149
			// Correction of the data by 1/cosine(theta_L)
			double factor = 1.0;
			if(args.is_defined("data-correct-cosine"))
			{
				double cart[6];
				params::convert(&v[0], input_parametrization(), params::CARTESIAN, cart);
150 151 152
				if(cart[5] > 0.0 && cart[2] > 0.0)
				{
					factor = 1.0/cart[5]*cart[2];
153 154 155 156
					for(int i=0; i<dimY(); ++i) 
					{
						v[i + dimX()] /= factor;
					}
157 158 159 160 161
				}
				else
				{
					continue;
				}
162 163
			}
			// End of correction
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
			// Check if the data containt a vertical segment around the mean
			// value.
			for(int i=0; i<dimY(); ++i)
			{
				double min_dt = 0.0;
				double max_dt = 0.0;


				if(vs[i] == 2)
				{
					linestream >> min_dt ;
					linestream >> max_dt ;
					min_dt = min_dt-v[dimX()+i];
					max_dt = max_dt-v[dimX()+i];
				}
				else if(vs[i] == 1)
				{
					double dt ;
					linestream >> dt ;
					min_dt = -dt;
					max_dt =  dt;
				}
				else
				{
					double dt = args.get_float("dt", 0.1f);
					min_dt = -dt;
					max_dt =  dt;
				}

				if(args.is_defined("dt-relative"))
				{
197
               v[dimX() +   dimY()+i] = v[dimX() + i] * (1.0 + min_dt) ;
198 199
					v[dimX() + 2*dimY()+i] = v[dimX() + i] * (1.0 + max_dt) ;
				}
200 201 202 203 204
				else if(args.is_defined("dt-max"))
				{
               v[dimX() +   dimY()+i] = v[dimX() + i] + std::max(v[dimX() + i] * min_dt, min_dt);
					v[dimX() + 2*dimY()+i] = v[dimX() + i] + std::max(v[dimX() + i] * max_dt, max_dt);
				}
205 206
				else
				{
207
					v[dimX() +   dimY()+i] = v[dimX() + i] + min_dt ;
208 209
					v[dimX() + 2*dimY()+i] = v[dimX() + i] + max_dt ;
				}
210 211 212 213

				// You can enforce the vertical segment to stay in the positive
				// region using the --data-positive command line argument. Note
				// that the data point is also clamped to zero if negative.
214
				if(args.is_defined("dt-positive"))
215 216 217 218 219 220
				{
					v[dimX() +          i] = std::max(v[dimX() +          i], 0.0);
					v[dimX() +   dimY()+i] = std::max(v[dimX() +   dimY()+i], 0.0);
					v[dimX() + 2*dimY()+i] = std::max(v[dimX() + 2*dimY()+i], 0.0);
				}

221 222 223
#ifdef DEBUG
                std::cout << "<<DEBUG>> vs = [" << v[dimX() +   dimY()+i] << ", " << v[dimX() + 2*dimY()+i] << "]" << std::endl;
#endif
224 225 226
			}

			_data.push_back(v) ;
227

228 229 230 231 232 233
			// Update min and max
			for(int k=0; k<dimX(); ++k)
			{
				_min[k] = std::min(_min[k], v[k]) ;
				_max[k] = std::max(_max[k], v[k]) ;
			}
234 235
		}
	}
236 237 238
			
	if(args.is_defined("data-correct-cosine"))
		save("/tmp/data-corrected.dat");
239 240 241 242 243 244 245

	std::cout << "<<INFO>> loaded file \"" << filename << "\"" << std::endl ;
	std::cout << "<<INFO>> data inside " << _min << " ... " << _max << std::endl ;
	std::cout << "<<INFO>> loading data file of R^" << dimX() << " -> R^" << dimY() << std::endl ;
	std::cout << "<<INFO>> " << _data.size() << " elements to fit" << std::endl ;
}

246
void vertical_segment::get(int i, vec& x, vec& yl, vec& yu) const
247
{
248 249 250 251 252 253 254 255 256 257 258 259 260
#ifdef DEBUG
    assert(i >= 0 && i < _data.size());
#endif
    x.resize(dimX()); yl.resize(dimY()) ; yu.resize(dimY()) ;
    for(int j=0; j<dimX(); ++j)
    {
        x[j] = _data[i][j] ;
    }
    for(int j=0; j<dimY(); ++j)
    {
        yl[j] = _data[i][dimX() + dimY() + j] ;
        yu[j] = _data[i][dimX() + 2*dimY() + j] ;
    }
261 262 263 264 265 266 267 268 269 270 271 272 273

}
		
void vertical_segment::get(int i, vec& yl, vec& yu) const
{
	yl.resize(dimY()) ; yu.resize(dimY()) ;
	for(int j=0; j<dimY(); ++j)	
	{
		yl[j] = _data[i][dimX() + dimY() + j] ;
		yu[j] = _data[i][dimX() + 2*dimY() + j] ;
	}
}
		
274
vec vertical_segment::operator[](int i) const
275 276 277
{
	return _data[i] ;
}
278
vec vertical_segment::get(int i) const 
279
{
Laurent Belcour's avatar
core  
Laurent Belcour committed
280 281 282 283 284
    const int n = dimX() + dimY();
    vec res(n);
    for(int k=0; k<n; ++k) { res[k] = _data[i][k]; }

    return res ;
285 286
}

287 288
//! \todo Check the vertical segment size and if the data
//! is not already present.
289
void vertical_segment::set(const vec& x)
290
{
291
//	assert(x.size() == dimX() + dimY() || x.size() == dimX() + 3*dimY());
292 293 294
	_data.push_back(x);
}

295 296 297 298 299 300
void vertical_segment::set(int i, const vec& x)
{
//	assert(x.size() == dimX() + dimY() || x.size() == dimX() + 3*dimY());
	_data[i] = x;
}

301 302 303 304
int vertical_segment::size() const
{
	return _data.size() ;
}