Exemple #1
0
    bool ModelContainer::writeFile(const char *filename)
    {
        bool result = false;
        unsigned int flags=0;
        unsigned int size;

        FILE *wf =fopen(filename,"wb");
        if(wf)
        {
            fwrite(VMAP_MAGIC,1,8,wf);
            result = true;
            if(result && fwrite("CTREE01",8,1,wf) != 1) result = false;
            if(result && fwrite(&flags,sizeof(unsigned int),1,wf) != 1) result = false;

            if(result && fwrite("POS ",4,1,wf) != 1) result = false;
            size = sizeof(float)*3;
            if(result && fwrite(&size,4,1,wf) != 1) result = false;
            Vector3 basePos = getBasePosition();
            if(result && fwrite(&basePos,sizeof(float),3,wf) != 3) result = false;

            if(result && fwrite("BOX ",4,1,wf) != 1) result = false;
            size = sizeof(float)*6;
            if(result && fwrite(&size,4,1,wf) != 1) result = false;
            Vector3 low = iBox.low();
            if(result && fwrite(&low,sizeof(float),3,wf) != 3) result = false;
            Vector3 high = iBox.high();
            if(result && fwrite(&high,sizeof(float),3,wf) != 3) result = false;

            if(result && fwrite("NODE",4,1,wf) != 1) result = false;
            size = sizeof(unsigned int)+ sizeof(TreeNode)*getNNodes();
            if(result && fwrite(&size,4,1,wf) != 1) result = false;
            unsigned int val = getNNodes();
            if(result && fwrite(&val,sizeof(unsigned int),1,wf) != 1) result = false;
            if(result && fwrite(getTreeNodes(),sizeof(TreeNode),getNNodes(),wf) != getNNodes()) result = false;

            if(result && fwrite("TRIB",4,1,wf) != 1) result = false;
            size = sizeof(unsigned int)+ sizeof(TriangleBox)*getNTriangles();
            if(result && fwrite(&size,4,1,wf) != 1) result = false;
            val = getNTriangles();
            if(result && fwrite(&val,sizeof(unsigned int),1,wf) != 1) result = false;
            if(result && fwrite(getTriangles(),sizeof(TriangleBox),getNTriangles(),wf) != getNTriangles()) result = false;

            if(result && fwrite("SUBM",4,1,wf) != 1) result = false;
            size = sizeof(unsigned int)+ sizeof(SubModel)*iNSubModel;
            if(result && fwrite(&size,4,1,wf) != 1) result = false;
            if(result && fwrite(&iNSubModel,sizeof(unsigned int),1,wf) != 1) result = false;
            if(result && fwrite(iSubModel,sizeof(SubModel),iNSubModel,wf) != iNSubModel) result = false;

            fclose(wf);
        }

        return(result);
    }
Exemple #2
0
    bool SubModel::operator==(const SubModel& pSm2) const
    {
        bool result = false;

        if(getNNodes() == pSm2.getNNodes() &&
            getNTriangles() == pSm2.getNTriangles() &&
            getBasePosition() == pSm2.getBasePosition() &&
            getNodesPos() == pSm2.getNodesPos() &&
            getTrianglesPos() == pSm2.getTrianglesPos())
        {
            result = true;
        }
        return result;
    }
Exemple #3
0
    bool ModelContainer::readFile(const char *filename)
    {
        bool result = false;
        unsigned int flags;
        unsigned int size;
        char ident[8];
        char chunk[4];
        unsigned int ival;
        FILE *rf = fopen(filename, "rb");
        if(rf)
        {
            free();

            result = true;
            char magic[8];                          // Ignore the added magic header
            fread(magic,1,8,rf);
            if(strncmp(VMAP_MAGIC,magic,8)) result = false;
            if(result && fread(ident,8,1,rf) != 1) result = false;
            if(result && fread(&flags,sizeof(unsigned int),1,rf) != 1) result = false;
            //POS
            if(result && fread(chunk,4,1,rf) != 1) result = false;
            if(result && fread(&size,4,1,rf) != 1) result = false;
            Vector3 basePos;
            if(result && fread(&basePos,sizeof(float),3,rf) != 3) result = false;
            setBasePosition(basePos);

            //---- Box
            if(result && fread(chunk,4,1,rf) != 1) result = false;
            if(result && fread(&size,4,1,rf) != 1) result = false;
            Vector3 low,high;
            if(result && fread(&low,sizeof(float),3,rf) != 3) result = false;
            if(result && fread(&high,sizeof(float),3,rf) != 3) result = false;
            setBounds(low, high);

            //---- TreeNodes
            if(result && fread(chunk,4,1,rf) != 1) result = false;
            if(result && fread(&size,4,1,rf) != 1) result = false;

            if(result && fread(&ival,sizeof(unsigned int),1,rf) != 1) result = false;
            if(result) setNNodes(ival);
            if(result) setTreeNodeArray(new TreeNode[getNNodes()]);
            if(result && fread(getTreeNodes(),sizeof(TreeNode),getNNodes(),rf) != getNNodes()) result = false;

            //---- TriangleBoxes
            if(result && fread(chunk,4,1,rf) != 1) result = false;
            if(result && fread(&size,4,1,rf) != 1) result = false;

            if(result && fread(&ival,sizeof(unsigned int),1,rf) != 1) result = false;
            setNTriangles(ival);
            if(result) setTriangleArray(new TriangleBox[getNTriangles()]);
            if(result && fread(getTriangles(),sizeof(TriangleBox),getNTriangles(),rf) != getNTriangles()) result = false;

            //---- SubModel
            if(result && fread(chunk,4,1,rf) != 1) result = false;
            if(result && fread(&size,4,1,rf) != 1) result = false;

            if(result && fread(&iNSubModel,sizeof(unsigned int),1,rf) != 1) result = false;
            if(result) iSubModel = new SubModel[iNSubModel];

            if(result)
            {
                for (unsigned int i=0; i<iNSubModel && result; ++i)
                {
                    unsigned char readBuffer[52];           // this is the size of SubModel on 32 bit systems
                    if(fread(readBuffer,sizeof(readBuffer),1,rf) != 1) result = false;
                    iSubModel[i].initFromBinBlock(readBuffer);
                    iSubModel[i].setTriangleArray(getTriangles());
                    iSubModel[i].setTreeNodeArray(getTreeNodes());
                }
            }
            fclose(rf);
        }
        return result;
    }