Contour of a image made ​​by a polyline


#1

There are some way to cut the contour, made by a polyline, of a image?

Thanks


(Dale Fugier) #2

I’m not sure I understand what you are asking. Can you explain further. Sometimes pictures and geometry can be helpful. Are you using RhinoCommon or C++?


#3

Sorry, I try to explain better

I need create a object and apply the texture from the shape defined by a polyline applied to an image.

I have managed create an object with the contour defined by the polyline, but I like apply the texture of the image.

For example, in the next image, I’ve selected the shape, but I don’t know get the image’s texture inside the polyline

I’m working with RhinoCommon and Visual Studio 10


#4

Somebody knows if I can do it?


(Dale Fugier) #5

@andy, any suggestions?


#6

andy…any idea?


#7

Is it a flat polyline?

Else PlanarSrf and properties>material>color use your image?


#8

I need get the image’s texture delimited by the polyline.

I don’t understand that you want say


(Dale Fugier) #9

In order for us to answer SDK question, we need to know how you do this just using Rhino. If you are not sure how to do this just using Rhino, then I suggest re-posting this under the “Rhino for Windows” category. Once you have a workflow, then we can begin to help with providing an SDK solution.


#10

Oki

Thanks


#11

Anyone know how to do this


#12

Make a pictureframe where you got your picture. Put your polyline over it. Trim it. Then the surface has the shape of you polyline and the picture is cut off at those positions.

Think you mean this. Else I dont understand what you mean :stuck_out_tongue:


#13

Well… I need Trim the two objects, but I don’t know how to do it


#14

Any idea?


(Dale Fugier) #15

RhinoCommon does not have a way of creating a picture frame. You could always create a planar surface and then add a bitmap texture to it. Once created, create a polyline on the surface, extrude, and then use Rhino.Geometry.Brep.Split.


(Matthieu Arnold) #16

Hi,

I’ve got exactly the same question.

Now I know how to insert a PictureFrame (it was added since the conversation started):
Dim MyPictureFrameID As Guid = doc.Objects.AddPictureFrame(plane, dialog.FileName, False, myImage.Size.Width, myImage.Size.Height, True, True)

But I dont get how to trim the pictureframe with a rectangle? (with rhinocommon)
It works with the “trim” command in rhino.

Thanks for helping

Regards


(Dale Fugier) #17

Hi Matthieu,

A PictureFrame is just a surface. Thus, you’ll need to trim it just like you would any other surface.

– Dale


(Matthieu Arnold) #18

Hi, I’m trying to do this but it does not work. Somehow I can’t seem to cast the picture frame as a surface (MyPictureSurf is always Nothing):

        'check version
        If RhinoApp.Version.Major <= 5 And RhinoApp.Version.Minor < 11 Then
        Rhino.RhinoApp.WriteLine("ERROR: This command requires at least Rhino5 SR11")
        Return Result.Failure
        End If

        'Pick image
        Dim dialog As New OpenFileDialog()
        dialog.Filter = "Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.pcx;*.png;*.tif;*.tiff"
        dialog.Title = "Select deck image"
        Dim rc As DialogResult = dialog.ShowDialog()
        If rc <> DialogResult.OK Then
            Return Result.Cancel
        End If

        'Read image size
        Dim myImage As Image = Image.FromFile(dialog.FileName)
        Dim p0 As New Point3d(0, 0, 0)
        Dim p1 As New Point3d(myImage.Size.Width, 0, 0)
        Dim p3 As New Point3d(0, myImage.Size.Height, 0)
        Dim plane As Plane = New Rhino.Geometry.Plane(p0, p1, p3)

        'add the pictureframe
        Dim MyPictureFrameID As Guid = doc.Objects.AddPictureFrame(plane, dialog.FileName, False, myImage.Size.Width, myImage.Size.Height, True, True)
        Dim MyPictureFrameObj As RhinoObject = doc.Objects.Find(MyPictureFrameID)
        Dim MyPictureSurf As Rhino.Geometry.Surface = TryCast(MyPictureFrameObj.Geometry, Rhino.Geometry.Surface)
        doc.Views.Redraw()

        'Pick the cutting rectangle
        Dim corners As Point3d()
        Dim res As Result = Rhino.Input.RhinoGet.GetRectangle(corners)
        If res <> Result.Success Then
            Return res
        End If
        Dim CuttingPt0 As Point3d = corners(0)
        Dim CuttingPt1 As Point3d = corners(1)
        Dim CuttingPt3 As Point3d = corners(3)
        Dim CuttingPt2 As New Point3d(CuttingPt1.X, CuttingPt3.Y, 0)
        Dim TrimmingRect As New Rhino.Geometry.Rectangle3d(plane, CuttingPt0, CuttingPt2)
        doc.Objects.AddPolyline(TrimmingRect.ToPolyline)
        doc.Views.Redraw()

        'trim the pictureframe
        Dim u0, u2, v0, v2 As Double
        MyPictureSurf.ClosestPoint(CuttingPt0, u0, v0)
        MyPictureSurf.ClosestPoint(CuttingPt2, u2, v2)
        Dim u As New Rhino.Geometry.Interval(u0, u2)
        Dim v As New Rhino.Geometry.Interval(v0, v2)
        MyPictureSurf.Trim(u, v)
        doc.Views.Redraw()

(Dale Fugier) #19

Hi Matthieu,

Try casting as a Rhino.Geometry.Brep.

– Dale


(Matthieu Arnold) #20

Ok, casting as Rhino.Geometry.Brep works but how do I trim a Brep with a closed polyline?
I just want to do the same as the trim command in rhino, but I couldn’t find any example on the web.

I tried to trim with plans created from my rectangle but it doesn’t work and it does not feel to be the best way to do this anyway:
MyPictureSurf.Trim(New Plane(CuttingPt0, CuttingPt1, New Point3d(CuttingPt0.X, CuttingPt0.Y, CuttingPt0.Z + 100)), 0.2)