Project to 2D

I'd like to project a part to 2D using hidden line removal with HLRAlgo_Projector, but the projection is off and I can't figure out why. I've disabled the perspective transformation and the coordinate system is perfectly top down and it still looks like it's being projected with a perspective. Here's a code snippet (using pyOCCT), and I've attached a screenshot of the generated lines.

Please let me know what needs to be changed to render an orthographic projection of the part.

# Define the transformation for the isometric projection
direction = gp_Dir(0.0, 1, 0)
point = gp_Pnt(0, 0, 0)
coordinate_system_3d = gp_Ax3(point, direction)

# Create a transformation from the coordinate system
transformation = gp_Trsf()
transformation.SetTransformation(coordinate_system_3d)

# Create the projector with orthogonal projection
projector = HLRAlgo_Projector(transformation, False, 0.0)

hlr = HLRBRep_Algo()
hlr.Add(shape.wrapped)

hlr.Projector(projector)
hlr.Update()
hlr.Hide()

hlr_shapes = HLRBRep_HLRToShape(hlr)
Attachments: 
Dmitrii Pasukhin's picture

Hello, please try to use gp_Ax2 instead of (gp_Trsf False 0.0). Just single gp_Ax2

Unfortunatelly, I have no more ideas.

Best regards, Dmitrii.

Alexander Kaszynski's picture

Worked! Here's the part I changed:

ax2 = gp_Ax2()
ax2.SetLocation(gp_Pnt(0.0, 0.0, 0.0))
ax2.SetDirection(gp_Dir(0.0, 1.0, 0.0))
ax2.SetXDirection(gp_Dir(1.0, 0.0, 0.0))

projector = HLRAlgo_Projector(ax2)

hlr = HLRBRep_Algo()
hlr.Add(shape.wrapped)

hlr.Projector(projector)
hlr.Update()
hlr.Hide()

Thanks for your help.

Shing Liu's picture

Hello, You can check the examples in the document: HLR Examples https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_10_1

For exact HLR algorithm, you need HLRBRep_HLRToShape to extract the result.

// Build The algorithm object 
myAlgo = new HLRBRep_Algo(); 

// Add Shapes into the algorithm 
TopTools_ListIteratorOfListOfShape anIterator(myListOfShape); 
for (;anIterator.More();anIterator.Next()) 
myAlgo->Add(anIterator.Value(),myNbIsos); 

// Set The Projector (myProjector is a HLRAlgo_Projector) 
myAlgo->Projector(myProjector); 

// Build HLR 
myAlgo->Update(); 

// Set The Edge Status 
myAlgo->Hide(); 

// Build the extraction object : 
HLRBRep_HLRToShape aHLRToShape(myAlgo); 

// extract the results : 
TopoDS_Shape VCompound           = aHLRToShape.VCompound(); 
TopoDS_Shape Rg1LineVCompound                            = 
aHLRToShape.Rg1LineVCompound(); 
TopoDS_Shape RgNLineVCompound                            = 
aHLRToShape.RgNLineVCompound(); 
TopoDS_Shape OutLineVCompound                            = 
aHLRToShape.OutLineVCompound(); 
TopoDS_Shape IsoLineVCompound                            = 
aHLRToShape.IsoLineVCompound(); 
TopoDS_Shape HCompound           = aHLRToShape.HCompound(); 
TopoDS_Shape Rg1LineHCompound                            = 
aHLRToShape.Rg1LineHCompound(); 
TopoDS_Shape RgNLineHCompound                            = 
aHLRToShape.RgNLineHCompound(); 
TopoDS_Shape OutLineHCompound                            = 
aHLRToShape.OutLineHCompound(); 
TopoDS_Shape IsoLineHCompound                            = 
aHLRToShape.IsoLineHCompound(); 
Alexander Kaszynski's picture

Follow up question: Is there any way to get the original faces associated with each extracted edge?

Dmitrii Pasukhin's picture

Looking into source code i dont see the options for that.

Shing Liu's picture

You can get the original edge for the extracted edge.

Alexander Kaszynski's picture

Cool! Could you please let me know how to do that?

Shing Liu's picture

Sorry, I misunderstand.

You can get the hidden/visible part of shape edges by give the shape to VCompound, HCompound, .etc.

TopoDS_Shape VCompound (const TopoDS_Shape& S);
TopoDS_Shape OutLineVCompound (const TopoDS_Shape& S);
TopoDS_Shape HCompound (const TopoDS_Shape& S);
TopoDS_Shape OutLineHCompound (const TopoDS_Shape& S);