Help needed: Projection of a shape on a plane

Forums: 

Hi together!

Currently i am working on a little project using pythonocc, and have a problem I can't get my head around.

My problem is the following:

I have a solid and a plane. I would like to project the solid onto this plane to create a new 2 shape (the "outline" of the solid). Then, i would like to extrude this new created outline to create a new solid.

This picture illustrates the projection from which i would like to create the new solid:
https://i.stack.imgur.com/eVq7h.png

I would really appreciate any help or ideas which could help me here!

Best,
John

Matt L's picture

Picture is a little unclear.
Do you want to project the whole silhouette of the shape?
Also, is it a perfectly orthogonal projection onto the plane? or are you indicating there is a vanishing point you the projection is converging to?

John Simac's picture

Hi, yes the whole silhouette of the shape in a perfectly orthogonal projection is what i meant. I see that the picture is actually wrong, since there isn't actually a vanishing point, just a defined plane

Matt L's picture

I'm not sure what's available to you in python (i primarily use C++) so apologies if some of this this isn't relevant.
I think a good place to look is the HLRBRep package. Looks like it can be used to get projected curves of a Brep onto the plane at origin. However, in my digging i didn't see a native "silhouette" functionality, but you can aggregate a bunch of different types of curves together, and maybe look into doing some culling and trimming to get what you desire.

To get the curves:
create an HLRBRep_Algo and add your shape to it
add a projector (HLRAlgo_Projector) to the algo to define the direction via transformation
call update and hide on the algo (hide seems to filter hidden geometry)
create an HLRBRep_HLRToShape and pass it the algo

you can then use HLRBRep_HLRToShape functions to get the compounds of the relevant geometry you want.
I found calling VCompound() and OutLineVCompound() to be satisfactory for my tests, but you can mess around with it.

after you get all of those curves, you will have to figure out the best way for culling/trimming them, because im not sure the best approach for that.

Sorry again if this is not available via python

John Simac's picture

Thanks for your reply! Ill see whats available in python, but your reply gives me a good starting point. I will definitely share whether i can get it to work.

John Simac's picture

I finally had some time to try it a bit. So far, thanks to Matt, i was able to get a wire from a projection. However, i think that my code is not correct so far, in particular i struggle with the transform of the projector. I've tried to use a vector as input for HLRAlgo_Projector().Transform(vec), but that doesn't seem to do anything. The HLRAlgo_Projector().Set(transform, perspective, focus) does seem to change something, however the result looks just broken.
Of course there could be also something wrong with how i try to visualize it, since i just make a wire from the edges without ordering them in any form, I am not sure how to do that right now to just create the outline of the body.
Anyway, i would be happy for any suggestions!

The code so far:

step_reader = STEPControl_Reader()
step_reader.ReadFile('./Example.STEP')
step_reader.TransferRoot()
shape = step_reader.Shape()

pnt1 = gp_Pnt(0,0,0)
dir1 = gp_Dir(0,1,0)

#vec = gp_Vec(pnt1, pnt2)
ax1 = gp_Ax1(pnt1, dir1)
trsf = gp_Trsf()
trsf.SetRotation(ax1, 0)

hlbrep = HLRBRep_Algo()
hlbrep.Add(shape)

projector = HLRAlgo_Projector()
pers = projector.Perspective()
#projector.Transform(vec)
projector.Set(trsf, pers, 1)

hlbrep.Projector(projector)
hlbrep.Update()
hlbrep.Hide()

tpshape = HLRBRep_HLRToShape(hlbrep)

newShape = tpshape.VCompound()

builder_wire = BRepBuilderAPI_MakeWire()
for edge in edges:
builder_wire.Add(edge)

wire = builder_wire.Shape()

my_renderer = x3dom_renderer.X3DomRenderer()
my_renderer.DisplayShape(wire)
my_renderer.render()

Jules Zweekhorst's picture

Hi John,
I was wondering if you solved your problem since I'm facing a similar issue. I'm also trying to obtain the silhouette of a object and extrude it. I've manage to get the outline however I can't seem to make an solid out of the outline I've created.
Hope you could provide me some insights.

Cheers,
Jules