[vtkusers] How to make the paintbrush paint only on one slice, not on the neighbor slices

Xiaopeng Yang yxp233 at postech.ac.kr
Sun Mar 27 20:23:33 EDT 2011


Hell Karthik,

Sorry to send this question again. Since I did not receive your reply yet. My question how to set the paintbrush width? I did as you suggested before, but it said that 'SetWidth' is not a function of 'vtkKWPaintbrushShape'.

Please help me!

Thanks a lot,
Yang

-----邮件原件-----
发件人: Xiaopeng Yang [mailto:yxp233 at postech.ac.kr] 
发送时间: 2011년 3월 23일 수요일 오후 8:49
收件人: 'Karthik Krishnan'
抄送: 'vtk'; 'VtkEdge at vtkedge.org'
主题: RE: [vtkusers] How to make the paintbrush paint only on one slice, not on the neighbor slices

Hi Karthik,

I tried to set the width of paintbrush. But the it said that SetWidth is not a function of 'vtkKWPaintbrushShape'. I added your code to the program (PaintbrushTest6) as follows:


  vtkKWEPaintbrushTesting *paintbrushTesting = vtkKWEPaintbrushTesting::New();
  paintbrushTesting->SetFilename( "D:/Hybrid Method/Hybrid/SWS/Diffusion_filter/mha/3D.mha" );
  paintbrushTesting->Initialize();
  vtkImageData * imageData  = paintbrushTesting->GetInput();

  vtkKWEWidgetGroup *set = vtkKWEWidgetGroup::New();

  for (int i = 0; i < 3; i++)
    {
    vtkKWEPaintbrushWidget *w = vtkKWEPaintbrushWidget::New();
    w->SetInteractor( paintbrushTesting->GetNthImageViewer(i)->
                      GetRenderWindow()->GetInteractor());
    vtkKWEPaintbrushRepresentationGrayscale2D * rep =
                vtkKWEPaintbrushRepresentationGrayscale2D::New();
    w->SetRepresentation(rep);
    if (rep)
      {
      vtkImageActor * imageActor = paintbrushTesting->GetNthImageActor(i);
      rep->SetImageActor(imageActor);
      rep->SetImageData(imageData);
      rep->GetPaintbrushOperation()->GetPaintbrushShape()->SetSpacing(
          imageData->GetSpacing() );
      rep->GetPaintbrushOperation()->GetPaintbrushShape()->SetOrigin(
          imageData->GetOrigin() );

      //********************************************************************************
      rep->GetPaintbrushOperation()->GetPaintbrushShape()->SetWidth(
          xx, xx, xx);
      //********************************************************************************
      }

    set->AddWidget(w);
    rep->Delete();
    w->Delete();
    }

  vtkKWEPaintbrushRepresentation2D * repx =
    vtkKWEPaintbrushRepresentation2D::SafeDownCast(
      set->GetNthWidget(0)->GetRepresentation());
  vtkKWEPaintbrushDrawing * drawingx = repx->GetPaintbrushDrawing();
  for (unsigned int i = 0; i < set->GetNumberOfWidgets(); i++)
    {
    vtkKWEPaintbrushRepresentation2D * repr =
      vtkKWEPaintbrushRepresentation2D::SafeDownCast(
        set->GetNthWidget(i)->GetRepresentation());
    repr->SetPaintbrushDrawing( drawingx );
    }

  // Now read in an initial segmentation.

  vtkKWEPaintbrushRepresentation2D * rep =
    vtkKWEPaintbrushRepresentation2D::SafeDownCast(
      set->GetNthWidget(0)->GetRepresentation());

  vtkKWEPaintbrushDrawing * drawing = rep->GetPaintbrushDrawing();
  drawing->InitializeData();
  vtkKWEPaintbrushGrayscaleData *data = vtkKWEPaintbrushGrayscaleData::New();

  // Read the file (initial segmentation)
  vtkMetaImageReader * reader = vtkMetaImageReader::New();
  reader->SetFileName( "D:/Hybrid Method/Hybrid/SWS/Threshold_LS/Hole filled/LabelMap/3D.mha" );
  reader->Update();
  data->SetImageData(reader->GetOutput());
  reader->Delete();

  // Set the first stroke as the initial segmentation.
  drawing->AddNewStroke(0, vtkKWEPaintbrushEnums::Draw, data);

  // Instead of the above line, you can set this directly as the new stencil,
  // saves some memory, as the overhead data of an extra stroke need not be
  // managed.
  // drawing->SetPaintbrushData(data);

  for (unsigned int i = 0; i < set->GetNumberOfWidgets(); i++)
    {
    vtkKWEPaintbrushRepresentation * repr =
      vtkKWEPaintbrushRepresentation::SafeDownCast(
        set->GetNthWidget(i)->GetRepresentation());
    repr->SetPaintbrushDrawing( drawing );
    }

  set->SetEnabled(1);
  paintbrushTesting->Run();


  // Save out the resulting segmentation.
  //
  vtkImageData * output = vtkImageData::New();
  drawing->GetPaintbrushData()->
                    GetPaintbrushDataAsImageData( output );
  vtkMetaImageWriter * outputWriter = vtkMetaImageWriter::New();
  outputWriter->SetFileName("Drawing.mha");
  outputWriter->SetInput( output );
  outputWriter->Write();

  // Save out each of the resulting segmentations.
  //
  for (int i = 0; i < drawing->GetNumberOfItems(); i++)
    {
    vtkImageData * outputN = vtkImageData::New();
    drawing->GetItem(i)->GetPaintbrushData()->
                    GetPaintbrushDataAsImageData( outputN );
    vtkMetaImageWriter * outputWriterN = vtkMetaImageWriter::New();
    std::ostringstream filenameN;
    filenameN << "Drawing" << i << ".mha" << std::ends;
    outputWriterN->SetFileName(filenameN.str().c_str());
    outputWriterN->SetInput( outputN );
    outputWriterN->Write();
    outputWriterN->Delete();
    outputN->Delete();
    }

  data->Delete();
  outputWriter->Delete();
  output->Delete();
  set->Delete();
  paintbrushTesting->Delete();

  return 0;


-----邮件原件-----
发件人: Karthik Krishnan [mailto:karthik.krishnan at kitware.com] 
发送时间: 2011년 3월 23일 수요일 오후 5:47
收件人: Xiaopeng Yang
抄送: vtk; VtkEdge at vtkedge.org
主题: Re: [vtkusers] How to make the paintbrush paint only on one slice, not on the neighbor slices

I apologize for the delay in getting back to your earlier mails. I
hope you've figured those out :).

To make the paintbrush go into slice by slice edit mode, you simply
set the width of the paintbrush shape along that axis to one unit
spacing along that axis....

paintbrushOperation->GetPaintbrushShape()->SetWidth(10,10,spacingZ)

On 3/23/11, Xiaopeng Yang <yxp233 at postech.ac.kr> wrote:
> Dear users,
>
>
>
> I found that when I painted on one slice of a series of images, the neighbor
> slices were also painted. My question is how to make the paintbrush paint
> only on that slice, not on the neighbor slices.
>
>
>
> Thanks very much in advance!
>
>
>
> Yang
>
>










More information about the vtkusers mailing list