bool ON_Brep::IsValidForV2( const ON_BrepTrim& trim ) const
{
    int ti = trim.m_trim_index;
    if ( ti < 0 || ti >= m_T.Count() )
        return false;
    if ( &trim != &m_T[ti] )
        return false;
    if ( trim.ProxyCurveIsReversed() )
        return false;
    if ( trim.Domain() != trim.ProxyCurveDomain() )
        return false;
    const ON_Curve * curve = trim.TrimCurveOf();
    if ( curve != trim.ProxyCurve() )
        return false;
    const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
    if ( 0 == nurbs_curve )
        return false;
    if ( !nurbs_curve->IsClamped(2) )
        return false;
    if ( nurbs_curve->m_dim != 2 )
        return false;
    if ( nurbs_curve->m_is_rat )
    {
        // 2 June 2003 Dale Lear - RR 8809 fix
        //    V2 likes end weights to be 1.0
        if ( nurbs_curve->m_cv[2] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[2] != 1.0 )
        {
            return false;
        }
    }

    if (    nurbs_curve->m_cv_count >= 4
            && 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
       )
    {
        // 14 April 2003 Dale Lear
        //     RR 8843 - V2 wants ends of this trim farther apart
        if ( trim.m_vi[0] != trim.m_vi[1] )
        {
            const ON_BrepLoop* loop = Loop(trim.m_li);
            if ( 0 != loop && loop->m_ti.Count() > 1 )
                return false;
        }
    }

    if ( curve->Domain() != trim.Domain() )
        return false;

    return true;
}
예제 #2
0
osg::Node* RhinoReader::BuildShadedFace(const ON_BrepFace* theFace)
{
    osg::ref_ptr<osg::Geode> aGeode = new osg::Geode();
    
    ON_NurbsSurface aSurface;

    if (theFace->GetNurbForm(aSurface) == 0)
    {
        return NULL;
    }

    osg::ref_ptr<osg::Geometry> aGeometry = new osg::Geometry();

    osg::ref_ptr<osg::Vec3Array> aUVPoints = new osg::Vec3Array();
    osg::ref_ptr<osg::Vec3Array> aPoints = new osg::Vec3Array();
    osg::ref_ptr<osg::Vec3Array> aBounds = new osg::Vec3Array();

    osg::ref_ptr<osgUtil::DelaunayTriangulator> dt = new osgUtil::DelaunayTriangulator();
    osg::ref_ptr<osgUtil::DelaunayConstraint> dc = new osgUtil::DelaunayConstraint();

    // add loop for the face.
    for (int i = 0; i < theFace->LoopCount(); ++i)
    {
        ON_BrepLoop* aLoop = theFace->Loop(i);

        if (aLoop->m_type == ON_BrepLoop::outer)
        {
            for (int j = 0; j < aLoop->TrimCount(); ++j)
            {
                ON_BrepTrim* aTrim = aLoop->Trim(j);

                const ON_Curve* aPCurve = aTrim->TrimCurveOf();
                if (aPCurve)
                {
                    ON_3dPoint aStartPoint = aPCurve->PointAtStart();
                    ON_3dPoint aEndPoint = aPCurve->PointAtEnd();

                    aUVPoints->push_back(osg::Vec3(aStartPoint.x, aStartPoint.y, 0.0));
                    aUVPoints->push_back(osg::Vec3(aEndPoint.x, aEndPoint.y, 0.0));
                }
            }
        }
        else if (aLoop->m_type == ON_BrepLoop::inner)
        {
            for (int j = 0; j < aLoop->TrimCount(); ++j)
            {
            }
        }
    }

    dc->setVertexArray(aBounds);
    dc->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, aBounds->size()));

    // triangulate the parametric space.
    //dt->addInputConstraint(dc);
    dt->setInputPointArray(aUVPoints);
    dt->triangulate();
    //dt->removeInternalTriangles(dc);

    for (osg::Vec3Array::const_iterator j = aUVPoints->begin(); j != aUVPoints->end(); ++j)
    {
        // evaluate the point on the surface
        ON_3dPoint aPoint = aSurface.PointAt((*j).x(), (*j).y());

        aPoints->push_back(osg::Vec3(aPoint.x, aPoint.y, aPoint.z));
    }

    //aGeometry->setVertexArray(aUVPoints);
    aGeometry->setVertexArray(aPoints);
    aGeometry->addPrimitiveSet(dt->getTriangles());

    aGeode->addDrawable(aGeometry);

    // use smoothing visitor to set the average normals
    //osgUtil::SmoothingVisitor sv;
    //sv.apply(*aGeode);

    return aGeode.release();
}