DM_r_convert.cpp
// =================================================================
// converting points into an R data frame objects
// =================================================================
#include <iostream>
#include <vector>
#include "DM/Datamanager.hpp"
#include "DM/RConverter.hpp"
using namespace std;
void DM_r_convert(const char *filename)
{
#ifdef DM_WITH_R_SUPPORT
//open the odm
DM::DatamanagerHandle dm = DM::IDatamanager::load(filename,true/*readOnly*/,false/*threadSafety*/);
//if the dm wasn't opened sucessful exit function
if (!dm)
{
cout << "Unable to open ODM '" << filename << "'" << endl;
return;
}
//create a layout for conversion
DM::AddInfoLayoutFactoryHandle f = DM::IAddInfoLayoutFactory::New();
f->addColumn(DM::ColumnSemantic::Amplitude); //pre-defined attribute "Amplitude"
f->addColumn(DM::ColumnSemantic::EchoWidth); //pre-defined attribute "EchoWidth"
DM::AddInfoLayoutHandle layout = f->getLayout();
DM::PointIndexHandle pi = dm->getPointIndex();
//convert each leaf into a data frame
std::vector<void *> dfs;
for(auto it = pi->beginLeaf(); it != pi->endLeaf(); ++it)
{
dfs.push_back( DM::RConverter::asDataFrame( it->beginPoint(), it->endPoint(), layout, true) );
}
//create a single data frame
__int64 idx = 0;
void *df = DM::RConverter::createDataFrame( pi->sizePoint(), layout, true );
for(auto it = pi->beginLeaf(); it != pi->endLeaf(); ++it)
{
DM::RConverter::fillDataFrame(df, idx, it->beginPoint(), it->endPoint());
idx += it->sizePoint();
}
#endif //#ifdef DM_WITH_R_SUPPORT
}
@ EchoWidth
Full width at half maximum [ns].
DM_API void initEmbeddedR(int argc=0, char *argv[]=0)
Initializes the embedded R instance Must be called only once for the overall process....
DM_API void * createDataFrame(int64_t rowCount, const AddInfoLayoutHandle &layout, bool withCoordinates=true)
Creates a empty data frame object of a given size based.
DM_API void * asDataFrame(const_iterator_point it, const_iterator_point end, const AddInfoLayoutHandle &layout, bool withCoordinates=true, FilterHandle filter=FilterHandle())
convert a set points including there attributes into an R data frame object
Definition: Handle.hpp:427
@ Amplitude
Linear scale value proportional to the receiving power.
DM_API int64_t fillDataFrame(void *sexpObj, int64_t rowIdx, const_iterator_point it, const_iterator_point end, FilterHandle filter=FilterHandle())
fill an existing data frame object with a set of points at the specified row index
static IDatamanager * load(const char *filename, bool readOnly=false, bool threadSafety=true)
Smart pointer class using reference counting with support for DM objects (see ObjectBase)
Definition: Handle.hpp:75