[vtkusers] A problem - who can help me ?

Amy Squillacote amy.squillacote at kitware.com
Fri Aug 17 08:23:21 EDT 2007


Hi JohnMark,

I'm copying your reply back to the mailing list. Please keep the
discussion on the vtkusers mailing list. That way other people can help
you find an answer to your questions, and the whole discussion is
archived so other people don't have to ask the same question in the future.

- Amy

JohnMark wrote:
> Hi,Amy, I want to keep the CT picture appearing all the time .but the
> program isn't so . the CT picture will disappear after you press the
> left mouse button . and my code is as follows :
>
> #include "vtkActor2D.h"
> #include "vtkCellArray.h"
> #include "vtkImageActor.h"
> #include "vtkImageShiftScale.h"
> #include "vtkInteractorStyleImage.h"
> #include "vtkPNGReader.h"
> #include "vtkPoints.h"
> #include "vtkPolyData.h"
> #include "vtkPolyDataMapper2D.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkRenderer.h"
> #include "vtkProperty.h"
> #include "vtkProperty2D.h"
> #include "vtkCamera.h"
> #include "vtkCommand.h"
> vtkRenderer *ren1;
> vtkRenderWindow *renWin;
> vtkRenderWindowInteractor *iren;
> vtkPoints *pts;
> vtkActor2D *bboxActor;
> vtkImageActor *ia;
> int X = 0 ;
> int Y = 0 ;
> double bboxEnabled = 0 ;
> class StartZoom_test : public vtkCommand
> {
> public:
> static StartZoom_test *New() { return new StartZoom_test; }
> void Delete() { delete this; }
> virtual void Execute(vtkObject *caller, unsigned long l, void *callData)
> {
> int * xy = iren->GetEventPosition();
> X = * (xy);
> xy++;
> Y = * (xy);
> pts->SetPoint(0, X, Y, 0);
> pts->SetPoint(1, X, Y, 0);
> pts->SetPoint(2, X, Y, 0);
> pts->SetPoint(3, X, Y, 0);
> bboxEnabled = 1 ;
> bboxActor->VisibilityOn();
> ia->VisibilityOn();
> }
> };
> class MouseMove_test : public vtkCommand
> {
> public:
> static MouseMove_test *New() { return new MouseMove_test; }
> void Delete() { delete this; }
> virtual void Execute(vtkObject *caller, unsigned long l, void *callData)
> {
> if(bboxEnabled)
> {
> int * xy = iren->GetEventPosition();
> int x = * (xy);
> xy++;
> int y = * (xy);
> pts->SetPoint(1, x, Y, 0);
> pts->SetPoint(2, x, y, 0);
> pts->SetPoint(3, X, y, 0);
>
> ia->VisibilityOn();
> renWin->Render();
> }
> }
> };
> class EndZoom_test : public vtkCommand
> {
> public:
>
> static EndZoom_test *New() { return new EndZoom_test; }
> void Delete() { delete this; }
>
> virtual void Execute(vtkObject *caller, unsigned long l, void *callData)
> {
> //Do the hard stuff: pan and dolly
> double p1[3] , p2[3] ;
> pts->GetPoint( 0 , p1 );
> pts->GetPoint( 2 , p2 );
> double x1 = p1[0];
> double y1 = p1[1];
> double x2 = p2[0];
> double y2 = p2[1];
>
> ren1->SetDisplayPoint( x1 , y1 , 0 );
> ren1->DisplayToWorld();
> double * q1 = ren1->GetWorldPoint();
> ren1->SetDisplayPoint( x2, y2, 0 );
> ren1->DisplayToWorld();
> double * q2 = ren1->GetWorldPoint();
>
> double p1X = * ( q1 );
> (q1)++;
> double p1Y = * ( q1 );
> (q1)++;
> double p1Z = * ( q1 );
>
> double p2X = * ( q2 );
> (q2)++;
> double p2Y = * ( q2 );
> (q2)++;
> double p2Z = * ( q2 );
>
> double * focalPt = ren1->GetActiveCamera()->GetFocalPoint();
> double focalX = * ( focalPt );
> focalPt++;
> double focalY = * ( focalPt );
> focalPt++;
> double focalZ = * ( focalPt );
> double * position = ren1->GetActiveCamera()->GetPosition();
> double positionX = * ( position );
> position++;
> double positionY = * ( position );
> position++;
> double positionZ = * ( position );
>
> double deltaX = focalX - (p1X + p2X) / 2.0 ;
> double deltaY = focalY - (p1Y + p2Y) / 2.0 ;
>
> //Set camera focal point to the center of the box
> ren1->GetActiveCamera()->SetFocalPoint((p1X + p2X)/2.0, (p1Y +
> p2Y)/2.0, focalZ);
> ren1->GetActiveCamera()->SetPosition((positionX - deltaX), (positionY
> - deltaY), positionZ);
>
> //Now dolly the camera to fill the box
> //This is a half-assed hack for demonstration purposes
> if( p1X > p2X )
> {
> deltaX = p1X - p2X;
> }
> else
> {
> deltaX = p2X - p1X;
> };
> if( p1Y > p2Y )
> {
> deltaY = p1Y - p2Y;
> }
> else
> {
> deltaY = p2Y - p1Y;
> };
>
> int * winSize = renWin->GetSize();
> int winX = * ( winSize );
> winSize++;
> int winY = * ( winSize );
>
> double sx = deltaX / winX;
> double sy = deltaY / winY;
>
> double dolly;
> if( sx > sy )
> {
> dolly = 1.0 + 1.0 / (2.0 * sx);
> }
> else
> {
> dolly = 1.0 + 1.0 / (2.0 * sy);
> };
> ren1->GetActiveCamera()->Dolly( dolly );
> ren1->ResetCameraClippingRange();
>
> bboxEnabled = 0 ;
> bboxActor->VisibilityOff();
> ia->VisibilityOff();
> //renWin->Render();
> }
> };
>
> void main()
> {
> // This example shows how to use the InteractorStyleImage and add your own
> // event handling. The InteractorStyleImage is a special interactor
> designed
> // to be used with vtkImageActor in a rendering window context. It
> forces the
> // camera to stay perpendicular to the x-y plane.
>
> // Create the RenderWindow, Renderer and both Actors
> ren1 = vtkRenderer::New();
> renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren1);
> iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
> // Create an image interactor style and associate it with the
> // interactive renderer. Then assign some callbacks with the
> // appropriate events. THe callbacks are implemented as Tcl procs.
> StartZoom_test * StartZoom = StartZoom_test::New();
> MouseMove_test * MouseMove = MouseMove_test::New();
> EndZoom_test * EndZoom = EndZoom_test::New();
> vtkInteractorStyleImage *interactor = vtkInteractorStyleImage::New();
> iren->SetInteractorStyle(interactor);
> interactor->AddObserver(vtkCommand::LeftButtonPressEvent, StartZoom);
> interactor->AddObserver(vtkCommand::MouseMoveEvent, MouseMove);
> interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, EndZoom);
> // Create the image
> //
> vtkPNGReader *reader = vtkPNGReader::New();
> reader->SetDataSpacing(0.8, 0.8, 1.5);
> reader->SetFileName("E:/Data/vtkdata/fullhead15.png");
>
> vtkImageShiftScale *shiftScale = vtkImageShiftScale::New();
> shiftScale->SetInputConnection(reader->GetOutputPort());
> shiftScale->SetShift(0);
> shiftScale->SetScale(0.07);
> shiftScale->SetOutputScalarTypeToUnsignedChar();
>
> ia = vtkImageActor::New();
> ia->SetInput(shiftScale->GetOutput());
>
> // Supporting data for callbacks
> pts = vtkPoints::New();
> pts->SetNumberOfPoints(4);
> vtkCellArray *lines = vtkCellArray::New();
> lines->InsertNextCell(5);
> lines->InsertCellPoint(0);
> lines->InsertCellPoint(1);
> lines->InsertCellPoint(2);
> lines->InsertCellPoint(3);
> lines->InsertCellPoint(0);
> vtkPolyData *pd = vtkPolyData::New();
> pd->SetPoints(pts);
> pd->SetLines(lines);
> vtkPolyDataMapper2D *bboxMapper = vtkPolyDataMapper2D::New();
> bboxMapper->SetInput(pd);
>
> bboxActor = vtkActor2D::New();
> bboxActor->SetMapper(bboxMapper);
> bboxActor->GetProperty()->SetColor( 1, 0, 0 );
> ren1->AddViewProp(bboxActor);
>
> // Add the actors to the renderer, set the background and size
> ren1->AddActor(ia);
> ren1->SetBackground(0.1, 0.2, 0.4);
> renWin->SetSize(400, 400);
>
> renWin->Render();
>
> ren1->ResetCameraClippingRange();
> iren->Initialize();
> iren->Start();
>
> }
>
> waiting for your answer ! thank you very much !
>
>
> ------------------------------------------------------------------------
>
> > Date: Fri, 17 Aug 2007 08:11:28 -0400
> > From: amy.squillacote at kitware.com
> > To: zhaojunxp at hotmail.com
> > CC: vtkusers at vtk.org
> > Subject: Re: [vtkusers] A problem - who can help me ?
> >
> > Hi JohnMark,
> >
> > Please provide sample code demonstrating your problem. It is very
> > difficult (if not impossible) to know what may be going wrong with your
> > program without seeing the relevant part of the code.
> >
> > - Amy
> >
> > JohnMark wrote:
> > > hi,
> > > when I compiled an example of vtkImageShiftScale with VTK and C++ , I
> > > found a small problem . the example is ImageInteractor .and my problem
> > > is : at first time , I can draw a rectangle on a CT picture with mouse
> > > , and when I press the mouse left button again ,a rectangle could be
> > > drawn again but the CT picture disappear . and I have make the picture
> > > to be visibility when I press the left mouse button :
> > > pictureActor->VisibilityOn();
> > > and when I release the left mouse button I set it to be invisibility :
> > > pictureActor->VisibilityOff();
> > > but unfortunately , I could not see the CT picture after I draw a
> > > rectangle . So what is wrong with my program ? and how should I do to
> > > work out it ? thank you !
> > >
> > >
> ------------------------------------------------------------------------
> > > 不登录就能管理多个邮件帐户,试试 Windows Live Mail。 立即尝试!
> > > <http://get.live.com/betas/maildesktop_betas>
> > >
> ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > This is the private VTK discussion list.
> > > Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> > > Follow this link to subscribe/unsubscribe:
> > > http://www.vtk.org/mailman/listinfo/vtkusers
> > >
> >
> > --
> > Amy Squillacote
> > Kitware, Inc.
> > 28 Corporate Drive
> > Clifton Park, NY 12065
> > Phone: (518) 371-3971 x106
> >
>
>
> ------------------------------------------------------------------------
> Windows Live Writer 让您告别龟速网络,轻松写日志! 立即使用!
> <http://writer.live.com/>

-- 
Amy Squillacote
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
Phone: (518) 371-3971 x106




More information about the vtkusers mailing list