[vtkusers] problem in alignment of vtkboxwidget with image
amit agarwal
amit_agarr at rediffmail.com
Fri Mar 5 05:13:15 EST 2004
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040305/d2094f1c/attachment.htm>
-------------- next part --------------
hi
i have used vtkBoxWidget for scaling my volume data and it works fine except that the image and the widget and not aligned.
When i scale the volume or rotate it , it moves out of the widget.
Please suugest a solution for this.
I am including my code here
vtkRenderWindowInteractor *iren;
vtkVolume *vol;
vtkRenderWindow *renwin;
vtkRenderer *ren;
vtkCamera *cam;
vtkVolumeRayCastMapper *volMapper;
class vtkMyCallback : public vtkCommand
{
public:
static vtkMyCallback *New()
{ return new vtkMyCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkTransform *t = vtkTransform::New();
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
widget->GetTransform(t);
widget->GetProp3D()->SetUserTransform(t);
}
};
int main( int argc, char *argv[] )
{
vtkImageReader *Reader = vtkImageReader::New();
Reader-> SetHeaderSize (0);
Reader->SetDataExtent (0,199,0,199,0,99);
Reader->SetDataSpacing(1.0,1.0,1.0);
Reader->SetDataScalarTypeToUnsignedChar();
Reader->SetDataByteOrderToLittleEndian();
Reader->SetFileDimensionality(3);
Reader->SetFileName("d:/bym280602b");
Reader->SetDataMask(0x7fff);
vtkPiecewiseFunction *oTFun =vtkPiecewiseFunction::New();
oTFun->AddSegment(32,0,255,1.0);
vtkPiecewiseFunction *gTFun =vtkPiecewiseFunction::New();
gTFun->AddSegment(0,1.0,5,1.0);
vtkVolumeProperty *volProperty = vtkVolumeProperty::New();
volProperty->SetColor(gTFun);
volProperty->SetScalarOpacity(oTFun);
volProperty->SetInterpolationTypeToLinear();
volProperty->ShadeOn();
vtkVolumeRayCastCompositeFunction *compositeFunction= vtkVolumeRayCastCompositeFunction::New();
volMapper = vtkVolumeRayCastMapper::New();
volMapper->SetInput(Reader->GetOutput());
volMapper->SetVolumeRayCastFunction(compositeFunction);
vol=vtkVolume::New();
vol->SetMapper(volMapper);
vol->SetProperty(volProperty);
ren=vtkRenderer::New();
ren->AddVolume(vol);
renwin=vtkRenderWindow::New();
renwin->AddRenderer(ren);
renwin->SetSize(500,500);
iren=vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renwin);
vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
vtkBoxWidget *boxWidget = vtkBoxWidget::New();
boxWidget->SetInteractor(iren);
boxWidget->SetPlaceFactor(1);
boxWidget->SetProp3D(vol);
boxWidget->PlaceWidget();
vtkMyCallback *callback = vtkMyCallback::New();
boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
boxWidget->On();
iren->Initialize();
iren->Start();
return 0;
}
More information about the vtkusers
mailing list