# Read VTFx File

This example reads a VTFx file and prints the content of the file to the console.

It outputs meta data on the file, database, case and all blocks. It also lists data content of data blocks (such as result values, node coordinates and ids). Only the first 100 values of such arrays are printed (if the size exceeds 100 items).

The example might be useful for dumping the file content to a console as help for debugging.

    cee::PtrRef<cee::Instance>  g_componentInstance;

    //--------------------------------------------------------------------------------------------------
    // Helper to turn variant into string
    //--------------------------------------------------------------------------------------------------
    cee::Str getAsString(cee::Variant v)
    {
        switch (v.type())
        {
            case cee::Variant::INVALID: return "Invalid";
            case cee::Variant::INT:     return cee::Str::number(v.getInt());
            case cee::Variant::UINT:    return cee::Str::number(v.getUInt());
            case cee::Variant::DOUBLE:  return cee::Str::number(v.getDouble());
            case cee::Variant::FLOAT:   return cee::Str::number(v.getFloat());
            case cee::Variant::BOOL:    return v.getBool() ? "true" : "false";
            case cee::Variant::VEC3D:   return cee::Str::number(v.getVec3d().x()) + ", " + cee::Str::number(v.getVec3d().y()) + ", " + cee::Str::number(v.getVec3d().z());
            case cee::Variant::COLOR3F: return cee::Str::number(v.getColor3f().r()) + ", " + cee::Str::number(v.getColor3f().g()) + ", " + cee::Str::number(v.getColor3f().b());
            case cee::Variant::STRING:  return v.getString();
            case cee::Variant::ARRAY:
            {
                cee::Str str;
                std::vector<cee::Variant> array = v.getArray();
                for (std::vector<cee::Variant>::iterator it = array.begin(); it != array.end(); it++)
                {
                    str = str + getAsString(*it) + " | ";
                }
                return str;
            }
            default:
                return "";
        }
    }

    //--------------------------------------------------------------------------------------------------
    //
    //--------------------------------------------------------------------------------------------------
    int main()
    {
        g_componentInstance = cee::CoreComponent::initialize(HOOPS_LICENSE);
        cee::vtfx::VTFxComponent::initialize(g_componentInstance.get());

        cee::PtrRef<cee::LogDestinationConsole> log = new cee::LogDestinationConsole();
        cee::CoreComponent::logManager()->setDestination(log.get());
        cee::CoreComponent::logManager()->setLevel("", 3);               // Log errors, warnings and info

        // Create the VTFx file
        // -------------------------------------------------------------------------
        cee::PtrRef<cee::vtfx::File> file = new cee::vtfx::File;
        if (!file->open("../../DemoFiles/SimpleExample.vtfx"))
        {
            return EXIT_FAILURE;
        }

        size_t numCases = file->fileCaseCount();
        for (size_t i = 0; i < numCases; i++)
        {
            // Case
            cee::vtfx::Case* c = file->fileCase(i);
            std::wcout << "Case " << c->id() << ": ";
            if (!c->description().isEmpty()) std::wcout << c->description().c_str();
            std::wcout << std::endl;

            // Properties
            const cee::PropertySetCollection* properties = c->properties();
            if (properties)
            {
                for (size_t j = 0; j < properties->count(); j++)
                {
                    const cee::PropertySet* propertySet = properties->propertySet(j);
                    std::wcout << "Class type: " << propertySet->classType().c_str() << std::endl;
                    std::vector<cee::Str> keys = propertySet->allKeys();
                    std::vector<cee::Variant> values = propertySet->allValues();
                    for (size_t k = 0; k < keys.size(); k++)
                    {
                        std::wcout << "     Key: " << keys.at(k).c_str() << std::endl;
                        std::wcout << "         Value: " << getAsString(values.at(k)).c_str() << std::endl;
                    }
                }
            }

            // Images
            size_t numImages = c->imageCount();
            std::wcout << "Image count: " << numImages << std::endl;
            for (size_t i = 0; i < numImages; i++)
            {
                const cee::Image* image = c->image(i);
                std::wcout << "Image name: " << c->imageName(i).c_str() << " w: " << image->width() << " h: " << image->height();
            }
        }

        size_t numDatabases = file->databaseCount();
        for (size_t i = 0; i < numDatabases; i++)
        {
            // Database
            cee::vtfx::Database* db = file->database(i);
            std::wcout << "Database " << db->id() << ": ";
            if (!db->name().isEmpty()) std::wcout << db->name().c_str();
            std::wcout << std::endl;

            // Nodes
            size_t numNodeBlocks = db->blockCount(cee::vtfx::Block::NODES);
            std::wcout << "Number of node blocks: " << numNodeBlocks << std::endl;
            for (size_t j = 0; j < numNodeBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::NODES, j);
                cee::vtfx::NodeBlock* nodeBlock = dynamic_cast<cee::vtfx::NodeBlock*>(block.get());

                std::wcout << "Node block id: " << nodeBlock->blockId() << std::endl;
                std::wcout << "     Number of nodes: " << nodeBlock->nodeCount() << std::endl;
                std::wcout << "     Nodes: ( x, y, z)" << std::endl;
                size_t nodeCount = nodeBlock->nodeCount() > 100 ? 100 : nodeBlock->nodeCount();     // Only first 100
                for (size_t k = 0; k < nodeCount; k++)
                {
                    std::wcout << "         (" << nodeBlock->nodes().at(k).x() << ", " << nodeBlock->nodes().at(k).y() << ", " << nodeBlock->nodes().at(k).z() << ")";
                    std::wcout << std::endl;
                }

                bool usesNodeIds = (nodeBlock->nodeIds().size() > 0);
                std::wcout << "     Using node ids: " << (usesNodeIds ? "yes" : "no") << std::endl;
                if (usesNodeIds)
                {
                    std::wcout << "     Node ids: ";

                    size_t nodeIdCount = nodeBlock->nodeIds().size() > 100 ? 100 : nodeBlock->nodeIds().size();     // Only first 100
                    for (size_t k = 0; k < nodeIdCount; k++)
                    {
                        std::wcout << "  " << nodeBlock->nodeIds().at(k);
                    }
                    std::wcout << std::endl;
                }
            }

            // Elements
            size_t numElementBlocks = db->blockCount(cee::vtfx::Block::ELEMENTS);
            std::wcout << "Number of element blocks: " << numElementBlocks << std::endl;
            for (size_t j = 0; j < numElementBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::ELEMENTS, j);
                cee::vtfx::ElementBlock* elementBlock = dynamic_cast<cee::vtfx::ElementBlock*>(block.get());

                std::wcout << "Element block id: " << elementBlock->blockId() << std::endl;
                std::wcout << "     Node block id: " << elementBlock->nodeBlockId() << std::endl;
                std::wcout << "     Number of elements: " << elementBlock->elementCount() << std::endl;
                std::wcout << "     Number of element nodes: " << elementBlock->elementNodeCount() << std::endl;
                std::wcout << "     Number of element groups: " << elementBlock->elementGroupCount() << std::endl;
                size_t elementGroupCount = elementBlock->elementGroupCount() > 100 ? 100 : elementBlock->elementGroupCount();     // Only first 100
                for (size_t k = 0; k < elementGroupCount; k++)
                {
                    std::wcout << "     Element group " << k << ":" << std::endl;
                    std::vector<int> elementNodes;
                    std::vector<int> elementIds;
                    std::wcout << "         Num elements: " << elementBlock->elementGroupElementCount(k) << std::endl;
                    std::wcout << "         Num element nodes: " << elementBlock->elementGroupElementNodeCount(k) << std::endl;
                    std::wcout << "         Element type: " << elementBlock->elementGroupType(k) << std::endl;
                    elementBlock->elementGroup(k, &elementNodes, &elementIds);
                    if (elementNodes.size() > 0)
                    {
                        std::wcout << "         Element nodes: ";
                        size_t elementNodeCount = elementNodes.size() > 100 ? 100 : elementNodes.size();     // Only first 100
                        for (size_t l = 0; l < elementNodeCount; l++)
                        {
                            std::wcout << elementNodes[l] << "  ";
                        }
                        std::wcout << std::endl;
                    }
                    if (elementIds.size() > 0)
                    {
                        std::wcout << "         Element ids: ";
                        size_t elementIdCount = elementIds.size() > 100 ? 100 : elementIds.size();     // Only first 100
                        for (size_t l = 0; l < elementIdCount; l++)
                        {
                            std::wcout << elementIds[l] << "  ";
                        }
                        std::wcout << std::endl;
                    }
                    int crossSectionId = elementBlock->crossSectionsBlockId();
                    if (crossSectionId >= 0)
                    {
                        std::wcout << "         Cross section block id: " << crossSectionId << std::endl;
                        std::vector<int> mappings = elementBlock->crossSectionsElementMapping(k);
                        std::wcout << "         Cross section mappings: ";
                        size_t crossSectionMappingCount = mappings.size() > 100 ? 100 : mappings.size();     // Only first 100
                        for (size_t l = 0; l < crossSectionMappingCount; l++)
                        {
                            std::wcout << mappings[l] << "  ";
                        }
                        std::wcout << std::endl;

                        std::vector<cee::Vec3f> directions = elementBlock->crossSectionsDirections(k);
                        std::wcout << "         Cross section directions: ";
                        size_t crossSectionDirectionCount = directions.size() > 100 ? 100 : directions.size();     // Only first 100
                        for (size_t l = 0; l < crossSectionDirectionCount; l++)
                        {
                            std::wcout << directions[l].x() << ", " << directions[l].y() << ", " << directions[l].z() << "  ";
                        }
                        std::wcout << std::endl;

                        std::vector<cee::Vec3f> eccentricities = elementBlock->crossSectionsEccentricities(k);
                        std::wcout << "         Cross section eccentricities: ";
                        size_t crossSectionEccentricityCount = eccentricities.size() > 100 ? 100 : eccentricities.size();     // Only first 100
                        for (size_t l = 0; l < crossSectionEccentricityCount; l++)
                        {
                            std::wcout << eccentricities[l].x() << ", " << eccentricities[l].y() << ", " << eccentricities[l].z() << "  ";
                        }
                        std::wcout << std::endl;
                    }
                }
            }

            // Results
            size_t numResultBlocks = db->blockCount(cee::vtfx::Block::RESULT);
            std::wcout << "Number of result blocks: " << numResultBlocks << std::endl;
            for (size_t j = 0; j < numResultBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::RESULT, j);
                cee::vtfx::ResultBlock* resultBlock = dynamic_cast<cee::vtfx::ResultBlock*>(block.get());

                std::wcout << "Result block id: " << resultBlock->blockId() << std::endl;
                std::wcout << "     Result id: " << resultBlock->resultId() << std::endl;
                std::wcout << "     Result name: " << resultBlock->name().c_str() << std::endl;
                std::wcout << "     Result type: " << resultBlock->resultType() << std::endl;
                std::wcout << "     Result mapping: " << resultBlock->resultMapping() << std::endl;
                if (resultBlock->resultType() == cee::vtfx::ResultBlock::DISPLACEMENT)
                {
                    std::wcout << "     Displacements are: " << (resultBlock->relativeDisplacementResults() ? "relative" : "absolute") << std::endl;
                }

                std::wcout << "     Number of states: " << resultBlock->stateCount() << std::endl;
                for (size_t k = 0; k < resultBlock->stateCount(); k++)
                {
                    std::wcout << "     State id: " << resultBlock->stateId(k) << std::endl;
                    std::vector<int> resultValuesBlocks = resultBlock->resultValuesBlocks(k);
                    std::wcout << "     Number of result values blocks: " << resultValuesBlocks.size() << std::endl;
                    std::wcout << "         Result values block ids: ";
                    for (std::vector<int>::iterator it = resultValuesBlocks.begin(); it != resultValuesBlocks.end(); ++it)
                    {
                        std::wcout << *it << "  ";
                    }
                    std::wcout << std::endl;
                }
            }

            // Result values
            size_t numResultValuesBlocks = db->blockCount(cee::vtfx::Block::RESULTVALUES);
            std::wcout << "Number of result values blocks: " << numResultValuesBlocks << std::endl;
            for (size_t j = 0; j < numResultValuesBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::RESULTVALUES, j);
                cee::vtfx::ResultValuesBlock* resultValuesBlock = dynamic_cast<cee::vtfx::ResultValuesBlock*>(block.get());

                std::wcout << "Result values block id: " << resultValuesBlock->blockId() << std::endl;
                std::wcout << "     Mapped to block id: " << resultValuesBlock->mapToBlockId() << std::endl;
                std::wcout << "     Mapped using ids: " << (resultValuesBlock->hasMapToItemIds() ? "yes" : "no") << std::endl;
                if (resultValuesBlock->hasMapToItemIds())
                {
                    std::vector<int> mapToItemIds = resultValuesBlock->mapToItemIds();
                    std::wcout << "         Mapped ids: ";
                    for (std::vector<int>::iterator it = mapToItemIds.begin(); it != mapToItemIds.end(); ++it)
                    {
                        std::wcout << *it << "  ";
                    }
                    std::wcout << std::endl;
                }
                std::wcout << "     Dimension: " << resultValuesBlock->dimension() << std::endl;

                std::vector<float> resultValues = resultValuesBlock->resultValues();
                std::wcout << "         Result values: ";
                size_t resultValueCount = resultValues.size() > 100 ? 100 : resultValues.size();     // Only first 100
                for (size_t l = 0; l < resultValueCount; l++)
                {
                    std::wcout << resultValues[l] << "  ";
                }
                std::wcout << std::endl;
            }

            // Geometry
            size_t numGeometryBlocks = db->blockCount(cee::vtfx::Block::GEOMETRY);
            std::wcout << "Number of geometry blocks: " << numGeometryBlocks << std::endl;
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::GEOMETRY, 0);
                cee::vtfx::GeometryBlock* geometryBlock = dynamic_cast<cee::vtfx::GeometryBlock*>(block.get());

                std::wcout << "Geometry block id: " << geometryBlock->blockId() << std::endl;
                std::wcout << "     Geometries per state: " << geometryBlock->geometryCountPerState() << std::endl;

                for (size_t stateIndex = 0; stateIndex < geometryBlock->stateCount(); stateIndex++)
                {
                    for (size_t geoIndex = 0; geoIndex < geometryBlock->geometryCountPerState(); geoIndex++)
                    {
                        std::wcout << "     Number of parts: " << geometryBlock->partCount(geoIndex, stateIndex) << std::endl;
                        std::vector<int> blockIds = geometryBlock->elementBlockIds(geoIndex, stateIndex);
                        std::wcout << "     Number of blocks: " << blockIds.size() << std::endl;
                        std::wcout << "         Element block ids: ";
                        for (std::vector<int>::iterator it = blockIds.begin(); it != blockIds.end(); ++it)
                        {
                            std::wcout << *it << "  ";
                        }
                        std::wcout << std::endl;
                    }
                }
            }

            // Geometry info
            size_t numGeometryInfoBlocks = db->blockCount(cee::vtfx::Block::GEOMETRYINFO);
            std::wcout << "Number of geometry info blocks: " << numGeometryInfoBlocks << std::endl;
            if (numGeometryInfoBlocks > 0)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::GEOMETRYINFO, 0);
                cee::vtfx::GeometryInfoBlock* geometryInfoBlock = dynamic_cast<cee::vtfx::GeometryInfoBlock*>(block.get());

                std::wcout << "Geometry info block id: " << geometryInfoBlock->blockId() << std::endl;
                std::wcout << "     Geometries per state: " << geometryInfoBlock->geometryCountPerState() << std::endl;

                for (size_t geoIndex = 0; geoIndex < geometryInfoBlock->geometryCountPerState(); geoIndex++)
                {
                    std::wcout << "     Number of parts: " << geometryInfoBlock->partCount(geoIndex) << std::endl;
                    for (size_t k = 0; k < geometryInfoBlock->partCount(geoIndex); k++)
                    {
                        std::wcout << "     Part id: " << geometryInfoBlock->partId(geoIndex, k) << std::endl;
                        std::wcout << "     Part name: " << geometryInfoBlock->partName(geoIndex, k).c_str() << std::endl;
                    }
                }
            }

            // State infos
            size_t numStateInfoBlocks = db->blockCount(cee::vtfx::Block::STATEINFO);
            std::wcout << "Number of state info blocks: " << numStateInfoBlocks << std::endl;
            for (size_t j = 0; j < numStateInfoBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::STATEINFO, j);
                cee::vtfx::StateInfoBlock* stateInfoBlock = dynamic_cast<cee::vtfx::StateInfoBlock*>(block.get());

                std::wcout << "State info block id: " << stateInfoBlock->blockId() << std::endl;
                std::wcout << "     Number of states: " << stateInfoBlock->stateCount() << std::endl;
                for (size_t k = 0; k < stateInfoBlock->stateCount(); k++)
                {
                    std::wcout << "     State id: " << stateInfoBlock->stateId(k) << std::endl;
                    std::wcout << "         State name: " << stateInfoBlock->stateName(k).c_str() << std::endl;
                    std::wcout << "         State reference value: " << stateInfoBlock->stateReferenceValue(k) << std::endl;
                    std::wcout << "         State reference value type: " << stateInfoBlock->stateReferenceValueType(k) << std::endl;
                    std::wcout << "         State name: " << stateInfoBlock->stateName(k).c_str() << std::endl;
                }
            }

            // Transformation results
            size_t numTransResultsBlocks = db->blockCount(cee::vtfx::Block::TRANSFORMATIONRESULT);
            std::wcout << "Number of transformation result blocks: " << numTransResultsBlocks << std::endl;
            for (size_t j = 0; j < numTransResultsBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::TRANSFORMATIONRESULT, j);
                cee::vtfx::TransformationResultBlock* transResultBlock = dynamic_cast<cee::vtfx::TransformationResultBlock*>(block.get());

                std::wcout << "Transformation result block id: " << transResultBlock->blockId() << std::endl;
                std::wcout << "     Result id: " << transResultBlock->resultId() << std::endl;
                std::wcout << "     Result name: " << transResultBlock->name().c_str() << std::endl;

                std::wcout << "     Number of states: " << transResultBlock->stateCount() << std::endl;
                for (size_t k = 0; k < transResultBlock->stateCount(); k++)
                {
                    std::wcout << "     State id: " << transResultBlock->stateId(k) << std::endl;
                    std::wcout << "     Number of result values blocks: " << transResultBlock->transformationResultValuesBlockCount(k) << std::endl;
                    std::vector<int> resultValuesBlocks = transResultBlock->transformationResultValuesBlocks(k);
                    std::wcout << "         Result values block ids: ";
                    for (std::vector<int>::iterator it = resultValuesBlocks.begin(); it != resultValuesBlocks.end(); ++it)
                    {
                        std::wcout << *it << "  ";
                    }
                    std::wcout << std::endl;
                }
            }

            // Transformation result values
            size_t numTransResultValuesBlocks = db->blockCount(cee::vtfx::Block::TRANSFORMATIONRESULTVALUES);
            std::wcout << "Number of transformation result values blocks: " << numTransResultValuesBlocks << std::endl;
            for (size_t j = 0; j < numTransResultValuesBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::TRANSFORMATIONRESULTVALUES, j);
                cee::vtfx::TransformationResultValuesBlock* resultValuesBlock = dynamic_cast<cee::vtfx::TransformationResultValuesBlock*>(block.get());

                std::wcout << "Result values block id: " << resultValuesBlock->blockId() << std::endl;
                cee::Mat4d matrix = resultValuesBlock->matrix();
                std::wcout << "     Matrix values: ";
                for (int row = 0; row < 4; ++row)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        std::wcout << matrix.rowCol(row, col) << "  ";
                    }
                }
                std::wcout << std::endl;
            }

            // Cross sections
            size_t numCrossSectionsBlocks = db->blockCount(cee::vtfx::Block::CROSSSECTIONS);
            std::wcout << "Number of cross sections blocks: " << numCrossSectionsBlocks << std::endl;
            for (size_t j = 0; j < numCrossSectionsBlocks; j++)
            {
                cee::PtrRef<cee::vtfx::Block> block = db->blockByIndex(cee::vtfx::Block::CROSSSECTIONS, j);
                cee::vtfx::CrossSectionsBlock* crossSectionsBlock = dynamic_cast<cee::vtfx::CrossSectionsBlock*>(block.get());

                std::wcout << "Cross sections block id: " << crossSectionsBlock->blockId() << std::endl;
                std::wcout << "     Number of cross sections: " << crossSectionsBlock->crossSectionCount() << std::endl;
                for (size_t k = 0; k < crossSectionsBlock->crossSectionCount(); k++)
                {
                    std::wcout << "     Cross section type: " << crossSectionsBlock->crossSectionType(k) << std::endl;
                    std::wcout << "     Cross section parameters: " << std::endl;
                    std::vector<cee::Str> parameterNames = crossSectionsBlock->crossSectionParameterNames(k);
                    std::vector<float> parameterValues = crossSectionsBlock->crossSectionParameterValues(k);
                    for (size_t l = 0; l < parameterNames.size(); l++)
                    {
                        std::wcout << "         " << parameterNames.at(l).c_str() << ": " << parameterValues.at(l) << std::endl;
                    }
                }
            }
        }

        // User text files
        size_t numFiles = file->userTextFileCount();
        for (size_t i = 0; i < numFiles; i++)
        {
            std::wcout << "     File name: " << file->userTextFileName(i).c_str() << std::endl;
            std::wcout << "     File content: " << file->userTextFileContent(i).c_str() << std::endl;
        }
        std::wcout << std::endl;

        if (!file->close())
        {
            return EXIT_FAILURE;
        }

        std::cout << std::endl << "Press enter to exit..." << std::endl;
        std::cin.ignore();

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your multilingual generative AI assistant for documentation. Ask me anything about HOOPS Envision for Desktop in your own language, or choose a sample question below to start a conversation:

What is HOOPS Envision for Desktop?
What are the latest release notes for HOOPS Envision for Desktop?
How do I start evaluating HOOPS Envision for Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...