void ccFastMarchingForNormsDirection::initTrialCells() { //we expect at most one 'ACTIVE' cell (i.e. the current seed) size_t seedCount = m_activeCells.size(); assert(seedCount <= 1); if (seedCount == 1) { unsigned index = m_activeCells.front(); DirectionCell* seedCell = static_cast<DirectionCell*>(m_theGrid[index]); assert(seedCell != NULL); assert(seedCell->T == 0); assert(seedCell->signConfidence == 1); //add all its neighbour cells to the TRIAL set for (unsigned i=0; i<m_numberOfNeighbours; ++i) { unsigned nIndex = index + m_neighboursIndexShift[i]; DirectionCell* nCell = static_cast<DirectionCell*>(m_theGrid[nIndex]); //if the neighbor exists (it shouldn't be in the TRIAL or ACTIVE sets) if (nCell/* && nCell->state == DirectionCell::FAR_CELL*/) { assert(nCell->state == DirectionCell::FAR_CELL); addTrialCell(nIndex); //compute its approximate arrival time nCell->T = seedCell->T + m_neighboursDistance[i] * computeTCoefApprox(seedCell,nCell); } } } }
void ccFastMarchingForNormsDirection::initTrialCells() { DirectionCell *aCell,*nCell; unsigned i,j,index,nIndex; for (j=0;j<activeCells.size();++j) { index = activeCells[j]; aCell = (DirectionCell*)theGrid[index]; assert(aCell != NULL); aCell->v = 1.0; for (i=0;i<CC_FM_NUMBER_OF_NEIGHBOURS;++i) { nIndex = index + neighboursIndexShift[i]; //pointeur vers la cellule voisine nCell = (DirectionCell*)theGrid[nIndex]; //si elle est définie if (nCell) { //et si elle n'est pas encore dans un groupe if (nCell->state==CCLib::FastMarching::Cell::FAR_CELL) { nCell->state = CCLib::FastMarching::Cell::TRIAL_CELL; nCell->T = neighboursDistance[i]*computeTCoefApprox(aCell,nCell); //on doit s'occuper de leur normales !!! float ps = CCVector3::vdot(aCell->N,nCell->N); if (ps<0.0) { nCell->N[0]=-nCell->N[0]; nCell->N[1]=-nCell->N[1]; nCell->N[2]=-nCell->N[2]; } nCell->v = 1.0; nCell->treated = true; addTrialCell(nIndex,nCell->T); //Console::print("cell %i added to TRIAL\n",nIndex); } } } } }
int ccFastMarchingForNormsDirection::step() { if (!m_initialized) return -1; //get 'earliest' cell unsigned minTCellIndex = getNearestTrialCell(); if (minTCellIndex == 0) return 0; CCLib::FastMarching::Cell* minTCell = m_theGrid[minTCellIndex]; assert(minTCell && minTCell->state != DirectionCell::ACTIVE_CELL); if (minTCell->T < Cell::T_INF()) { #ifdef QT_DEBUG if (s_cellIndex == 0) { //process seed cells first! for (size_t i=0; i<m_activeCells.size(); ++i) static_cast<DirectionCell*>(m_theGrid[m_activeCells[i]])->scalar = static_cast<float>(0); s_cellIndex++; } static_cast<DirectionCell*>(minTCell)->scalar = static_cast<float>(s_cellIndex++); #endif //resolve the cell orientation resolveCellOrientation(minTCellIndex); //we add this cell to the "ACTIVE" set addActiveCell(minTCellIndex); //add its neighbors to the TRIAL set for (unsigned i=0;i<m_numberOfNeighbours;++i) { //get neighbor cell unsigned nIndex = minTCellIndex + m_neighboursIndexShift[i]; CCLib::FastMarching::Cell* nCell = m_theGrid[nIndex]; if (nCell) { //if it' not yet a TRIAL cell if (nCell->state == DirectionCell::FAR_CELL) { nCell->T = computeT(nIndex); addTrialCell(nIndex); } //otherwise we must update it's arrival time else if (nCell->state == DirectionCell::TRIAL_CELL) { const float& t_old = nCell->T; float t_new = computeT(nIndex); if (t_new < t_old) nCell->T = t_new; } } } } else { addIgnoredCell(minTCellIndex); } return 1; }
int ccFastMarchingForNormsDirection::step() { if (!initialized) { //printf("Not yet initialized !"); return -1; } unsigned minTCellIndex = getNearestTrialCell(); if (minTCellIndex==0) { //fl_alert("No more trial cells !"); return 0; } //printf("minTCellIndex=%i\n",minTCellIndex); CCLib::FastMarching::Cell* minTCell = theGrid[minTCellIndex]; assert(minTCell != NULL); assert(minTCell->state != CCLib::FastMarching::Cell::ACTIVE_CELL); if (minTCell->T < FM_INF) { //on rajoute cette cellule au groupe des cellules "ACTIVE" minTCell->state = CCLib::FastMarching::Cell::ACTIVE_CELL; activeCells.push_back(minTCellIndex); //printf("Cell %i added to ACTIVE\n",minTCellIndex); //fprintf(fp,"%f %f %f\n",((DirectionCell*)minTCell)->f,minTCell->T,(minTCell->T-lastT)/cellSize); lastT = minTCell->T; //on doit rajouter ses voisines au groupe TRIAL unsigned nIndex; CCLib::FastMarching::Cell* nCell; for (int i=0;i<CC_FM_NUMBER_OF_NEIGHBOURS;++i) { nIndex = minTCellIndex + neighboursIndexShift[i]; //pointeur vers la cellule voisine nCell = theGrid[nIndex]; //si elle est définie if (nCell) { //et si elle n'est pas encore dans un groupe, on la rajoute if (nCell->state==CCLib::FastMarching::Cell::FAR_CELL) { nCell->state = CCLib::FastMarching::Cell::TRIAL_CELL; nCell->T = computeT(nIndex); addTrialCell(nIndex,nCell->T); //Console::print("Cell %i added to TRIAL\n",nIndex); } else if (nCell->state == CCLib::FastMarching::Cell::TRIAL_CELL) //sinon, il faut recaculer T { float t_old = nCell->T; float t_new = computeT(nIndex); if (t_new<t_old) nCell->T = t_new; } } } } return 1; }
int FastMarchingForFacetExtraction::step() { if (!m_initialized) return -1; //get 'earliest' cell unsigned minTCellIndex = getNearestTrialCell(); if (minTCellIndex == 0) return 0; CCLib::FastMarching::Cell* minTCell = m_theGrid[minTCellIndex]; assert(minTCell && minTCell->state != PlanarCell::ACTIVE_CELL); if (minTCell->T < Cell::T_INF()) { assert(m_currentFacetPoints); unsigned sizeBefore = m_currentFacetPoints->size(); //check if we can add the cell to the current "ACTIVE" set ScalarType error = addCellToCurrentFacet(minTCellIndex); if (error >= 0) { if (error > m_maxError) { //resulting error would be too high m_currentFacetPoints->resize(sizeBefore); //we leave the cell as is (in the EMPTY state) //so that we won't look at it again! addIgnoredCell(minTCellIndex); } else { m_currentFacetError = error; //add the cell to the "ACTIVE" set addActiveCell(minTCellIndex); //add its neighbors to the TRIAL set for (unsigned i=0; i<m_numberOfNeighbours; ++i) { //get neighbor cell unsigned nIndex = minTCellIndex + m_neighboursIndexShift[i]; CCLib::FastMarching::Cell* nCell = m_theGrid[nIndex]; if (nCell) { //if it' not yet a TRIAL cell if (nCell->state == PlanarCell::FAR_CELL) { nCell->T = computeT(nIndex); addTrialCell(nIndex); } //otherwise we must update it's arrival time else if (nCell->state == PlanarCell::TRIAL_CELL) { const float& t_old = nCell->T; float t_new = computeT(nIndex); if (t_new < t_old) nCell->T = t_new; } } } } } else { //an error occurred return -1; } } else { addIgnoredCell(minTCellIndex); } return 1; }