[vtkusers] Color a point in a 3D volume
Valerie Coffman
valerie.coffman at nist.gov
Mon Jul 13 10:32:34 EDT 2009
VJay,
We've done something similar to what you describe in our software. We
need to be able to tint voxels if the user has selected them. We also
make voxels transparent if the user has set them to be "inactive". We
derived a class from SimpleImageToImageFilter called ResampleImage which
accomplishes this.
The objects returned by "GetBitmap" and its methods are specific to our
project -- they just store which voxels to resample and the color
information.
The relevant code is :
template <class T>
void ResampleImageExecute(ResampleImage *self, vtkImageData *inData,
vtkImageData *outData, int extent[6], T* inPtr, T* outPtr)
{
int idxX, idxY, idxZ, C=4;
CColor tint = self->GetBitmap()->getFG();
double alpha1 = self->GetBitmap()->getTintAlpha();
double alpha2 = self->GetBitmap()->getVoxelAlpha();
ICoord temp;
for (idxZ = extent[4]; idxZ <= extent[5]; idxZ++){
for (idxY = extent[2]; idxY <= extent[3]; idxY++){
for (idxX = extent[0]; idxX <= extent[1]; idxX++){
temp = ICoord(idxX,idxY,idxZ);
if(self->GetBitmap()->get(&temp)) {
outPtr[0] = (unsigned
char)(alpha1*255*tint.getRed()+(1-alpha1)*inPtr[0]);
outPtr[1] = (unsigned
char)(alpha1*255*tint.getGreen()+(1-alpha1)*inPtr[1]);
outPtr[2] = (unsigned
char)(alpha1*255*tint.getBlue()+(1-alpha1)*inPtr[2]);
outPtr[3] = (unsigned char)(255*log(101-100*alpha2)/log(101));
}
else {
outPtr[0] = inPtr[0];
outPtr[1] = inPtr[1];
outPtr[2] = inPtr[2];
outPtr[3] = inPtr[3];
}
outPtr+=C;
inPtr+=C;
}
}
}
}
Hope that helps.
Valerie
VJay wrote:
> I am a newbie to VTK and I am working on volume rendering of DICOM data sets.
> I have successfully volume rendered the input dataset which consisted of
> slices of image data. I wanted to know if I could render a different color
> to each point (x,y,z) in the volume (color it according to my own algorithm)
> and also in the same time set the opacity for each point in the volume i.e.,
> I should be able to access a particular point inside the volume and color it
> (for example lets say red) and also fix the level of opacity for it (say
> 0.3).
>
> Could you please help me at the earliest ? Thanks a lot.
>
> Thanks,
> VJ
>
More information about the vtkusers
mailing list