Ejemplo n.º 1
0
bool MT_ExperimentDataFile::readDataGroupFromXML(MT_DataGroup* dg)
{
    if(m_bStatus == MT_XDF_ERROR)
    {
        return setError();
    }
    ReadDataGroupFromXML(m_XMLFile, dg);
    return setOK();
}
Ejemplo n.º 2
0
bool MT_ExperimentDataFile::writeDataGroupToXML(MT_DataGroup* dg)
{
    if(m_bStatus == MT_XDF_ERROR)
    {
        return setError();
    }
    WriteDataGroupToXML(&m_XMLFile, dg);
    return setOK();
}
Ejemplo n.º 3
0
bool MT_ExperimentDataFile::getParameterAsDouble(const char* param_name,
                                                 double* val)
    const 
{
    std::string sv;

    if(getParameterString(param_name, &sv) == MT_XDF_ERROR)
    {
        return setError();
    }
    else
    {
        std::stringstream ss(sv);
        ss >> *val;
        return setOK();
    }
}
Ejemplo n.º 4
0
bool MT_ExperimentDataFile::writeData(const char* stream_name,
                                   const std::vector<double>& data,
                                   const char* format_str)
{
    if(m_bStatus == MT_XDF_ERROR)
    {
        return setError();
    }

    /* find the file index by label */
    int i = findStreamIndexByLabel(stream_name);

    /* if not found, return false */
    if(i == MT_XDF_STREAM_INDEX_ERROR)
    {
        fprintf(stderr, "Error:  No stream with label %s\n", stream_name);
        return setError();
    }

    FILE* fp = m_vpDataFiles[i];
    unsigned int n_data = data.size();

    /* if the data vector's size is 0, write NaN */
    if(n_data == 0)
    {
        fprintf(fp, "NaN \n");
    }
    else
    {
        /* otherwise write the data to the file */
        for(unsigned int i = 0; i < n_data; i++)
        {
            fprintf(fp, format_str, data[i]);
        }
        /* append a newline at the end of the data */
        fprintf(fp, "\n");
    }

    /* mark that we've written to this file this time step */
    m_vWroteThisTimeStep[i] = true;

    /* return true to indicate success */
    return setOK();

}
Ejemplo n.º 5
0
bool arlCore::Point::load( std::ifstream &f, unsigned int &cam, void* &tag, int &fringe, int &no, unsigned int dim )
{
    Object::update();
    setOK(false);
    if(!f.is_open()) return false;
    init(dim);
    no=-1;
    unsigned int i,j;
    std::string token,text;
    double val; //,version;
    bool b=false;
    do
    {
        f>>token;
        //if(token=="Version") f>>version;
        if(token=="Visibility") f>>m_visibility;
        //if(token=="Status") f>>""; //TODO
        if(token=="Radius") f>>m_scalar; // Deprecated
        if(token=="Scalar") f>>m_scalar;
        if(token=="Confidence") f>>m_confidence;
        if(token=="Error") f>>m_error;
        if(token=="Numero") f>>no;
        if(token=="Camera") f>>cam;
        if(token=="Tag") f>>tag;
        if(token=="Fringe") f>>fringe;
        if(token=="Name")
        {
            f>>text;
            setName(text);
        }
        if(token=="Dimension")
        {
            if(dim>0) f>>i;
            else
            {
                f>>dim;
                m_coordinates.set_size(dim);
                m_stat.resize(size());
                for( i=0 ; i<size() ; ++i )
                    m_stat[i].fill(0.0);
                m_coordinates.fill(0.0);
                m_covMatrix.set_size(dim,dim);
                m_covMatrix.fill(0.0);
            }
        }
Ejemplo n.º 6
0
bool MT_ExperimentDataFile::writeParameterToXML(const char* param_name,
                                             const char* value)
{
    if(m_bStatus == MT_XDF_ERROR)
    {
        return setError();
    }

    std::string _label(param_name);

    /* the label can't have any spaces */
    _label = MT_ReplaceSpacesInString(_label);

    MT_AddOrReplaceNodeValue(getParametersNode(), _label.c_str(), value);

    /* save the file */
    m_XMLFile.SaveFile();

    return setOK();
}
Ejemplo n.º 7
0
arlCore::Point::Point( unsigned int dim, ARLCORE_POINT_TYPE type, long int date, long int time ):
m_type(type),
m_confidence(0),
m_visibility(true),
m_status(ARLCORE_POINT_STATUS_UNKNOWN),
m_scalar(-1.0),
m_isColored(false),
m_colour(0,0,0),
m_ponderation(1.0),
m_error(-1.0)
{
    unsigned int i;
    setOK(true);
    //VAG setTime(date,time);
    m_coordinates.set_size(dim);
    m_coordinates.fill(0.0);
    m_stat.resize(size());
    for( i=0 ; i<size() ; ++i )
        m_stat[i].fill(0.0);
    initUncertainty();
}
Ejemplo n.º 8
0
arlCore::Point::Point( double x, double y, double z, ARLCORE_POINT_TYPE type, long int date, long int time ):
//Object(ARLCORE_CLASS_POINT),
m_type(type),
m_confidence(0),
m_visibility(true),
m_status(ARLCORE_POINT_STATUS_UNKNOWN),
m_scalar(-1.0),
m_isColored(false),
m_colour(0,0,0),
m_ponderation(1.0),
m_error(-1.0)
{
    unsigned int i;
    //VAG setTime(date,time);
    m_coordinates.set_size(3);
    m_coordinates.put(0,x);
    m_coordinates.put(1,y);
    m_coordinates.put(2,z);
    m_stat.resize(size());
    for( i=0 ; i<size() ; ++i )
        m_stat[i].fill(0.0);
    initUncertainty();
    setOK(true);
}
Ejemplo n.º 9
0
arlCore::PlaneSystem::PlaneSystem( const std::string &name ):
Object(ARLCORE_CLASS_PLANESYSTEM, name)
{
    setOK(true);
}
Ejemplo n.º 10
0
bool MT_ExperimentDataFile::init(const char* filename, 
                              bool asreadonly,
                              bool force_overwrite)
{
    m_bReadOnly = asreadonly;

    std::string _filename = MT_EnsurePathHasExtension(std::string(filename), "xdf");
    m_sPathPrefix = get_prefix(filename);

    bool exists = MT_FileIsAvailable(_filename.c_str());

    if(m_bReadOnly == MT_XDF_READ_WRITE &&
       force_overwrite == MT_XDF_NO_OVERWRITE &&
       exists)
    {
        /* check to make sure the file doesn't exist */
        m_bStatus = MT_XDF_ERROR;
        fprintf(stderr,
                "File %s exists.  Try "
                "initAsNew(filename, MT_XDF_READ_WRITE, MT_XDF_OVERWRITE) "
                "if you really mean to overwrite this file.\n",
                _filename.c_str());
        return setError();
    }

    if(m_bReadOnly == MT_XDF_READ_ONLY
       && !exists)
    {
        m_bStatus = MT_XDF_ERROR;
        std::cerr << "MT_ExperimentDataFile init error:  File " << filename
                  << " does not exist\n";
        return setError();
    }

    /* create or open the XML file */
    if(exists)
    {
        if(!m_XMLFile.ReadFile(_filename.c_str()))
        {
            fprintf(stderr,
                    "Error reading MT_ExperimentDataFile "
                    "%s.\n",
                    _filename.c_str());
            m_bStatus = MT_XDF_ERROR;
            return setError();
        }
        if(!m_XMLFile.HasRootname(MT_XDF_XML_ROOT))
        {
            fprintf(stderr,
                    "Error: File %s does not have the proper root name\n"
                    "  Root is %s, should be %s\n",
                    _filename.c_str(),
                    m_XMLFile.Rootname(),
                    MT_XDF_XML_ROOT);
            m_bStatus = MT_XDF_ERROR;
            return setError();
        }
    } 
    else
    {
        m_XMLFile.SetFilename(_filename.c_str());
        if(!m_XMLFile.InitNew(MT_XDF_XML_ROOT))
        {
            fprintf(stderr,
                    "Error:  Unable to create root %s in %s\n",
                    MT_XDF_XML_ROOT,
                    _filename.c_str());
            m_bStatus = MT_XDF_ERROR;
            return setError();
        }
    }
    return setOK();

}
Ejemplo n.º 11
0
bool MT_ExperimentDataFile::addDataStream(const char* label,
                                       const char* filename,
                                       bool force_overwrite)
{
    if(m_bStatus == MT_XDF_ERROR)
    {
        return setError();
    }

    /* if this is already one of our streams, return true
     * without doing anything */
    if(findStreamIndexByLabel(label) != MT_XDF_STREAM_INDEX_ERROR)
    {
        return setOK();
    }

    /* if filename == NULL, use filename = label */
    std::string _filename(filename);
    if(!filename)
    {
        _filename = label;
    }

    std::string dir = dir_from_xdf(m_XMLFile.GetFilename());
    _filename = dir + _filename;
    MT_mkdir(dir.c_str());

    /* check to see if filename exists (for reading) */
    bool exists = MT_FileIsAvailable(_filename.c_str(), "r");

    /* if it does and force_overwrite is false, then
     * return false. if force_overwrite is true, then
     * overwrite the file. */
    if(exists)
    {
        if(force_overwrite == MT_XDF_NO_OVERWRITE)
        {
            fprintf(stderr,
                    "File %s already exists.  If you are sure you want "
                    "to overwrite it, try addDataStream(label, filename, MT_XDF_OVERWRITE).\n",
                    _filename.c_str());
            return setError();
        }
    }

    /* make sure we can write to the file (this will erase the file if it's there!) */
    FILE* fp = fopen(_filename.c_str(), "w");
    if(!fp)
    {
        fprintf(stderr,
                "Error: Can't write to file %s.  Unable to "
                "add to experiment data stream.\n",
                _filename.c_str());
        return setOK();
    }

    /* register the file in the XML master */
    registerFile(label, _filename.c_str());
    /* save the file */
    m_XMLFile.SaveFile();

    /* set up the various registers */
    m_vpDataFiles.push_back(fp);
    m_vFileNames.push_back(_filename);
    m_vNames.push_back(label);
    m_vWroteThisTimeStep.push_back(false);
    m_viCheckedOut.push_back(0);

    /* if everything goes well, return true */
    return setOK();

}