Displaying a Face in 2D

Hello all,

When set in a 2D view (View->SetProj(V3d_Zpos)), what is the best topology to display a shape? It sounds like a weird question, bear with me...

I have a setup whereby the user can create (2D) shape outlines using AIS_Point() and AIS_Line(). When the shape is closed, I'm creating an AIS_ColoredShape() from the outline, but its not being displayed.

In particular, I'm trying to do this via a Face - but not sure if this the best medium to use, as I can't get it to close?

Not sure whether its the non-closing face which is causing the problem, or simply the AIS_Shape() doesn't want to display in a Z-down view?

Any thoughts, code below?...

Mat

{
    unsigned i;
    gp_Pnt p1, p2;
    TopoDS_Wire aWire;
    TopoDS_Face aFace;
    BRepBuilderAPI_MakeWire mkWire;
    BRepBuilderAPI_MakePolygon aPoly;


    //--------------create polygon from stored points-------------------
    for(i=0; i<m_vVertexes.size(); i++)
    {
        p1.SetX(m_vVertexes[i].X());
        p1.SetY(m_vVertexes[i].Y());
        aPoly.Add(p1);
    }
    aPoly.Close();
    aWire = aPoly.Wire();

    //--------------create face from polygon-------------------------
    gp_Pln aPln(gp::XOY());
    aFace = BRepBuilderAPI_MakeFace(aPln, aWire);

#ifdef _DEBUG
    qDebug() << "Face Closed: " << aFace.Closed();  //SHOWS FALSE
#endif

    //-------------create AIS shape to display----------------------

    Handle(AIS_ColoredShape) myAIS_Shape = new AIS_ColoredShape(aFace);
    myAIS_Shape->SetColor(Quantity_Color(Quantity_NOC_DEEPSKYBLUE1));

    m_AIScontext->Display(myAIS_Shape, true);

    //NOTHING SHOWN 
}
gkv311 n's picture

Well, the code looks working for me for a simple shape:

std::vector<gp_Pnt> m_vVertexes = {
  gp_Pnt(0,0,0),
  gp_Pnt(10,0,0),
  gp_Pnt(10,10,0)
};

Make sure to call V3d_View::FitAll() to fit the scene.

Mat M's picture

How very odd. Thanks for checking, at least I know where not to look!

As my points and lines are showing up fine, I'm wondering two things...
1. I've got a problem with my view setup (defaulting to displaying lines but not faces)?
2. Unexpected transparency on the face

Weirdly, select detection of the face works when I click it, it just isn't visible.

Difficult to pull all the setup together in one place, but does this look any different to your setup?...

    Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection();
    Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (aDisp, false);
    // lets QOpenGLWidget to manage buffer swap
    aDriver->ChangeOptions().buffersNoSwap = true;
    // don't write into alpha channel
    aDriver->ChangeOptions().buffersOpaqueAlpha = true;
    // offscreen FBOs should be always used
    aDriver->ChangeOptions().useSystemBuffer = false;

    // create viewer
    myViewer = new V3d_Viewer (aDriver);
    
    myViewer->SetDefaultBackgroundColor (Quantity_NOC_IVORY);

    myViewer->SetDefaultLights();
    myViewer->SetLightOn();

    myView = myViewer->CreateView();
    myView->SetImmediateUpdate (false);

    // create AIS context
    myContext = new AIS_InteractiveContext (myViewer);

    if (is2DWindow)
    {
        myViewer->ActivateGrid (Aspect_GT_Rectangular, Aspect_GDM_Lines);

        myGrid = myViewer->Grid();
        myGrid->SetColors(Quantity_NOC_GREEN1, Quantity_NOC_GREEN3);

        //turn off 3D controls
        AIS_ViewController::SetAllowRotation(false);
        AIS_ViewController::SetAllowPanning (true);
        AIS_ViewController::SetAllowZooming(true);

        //set camera to top-down facing
        myView->SetProj(V3d_Zpos);
        myView->Zoom(-100,-100,+100,+100);
       
    }

Mat M's picture

Solved!

Missing a line from the display setup:

myContext->SetDisplayMode(AIS_Shaded, Standard_False);

Thanks!