// Extend the sequence by finding a consensus right-ward extension base void BWTTraverse::extendRight(const unsigned int len, std::string& str, bool_vec& visited, const BWT* pBWT, const BWT* pRevBWT, bool isReverse) { // Extract the last len characters unsigned int overlapLen = len - 1; // Initialize the range for str BWTIntervalPair ranges = BWTAlgorithms::findIntervalPair(pBWT, pRevBWT, str); bool done = false; while(!done) { AlphaCount ext_counts = BWTAlgorithms::getExtCount(ranges.interval[1], pRevBWT); if(ext_counts.hasUniqueDNAChar()) { char b = ext_counts.getUniqueDNAChar(); // There is a unique extension from the seed sequence to B // Ensure that the reverse is true and that the sequence we are extending to, extends to this one std::string joined = str + b; std::string back_search = suffix(joined, len); // Get the count of bases back to the ending sequence of seed // We do this in the opposite direction of extension AlphaCount back_count = BWTAlgorithms::calculateExactExtensions(overlapLen, reverse(back_search), pRevBWT, pBWT); if(back_count.hasUniqueDNAChar()) { // Assert back is the character we are expecting assert(back_count.getUniqueDNAChar() == str[str.length() - len]); str = joined; // mark the newly visited l-mers if(!isReverse) { markVisited(back_search, visited, pBWT); } else { markVisited(reverse(back_search), visited, pRevBWT); } BWTAlgorithms::updateBothR(ranges, b, pRevBWT); } else { done = true; } } else { done = true; } } }
boost::optional<ConfigTree> ConfigTree:: getConfSubtreeOptional(std::string const& root) const { checkUnique(root); if (auto subtree = _tree->get_child_optional(root)) { markVisited(root, Attr::TAG, false); return ConfigTree(*subtree, *this, root); } else { markVisited(root, Attr::TAG, true); return boost::none; } }
void markVisited (tGraph ** pGraph, char ** pVisited, int pId, char ** pOrder) { int i; int SizeAdj = (*pGraph)->nodesList[pId]->size; int IdNodeAdj; if ((*pVisited)[pId] == 0) { (*pVisited)[pId] = 1; for (i=0; (*pOrder)[i]!=0 ; i++){} (*pOrder)[i] = (*pGraph)->nodesList[pId]->name; i=0; while (i<SizeAdj) { IdNodeAdj = (*pGraph)->nodesList[pId]->adjList[i]->id; if ((*pVisited)[IdNodeAdj] == 0) { (*pVisited)[IdNodeAdj] = 1; for (i=0; (*pOrder)[i]!=0 ; i++){} (*pOrder)[i] = (*pGraph)->nodesList[IdNodeAdj]->name; } i++; } markVisited (&(*pGraph), &(*pVisited), IdNodeAdj, &(*pOrder)); } }
ALWAYS_INLINE bool DataWalker::visitTypedValue(TypedValue rval, DataFeature& features, PointerSet& visited, PointerMap* seenArrs) const { if (isRefType(rval.m_type)) { if (rval.m_data.pref->isReferenced()) { if (markVisited(rval.m_data.pref, features, visited)) { // Don't recurse forever; we already went down this path, and // stop the walk if we've already got everything we need. return canStopWalk(features); } // Right now consider it circular even if the referenced variant // only showed up in one spot. This could be revisted later. features.isCircular = true; if (canStopWalk(features)) return true; } rval = *rval.m_data.pref->cell(); } if (rval.m_type == KindOfObject) { features.hasObjectOrResource = true; traverseData(rval.m_data.pobj, features, visited); } else if (isArrayLikeType(rval.m_type)) { traverseData(rval.m_data.parr, features, visited, seenArrs); } else if (rval.m_type == KindOfResource) { features.hasObjectOrResource = true; } return canStopWalk(features); }
void DataWalker::traverseData(ArrayData* data, DataFeature& features, PointerSet& visited) const { for (ArrayIter iter(data); iter; ++iter) { const Variant& var = iter.secondRef(); if (var.isReferenced()) { Variant *pvar = var.getRefData(); if (markVisited(pvar, features, visited)) { if (canStopWalk(features)) return; continue; // don't recurse forever; we already went down this path } // Right now consider it circular even if the referenced variant only // showed up in one spot. This could be revisted later. features.isCircular = true; if (canStopWalk(features)) return; } auto const type = var.getType(); // cheap enough, do it always features.hasRefCountReference = isRefcountedType(type); if (type == KindOfObject) { features.hasObjectOrResource = true; traverseData(var.getObjectData(), features, visited); } else if (isArrayType(type)) { traverseData(var.getArrayData(), features, visited); } else if (type == KindOfResource) { features.hasObjectOrResource = true; } if (canStopWalk(features)) return; } }
void ConfigTree::ignoreConfParam(const std::string ¶m) const { checkUnique(param); // if not found, peek only bool peek_only = _tree->find(param) == _tree->not_found(); markVisited(param, Attr::TAG, peek_only); }
void DataWalker::traverseData( ObjectData* data, DataFeature& features, PointerSet& visited) const { objectFeature(data, features); if (markVisited(data, features, visited)) { return; // avoid infinite recursion } if (canStopWalk(features)) return; if (data->isCollection()) { auto const arr = collections::asArray(data); if (arr) { traverseData(arr, features, visited); return; } assertx(data->collectionType() == CollectionType::Pair); auto const pair = static_cast<c_Pair*>(data); visitTypedValue(*pair->get(0), features, visited); visitTypedValue(*pair->get(1), features, visited); return; } IteratePropMemOrderNoInc( data, [&](Slot slot, const Class::Prop& prop, tv_rval val) { visitTypedValue(val.tv(), features, visited); }, [&](Cell key_tv, TypedValue val) { visitTypedValue(val, features, visited); } ); }
/** Determines whether a sequence of flights between two cities * exists. Nonrecursive stack version. * @pre originCity and destinationCity both exist in the Map. * @post None. * @param originCity Number of the origin city. * @param destinationCity Number of the destination city. * @return True if a sequence of flights exists from originCity to * destinationCity; otherwise returns false. Cities visited * during the search are marked as visited in the flight * map. * @note Uses a stack for the city numbers of a potential * path. Calls unvisitAll, markVisited, and getNextCity. */ bool Map::isPath(int originCity, int destinationCity) { Stack aStack; int topCity, nextCity; bool success; unvisitAll(); // clear marks on all cities // push origin city onto aStack, mark it visited try { aStack.push(originCity); markVisited(originCity); aStack.getTop(topCity); while (!aStack.isEmpty() && (topCity != destinationCity)) { // Loop invariant: The stack contains a directed path // from the origin city at the bottom of the stack to // the city at the top of the stack // find an unvisited city adjacent to the city on the // top of the stack success = getNextCity(topCity, nextCity); if (!success) aStack.pop(); // no city found; backtrack else // visit city { aStack.push(nextCity); markVisited(nextCity); } // end if if(!aStack.isEmpty()) aStack.getTop(topCity); } // end while if (aStack.isEmpty()) return false; // no path exists else return true; // path exists } catch (StackException e) { cout << e.what() << endl; } // end try } // end isPath
void DataWalker::traverseData(ArrayData* data, DataFeature& features, PointerSet& visited) const { // shared arrays by definition do not contain circular references or // collections if (data->isSharedArray()) { // If not looking for references to objects/resources OR // if one was already found we can bail out if (!(m_features & LookupFeature::HasObjectOrResource) || features.hasObjectOrResource()) { features.m_hasRefCountReference = true; // just in case, cheap enough... return; } } for (ArrayIter iter(data); iter; ++iter) { const Variant& var = iter.secondRef(); if (var.isReferenced()) { Variant *pvar = var.getRefData(); if (markVisited(pvar, features, visited)) { // don't recurse forever if (canStopWalk(features)) { return; } continue; } markVisited(pvar, features, visited); } DataType type = var.getType(); // cheap enough, do it always features.m_hasRefCountReference = IS_REFCOUNTED_TYPE(type); if (type == KindOfObject) { features.m_hasObjectOrResource = true; traverseData(var.getObjectData(), features, visited); } else if (type == KindOfArray) { traverseData(var.getArrayData(), features, visited); } else if (type == KindOfResource) { features.m_hasObjectOrResource = true; } if (canStopWalk(features)) return; } }
void ConfigTree::ignoreConfParamAll(const std::string ¶m) const { checkUnique(param); auto& ct = markVisited(param, Attr::TAG, true); auto p = _tree->equal_range(param); for (auto it = p.first; it != p.second; ++it) { ++ct.count; } }
void ConfigTree::ignoreConfAttribute(const std::string &attr) const { checkUniqueAttr(attr); // Exercise: Guess what not! (hint: if not found, peek only) // Btw. (not a hint) _tree->find() does not seem to work here. bool peek_only = !_tree->get_child_optional("<xmlattr>." + attr); markVisited(attr, Attr::ATTR, peek_only); }
void DataWalker::traverseData( ObjectData* data, DataFeature& features, PointerSet& visited) const { objectFeature(data, features, visited); if (markVisited(data, features, visited)) { return; // avoid infinite recursion } if (!canStopWalk(features)) { traverseData(data->toArray().get(), features, visited); } }
Range<ConfigTree::SubtreeIterator> ConfigTree:: getConfSubtreeList(std::string const& root) const { checkUnique(root); markVisited(root, Attr::TAG, true); auto p = _tree->equal_range(root); return Range<SubtreeIterator>( SubtreeIterator(p.first, root, *this), SubtreeIterator(p.second, root, *this)); }
Range<ConfigTree::ParameterIterator> ConfigTree:: getConfParamList(const std::string ¶m) const { checkUnique(param); markVisited(param, Attr::TAG, true); auto p = _tree->equal_range(param); return Range<ParameterIterator>( ParameterIterator(p.first, param, *this), ParameterIterator(p.second, param, *this)); }
void BWTTraverse::extractSG(const BWT* pBWT, const BWT* pRevBWT, const unsigned int len) { WARN_ONCE("Skipping bwt[0]"); // Keep a bool vector marking which entries in pBWT have been visited size_t n_elems = pBWT->getBWLen(); bool_vec visited(n_elems, false); size_t count = 0; size_t currIdx = 1; while(currIdx < n_elems) { // Invariant: currIdx is the index into pBWT that is the lowest index that has not been visited // Left-extend the entry at currIdx into a string of length len std::string str; str.reserve(len); // Get the first character of the suffix starting at this position char first = pBWT->getF(currIdx); str += first; BWTInterval range(currIdx, currIdx); while(str.length() < len) { char b = pBWT->getChar(range.lower); if(b == '$') break; str += b; BWTAlgorithms::updateInterval(range, b, pBWT); } // The string was built backwards, reverse it str = reverse(str); if(str.length() < len) { visited[currIdx] = true; } else if(!visited[range.lower]) { markVisited(str, visited, pBWT); //std::cout << currIdx << " interval: " << range << " string: " << str << "\n"; extendLeft(len, str, visited, pBWT, pRevBWT); extendRight(len, str, visited, pBWT, pRevBWT, false); printf(">%zu %zu 0\n%s\n", count++, str.length(), str.c_str()); } currIdx++; } }
void breadthFirstSearch (tGraph ** pGraph, char ** pVisited, char ** pOrder) { int i; int size; char * completed; size = (*pGraph)->size; (*pVisited) = (char*) malloc (size*sizeof(char)); (*pOrder) = (char*) malloc (size*sizeof(char)); for (i=0; i<size; i++) { (*pVisited)[i] = 0; (*pOrder)[i] = 0; } markVisited (&(*pGraph), &(*pVisited), 0, &(*pOrder)); }
void Floodfill::eval_connectivity(void) { if(volobj==NULL) return; edges.resize(1); edges[0].resize(region_colours_tokeep.size()); for(int j=0; j<edges[0].size(); j++) edges[0][j].resize(region_colours_tokeep.size()); for(int i=0; i<edges[0].size(); i++) for(int j=0; j<edges[0][i].size(); j++) edges[0][i][j]=false; //holds voxel indices of the current region of interest vector< vector<Point3D> > stack; vector<Point3D> s; Point3D temp; int tempi; int x, y, z; int border = 0; init(volobj->texwidth, volobj->texheight, volobj->texdepth, VISITEDARRAY); Vector rgb, region_rgb; Vector black = Vector(0,0,0); Vector yellow = Vector(255,255,0); int current_regionindex; int regionindex; int recursiondepth=0; int maxrecursiondepth = 25; int currentlvl=0; int go = 1; //for each x for (x =border; x < width-border; x++) { progress(x, width-border); //for each y for (y =border; y < height-border; y++) { for (z = 0; z < depth; z++) { //save current position temp.x = x; temp.y = y; temp.z = z; tempi = get1Dindex(temp); region_rgb.x = volobj->texture3d[3*tempi+0]; region_rgb.y = volobj->texture3d[3*tempi+1]; region_rgb.z = volobj->texture3d[3*tempi+2]; //if voxel is data and not visited //----------------------------------- //we can mark our voxels space with -1 or 0 //if -1 then it is a voxel we want to apply our flood fill to //how we mark which voxels are data is done elsewhere. if(region_rgb!=yellow && region_rgb!=black && isVisited(x,y,z,VISITEDARRAY)==false) // { for(int i=0; i<region_colours_tokeep.size(); i++) { if(region_rgb==region_colours_tokeep[i]) { current_regionindex = i; } } s.push_back(temp); stack.push_back(s); //printf("regionsize: %d\n", region_sizes[current_regionindex]); //printf("setting maxrecursiondepth to: %d\n", maxrecursiondepth); recursiondepth=0; currentlvl=0; go = 1; while(go) { s.clear(); //while stack not empty while(stack[currentlvl].size()) { //save item and pop off stack //printf("currentlvl: %d, currentlvlstacksize: %d\n", currentlvl, stack[currentlvl].size()); temp = stack[currentlvl][stack[currentlvl].size()-1]; tempi = get1Dindex(temp); stack[currentlvl].pop_back(); //mark the voxel markVisited(temp.x, temp.y, temp.z, VISITEDARRAY); /* rgb.x = volobj->texture3d[3*tempi+0]; rgb.y = volobj->texture3d[3*tempi+1]; rgb.z = volobj->texture3d[3*tempi+2]; */ volobj->texture3d[3*tempi+0] = region_rgb.x; volobj->texture3d[3*tempi+1] = region_rgb.y; volobj->texture3d[3*tempi+2] = region_rgb.z; //search neighborhood for the next pixel search_neighborhood((int)temp.x, (int)temp.y, (int)temp.z, &s, FILL_RULE, CONNECT26, VISITEDARRAY); //if it isnt marked as an edge /*if(rgb.x!=255.0 && rgb.y!=255.0 && rgb.z !=0.0) { volobj->texture3d[3*tempi+0] = region_rgb.x; volobj->texture3d[3*tempi+1] = region_rgb.y; volobj->texture3d[3*tempi+2] = region_rgb.z; }*/ /*if(region_rgb!=rgb) { for(int i=0; i<region_colours_tokeep.size(); i++) { if(rgb==region_colours_tokeep[i]) { printf("FOUND EDGE\n"); regionindex = i; edges[0][current_regionindex][regionindex] = true; edges[0][regionindex][current_regionindex] = true; visited_voxels[(int)temp.x][(int)temp.y][(int)temp.z] = false; } } }*/ } //printf("recursiondepth: %d, stacksize: %d\n", recursiondepth, s.size()); stack.push_back(s); stack[currentlvl].clear(); currentlvl++; recursiondepth++; if(recursiondepth>=maxrecursiondepth || s.empty()) { /*for(int j=0; j<stack.size(); j++) { for(int i=0; i<stack[j].size(); i++) { temp = stack[j][i]; visited_voxels[(int)temp.x][(int)temp.y][(int)temp.z] = false; } stack[j].clear(); }*/ stack.clear(); /*for(int i=0; i<s.size(); i++) { visited_voxels[(int)s[i].x][(int)s[i].y][(int)s[i].z] = false; }*/ s.clear(); go=0; //return; } /*else { stack[currentlvl].clear(); }*/ } } } } } // printf("\n Regions Found: %i \n", regions); printf("\n Regions Found: %i \n", regions); }
//search (6) or (26) connected neighborhood for similiar voxel as starting point void Floodfill::search_neighborhood(int x, int y, int z, vector<Point3D>* stack, int rule, int connectivity, int visitmode) { //resolution of steps int steps = 1; //setup our searh indices int indexNorth = y + steps; int indexSouth = y - steps; int indexEast = x + steps; int indexWest = x - steps; int indexUp = z + steps; int indexDown = z - steps; //helper Point3D temp; // look around for connected voxels marked as data (ie: equal to -1) // 6 CONNECTED //----------------- //EAST if(indexEast < width ) //if we aint out of bounds { //if the voxel has not been visited if(isVisited(indexEast, y, z, visitmode)==false) { if(apply_rule(x,y,z, indexEast,y,z, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = y; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info markVisited(indexEast, y, z, visitmode); } } } //WEST if(indexWest >= 0 ) //if we aint out of bounds { //if the voxel has not been visited if(isVisited(indexWest, y, z, visitmode)==false) { if( apply_rule(x,y,z, indexWest,y,z, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = y; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info markVisited(indexWest, y, z, visitmode); } } } //NORTH if(indexNorth < height ) //if we aint out of bounds { //if the voxel has not been visited if(isVisited(x, indexNorth, z, visitmode)==false) { if(apply_rule(x,y,z, x,indexNorth,z, rule)) { //then voxel is in the same region temp.x = x; temp.y = indexNorth; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info markVisited(x, indexNorth, z, visitmode); } } } //SOUTH if(indexSouth >= 0) //if we aint out of bounds { //if the voxel has not been visited if(isVisited(x, indexSouth, z, visitmode)==false) { if(apply_rule(x,y,z, x,indexSouth,z, rule)) { //then voxel is in the same region temp.x = x; temp.y = indexSouth; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info markVisited(x, indexSouth, z, visitmode); } } } //UP if(indexUp < depth ) //if we aint out of bounds { //if the voxel has not been visited if(isVisited(x, y, indexUp, visitmode)==false) { if(apply_rule(x,y,z, x,y,indexUp, rule)) { //then voxel is in the same region temp.x = x; temp.y = y; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info markVisited(x, y, indexUp, visitmode); } } } //DOWN if(indexDown >= 0) //if we aint out of bounds { //if the voxel has not been visited if(isVisited(x, y, indexDown, visitmode)==false) { if(apply_rule(x,y,z, x,y,indexDown, rule)) { //then voxel is in the same region temp.x = x; temp.y = y; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info markVisited(x, y, indexDown, visitmode); } } } /* if(connectivity==CONNECT26) //CONNECT26 { // 26 CONNECTED (20 additional cases) //---------------------------------- //NORTH WEST if(indexNorth < height && indexWest >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][indexNorth][z]==false) if(apply_rule(x,y,z, indexWest,indexNorth,z, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = indexNorth; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][indexNorth][z] = true; } } //SOUTH WEST if(indexSouth >= 0 && indexWest >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][indexSouth][z]==false) if(apply_rule(x,y,z, indexWest,indexSouth,z, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = indexSouth; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][indexSouth][z] = true; } } //NORTH EAST if(indexNorth < height && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][indexNorth][z]==false) if(apply_rule(x,y,z, indexEast,indexNorth,z, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = indexNorth; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][indexNorth][z] = true; } } //SOUTH EAST if(indexSouth >= 0 && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][indexSouth][z]==false) if(apply_rule(x,y,z, indexEast,indexSouth,z, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = indexSouth; temp.z = z; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][indexSouth][z] = true; } } //------------------------------------------------------------------------- //UP NORTH if(indexUp < depth && indexNorth < height) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[x][indexNorth][indexUp]==false) if(apply_rule(x,y,z, x,indexNorth,indexUp, rule)) { //then voxel is in the same region temp.x = x; temp.y = indexNorth; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[x][indexNorth][indexUp] = true; } } //UP SOUTH if(indexUp < depth && indexSouth >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[x][indexSouth][indexUp]==false) if(apply_rule(x,y,z, x,indexSouth,indexUp, rule)) { //then voxel is in the same region temp.x = x; temp.y = indexSouth; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[x][indexSouth][indexUp] = true; } } //UP EAST if(indexUp < depth && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][y][indexUp]==false) if(apply_rule(x,y,z, indexEast,y,indexUp, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = y; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][y][indexUp] = true; } } //UP WEST if(indexUp < depth && indexWest >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][y][indexUp]==false) if(apply_rule(x,y,z, indexWest,y,indexUp, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = y; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][y][indexUp] = true; } } //UP SOUTH WEST if(indexUp < depth && indexSouth >= 0 && indexWest >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][indexSouth][indexUp]==false) if(apply_rule(x,y,z, indexWest,indexSouth,indexUp, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = indexSouth; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][indexSouth][indexUp] = true; } } //UP SOUTH EAST if(indexUp < depth && indexSouth >= 0 && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][indexSouth][indexUp]==false) if(apply_rule(x,y,z, indexEast,indexSouth,indexUp, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = indexSouth; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][indexSouth][indexUp] = true; } } //UP NORTH EAST if(indexUp < depth && indexNorth < height && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][indexNorth][indexUp]==false) if(apply_rule(x,y,z, indexEast,indexNorth,indexUp, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = indexNorth; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][indexNorth][indexUp] = true; } } //UP NORTH WEST if(indexUp < depth && indexNorth < height && indexWest >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][indexNorth][indexUp]==false) if(apply_rule(x,y,z, indexWest,indexNorth,indexUp, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = indexNorth; temp.z = indexUp; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][indexNorth][indexUp] = true; } } //------------------------------------------------------------------------- //DOWN NORTH if(indexDown >= 0 && indexNorth < height) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[x][indexNorth][indexDown]==false) if(apply_rule(x,y,z, x,indexNorth,indexDown, rule)) { //then voxel is in the same region temp.x = x; temp.y = indexNorth; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[x][indexNorth][indexDown] = true; } } //DOWN SOUTH if(indexDown >= 0 && indexSouth >= 0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[x][indexSouth][indexDown]==false) if(apply_rule(x,y,z, x,indexSouth,indexDown, rule)) { //then voxel is in the same region temp.x = x; temp.y = indexSouth; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[x][indexSouth][indexDown] = true; } } //DOWN WEST if(indexDown >= 0 && indexWest >=0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][y][indexDown]==false) if(apply_rule(x,y,z, indexWest,y,indexDown, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = y; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][y][indexDown] = true; } } //DOWN EAST if(indexDown >= 0 && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][y][indexDown]==false) if(apply_rule(x,y,z, indexEast,y,indexDown, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = y; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][y][indexDown] = true; } } //DOWN SOUTH WEST if(indexDown >= 0 && indexSouth >= 0 && indexWest >=0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][indexSouth][indexDown]==false) if(apply_rule(x,y,z, indexWest,indexSouth,indexDown, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = indexSouth; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][indexSouth][indexDown] = true; } } //DOWN SOUTH EAST if(indexDown >= 0 && indexSouth >= 0 && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][indexSouth][indexDown]==false) if(apply_rule(x,y,z, indexEast,indexSouth,indexDown, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = indexSouth; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][indexSouth][indexDown] = true; } } //DOWN NORTH WEST if(indexDown >= 0 && indexNorth < height && indexWest >=0) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexWest][indexNorth][indexDown]==false) if(apply_rule(x,y,z, indexWest,indexNorth,indexDown, rule)) { //then voxel is in the same region temp.x = indexWest; temp.y = indexNorth; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexWest][indexNorth][indexDown] = true; } } //DOWN NORTH EAST if(indexDown >= 0 && indexNorth < height && indexEast < width) //if we aint out of bounds { //if the voxel has not been visited if(visited_voxels[indexEast][indexNorth][indexDown]==false) if(apply_rule(x,y,z, indexEast,indexNorth,indexDown, rule)) { //then voxel is in the same region temp.x = indexEast; temp.y = indexNorth; temp.z = indexDown; //we can add it to the stack stack->push_back(temp); //and mark the voxel with region info visited_voxels[indexEast][indexNorth][indexDown] = true; } } }*/ }
void Floodfill::applyfloodfillseededsmoothed(Point3D seedpoint, int src, int dst) { if(volobj==NULL) return; Filter filter; filter.volobj = volobj; WINDOW_SIZE = 2; int GAUSSIAN_SIZE = 1; float GAUSSIAN_SIGMA = 2.0; int THRESHOLD_SIZE = 100; SRC_CHANNEL = src; DST_CHANNEL = dst; int visitedmode = VISITEDDIRECT; int rule = -1; if(SRC_CHANNEL==0) rule = RCOLOURWINDOW_RULE; else if(SRC_CHANNEL==1) rule = GCOLOURWINDOW_RULE; else if(SRC_CHANNEL==2) rule = BCOLOURWINDOW_RULE; //printf("channels src: %d, dst: %d\n", SRC_CHANNEL, DST_CHANNEL); init(volobj->texwidth, volobj->texheight, volobj->texdepth, visitedmode); //empty destination channels int size = volobj->texwidth*volobj->texheight*volobj->texdepth; for(int i=0; i<size; i++) { if(SRC_CHANNEL==0) { volobj->texture3d[3*i+1] = 0; volobj->texture3d[3*i+2] = 0; } if(SRC_CHANNEL==1) { volobj->texture3d[3*i+0] = 0; volobj->texture3d[3*i+1] = 0; } if(SRC_CHANNEL==1) { volobj->texture3d[3*i+0] = 0; volobj->texture3d[3*i+2] = 0; } } //holds voxel indices of the current region of interest vector<Point3D> stack; vector<int> curr_region; int tempi; Point3D temp; int x, y, z; int recursiondepth=0; int index, helper, oldhelper; bool stopsearch=false; //================== //FLOODFILL //================== //push to stack stack.push_back(seedpoint); //while stack not empty while(stack.size()) { //save item and pop off stack temp = stack[stack.size()-1]; tempi = get1Dindex(temp); stack.pop_back(); //mark the voxel markVisited(temp.x, temp.y, temp.z, visitedmode); //curr_region.push_back(tempi); //search neighborhood for the next pixel if(!stopsearch) search_neighborhood((int)temp.x, (int)temp.y, (int)temp.z, &stack, rule, CONNECT6, visitedmode); vector< bool > channels; channels.resize(3); channels[0]=false; channels[1]=true; channels[2]=false; // printf("helper: %d\n", helper); // return; recursiondepth++; if(recursiondepth>10) stopsearch=true; } return; /* filter.apply_gaussian_filter_decomp(1, 2.0, 0, channels); size = volobj->texwidth*volobj->texheight*volobj->texdepth; helper=0; for(int i=0; i<size; i++) { if(volobj->texture3d[3*i+DST_CHANNEL]>(255-WINDOW_SIZE)) { volobj->texture3d[3*i+DST_CHANNEL] = 255; helper++; } else { volobj->texture3d[3*i+DST_CHANNEL]=0; } } */ filter.volobj = 0; }
/* * Descend through the hierarchy, starting at "fullpath". * If "fullpath" is anything other than a directory, we lstat() it, * call the search function, and return. For a directory, we call ourself * recursively for each name in the directory. */ static int /* we return whatever func() returns */ dopath(char *searchstr, struct FlagOpts *flags) { struct stat statbuf; struct dirent *dirp; DIR *dp; int ret; char *ptr; int errnum; errno = 0; if (lstat(fullpath, &statbuf) < 0) { /* stat error */ errnum = errno; my_errprintf("Error reading file attribute: %s\n", strerror(errnum) ); } if (S_ISLNK(statbuf.st_mode) != 0) { /* symbolic link */ if( (*flags).l == 1) { // search symbolic links int k = readlink( fullpath, symlpath, PATH_MAX+1 ); symlpath[k] = '\0'; if (stat(fullpath, &statbuf) < 0) { /* stat error */ errnum = errno; my_errprintf("Error reading file attribute: %s\n", strerror(errnum) ); } } else { // do not search file or folder return 0; } } // Do not read already visited files if ( alreadyVisited(statbuf.st_ino) == 1 ) { return 0; } if (S_ISDIR(statbuf.st_mode) == 0) { /* not a directory */ // Skip certain files according to [-f] flags used if ( fileTypesFlag == 1 ) { if ( checkEnding('c',fullpath)==1 ) { if( flags->c == 0) return 0; } else if ( checkEnding('h',fullpath)==1 ) { if( flags->h == 0) return 0; } else if ( checkEnding('S',fullpath)==1 ) { if( flags->S == 0) return 0; } else { //other type of file - skip since flag opt used return 0; } } // add regular file i-node to list of files visited markVisited(statbuf.st_ino); return(readfile(fullpath, searchstr, &statbuf, FTW_F)); } /* * It's a directory. First call func() for the directory, * then process each filename in the directory. */ // add directory i-node to list of files visited markVisited(statbuf.st_ino); if ((ret = readfile(fullpath, searchstr, &statbuf, FTW_D)) != 0) return(ret); ptr = fullpath + strlen(fullpath); /* point to end of fullpath */ *ptr++ = '/'; *ptr = 0; if ((dp = opendir(fullpath)) == NULL) /* can't read directory */ return(readfile(fullpath, searchstr, &statbuf, FTW_DNR)); while ((dirp = readdir(dp)) != NULL) { if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) continue; /* ignore dot and dot-dot */ strcpy(ptr, dirp->d_name); /* append name after slash */ if ((ret = dopath(searchstr, flags)) != 0) /* recursive */ break; /* time to leave */ } ptr[-1] = 0; /* erase everything from slash onwards */ if (closedir(dp) < 0) ; return(ret); }
void Floodfill::floodfill(int rule) { if(volobj==NULL) return; //holds voxel indices of the current region of interest vector<Point3D> stack; vector<int> curr_region; Point3D temp; int tempi; int x, y, z; regions = 0; region_sizes.clear(); region_colours.clear(); region_indices.clear(); init(volobj->texwidth, volobj->texheight, volobj->texdepth, VISITEDARRAY); int border = 0; printf("Labelling Background\n"); //floodfillseeded(Point3D(0,0,0), rule); printf("done...\n"); Vector rgb, hsv; int recursiondepth=0; //for each x for (x =border; x < width-border; x++) { progress(x, width-border); //for each y for (y =border; y < height-border; y++) { for (z = 0; z < depth; z++) { temp.x = x; temp.y = y; temp.z = z; tempi = get1Dindex(temp); rgb.x = volobj->texture3d[3*tempi+0]; rgb.y = volobj->texture3d[3*tempi+1]; rgb.z = volobj->texture3d[3*tempi+2]; //if voxel is data and not visited //----------------------------------- //we can mark our voxels space with -1 or 0 //if -1 then it is a voxel we want to apply our flood fill to //how we mark which voxels are data is done elsewhere. if(isVisited(x,y,z,VISITEDARRAY)==false && rgb!=0.0) { //we found a region regions++; /*hsv.x = rand()%360; hsv.y = (float)(rand()%255)/255.0; hsv.z = 1.0; HSVtoRGB(hsv, &rgb);*/ int cont=1; while(cont) { rgb.x = (float)(rand()%255)/255.0; rgb.y = 0.0; rgb.z = (float)(rand()%255)/255.0; rgb *= 255; cont = 0; for(int i=0; i<region_colours.size(); i++) { if(rgb==region_colours[i]) cont = 1; } } //save current position temp.x = x; temp.y = y; temp.z = z; recursiondepth=0; stack.push_back(temp); curr_region.push_back(get1Dindex(temp)); //while stack not empty while(stack.size()) { //save item and pop off stack temp = stack[stack.size()-1]; stack.pop_back(); //mark the voxel markVisited(temp.x, temp.y, temp.z, VISITEDARRAY); curr_region.push_back(get1Dindex(temp)); //search neighborhood for the next pixel search_neighborhood((int)temp.x, (int)temp.y, (int)temp.z, &stack, rule, CONNECT26, VISITEDARRAY); //curr_region.push_back(get1Dindex(temp)); tempi = get1Dindex(temp); volobj->texture3d[3*tempi+0] = rgb.x; volobj->texture3d[3*tempi+1] = rgb.y; volobj->texture3d[3*tempi+2] = rgb.z; recursiondepth++; } region_colours.push_back(Vector((int)rgb.x, (int)rgb.y, (int)rgb.z)); //region_sizes.push_back(recursiondepth); region_indices.push_back(curr_region); curr_region.clear(); } } } } // printf("\n Regions Found: %i \n", regions); printf("\n Regions Found: %i \n", regions); }
void Floodfill::applyfloodfillseeded(Point3D seedpoint, int src, int dst, int window) { if(volobj==NULL) return; SRC_CHANNEL = src; DST_CHANNEL = dst; WINDOW_SIZE = window; int visitedmode = VISITEDDIRECT; int rule = -1; if(SRC_CHANNEL==0) rule = RCOLOURWINDOW_RULE; else if(SRC_CHANNEL==1) rule = GCOLOURWINDOW_RULE; else if(SRC_CHANNEL==2) rule = BCOLOURWINDOW_RULE; //printf("channels src: %d, dst: %d\n", SRC_CHANNEL, DST_CHANNEL); init(volobj->texwidth, volobj->texheight, volobj->texdepth, visitedmode); //empty destination channels int size = volobj->texwidth*volobj->texheight*volobj->texdepth; for(int i=0; i<size; i++) { if(SRC_CHANNEL==0) { volobj->texture3d[3*i+1] = 0; volobj->texture3d[3*i+2] = 0; } if(SRC_CHANNEL==1) { volobj->texture3d[3*i+0] = 0; volobj->texture3d[3*i+1] = 0; } if(SRC_CHANNEL==1) { volobj->texture3d[3*i+0] = 0; volobj->texture3d[3*i+2] = 0; } } //holds voxel indices of the current region of interest vector<Point3D> stack; vector<int> curr_region; int tempi; Point3D temp; int x, y, z; int recursiondepth=0; int index; //================== //FLOODFILL //================== //push to stack stack.push_back(seedpoint); //while stack not empty while(stack.size()) { //save item and pop off stack temp = stack[stack.size()-1]; tempi = get1Dindex(temp); stack.pop_back(); //mark the voxel markVisited(temp.x, temp.y, temp.z, visitedmode); //curr_region.push_back(tempi); //search neighborhood for the next pixel search_neighborhood((int)temp.x, (int)temp.y, (int)temp.z, &stack, rule, CONNECT6, visitedmode); } volobj->is_greyscale = false; if(src==0) volobj->has_red = true; if(src==1) volobj->has_green = true; if(src==2) volobj->has_blue = true; if(dst==0) volobj->has_red = true; if(dst==1) volobj->has_green = true; if(dst==2) volobj->has_blue = true; }