2

Given that g is a graphics object with primitives such as Lines and Polygons, how do you remove some of them? To add more primitives to an existing graphics object we can use Show, for instance: Show[g, g2] where g2 is another graphics object with other primitives. But how do you remove unwanted primitive objects? Take a look at the following

ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]

Output

Now, for the input form:

InputForm[
   ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]
 ]

Output

To create a wire frame from this object all we have to do is remove the polygons. As an extra we can also remove the vertex normals since they don't contribute to the wireframe.

Notice that to make a wireframe we can simply set PlotStyle -> None as an option in ListPlot3D. This gets rid of the Polygons but doesn't remove the VertexNormals.

To clarify the question. Given that

 g = ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, Mesh -> {1, 1}]

How do you remove some of the of the graphics primitives from g and how do you remove some of the options, i.e. VertexNormals? Note: option VertexNormals is an option of GraphicsComplex.

If this is not possible then maybe the next question would be, how do you obtain the data used to generate g to generate a new graphics object with some of the data obtained from g.

jmlopez
  • 4,853
  • 4
  • 40
  • 74

1 Answers1

6

One way is to use transformation rules. Given your

im = ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}},  Mesh -> {1, 1}]

You can do

newim = im /. {_Polygon :> Sequence[], (VertexNormals -> _) :> Sequence[]}

or, more compactly using Alternatives:

newim = im /. _Polygon | (VertexNormals -> _) :> Sequence[]

You could also use DeleteCases to get a similar effect:

newim = DeleteCases[im, (_Polygon | (VertexNormals -> _)), Infinity]

enter image description here

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Leonid Shifrin
  • 22,449
  • 4
  • 68
  • 100
  • @Leonid, well now I feel pretty dumb. Thank you for showing me all these different ways. – jmlopez Jun 11 '11 at 21:07
  • Leonid, is there any reason to leave the verbose form in your post? To me it just adds confusion. – Mr.Wizard Jun 11 '11 at 22:29
  • @Mr.Wizard I had an impression that less experienced users will find the first one easier to understand. I may be wrong. – Leonid Shifrin Jun 12 '11 at 10:23
  • Leonid, you surprise me, because in a prior exchange you said: "... it seems a little inelegant to give a name for the pattern if that name is never used. For someone not fully understanding the reasons for that, your intentions may look unclear, as if something was planned but forgotten." – Mr.Wizard Jun 12 '11 at 22:00
  • @Mr.Wizard Yes, you are right, regarding pattern names - those are not needed, I will edit to remove them. I rather meant a list of rules - seems easier to grasp than combining patterns with `Alternatives`. And as I said, I may be wrong. – Leonid Shifrin Jun 13 '11 at 08:37
  • I like that better. I added a link to Alternatives help; I hope you don't mind. – Mr.Wizard Jun 13 '11 at 08:41