Пример #1
0
void SMaskEdit::SetMaskedText(LPCTSTR lpszMaskedText, int nPos, BOOL bUpdateWindow)
{
    int nMaskedTextLength = (int)_tcslen(lpszMaskedText);

    m_strWindowText = m_strWindowText.Left(nPos);

    int nIndex = 0;
    for (; (nPos <  m_strLiteral.GetLength()) && (nIndex < nMaskedTextLength) ; nPos++)
    {
        TCHAR uChar = lpszMaskedText[nIndex];

        if (IsPromptPos(nPos) && ((uChar == m_chPrompt) || ProcessMask(uChar, nPos)))
        {
            m_strWindowText += (TCHAR)uChar;
            nIndex ++;
        }
        else
        {
            m_strWindowText += m_strLiteral[nPos];
        }
    }

    if (bUpdateWindow)
    {
        SetMaskState();
    }
    else
    {
        CorrectWindowText();
    }
}
void FillHoleShiftMap::ComputeShiftMap2(IplImage* input, IplImage* saliency, CvSize output, CvSize shiftSize, MaskShift* maskShift)
{
	try{
		_input = input;
		_shiftSize = shiftSize;

		IplImage* inputGradient = cvCloneImage(input);
		cvSobel(input, inputGradient, 1, 1);

		// first processing the mask (including neighborhood)	
		// ProcessMask();
		ProcessMask(maskShift);

		// setup data cost & smooth cost for masked data
		ForDataFH2 dataCost;
		dataCost.mask = maskShift;
		 
		IplImage* maskDataGradient = cvCloneImage(_maskData);
		cvSobel(_maskData, maskDataGradient, 1, 1);
		 
		dataCost.pointMapping = _pointMapping;
		dataCost.shiftSize = shiftSize;
		dataCost.saliency = saliency;
		dataCost.inputSize = cvSize(input->width, input->height);
		dataCost.maskNeighbor = _maskNeighbor;
		dataCost.inputGradient = inputGradient;
		dataCost.input = input;
		_gcGeneral->setDataCost(&dataFunctionFH2, &dataCost);

		// setup smooth cost
		ForSmoothFH smoothCost;
		smoothCost.input = input;
		smoothCost.inputGradient = inputGradient;
		smoothCost.inputSize = cvSize(input->width, input->height);
		smoothCost.pointMapping = _pointMapping;
		smoothCost.shiftSize = shiftSize;
		_gcGeneral->setSmoothCost(&smoothFunctionFH, &smoothCost);

		printf("\nBefore optimization energy is %d \n", _gcGeneral->compute_energy());
		//gc->swap(20);
		_gcGeneral->expansion(2);// run expansion for 2 iterations. For swap use gc->swap(num_iterations);
		printf("\nAfter optimization energy is %d \n", _gcGeneral->compute_energy()); 
	}
	catch (GCException e){
		e.Report();
	}
}
Пример #3
0
BOOL SMaskEdit::CheckChar(TCHAR& nChar, int nPos)
{
    // do not use mask
    if (!CanUseMask())
        return FALSE;

    // control character, OK
    if (!IsPrintChar(nChar))
        return TRUE;

    // make sure the string is not longer than the mask
    if (nPos >= m_strMask.GetLength())
        return FALSE;

    if (!IsPromptPos(nPos))
        return FALSE;

    return ProcessMask(nChar, nPos);
}
Пример #4
0
void SMaskEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    if (!CanUseMask())
    {
        __super::OnKeyDown(nChar, nRepCnt, nFlags);
        return;
    }

    BOOL bShift = (::GetKeyState(VK_SHIFT) < 0);
    BOOL bCtrl  = (::GetKeyState(VK_CONTROL) < 0);

    switch (nChar)
    {
    case VK_UP:
    case VK_LEFT:
    case VK_HOME:
        {
            __super::OnKeyDown(nChar, nRepCnt, nFlags);

            GetMaskState(FALSE);

            int nStartChar = m_nStartChar;
            CorrectPosition(nStartChar, FALSE);

            if (m_nStartChar < nStartChar)
            {
                m_nStartChar = nStartChar;

                if (!bShift)
                    m_nEndChar = nStartChar;
            }

            SetMaskState();
        }
        return;

    case VK_DOWN:
    case VK_RIGHT:
    case VK_END:
        {
            __super::OnKeyDown(nChar, nRepCnt, nFlags);

            GetMaskState(FALSE);

            int iEndChar = m_nEndChar;
            CorrectPosition(iEndChar);

            if (m_nEndChar > iEndChar)
            {
                m_nEndChar = iEndChar;

                if (!bShift)
                    m_nStartChar = iEndChar;
            }

            SetMaskState();
        }
        return;

    case VK_INSERT:
        {
            if (bCtrl)
            {
                MaskCopy();
            }
            else if (bShift)
            {
                MaskPaste();
            }
            else
            {
                m_bOverType = !m_bOverType; // set the type-over flag
            }
        }
        return;

    case VK_DELETE:
        {
            GetMaskState();

            if (m_nStartChar == m_nEndChar)
            {
                m_nEndChar = m_nStartChar +1;
            }
            else if (bShift)
            {
                MaskCopy();
            }

            MaskDeleteSel();
            SetMaskState();
        }
        return;

    case VK_SPACE:
        {
            GetMaskState();

            if (!PosInRange(m_nStartChar) || !IsPromptPos(m_nStartChar))
            {
                NotifyPosNotInRange();
                return;
            }

            TCHAR chSpace = _T(' ');

            if (!ProcessMask(chSpace, m_nStartChar))
                chSpace = m_chPrompt;

            ProcessChar(chSpace);

            SetMaskState();
        }
        return;

    case VK_BACK:
        {
            GetMaskState(FALSE);

            if (((m_nStartChar > 0) || (m_nStartChar == 0 && m_nEndChar != 0))  && (m_nStartChar <= m_strLiteral.GetLength()))
            {
                if (m_nStartChar == m_nEndChar)
                {
                    m_nStartChar--;
                    CorrectPosition(m_nStartChar, FALSE);

                    if (m_bOverType && PosInRange(m_nStartChar))
                    {
                        m_strWindowText.SetAt(m_nStartChar, m_strDefault[m_nStartChar]);
                        m_nEndChar = m_nStartChar;
                    }
                }

                MaskDeleteSel();
                SetMaskState();
            }
            else
            {
                NotifyPosNotInRange();
            }
        }
        return;
    }

    __super::OnKeyDown(nChar, nRepCnt, nFlags);
}
Пример #5
0
/** Read command line args. */
Cpptraj::Mode Cpptraj::ProcessCmdLineArgs(int argc, char** argv) {
  bool hasInput = false;
  bool interactive = false;
  Sarray inputFiles;
  Sarray topFiles;
  Sarray trajinFiles;
  Sarray trajoutFiles;
  Sarray refFiles;
  for (int i = 1; i < argc; i++) {
    std::string arg(argv[i]);
    if ( arg == "--help" || arg == "-h" ) {
      // --help, -help: Print usage and exit
      SetWorldSilent(true);
      Usage();
      return QUIT;
    }
    if ( arg == "-V" || arg == "--version" ) {
      // -V, --version: Print version number and exit
      SetWorldSilent( true );
      loudPrintf("CPPTRAJ: Version %s\n", CPPTRAJ_VERSION_STRING);
      return QUIT;
    }
    if ( arg == "--internal-version" ) {
      // --internal-version: Print internal version number and quit.
      SetWorldSilent( true );
      loudPrintf("CPPTRAJ: Internal version # %s\n", CPPTRAJ_INTERNAL_VERSION);
      return QUIT;
    }
    if ( arg == "--defines" ) {
      // --defines: Print information on compiler defines used and exit
      SetWorldSilent( true );
      loudPrintf("Compiled with:");
      loudPrintf("%s\n", Cpptraj::Defines().c_str());
      return QUIT;
    }
    if (arg == "-tl") {
      // -tl: Trajectory length
      if (topFiles.empty()) {
        mprinterr("Error: No topology file specified.\n");
        return ERROR;
      }
      SetWorldSilent( true );
      if (State_.TrajLength( topFiles[0], trajinFiles )) return ERROR;
      return QUIT;
    }
    if ( arg == "--interactive" )
      interactive = true;
    else if ( arg == "-debug" && i+1 != argc) {
      // -debug: Set overall debug level
      ArgList dbgarg( argv[++i] );
      State_.SetListDebug( dbgarg );
    } else if ( arg == "--log" && i+1 != argc)
      // --log: Set up log file for interactive mode
      logfilename_ = argv[++i];
    else if ( arg == "-p" && i+1 != argc) {
      // -p: Topology file
      topFiles.push_back( argv[++i] );
    } else if ( arg == "-y" && i+1 != argc) {
      // -y: Trajectory file in
      trajinFiles.push_back( argv[++i] );
    } else if ( arg == "-x" && i+1 != argc) {
      // -x: Trajectory file out
      trajoutFiles.push_back( argv[++i] );
    } else if ( arg == "-c" && i+1 != argc) {
      // -c: Reference file
      refFiles.push_back( argv[++i] );
    } else if (arg == "-i" && i+1 != argc) {
      // -i: Input file(s)
      inputFiles.push_back( argv[++i] );
    } else if (arg == "-ms" && i+1 != argc) {
      // -ms: Parse mask string, print selected atom #s
      if (ProcessMask( topFiles, refFiles, std::string(argv[++i]), false, false )) return ERROR;
      return QUIT;
    } else if (arg == "-mr" && i+1 != argc) {
      // -mr: Parse mask string, print selected res #s
      if (ProcessMask( topFiles, refFiles, std::string(argv[++i]), false, true )) return ERROR;
      return QUIT;
    } else if (arg == "--mask" && i+1 != argc) {
      // --mask: Parse mask string, print selected atom details
      if (ProcessMask( topFiles, refFiles, std::string(argv[++i]), true, false )) return ERROR;
      return QUIT;
    } else if (arg == "--resmask" && i+1 != argc) {
      // --resmask: Parse mask string, print selected residue details
      if (ProcessMask( topFiles, refFiles, std::string(argv[++i]), true, true )) return ERROR;
      return QUIT;
    } else if ( i == 1 ) {
      // For backwards compatibility with PTRAJ; Position 1 = TOP file
      topFiles.push_back( argv[i] );
    } else if ( i == 2 ) {
      // For backwards compatibility with PTRAJ; Position 2 = INPUT file
      inputFiles.push_back( argv[i] );
    } else {
      // Unrecognized
      mprintf("  Unrecognized input on command line: %i: %s\n", i,argv[i]);
      Usage();
      return ERROR;
    }
  }
  Cpptraj::Intro();
  // Add all topology files specified on command line.
  for (Sarray::const_iterator topFilename = topFiles.begin();
                              topFilename != topFiles.end();
                              ++topFilename)
    if (State_.AddTopology( *topFilename, ArgList() )) return ERROR;
  // Add all reference trajectories specified on command line.
  for (Sarray::const_iterator refName = refFiles.begin();
                              refName != refFiles.end();
                              ++refName)
    if (State_.AddReference( *refName )) return ERROR;
  // Add all input trajectories specified on command line.
  for (Sarray::const_iterator trajinName = trajinFiles.begin();
                              trajinName != trajinFiles.end();
                              ++trajinName)
    if (State_.AddTrajin( *trajinName )) return ERROR;
  // Add all output trajectories specified on command line.
  if (!trajoutFiles.empty()) {
    hasInput = true; // This allows direct traj conversion with no other input 
    for (Sarray::const_iterator trajoutName = trajoutFiles.begin();
                                trajoutName != trajoutFiles.end();
                                ++trajoutName)
      if (State_.AddOutputTrajectory( *trajoutName )) return ERROR;
  }
  // Process all input files specified on command line.
  if ( !inputFiles.empty() ) {
    hasInput = true;
    for (Sarray::const_iterator inputFilename = inputFiles.begin();
                                inputFilename != inputFiles.end();
                                ++inputFilename)
    {
      Command::RetType c_err = Command::ProcessInput( State_, *inputFilename );
      if (c_err == Command::C_ERR && State_.ExitOnError()) return ERROR;
      if (c_err == Command::C_QUIT) return QUIT;
    }
  }
  // Determine whether to enter interactive mode
  if (!hasInput || interactive) {
    // Test if input is really from a console
    if ( isatty(fileno(stdin)) )
      return INTERACTIVE;
    else {
      // "" means read from STDIN
      Command::RetType c_err = Command::ProcessInput( State_, "" ); 
      if (c_err == Command::C_ERR && State_.ExitOnError()) return ERROR;
      if (c_err == Command::C_QUIT) return QUIT;
    }
  }
  return BATCH;
}