[vtkusers] adding cells to existing Polydata

Tasnim hanene-jeder at hotmail.fr
Mon Sep 10 13:26:42 EDT 2012



class MouseInteractorStyle : public vtkInteractorStyleTrackballCamera

{

  public:

  static MouseInteractorStyle* New();

  vtkSmartPointer sphere ;

  vtkSmartPointer renderer;


  MouseInteractorStyle()

  {

    selectedMapper = vtkSmartPointer::New();

    selectedActor = vtkSmartPointer::New();

	vtkSmartPointer selected =  vtkSmartPointer::New();

	selected = vtkSmartPointer::New();

	selectedActor->SetMapper(selectedMapper);

  	

  }

      virtual void OnLeftButtonDown()

    {

			vtkSmartPointer polydata =vtkSmartPointer::New(); 

			polydata=sphere->GetOutput();

//here i have a function that will devide my mesh to 8 regions ( octree
nodes), it  is so long, so i prefer to not put it


int* pos = this->GetInteractor()->GetEventPosition();

 
	  vtkSmartPointer picker = vtkSmartPointer::New();

     
      picker->Pick(pos[0], pos[1], pos[2], this->GetDefaultRenderer());

 
      double* worldPosition = picker->GetPickPosition();

	  vtkIdType pointId=picker->GetPointId();


	  if(pointId!= -1)

	  {

int  region=PointsNode->GetValue(pointId);

int nbIdr=0;

vectorids(1,1);

for (int i=1; iGetNumberOfPoints(); i++)

{

	if(PointsNode->GetValue(i)==region)//verify if this points belongs to the
same region of pointId

		{

			ids.push_back(i);

	nbIdr++;	

	}

	
}

cout<<"the number of vertex in this  region is : "<<nbIdr;&lt;br>
int nbpp=polydata->GetNumberOfPoints();

/*************************** *************************/

int nbrligne;  //number of vertex (points) in the file

for (int i=0;i<nbrligne;i++)  &lt;br>
double* so;

so=sommet[i];// sommet[i]:is the table of vertex in the file

int nbp=polydata->GetNumberOfPoints();

int nbp1=nbp+1;

polydata->GetPoints()->InsertPoint(nbp1,so);// add point to the existed
polydata

//polydata->GetPoints()->InsertNextPoint(so);

polydata->GetPoints()->Modified();

polydata->Modified();

polydata->Update();


}  

/ /**********************************add cells *************************/

 vtkIdList* points = vtkIdList::New(); 

// Ids: 2d vector which contains the list of cells 

	  int z;

for (int j=0;j<m;j++)&lt;br>
{

for (k=0;k<3;k++)

z=ids[j][k];

 int zz=z+nbpp;

	   points->InsertNextId(zz); 

   } 

int cell=polydata->GetPolys()->GetNumberOfCells();

polydata->GetPolys()->InsertNextCell(points);

polydata->BuildCells();

polydata->BuildLinks();

polydata->GetPolys()->Modified();

int cells=cell+1;

polydata->GetPolys()->UpdateCellCount(cells);

nbrligneface++;  

 }    

};

       
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);

 

      vtkInteractorStyleTrackballCamera::OnLeftButtonDown();

    }

 
    vtkSmartPointer Data;

    vtkSmartPointer selectedMapper;

    vtkSmartPointer selectedActor;

	  vtkSmartPointer selected;

 
};

 
vtkStandardNewMacro(MouseInteractorStyle);

 

int main(int , char *[])

{

  vtkSmartPointer sphereSource = vtkSmartPointer::New();

  sphereSource->Update();

  
  vtkSmartPointer triangleFilter =  vtkSmartPointer::New();

  triangleFilter->SetInputConnection(sphereSource->GetOutputPort());

  triangleFilter->Update();

 
  vtkSmartPointer mapper = vtkSmartPointer::New();

  mapper->SetInputConnection(triangleFilter->GetOutputPort());

 
  vtkSmartPointer actor = vtkSmartPointer::New();

  actor->SetMapper(mapper);

 
  vtkSmartPointer renderWindow =  vtkSmartPointer::New();


  vtkSmartPointer renderer =  vtkSmartPointer::New();

      renderWindow->AddRenderer(renderer);

  vtkSmartPointer renderWindowInteractor =vtkSmartPointer::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderWindowInteractor->Initialize();

   vtkSmartPointer style = vtkSmartPointer::New();

  style->SetDefaultRenderer(renderer);

  style->sphere=sphereSource; 

  renderWindowInteractor->SetInteractorStyle(style);

  renderer->AddActor(actor);

  renderer->ResetCamera();  

  renderWindow->Render();

  renderWindowInteractor->Start();

  return EXIT_SUCCESS;

}


I hope that this code is "minimal" and "compilable".


Regards,

Tasnim






--
View this message in context: http://vtk.1045678.n5.nabble.com/adding-cells-to-existing-Polydata-tp5715971p5715983.html
Sent from the VTK - Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120910/3f543515/attachment.htm>


More information about the vtkusers mailing list