[vtkusers] artifacts while rendering 3d surface

Ajit Rajwadé ajit_v_r at hotmail.com
Wed Jun 25 13:58:54 EDT 2003


Hello,

I am using the following piece of code to render a 3D surface given the 
X,Y,Z coordinates of several equi-sampled points of the surface . While 
rendering the surface, I get very weird artifacts. For instance, here is an 
attached file that contains a rendered sphere.  I am unable to trace the 
bug, what could the cause be?

The code is here:

               // Read all the vertices into an ARRAY called "mean"

	    	vtkRenderer *ren = vtkRenderer::New();
		vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(ren);
		renWin->SetSize (300,300);

	    	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
		iren->SetRenderWindow(renWin);

               //Inserting points one by one
    		vtkPoints *meanPoints = vtkPoints::New();
		for (i=0;i<SIZE;i++)
		{
			point[0] = Mean[i][0];
			point[1] = Mean[i][1];
			point[2] = Mean[i][2];
			meanPoints->InsertNextPoint(point);
		}

    		// Create a data set. Load the starting points
	    	vtkPolyData *inputDataSet = vtkPolyData::New();
	    	inputDataSet->SetPoints(meanPoints);

	    	// Construct the surface
    		vtkSurfaceReconstructionFilter *surf = 
vtkSurfaceReconstructionFilter::New();
	    	surf->SetInput(inputDataSet);
    		printf ("\nSurface construction done...");

    		// Create isosurface (contour value of 0)
	    	vtkContourFilter *cf = vtkContourFilter::New();
	    	cf->SetInput(surf->GetOutput());
	    	cf->SetValue(0,0.0);

		// PolyNormals Filter to obtain normals for "Smooth Shading"
		vtkPolyDataNormals *bNormals = vtkPolyDataNormals::New();
    		bNormals->SetInput(cf ->GetOutput());
    		//bNormals->SetFeatureAngle(180.0);

		// Creates Triangle strips from the Iso-surface
  		vtkStripper *bStripper = vtkStripper::New();
    		bStripper->SetInput(bNormals->GetOutput());

		// Create the mapper and actor and finish up the visualization pipeline
    		vtkPolyDataMapper *map = vtkPolyDataMapper::New();
		map->SetInput(bStripper->GetOutput());
    		map->ScalarVisibilityOff();
		//map->ImmediateModeRenderingOn ();

	    	cout << "Mapper construction done..." << endl;

	    	vtkActor *surfaceActor = vtkActor::New();
    		surfaceActor->SetMapper( map );
	    	surfaceActor->GetProperty()->SetDiffuseColor( 1.0000, 0.3882, 0.2784 
);
    		surfaceActor->GetProperty()->SetSpecularColor( 1, 1, 1 );
	    	surfaceActor->GetProperty()->SetSpecular(0.4);
    		surfaceActor->GetProperty()->SetSpecularPower(50);

	    	ren->AddActor(surfaceActor);
    		ren->SetBackground(1,1,1);
		cout << "Surface actor construction done..." << endl;

    		// Interact with data
	   	renWin->Render();
		iren->Initialize ();
		iren->Start ();

		printf ("\nPress any key");
		scanf ("%d", &choice);

    		// Clean up
		ren->RemoveActor (surfaceActor);
	   	meanPoints->Delete();
    		inputDataSet->Delete();
	    	surf->Delete();
    		cf->Delete();
	    	map->Delete();
	    	surfaceActor->Delete();
		ren->Delete();
		renWin->Delete();
		//iren->Delete ();

_________________________________________________________________
MSN Search, le moteur de recherche qui pense comme vous ! 
http://search.msn.fr/worldwide.asp




More information about the vtkusers mailing list