[vtkusers] vtkCubeSource code question
Bill Lorensen
bill.lorensen at gmail.com
Thu Nov 5 08:04:36 EST 2009
1) It creates 24 points and 6 cells (not 6 points and 24 cells as you
stated). Each cell is a quad and corresponds to each face of the cube.
2) Each face (cell) has its own set of points because each point will
have its own normal and texture coordinate. A point can only have a
single normal or texture coordinate. Each point normal is "normal" to
the face it belongs to. If the cells shared the corner points, then a
rendered cube would appear to have flat faces.
3) The order of the points defining a cell is consistent so that each
cell is numbered in a counterclockwise ordering when viewed from the
outside. Draw a picture to understand.
On Wed, Nov 4, 2009 at 6:33 PM, Anja Ende <anja.ende at googlemail.com> wrote:
> Hello all,
>
> I have a question about vtkCubeSource. I was going through the code
> and have a bit of trouble understanding the following bit:
>
> It seems that it creates 6 points and 24 cells. Can someone explain
> the VTK concept of cells? I am guessing a point is a simple 3D point,
> but I am a bit confused about what the vtkCell is.
>
> I see that it is creating 6 polys (I am assuming one for each cube
> face) and 24 points. So, it is storing the 4 vertices for each cube
> face. I am sure there is a good reason for this but why does it not
> store only 8 points in a specified order and create the cube from that
> as the other points are redundant and shared between different
> faces......
>
> Also, then I am stuck in particular bit of code.... I am hoping
> someone can help me understand this.
>
> It seems that the following code constructs 2 faces of the cube...
>
> for (x[0]=this->Center[0]-this->XLength/2.0, n[0]=(-1.0), n[1]=n[2]=0.0, i=0;
> i<2; i++, x[0]+=this->XLength, n[0]+=2.0)
> {
> for (x[1]=this->Center[1]-this->YLength/2.0, j=0; j<2;
> j++, x[1]+=this->YLength)
> {
> tc[1] = x[1] + 0.5;
> for (x[2]=this->Center[2]-this->ZLength/2.0, k=0; k<2;
> k++, x[2]+=this->ZLength)
> {
> tc[0] = (x[2] + 0.5) * ( 1 - 2*i );
> newPoints->InsertNextPoint(x);
> newTCoords->InsertNextTuple(tc);
> newNormals->InsertNextTuple(n);
> }
> }
> }
> pts[0] = 0; pts[1] = 1; pts[2] = 3; pts[3] = 2;
> newPolys->InsertNextCell(4,pts);
> pts[0] = 4; pts[1] = 6; pts[2] = 7; pts[3] = 5;
> newPolys->InsertNextCell(4,pts);
>
> So, I can understand the order of points in the first face as 0, 1, 3,
> 2...However, the order of points on the second face (4, 6, 7, 5) is in
> the other direction in the sense that the order of points is reversed.
> I am sure there is a good topological reason for this. Can someone
> tell me why the order is reversed for the second face here...
>
> One further question...what exactly is it doing here with the normals
> calculation?
>
> I would really appreciate it if someone could help me with these
> questions. Many thanks to those who helped me with the earlier
> question on how to try and generate this geometry...
>
> Many thanks,
>
> Anja
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list