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

Xiaopeng Yang yxp233 at postech.ac.kr
Mon Mar 28 10:50:59 EDT 2011


Hi Karthik,

 

I did as you suggested. Unfortunately it did not work. Still if I paint or erase some part on one slice, the connected slices are also painted or erased. Please check the code I modified from paintbrushtest6.

 

int main( int argc, char *argv[] )

{

  

  vtkKWEPaintbrushTesting *paintbrushTesting = vtkKWEPaintbrushTesting::New();

  paintbrushTesting->SetFilename( "C:/Users/User/Desktop/CT data/SWS/Diffusion/mha/3D.mha" );

  paintbrushTesting->Initialize();

  vtkImageData * imageData  = paintbrushTesting->GetInput();

 

  vtkKWEWidgetGroup *set = vtkKWEWidgetGroup::New();

 

  for (int i = 0; i < 1; 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() );      

      }

 

    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( "C:/Users/User/Desktop/CT data/SWS/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월 28일 월요일 오후 5:16
收件人: Xiaopeng Yang
抄送: vtk; VtkEdge at vtkedge.org
主题: Re: [vtkusers] How to make the paintbrush paint only on one slice, not on the neighbor slices

 

Ok.. I made the API simpler that setting the shape size...

 

If you do :

 

   paintbrushRepresentation2D->SetSingleSliceThickBrush(true);

 

you will get a slice by slice edit, ie the edits will be confined to the a single slice on all your views (axial/coronal/sagittal).

 

That's it :). I checked this in a few weeks ago. So please be sure to update the repository.

 

 

----

 

The issue with setting the Shape size to flatten along an axis was that this had to be managed at the application level, since you have to flatten the shape when you switch views.

 

Thanks

--

karthik

 

On Mon, Mar 28, 2011 at 5:54 AM, Xiaopeng Yang <yxp233 at postech.ac.kr> wrote:

Sorry I mean "Hello" not "Hell".


-----邮件原件-----
发件人: Xiaopeng Yang [mailto:yxp233 at postech.ac.kr]

发送时间: 2011년 3월 28일 월요일 오전 9:24

收件人: 'Karthik Krishnan'
抄送: 'vtk'; 'VtkEdge at vtkedge.org'

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


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
>
>








 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110328/5441c780/attachment.htm>


More information about the vtkusers mailing list