[vtkusers] How to display contours on a quad polygon from Java

kent myers dakota_63124 at yahoo.com
Sun May 10 19:59:33 EDT 2015


I am trying to learn how to create a contour map on a quadrilateral polygon
from a Java application using VTK 6.2 and Java 8.  The code below has been
added to the standard vtkDemo application (I can supply the complete
application if desired).

The result is a cube that is solid blue instead of having a contour pattern
based on the scalar values assigned to the vertices of the cube.  

I am probably doing something wrong, but this code is based on other similar
examples I have found.

Does anyone have suggestions about what might be wrong?

Thanks,
Kent


    private void createCube() {
    	float[] points = {
    			0.0f, 0.0f, 0.0f,
    			1.0f, 0.0f, 0.0f,
    			1.0f, 1.0f, 0.0f,
    			0.0f, 1.0f, 0.0f,
    			
    			1.0f, 0.0f, 0.0f,
    			1.0f, 0.0f, 1.0f,
    			1.0f, 1.0f, 1.0f,
    			1.0f, 1.0f, 0.0f,
    			
    			1.0f, 0.0f, 1.0f,
    			0.0f, 0.0f, 1.0f,
    			0.0f, 1.0f, 1.0f,
    			1.0f, 1.0f, 1.0f,
    			
    			0.0f, 0.0f, 1.0f,
    			0.0f, 0.0f, 0.0f,
    			0.0f, 1.0f, 0.0f,
    			0.0f, 1.0f, 1.0f
    	};
    	
    	int[] seq = {
    			4,0,1,2,3,
    			4,4,5,6,7,
    			4,8,9,10,11,
    			4,12,13,14,15,
    	};
    	
		double[] faceScalars = {
				1.0f,
				2.0f,
				3.0f,
				2.0f,
				
				2.0f,
				4.0f,
				5.0f,
				3.0f,
				
				4.0f,
				4.0f,
				5.0f,
				5.0f,
				
				4.0f,
				1.0f,
				2.0f,
				5.0f
		};

    	
    	vtkPolyData poly = new vtkPolyData();
    	vtkDoubleArray scalarData = new vtkDoubleArray();
    	scalarData.SetJavaArray(faceScalars);

        vtkPoints vtkPoints = new vtkPoints();
        vtkFloatArray d = new vtkFloatArray();
        d.SetJavaArray(points);
        d.SetNumberOfComponents(3);
        vtkPoints.SetData(d);
        
        poly.SetPoints(vtkPoints);
        poly.GetPointData().SetScalars(scalarData);
                
        vtkCellArray vtkCells = new vtkCellArray();
        vtkIdTypeArray array = new vtkIdTypeArray();
        vtkIntArray intArray = new vtkIntArray();
        intArray.SetJavaArray(seq);
        array.DeepCopy(intArray);
        vtkCells.SetCells(seq.length, array);

        poly.SetPolys(vtkCells);
 
    	cubeActor = new vtkActor();
    	vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();
    	cubeMapper.SetInputData(poly);
    	cubeActor.SetMapper(cubeMapper);
    	
        // set up contours
    	
        vtkContourFilter contourFilter = new vtkContourFilter();
        contourFilter.GenerateValues(10,1.0,5.0);
        contourFilter.SetInputData(poly);
        vtkPolyDataMapper contourMapper = new vtkPolyDataMapper();
        contourMapper.SetInputData(contourFilter.GetOutput());
        vtkLookupTable lut = createColorTable(10,1.0f,5.0f);
        contourMapper.SetLookupTable(lut);
        contourActor = new vtkActor();
        contourActor.SetMapper(contourMapper);
        contourActor.VisibilityOn();
    	
		renWin.GetRenderer().AddActor(cubeActor);
		renWin.GetRenderer().AddActor(contourActor);
		
    }
    
    private vtkLookupTable createColorTable(int levels, float min, float
max) {
    	vtkLookupTable colorTable = new vtkLookupTable();

    	// original color table
//    	Color[] contourColorTable = initColors(levels,min,max);
    	
		colorTable.SetNumberOfColors(levels);
		
        for(int i=0; i<levels; i++) {
        	// just create a simple color table for now
        	double r = (double) i/levels;
        	double g = (double) i/(2*levels);
        	double b = (double) (levels - i)/levels;
        	double intensity = 1.0;
//        	double r = contourColorTable[i].getRed()/255.0f;
//        	double g = contourColorTable[i].getGreen()/255.0f;
//        	double b = contourColorTable[i].getBlue()/255.0f;
//        	double intensity = contourColorTable[i].getAlpha()/255.0f;

        	colorTable.SetTableValue(i,r,g,b,intensity);
        }
        
        return colorTable;
	}



--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-display-contours-on-a-quad-polygon-from-Java-tp5731870.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list