예제 #1
0
void orthoview::set_projection(gp_Ax2 cs)
{
    gp_Ax2  actual_cs;
    gp_Dir  actual_X;

    // coord system & directions for desired projection
    X_dir = cs.XDirection();
    Y_dir = cs.YDirection();
    Z_dir = cs.Direction();

    // coord system of created view - same code as used in projection algos
    // actual_cs = gp_Ax2(gp_Pnt(0,0,0), gp_Dir(Z_dir.X(),Z_dir.Y(),Z_dir.Z()));

    // but as the file gets saved the projection direction gets rounded.
    // this can lead to choosing a different normal x-direction when the file
    // gets reloaded see issue #1909
    // we anticipate the actual_cs after reloading by rounding the Z_dir now
    const double x = round( Z_dir.X()  * 1e12 ) / 1e12;
    const double y = round( Z_dir.Y()  * 1e12 ) / 1e12;
    const double z = round( Z_dir.Z()  * 1e12 ) / 1e12;
    actual_cs = gp_Ax2(gp_Pnt(0,0,0), gp_Dir(x,y,z));

    actual_X = actual_cs.XDirection();

    // angle between desired projection and actual projection
    float rotation = X_dir.Angle(actual_X);

    if (rotation != 0 && abs(PI - rotation) > 0.05)
        if (!Z_dir.IsEqual(actual_X.Crossed(X_dir), 0.05))
            rotation = -rotation;

    calcCentre();

    //this_view->Direction.setValue(Z_dir.X(), Z_dir.Y(), Z_dir.Z());
    this_view->Direction.setValue(x,y,z);
    this_view->Rotation.setValue(180 * rotation / PI);
}
//!set up a hidden line remover and project a shape with it
void GeometryObject::projectShape(const TopoDS_Shape& input,
                                  const gp_Ax2 viewAxis)
{
    // Clear previous Geometry
    clear();

//*******
    gp_Dir x = viewAxis.XDirection();
    gp_Dir y = viewAxis.YDirection();
    gp_Dir z = viewAxis.Direction();
    Base::Vector3d vx(x.X(),x.Y(),x.Z());
    Base::Vector3d vy(y.X(),y.Y(),y.Z());
    Base::Vector3d vz(z.X(),z.Y(),z.Z());
//    Base::Console().Message("TRACE - GO::projectShape - %s viewAxis x: %s y: %s Z: %s\n",m_parentName.c_str(),
//                            DrawUtil::formatVector(vx).c_str(), DrawUtil::formatVector(vy).c_str(), DrawUtil::formatVector(vz).c_str());
//*******

    auto start = chrono::high_resolution_clock::now();

    Handle_HLRBRep_Algo brep_hlr = NULL;
    try {
        brep_hlr = new HLRBRep_Algo();
        brep_hlr->Add(input, m_isoCount);
        HLRAlgo_Projector projector( viewAxis );
        brep_hlr->Projector(projector);
        brep_hlr->Update();
        brep_hlr->Hide();
    }
    catch (...) {
        Standard_Failure::Raise("GeometryObject::projectShape - error occurred while projecting shape");
    }
    auto end   = chrono::high_resolution_clock::now();
    auto diff  = end - start;
    double diffOut = chrono::duration <double, milli> (diff).count();
    Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in HLRBRep_Algo & co\n",m_parentName.c_str(),diffOut);

    try {
        HLRBRep_HLRToShape hlrToShape(brep_hlr);

        visHard    = hlrToShape.VCompound();
        visSmooth  = hlrToShape.Rg1LineVCompound();
        visSeam    = hlrToShape.RgNLineVCompound();
        visOutline = hlrToShape.OutLineVCompound();
        visIso     = hlrToShape.IsoLineVCompound();
        hidHard    = hlrToShape.HCompound();
        hidSmooth  = hlrToShape.Rg1LineHCompound();
        hidSeam    = hlrToShape.RgNLineHCompound();
        hidOutline = hlrToShape.OutLineHCompound();
        hidIso     = hlrToShape.IsoLineHCompound();

//need these 3d curves to prevent "zero edges" later
        BRepLib::BuildCurves3d(visHard);
        BRepLib::BuildCurves3d(visSmooth);
        BRepLib::BuildCurves3d(visSeam);
        BRepLib::BuildCurves3d(visOutline);
        BRepLib::BuildCurves3d(visIso);
        BRepLib::BuildCurves3d(hidHard);
        BRepLib::BuildCurves3d(hidSmooth);
        BRepLib::BuildCurves3d(hidSeam);
        BRepLib::BuildCurves3d(hidOutline);
        BRepLib::BuildCurves3d(hidIso);
    }
    catch (...) {
        Standard_Failure::Raise("GeometryObject::projectShape - error occurred while extracting edges");
    }

}