Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alta
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alta
alta
Commits
df6b8a59
Commit
df6b8a59
authored
Nov 05, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding the matlab interpolator. Need to check for duplicates
parent
2f7c8b0a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
220 additions
and
0 deletions
+220
-0
sources/plugins/data_interpolant_matlab/data.cpp
sources/plugins/data_interpolant_matlab/data.cpp
+157
-0
sources/plugins/data_interpolant_matlab/data.h
sources/plugins/data_interpolant_matlab/data.h
+47
-0
sources/plugins/data_interpolant_matlab/data_interpolant_matlab.pro
...ugins/data_interpolant_matlab/data_interpolant_matlab.pro
+15
-0
sources/plugins/plugins.pro
sources/plugins/plugins.pro
+1
-0
No files found.
sources/plugins/data_interpolant_matlab/data.cpp
0 → 100644
View file @
df6b8a59
#include "data.h"
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <core/vertical_segment.h>
mxArray
*
X
,
*
Y
,
*
x
,
*
y
;
#define BUFFER_SIZE 10000
char
*
output
=
new
char
[
BUFFER_SIZE
+
1
];
data_interpolant
::
data_interpolant
()
{
_data
=
new
vertical_segment
();
// Create matlab engine
#ifdef WIN32
if
(
!
(
ep
=
engOpen
(
NULL
)))
#else
if
(
!
(
ep
=
engOpen
(
"matlab -nosplash"
)))
#endif
{
std
::
cerr
<<
"<ERROR>> can't start MATLAB engine"
<<
std
::
endl
;
}
}
data_interpolant
::~
data_interpolant
()
{
delete
_data
;
mxDestroyArray
(
x
);
mxDestroyArray
(
y
);
mxDestroyArray
(
X
);
mxDestroyArray
(
Y
);
engClose
(
ep
);
}
// Load data from a file
void
data_interpolant
::
load
(
const
std
::
string
&
filename
)
{
// Load the data
_data
->
load
(
filename
);
// Copy the informations
setDimX
(
_data
->
dimX
());
setDimY
(
_data
->
dimY
());
setMin
(
_data
->
min
());
setMax
(
_data
->
max
());
Eigen
::
MatrixXd
eX
(
_data
->
size
(),
dimX
()
*
dimY
());
Eigen
::
MatrixXd
eY
(
_data
->
size
(),
dimY
());
for
(
int
i
=
0
;
i
<
_data
->
size
();
++
i
)
{
vec
x
=
_data
->
get
(
i
);
for
(
int
k
=
0
;
k
<
dimY
();
++
k
)
{
for
(
int
j
=
0
;
j
<
dimX
();
++
j
)
{
eX
(
i
,
j
+
k
*
dimX
())
=
x
[
j
];
}
eY
(
i
,
k
)
=
x
[
dimX
()
+
k
];
}
}
// Create matrices
X
=
mxCreateDoubleMatrix
(
_data
->
size
(),
dimX
()
*
dimY
(),
mxREAL
);
memcpy
((
void
*
)
mxGetPr
(
X
),
(
void
*
)
eX
.
data
(),
_data
->
size
()
*
dimY
()
*
dimX
()
*
sizeof
(
double
));
engPutVariable
(
ep
,
"X"
,
X
);
Y
=
mxCreateDoubleMatrix
(
_data
->
size
(),
dimY
(),
mxREAL
);
memcpy
((
void
*
)
mxGetPr
(
Y
),
(
void
*
)
eY
.
data
(),
_data
->
size
()
*
dimY
()
*
sizeof
(
double
));
engPutVariable
(
ep
,
"Y"
,
Y
);
output
[
BUFFER_SIZE
]
=
'\0'
;
engOutputBuffer
(
ep
,
output
,
BUFFER_SIZE
)
;
engEvalString
(
ep
,
"display(X)"
);
std
::
cout
<<
output
<<
std
::
endl
;
engEvalString
(
ep
,
"display(Y)"
);
std
::
cout
<<
output
<<
std
::
endl
;
x
=
mxCreateDoubleMatrix
(
1
,
dimX
(),
mxREAL
);
engPutVariable
(
ep
,
"x"
,
x
);
}
void
data_interpolant
::
load
(
const
std
::
string
&
filename
,
const
arguments
&
)
{
load
(
filename
);
}
void
data_interpolant
::
save
(
const
std
::
string
&
filename
)
const
{
}
// Acces to data
vec
data_interpolant
::
get
(
int
id
)
const
{
vec
res
(
dimX
()
+
dimY
())
;
return
res
;
}
vec
data_interpolant
::
operator
[](
int
i
)
const
{
return
get
(
i
)
;
}
//! \todo Test this function
void
data_interpolant
::
set
(
vec
x
)
{
assert
(
x
.
size
()
==
dimX
());
}
vec
data_interpolant
::
value
(
vec
,
vec
)
const
{
vec
res
(
dimY
());
std
::
cerr
<<
"<<ERROR>> Deprecated function: "
<<
__func__
<<
std
::
endl
;
return
res
;
}
vec
data_interpolant
::
value
(
vec
ax
)
const
{
vec
res
=
vec
::
Zero
(
dimY
());
// Copy the input vector to matlab code
memcpy
((
void
*
)
mxGetPr
(
x
),
(
void
*
)
&
ax
[
0
],
dimX
()
*
sizeof
(
double
));
// Evaluate the matlab routine
std
::
stringstream
cmd
;
cmd
<<
"y = griddatan(X(:, 1:"
<<
dimX
()
<<
"), Y(:, 1), x)"
;
engEvalString
(
ep
,
cmd
.
str
().
c_str
());
std
::
cout
<<
output
<<
std
::
endl
;
engEvalString
(
ep
,
"display(y)"
);
std
::
cout
<<
output
<<
std
::
endl
;
// Get results and copy it
y
=
engGetVariable
(
ep
,
"y"
)
;
double
*
y_val
=
(
double
*
)
mxGetData
(
y
);
memcpy
(
&
res
[
0
],
y_val
,
dimY
()
*
sizeof
(
double
));
return
res
;
}
// Get data size, e.g. the number of samples to fit
int
data_interpolant
::
size
()
const
{
assert
(
_data
!=
NULL
);
return
_data
->
size
();
}
ALTA_DLL_EXPORT
data
*
provide_data
()
{
return
new
data_interpolant
();
}
sources/plugins/data_interpolant_matlab/data.h
0 → 100644
View file @
df6b8a59
#pragma once
#include <core/data.h>
#include <core/common.h>
#include <core/args.h>
#include <engine.h>
/*! \brief Load a data file, but provide access to an interpolated version of
* the data points.
*
* <h2>Requirements:</h2>
* Matlab engine
*/
class
data_interpolant
:
public
data
{
public:
// methods
data_interpolant
();
~
data_interpolant
();
// Load data from a file
virtual
void
load
(
const
std
::
string
&
filename
)
;
virtual
void
load
(
const
std
::
string
&
filename
,
const
arguments
&
args
)
;
virtual
void
save
(
const
std
::
string
&
filename
)
const
;
// Acces to data
virtual
vec
get
(
int
i
)
const
;
virtual
vec
operator
[](
int
i
)
const
;
virtual
vec
value
(
vec
in
,
vec
out
)
const
;
virtual
vec
value
(
vec
x
)
const
;
// Set data
virtual
void
set
(
vec
x
);
// Get data size, e.g. the number of samples to fit
virtual
int
size
()
const
;
private:
// data
// The data object used to load sparse points sets
data
*
_data
;
Engine
*
ep
;
}
;
sources/plugins/data_interpolant_matlab/data_interpolant_matlab.pro
0 → 100644
View file @
df6b8a59
TEMPLATE
=
lib
CONFIG
*=
plugin
\
eigen
\
matlab
DESTDIR
=
..
/../
build
INCLUDEPATH
+=
..
/..
HEADERS
=
data
.
h
SOURCES
=
data
.
cpp
LIBS
+=
-
L
..
/../
build
\
-
lcore
sources/plugins/plugins.pro
View file @
df6b8a59
...
...
@@ -29,5 +29,6 @@ SUBDIRS = \
data_merl
\
data_brdf_slice
\
data_interpolant
\
data_interpolant_matlab
\
#
data_astm
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment