[vtkusers] problem in add line in vtkImageViewer2

Jothy jothybasu at gmail.com
Thu Oct 21 05:21:41 EDT 2010


Instead of adding actor like
vtkRenderer ren = image_viewer2.GetRenderer();
ren.AddActor(lineActor);


Try image_viewer2.GetRenderer()->AddActor(line).

Please, keep the messages on the list.

Jothy

On Thu, Oct 21, 2010 at 8:58 AM, myaqua1982 <myaqua1982 at 163.com> wrote:

>  Hi,
>
> When I click the button just only the first line can be add to the viewer.
> I want to add more lines when I click the button follow by the first two
> clicks. Here is the key code. Could you please check it for me to see where
> the problem is? It is in the form of c# the same as c++.  Thank you !
>
> //////////////////////////////////////////////////////////
> bool mouseDown = false;
> int pointNum = 0;
> double[] P0 = new double[3]; double [] P1 = new double[3];
>
> vtkPoints pts = new vtkPoint();
> vtkCellArray lineCell = new vtkCellArray();
> vtkPolyData linesPolyData = new vtkPolyData();
> vtkPolyDataMapper lineMapper = new vtkPolyDataMapper();
> vtkActor lineActor = new vtkActor();
>
> ArrayList iniPointList = new ArrayList();        //to save the point of the
> lines
>
>           public void RenderLine(double[] p0, double[] p1, int pN)
> //render the line with two points p0 and p1, pN is pointNum
>          {
>             if ((pN - 1) > 0)
>             {
>                  pts.InsertNextPoint(p0);
>                 pts.InsertNextPoint(p1);
>                  vtkLine line = new vtkLine();
>                 line.GetPointIds().SetId(0, pN - 2);
>                 line.GetPointIds().SetId(1, pN - 1);
>                  lineCell.InsertNextCell(line);
>                  linesPolyData.SetPoints(pts);
>                 linesPolyData.SetLines(lineCell);
>                  lineMapper.SetInput(linesPolyData);
>                  lineActor.SetMapper(lineMapper);
>                  lineActor.GetProperty().SetColor(1.0, 0.0, 0.0);
>                  vtkRenderer ren = image_viewer2.GetRenderer();
>                 ren.AddActor(lineActor);
>                 ren.Render();
>             }
>         }
>
>  private void wnd1_MouseDown(object sender, MouseEventArgs e)    //left
> button down
>  {
>             if (mouseDown)
>             {
>                 int xp, yp;
>                 vtkPropPicker picker = new vtkPropPicker();
>                 vtkImageActor imageActor = image_viewer2.GetImageActor();
>                 vtkImageData imageData = image_viewer2.GetInput();
>                 vtkRenderer ren = image_viewer2.GetRenderer();
>                 int[] pos = iren.GetEventPosition();
>                 xp = pos[0]; yp = pos[1];
>                 picker.Pick(xp, yp, 0.0, ren);
>                 pickPos1 = picker.GetPickPosition();
>
>                  double[] pickPos_new = new double[3] { pickPos1[0],
> pickPos1[1], 1.0 };    //the Z coordinate I've changed followed by your
> advice
>                  iniPointList.Add(pickPos_new);
>                 pointNum = iniPointList.Count;  //the num of the point in
> the list
>                  P1 = (double[])iniPointList[pointNum - 1];   //acquire
> the coordinate of the point specified by the index
>
>                  if (pointNum > 1)
>                 {
>                     P0 = (double[])iniPointList[pointNum - 2];
>                 }
>             }
>         }
>
>          private void wnd1_MouseUp(object sender, MouseEventArgs e)
> //left button up
>         {
>             if (mouseDown)
>             {
>                 RenderLine(P0, P1, pointNum);
>             }
>         }
>
> //////////////////////////////////////////////////////////
>
>
> 2010-10-21
> ------------------------------
>  myaqua1982
> ------------------------------
> *发件人:* Jothy
> *发送时间:* 2010-10-20  17:09:44
> *收件人:* myaqua1982
> *抄送:* vtkusers
> *主题:* Re: [vtkusers] problem in add line in vtkImageViewer2
>   Try p0 = {0.0, 0.0, 100.0},p1 = {0.0, 100.0, 100.0} or -100 make sure
> your z corodinate of the line is always greater such that the line is always
> above the image actor.
>
>
> Jothy
>
> 2010/10/20 myaqua1982 <myaqua1982 at 163.com>
>
>>  Hi,
>>
>> I have shown Dicom images in vtkImageViewer2. And now I want to add lines
>> in the viewer . Such as , I click left button to select two point ,and then
>> show the line defined by these two points. The problem is that the line can
>> not show above the image. When I set p0 = {0.0, 0.0, 0.0},p1 = {0.0, 100.0,
>> 0.0},the line can be shown in the leftmost of the image (it looks like Y
>> axes). But when I change p1 = {20.0, 100.0, 0.0}, the line can not show.
>> What is the problem?  Please give me some help. Thank you very much!
>>
>> 2010-10-20
>> ------------------------------
>> myaqua1982
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101021/e4fc0d7c/attachment.htm>


More information about the vtkusers mailing list