<div dir="ltr"><div class="gmail_default" style="font-size:small">The fact you changed the resolution and got the same issues means it is not related to something in the vtkParametric classes. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">BTW I'm getting no crashes in Linux.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Regards</div><div class="gmail_default" style="font-size:small"> Andrew</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 7, 2018 at 4:00 AM, Jeffery Lewis <span dir="ltr"><<a href="mailto:jlewis@accuray.com" target="_blank">jlewis@accuray.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thank you Andrew for looking into this.<br>
<br>
Doing the changes does seem to work. Unfortunately, if you change the resolution of the surface model by adding the following two lines of code...<br>
<br>
source->SetPhiResolution(100);<br>
source->SetThetaResolution(<wbr>100);<br>
<br>
...you will see the same type of issues on the filled contour.<br>
<br>
Also, if I substitute the vtkPlaneCutter for the vtkCutter using the vtkSuperquadricSource, it crashes in a similar way.<br>
<br><br>
Message: 11<br>
Date: Tue, 6 Mar 2018 15:24:06 +1100<br>
From: Andrew Maclean <<a href="mailto:andrew.amaclean@gmail.com">andrew.amaclean@gmail.com</a>><br>
To: vtk <<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>><br>
Cc: Jeffery Lewis <<a href="mailto:jlewis@accuray.com">jlewis@accuray.com</a>><br>
Subject: Re: [vtkusers] Problem with vtkContourTriangulator and<br>
vtkPlaneCutter (Jeffery Lewis)<br>
Message-ID:<br>
<<a href="mailto:CAHDsG9Ny9mCJsY4BCetcYowhQdPftzVhPcdspXCSW8nwdyvVhA@mail.gmail.com">CAHDsG9Ny9mCJsY4BCetcYowhQdPf<wbr>tzVhPcdspXCSW8nwdyvVhA@mail.<wbr>gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Jeffery<br>
<br>
?I think this is related to the ParametricFunctions. These functions are<br>
generated by mapping R? -> R? and are then triangulated.<br>
I tried vtkParametricSuperToroid and sometimes the contouring and cutting<br>
worked but in some orientations the triangulation failed.<br>
<br>
?If you use a vtkSuperquadricSource e.g:<br>
vtkSmartPointer<<wbr>vtkSuperquadricSource> source =<br>
vtkSmartPointer<<wbr>vtkSuperquadricSource>::New();<br>
source->SetCenter(0, 0, 0);<br>
source->SetPhiRoundness(1.0);<br>
source->SetThetaRoundness(1.0)<wbr>;<br>
source->ToroidalOn();<br>
<br>
Everything seems to work Ok.<br>
<br>
Andrew<br>
<br>
<br>
> ---------- Forwarded message ----------<br>
> From: Jeffery Lewis <<a href="mailto:jlewis@accuray.com">jlewis@accuray.com</a>><br>
> To: "<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>" <<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>><br>
> Cc:<br>
> Bcc:<br>
> Date: Fri, 2 Mar 2018 23:46:09 +0000<br>
> Subject: Re: [vtkusers] Problem with vtkContourTriangulator and<br>
> vtkPlaneCutter (Jeffery Lewis)<br>
> Seems like the attachments didn't go through. Here is the code.<br>
><br>
> #include <vtkSmartPointer.h><br>
> #include <vtkParametricSuperToroid.h><br>
> #include <vtkParametricFunctionSource.<wbr>h><br>
> #include <vtkSphereSource.h><br>
> #include <vtkCamera.h><br>
> #include <vtkPolyDataMapper.h><br>
> #include <vtkPolyDataMapper2D.h><br>
> #include <vtkDataSetMapper.h><br>
> #include <vtkCompositePolyDataMapper.h><br>
> #include <vtkActor.h><br>
> #include <vtkActor2D.h><br>
> #include <vtkPlane.h><br>
> #include <vtkCutter.h><br>
> #include <vtkPlaneCutter.h><br>
> #include <vtkProperty.h><br>
> #include <vtkProperty2D.h><br>
> #include <vtkRenderWindow.h><br>
> #include <vtkRenderer.h><br>
> #include <vtkRenderWindowInteractor.h><br>
> #include <vtkMath.h><br>
> #include <vtkInteractorStyle.h><br>
> #include <vtkInteractorStyleImage.h><br>
> #include <vtkTransform.h><br>
> #include <vtkContourTriangulator.h><br>
> #include <vtkCleanPolyData.h><br>
> #include <vtkConeSource.h><br>
> #include <vtkCommand.h><br>
> #include <vtkSliderWidget.h><br>
> #include <vtkSliderRepresentation2D.h><br>
><br>
> // Callbacks for the interactions<br>
> class SliderCallbackN1 : public vtkCommand {<br>
> public:<br>
> static SliderCallbackN1 *New() {<br>
> return new SliderCallbackN1;<br>
> }<br>
> virtual void Execute(vtkObject *caller, unsigned long, void*) {<br>
> vtkSliderWidget *sliderWidget =<br>
> reinterpret_cast<<wbr>vtkSliderWidget*>(caller);<br>
> double value = static_cast<<wbr>vtkSliderRepresentation2D *>(sliderWidget-><br>
> GetRepresentation())-><wbr>GetValue();<br>
> this->SuperToroid->SetN1(<wbr>value);<br>
> }<br>
> SliderCallbackN1() :SuperToroid(0) {}<br>
> vtkParametricSuperToroid *SuperToroid;<br>
> };<br>
><br>
> class SliderCallbackN2 : public vtkCommand {<br>
> public:<br>
> static SliderCallbackN2 *New() {<br>
> return new SliderCallbackN2;<br>
> }<br>
> virtual void Execute(vtkObject *caller, unsigned long, void*) {<br>
> vtkSliderWidget *sliderWidget =<br>
> reinterpret_cast<<wbr>vtkSliderWidget*>(caller);<br>
> double value = static_cast<<wbr>vtkSliderRepresentation2D *>(sliderWidget-><br>
> GetRepresentation())-><wbr>GetValue();<br>
> this->SuperToroid->SetN2(<wbr>value);<br>
> }<br>
> SliderCallbackN2() :SuperToroid(0) {}<br>
> vtkParametricSuperToroid *SuperToroid;<br>
> };<br>
><br>
> /**This callback will rotate the surface model about x and y axis<br>
> depending on the<br>
> *current location of the mouse. This will in turn update the cut plane<br>
> that is ment to<br>
> *be normal to the camera and cuts through the middle of the model, showing<br>
> a red<br>
> *cut contour, and green filled contour. */<br>
> class InteractionCallback : public vtkCommand {<br>
> public:<br>
> static InteractionCallback* New() {<br>
> return new InteractionCallback;<br>
> }<br>
><br>
> virtual void Execute(vtkObject*, unsigned long eventID, void* pCallData)<br>
> VTK_OVERRIDE {<br>
> if (eventID == vtkCommand::MouseMoveEvent) {<br>
> // Get the current mouse position.<br>
> int aiCurrentPosition[2];<br>
> m_pInteractor-><wbr>GetEventPosition(<wbr>aiCurrentPosition);<br>
><br>
> // Get the view port size.<br>
> int iViewPortWidth = m_pInteractor-><wbr>GetRenderWindow()->GetSize()[<wbr>0];<br>
> int iViewPortHeight = m_pInteractor-><wbr>GetRenderWindow()->GetSize()[<wbr>1];<br>
><br>
> // Compute rotations about x and y axis.<br>
> int iMousePositionAboutCenterX = aiCurrentPosition[0] - iViewPortWidth/2.0;<br>
> int iMousePositionAboutCenterY = aiCurrentPosition[1] -<br>
> iViewPortHeight/2.0;<br>
> double dRotationAboutX = -iMousePositionAboutCenterY/(<br>
> iViewPortHeight/2.0)*180.0;<br>
> double dRotationAboutY = iMousePositionAboutCenterX/(<br>
> iViewPortWidth/2.0)*180.0;<br>
><br>
> // Compute transform.<br>
> vtkSmartPointer<vtkTransform> sptmSurfacModel =<br>
> vtkSmartPointer<vtkTransform>:<wbr>:New();<br>
> sptmSurfacModel->RotateX(<wbr>dRotationAboutX);<br>
> sptmSurfacModel->RotateY(<wbr>dRotationAboutY);<br>
><br>
> // Apply the rotation to the surface model actor.<br>
> m_pActorSurface-><wbr>SetUserMatrix(sptmSurfacModel-<wbr>>GetMatrix());<br>
><br>
> // Apply the change to the cut plan normal vector.<br>
> // Translations are not required to be removed from the matrix since there<br>
> should be none.<br>
> double adInitialVector[3];<br>
> adInitialVector[0] = 0.0;<br>
> adInitialVector[1] = 0.0;<br>
> adInitialVector[2] = 1.0;<br>
> double adTransformedVector[3];<br>
> sptmSurfacModel-><wbr>TransformPoint(<wbr>adInitialVector, adTransformedVector);<br>
> m_pCutPlane->SetNormal(<wbr>adTransformedVector[0], adTransformedVector[1],<br>
> adTransformedVector[2]);<br>
><br>
> // Apply the rotation to the contour actor in the opposite direction to<br>
> make normal to camera.<br>
> sptmSurfacModel->Inverse();<br>
> m_pActorContour-><wbr>SetUserMatrix(sptmSurfacModel-<wbr>>GetMatrix());<br>
><br>
> // Apply the rotation to the filled actor in the opposite direction to<br>
> make normal to camera.<br>
> m_pActorFilled->SetUserMatrix(<wbr>sptmSurfacModel->GetMatrix());<br>
><br>
> m_pInteractor->Render();<br>
> }<br>
> }<br>
><br>
> // Member variables<br>
> // ----------------<br>
> vtkRenderWindowInteractor* m_pInteractor;<br>
> vtkActor* m_pActorSurface;<br>
> vtkPlane* m_pCutPlane;<br>
> vtkActor* m_pActorContour;<br>
> vtkActor* m_pActorFilled;<br>
> };<br>
><br>
><br>
> int main(int, char *[]) {<br>
><br>
> vtkSmartPointer<<wbr>vtkParametricSuperToroid> surface =vtkSmartPointer<<br>
> vtkParametricSuperToroid>::<wbr>New();<br>
> vtkSmartPointer<<wbr>vtkParametricFunctionSource> source = vtkSmartPointer<<br>
> vtkParametricFunctionSource>::<wbr>New();<br>
> source->SetParametricFunction(<wbr>surface);<br>
><br>
> // Create a synthetic cone.<br>
> /*// Un-commented out so can switch surface model source.<br>
> vtkSmartPointer<vtkConeSource> source = vtkSmartPointer<vtkConeSource><br>
> ::New();<br>
> source->SetCenter(0, 0, 0);<br>
> source->SetRadius(1);<br>
> source->SetHeight(2);<br>
> source->SetResolution(30);<br>
> source->Update();<br>
> */<br>
><br>
> vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>:<br>
> :New();<br>
> vtkSmartPointer<<wbr>vtkPolyDataMapper> mapper =vtkSmartPointer<<br>
> vtkPolyDataMapper>::New();<br>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::<wbr>New();<br>
><br>
> mapper->SetInputConnection(<wbr>source->GetOutputPort());<br>
><br>
> vtkSmartPointer<vtkProperty> backProperty = vtkSmartPointer<vtkProperty>::<br>
> New();<br>
> backProperty->SetColor(0.8, 0.8, 0.8);<br>
> backProperty->SetOpacity(0.6);<br>
> actor->SetMapper(mapper);<br>
> actor->SetBackfaceProperty(<wbr>backProperty);<br>
> actor->GetProperty()-><wbr>SetDiffuseColor(1, 1, 1);<br>
> actor->GetProperty()-><wbr>SetOpacity(0.6);<br>
><br>
> vtkSmartPointer<<wbr>vtkRenderWindow> renderWindow =vtkSmartPointer<<br>
> vtkRenderWindow>::New();<br>
> renderWindow->AddRenderer(<wbr>renderer);<br>
> renderWindow->SetSize(640, 480);<br>
> renderer->AddActor(actor);<br>
> renderer->SetBackground(.2, .3, .4);<br>
><br>
> vtkSmartPointer<<wbr>vtkRenderWindowInteractor> interactor =vtkSmartPointer<<br>
> vtkRenderWindowInteractor>::<wbr>New();<br>
> interactor->SetRenderWindow(<wbr>renderWindow);<br>
><br>
> // Setup a slider widget for each varying parameter BEGIN<br>
> double tubeWidth(.004);<br>
> double sliderLength(.004);<br>
> double titleHeight(.02);<br>
> double labelHeight(.02);<br>
><br>
> vtkSmartPointer<<wbr>vtkSliderRepresentation2D> sliderRepN1 = vtkSmartPointer<<br>
> vtkSliderRepresentation2D>::<wbr>New();<br>
><br>
> sliderRepN1->SetMinimumValue(<wbr>0.0);<br>
> sliderRepN1->SetMaximumValue(<wbr>4.0);<br>
> sliderRepN1->SetValue(1.0);<br>
> sliderRepN1->SetTitleText("Z squareness");<br>
><br>
> sliderRepN1-><wbr>GetPoint1Coordinate()-><wbr>SetCoordinateSystemToNormalize<br>
> dDisplay();<br>
> sliderRepN1-><wbr>GetPoint1Coordinate()-><wbr>SetValue(.1, .1);<br>
> sliderRepN1-><wbr>GetPoint2Coordinate()-><wbr>SetCoordinateSystemToNormalize<br>
> dDisplay();<br>
> sliderRepN1-><wbr>GetPoint2Coordinate()-><wbr>SetValue(.9, .1);<br>
><br>
> sliderRepN1->SetTubeWidth(<wbr>tubeWidth);<br>
> sliderRepN1->SetSliderLength(<wbr>sliderLength);<br>
> sliderRepN1->SetTitleHeight(<wbr>titleHeight);<br>
> sliderRepN1->SetLabelHeight(<wbr>labelHeight);<br>
><br>
> vtkSmartPointer<<wbr>vtkSliderWidget> sliderWidgetN1 = vtkSmartPointer<<br>
> vtkSliderWidget>::New();<br>
> sliderWidgetN1->SetInteractor(<wbr>interactor);<br>
> sliderWidgetN1-><wbr>SetRepresentation(sliderRepN1)<wbr>;<br>
> sliderWidgetN1-><wbr>SetAnimationModeToAnimate();<br>
> sliderWidgetN1->EnabledOn();<br>
><br>
> vtkSmartPointer<<wbr>SliderCallbackN1> callbackN1 = vtkSmartPointer<<br>
> SliderCallbackN1>::New();<br>
> callbackN1->SuperToroid = surface;<br>
><br>
> sliderWidgetN1->AddObserver(<wbr>vtkCommand::InteractionEvent, callbackN1);<br>
><br>
> vtkSmartPointer<<wbr>vtkSliderRepresentation2D> sliderRepN2 = vtkSmartPointer<<br>
> vtkSliderRepresentation2D>::<wbr>New();<br>
><br>
> sliderRepN2->SetMinimumValue(<wbr>0.0001);<br>
> sliderRepN2->SetMaximumValue(<wbr>4.0);<br>
> sliderRepN2->SetValue(1.0);<br>
> sliderRepN2->SetTitleText("XY squareness");<br>
><br>
> sliderRepN2-><wbr>GetPoint1Coordinate()-><wbr>SetCoordinateSystemToNormalize<br>
> dDisplay();<br>
> sliderRepN2-><wbr>GetPoint1Coordinate()-><wbr>SetValue(.1, .9);<br>
> sliderRepN2-><wbr>GetPoint2Coordinate()-><wbr>SetCoordinateSystemToNormalize<br>
> dDisplay();<br>
> sliderRepN2-><wbr>GetPoint2Coordinate()-><wbr>SetValue(.9, .9);<br>
><br>
> sliderRepN2->SetTubeWidth(<wbr>tubeWidth);<br>
> sliderRepN2->SetSliderLength(<wbr>sliderLength);<br>
> sliderRepN2->SetTitleHeight(<wbr>titleHeight);<br>
> sliderRepN2->SetLabelHeight(<wbr>labelHeight);<br>
><br>
> vtkSmartPointer<<wbr>vtkSliderWidget> sliderWidgetN2 = vtkSmartPointer<<br>
> vtkSliderWidget>::New();<br>
> sliderWidgetN2->SetInteractor(<wbr>interactor);<br>
> sliderWidgetN2-><wbr>SetRepresentation(sliderRepN2)<wbr>;<br>
> sliderWidgetN2-><wbr>SetAnimationModeToAnimate();<br>
> sliderWidgetN2->EnabledOn();<br>
><br>
> vtkSmartPointer<<wbr>SliderCallbackN2> callbackN2 = vtkSmartPointer<<br>
> SliderCallbackN2>::New();<br>
> callbackN2->SuperToroid = surface;<br>
><br>
> sliderWidgetN2->AddObserver(<wbr>vtkCommand::InteractionEvent, callbackN2);<br>
><br>
> vtkSmartPointer<<wbr>vtkSliderRepresentation2D> sliderRepMinimumV =<br>
> vtkSmartPointer<<wbr>vtkSliderRepresentation2D>::<wbr>New();<br>
><br>
> sliderRepN1->SetMinimumValue(.<wbr>0001);<br>
> sliderRepMinimumV-><wbr>SetMaximumValue(.9999*vtkMath:<wbr>:Pi());<br>
> sliderRepMinimumV->SetValue(.<wbr>0001);<br>
> sliderRepMinimumV-><wbr>SetTitleText("V min");<br>
><br>
> sliderRepMinimumV-><wbr>GetPoint1Coordinate()-><wbr>SetCoordinateSystemToNormalize<br>
> dDisplay();<br>
> sliderRepMinimumV-><wbr>GetPoint1Coordinate()-><wbr>SetValue(.1, .1);<br>
> sliderRepMinimumV-><wbr>GetPoint2Coordinate()-><wbr>SetCoordinateSystemToNormalize<br>
> dDisplay();<br>
> sliderRepMinimumV-><wbr>GetPoint2Coordinate()-><wbr>SetValue(.1, .9);<br>
><br>
> sliderRepMinimumV-><wbr>SetTubeWidth(tubeWidth);<br>
> sliderRepMinimumV-><wbr>SetSliderLength(sliderLength);<br>
> sliderRepMinimumV-><wbr>SetTitleHeight(titleHeight);<br>
> sliderRepMinimumV-><wbr>SetLabelHeight(labelHeight);<br>
><br>
> surface->SetN1(1.0);<br>
> surface->SetN2(1.0);<br>
> // Setup a slider widget for each varying parameter END<br>
><br>
> // Set up the cut plane.<br>
> vtkSmartPointer<vtkPlane> planeCut = vtkSmartPointer<vtkPlane>::<wbr>New();<br>
> planeCut->SetOrigin(0.0, 0.0, 0.0);<br>
> planeCut->SetNormal(0.0, 0.0, 1.0);<br>
><br>
> // Set up the cutter which will produce the contour polygons.<br>
> vtkSmartPointer<vtkCutter> polygonsContour = vtkSmartPointer<vtkCutter>::<br>
> New();<br>
> //vtkSmartPointer<<wbr>vtkPlaneCutter> polygonsContour = vtkSmartPointer<<wbr>vtkPlaneCutter>::New();<br>
> // testjal<br>
> polygonsContour-><wbr>SetInputConnection(source-><wbr>GetOutputPort());<br>
> //polygonsContour->SetPlane(<wbr>planeCut); // SetPlane only works with a<br>
> vtkPlaneCutter. // testjal<br>
> polygonsContour-><wbr>SetCutFunction(planeCut);<br>
><br>
> // Clean the polygons from the cutter. Note, this is an experiment to see<br>
> if this helps the fills. It does not<br>
> // seem to help.<br>
> vtkSmartPointer<<wbr>vtkCleanPolyData> polygonsContourClean = vtkSmartPointer<<wbr>vtkCleanPolyData>::New();<br>
> // testjal<br>
> polygonsContourClean-><wbr>SetInputConnection(<wbr>polygonsContour-><wbr>GetOutputPort());<br>
> // testjal<br>
><br>
> // Set up the filled polygons of the contour.<br>
> vtkSmartPointer<<wbr>vtkContourTriangulator> polygonsFilled = vtkSmartPointer<<br>
> vtkContourTriangulator>::New()<wbr>;<br>
> polygonsFilled-><wbr>SetInputConnection(<wbr>polygonsContourClean-><wbr>GetOutputPort());<br>
> polygonsFilled-><wbr>TriangulationErrorDisplayOn(); // testjal<br>
><br>
> // Set up the mapper of the contour.<br>
> vtkSmartPointer<<wbr>vtkDataSetMapper> mapperContour = vtkSmartPointer<<br>
> vtkDataSetMapper>::New();<br>
> mapperContour-><wbr>SetInputConnection(<wbr>polygonsContourClean-><wbr>GetOutputPort());<br>
> mapperContour-><wbr>ScalarVisibilityOff();<br>
><br>
> // Set up the mapper of the filled polygons of the contour<br>
> vtkSmartPointer<<wbr>vtkDataSetMapper> mapperFilled = vtkSmartPointer<<br>
> vtkDataSetMapper>::New();<br>
> mapperFilled-><wbr>SetInputConnection(<wbr>polygonsFilled->GetOutputPort(<wbr>));<br>
> mapperFilled-><wbr>ScalarVisibilityOff();<br>
><br>
> // Set up the actor of the contour.<br>
> vtkSmartPointer<vtkActor> actorContour = vtkSmartPointer<vtkActor>::<wbr>New();<br>
> actorContour->SetMapper(<wbr>mapperContour);<br>
> actorContour->GetProperty()-><wbr>SetColor(1,0,0);<br>
> actorContour->GetProperty()-><wbr>SetLineWidth(5);<br>
><br>
> // Set up the actor of the filled polygons of the contour.<br>
> vtkSmartPointer<vtkActor> actorFilled = vtkSmartPointer<vtkActor>::<wbr>New();<br>
> actorFilled->SetMapper(<wbr>mapperFilled);<br>
> actorFilled->GetProperty()-><wbr>SetColor(0, 1, 0);<br>
><br>
> // Add the contour actor.<br>
> renderer->AddActor(<wbr>actorContour);<br>
><br>
> // Add the filld polygons of the contour.<br>
> renderer->AddActor(<wbr>actorFilled);<br>
><br>
> // Set up the interaction.<br>
> vtkSmartPointer<<wbr>InteractionCallback> callback = vtkSmartPointer<<br>
> InteractionCallback>::New();<br>
> callback->m_pInteractor = interactor.Get();<br>
> callback->m_pActorSurface = actor.Get();<br>
> callback->m_pCutPlane = planeCut.Get();<br>
> callback->m_pActorContour = actorContour.Get();<br>
> callback->m_pActorFilled = actorFilled.Get();<br>
> vtkSmartPointer<<wbr>vtkInteractorStyle> style = vtkSmartPointer<<br>
> vtkInteractorStyle>::New();<br>
> interactor-><wbr>SetInteractorStyle(style);<br>
> style->AddObserver(vtkCommand:<wbr>:MouseMoveEvent, callback);<br>
><br>
> renderer->ResetCamera(-1, 1, -1, 1, -1, 1);<br>
> renderer->GetActiveCamera()-><wbr>ParallelProjectionOn();<br>
> renderWindow->Render();<br>
><br>
> interactor->Initialize();<br>
><br>
> interactor->Start();<br>
><br>
> return EXIT_SUCCESS;<br>
> }<br>
><br></blockquote></div>-- <br><div class="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div>
</div></div>