[vtkusers] how create a ply file from an extractedselection in a polydata

cerina cerine-baratelli at hotmail.fr
Tue Sep 18 08:14:40 EDT 2012


Hi david,
i tried your last suggestion : I create a new polydata and adding to it:
points, vertices,lines and triangles like this:
// Assign all points to root node	
for (int i=0;i<this->Input->GetNumberOfPoints();i++) 
PointsNode->SetValue(i,0); 

int NumberOfSplitNodes; 
int Level=0; 
for(int h=0;h<8; h++) 
{ 
.................. // subdividing the octree 
} 
for(int m=1; m<NumberOfSplitNodes; m++)// debut de boucle des régions
{ 

vtkIdType v1;
vtkIdType v2;
vtkIdType v3;
vtkIdList *pts=vtkIdList::New();
vtkPoints* points = vtkPoints::New();
 vtkSmartPointer&lt;vtkCellArray> vertices =
vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkCellArray> triangles =
vtkSmartPointer<vtkCellArray>::New();
 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
 vtkSmartPointer<vtkTriangle> triangle =
vtkSmartPointer<vtkTriangle>::New();
vtkSmartPointer<vtkLine> line0 = vtkSmartPointer<vtkLine>::New();
vtkSmartPointer<vtkLine> line1 = vtkSmartPointer<vtkLine>::New();
vtkSmartPointer<vtkLine> line2 = vtkSmartPointer<vtkLine>::New();
 int j=(this->Input->GetNumberOfPoints()/8);
for ( int k=0; k<j;k++)
{
double x[3];
this->Input->GetPointCoordinates(k,x);
vtkIdType pid[1];
pid[0] = points->InsertNextPoint(x[0],x[1],x[2]);
vertices->InsertNextCell(1,pid);
}
int jj=(this->Input->GetNumberOfCells()/8);
for (int k=0; k<jj;k++)
{
this->Input->GetFaceVertices(k,v1,v2,v3);
 line0->GetPointIds()->SetId ( 0,v1 );
  line0->GetPointIds()->SetId ( 1,v2 );
 
  line1->GetPointIds()->SetId ( 0,v1 );
  line1->GetPointIds()->SetId ( 1,v3 );
 
  line2->GetPointIds()->SetId ( 0,v2 );
  line2->GetPointIds()->SetId ( 1,v3 );
lines->InsertNextCell(line0);

  lines->InsertNextCell( line1 );
  lines->InsertNextCell( line2 );
 					
triangle->GetPointIds()->SetId(v1,v1);
triangle->GetPointIds()->SetId(v2,v2);
triangle->GetPointIds()->SetId(v3,v3);
triangles->InsertNextCell(triangle);
			
}

            vtkSmartPointer<vtkPolyData> newdata = 
   vtkSmartPointer<vtkPolyData>::New(); 
			
 
newdata->SetPoints(points); 
newdata->SetVerts(vertices);
newdata->SetLines(lines);
newdata->SetPolys(triangles);


vtkPLYWriter *Writer=vtkPLYWriter::New();

Writer->SetInput(newdata);
std::stringstream strfile;
strfile<<"Region"<<m&lt;&lt;&quot;.ply&quot;;
Writer->SetFileName(strfile.str().c_str());
Writer->Write();

}

but i got just one file and when i open it, i visualize just one triangle:
<http://vtk.1045678.n5.nabble.com/file/n5716167/tri.jpg> 



--
View this message in context: http://vtk.1045678.n5.nabble.com/how-create-a-ply-file-from-an-extractedselection-in-a-polydata-tp5716164p5716167.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list