当前位置: 首页>>代码示例>>C++>>正文


C++ AABB::clip方法代码示例

本文整理汇总了C++中AABB::clip方法的典型用法代码示例。如果您正苦于以下问题:C++ AABB::clip方法的具体用法?C++ AABB::clip怎么用?C++ AABB::clip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AABB的用法示例。


在下文中一共展示了AABB::clip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getClippedAABB

AABB Triangle::getClippedAABB(const Point *positions, const AABB &aabb) const {
    /* Reserve room for some additional vertices */
    Point3d vertices1[MAX_VERTS], vertices2[MAX_VERTS];
    int nVertices = 3;

    /* The kd-tree code will frequently call this function with
       almost-collapsed AABBs. It's extremely important not to introduce
       errors in such cases, otherwise the resulting tree will incorrectly
       remove triangles from the associated nodes. Hence, do the
       following computation in double precision! */
    for (int i=0; i<3; ++i)
        vertices1[i] = Point3d(positions[idx[i]]);

    for (int axis=0; axis<3; ++axis) {
        nVertices = sutherlandHodgman(vertices1, nVertices, vertices2, axis, aabb.min[axis], true);
        nVertices = sutherlandHodgman(vertices2, nVertices, vertices1, axis, aabb.max[axis], false);
    }

    AABB result;
    for (int i=0; i<nVertices; ++i) {
#if defined(SINGLE_PRECISION)
        for (int j=0; j<3; ++j) {
            /* Now this is really paranoid! */
            double pos_d = vertices1[i][j];
            float  pos_f = (float) pos_d;
            float  pos_roundedDown, pos_roundedUp;

            if (pos_f < pos_d) {
                /* Float value is too small */
                pos_roundedDown = pos_f;
                pos_roundedUp = nextafterf(pos_f,
                                           std::numeric_limits<float>::infinity());
            } else if (pos_f > pos_d) {
                /* Float value is too large */
                pos_roundedUp = pos_f;
                pos_roundedDown = nextafterf(pos_f,
                                             -std::numeric_limits<float>::infinity());
            } else {
                /* Double value is exactly representable */
                pos_roundedDown = pos_roundedUp = pos_f;
            }

            result.min[j] = std::min(result.min[j], pos_roundedDown);
            result.max[j] = std::max(result.max[j], pos_roundedUp);
        }
#else
        result.expandBy(vertices1[i]);
#endif
    }
    result.clip(aabb);

    return result;
}
开发者ID:tomka,项目名称:mitsuba-renderer,代码行数:53,代码来源:triangle.cpp

示例2: findBestPlane

void AABBTree::findBestPlane(const vector<Triangle>& T, const AABB& V, SplittingPlane& p_est, float& C_est, PlaneSide& pside_est)
{
    C_est = numeric_limits<float>::max();

    for(int axis=0; axis<3; axis++) {
        vector<SplitEvent> events;
        events.reserve(T.size()*2);

        for(int i=0; i<T.size(); ++i) {
            auto ti = T[i];
            AABB tibb = V.clip(ti);

            if(tibb.isPlanar()) {
                events.push_back(SplitEvent(ti, axis, tibb.minPos(axis), SplitEvent::LyingOnPlane));
            }
            else {
                events.push_back(SplitEvent(ti, axis, tibb.minPos(axis), SplitEvent::StartingOnPlane));
                events.push_back(SplitEvent(ti, axis, tibb.maxPos(axis), SplitEvent::EndingOnPlane));
            }
        }

        // sort the events
        sort(events.begin(), events.end());

        // test every candidate plane
        int NL = 0, NP = 0, NR = T.size();
        for(int i=0; i<events.size(); ++i) {
            auto p = events[i].p;

            int tLyingOnPlane = 0, tEndingOnPlane=0, tStartingOnPlane=0;
            while( i<events.size() && events[i].p.pe == p.pe && events[i].type == SplitEvent::EndingOnPlane ) {
                ++tEndingOnPlane;
                i++;
            }
            while( i<events.size() && events[i].p.pe == p.pe && events[i].type == SplitEvent::LyingOnPlane ) {
                ++tLyingOnPlane;
                i++;
            }
            while( i<events.size() && events[i].p.pe == p.pe && events[i].type == SplitEvent::StartingOnPlane ) {
                ++tStartingOnPlane;
                i++;
            }

            NP = tLyingOnPlane;
            NR -= tLyingOnPlane;
            NR -= tEndingOnPlane;

            float C;
            PlaneSide ps;
            SAH(p, V, NL, NR, NP, C, ps);

            if(C < C_est) {
                C_est = C;
                p_est = p;
                pside_est = ps;
            }
            NL += tStartingOnPlane;
            NL += tLyingOnPlane;
            NP = 0;
        }
    }
}
开发者ID:zhuangfangwang,项目名称:CSCE647,代码行数:62,代码来源:aabbtree.cpp

示例3: getClippedAABB

AABB Shape::getClippedAABB(const AABB &box) const {
	AABB result = getAABB();
	result.clip(box);
	return result;
}
开发者ID:AdrianJohnston,项目名称:ShapeNetRender,代码行数:5,代码来源:shape.cpp


注:本文中的AABB::clip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。