[vtkusers] how to get the details about the object created by vtk sources?

Shriram Iyer shriram.uc at gmail.com
Mon Oct 22 20:25:59 EDT 2007


Toron,

You are getting the error because you've not included <vtkPolyData.h>
Adding this should help you compile the code. Also remove '#include "
vtkIdType.h". Such a file doesn't exist. vtkIdType is defined in vtkPoints.h
.

If you want to identify the vertex with the max X value and identify
surfaces connected to this vertex, you can try the following:

double maxX = -9999;
vtkIdType maxXid = -1;
for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
{
    double Pt[3];
    points->GetPoint(i, Pt);
    if (Pt[0] > maxX)
    {
         maxX = Pt[0];
         maxXid = i;
    }
}
double Pt[3];
points->GetPoint(maxXid, Pt);
// you can move the vertex here by using points->SetPoint(maxXid, newPt);

// each surface on the cone is a cell
for (vtkIdType i = 0; i < cone->GetOutput()->GetNumberOfCells(); i++)
{
    int numPts;
    vtkIdType* pts;
    cone->GetOutput()->GetCellPoints(i, numPts, pts)
    for (vtkIdType j = 0; j < numPts; j++)
    {
         if (*pts++ == maxXid)
              // cell i is a surface connected to vertex with max X
    }
}

HTH.
Shriram


On 10/22/07, Toron J. <ji_wi at yahoo.com> wrote:
>
> Hi Shriram,
>
> Thanks for response!
>
> I got the error message "error: invalid use of incomplete type 'struct
> vtkPolyData' " related to the line "points =
> cone->GetOutput()->GetPoints();" when I compiled my program. I do not know
> how to correct it.
>
> Actually I want to move the vertex with the max X value of the cone and
> change the colors of the surfaces conjoint to this vertex. So i have to get
> all the vertices information including the each x-y-z and the points-index
> (rendering order) of each surface.
>
> Toron
>
> my codes is here
> --------------------------------------------------------------
> #include "vtkPolyDataMapper.h"
> #include "vtkRenderWindow.h"
> #include "vtkCamera.h"
> #include "vtkActor.h"
> #include "vtkRenderer.h"
> #include "vtkPoints.h"
> #include "vtkCellArray.h"
> #include "vtkIdType.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkInteractorStyleTrackballCamera.h"
>
> int main( int argc, char *argv[] )
> {
>   vtkConeSource *cone = vtkConeSource::New();
>   cone->SetHeight( 3.0 );
>   cone->SetRadius( 1.0 );
>   cone->SetResolution( 10 );
>
>   vtkPoints* points = vtkPoints::New();
>   points = cone->GetOutput()->GetPoints();
>
>   for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
>   {
>     double Pt[3];
>     points->GetPoint(i, Pt);
>     // ...
>     // Pt will now have the x, y, z coordinates of vertex i.
>   }
>
>   //vtkCellArray *indexes = vtkCellArray::New();
>   //indexes = cone->GetOutput()->GetPoints();
>
>   vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
>   coneMapper->SetInput( cone->GetOutput() );
>
>   vtkActor *coneActor = vtkActor::New();
>   coneActor->SetMapper( coneMapper );
>
>   vtkRenderer *ren1= vtkRenderer::New();
>   ren1->AddActor( coneActor );
>   ren1->SetBackground( 0.1, 0.2, 0.4 );
>
>   vtkRenderWindow *renWin = vtkRenderWindow::New();
>   renWin->AddRenderer( ren1 );
>   renWin->SetSize( 300, 300 );
>
>   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>   iren->SetRenderWindow(renWin);
>   iren->Initialize();
>   iren->Start();
>
>   cone->Delete();
>   coneMapper->Delete();
>   coneActor->Delete();
>   ren1->Delete();
>   renWin->Delete();
>
>   return 0;
> }
> --------------------------------------------------------------
>
>
>
>
> *Shriram Iyer <shriram.uc at gmail.com>* wrote:
>
> Toron,
>
> I'm not quite sure what you are trying to do here. If you just want to the
> location of
> each vertex in the cone, you can use following code.
>
> vtkPoints* points = vtkPoints::New();
> points = cone->GetOutput()->GetPoints();
>
> for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
> {
>   double Pt[3];
>   points->GetPoint(i, Pt);
>   // Pt will now have the x, y, z coordinates of vertex i.
>  ...
> }
>
> HTH.
> Shriram
>
> On 10/22/07, Toron J. <ji_wi at yahoo.com> wrote:
> >
> > Thanks, Shriram.
> >
> > I do know how to read 'cone->GetOutput()->GetPoints()' you suggested. So
> > I tired to add the below codes.
> >
> > -------------------------------------------------------------------------
> >   vtkPoints *points = vtkPoints::New();
> >     points = cone->GetOutput()->GetPoints();
> >
> >   vtkCellArray *indexes = vtkCellArray::New();
> >     indexes = cone->GetOutput()->GetPoints();
> > ------------------------------------------------------------------------
> >
> > They did work. Could you correct them or let me know any example like
> > this?
> >
> > Toron
> >
> >
> >
> >
> >
> > *Shriram Iyer < shriram.uc at gmail.com>* wrote:
> >
> > Use cone->GetOutput()->GetPoints() to get the vertices.
> >
> > Shriram
> >
> > On 10/22/07, Toron J. <ji_wi at yahoo.com > wrote:
> > >
> > > Hi All,
> > >
> > > I used the following codes to build a simple cone.
> > > ---------------------------------------------------------------------------------------
> > >
> > >   vtkConeSource *cone = vtkConeSource::New();
> > >       cone->SetHeight( 3.0 );
> > >       cone->SetRadius( 1.0 );
> > >       cone->SetResolution( 6 );
> > >
> > >   vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
> > >       coneMapper->SetInput( cone->GetOutput() );
> > >
> > > --------------------------------------------------------------------------------------
> > > Does any one can help me to know how to get the position (x,y,z) of
> > > each vertex and the rendering index?      Thanks in advance!
> > >
> > > Toron
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam protection around
> > > http://mail.yahoo.com
> > >
> > > _______________________________________________
> > > This is the private VTK discussion list.
> > > Please keep messages on-topic. Check the FAQ at:
> > > http://www.vtk.org/Wiki/VTK_FAQ
> > > Follow this link to subscribe/unsubscribe:
> > > http://www.vtk.org/mailman/listinfo/vtkusers
> > >
> > >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071022/d7b758e5/attachment.htm>


More information about the vtkusers mailing list