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/

Commit 7396f610 authored by Ludovic Courtès's avatar Ludovic Courtès

core: 'data::load' now takes an 'std::istream'.

parent 653f2f20
......@@ -53,10 +53,26 @@ class data
// Virtual destructor
virtual ~data() {}
// Load data from a file
virtual void load(const std::string& filename,
// Load data from an input stream.
virtual void load(std::istream& input,
const arguments& args = arguments()) = 0;
// Load data from an input file.
void load(const std::string& file,
const arguments& args = arguments())
{
std::ifstream stream;
// Raise an exception when 'open' fails, and open in binary mode to
// placate Windows.
stream.exceptions(std::ios::failbit);
stream.open(file.c_str(), std::ifstream::binary);
stream.exceptions(std::ios::goodbit);
load(stream, args);
stream.close(); // FIXME: make it auto-close
}
// Save the data to a file
virtual void save(const std::string& filename) const;
......@@ -167,7 +183,7 @@ class data_params : public data
NOT_IMPLEMENTED();
}
virtual void load(const std::string&, const arguments&)
virtual void load(std::istream&, const arguments&)
{
std::cerr << "<<ERROR>> this data type cannot load data" << std::endl;
throw;
......
......@@ -61,16 +61,9 @@ vertical_segment::initializeToZero( unsigned int number_of_data_elements )
void vertical_segment::load(const std::string& filename, const arguments& args)
void vertical_segment::load(std::istream& input, const arguments& args)
{
std::ifstream file;
// Raise an exception when 'open' fails.
file.exceptions (std::ios::failbit);
file.open(filename.c_str());
file.exceptions (std::ios::goodbit);
arguments header = arguments::parse_header(file);
arguments header = arguments::parse_header(input);
// Default behaviour: parsing a file as TEXT file. Send a message error in case
// the user did not set it.
......@@ -79,23 +72,11 @@ void vertical_segment::load(const std::string& filename, const arguments& args)
}
if (header["FORMAT"] == "binary") {
#ifdef _WIN32
// On MS Windows strange things happen when the ifstream is not opened in
// binary mode. To avoid having badbit set after a few entries read, we
// close and re-open the file with correct flags.
file.close();
file.open(filename.c_str(), std::ifstream::binary);
header = arguments::parse_header(file);
#endif
load_data_from_binary(file, header, *this);
load_data_from_binary(input, header, *this);
} else {
// FIXME: ARGS is currently ignored.
load_data_from_text(file, header, *this);
load_data_from_text(input, header, *this);
}
file.close();
}
void vertical_segment::get(int i, vec& x, vec& yl, vec& yu) const
......
......@@ -94,7 +94,7 @@ class vertical_segment : public data
unsigned int size );
//! \brief Load data from a file using the command line arguments
//! \brief Load data from a stream using the command line arguments.
//!
//! \details
//! Specific arguments for the vertical segment data
......@@ -103,7 +103,7 @@ class vertical_segment : public data
//! --data-positive for the data to be positive
//! --dt-relative use a relative segment intervale. The dt is used
//! multipled by the data
virtual void load(const std::string& filename,
virtual void load(std::istream& input,
const arguments& args = arguments()) ;
......
......@@ -269,20 +269,13 @@ class BrdfGrid : public vertical_segment {
}
// Load data from a file
virtual void load(const std::string& filename, const arguments& args)
virtual void load(std::istream& input, const arguments& args)
{
std::ifstream file;
// Raise an exception when 'open' fails.
file.exceptions (std::ios::failbit);
file.open(filename.c_str());
file.exceptions (std::ios::goodbit);
arguments header = arguments::parse_header(file);
arguments header = arguments::parse_header(input);
initialize(header, false);
// FIXME: ARGS is ignored.
load_data_from_text(file, header, *this);
load_data_from_text(input, header, *this);
}
void save(const std::string& filename) const
......
......@@ -87,10 +87,10 @@ class MatlabInterpolant : public data
}
// Load data from a file
virtual void load(const std::string& filename, const arguments& args)
virtual void load(std::istream& input, const arguments& args)
{
// Load the data
_data->load(filename, args);
_data->load(input, args);
// Copy the informations
setDimX(_data->dimX());
......
......@@ -89,10 +89,10 @@ class rbf_interpolant : public data
}
// Load data from a file
virtual void load(const std::string& filename, const arguments& args)
virtual void load(std::istream& input, const arguments& args)
{
// Load the data
_data->load(filename, args);
_data->load(input, args);
// Copy the informations
parameters p(_data->parametrization().dimX(),
......
......@@ -6,17 +6,31 @@
#include <stdexcept>
#include <cassert>
#include <ImfRgbaFile.h>
#include <ImfArray.h>
// XXX: This header is not installed as of version 2.2.0 of OpenEXR, see
// <https://lists.nongnu.org/archive/html/openexr-devel/2016-06/msg00001.html>
// and <https://github.com/openexr/openexr/pull/184>.
#include <ImfStdIO.h>
template<typename FType>
class t_EXR_IO
{
public:
static bool LoadEXR(const char *filename,int& W,int& H, FType *& pix,int nC=3)
static bool LoadEXR(std::istream& input, int& W,int& H, FType *& pix,int nC=3)
{
Imf::RgbaInputFile file(filename);
// XXX: OpenEXR implements its own IStream and OStream classes, but
// they are completely independent from those of libstdc++. The
// closest thing it has is 'StdIFStream', hence this hack.
std::ifstream* ifstream = dynamic_cast<std::ifstream*>(&input);
assert(ifstream != NULL);
Imf::StdIFStream iifstream(*ifstream, "unknown file name");
Imf::RgbaInputFile file(iifstream);
Imath::Box2i dw = file.dataWindow();
W = dw.max.x - dw.min.x + 1;
......
Import('env', 'openexr_available')
env = env.Clone()
have_openexr = openexr_available(env)
if have_openexr:
# Make sure we have the 'ImfStdIO.h' header, which OpenEXR 2.2.0
# does not install:
# <https://lists.nongnu.org/archive/html/openexr-devel/2016-06/msg00001.html>.
conf = Configure(env)
have_openexr = conf.CheckCXXHeader('ImfStdIO.h')
conf.Finish()
# Special linking flags, defined in the OS dependant configuration file
env.AppendUnique(LIBS = ['core'])
have_openexr = openexr_available(env)
targets = \
env.SharedLibrary('#build/plugins/data_merl', ['merl.cpp']) + \
env.SharedLibrary('#build/plugins/data_astm', ['astm.cpp']) + \
......
......@@ -126,13 +126,12 @@ public: //methods
}
// Load data from a file
virtual void load(const std::string& filename, const arguments& args)
virtual void load(std::istream& input, const arguments& args)
{
std::ifstream file(filename.c_str());
std::string line;
// Parse the header, get the output/input dimensions and params
arguments header = parse_header(file);
arguments header = parse_header(input);
auto vars = header.get_vec<std::string>("VARS");
update_params(vars);
......@@ -145,9 +144,9 @@ public: //methods
const int n = parametrization().dimX() + parametrization().dimY();
int i = 0;
while(file.good())
while(input.good())
{
std::getline(file, line);
std::getline(input, line);
if(line.size() == 0 || line.rfind(',') == std::string::npos)
continue;
......@@ -168,8 +167,6 @@ public: //methods
if(header.is_defined("NUM_POINTS")) {
assert(this->size() == header.get_int("NUM_POINTS"));
}
file.close();
}
};
......
......@@ -100,9 +100,9 @@ public: // methods
// Load data from a file
void load(const std::string& filename, const arguments& args)
void load(std::istream& input, const arguments& args)
{
if(!read_brdf(filename.c_str(), brdf))
if(!read_brdf(input, brdf))
{
std::cerr << "<<ERROR>> unable to load the data as a MERL file" << std::endl ;
throw;
......@@ -445,29 +445,21 @@ private: //methods
}
// Read BRDF data
bool read_brdf(const char *filename, double* &brdf)
bool read_brdf(std::istream& input, double* &brdf)
{
FILE *f = fopen(filename, "rb");
if (!f) {
std::cerr << "<<ERROR>> File \"" << filename << "\" is not present, please check path and use absolute path." << std::endl;
return false;
}
int dims[3];
fread(dims, sizeof(int), 3, f);
input.read((char *) &dims, sizeof dims);
int n = dims[0] * dims[1] * dims[2];
if (n != BRDF_SAMPLING_RES_THETA_H *
BRDF_SAMPLING_RES_THETA_D *
BRDF_SAMPLING_RES_PHI_D / 2)
{
fprintf(stderr, "Dimensions don't match\n");
fclose(f);
return false;
}
fread(brdf, sizeof(double), 3*n, f);
input.read((char *) brdf, 3 * n * sizeof(double));
fclose(f);
return true;
}
......
......@@ -106,10 +106,10 @@ class BrdfSlice : public data {
}
// Load data from a file
void load(const std::string& filename, const arguments& args)
void load(std::istream& input, const arguments& args)
{
delete[] _data;
t_EXR_IO<double>::LoadEXR(filename.c_str(), width, height, _data);
t_EXR_IO<double>::LoadEXR(input, width, height, _data);
}
void save(const std::string& filename) const
......
......@@ -90,8 +90,9 @@ public:
}
// Load data from a file
virtual void load(const std::string& filename, const arguments& args) {
virtual void load(std::istream& input, const arguments& args) {
#if 0 // FIXME: backport this
/* If the file is an OpenEXR image */
if(filename.substr(filename.find_last_of(".") + 1) == "exr") {
double* temp;
......@@ -115,25 +116,19 @@ public:
}
/* If the file is a binary */
} else {
std::ifstream stream(filename.c_str(), std::ios_base::in | std::ios_base::binary);
/*
if (!stream.is_open()) {
std::cerr << "<<ERROR>> Unable to open file '" << filename << "' !" << std::endl;
throw;
}*/
} else
#endif
{
int count = 0;
for(int isp=0;isp<planes;isp++) {
for(int ni=0;ni<nti*npi;ni++)
for(int nv=0;nv<ntv*npv;nv++) {
stream >> Bd[count++];
input >> Bd[count++];
}
}
}
std::cout << "<<INFO>> Reading BRDF from file '" << filename << "' ...done" << std::endl;
std::cout << "<<INFO>> Successfully read BRDF" << std::endl;
}
virtual void save(const std::string& filename) const {
......
......@@ -473,8 +473,9 @@ main(int argc, char* argv[])
try
{
t.start();
vs_data->load(args["input"], args);
t.stop();
ptr<data> data = vs_data;
data->load(args["input"], args);
t.stop();
}
catch(...)
{
......
......@@ -119,10 +119,10 @@ int main(int argc, char** argv)
try
{
// Use the standard load/save methods.
sample1.load(input_file);
((data&)sample1).load(input_file);
sample1.save(temp_file1);
sample2.load(temp_file1);
((data&)sample2).load(temp_file1);
sample2.save(temp_file2);
// Now use the binary output format.
......@@ -132,7 +132,7 @@ int main(int argc, char** argv)
out.close();
// This should automatically load using the binary format loader.
sample3.load(temp_file3);
((data&)sample3).load(temp_file3);
}
CATCH_FILE_IO_ERROR(input_file);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment