[vtkusers] rendering voxels from Java
kent myers
dakota_63124 at yahoo.com
Thu May 14 23:41:35 EDT 2015
I am attempting to display a 3D voxel array from a java application, by
following the example given at
http://vtk.1045678.n5.nabble.com/Visualizing-populated-voxels-td4385698.html
I have a 3d short[][][] array containing the material index for each cell of
a 3D voxel array. My understanding is that I need to convert this to a 1
dimensional array and pass it to a vtkShortArray. The java code is shown
below. I think I have made the correct substitutions of java methods for
C++ methods, but I do not know where to find the constants
VTK_UNSIGNED_CHAR, FIELD_ASSOCIATION_CELLS and SCALARS. Also, I don't
understand how to use the vtkInformation object that is needed for the
vtkImageData object to SetScalarType().
Can anyone help or point me to a java example?
Thanks,
Kent
public void showExternal(SimExternal external) {
short[][][] voxelData = external.matrixData.voxelMatrix;
int dimX = voxelData.length;
int dimY = voxelData[0].length;
int dimZ = voxelData[0][0].length;
double[] values = external.getValues();
double voxX = values[3];
double voxY = values[4];
double voxZ = values[5];
double minX = 0.0;
double minY = 0.0;
double minZ = 0.0;
if(dimZ >= 4) {
int numSamples = dimX * dimY * dimZ;
short[] sampleGrid = new short[numSamples];
for(int i=0, l=0; i<dimX; i++) {
for(int j=0; i<dimY; j++) {
for(int k=0; k<dimZ; k++) {
sampleGrid[l++] = voxelData[i][j][k];
}
}
}
vtkShortArray sampleData = new vtkShortArray();
sampleData.SetJavaArray(sampleGrid);
sampleData.SetNumberOfComponents( 1 );
sampleData.SetNumberOfTuples( numSamples );
sampleData.SetName( "values" );
// Set up sampled data space
vtkImageData sampledSpace = new vtkImageData();
sampledSpace.SetDimensions( dimX, dimY, dimZ );
vtkInformation info = new vtkInformation(); // ???
sampledSpace.SetScalarType(3, info); // VTK_UNSIGNED_CHAR = 3
sampledSpace.GetPointData().SetScalars( sampleData );
sampledSpace.SetSpacing( voxX, voxY, voxZ ); // set dimensions of a
voxel
sampledSpace.SetOrigin( (double)minX,
(double)minY,
(double)minZ ); // set lower left corner
location
vtkThreshold threshold = new vtkThreshold();
threshold.SetInputData(sampledSpace);
threshold.SetInputArrayToProcess(0,0,0,1,0);
// FieldAssociations.FIELD_ASSOCIATION_CELLS = 1, AttributeTypes.SCALARS = 0
threshold.ThresholdBetween(5,100);
threshold.Update();
vtkGeometryFilter geomFilter = new vtkGeometryFilter();
geomFilter.SetInputData(threshold.GetOutput());
geomFilter.Update();
// Create mapper and actor, and add to renderer
vtkPolyDataMapper voxelMapper = new vtkPolyDataMapper();
voxelMapper.SetInputData( geomFilter.GetOutput() );
//voxelMapper->SetScalarRange(5,100);
voxelMapper.SetScalarModeToUseCellData();
//voxelMapper->SetColorModeToMapScalars();
SimVisualDocumentVTK doc = ((SimVisualDocumentVTK) document);
vtkActor impGeoActor = doc.getElementFaceActor();
impGeoActor.SetMapper( voxelMapper );
//impGeoActor->GetProperty()->SetColor( 1.0, 0, 0 );
//impGeoActor->GetProperty()->SetOpacity( alpha );
// int actorId = addActor( impGeoActor );
// voxelMapper->Delete();
// geomFilter->Delete();
// threshold->Delete();
// sampledSpace->Delete();
// sampleData->Delete();
// return actorId;
}
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/rendering-voxels-from-Java-tp5731920.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list