示例#1
0
ThemeData RenderThemeGdk::getThemeData(RenderObject* o)
{
    ThemeData result;
    switch (o->style()->appearance()) {
        case PushButtonAppearance:
        case ButtonAppearance:
            result.m_part = BP_BUTTON;
            result.m_state = determineState(o);
            break;
        case CheckboxAppearance:
            result.m_part = BP_CHECKBOX;
            result.m_state = determineState(o);
            break;
        case RadioAppearance:
            result.m_part = BP_RADIO;
            result.m_state = determineState(o);
            break;
        case TextFieldAppearance:
            result.m_part = TFP_TEXTFIELD;
            result.m_state = determineState(o);
            break;
        default:
            // FIXME: much more?
            break;
    }

    return result;
}
示例#2
0
ThemeData RenderThemeChromiumWin::getThemeData(RenderObject* o, ControlSubPart subPart)
{
    ThemeData result;
    switch (o->style()->appearance()) {
    case CheckboxPart:
        result.m_part = BP_CHECKBOX;
        result.m_state = determineState(o);
        result.m_classicState = DFCS_BUTTONCHECK;
        break;
    case RadioPart:
        result.m_part = BP_RADIOBUTTON;
        result.m_state = determineState(o);
        result.m_classicState = DFCS_BUTTONRADIO;
        break;
    case SquareButtonPart:
    case PushButtonPart:
    case ButtonPart:
        result.m_part = BP_PUSHBUTTON;
        result.m_state = determineState(o);
        result.m_classicState = DFCS_BUTTONPUSH;
        break;
    case SliderHorizontalPart:
        result.m_part = TKP_TRACK;
        result.m_state = TRS_NORMAL;
        break;
    case SliderVerticalPart:
        result.m_part = TKP_TRACKVERT;
        result.m_state = TRVS_NORMAL;
        break;
    case SliderThumbHorizontalPart:
        result.m_part = TKP_THUMBBOTTOM;
        result.m_state = determineSliderThumbState(o);
        break;
    case SliderThumbVerticalPart:
        result.m_part = TKP_THUMBVERT;
        result.m_state = determineSliderThumbState(o);
        break;
    case ListboxPart:
    case MenulistPart:
    case MenulistButtonPart:
    case SearchFieldPart:
    case TextFieldPart:
    case TextAreaPart:
        result.m_part = EP_EDITTEXT;
        result.m_state = determineState(o);
        break;
    case InnerSpinButtonPart:
        result.m_part = subPart == SpinButtonUp ? SPNP_UP : SPNP_DOWN;
        result.m_state = determineState(o, subPart);
        result.m_classicState = subPart == SpinButtonUp ? DFCS_SCROLLUP : DFCS_SCROLLDOWN;
        break;
    }

    result.m_classicState |= determineClassicState(o, subPart);

    return result;
}
示例#3
0
ThemeData RenderThemeWin::getThemeData(RenderObject* o)
{
    ThemeData result;
    switch (o->style()->appearance()) {
        case PushButtonAppearance:
        case ButtonAppearance:
            result.m_part = BP_BUTTON;
            result.m_classicState = DFCS_BUTTONPUSH;
            break;
        case CheckboxAppearance:
            result.m_part = BP_CHECKBOX;
            result.m_classicState = DFCS_BUTTONCHECK;
            break;
        case RadioAppearance:
            result.m_part = BP_RADIO;
            result.m_classicState = DFCS_BUTTONRADIO;
            break;
        case ListboxAppearance:
        case MenulistAppearance:
        case TextFieldAppearance:
        case TextAreaAppearance:
            result.m_part = TFP_TEXTFIELD;
            break;
    }

    result.m_state = determineState(o);
    result.m_classicState |= determineClassicState(o);

    return result;
}
/* The chessboard cells are numbered from 0 to 63. The numbering starts from top to bottom, from left to right. */
int main()
{
    int kingCellId, queenCellId, newQueenCellId;
    enum STATE result;
    while(scanf("%d %d %d", &kingCellId, &queenCellId, &newQueenCellId) > 0)
    {
        result = determineState(kingCellId, queenCellId, newQueenCellId);

        switch(result)
        {
            case ILLEGAL_STATE:
                printf("Illegal state\n");
                break;
            case ILLEGAL_MOVE:
                printf("Illegal move\n");
                break;
            case MOVE_NOT_ALLOWED:
                printf("Move not allowed\n");
                break;
            case CONTINUE:
                printf("Continue\n");
                break;
            case STOP:
                printf("Stop\n");
        }
    }

    return 0;
}
示例#5
0
文件: nvm.c 项目: AWRyder/contiki
int8u halCommonReadFromNvm(void *data, int32u offset, int16u length)
{
  int16u i;
  int16u *flash;
  //Remember: all flash writes are 16bits.
  int16u *ram = (int16u*)data;
  
  //The NVM data storage system cannot function if the LEFT and RIGHT
  //storage are not aligned to physical flash pages.
  assert((NVM_LEFT_PAGE%MFB_PAGE_SIZE_B)==0);
  assert((NVM_RIGHT_PAGE%MFB_PAGE_SIZE_B)==0);
  //The offset of the NVM data must be 16bit aligned.
  assert((offset&0x1)==0);
  //The length of the NVM data must be 16bit aligned.
  assert((length&0x1)==0);
  
  assert(offset+length<NVM_DATA_SIZE_B);
  
  //Obtain the data from NVM storage.
  switch(determineState()) {
    case 1:
    case 2:
    case 3:
    case 4:
    case 9:
    case 10:
      flash = (int16u *)(NVM_LEFT_PAGE+offset);
      for(i=0;i<(length/2);i++) {
        ram[i] = flash[i];
      }
    break;
    case 5:
    case 6:
    case 7:
    case 8:
      flash = (int16u *)(NVM_RIGHT_PAGE+offset);
      for(i=0;i<(length/2);i++) {
        ram[i] = flash[i];
      }
    break;
    case 0:
    default:
      //Reading from NVM while the mgmt bytes are in an invalid state
      //should not return any bytes actually found in flash.  Instead,
      //return nothing but 0xFF.  This is legitimate because the next
      //call to the write function will also find invalid mgmt bytes
      //and trigger an erasure of NVM, after which the NVM really will
      //contain just 0xFF for data (plus the new data supplied during
      //the write call).
      for(i=0;i<(length/2);i++) {
        ram[i] = 0xFFFF;
      }
    //Inform the calling code. using ST_ERR_FATAL, that there were
    //invalid mgmt bytes and 0xFF was forcefully returned.
    return ST_ERR_FATAL;
  }
  
  return ST_SUCCESS;
}
// Used to paint unstyled menulists (i.e. with the default border)
bool RenderThemeChromiumWin::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
    if (!o->isBox())
        return false;

    const RenderBox* box = toRenderBox(o);
    int borderRight = box->borderRight();
    int borderLeft = box->borderLeft();
    int borderTop = box->borderTop();
    int borderBottom = box->borderBottom();

    // If all the borders are 0, then tell skia not to paint the border on the
    // textfield.  FIXME: http://b/1210017 Figure out how to get Windows to not
    // draw individual borders and then pass that to skia so we can avoid
    // drawing any borders that are set to 0. For non-zero borders, we draw the
    // border, but webkit just draws over it.
    bool drawEdges = !(borderRight == 0 && borderLeft == 0 && borderTop == 0 && borderBottom == 0);

    paintTextFieldInternal(o, i, r, drawEdges);

    // Take padding and border into account.  If the MenuList is smaller than
    // the size of a button, make sure to shrink it appropriately and not put
    // its x position to the left of the menulist.
    const int buttonWidth = GetSystemMetrics(SM_CXVSCROLL);
    int spacingLeft = borderLeft + box->paddingLeft();
    int spacingRight = borderRight + box->paddingRight();
    int spacingTop = borderTop + box->paddingTop();
    int spacingBottom = borderBottom + box->paddingBottom();

    int buttonX;
    if (r.right() - r.x() < buttonWidth)
        buttonX = r.x();
    else
        buttonX = o->style()->direction() == LTR ? r.right() - spacingRight - buttonWidth : r.x() + spacingLeft;

    // Compute the rectangle of the button in the destination image.
    IntRect rect(buttonX,
                 r.y() + spacingTop,
                 std::min(buttonWidth, r.right() - r.x()),
                 r.height() - (spacingTop + spacingBottom));

    // Get the correct theme data for a textfield and paint the menu.
    WebCore::ThemePainter painter(i.context, rect);
    ChromiumBridge::paintMenuList(painter.context(),
                                  CP_DROPDOWNBUTTON,
                                  determineState(o),
                                  determineClassicState(o),
                                  painter.drawRect());
    return false;
}
示例#7
0
bool RenderThemeWin::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
    HDC hdc = prepareForDrawing(i.context);
    RECT widgetRect = r;
    if (m_themeDLL && !m_menuListTheme)
        m_menuListTheme = openTheme(0, L"Combobox");
    if (m_menuListTheme && drawThemeBG)
        drawThemeBG(m_menuListTheme, hdc, CP_DROPDOWNBUTTON, determineState(o), &widgetRect, NULL);
    else
        DrawFrameControl(hdc, &widgetRect, DFC_SCROLL, DFCS_SCROLLCOMBOBOX | determineClassicState(o));
    doneDrawing(i.context, hdc);

    return false;
}
示例#8
0
文件: nvm.c 项目: aiss83/nucbit
int16u *halCommonGetAddressFromNvm(int32u offset)
{
    int16u *flash;

    //The NVM data storage system cannot function if the LEFT and RIGHT
    //storage are not aligned to physical flash pages.
    assert((NVM_LEFT_PAGE%MFB_PAGE_SIZE_B)==0);
    assert((NVM_RIGHT_PAGE%MFB_PAGE_SIZE_B)==0);
    //The offset of the NVM data must be 16bit aligned.
    assert((offset&0x1)==0);

    //Obtain the data from NVM storage.
    switch(determineState())
    {
    case 1:
    case 2:
    case 3:
    case 4:
    case 9:
    case 10:
        flash = (int16u *)(NVM_LEFT_PAGE+offset);
        break;
    case 5:
    case 6:
    case 7:
    case 8:
        flash = (int16u *)(NVM_RIGHT_PAGE+offset);
        break;
    case 0:
    default:
        // Flash is in an invalid state
        // Fix it with a dummy write and then return the flash page left
    {
        int16u dummy = 0xFFFF;
        halCommonWriteToNvm(&dummy, 0, 2);
        flash = (int16u *)(NVM_LEFT_PAGE+offset);
    }
    }

    return flash;
}
bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, const RenderObject& o, const PaintInfo& paintInfo, const IntRect& r)
{
    GraphicsContextStateSaver stateSaver(*paintInfo.context);

    switch (part) {
    case MediaEnterFullscreenButton:
    case MediaExitFullscreenButton:
        if (MediaControlFullscreenButtonElement* btn = static_cast<MediaControlFullscreenButtonElement*>(o.node())) {
            bool enterButton = btn->displayType() == MediaEnterFullscreenButton;
            wkDrawMediaUIPart(enterButton ? WKMediaUIPartFullscreenButton : WKMediaUIPartExitFullscreenButton, paintInfo.context->platformContext(), r, determineState(o));
        }
        break;
    case MediaShowClosedCaptionsButton:
    case MediaHideClosedCaptionsButton:
        if (MediaControlToggleClosedCaptionsButtonElement* btn = static_cast<MediaControlToggleClosedCaptionsButtonElement*>(o.node())) {
            bool captionsVisible = btn->displayType() == MediaHideClosedCaptionsButton;
            wkDrawMediaUIPart(captionsVisible ? WKMediaUIPartHideClosedCaptionsButton : WKMediaUIPartShowClosedCaptionsButton, paintInfo.context->platformContext(), r, determineState(o));
        }
        break;
    case MediaMuteButton:
    case MediaUnMuteButton:
        if (MediaControlMuteButtonElement* btn = static_cast<MediaControlMuteButtonElement*>(o.node())) {
            bool audioEnabled = btn->displayType() == MediaMuteButton;
            wkDrawMediaUIPart(audioEnabled ? WKMediaUIPartMuteButton : WKMediaUIPartUnMuteButton, paintInfo.context->platformContext(), r, determineState(o));
        }
        break;
    case MediaPauseButton:
    case MediaPlayButton:
        if (MediaControlPlayButtonElement* btn = static_cast<MediaControlPlayButtonElement*>(o.node())) {
            bool canPlay = btn->displayType() == MediaPlayButton;
            wkDrawMediaUIPart(canPlay ? WKMediaUIPartPlayButton : WKMediaUIPartPauseButton, paintInfo.context->platformContext(), r, determineState(o));
        }
        break;
    case MediaRewindButton:
        wkDrawMediaUIPart(WKMediaUIPartRewindButton, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaReturnToRealtimeButton:
        wkDrawMediaUIPart(WKMediaUIPartSeekToRealtimeButton, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaSeekBackButton:
        wkDrawMediaUIPart(WKMediaUIPartSeekBackButton, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaSeekForwardButton:
        wkDrawMediaUIPart(WKMediaUIPartSeekForwardButton, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaSlider: {
        if (HTMLMediaElement* mediaElement = parentMediaElement(o)) {
            FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
            wkDrawMediaSliderTrack(paintInfo.context->platformContext(), unzoomedRect, mediaElement->percentLoaded() * mediaElement->duration(), mediaElement->currentTime(), mediaElement->duration(), determineState(o));
        }
        break;
    }
    case MediaSliderThumb:
        wkDrawMediaUIPart(WKMediaUIPartTimelineSliderThumb, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaVolumeSliderContainer:
        wkDrawMediaUIPart(WKMediaUIPartVolumeSliderContainer, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaVolumeSlider:
        wkDrawMediaUIPart(WKMediaUIPartVolumeSlider, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaVolumeSliderThumb:
        wkDrawMediaUIPart(WKMediaUIPartVolumeSliderThumb, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaFullScreenVolumeSlider:
        wkDrawMediaUIPart(WKMediaUIPartFullScreenVolumeSlider, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaFullScreenVolumeSliderThumb:
        wkDrawMediaUIPart(WKMediaUIPartFullScreenVolumeSliderThumb, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaTimelineContainer:
        wkDrawMediaUIPart(WKMediaUIPartBackground, paintInfo.context->platformContext(), r, determineState(o));
        break;
    case MediaCurrentTimeDisplay:
        ASSERT_NOT_REACHED();
        break;
    case MediaTimeRemainingDisplay:
        ASSERT_NOT_REACHED();
        break;
    case MediaControlsPanel:
        ASSERT_NOT_REACHED();
    case MediaTextTrackDisplayContainer:
    case MediaTextTrackDisplay:
    case MediaClosedCaptionsContainer:
    case MediaClosedCaptionsTrackList:
        ASSERT_NOT_REACHED();
        break;
    }

    return false;
}
示例#10
0
int main(void)
{
    SYSTEMConfigPerformance(40000000);
    initLCD(); //initialize the LCD
    enableInterrupts();
    initADC(); //initialize the ADC
    initPWM(); //initialize the PWM
    initTimer3(); //initialize the timer
    TRISDbits.TRISD0 = 0;
    LATDbits.LATD0 = 0;
    initUART(); //initialize UART
    
    sendByte('M');
    
   while(1)
   {
        if(U2STAbits.URXDA)
        {
            input = U2RXREG; //saves RX reg buffer
            sendByte(input); //echos pressed key back to prompt
            sendByte(':'); //sends : to terminal prompt
        }
       
        switch(input) {
            case 'w': //forward
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 700;
                LW = 700; 
                break;
            case 'a': //left
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 700; 
                LW = 100;
                break;
            case 's': //backward
                LEFTMOTORDIRECTION1 = 1; 
                LEFTMOTORDIRECTION2 = 0;         
                RIGHTMOTORDIRECTION1 = 1;
                RIGHTMOTORDIRECTION2 = 0;
                RW = 700; 
                LW = 700;               
                break;
            case 'd': //right
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 100; 
                LW = 700;                
                break;
            case 'p':
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 0;
                LW = 0; 
                break;
        }
        
        
       startRead(0); //starts reading from ADC (POT)
       adcVal0 = waitToFinish0(); //save digital value of pot
       
       startRead(1); //starts reading from ADC (Leftmost)
       adcVal1 = waitToFinish1(); //save digital value of leftmost phototransistor
       
       startRead(2); //starts reading from ADC (Middle)
       adcVal2 = waitToFinish2(); //save digital value of middle phototransistor
       
       startRead(3); //starts reading from ADC (Rightmost)
       adcVal3 = waitToFinish3(); //save digital value of rightmost phototransistor
       
       moveCursorLCD(0,2);
       sprintf(str, "%d,%d,%d", adcVal1/10, adcVal2/10, adcVal3/10);
       printStringLCD(str);
       
       scan(); //scan three transistors
       
       moveCursorLCD(0,1);
       sprintf(str, "%d, %d, %d", L1, L2, L3);
       printStringLCD(str);
       
       determineState();
       
       switch(jason)
       {
           case followLine_detectEnd:
               followLine();
               detectEnd();
               break;
           case turnAroundJason:
               turnAround();
               break;      
       }       
   }
    
    return 0;
}
示例#11
0
bool RenderThemeChromiumWin::paintMenuListButton(RenderObject* o, const PaintInfo& i, const IntRect& r)
{
    if (!o->isBox())
        return false;

    const RenderBox* box = toRenderBox(o);
    // Take padding and border into account.  If the MenuList is smaller than
    // the size of a button, make sure to shrink it appropriately and not put
    // its x position to the left of the menulist.
    const int buttonWidth = menuListButtonWidth();
    int spacingLeft = box->borderLeft() + box->paddingLeft();
    int spacingRight = box->borderRight() + box->paddingRight();
    int spacingTop = box->borderTop() + box->paddingTop();
    int spacingBottom = box->borderBottom() + box->paddingBottom();

    int buttonX;
    if (r.maxX() - r.x() < buttonWidth)
        buttonX = r.x();
    else
        buttonX = o->style()->direction() == LTR ? r.maxX() - spacingRight - buttonWidth : r.x() + spacingLeft;

    // Compute the rectangle of the button in the destination image.
    IntRect rect(buttonX,
                 r.y() + spacingTop,
                 std::min(buttonWidth, r.maxX() - r.x()),
                 r.height() - (spacingTop + spacingBottom));

    // Get the correct theme data for a textfield and paint the menu.
    ThemePainter painter(i.context, rect);
    WebKit::WebCanvas* canvas = painter.context()->platformContext()->canvas();
    WebKit::Platform::current()->themeEngine()->paintMenuList(canvas, CP_DROPDOWNBUTTON, determineState(o), determineClassicState(o), WebKit::WebRect(painter.drawRect()));
    return false;
}
示例#12
0
文件: nvm.c 项目: aiss83/nucbit
int8u halCommonWriteToNvm(const void *data, int32u offset, int16u length)
{
    StStatus status;
    int8u state, exitState;
    int32u srcPage;
    int32u destPage;
    //Remember: NVM data storage works on 16bit quantities.
    int16u *ram = (int16u*)data;

    //The NVM data storage system cannot function if the LEFT and RIGHT
    //storage are not aligned to physical flash pages.
    assert((NVM_LEFT_PAGE%MFB_PAGE_SIZE_B)==0);
    assert((NVM_RIGHT_PAGE%MFB_PAGE_SIZE_B)==0);
    //The offset of the NVM data must be 16bit aligned.
    assert((offset&0x1)==0);
    //The length of the NVM data must be 16bit aligned.
    assert((length&0x1)==0);
    //It is illegal to write to an offset outside of NVM storage.
    assert(offset+length<NVM_DATA_SIZE_B);


    state = determineState();

    switch(state)
    {
    case 1:
    case 2:
    case 3:
    case 4:
    case 9:
    case 10:
        srcPage = NVM_LEFT_PAGE;
        destPage = NVM_RIGHT_PAGE;
        exitState = 7;
        break;
    case 5:
    case 6:
    case 7:
    case 8:
        srcPage = NVM_RIGHT_PAGE;
        destPage = NVM_LEFT_PAGE;
        exitState = 3;
        break;
    case 0:
    default:
        //Invalid state.  Default to writing to the LEFT page.  Defaulting to
        //using RIGHT as the source page is valid since the RIGHT page
        //will also be erased and therefore produce 0xFF for data values.
        state = 0;
        srcPage = NVM_RIGHT_PAGE;
        destPage = NVM_LEFT_PAGE;
        exitState = 3;
        break;
    }

    //Advance the state machine.  Starting on state 3 requires state 7 to
    //exit and starting on state 7 requires state 3 to exit.  Starting on
    //any other state requires either 3 or 7 to exit.
    //NOTE:  Refer to nvm.h for a description of the states and how the
    //       state transitions correspond to erasing, writing data, and
    //       writing mgmt values.
    while(TRUE)
    {
        switch(state)
        {
        case 0:
            //State 0 is the only state where the source page needs to be erased.
            ERASE_PAGE(srcPage);
            ERASE_PAGE(destPage);
            WRITE_DATA(destPage, srcPage, offset, length);
            WRITE_MGMT_16BITS(NVM_LEFT_PAGE+0, 0x0000);
            state=1;
            break;
        case 1:
            WRITE_MGMT_16BITS(NVM_RIGHT_PAGE+2, 0xFF00);
            state=2;
            break;
        case 2:
            WRITE_MGMT_16BITS(NVM_RIGHT_PAGE+0, 0x0000);
            state=3;
            break;
        case 3:
            if(exitState==3)
            {
                return ST_SUCCESS;
            }
            ERASE_PAGE(destPage);
            state=4;
            break;
        case 4:
            WRITE_DATA(destPage, srcPage, offset, length);
            WRITE_MGMT_16BITS(NVM_RIGHT_PAGE+0, 0xFF00);
            state=5;
            break;
        case 5:
            WRITE_MGMT_16BITS(NVM_LEFT_PAGE+2, 0xFF00);
            state=6;
            break;
        case 6:
            WRITE_MGMT_16BITS(NVM_RIGHT_PAGE+0, 0x0000);
            state=7;
            break;
        case 7:
            if(exitState==7)
            {
                return ST_SUCCESS;
            }
            ERASE_PAGE(destPage);
            state=8;
            break;
        case 8:
            WRITE_DATA(destPage, srcPage, offset, length);
            WRITE_MGMT_16BITS(NVM_LEFT_PAGE+0, 0xFF00);
            state=9;
            break;
        case 9:
            WRITE_MGMT_16BITS(NVM_RIGHT_PAGE+2, 0xFF00);
            state=10;
            break;
        case 10:
            WRITE_MGMT_16BITS(NVM_LEFT_PAGE+0, 0x0000);
            state=3;
            break;
        }
    }
}
//------------------------------------------------------------------------------
// DBRootExtentTracker constructor
//
// Mutex lock not needed in this function as it is only called from main thread
// before processing threads are spawned.
//------------------------------------------------------------------------------
DBRootExtentTracker::DBRootExtentTracker ( OID oid,
    const std::vector<int>& colWidths,
    const std::vector<BRM::EmDbRootHWMInfo_v>& dbRootHWMInfoColVec,
    unsigned int columnIdx,
    Log* logger ) :
    fOID(oid),
    fLog(logger),
    fCurrentDBRootIdx(-1),
    fEmptyOrDisabledPM(false),
    fEmptyPM(true),
    fDisabledHWM(false)
{
    const BRM::EmDbRootHWMInfo_v& emDbRootHWMInfo =
        dbRootHWMInfoColVec[columnIdx];
    int colWidth = colWidths[columnIdx];

    fBlksPerExtent = (long long)BRMWrapper::getInstance()->getExtentRows() *
        (long long)colWidth / (long long)BYTE_PER_BLOCK;

    std::vector<bool> resetState;
    for (unsigned int i=0; i<emDbRootHWMInfo.size(); i++)
    {
        resetState.push_back(false);
        DBRootExtentInfoState state = determineState(
            colWidths[columnIdx],
            emDbRootHWMInfo[i].localHWM,
            emDbRootHWMInfo[i].totalBlocks,
            emDbRootHWMInfo[i].status);

        // For a full extent...
        // check to see if any of the column HWMs are partially full, in which
        // case we consider all the columns for that DBRoot to be partially
        // full.  (This can happen if a table has columns with varying widths,
        // as the HWM may be at the last extent block for a shorter column, and
        // still have free blocks for wider columns.)
        if (state == DBROOT_EXTENT_EXTENT_BOUNDARY)
        {
            for (unsigned int kCol=0; kCol<dbRootHWMInfoColVec.size(); kCol++)
            {
                const BRM::EmDbRootHWMInfo_v& emDbRootHWMInfo2 =
                    dbRootHWMInfoColVec[kCol];
                DBRootExtentInfoState state2 = determineState(
                    colWidths[kCol],
                    emDbRootHWMInfo2[i].localHWM,
                    emDbRootHWMInfo2[i].totalBlocks,
                    emDbRootHWMInfo2[i].status);
                if (state2 == DBROOT_EXTENT_PARTIAL_EXTENT)
                {
                    state = DBROOT_EXTENT_PARTIAL_EXTENT;
                    resetState[ resetState.size()-1 ] = true;
                    break;
                }
            }
        }

        DBRootExtentInfo dbRootExtent(
            emDbRootHWMInfo[i].dbRoot,
            emDbRootHWMInfo[i].partitionNum,
            emDbRootHWMInfo[i].segmentNum,
            emDbRootHWMInfo[i].startLbid,
            emDbRootHWMInfo[i].localHWM,
            emDbRootHWMInfo[i].totalBlocks,
            state);

        fDBRootExtentList.push_back( dbRootExtent );
    }

    std::sort( fDBRootExtentList.begin(), fDBRootExtentList.end() );

    if (fLog)
    {
        // Always log this info for now; may control with debug later
        //if (fLog->isDebug(DEBUG_1))
        {
            std::ostringstream oss;
            oss << "Starting DBRoot info for OID " << fOID;
            for (unsigned int k=0; k<fDBRootExtentList.size(); k++)
            {
                oss << std::endl;
                oss << "  DBRoot-" << fDBRootExtentList[k].fDbRoot <<
                    ", part/seg/hwm/LBID/totBlks/state: "          <<
                    fDBRootExtentList[k].fPartition                <<
                    "/" << fDBRootExtentList[k].fSegment           <<
                    "/" << fDBRootExtentList[k].fLocalHwm          <<
                    "/" << fDBRootExtentList[k].fStartLbid         <<
                    "/" << fDBRootExtentList[k].fDBRootTotalBlocks <<
                    "/" << stateStrings[ fDBRootExtentList[k].fState ];
                if (resetState[k])
                    oss << ".";
            }
            fLog->logMsg( oss.str(), MSGLVL_INFO2 );
        }
    }
}
void TrafficLightDetector::brightnessDetect(const cv::Mat &input) {

  cv::Mat tmpImage;
  input.copyTo(tmpImage);

  /* contrast correction */
  cv::Mat tmp;
  cvtColor(tmpImage, tmp, CV_BGR2HSV);
  std::vector<cv::Mat> hsv_channel;
  split(tmp, hsv_channel);

  float correction_factor = 10.0;
  uchar lut[256];
  for (int i=0; i<256; i++) {
    lut[i] = 255.0 / (1 + exp(-correction_factor*(i-128)/255));
  }

  LUT(hsv_channel[2], cv::Mat(cv::Size(256, 1), CV_8U, lut), hsv_channel[2]);
  merge(hsv_channel, tmp);
  cvtColor(tmp, tmpImage, CV_HSV2BGR);

  for (int i = 0; i < static_cast<int>(contexts.size()); i++) {
    Context context = contexts.at(i);

    if (context.topLeft.x > context.botRight.x)
      continue;

    /* extract region of interest from input image */
    cv::Mat roi = tmpImage(cv::Rect(context.topLeft, context.botRight));

    /* convert color space (BGR -> HSV) */
    cv::Mat roi_HSV;
    cvtColor(roi, roi_HSV, CV_BGR2HSV);

    /* search the place where traffic signals seem to be */
    cv::Mat    signalMask    = signalDetect_inROI(roi_HSV, input.clone(), context.lampRadius, context.topLeft);

    /* detect which color is dominant */
    cv::Mat extracted_HSV;
    roi.copyTo(extracted_HSV, signalMask);

    // extracted_HSV.copyTo(roi);
    // imshow("tmpImage", tmpImage);
    // waitKey(5);

    cvtColor(extracted_HSV, extracted_HSV, CV_BGR2HSV);

    int red_pixNum    = 0;
    int yellow_pixNum = 0;
    int green_pixNum  = 0;
    int valid_pixNum  = 0;
    for (int y=0; y<extracted_HSV.rows; y++)
      {
        for (int x=0; x<extracted_HSV.cols; x++)
          {
            /* extract H, V value from pixel */
            double hue = Actual_Hue(extracted_HSV.at<cv::Vec3b>(y, x)[0]);
            uchar  val = extracted_HSV.at<cv::Vec3b>(y, x)[2];

            if (val == 0) {
              continue;         // this is masked pixel
            }
            valid_pixNum++;

            /* search which color is actually bright */
            if (IsRange(thSet.Red.Hue.lower, thSet.Red.Hue.upper, hue)) {
              red_pixNum++;
            }

            if (IsRange(thSet.Yellow.Hue.lower, thSet.Yellow.Hue.upper, hue)) {
              yellow_pixNum++;
            }

            if (IsRange(thSet.Green.Hue.lower, thSet.Green.Hue.upper, hue)) {
              green_pixNum++;
            }
          }
    }

    // std::cout << "(green, yellow, red) / valid = (" << green_pixNum << ", " << yellow_pixNum << ", " << red_pixNum << ") / " << valid_pixNum <<std::endl;

    bool isRed_bright;
    bool isYellow_bright;
    bool isGreen_bright;

    if (valid_pixNum > 0) {
      isRed_bright    = ( ((double)red_pixNum / valid_pixNum)    > 0.45) ? true : false; // detect red a little largely
      isYellow_bright = ( ((double)yellow_pixNum / valid_pixNum) > 0.5) ? true : false;
      isGreen_bright  = ( ((double)green_pixNum / valid_pixNum)  > 0.5) ? true : false;
    } else {
      isRed_bright    = false;
      isYellow_bright = false;
      isGreen_bright  = false;
    }

    int currentLightsCode = getCurrentLightsCode(isRed_bright, isYellow_bright, isGreen_bright);
    contexts.at(i).lightState = determineState(contexts.at(i).lightState, currentLightsCode, &(contexts.at(i).stateJudgeCount));

    roi.setTo(cv::Scalar(0));
  }
}
示例#15
0
int ResilienceLow::determineState(){
   double dd = strain - Cstrain; 
   if (fabs(dd)<1.0e-14) {
      stress = Cstress;
	  tangent = Ctangent;
       return mode;
   }
   switch (mode){
   // 第一次计算

// mode1曲线1,3
	case 1:
		if(dd>=0){
			if(strain>DY){        
                mode=2;
				determineState( );}
            else
                stress=Ke*strain;
		}
		else {
			if(strain<-DY){
                mode=4;
				determineState( );}
            else
                stress = Ke*strain;
         }
		break; 
        
// 曲线1,2
	case 2:
		if(dd>=0){
			if(strain>DPmax){
                mode=6;
				determineState( );}
            else
                stress=(Pmax-PY)/(DPmax-DY)*(strain-DY)+PY;
		}
		else{
            strainRFMode2=Cstrain;
            stressRFMode2=Cstress;
            mode=3;
            determineState( );
		}
		break;
       
// 曲线3,5  mode3
	case 3:
		if(dd>=0)
			{
				if(strain>strainRFMode2)
				{
                mode=2;
				determineState( );
				}
				else
                stress=(stressRFMode2+PY)/(strainRFMode2+DY)*(strain-strainRFMode2)+stressRFMode2;
			}
        else
		{
			if(strain<-DY)
			{
                mode=4;
				determineState( );
			}
            else
                stress=(stressRFMode2+PY)/(strainRFMode2+DY)*(strain-strainRFMode2)+stressRFMode2;
		}
        break;
        
// mode4,曲线3,4
	case 4:
		if(dd>=0)
		{
            strainRFMode4=Cstrain;
            stressRFMode4=Cstress;
            mode=5;
			determineState( );
		}           
        else
		{
			if(strain<-DPmax)
			{
                mode=11;
                determineState( ); 
			}
            else
                stress=(Pmax-PY)/(DPmax-DY)*(strain+DPmax)-Pmax;
		}
		break;
        
        // mode5,曲线4,5
	case 5:
        if(dd>=0)
		{
            if(strain>DY)
			{mode=2;
             determineState( );}
            else
                stress=(stressRFMode4-PY)/(strainRFMode4-DY)*(strain-DY)+PY;
		}
        else
		{
			if(strain<strainRFMode4)
			{mode=4;
			determineState( );}
            else
                stress=(stressRFMode4-PY)/(strainRFMode4-DY)*(strain-DY)+PY;
		}
        break;
        // 6 曲线6,7
	case 6:
		if(dd>=0)
		{stress=-Kd*(strain-DPmax)+Pmax;
			if(strain>Di)
			{Di=strain;}
			 if(stress<0.55*Pmax)
			 { stress=0.55*Pmax;}
		}
		else
		{
            strainRFMode6=Cstrain;
            stressRFMode6=Cstress;
			Flag=6;
            mode=7;
			determineState( );
		}
        break;
        
        // mode 7 曲线7,8

	case 7:
		if(strain>0.45*Pmax/Kd+DPmax)
			{ Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
			Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
        else
			{Kri=(0.5*Pmax-Kd*(Di-DPmax))/(Di-0.5*Pmax/Ke);
			Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
		if(Kri<0)
		{   Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
            Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di); }
        if(Kui>Ke||Kui<0)
		{Kui=Ke;}

		if(Flag==6)
			{stress=Kui*(strain-strainRFMode6)+stressRFMode6;
				if(dd>=0){
					if(strain>strainRFMode6){
                         mode=6;
						 determineState( );}}
				else 
				{if(stress<Kri*(strain+0.5*Pmax/Ke)-0.5*Pmax)
				{ mode=8;
                     determineState( ); }
					}}
      else 
		 { stress=Kui*(strain-strainRFMode8)+stressRFMode8;
			if(dd>=0){
                  if(stress>Kri*(strain-0.5*Pmax/Ke)+0.5*Pmax)
				  { mode=10;
				  determineState( );}
				  stressRFMode6=-Kd*(strainRFMode6-DPmax)+Pmax;
				if(stressRFMode6<0.55*Pmax)
					stressRFMode6=0.55*Pmax;
				  if(strain>strainRFMode6||stress>stressRFMode6){
                         mode=6;
                         determineState( );
				  }}
              else
			  { if(strain<strainRFMode8){
                     mode=8;
                     determineState( );
			}}}
 break;


	case 8:
			if(dd>=0)
			{		strainRFMode8=Cstrain;
					stressRFMode8=Cstress;
					Flag=8;
					mode=7;
					determineState(); }
				else
				{   if(strain<-0.45*Pmax/Kd-DPmax){
					  Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
					  Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
				else{
					  Kri=(0.5*Pmax-Kd*(Di-DPmax))/(Di-0.5*Pmax/Ke);
					  Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);
				}
				if(Kri<0){
					Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
					Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);
				}
					stress=Kri*(strain+0.5*Pmax/Ke)-0.5*Pmax;
			 if(strain<-DPmax&&stress<-Kd*(strain+DPmax)-Pmax)
			 {mode=11;
			 determineState( );}}

	break;

case 9:
		if(strain<-0.45*Pmax/Kd-DPmax){
              Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
			  Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
		else{
              Kri=(0.5*Pmax-Kd*(Di-DPmax))/(Di-0.5*Pmax/Ke);
              Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
		if(Kri<0){
            Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
            Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
            if(Kui>Ke||Kui<0)
			{  Kui=Ke;}

			if(Flag==11){
                stress=Kui*(strain-strainRFMode11)+stressRFMode11;
				if(dd<0){
					if(strain<strainRFMode11){
                        mode=11;
                        determineState( );
					}}
                else
				{if(stress>Kri*(strain-0.5*Pmax/Ke)+0.5*Pmax){
                        mode=10;
                        determineState( );
					}}}
            else
			{stress=Kui*(strain-strainRFMode10)+stressRFMode10;
             if(dd>=0){
					if(strain>strainRFMode10){
                        mode=10;
                        determineState( );
					}}
				else{
                    if(stress<Kri*(strain+0.5*Pmax/Ke)-0.5*Pmax)
					{  mode=8;
                          determineState( );}
					stressRFMode11=-Kd*(strainRFMode11+DPmax)-Pmax;
					if(stressRFMode11>-0.55*Pmax)
					stressRFMode11=-0.55*Pmax;
					if(strain<strainRFMode11||stress<stressRFMode11){
                        mode=11;
						determineState( );}}}
break;

case 10:
		if(dd>=0)
		{if(strain>0.45*Pmax/Kd+DPmax){
              Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
			  Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);}
            else
			{ Kri=(0.5*Pmax-Kd*(Di-DPmax))/(Di-0.5*Pmax/Ke);
              Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);
		}
		if(Kri<0){
            Kri=0.05*Pmax/(Di-0.5*Pmax/Ke);
            Kui=(1.25*Pmax-Kd*(Di-DPmax))/(0.5*Pmax/Ke-0.25*Pmax/Kri+Di);
		}
            stress=Kri*(strain-0.5*Pmax/Ke)+0.5*Pmax;
            
            if(strain>DPmax&&stress>-Kd*(strain-DPmax)+Pmax)
			{mode=6;
                 determineState();          
			}}
        else
		{	strainRFMode10=Cstrain;
            stressRFMode10=Cstress;
            Flag=10;
            mode=9;
			determineState();}

break;

case 11:
        if(dd>=0)
		{
            strainRFMode11=Cstrain;
            stressRFMode11=Cstress;
            Flag=11;
			 mode=9;
			determineState();
		}
        else
		{
           stress=-Kd*(strain+DPmax)-Pmax;
		   if(fabs(strain)>Di){
                Di=fabs(strain);
		   }
		   if(stress>-0.55*Pmax){
                stress=-0.55*Pmax;
                }}
		break;
  } 
  return mode;
};