⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dimoopxt.h

📁 转化为DIB位图再显示出来的dicom文件C++代码
💻 H
📖 第 1 页 / 共 5 页
字号:
        }        if (ColorData != NULL)            return ColorData->writePPM(stream);        return 0;    } protected:    /** examine which pixel values are actually used     */    inline void determineUsedValues()    {        if ((UsedValues == NULL) && (MaxValue > 0) && (MaxValue < MAX_TABLE_ENTRY_COUNT))        {            UsedValues = new Uint8[MaxValue + 1];            if (UsedValues != NULL)            {                OFBitmanipTemplate<Uint8>::zeroMem(UsedValues, MaxValue + 1); // initialize array                register const T3 *p = Data;                register Uint8 *q = UsedValues;                register unsigned long i;                for (i = Count; i != 0; --i)                    *(q + *(p++)) = 1;                                        // mark used entries            }        }    } private:    /** create a display LUT with the specified number of input bits     *     ** @param  dlut  reference to storage area where the display LUT should be stored     *  @param  disp  pointer to object describing the current display function     *  @param  bits  number of bits defining the input width of the display LUT     */    inline void createDisplayLUT(const DiDisplayLUT *&dlut,                                 DiDisplayFunction *disp,                                 const int bits)    {        if ((disp != NULL) && (disp->isValid()))        {                                                                     // create Display LUT            dlut = disp->getLookupTable(bits);            if ((dlut != NULL) && (dlut->isValid()))                          // LUT is valid            {#ifdef DEBUG                if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                {                    ofConsole.lockCerr() << "INFO: using display transformation" << endl;                    ofConsole.unlockCerr();                }#endif            } else {                if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))                {                    ofConsole.lockCerr() << "WARNING: can't create display LUT ... ignoring display transformation !" << endl;                    ofConsole.unlockCerr();                }                dlut = NULL;            }        }    }    /** initialize an optimization LUT if the optimization criteria is fulfilled     *     ** @param  lut   reference to storage area where the optimization LUT should be stored     *  @param  ocnt  number of entries for the optimization LUT     */    inline int initOptimizationLUT(T3 *&lut,                                   const unsigned long ocnt)    {        int result = 0;        if ((sizeof(T1) <= 2) && (Count > 3 * ocnt))                          // optimization criteria        {                                                                     // use LUT for optimization            lut = new T3[ocnt];            if (lut != NULL)            {#ifdef DEBUG                if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                {                    ofConsole.lockCerr() << "INFO: using optimized routine with additional LUT" << endl;                    ofConsole.unlockCerr();                }#endif                result = 1;            }        }        return result;    }#ifdef PASTEL_COLOR_OUTPUT    void color(void *buffer,                               // create true color pastel image               const DiMonoPixel *inter,               const unsigned long frame,               const unsigned long frames)    {        ColorData = new DiMonoColorOutputPixelTemplate<T1, T3>(buffer, inter, frame, frames);        if (ColorData != NULL)        {            ofConsole.lockCout() << "COLOR" << endl;            ofConsole.unlockCout();        }    }#endif    /** apply the currently active VOI LUT to the output data     *     ** @param  inter  pointer to intermediate pixel representation     *  @param  start  offset of the first pixel to be processed     *  @param  vlut   VOI LUT     *  @param  plut   presentation LUT (optional, maybe NULL)     *  @param  disp   display function (optional, maybe NULL)     *  @param  low    lowest pixel value for the output data (e.g. 0)     *  @param  high   highest pixel value for the output data (e.g. 255)     */    void voilut(const DiMonoPixel *inter,                const Uint32 start,                const DiLookupTable *vlut,                const DiLookupTable *plut,                DiDisplayFunction *disp,                const T3 low,                const T3 high)    {        const T1 *pixel = OFstatic_cast(const T1 *, inter->getData());        if ((pixel != NULL) && (vlut != NULL))        {            if (Data == NULL)                Data = new T3[FrameSize];            if (Data != NULL)            {#ifdef DEBUG                if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                {                    ofConsole.lockCerr() << "INFO: using VOI routine 'voilut()'" << endl;                    ofConsole.unlockCerr();                }#endif                const DiDisplayLUT *dlut = NULL;                const double minvalue = vlut->getMinValue();                const double outrange = OFstatic_cast(double, high) - OFstatic_cast(double, low) + 1;                register unsigned long i;                if (minvalue == vlut->getMaxValue())                                    // LUT has only one entry or all entries are equal                {                    T3 value;                    if ((plut != NULL) && (plut->isValid()))                            // has presentation LUT                    {#ifdef DEBUG                        if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                        {                            ofConsole.lockCerr() << "INFO: using presentation LUT transformation" << endl;                            ofConsole.unlockCerr();                        }#endif                        createDisplayLUT(dlut, disp, plut->getBits());                        const Uint32 value2 = OFstatic_cast(Uint32, (minvalue / OFstatic_cast(double, vlut->getAbsMaxRange())) * plut->getCount());                        if (dlut != NULL)                                               // perform display transformation                        {                            /* UNTESTED !! */                            if (low > high)                                             // invers                                value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, plut->getAbsMaxRange() - plut->getValue(value2) - 1)));                            else                                                        // normal                                value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, plut->getValue(value2))));                        } else {                                                        // don't use display: invalid or absent                            value = OFstatic_cast(T3, OFstatic_cast(double, low) + OFstatic_cast(double, plut->getValue(value2)) * outrange / OFstatic_cast(double, plut->getAbsMaxRange()));                        }                    } else {                                                            // has no presentation LUT                        createDisplayLUT(dlut, disp, vlut->getBits());                        if (dlut != NULL)                                               // perform display transformation                        {                            /* UNTESTED !! */                            if (low > high)                                             // invers                                value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, vlut->getAbsMaxRange() - minvalue - 1)));                            else                                                        // normal                                value = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, minvalue)));                        } else                                                          // don't use display: invalid or absent                            value = OFstatic_cast(T3, OFstatic_cast(double, low) + (minvalue / OFstatic_cast(double, vlut->getAbsMaxRange())) * outrange);                    }                    OFBitmanipTemplate<T3>::setMem(Data, value, Count);                 // set output pixels to LUT value                } else {                    register T2 value = 0;                    const T2 absmin = OFstatic_cast(T2, inter->getAbsMinimum());                    const T2 firstentry = vlut->getFirstEntry(value);                   // choose signed/unsigned method                    const T2 lastentry = vlut->getLastEntry(value);                    const unsigned long ocnt = OFstatic_cast(unsigned long, inter->getAbsMaxRange());  // number of LUT entries                    register const T1 *p = pixel + start;                    register T3 *q = Data;                    T3 *lut = NULL;                    if ((plut != NULL) && (plut->isValid()))                            // has presentation LUT                    {#ifdef DEBUG                        if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Informationals))                        {                            ofConsole.lockCerr() << "INFO: using presentation LUT transformation" << endl;                            ofConsole.unlockCerr();                        }#endif                        createDisplayLUT(dlut, disp, plut->getBits());                        register Uint32 value2;                                         // presentation LUT is always unsigned                        const Uint32 pcnt = plut->getCount();                        const double gradient1 = OFstatic_cast(double, pcnt) / OFstatic_cast(double, vlut->getAbsMaxRange());                        const Uint32 firstvalue = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getFirstValue()) * gradient1);                        const Uint32 lastvalue = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getLastValue()) * gradient1);                        if (initOptimizationLUT(lut, ocnt))                        {                                                                 // use LUT for optimization                            q = lut;                            if (dlut != NULL)                                             // perform display transformation                            {                                if (low > high)                                           // inverse                                {                                    const Uint16 maxvalue = OFstatic_cast(Uint16, plut->getAbsMaxRange() - 1);                                    for (i = 0; i < ocnt; ++i)                                    {                                        value = OFstatic_cast(T2, i) + absmin;                                        if (value <= firstentry)                                            value2 = firstvalue;                                        else if (value >= lastentry)                                            value2 = lastvalue;                                        else                                            value2 = OFstatic_cast(Uint32, OFstatic_cast(double, vlut->getValue(value)) * gradient1);                                        *(q++) = OFstatic_cast(T3, dlut->getValue(OFstatic_cast(Uint16, maxvalue - plut->getValue(value2))));                                    }                                } else {                                                  // normal                                    for (i = 0; i < ocnt; ++i)                                    {                                        value = OFstatic_cast(T2, i) + absmin;                                        if (value <= firstentry)                                            value2 = firstvalue;                                        else if (value >= lastentry)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -