void FieldContainer::dumpFieldInfo(void) const
{
    const TypeObject &oType = this->getType();

    fprintf(stderr, "Dump Container (%s) Field Info\n",
            oType.getCName());

    for(UInt32 i = 1; i <= oType.getNumFieldDescs(); ++i)
    {
        FieldDescriptionBase *pDesc = oType.getFieldDesc(i);

        if(pDesc != NULL)
        {
            UInt32 uiTmp  = (_bvChanged & pDesc->getFieldMask()) != 0x0000;
            UInt32 uiTmp1 = 0x0000;

            fprintf(stderr, WS30"                                  ch : %x\r", 
                    uiTmp);


            uiTmp  = (pDesc->getFlags() & Field::FClusterLocal) != 0x0000;
            uiTmp1 = (_pFieldFlags->_bClusterLocalFlags & 
                       pDesc      ->getFieldMask()       ) == 0x0000;

            fprintf(stderr, WS30"                     cl : %x | %x\r",
                    uiTmp,
                    uiTmp1);


            uiTmp  = (pDesc->getFlags() & Field::FThreadLocal) != 0x0000;
            uiTmp1 = (_pFieldFlags->_bThreadLocalFlags & 
                       pDesc      ->getFieldMask()     ) == 0x0000;

            fprintf(stderr, WS30"        tl : %x | %x\r",
                    uiTmp,
                    uiTmp1);


            fprintf(stderr, "(%d) : %s :\r", 
                    i, 
                    pDesc->getCName());


            fprintf(stderr, "\n");

#if 0
            fprintf(stderr, "0x%016"PRIx64" 0x%016"PRIx64"\n",
                    _pFieldFlags->_bClusterLocalFlags,
                    pDesc      ->getFieldMask());
#endif
        }
        else
        {
            fprintf(stderr, "(%d) : NULL\n", i);
        }
    }
}
Exemplo n.º 2
0
/*!
    Tries to write the image object to the given output stream.
    Returns true on success.
*/
bool EXRImageFileType::write(const Image        *image, 
                                   std::ostream &os, 
                             const std::string  &mimetype)
{
#ifdef OSG_WITH_IMF
    if (!os.good())
        return false;

    if(image->getDataType() != Image::OSG_FLOAT16_IMAGEDATA)
    {
        FWARNING(("EXRImageFileType::write: Image has non float data type!\n"));
        return false;
    }
    if(image->getComponents() != 4)
    {
        FWARNING(("EXRImageFileType::write: Image has != 4 components!\n"));
        return false;
    }
    if (image->getSideCount() == 6)
    {
        FWARNING(("EXRImageFileType::write: NYI for cubemaps\n"));  //TODO
        return false;
    }

    try
    {
        Int32 width  = image->getWidth();
        Int32 height = image->getHeight();

        const char *dummy = "";
        StdOStream file(os, dummy);
        Imf::Header header(width, height);

#if 0
        // now add custom attributes
        ImageGenericAtt *att = dynamic_cast<ImageGenericAtt *>(
            image->findAttachment(
                ImageGenericAtt::getClassType().getGroupId()));

        if(att != NULL)
        {
            FieldContainerType  &fcType = att->getType();
            Int32 count = att->getType().getNumFieldDescs();

            for(Int32 i = 1; i <= count; ++i)
            {
                FieldDescriptionBase *fDesc = fcType.getFieldDesc(i);
                Field                *field = att->getField(i);

                if(fDesc != NULL && field != NULL)
                {
                    SFString *strField = dynamic_cast<SFString*>(field);

                    if(strField != NULL)
                    {
                        Imf::StringAttribute imfAttr(
                            strField->getValue().c_str());

                        header.insert(fDesc->getCName(), imfAttr);
                    }
                }
            }
        }
#endif

        // we write each side as 4 channels out
        // side 0 RGBA
        // side 1 R1G1B1A1
        // ...
        for(Int32 side=0;side<image->getSideCount();++side)
        {
            char cn[20];
            sprintf(cn, "%d", side);

            char name[20];
            sprintf(name, "R%s", side == 0 ? "" : cn);
            header.channels().insert(name, Imf::Channel(Imf::HALF));
            sprintf(name, "G%s", side == 0 ? "" : cn);
            header.channels().insert(name, Imf::Channel(Imf::HALF));
            sprintf(name, "B%s", side == 0 ? "" : cn);
            header.channels().insert(name, Imf::Channel(Imf::HALF));
            sprintf(name, "A%s", side == 0 ? "" : cn);
            header.channels().insert(name, Imf::Channel(Imf::HALF));
        }

        Imf::OutputFile stream(file, header);
        Imf::FrameBuffer frame_buffer;

        // we need to do a vertical flip so we write single scan lines out.
        for(int i=height-1;i>=0;--i)
        {
            for(Int32 side=0;side<image->getSideCount();++side)
            {
                const char *data = (reinterpret_cast<const char *>(image->getData(0, 0, side))) + i * (sizeof(Real16) * 4 * width);

                // writePixels() adds the current scan line index as an offset to the
                // base address we need to eliminate this!
                data -= stream.currentScanLine() * (sizeof(Real16) * 4 * width);

                char cn[20];
                sprintf(cn, "%d", side);
                char name[20];
                sprintf(name, "R%s", side == 0 ? "" : cn);
                frame_buffer.insert(name, Imf::Slice(Imf::HALF, 
                                                     const_cast<char *>(data), sizeof(Real16) * 4, sizeof(Real16) * 4 * width));
                sprintf(name, "G%s", side == 0 ? "" : cn);
                frame_buffer.insert(name, Imf::Slice(Imf::HALF, 
                                                     const_cast<char *>(data) + 1 * sizeof(Real16), sizeof(Real16) * 4, sizeof(Real16) * 4 * width));
                sprintf(name, "B%s", side == 0 ? "" : cn);
                frame_buffer.insert(name, Imf::Slice(Imf::HALF, 
                                                     const_cast<char *>(data) + 2 * sizeof(Real16), sizeof(Real16) * 4, sizeof(Real16) * 4 * width));
                sprintf(name, "A%s", side == 0 ? "" : cn);
                frame_buffer.insert(name, Imf::Slice(Imf::HALF, 
                                                     const_cast<char *>(data) + 3 * sizeof(Real16), sizeof(Real16) * 4, sizeof(Real16) * 4 * width));
            }
            stream.setFrameBuffer(frame_buffer);
            stream.writePixels(1);
        }

        return true;
    }
    catch(std::exception &e)
    {
        FFATAL(( "Error while trying to write OpenEXR Image from stream: %s\n",
                  e.what() ));
        return false;
    }

#else
    SWARNING << getMimeType()
             << " write is not compiled into the current binary "
             << std::endl;
    return false;
#endif
}
/*-------------------------------------------------------------------------*\
 -  private                                                                 -
\*-------------------------------------------------------------------------*/
void GenericFieldContainerEditor::updateFieldsPanel(FieldContainer* fc)
{
    _FieldsContainer->clearChildren();

    UInt32 NumFields(fc->getType().getNumFieldDescs());
    FieldDescriptionBase* Desc;
    FieldEditorComponentUnrecPtr TheEditor;
    LabelUnrecPtr TheLabel;
    ComponentRecPtr TheToolTip;
    GridBagLayoutConstraintsRefPtr LayoutConstraints;
    PanelRefPtr FieldPanel;
    UInt32 NumRows(0),NumRowsForField(1);

    BorderLayoutRefPtr TheBorderLayout = BorderLayout::create();
    BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create();
    WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST);
    BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create();
    CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER);

    //Backgrounds
    ColorLayerRefPtr HeaderBgLayer = ColorLayer::create();
    HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f));

    ColorLayerRefPtr LightBgLayer = ColorLayer::create();
    LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f));
    ColorLayerRefPtr DarkBgLayer = ColorLayer::create();
    DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f));

    LayoutConstraints = GridBagLayoutConstraints::create();
    LayoutConstraints->setGridX(0);
    LayoutConstraints->setGridY(NumRows);
    LayoutConstraints->setGridHeight(1);
    LayoutConstraints->setGridWidth(2);
    LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);

    LabelRecPtr FieldsLabel = Label::create();
    FieldsLabel->setAlignment(Vec2f(0.5f,0.5f));
    FieldsLabel->setText("Fields");
    FieldsLabel->setBackgrounds(HeaderBgLayer);
    FieldsLabel->setConstraints(LayoutConstraints);
    FieldsLabel->setFont(_BoldFont);

    _FieldsContainer->pushToChildren(FieldsLabel);
    ++NumRows;

    if(_GenericNameAttachmentEditor->isTypeEditable(fc->getType()))
    {
        //Create the Label
        TheLabel = Label::create();
        TheLabel->setText("Name");
        TheLabel->setBackgrounds(NULL);
        TheLabel->setConstraints(WestConstraint);
        TheLabel->setPreferredSize(Vec2f(160.0f,22.0f));

        //Attach the Generic Name Editor
        _GenericNameAttachmentEditor->setCommandManager(_CmdManager);
        _GenericNameAttachmentEditor->attachContainer(fc);
        _GenericNameAttachmentEditor->setConstraints(CenterConstraint);

        //Create the Panel
        LayoutConstraints = GridBagLayoutConstraints::create();
        LayoutConstraints->setGridX(0);
        LayoutConstraints->setGridY(NumRows);
        LayoutConstraints->setGridHeight(1);
        LayoutConstraints->setGridWidth(1);
        LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);

        FieldPanel = Panel::createEmpty();
        FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f));
        FieldPanel->pushToChildren(TheLabel);
        FieldPanel->pushToChildren(_GenericNameAttachmentEditor);
        FieldPanel->setLayout(TheBorderLayout);
        FieldPanel->setConstraints(LayoutConstraints);
        FieldPanel->setBackgrounds(LightBgLayer);

        _FieldsContainer->pushToChildren(FieldPanel);
        ++NumRows;
    }

    UInt32 UsedFieldCount(0);
    for(UInt32 i(1) ; i<=NumFields ; ++i)
    {
        Desc = fc->getFieldDescription(i);
        if(Desc != NULL &&
           !Desc->isInternal() &&
           Desc->getFieldType().getClass() != FieldType::ParentPtrField &&
           //HACK: Stop the pixel field from being editable on Images
           !(fc->getType().isDerivedFrom(Image::getClassType()) &&
             Desc->getFieldId() == Image::PixelFieldId))
        {
            //Create the Editor
            TheEditor = FieldEditorFactory::the()->createDefaultEditor(fc, Desc->getFieldId(), _CmdManager);
            if(TheEditor != NULL)
            {
                NumRowsForField = TheEditor->getNumRequestedRows();
                pushToEditors(TheEditor);
                TheEditor->setConstraints(CenterConstraint);

                //Create the Label
                TheLabel = Label::create();
                TheLabel->setText(Desc->getCName());
                TheLabel->setBackgrounds(NULL);
                TheLabel->setConstraints(WestConstraint);
                TheLabel->setPreferredSize(Vec2f(160.0f,22.0f));
                TheToolTip = createFieldToolTip(Desc);
                TheLabel->setToolTip(TheToolTip);

                //Create the Panel
                LayoutConstraints = GridBagLayoutConstraints::create();
                LayoutConstraints->setGridX(0);
                LayoutConstraints->setGridY(NumRows);
                LayoutConstraints->setGridHeight(NumRowsForField);
                LayoutConstraints->setGridWidth(1);
                LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);


                FieldPanel = Panel::createEmpty();
                FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f));
                FieldPanel->pushToChildren(TheLabel);
                FieldPanel->pushToChildren(TheEditor);
                FieldPanel->setLayout(TheBorderLayout);
                FieldPanel->setConstraints(LayoutConstraints);
                if((UsedFieldCount%2) == 0)
                {
                    FieldPanel->setBackgrounds(DarkBgLayer);
                }
                else
                {
                    FieldPanel->setBackgrounds(LightBgLayer);
                }

                _FieldsContainer->pushToChildren(FieldPanel);
                NumRows += NumRowsForField;
                TheEditor->setPreferredSize(Vec2f(50.0f,22.0f * NumRowsForField));
                ++UsedFieldCount;
            }
        }
    }

    //Set the number of rows for the grid layout
    dynamic_cast<GridBagLayout*>(_FieldsContainer->getLayout())->setRows(NumRows);
    _FieldsContainer->setPreferredSize(Vec2f(400.0f, NumRows*24.0f));
}