[vtkusers] vtkPolyDataMapper ColorByArrayComponent

Eric Pichon eric at ece.gatech.edu
Tue Jun 17 10:00:07 EDT 2003


Hi,

I finally managed to solve my own problem (creating an isosurface from a
scalar field and coloring it with another scalar field). I was using
PointFieldData instead of PointData. If you want more details the correct
pipeline is below.

Sorry for bothering you all with that,

Eric

---

	// Create the RenderWindow, Renderer and both Actors
	vtkRenderer *ren1 = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);

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

	// create pipeline
	vtkMergePoints *locator = vtkMergePoints::New();
	locator->SetDivisions(32, 32, 46);
	locator->RetainCellListsOff();
	locator->SetNumberOfPointsPerBucket(2);
	locator->AutomaticOff();

	vtkImageData *data = vtkImageData::New();
	data->SetScalarTypeToShort();

	data->SetSpacing( dx, dy, dz );
	data->SetDimensions( nX, nY, nZ );

	short *ptrData = (short *)data->GetScalarPointer();

	vtkShortArray *array = vtkShortArray::New();
	array->SetName("HU");
	array->SetNumberOfValues(nX*nY*nZ);
	short *ptrArray = array->GetPointer( 0 );

	int x, y, z;
	int index=0;
		for( z=0;z<nZ;z++)
			for( y=0;y<nY;y++)
				for( x=0;x<nX;x++)
				{

ptrData[index]=inImage->xyz(x,y,z);

ptrArray[index]=outImage->xyz(x,y,z);
					index++;
				}

	vtkPointData *pointData = data->GetPointData();
	pointData->AddArray( array );

	vtkContourFilter *iso = vtkContourFilter::New();
    iso->SetInput( data );
    iso->SetValue( 0, 0.5 );

/*
	vtkMarchingCubes *iso = vtkMarchingCubes::New();
    iso->SetInput( data );
    iso->SetValue( 0, 0.5 );
    iso->ComputeGradientsOn();
    iso->ComputeScalarsOn(); //iso->ComputeScalarsOff();
    iso->SetLocator(locator);
*/

	vtkPolyDataMapper *isoMapper = vtkPolyDataMapper::New();
	isoMapper->SetInput( iso->GetOutput() );
	isoMapper->ScalarVisibilityOn();
	isoMapper->SetScalarRange(0, 500);
	isoMapper->SetScalarModeToUsePointFieldData();
	isoMapper->ColorByArrayComponent("HU", 0);

	vtkActor *isoActor=vtkActor::New();
    isoActor->SetMapper( isoMapper );

	vtkOutlineFilter *outline=vtkOutlineFilter::New();
    outline->SetInput( data );
	vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
    outlineMapper->SetInput( outline->GetOutput() );
	vtkActor *outlineActor = vtkActor::New();
    outlineActor->SetMapper( outlineMapper );

	// Add the actors to the renderer, set the background and size
	ren1->AddActor( outlineActor );
	ren1->AddActor( isoActor );
	ren1->SetBackground( 1, 1, 1 );

	renWin->SetSize( 500, 500 );
	ren1->SetBackground( 0.1, 0.2, 0.4 );

	ren1->GetActiveCamera()->Elevation(90);
	ren1->GetActiveCamera()->SetViewUp( 0, 0, -1 );
	ren1->GetActiveCamera()->Zoom( 1.5 );

	ren1->ResetCameraClippingRange();

	// render the image
	renWin->Render();

	iren->Start();


On Mon, 16 Jun 2003, Eric Pichon wrote:

> Hi All,
>
> I am trying to generate an isosurface and then color it with a different
> scalar field. This is described in the VTK user guide (p86, 5.1, "Color an
> isosurface with another scalar") but strangely whichever color field I
> try to map to the isosurface color I cannot seem to get anything but a
> dull gray.
>
> Any idea on what I am doing wrong would be really appreciated !
>
> Thanks,
>
> Eric
>
> ----
> (I think that the construction of the vtkImageData might be incorrect ? I
> am trying to use 'inImage' for the isosurface and 'outImage' for the
> color. Again, the isosurface is fine but not colored.
>
> It looks like any arguments can be given to ColorByArray component
> without causing any error message at runtime. This is also the behavior
> in the example ColorIsosurface.tcl)
>
>
> 	// Create the RenderWindow, Renderer and both Actors
> 	vtkRenderer *ren1 = vtkRenderer::New();
> 	vtkRenderWindow *renWin = vtkRenderWindow::New();
>     renWin->AddRenderer(ren1);
>
> 	vtkRenderWindowInteractor *iren =
> vtkRenderWindowInteractor::New();
>     iren->SetRenderWindow(renWin);
>
> 	// create pipeline
> 	vtkMergePoints *locator = vtkMergePoints::New();
> 	locator->SetDivisions(32, 32, 46);
> 	locator->RetainCellListsOff();
> 	locator->SetNumberOfPointsPerBucket(2);
> 	locator->AutomaticOff();
>
> 	vtkImageData *data = vtkImageData::New();
> 	data->SetScalarTypeToShort();
>
> 	data->SetSpacing( dx, dy, dz );
> 	data->SetDimensions( nX, nY, nZ );
>
> 	short *ptrData = (short *)data->GetScalarPointer();
>
> 	vtkShortArray *array = vtkShortArray::New();
> 	array->SetName("HU");
> 	array->SetNumberOfValues(nX*nY*nZ);
> 	short *ptrArray = array->GetPointer( 0 );
>
> 	int x, y, z;
> 	int index=0;
> 		for( z=0;z<nZ;z++)
> 			for( y=0;y<nY;y++)
> 				for( x=0;x<nX;x++)
> 				{
>
> ptrData[index]=inImage->xyz(x,y,z);
>
> ptrArray[index]=outImage->xyz(x,y,z);
>
> 					index++;
> 				}
>
> 	vtkFieldData *field = vtkFieldData::New();
> 	field->AddArray( array );
>
> 	cout << "field:";
> 	vtkIndent *indent = vtkIndent::New();
> 	field->PrintSelf(cout, *indent );
> 	cout << endl;
>
> 	data->SetFieldData( field );
>
> 	vtkContourFilter *iso = vtkContourFilter::New();
>     iso->SetInput( data );
>     iso->SetValue( 0, 0.5 );
>
> /*
> 	vtkMarchingCubes *iso = vtkMarchingCubes::New();
>     iso->SetInput( data );
>     iso->SetValue( 0, 0.5 );
>     iso->ComputeGradientsOn();
>     iso->ComputeScalarsOn(); //iso->ComputeScalarsOff();
>     iso->SetLocator(locator);
> */
>
> 	cout << "iso:";
> 	iso->PrintSelf(cout, *indent );
> 	cout << endl;
>
> 	cout << "iso->GetFieldData():";
> 	iso->GetOutput()->GetFieldData()->PrintSelf(cout, *indent );
> 	cout << endl;
>
> 	vtkPolyDataMapper *isoMapper = vtkPolyDataMapper::New();
> 	isoMapper->SetInput( iso->GetOutput() );
> 	isoMapper->ScalarVisibilityOn();
> 	isoMapper->SetScalarRange(0, 500);
> 	isoMapper->SetScalarModeToUsePointFieldData();
> 	isoMapper->ColorByArrayComponent("HU", 0);
>
> 	vtkActor *isoActor=vtkActor::New();
>     isoActor->SetMapper( isoMapper );
>
> 	vtkOutlineFilter *outline=vtkOutlineFilter::New();
>     outline->SetInput( data );
> 	vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
>     outlineMapper->SetInput( outline->GetOutput() );
> 	vtkActor *outlineActor = vtkActor::New();
>     outlineActor->SetMapper( outlineMapper );
>
> 	// Add the actors to the renderer, set the background and size
> 	ren1->AddActor( outlineActor );
> 	ren1->AddActor( isoActor );
> 	ren1->SetBackground( 1, 1, 1 );
>
> 	renWin->SetSize( 500, 500 );
> 	ren1->SetBackground( 0.1, 0.2, 0.4 );
>
> 	ren1->GetActiveCamera()->Elevation(90);
> 	ren1->GetActiveCamera()->SetViewUp( 0, 0, -1 );
> 	ren1->GetActiveCamera()->Zoom( 1.5 );
>
> 	ren1->ResetCameraClippingRange();
>
> 	// render the image
> 	renWin->Render();
>
> 	iren->Start();
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list