[vtkusers] some queries with vtkcellarrays
Sankhesh Jhaveri
sankhesh.jhaveri at kitware.com
Tue Jul 21 10:57:19 EDT 2015
Hi Chiranjib,
Your code calls InsertNextCell once and adds all points to that cell using
InsertCellPoint. Thats why you just end up with one cell.
You can add more cells by calling InsertNextCell as many times as the
number of cells you want. You will have to distribute the points in the
resultant cells accordingly.
Take a look at examples here: http://www.vtk.org/Wiki/VTK/Examples/Cxx
Warm Regards,
Sankhesh Jhaveri
Research & Development Engineer
Kitware, Inc.
*Phone*: (518) 881 4417
*Fax*: (518) 371 4573
On Mon, Jul 20, 2015 at 5:48 AM, Chiranjib Sur <sur.chiranjib at gmail.com>
wrote:
> Hi VTK experts,
> I am not an expert vtk programmers like many others in the forum. I have a
> confusion.
>
> I am creating a set of vtk points (and eventually a vtkpolydata) and want
> to create vtkcells for the associated points. I was looking at the examples
> and trying to implement this way (
> http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/VisualizationAlgorithms/Cxx/TubesWithVaryingRadiusAndColors.cxx
> )
>
> What I am observing is that when I create vtkcells, I only create ONE
> cell. What is going wrong here and why not all vtkcells are created?
>
> Any suggestions ?
>
> Thanks in advance,
> Chiranjib
>
> Here is my code snippet
>
>
>
> // VTK points are defined here
>
> vtkSmartPointer<vtkPoints> newPoints =
> vtkSmartPointer<vtkPoints>::New();
>
> // Set precision for the vtk points
> newPoints->SetDataType( VTK_DOUBLE );
>
> unsigned int count = 0;
> double resolution = 0.1;
>
> // Create the points for the entire volume
> for (unsigned int j = 0; j<10; j++)
> {
> for (unsigned int i = 0; i<10; i++)
> {
> for (unsigned int k = 0; k<10; k++)
> {
> newPoints->InsertNextPoint( x0[0]+ resolution*i, x0[1]+
> resolution*j, x0[2]+ resolution*k );
> count++;
> }
> }
> }
>
> std::cout << "length of mycube = " << xl << ","<<yl<<","<<zl << std::endl;
> std::cout << "Number of points = " << count << std::endl;
>
>
>
> // Insert vtk cell arrays
> vtkSmartPointer<vtkCellArray> cell =
> vtkSmartPointer<vtkCellArray>::New();
>
> cell->InsertNextCell( count);
>
> for (vtkIdType i= 0; i < count; i++)
> {
> cell->InsertCellPoint(i);
> }
>
> // Define the polydata for the cube
> vtkSmartPointer<vtkPolyData> np =
> vtkSmartPointer<vtkPolyData>::New();
> np->SetPoints( newPoints );
> np->SetLines( cell);
>
> std::cout << "Number of cells "<< np->GetNumberOfCells() << ":" <<
> count << std::endl;
>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150721/0d719342/attachment.html>
More information about the vtkusers
mailing list