コード例 #1
0
ファイル: ModuleFeedbackManager.cpp プロジェクト: nixz/covise
void
ModuleFeedbackManager::updateColorBar(RenderObject *containerObject)
{

    RenderObject *colorObj = NULL;
    const char *colormapString = NULL;

    if (containerObject)
    {
        colorObj = containerObject->getColors();
        if (!colorObj)
            colorObj = containerObject->getTexture();
        if (colorObj)
        {
            colormapString = colorObj->getAttribute("COLORMAP");
            if (colormapString == NULL && colorObj->isSet())
            {
                size_t noElems = colorObj->getNumElements();
                for (size_t elem = 0; elem < noElems; ++elem)
                {
                    colormapString = colorObj->getElement(elem)->getAttribute("COLORMAP");
                    if (colormapString)
                        break;
                }
            }
            // compute colorbar
            std::string tmpStr = ModuleName(geomObjectName_.c_str());
            const char *modname = tmpStr.c_str();
            float min = 0.0;
            float max = 1.0;
            int numColors;
            float *r = NULL;
            float *g = NULL;
            float *b = NULL;
            float *a = NULL;
            char *species = NULL;
            if (colormapString)
            {
                //cerr << "ModuleFeedbackManager::updateColorBar(..) COLORMAPSTRING " << colormapString << endl;
                ColorBar::parseAttrib(colormapString, species, min, max, numColors, r, g, b, a);
            }
            else
            {
                species = new char[16];
                strcpy(species, "NoColors");
                numColors = 2;
                min = 0.0;
                min = 1.0;
                r = new float[2];
                g = new float[2];
                b = new float[2];
                a = new float[2];
                r[0] = 0.0;
                g[0] = 0.0;
                b[0] = 0.0;
                a[0] = 1.0;
                r[1] = 1.0;
                g[1] = 1.0;
                b[1] = 1.0;
                a[1] = 1.0;
            }

            // color bar
            if (colorBar_)
            {
                colorBar_->update(species, min, max, numColors, r, g, b, a);
            }
            else
            {
                //cerr << "ModuleFeedbackManager::updateColorBar(..) MODNAME <" << modname << ">" << endl;
                colorBar_ = new ColorBar(colorsButton_, menu_,
                                         modname, species, min, max, numColors, r, g, b, a);
            }
            delete[] species;
            delete[] r;
            delete[] g;
            delete[] b;
            delete[] a;
        }
        else // container without colors
        {
            if (colorBar_) // the previous object had colors
                delete colorBar_;
            colorBar_ = NULL;
        }
    }
    else // no container
    {
        if (colorBar_) //the previous object had colors
            delete colorBar_;
        colorBar_ = NULL;
    }
}
コード例 #2
0
ファイル: cuIsoSurface.cpp プロジェクト: nixz/covise
void cuIsoSurface::addObject(RenderObject *container,
                             RenderObject *geometry, RenderObject *normals,
                             RenderObject *colorObj, RenderObject *texObj,
                             osg::Group * /*setName*/, int /*numCol*/,
                             int, int /*colorPacking*/, float *, float *,
                             float *, int *,
                             int, int, float *, float *, float *, float)
{
    osg::Group *group = NULL;

    std::map<std::string, osg::Group *>::iterator gi = groups.find(container->getName());
    if (gi == groups.end())
    {
        group = new osg::Group();
        group->setName(container->getName());
        cover->getObjectsRoot()->addChild(group);
        groups[container->getName()] = group;
    }
    else
        group = gi->second;

    if (!menu)
    {
        coMenu *coviseMenu = (coMenu *)(VRPinboard::instance()->namedMenu("COVISE")->getCoMenu());
        coSubMenuItem *menuItem = new coSubMenuItem("cuIsoSurfaceUSG");
        menu = new coRowMenu("cuIsoSurfaceUSG", coviseMenu);
        menuItem->setMenu(menu);
        coviseMenu->add(menuItem);
    }

    if (container)
    {
        // get min and max from COLORMAP parameter of the container object
        RenderObject *tex = container->getTexture();
        if (tex && tex->isSet())
        {
            const char *attr = tex->getAttribute("COLORMAP");
            if (attr)
            {
                char *species;
                float *r = NULL, *g = NULL, *b = NULL, *a = NULL;
                int numColors;
                float min, max;
                ColorBar::parseAttrib(attr, species, min, max,
                                      numColors, r, g, b, a);
                struct minmax m = { min, max };
                minMax[container->getName()] = m;

                delete[] r;
                delete[] g;
                delete[] b;
                delete[] a;
            }
        }
    }

    if (geometry && geometry->isUnstructuredGrid())
    {

        if (colorObj)
        {
            const float *red = colorObj->getFloat(Field::Red);
            const float *green = colorObj->getFloat(Field::Green);
            const float *blue = colorObj->getFloat(Field::Blue);
            const int *pc = colorObj->getInt(Field::RGBA);

            if (red && (!pc && !green && !blue))
            {
                float box[6];
                geometry->getMinMax(box[0], box[1], box[2], box[3], box[4], box[5]);

                float min = 0.0, max = 1.0;
                float dataMin = 0.0, dataMax = 1.0;
                getMinMax(red, colorObj->getNumElements(), &dataMin, &dataMax);
                removeSpikesAdaptive(red, colorObj->getNumElements(), &dataMin, &dataMax);

                std::map<std::string, struct minmax>::iterator mi = minMax.find(container->getName());
                if (mi != minMax.end())
                {
                    min = mi->second.min;
                    max = mi->second.max;
                }
                else
                {
                    const char *attrMin = container->getAttribute("MIN");
                    const char *attrMax = container->getAttribute("MAX");
                    if (attrMin && attrMax)
                    {
                        min = atof(attrMin);
                        max = atof(attrMax);
                    }
                }
                //fprintf("stderr, Iso minmax: %f %f\n", min, max);

                osg::ref_ptr<osg::StateSet> state = new osg::StateSet();
                state->setGlobalDefaults();

                if (texObj)
                {

                    osg::Texture1D *colorTex = new osg::Texture1D();
                    colorTex->setDataVariance(osg::Object::DYNAMIC);

                    int wx, wy, wz;
                    texObj->getSize(wx, wy, wz);

                    osg::Image *texImage = new osg::Image();
                    texImage->allocateImage(wx, wy, 1, GL_RGB, GL_UNSIGNED_BYTE);
                    // copy texture
                    unsigned char *it = new unsigned char[wx * wy * wz];
                    memcpy(it, texObj->getByte(Field::Texture), wx * wy * wz);

                    texImage->setImage(wx, wy, 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, it, osg::Image::USE_NEW_DELETE);

                    colorTex->setImage(texImage);
                    colorTex->setFilter(osg::Texture1D::MIN_FILTER,
                                        osg::Texture1D::LINEAR);
                    colorTex->setFilter(osg::Texture1D::MAG_FILTER,
                                        osg::Texture1D::LINEAR);

                    state->setTextureAttributeAndModes(0, colorTex,
                                                       osg::StateAttribute::ON);

                    state->setTextureMode(0, GL_TEXTURE_1D,
                                          osg::StateAttribute::ON);
                }
                osg::ref_ptr<osg::Geode> g = new osg::Geode();

                state->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::ON);
                state->setMode(GL_BLEND, osg::StateAttribute::OFF);
                state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
                state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
                state->setRenderBinDetails(10, "RenderBin");
                state->setNestRenderBins(false);
                /*
                osg::Material *mtl = new osg::Material;
                mtl->setColorMode(osg::Material::OFF);
                mtl->setAmbient(osg::Material::FRONT_AND_BACK,
                            osg::Vec4(1.0, 0.0, 0.0, 0.5));
                mtl->setDiffuse(osg::Material::FRONT_AND_BACK,
                            osg::Vec4(1.0, 0.0, 0.0, 0.5));
                mtl->setSpecular(osg::Material::FRONT_AND_BACK,
                             osg::Vec4(0.8, 0.8, 0.8, 0.5));
                mtl->setEmission(osg::Material::FRONT_AND_BACK,
                             osg::Vec4(0.0, 0.0, 0.0, 0.5));
                mtl->setAlpha(osg::Material::FRONT_AND_BACK, 1.0);
                state->setAttributeAndModes(mtl, osg::StateAttribute::ON);
                osg::TexEnv *env = new osg::TexEnv();
                env->setMode(osg::TexEnv::REPLACE);
                state->setTextureAttributeAndModes(0, env, osg::StateAttribute::ON);
                */
                g->setStateSet(state.get());

                //coSliderMenuItem *slider = NULL;
                coPotiToolboxItem *slider = NULL;
                coTUIFloatSlider *tuiSlider = NULL;
                coTUIToggleButton *tuiButton = NULL;

                //std::map<std::string, coSliderMenuItem *>::iterator i =
                std::map<std::string, coPotiToolboxItem *>::iterator i = sliders.find(container->getName());
                std::map<std::string, coTUIFloatSlider *>::iterator ti = tuiSliders.find(container->getName());
                std::map<std::string, coTUIToggleButton *>::iterator tbi = tuiButtons.find(container->getName());

                if (i == sliders.end())
                {
                    const char *name = colorObj->getAttribute("LABEL");
                    if (!name)
                        name = container->getName();

                    slider = new coPotiToolboxItem(name, dataMin, dataMax, dataMin);
                    sliders[container->getName()] = slider;
                    menu->add(slider);
                }
                else
                    slider = i->second;

                if (ti == tuiSliders.end())
                {
                    const char *name = colorObj->getAttribute("LABEL");
                    if (!name)
                        name = container->getName();

                    tuiSlider = new coTUIFloatSlider(name, tuiTab->getID());
                    tuiSlider->setMin(min);
                    tuiSlider->setMax(max);
                    tuiSlider->setValue(min);
                    tuiSlider->setPos(0, tuiSliders.size());
                    tuiSliders[container->getName()] = tuiSlider;
                }
                else
                    tuiSlider = ti->second;

                if (tbi == tuiButtons.end())
                {
                    const char *name = colorObj->getAttribute("LABEL");
                    if (!name)
                        name = container->getName();

                    tuiButton = new coTUIToggleButton("animate", tuiTab->getID());
                    tuiButton->setState(false);
                    tuiButton->setPos(1, tuiButtons.size());
                    tuiButtons[container->getName()] = tuiButton;
                }
                else
                    tuiSlider = ti->second;

                osg::ref_ptr<IsoDrawable> draw = new IsoDrawable(slider, tuiSlider, tuiButton,
                        geometry, normals, colorObj, box, min, max);

                opencover::coVRShader *shader = coVRShaderList::instance()->get("texture1d");
                if (shader)
                    shader->apply(g);

                g->addDrawable(draw.get());
                draw->setUseDisplayList(false);
                group->addChild(g.get());
                char name[256];
                snprintf(name, 256, "%s_%s", container->getName(),
                         geometry->getName());
                geode[std::string(name)] = g.get();
                g->setName(strdup(name));
                //printf("added geode [%s]\n", name);
            }
            else
                cerr << "no/wrong data received" << endl;
        }
    }
}