Esempio n. 1
0
KDvoid Sample_Fresnel::setupProps ( KDvoid )
{
    Entity*  pEntity;
    
    // setting up props might take a while, so create a progress bar for visual feedback
    ProgressBar*  pProgress = m_pTrayMgr->createProgressBar ( TL_CENTER, "FresnelBuildingBar", "Creating Props...", 280, 100 );
    m_pTrayMgr->showBackdrop ( "SdkTrays/Shade" );

    pProgress->setComment ( "Upper Bath" );
    pEntity = m_pSceneMgr->createEntity ( "UpperBath", "RomanBathUpper.mesh" );
    m_pSceneMgr->getRootSceneNode()->attachObject ( pEntity );
    m_aSurfaceEnts.push_back ( pEntity );
    pProgress->setProgress ( 0.4 );
 
    pProgress->setComment("Columns");
    pEntity = m_pSceneMgr->createEntity ( "Columns", "columns.mesh" );
    m_pSceneMgr->getRootSceneNode ( )->attachObject ( pEntity );
    m_aSurfaceEnts.push_back ( pEntity );
    pProgress->setProgress ( 0.5 );

    pProgress->setComment ( "Ogre Head" );
    pEntity = m_pSceneMgr->createEntity ( "Head", "ogrehead.mesh" );
    pEntity->setMaterialName ( "RomanBath/OgreStone" );
    m_aSurfaceEnts.push_back ( pEntity );
    pProgress->setProgress ( 0.6 );
    
    SceneNode*  pHeadNode = m_pSceneMgr->getRootSceneNode ( )->createChildSceneNode ( );
    pHeadNode->setPosition ( -350, 55, 130 );
    pHeadNode->yaw ( Degree ( 90 ) );
    pHeadNode->attachObject ( pEntity );

    pProgress->setComment ( "Lower Bath" );
    pEntity = m_pSceneMgr->createEntity ( "LowerBath", "RomanBathLower.mesh" );
    m_pSceneMgr->getRootSceneNode ( )->attachObject ( pEntity );
    m_aSubmergedEnts.push_back( pEntity );
    pProgress->setProgress ( 1 );

    m_pTrayMgr->destroyWidget ( pProgress );
    m_pTrayMgr->hideBackdrop ( );
}
Esempio n. 2
0
VolumeFlow3D* FlowReader::readConvert(const tgt::ivec3& dimensions, const BYTE orientation,
                                      std::fstream& ifs)
{
    tgt::ivec3 permutation = Flow3D::getAxisPermutation(orientation);
    switch (orientation) {
        case Flow3D::XZY:
            LINFO("voxel order: XZY (code = " << static_cast<int>(orientation) << ")");
            LINFO("changing voxel order from XZY to XYZ...");
            break;
        case Flow3D::YXZ:
            LINFO("voxel order: YXZ (code = " << static_cast<int>(orientation) << ")");
            LINFO("changing voxel order from YXZ to XYZ...");
            break;
        case Flow3D::YZX:
            LINFO("voxel order: YZX (code = " << static_cast<int>(orientation) << ")");
            LINFO("changing voxel order from YZX to XYZ...");
            break;
        case Flow3D::ZXY:
            LINFO("voxel order: ZXY (code = " << static_cast<int>(orientation) << ")");
            LINFO("changing voxel order from ZXY to XYZ...");
            break;
        case Flow3D::ZYX:
            LINFO("voxel order: ZYX (code = " << static_cast<int>(orientation) << ")");
            LINFO("changing voxel order from ZYX to XYZ...");
            break;
        case Flow3D::XYZ:
            LINFO("voxel order: XYZ (code = " << static_cast<int>(orientation) << ")");
            LINFO("no conversion of voxel order required.");
            break;
        default:
            LINFO("voxel order: unknown (code = " << static_cast<int>(orientation) << ")");
            LINFO("further processing not possible! canceling");
            return 0;
    }

    const size_t numVoxels = dimensions.x * dimensions.y * dimensions.z;
    const size_t byteSize = numVoxels * sizeof(tgt::vec3);

    tgt::vec3* voxels = 0;
    try {
        voxels = new tgt::vec3[numVoxels];
    } catch (std::bad_alloc) {
        throw;
    }

    const tgt::ivec3 xyz(0, 1, 2);  // target voxel order is XYZ
    const int max = tgt::max(dimensions);

    // no remainder possible because getNumBytes is a multiple of max
    //
    const size_t bufferByteSize = byteSize / static_cast<size_t>(max);
    const size_t numBufferElements = bufferByteSize / sizeof(tgt::vec3);
    tgt::vec3* buffer = new tgt::vec3[numBufferElements];
    memset(buffer, 0, bufferByteSize);

    ProgressBar* progress = getProgressBar();

    tgt::ivec3 pos(0, 0, 0);
    float maxValue = std::numeric_limits<float>::min();
    float minValue = std::numeric_limits<float>::max();
    float maxMagnitude = 0.0f;

    for (size_t i = 0; i < size_t(max); ++i) {
        ifs.read(reinterpret_cast<char*>(buffer), bufferByteSize);
        if (progress)
            progress->setProgress(static_cast<float>(i) / static_cast<float>(max));

        for (size_t j = 0; j < numBufferElements; ++j) {
            // get the number of the voxel in current data orientation
            //
            size_t voxelNumber = j + (i * numBufferElements);

            if (orientation != Flow3D::XYZ) {
                // convert the number into the position within the voxel
                // ((x, y, z)-coordinates in volume's bounding box)
                //
                pos = Flow3D::voxelNumberToPos(voxelNumber, permutation, dimensions);

                // re-calculate the number of the voxel for the desired
                // data orientation
                //
                size_t newNumber = Flow3D::posToVoxelNumber(pos, xyz, dimensions);
                voxels[newNumber] = buffer[j];
            } else
                voxels[voxelNumber] = buffer[j];

            // calculate max and min of current voxel and dataset's min and max.
            //
            float voxelMax = tgt::max(buffer[j]);
            float voxelMin = tgt::min(buffer[j]);
            float magnitude = tgt::length(buffer[j]);

            if (voxelMax > maxValue)
                maxValue = voxelMax;
            if (voxelMin < minValue)
                minValue = voxelMin;
            if (magnitude > maxMagnitude)
                maxMagnitude = magnitude;
        }
    }

    progress->setProgress(1.f);

    delete [] buffer;

    LINFO("min. among all components of all voxels: " << minValue);
    LINFO("max. among all components of all voxels: " << maxValue);
    LINFO("max. magnitude among all  voxels: " << maxMagnitude);

    return new VolumeFlow3D(voxels, dimensions, minValue, maxValue, maxMagnitude);
}
void ImageSequenceSource::loadImageSequence(const std::string& d)
    throw (tgt::FileException, std::bad_alloc) {

    if (!isInitialized()) {
        LERROR("loadImageSequence(): not initialized");
        return;
    }

    // important: d might be cleared by clearSequence
    std::string dir(d);

    forceReload_ = false;

    if (!imageSequence_) {
        LERROR("No image sequence present");
        return;
    }

    // clear current sequence
    clearSequence();

    if (dir.empty())
        return;

    LINFO("Loading images from directory " << dir << " ...");
    currentDir_ = dir;
    imageDirectory_.set(dir);

    // load images as textures and collect them in an image sequence
    std::vector<std::string> filenames = tgt::FileSystem::readDirectory(dir, true, false);

    // create progress bar
    ProgressBar* progressDialog = 0;
    if (showProgressBar_.get() && !filenames.empty()) {
        progressDialog = VoreenApplication::app()->createProgressDialog();
        if (progressDialog) {
            progressDialog->setTitle("Loading Images");
            progressDialog->show();
            progressDialog->setProgress(0.f);
            progressDialog->forceUpdate();
        }
    }

    tgt::Texture::Filter filterMode = textureFiltering_.get() ? tgt::Texture::LINEAR : tgt::Texture::NEAREST;
    for (size_t i=0; i<filenames.size(); ++i) {
        if (progressDialog) {
            progressDialog->setMessage("Loading " + filenames[i] + " ...");
            progressDialog->setProgress(static_cast<float>(i) / static_cast<float>(filenames.size()));
        }
        LINFO("Loading image " << filenames[i] << " ...");
        tgt::Texture* texture = TexMgr.load(dir + "/" + filenames[i], filterMode,
            false, false, true, false, !GpuCaps.isNpotSupported());
        if (texture)
            imageSequence_->add(texture);
        else
            LWARNING("Failed to load image: " << filenames[i]);
    }
    LGL_ERROR;

    // upload texture data
    if (uploadTextureData_.get()) {
        LINFO("Uploading texture data ...");
        for (unsigned int i=0; i<imageSequence_->size(); i++)
            imageSequence_->at(i)->uploadTexture();
        LGL_ERROR;
    }

    // clear progress
    if (progressDialog) {
        progressDialog->hide();
        delete progressDialog;
        progressDialog = 0;
    }

    // output sequence
    outport_.setData(imageSequence_);

    LINFO("Successfully loaded " << imageSequence_->size() << " images.");
    numImages_.set(imageSequence_->size());
    LGL_ERROR;
}