[vtkusers] Question about drawing contours on different slices and display them
Jonathan Morra
jonmorra at gmail.com
Sun Oct 17 14:31:02 EDT 2010
First, I implemented this in Java, but here's what I did. I created a data
structure that is an array of sets. The length of the array is the same as
the number of planes in the direction I was drawing on (for me that was the
XY plane). The elements in the array were sets because I can have multiple
contours on each plane. For each contour I used a vtkImageActorPointPlacer.
This causes the contours to always be drawn above the image. Then, every
time the XY plane that was being viewed changed, I set every contour in my
dataset to Off(), and turned On only those contours that were on the plane
being viewed. This gives the effect of contours being associated with
specific planes.
On Sat, Oct 16, 2010 at 11:58 PM, <shengwen.guo at gmail.com> wrote:
> Dear Mr.Jonathan Morra
> I have a question about the contours for 3D data as same as it at
> http://vtk.1045678.n5.nabble.com/Question-about-contour-widget-td3208404.html#a3211419
> Would you please help me to solve this problem or send me a sample code?
> Thanks,
> Shengwen
>
> My code is as following:
>
>
>
> ///////////////////////////////////////////
> // TestContours.cxx
> // lars
> ////////////////////////////////////////////
>
> #include "vtkImageData.h"
> #include "vtkVolume16Reader.h"
> #include "vtkImageShiftScale.h"
> #include "vtkImageViewer2.h"
> #include "vtkPoints.h"
> #include "vtkPolyData.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkSliderRepresentation.h"
> #include "vtkSliderRepresentation2D.h"
> #include "vtkSliderWidget.h"
> #include "vtkCommand.h"
> #include "vtkContourWidget.h"
> // Add the following header files by shengwen at GZ 10/17/2010
>
> #include "vtkOrientedGlyphContourRepresentation.h"
> #include "vtkContourWidget.h"
> #include "vtkImageActorPointPlacer.h"
> #include "vtkTestUtilities.h"
> #include "vtkBoundedPlanePointPlacer.h"
>
> class vtkSliderCallback : public vtkCommand
> {
> public:
> static vtkSliderCallback *New()
> { return new vtkSliderCallback; }
> void Delete()
> { delete this; }
> void SetImageViewer(vtkImageViewer2 *viewer)
> { m_Viewer = viewer; }
> virtual void Execute(vtkObject *caller, unsigned long ul, void* vd)
> {
> vtkSliderWidget *slider = (vtkSliderWidget *)caller;
> vtkSliderRepresentation *sliderRepres = (vtkSliderRepresentation
> *)slider->GetRepresentation();
> int pos = (int)sliderRepres->GetValue();
>
> m_Viewer->SetSlice(pos);
> }
> protected:
> vtkImageViewer2 *m_Viewer;
> };
>
> int main(int argc, char *argv[])
> {
> char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv,
> "Data/headsq/quarter");
> //char* fname = "/home/philipp/libs/vtk/VTKData/Data/headsq/quarter";
>
> vtkVolume16Reader* v16 = vtkVolume16Reader::New();
> v16->SetDataDimensions(64, 64);
> v16->SetDataByteOrderToLittleEndian();
> v16->SetImageRange(1, 93);
> v16->SetDataSpacing(3.2, 3.2, 1.5);
> v16->SetFilePrefix(fname);
> v16->ReleaseDataFlagOn();
> v16->SetDataMask(0x7fff);
> v16->Update();
> //delete[] fname;
>
> double range[2];
> v16->GetOutput()->GetScalarRange(range);
>
> vtkImageShiftScale* shifter = vtkImageShiftScale::New();
> shifter->SetShift(-1.0*range[0]);
> shifter->SetScale(255.0/(range[1]-range[0]));
> shifter->SetOutputScalarTypeToUnsignedChar();
> shifter->SetInputConnection(v16->GetOutputPort());
> shifter->ReleaseDataFlagOff();
> shifter->Update();
>
>
> vtkImageViewer2 *ImageViewer = vtkImageViewer2::New();
> ImageViewer->SetInput(shifter->GetOutput());
> ImageViewer->SetColorLevel(127);
> ImageViewer->SetColorWindow(255);
>
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> ImageViewer->SetupInteractor(iren);
>
> ImageViewer->Render();
> ImageViewer->GetRenderer()->ResetCamera();
>
> ImageViewer->Render();
>
> int *dims = v16->GetOutput()->GetDimensions();
> std::cout << dims[0] << "," << dims[1] << "," << dims[2] << "\n";
>
> vtkSliderRepresentation2D *SliderRepres =
> vtkSliderRepresentation2D::New();
> int min = ImageViewer->GetSliceMin();
> int max = ImageViewer->GetSliceMax();
> SliderRepres->SetMinimumValue(min);
> SliderRepres->SetMaximumValue(max);
> SliderRepres->SetValue((int)((min + max) / 2));
> SliderRepres->SetTitleText("Slice");
>
> SliderRepres->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay();
> SliderRepres->GetPoint1Coordinate()->SetValue(0.3, 0.05);
>
> SliderRepres->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay();
> SliderRepres->GetPoint2Coordinate()->SetValue(0.7, 0.05);
> SliderRepres->SetSliderLength(0.02);
> SliderRepres->SetSliderWidth(0.03);
> SliderRepres->SetEndCapLength(0.01);
> SliderRepres->SetEndCapWidth(0.03);
> SliderRepres->SetTubeWidth(0.005);
> SliderRepres->SetLabelFormat("%3.0lf");
> SliderRepres->SetTitleHeight(0.02);
> SliderRepres->SetLabelHeight(0.02);
>
> vtkSliderWidget *SliderWidget = vtkSliderWidget::New();
> SliderWidget->SetInteractor(iren);
> SliderWidget->SetRepresentation(SliderRepres);
> SliderWidget->KeyPressActivationOff();
> SliderWidget->SetAnimationModeToAnimate();
> SliderWidget->SetEnabled(true);
>
> vtkSliderCallback *SliderCb = vtkSliderCallback::New();
> SliderCb->SetImageViewer(ImageViewer);
> SliderWidget->AddObserver(vtkCommand::InteractionEvent, SliderCb);
>
> ImageViewer->SetSlice((int)SliderRepres->GetValue());
>
> // vtkContourWidget *ContourWidget = vtkContourWidget::New();
> // Change new codes
>
> vtkOrientedGlyphContourRepresentation *rep =
> vtkOrientedGlyphContourRepresentation::New();
> vtkContourWidget *ContourWidget = vtkContourWidget::New();
> ContourWidget->SetRepresentation(rep);
> // Add
> vtkBoundedPlanePointPlacer *placer =
> vtkBoundedPlanePointPlacer::New();
> placer->SetProjectionNormalToZAxis();
>
> //placer.SetProjectionPosition(panel.getImageViewer().GetImageActor().GetCenter()[2]);
> rep->SetPointPlacer(placer);
> //
>
> vtkImageActorPointPlacer * imageActorPointPlacer =
> vtkImageActorPointPlacer::New();
> imageActorPointPlacer->SetImageActor(ImageViewer->GetImageActor());
> rep->SetPointPlacer(imageActorPointPlacer);
>
> imageActorPointPlacer->Delete();
> rep->Delete();
>
> // end of changing new codes
>
>
> ContourWidget->SetInteractor(iren);
> ContourWidget->SetEnabled(true);
> ContourWidget->ProcessEventsOn();
>
> iren->Start();
>
> return -1;
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101017/bb862dd3/attachment.htm>
More information about the vtkusers
mailing list