示例#1
0
    bool Cube::intersects(Line line, double *alpha_1, double *alpha_2)
    {
        //line.dump();
        bool hasValue = false;
        double minimum=0, maximum=0;
        consider(xMin, xMax, line.origin.x, line.direction.x, minimum, maximum, hasValue);
        //std::cout << xMin << ">" << xMax << " " << hasValue << " " << minimum << " " << maximum << std::endl;
        consider(yMin, yMax, line.origin.y, line.direction.y, minimum, maximum, hasValue);
        //std::cout << yMin << ">" << yMax << " " << hasValue << " " << minimum << " " << maximum << std::endl;
        consider(zMin, zMax, line.origin.z, line.direction.z, minimum, maximum, hasValue);
        //std::cout << zMin << ">" << zMax << " " << hasValue << " " << minimum << " " << maximum << std::endl;

        /**
        // Plots the intersection
        auto A = line.get(minimum);
        auto B = line.get(maximum);
        std::cout << A.x << " " << A.y << " " << A.z << std::endl;
        std::cout << B.x << " " << B.y << " " << B.z << std::endl;
        */
        if (alpha_1 != NULL) {
            *alpha_1 = minimum;
        }
        if (alpha_2 != NULL) {
            *alpha_2 = maximum;
        }

        return (hasValue && minimum <= maximum);
    }
            inline void consider(DIT begin, DIT end, const RET& max_dist, int& n,
                            const PSDS& ps_distance_strategy) const
            {
                size_t size = end - begin;
                // size must be at least 3 here: we want to consider a candidate point between begin and end
                if (size <= 2)
                {
#ifdef GL_DEBUG_SIMPLIFY
                    if (begin != end)
                    {
                        std::cout << "ignore between " << begin->p << " and " << (end - 1)->p << " size=" << size << std::endl;
                    }
                    std::cout << "return because size=" << size << std::endl;
#endif
                    return;
                }

                DIT last = end - 1;

#ifdef GL_DEBUG_SIMPLIFY
                std::cout << "find between " << begin->p << " and " << last->p << " size=" << size << std::endl;
#endif


                // Find most distance point, compare to the current segment
                ggl::segment<const P> s(begin->p, last->p);
                RET md(-1.0); // any value < 0
                DIT candidate;
                for(DIT it = begin + 1; it != last; it++)
                {
                    RET dist = ps_distance_strategy(it->p, s);

#ifdef GL_DEBUG_SIMPLIFY
                    std::cout << "consider " << it->p << " at " << dist.value() << (dist.value() > max_dist.value() ? " maybe" : " no") << std::endl;
#endif
                    if (dist > md)
                    {
                        md = dist;
                        candidate = it;
                    }
                }

                // If a point is found, set the include flag and handle segments in between recursively
                if (md > max_dist)
                {
#ifdef GL_DEBUG_SIMPLIFY
                    std::cout << "use " << candidate->p << std::endl;
#endif

                    candidate->included = true;
                    n++;

                    consider(begin, candidate + 1, max_dist, n, ps_distance_strategy);
                    consider(candidate, end, max_dist, n, ps_distance_strategy);
                }
            }
示例#3
0
bool cycle_writer::setup(string base_file_name, int rollover_mb, int duration_seconds, int file_limit, unsigned long event_limit, scap_dumper_t** dumper)
{
	if(m_first_consider) 
	{
		return false;
	}
	m_base_file_name = base_file_name;
	m_rollover_mb = rollover_mb * 1000000L;
	m_duration_seconds = duration_seconds;
	m_file_limit = file_limit;
	m_event_limit = event_limit;
	m_dumper = dumper;

	if(duration_seconds > 0 && file_limit > 0)
	{
		m_past_names = new string[file_limit];
		
		for(int32_t j = 0; j < file_limit; j++)
		{
			m_past_names[j] = "";
		}
	}

	//
	// Seed the filename with an initial
	// value.
	//
	consider(NULL);
	return true;
}
            /*!
                \brief Call simplification on an iterator pair
            */
            inline void simplify(const R& range, O_IT out, double max_distance) const
            {
                PSDS strategy;
                // Init the output, a vector of references to all points

                // Note Geometry Algorithms suggest here
                // http://geometryalgorithms.com/Archive/algorithm_0205/algorithm_0205.htm
                // to "STAGE 1: Vertex Reduction within max_distance of prior vertex cluster"
                // However, that is not correct: a vertex within the specified distance might be
                // excluded here, but might be a better candidate for final inclusion than the point before.

                std::vector<DP> ref_candidates(boost::begin(range), boost::end(range));

                // Include first and last point of line, they are always part of the line
                int n = 2;
                ref_candidates.front().included = true;
                ref_candidates.back().included = true;

                // Get points, recursively, including them if they are further away than the specified distance
                typedef typename PSDS::return_type RET;

                consider(boost::begin(ref_candidates), boost::end(ref_candidates),
                    make_distance_result<RET>(max_distance), n, strategy);

                // Copy included elements to the output  (might be changed using copy_if)
                for(typename std::vector<DP>::const_iterator it = boost::begin(ref_candidates);
                    it != boost::end(ref_candidates); it++)
                {
                    if (it->included)
                    {
                        *out = it->p;
                        out++;
                    }
                }
            }
示例#5
0
bool ompl::control::KPIECE1::CloseSamples::selectMotion(Motion* &smotion, Grid::Cell* &scell)
{
    if (samples.size() > 0)
    {
        scell = samples.begin()->cell;
        smotion = samples.begin()->motion;
        // average the highest & lowest distances and multiply by CLOSE_MOTION_DISTANCE_INFLATION_FACTOR
        // (make the distance appear artificially longer)
        double d = (samples.begin()->distance + samples.rbegin()->distance) * (CLOSE_MOTION_DISTANCE_INFLATION_FACTOR / 2.0);
        samples.erase(samples.begin());
        consider(scell, smotion, d);
        return true;
    }
    return false;
}
        inline OutputIterator apply(Range const& range,
                                    OutputIterator out,
                                    distance_type max_distance) const
        {
#ifdef BOOST_GEOMETRY_DEBUG_DOUGLAS_PEUCKER
                std::cout << "max distance: " << max_distance
                          << std::endl << std::endl;
#endif
            distance_strategy_type strategy;

            // Copy coordinates, a vector of references to all points
            std::vector<dp_point_type> ref_candidates(boost::begin(range),
                            boost::end(range));

            // Include first and last point of line,
            // they are always part of the line
            int n = 2;
            ref_candidates.front().included = true;
            ref_candidates.back().included = true;

            // Get points, recursively, including them if they are further away
            // than the specified distance
            consider(boost::begin(ref_candidates), boost::end(ref_candidates), max_distance, n, strategy);

            // Copy included elements to the output
            for(typename std::vector<dp_point_type>::const_iterator it
                            = boost::begin(ref_candidates);
                it != boost::end(ref_candidates);
                ++it)
            {
                if (it->included)
                {
                    // copy-coordinates does not work because OutputIterator
                    // does not model Point (??)
                    //geometry::convert(it->p, *out);
                    *out = it->p;
                    out++;
                }
            }
            return out;
        }
示例#7
0
    static inline OutputIterator apply(Range const& range,
                    OutputIterator out, double max_distance)
    {
        distance_strategy_type strategy;

        // Copy coordinates, a vector of references to all points
        std::vector<dp_point_type> ref_candidates(pdalboost::begin(range),
                        pdalboost::end(range));

        // Include first and last point of line,
        // they are always part of the line
        int n = 2;
        ref_candidates.front().included = true;
        ref_candidates.back().included = true;

        // Get points, recursively, including them if they are further away
        // than the specified distance
        typedef typename strategy::distance::services::return_type<distance_strategy_type>::type return_type;

        consider(pdalboost::begin(ref_candidates), pdalboost::end(ref_candidates), max_distance, n, strategy);

        // Copy included elements to the output
        for(typename std::vector<dp_point_type>::const_iterator it
                        = pdalboost::begin(ref_candidates);
            it != pdalboost::end(ref_candidates);
            ++it)
        {
            if (it->included)
            {
                // copy-coordinates does not work because OutputIterator
                // does not model Point (??)
                //geometry::convert(it->p, *out);
                *out = it->p;
                out++;
            }
        }
        return out;
    }
    std::pair <double, POINT> closest_point_on_triangle (const POINT &a, const POINT *tri)
    {
        std::pair <double, POINT> ret;
        ret.first = INFINITY;
        consider (&ret, a, tri[0]);
        consider (&ret, a, tri[1]);
        consider (&ret, a, tri[2]);

        POINT new_p = closest_point_in_aff_subspace <3> (a, tri);
        consider (&ret, a, new_p);

        POINT line[2] = { tri[0], tri[1] };
        new_p = closest_point_in_aff_subspace <2> (a, line);
        consider (&ret, a, new_p);
        line[1] = tri[2];
        new_p = closest_point_in_aff_subspace <2> (a, line);
        consider (&ret, a, new_p);
        line[0] = tri[1];
        new_p = closest_point_in_aff_subspace <2> (a, line);
        consider (&ret, a, new_p);

        return ret;
    }
    static inline void consider(iterator_type begin,
                iterator_type end,
                return_type const& max_dist, int& n,
                distance_strategy_type const& ps_distance_strategy)
    {
        std::size_t size = end - begin;

        // size must be at least 3
        // because we want to consider a candidate point in between
        if (size <= 2)
        {
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
            if (begin != end)
            {
                std::cout << "ignore between " << dsv(begin->p)
                    << " and " << dsv((end - 1)->p)
                    << " size=" << size << std::endl;
            }
            std::cout << "return because size=" << size << std::endl;
#endif
            return;
        }

        iterator_type last = end - 1;

#ifdef GL_DEBUG_DOUGLAS_PEUCKER
        std::cout << "find between " << dsv(begin->p)
            << " and " << dsv(last->p)
            << " size=" << size << std::endl;
#endif


        // Find most far point, compare to the current segment
        //geometry::segment<Point const> s(begin->p, last->p);
        return_type md(-1.0); // any value < 0
        iterator_type candidate;
        for(iterator_type it = begin + 1; it != last; ++it)
        {
            return_type dist = ps_distance_strategy.apply(it->p, begin->p, last->p);

#ifdef GL_DEBUG_DOUGLAS_PEUCKER
            std::cout << "consider " << dsv(it->p)
                << " at " << double(dist)
                << ((dist > max_dist) ? " maybe" : " no") 
                << std::endl;

#endif
            if (dist > md)
            {
                md = dist;
                candidate = it;
            }
        }

        // If a point is found, set the include flag
        // and handle segments in between recursively
        if (md > max_dist)
        {
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
            std::cout << "use " << dsv(candidate->p) << std::endl;
#endif

            candidate->included = true;
            n++;

            consider(begin, candidate + 1, max_dist, n, ps_distance_strategy);
            consider(candidate, end, max_dist, n, ps_distance_strategy);
        }
    }
示例#10
0
int Player::displayCreature(Creature* target)  {
    int     percent=0, align=0, rank=0, chance=0, flags = displayFlags();
    Player  *pTarget = target->getAsPlayer();
    Monster *mTarget = target->getAsMonster();
    std::ostringstream oStr;
    bstring str = "";
    bool space=false;

    if(mTarget) {
        oStr << "You see " << mTarget->getCrtStr(this, flags, 1) << ".\n";
        if(mTarget->getDescription() != "")
            oStr << mTarget->getDescription() << "\n";
        else
            oStr << "There is nothing special about " << mTarget->getCrtStr(this, flags, 0) << ".\n";

        if(mTarget->getMobTrade()) {
            rank = mTarget->getSkillLevel()/10;
            oStr << "^y" << mTarget->getCrtStr(this, flags | CAP, 0) << " is a " << get_trade_string(mTarget->getMobTrade())
                 << ". " << mTarget->upHisHer() << " skill level: " << get_skill_string(rank) << ".^x\n";
        }
    } else if(pTarget) {

        oStr << "You see " << pTarget->fullName() << " the "
             << gConfig->getRace(pTarget->getDisplayRace())->getAdjective();
        // will they see through the illusion?
        if(willIgnoreIllusion() && pTarget->getDisplayRace() != pTarget->getRace())
            oStr << " (" << gConfig->getRace(pTarget->getRace())->getAdjective() << ")";
        oStr << " "
             << pTarget->getTitle() << ".\n";

        if(gConfig->getCalendar()->isBirthday(pTarget)) {
            oStr << "^yToday is " << pTarget->getCName() << "'s birthday! " << pTarget->upHeShe()
                 << " is " << pTarget->getAge() << " years old.^x\n";
        }

        if(pTarget->description != "")
            oStr << pTarget->description << "\n";
    }

    if(target->isEffected("vampirism")) {
        chance = intelligence.getCur()/10 + piety.getCur()/10;
        // vampires and werewolves can sense each other
        if(isEffected("vampirism") || isEffected("lycanthropy"))
            chance = 101;
        if(chance > mrand(0,100)) {
            switch(mrand(1,4)) {
            case 1:
                oStr << target->upHeShe() << " looks awfully pale.\n";
                break;
            case 2:
                oStr << target->upHeShe() << " has an unearthly presence.\n";
                break;
            case 3:
                oStr << target->upHeShe() << " has hypnotic eyes.\n";
                break;
            default:
                oStr << target->upHeShe() << " looks rather pale.\n";
            }
        }
    }

    if(target->isEffected("lycanthropy")) {
        chance = intelligence.getCur()/10 + piety.getCur()/10;
        // vampires and werewolves can sense each other
        if(isEffected("vampirism") || isEffected("lycanthropy"))
            chance = 101;
        if(chance > mrand(0,100)) {
            switch(mrand(1,3)) {
            case 1:
                oStr << target->upHeShe() << " looks awfully shaggy.\n";
                break;
            case 2:
                oStr << target->upHeShe() << " has a feral presence.\n";
                break;
            default:
                oStr << target->upHeShe() << " looks rather shaggy.\n";
            }
        }
    }

    if(target->isEffected("slow"))
        oStr << target->upHeShe() << " is moving very slowly.\n";
    else if(target->isEffected("haste"))
        oStr << target->upHeShe() << " is moving unnaturally quick.\n";


    if((cClass == CreatureClass::CLERIC && deity == JAKAR && level >=7) || isCt())
        oStr << "^y" << target->getCrtStr(this, flags | CAP, 0 ) << " is carrying "
             << target->coins[GOLD] << " gold coin"
             << (target->coins[GOLD] != 1 ? "s" : "") << ".^x\n";

    if(isEffected("know-aura") || cClass==CreatureClass::PALADIN) {
        space = true;
        oStr << target->getCrtStr(this, flags | CAP, 0) << " ";

        align = target->getAdjustedAlignment();

        switch(align) {
        case BLOODRED:
            oStr << "has a blood red aura.";
            break;
        case REDDISH:
            oStr << "has a reddish aura.";
            break;
        case PINKISH:
            oStr << "has a pinkish aura.";
            break;
        case NEUTRAL:
            oStr << "has a grey aura.";
            break;
        case LIGHTBLUE:
            oStr << "has a light blue aura.";
            break;
        case BLUISH:
            oStr << "has a bluish aura.";
            break;
        case ROYALBLUE:
            oStr << "has a royal blue aura.";
            break;
        default:
            oStr << "has a grey aura.";
            break;
        }
    }

    if(mTarget && mTarget->getRace()) {
        if(space)
            oStr << " ";
        space = true;
        oStr << mTarget->upHeShe() << " is ^W"
             << gConfig->getRace(mTarget->getRace())->getAdjective().toLower() << "^x.";
    }
    if(target->getSize() != NO_SIZE) {
        if(space)
            oStr << " ";
        space = true;
        oStr << target->upHeShe() << " is ^W" << getSizeName(target->getSize()) << "^x.";
    }

    if(space)
        oStr << "\n";

    if(target->hp.getCur() > 0 && target->hp.getMax())
        percent = (100 * (target->hp.getCur())) / (target->hp.getMax());
    else
        percent = -1;

    if(!(mTarget && mTarget->flagIsSet(M_UNKILLABLE))) {
        oStr << target->upHeShe();
        if(percent >= 100 || !target->hp.getMax())
            oStr << " is in excellent condition.\n";
        else if(percent >= 90)
            oStr << " has a few scratches.\n";
        else if(percent >= 75)
            oStr << " has some small wounds and bruises.\n";
        else if(percent >= 60)
            oStr << " is wincing in pain.\n";
        else if(percent >= 35)
            oStr << " has quite a few wounds.\n";
        else if(percent >= 20)
            oStr << " has some big nasty wounds and scratches.\n";
        else if(percent >= 10)
            oStr << " is bleeding awfully from big wounds.\n";
        else if(percent >= 5)
            oStr << " is barely clinging to life.\n";
        else if(percent >= 0)
            oStr << " is nearly dead.\n";
    }

    if(pTarget) {
        if(pTarget->isEffected("mist")) {
            oStr << pTarget->upHeShe() << "%s is currently in mist form.\n";
            printColor("%s", oStr.str().c_str());
            return(0);
        }

        if(pTarget->flagIsSet(P_UNCONSCIOUS))
            oStr << pTarget->getName() << " is "
                 << (pTarget->flagIsSet(P_SLEEPING) ? "sleeping" : "unconscious") << ".\n";

        if(pTarget->isEffected("petrification"))
            oStr << pTarget->getName() << " is petrified.\n";

        if(pTarget->isBraindead())
            oStr << pTarget->getName() << "%M is currently brain dead.\n";
    } else {
        if(mTarget->isEnemy(this))
            oStr << mTarget->upHeShe() << " looks very angry at you.\n";
        else if(mTarget->getPrimeFaction() != "")
            oStr << mTarget->upHeShe() << " " << getFactionMessage(mTarget->getPrimeFaction()) << ".\n";

        Creature* firstEnm = nullptr;
        if((firstEnm = mTarget->getTarget(false)) != nullptr) {
            if(firstEnm == this) {
                if(  !mTarget->flagIsSet(M_HIDDEN) &&
                    !(mTarget->isInvisible() && isEffected("detect-invisible")))
                    oStr << mTarget->upHeShe() << " is attacking you.\n";
            } else
                oStr << mTarget->upHeShe() << " is attacking " << firstEnm->getName() << ".\n";

            /// print all the enemies if a CT or DM is looking
            if(isCt())
                oStr << mTarget->threatTable;
        }
        oStr << consider(mTarget);

        // pet code
        if(mTarget->isPet() && mTarget->getMaster() == this) {
            str = mTarget->listObjects(this, true);
            oStr << mTarget->upHeShe() << " ";
            if(str == "")
                oStr << "isn't holding anything.\n";
            else
                oStr << "is carrying: " << str << ".\n";
        }
    }
    printColor("%s", oStr.str().c_str());
    target->printEquipList(this);
    return(0);
}