[vtkusers] vtkDelauany2D triangulation--But where are the triangles????
Sylvain Jaume
sylvain.jaume at kitware.com
Mon Nov 7 09:07:56 EST 2005
Hi Dhaniram Kshirsagar,
vtkDelaunay2D takes points at its input, and gives triangles at its ouput.
Read http://www.vtk.org/doc/nightly/html/classvtkDelaunay2D.html
More information in the VTK book:
http://www.kitware.com/products/vtktextbook.html
You may find this code snippet useful:
vtkPoints *newPoints = vtkPoints::New();
newPoints->InsertNextPoint( 0, 0, 0 );
newPoints->InsertNextPoint( 1, 0, 0 );
// create more points
vtkPolyData *polyData = vtkPolyData::New();
polyData->SetPoints( newPoints );
newPoints->Delete();
vtkDelaunay2D *delaunay2D = vtkDelaunay2D::New();
delaunay2D->SetInput( polyData );
polyData->Delete();
delaunay2D->Update();
int npts, *pts;
delaunay2D->GetPolys()->InitTraversal();
while ( delaunay2D->GetPolys()->GetNextCell( npts, pts ) )
{
cout << "points in the triangle: " << pts[0] << " " << pts[1] << " "
<< pts[2] << "\n";
}
Cheers,
Sylvain
Dhaniram Kshirsagar wrote:
> Hi Sylvain,
>
> ---->>>>>Do you mean that you get the input triangles at the output?
> Yes I made some sequential polys like this...
>
> int numPts = Points->GetNumberOfPoints();
> for( int idx=0; idx< numPts; )
> {
> int nPoly[3];
> nPoly[0] = idx;
> nPoly[1] = ++idx;
> nPoly[2] = ++idx;
> *vtkPolys*->InsertNextCell( 3, nPoly );
> }
>
> *vtkPolys --> input to vtkPolyData which already contains the vtkPoints.*
> **
> ---->>>>>You do not need to set the polys.
>
> You mean to say I need to input *only points*
> (vtkPoints->vtkPolyData->vtkDelaunay2D)?
> and i will get the triangles at output? no cellarray for polys?
>
> If yes please let me know the code snippet for the same which will
> take points and will result in polys(triangles).
>
> Thanks for the reply.
>
> Thankx
>
>
> 2005/11/5, Sylvain Jaume <sylvain.jaume at kitware.com
> <mailto:sylvain.jaume at kitware.com>>:
>
> Hi Dhaniram Kshirsagar,
>
> Do you mean that you get the input triangles at the output?
> You do not need to set the polys.
>
> Cheers,
> Sylvain
>
> Dhaniram Kshirsagar wrote:
>
> > Hi Sylvain,
> >
> > After setting the vtkcellarray(for polys) in vtkpolydata (which is
> > input to the delaunay2d), Now I am able to get the triangles.
> >
> > Thankx
> >
> >
> > 2005/11/4, Sylvain Jaume <sylvain.jaume at kitware.com
> <mailto:sylvain.jaume at kitware.com>
> > <mailto:sylvain.jaume at kitware.com
> <mailto:sylvain.jaume at kitware.com>>>:
> >
> > Hi Dhaniram Kshirsagar,
> >
> > You don't need to use delaunay->SetSource().
> > Use it only if you want constrained Delaunay.
> >
> > Cheers,
> > Sylvain
> >
> > Dhaniram Kshirsagar wrote:
> >
> > > Hi,
> > >
> > > I searched the entire mail archive for answer to my
> problem, but
> > found
> > > only problems no solutions to them.
> > >
> > > My problem is, I have input points in the form of x, y and
> z (large
> > > numbers(double type)) and i want the output as the set of
> triangles,
> > > however i am getting only the
> > > vertics.
> > >
> > > Here is the code snippet that i am using to get the output
> as set of
> > > triangles.
> > >
> > > vtkDelaunay2D* pDelny = vtkDelaunay2D::New( );
> > > vtkPolyData* pPointSet = vtkPolyData::New( );
> > > vtkPoints* pPoints = vtkPoints::New( );
> > >
> > > //collects the points i.e. x , y, and z
> > > GetPoints( pPoints );
> > >
> > > pPointSet->SetPoints( pPoints );
> > >
> > > //now generate the vtk file
> > > vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
> > > writer->SetFileName( "c:\\earth.vtk");
> > > writer->SetInput( pPointSet );
> > > writer->Write(); //throws an exception
> > > writer->Update();
> > > * /***the generated vtk file contains the
> only one
> > fixed
> > > value***/
> > > ///However i am not usig this file
> > > *
> > > pDelny->SetTolerance( 0.001 );
> > > //pDelny->SetBoundingTriangulation(1);
> > > pDelny->SetAlpha( 1 );
> > > //pDelny->BoundingTriangulationOff();
> > > //pDelny->SetOffset( 1000 );
> > >
> > > pDelny->SetInput(pPointSet);
> > > pDelny->SetSource( pPointSet );
> > > pDelny->Update();
> > >
> > >
> > > vtkPolyData* pVtkData = pDelny->GetOutput( );
> > > int nsize = pVtkData->GetNumberOfCells(); //returned the
> same
> > number
> > > as the number of points
> > > vtkCellArray* cellPol = pVtkData->GetPolys(); //zero returned
> > > int numpol = cellPol->GetNumberOfCells();
> > > vtkCellArray* cellVert = pVtkData->GetVerts();
> > > int numver = cellVert->GetNumberOfCells(); //returned the
> same
> > number
> > > as the number of points
> > >
> > > nCells = pVtkData->GetNumberOfPolys();
> > > nCnt3 = pVtkData->GetNumberOfVerts(); //returned the same
> number as
> > > the number of points
> > >
> > > But where are the triangles????
> > >
> > > Now through pDelny->GetOutput I am expecting set of
> triangles in
> > > vtkPolyData object.
> > > Am I right?
> > >
> > > Thanks
> > >
> >
> >------------------------------------------------------------------------
> > >
> > >_______________________________________________
> > >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
> > >
> > >
> >
> >
>
>
More information about the vtkusers
mailing list