コード例 #1
0
//sketch to join the originally irrelevant components (cylinders)
bool KW_CS2Surf::SketchJoin(vector<CPoint> UserScrPoint,GLdouble* modelview,GLdouble* projection,GLint* viewport)
{
    //get the cylinders selected
    vector<int> vecSelCylin;
    int iSSId=-1;
    Point_3 DstPoint;
    bool bResult=SJGetSelCylin(UserScrPoint,modelview,projection,viewport,vecSelCylin,iSSId,DstPoint);
    if (!bResult)
    {
        return false;
    }
    //stretch the first selected cylinder
    SJStretchCylin(this->vecSinglePoly.at(vecSelCylin.front()),DstPoint);
    //collect the cylinders in this subspace
    vector<KW_Mesh> vecCurrCylin;
    for (unsigned int i=0; i<this->vecSinglePoly.size(); i++)
    {
        if (vecSinglePoly.at(i).GetReserved()==iSSId)
        {
            vecCurrCylin.push_back(vecSinglePoly.at(i));
        }
    }
    //compute the union
    KW_Mesh ResultPolyh;
    ComputeUnionInSubspace(vecCurrCylin,ResultPolyh);
    ResultPolyh.SetReserved(iSSId);
    OBJHandle::UnitizeCGALPolyhedron(ResultPolyh,false,false);
    //update the cylinders stored in vecUnionPoly
    for (unsigned int i=0; i<this->vecUnionPoly.size(); i++)
    {
        if (this->vecUnionPoly.at(i).GetReserved()==iSSId)
        {
            this->vecUnionPoly.at(i)=ResultPolyh;
            break;
        }
    }
    //remove face points
    vector<int>::iterator IntIter=find(this->vecSubSurfSSId.begin(),this->vecSubSurfSSId.end(),iSSId);
    assert(IntIter!=this->vecSubSurfSSId.end());
    int iIndex=distance(this->vecSubSurfSSId.begin(),IntIter);
    vector<Point_3> vecNewSubPoint;
    vector<vector<int>> vecNewSubSurf;
    RemoveFaceTriangles(iSSId,ResultPolyh,this->vecvecvecFacePoint.at(iIndex),vecNewSubPoint,vecNewSubSurf);
    //update the points and triangles
    this->vecvecSubPoint.at(iIndex)=vecNewSubPoint;
    this->vecvecSubSurf.at(iIndex)=vecNewSubSurf;
    //stitch surface
    //stitch the submeshes together
    StitchMesh(this->vecvecSubPoint,this->vecvecSubSurf,this->InitPolyh);
    PostProcMesh();

    return true;
}
コード例 #2
0
bool KW_CS2Surf::SketchSplit(vector<CPoint> UserScrPoint,GLdouble* modelview,GLdouble* projection,GLint* viewport)
{
    //first filter to reduce the num of points on input curve
    GeometryAlgorithm compute;
    compute.ProcessCurverPoint(UserScrPoint,20.0);//15.0
    //get the cylinders selected
    vector<int> vecSelCylin;
    int iSSId=-1;
    bool bResult=SSGetSelCylin(UserScrPoint,modelview,projection,viewport,vecSelCylin,iSSId);
    if (!bResult)
    {
        return false;
    }
    //collect the cylinders in this subspace
    vector<KW_Mesh> vecSplitPoly,vecOtherPoly;
    for (unsigned int i=0; i<vecSelCylin.size(); i++)
    {
        vecSplitPoly.push_back(this->vecSinglePoly.at(vecSelCylin.at(i)));
    }
    for (unsigned int i=0; i<this->vecSinglePoly.size(); i++)
    {
        if (vecSinglePoly.at(i).GetReserved()==iSSId)
        {
            vector<int>::iterator IntIter=find(vecSelCylin.begin(),vecSelCylin.end(),i);
            if (IntIter==vecSelCylin.end())
            {
                vecOtherPoly.push_back(this->vecSinglePoly.at(i));
            }
        }
    }
    //compute the union
    KW_Mesh ResultPolyh;
    ComputeUnionInSubspace(vecSplitPoly,vecOtherPoly,ResultPolyh);
    ResultPolyh.SetReserved(iSSId);
    OBJHandle::UnitizeCGALPolyhedron(ResultPolyh,false,false);
    //update the cylinders stored in vecUnionPoly
    for (unsigned int i=0; i<this->vecUnionPoly.size(); i++)
    {
        if (this->vecUnionPoly.at(i).GetReserved()==iSSId)
        {
            this->vecUnionPoly.at(i)=ResultPolyh;
            break;
        }
    }

    //kw debug test
    if (this->CtrName=="skull.contour")
    {
        return true;
    }


    //remove face points
    vector<int>::iterator IntIter=find(this->vecSubSurfSSId.begin(),this->vecSubSurfSSId.end(),iSSId);
    assert(IntIter!=this->vecSubSurfSSId.end());
    int iIndex=distance(this->vecSubSurfSSId.begin(),IntIter);
    vector<Point_3> vecNewSubPoint;
    vector<vector<int>> vecNewSubSurf;
    RemoveFaceTriangles(iSSId,ResultPolyh,this->vecvecvecFacePoint.at(iIndex),vecNewSubPoint,vecNewSubSurf);
    //update the points and triangles
    this->vecvecSubPoint.at(iIndex)=vecNewSubPoint;
    this->vecvecSubSurf.at(iIndex)=vecNewSubSurf;
    //stitch surface
    //stitch the submeshes together
    StitchMesh(this->vecvecSubPoint,this->vecvecSubSurf,this->InitPolyh);
    PostProcMesh();

    return true;
}