Beispiel #1
0
bool ccObject::fromFile(QFile& in, short dataVersion, int flags)
{
    assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

    if (dataVersion<20)
        return CorruptError();

    //DGM: if we are here, we assume the class ID has already been read!
    //Call ccObject::readClassIDFromFile if necessary
    ////class ID (dataVersion>=20)
    //uint32_t classID = 0;
    //if (in.read((char*)&classID,4) < 0)
    //	return ReadError();

    //unique ID (dataVersion>=20)
    //DGM: this ID will be usefull to recreate dynamic links between entities!
    uint32_t uniqueID = 0;
    if (in.read((char*)&uniqueID,4) < 0)
        return ReadError();
    m_uniqueID = (unsigned)uniqueID;

    //name
    if (dataVersion < 22) //old style
    {
        char name[256];
        if (in.read(name,256) < 0)
            return ReadError();
        setName(name);
    }
    else //(dataVersion>=22)
    {
        QDataStream inStream(&in);
        inStream >> m_name;
    }

    //flags (dataVersion>=20)
    uint32_t objFlags = 0;
    if (in.read((char*)&objFlags,4) < 0)
        return ReadError();
    m_flags = (unsigned)objFlags;

    //meta data (dataVersion>=30)
    if (dataVersion >= 30)
    {
        //count
        uint32_t metaDataCount = 0;
        if (in.read((char*)&metaDataCount,4) < 0)
            return ReadError();

        //"key + value" pairs
        for (uint32_t i=0; i<metaDataCount; ++i)
        {
            QDataStream inStream(&in);
            QString key;
            QVariant value;
            inStream >> key;
            inStream >> value;
            setMetaData(key,value);
        }
    }
bool ccGenericPointCloud::fromFile_MeOnly(QFile& in, short dataVersion)
{
	if (!ccHObject::fromFile_MeOnly(in, dataVersion))
		return false;

	if (dataVersion<20)
		return CorruptError();

	//'coordinates shift' (dataVersion>=20)
	if (in.read((char*)m_originalShift,sizeof(double)*3)<0)
		return ReadError();

	//'visibility' array (dataVersion>=20)
	bool hasVisibilityArray = false;
	if (in.read((char*)&hasVisibilityArray,sizeof(bool))<0)
		return ReadError();
	if (hasVisibilityArray)
	{
		if (!m_visibilityArray)
		{
			m_visibilityArray = new VisibilityTableType();
			m_visibilityArray->link();
		}
		if (!ccSerializationHelper::GenericArrayFromFile(*m_visibilityArray,in,dataVersion))
		{
			unallocateVisibilityArray();
			return false;
		}
	}

	return true;
}
Beispiel #3
0
bool ccObject::fromFile(QFile& in, short dataVersion)
{
	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	if (dataVersion<20)
		return CorruptError();

	//DGM: if we are here, we assume the class ID has already been read!
	//Call ccObject::readClassIDFromFile if necessary
	////class ID (dataVersion>=20)
	//uint32_t classID = 0;
	//if (in.read((char*)&classID,4)<0)
	//	return ReadError();

	//unique ID (dataVersion>=20)
	//DGM: this ID will be usefull to recreate dynamic links between entities!
	uint32_t uniqueID = 0;
	if (in.read((char*)&uniqueID,4)<0)
		return ReadError();
	m_uniqueID = (unsigned)uniqueID;

	//name (dataVersion>=20)
	if (in.read(m_name,256)<0)
		return ReadError();

	//flags (dataVersion>=20)
	uint32_t flags = 0;
	if (in.read((char*)&flags,4)<0)
		return ReadError();
	m_flags = (unsigned)flags;

	return true;
}
Beispiel #4
0
bool ccHObject::fromFile(QFile& in, short dataVersion)
{
    assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

    //read 'ccObject' header
    if (!ccObject::fromFile(in,dataVersion))
        return false;

    //read own data
    if (!fromFile_MeOnly(in,dataVersion))
        return false;

    //(serializable) child count (dataVersion>=20)
    uint32_t serializableCount = 0;
    if (in.read((char*)&serializableCount,4)<0)
        return ReadError();

    //read serializable children (if any)
    for (uint32_t i=0; i<serializableCount; ++i)
    {
        //read children class ID
        unsigned classID=0;
        if (!ReadClassIDFromFile(classID, in, dataVersion))
            return false;

        //create corresponding child object
        ccHObject* child = New(classID);
        assert(child && child->isSerializable());
        if (child)
        {
            if (child->fromFile(in,dataVersion))
            {
                addChild(child,child->getFlagState(CC_FATHER_DEPENDANT));
            }
            else
            {
                delete child;
                return false;
            }
        }
        else
        {
            return CorruptError();
        }
    }

    //write current selection behavior (dataVersion>=23)
    if (dataVersion>=23)
    {
        if (in.read((char*)&m_selectionBehavior,sizeof(SelectionBehavior))<0)
            return ReadError();
    }
    else
    {
        m_selectionBehavior = SELECTION_AA_BBOX;
    }

    return true;
}
bool ccGenericPointCloud::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
	if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags))
		return false;

	if (dataVersion < 20)
		return CorruptError();

	if (dataVersion < 33)
	{
		//'coordinates shift' (dataVersion>=20)
		if (in.read((char*)m_globalShift.u,sizeof(double)*3) < 0)
			return ReadError();

		m_globalScale = 1.0;
	}
	else
	{
		//'global shift & scale' (dataVersion>=33)
		if (!loadShiftInfoFromFile(in))
			return ReadError();
	}

	//'visibility' array (dataVersion>=20)
	bool hasVisibilityArray = false;
	if (in.read((char*)&hasVisibilityArray,sizeof(bool)) < 0)
		return ReadError();
	if (hasVisibilityArray)
	{
		if (!m_pointsVisibility)
		{
			m_pointsVisibility = new VisibilityTableType();
			m_pointsVisibility->link();
		}
		if (!ccSerializationHelper::GenericArrayFromFile(*m_pointsVisibility,in,dataVersion))
		{
			unallocateVisibilityArray();
			return false;
		}
	}

	//'point size' (dataVersion>=24)
	if (dataVersion >= 24)
	{
		if (in.read((char*)&m_pointSize,1) < 0)
			return WriteError();
	}
	else
	{
		m_pointSize = 0; //= follows default setting
	}

	return true;
}
Beispiel #6
0
bool ccGLMatrix::fromFile(QFile& in, short dataVersion)
{
	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	if (dataVersion<20)
		return CorruptError();

	//data (dataVersion>=20)
	if (in.read((char*)m_mat,sizeof(float)*OPENGL_MATRIX_SIZE)<0)
		return ReadError();

	return true;
}
//=======================================================fromFile========================================================================//
bool ccIndexedTransformation::fromFile(QFile& in, short dataVersion, int flags)
{
	if (!ccGLMatrix::fromFile(in, dataVersion, flags))
		return false;

	assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));

	if (dataVersion<34)
		return CorruptError();

	//index (dataVersion>=34)
	if (in.read((char*)&m_index,sizeof(double)) < 0)
		return ReadError();

	return true;
}
Beispiel #8
0
bool ccHObject::fromFile(QFile& in, short dataVersion, int flags)
{
	if (!fromFileNoChildren(in, dataVersion, flags))
		return false;

	//(serializable) child count (dataVersion>=20)
	uint32_t serializableCount = 0;
	if (in.read((char*)&serializableCount,4) < 0)
		return ReadError();

	//read serializable children (if any)
	for (uint32_t i = 0; i < serializableCount; ++i)
	{
		//read children class ID
		CC_CLASS_ENUM classID = ReadClassIDFromFile(in, dataVersion);
		if (classID == CC_TYPES::OBJECT)
			return false;

		//create corresponding child object
		ccHObject* child = New(classID);

		//specifc case of custom objects (defined by plugins)
		if (classID == CC_TYPES::CUSTOM_H_OBJECT)
		{
			//store current position
			size_t originalFilePos = in.pos();
			//we need to load the custom object as plain ccCustomHobject
			child->fromFileNoChildren(in, dataVersion, flags);
			//go back to original position
			in.seek(originalFilePos);
			//get custom object name and plugin name
			QString childName = child->getName();
			QString classId = child->getMetaData(ccCustomHObject::DefautMetaDataClassName()).toString();
			QString pluginId = child->getMetaData(ccCustomHObject::DefautMetaDataPluginName()).toString();
			//dont' need this instance anymore
			delete child;
			child = 0;

			// try to get a new object from external factories
			ccHObject* newChild = ccHObject::New(pluginId, classId);
			if (newChild) // found a plugin that can deserialize it
			{
				child = newChild;
			}
			else
			{
				ccLog::Warning(QString("[ccHObject::fromFile] Couldn't found any plugin able to deserialize custom object '%1' (class_ID = %2 / plugin_ID = %3").arg(childName).arg(classID).arg(pluginId));
				return false; // FIXME: for now simply return false. We may want to skip it but I'm not sure if there is a simple way of doing that
			}
		}

		assert(child && child->isSerializable());
		if (child)
		{
			if (child->fromFile(in, dataVersion, flags))
			{
				//FIXME
				//addChild(child,child->getFlagState(CC_FATHER_DEPENDENT));
				addChild(child);
			}
			else
			{
				//delete child; //we can't do this as the object might be invalid
				return false;
			}
		}
		else
		{
			return CorruptError();
		}
	}

	//read the selection behavior (dataVersion>=23)
	if (dataVersion >= 23)
	{
		if (in.read((char*)&m_selectionBehavior,sizeof(SelectionBehavior)) < 0)
			return ReadError();
	}
	else
	{
		m_selectionBehavior = SELECTION_AA_BBOX;
	}

	//read transformation history (dataVersion >= 45)
	if (dataVersion >= 45)
	{
		if (!m_glTransHistory.fromFile(in, dataVersion, flags))
		{
			return false;
		}
	}

	return true;
}