[vtkusers] vtkCubeSource code question

Anja Ende anja.ende at googlemail.com
Wed Nov 4 18:33:32 EST 2009


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



More information about the vtkusers mailing list