1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
23 // File : VVTK_ImplicitFunctionWidget.cxx
24 // Author : Peter KURNEV
28 #include "VISU_PlanesWidget.hxx"
29 #include "VISU_ImplicitFunctionWidget.hxx"
32 #include <vtkAssemblyNode.h>
33 #include <vtkAssemblyPath.h>
34 #include <vtkCallbackCommand.h>
35 #include <vtkCamera.h>
36 #include <vtkCellPicker.h>
37 #include <vtkConeSource.h>
38 #include <vtkCutter.h>
39 #include <vtkFeatureEdges.h>
40 #include <vtkImageData.h>
41 #include <vtkLineSource.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkOutlineFilter.h>
46 #include <vtkPolyData.h>
47 #include <vtkPolyDataMapper.h>
48 #include <vtkProperty.h>
49 #include <vtkRenderWindowInteractor.h>
50 #include <vtkRenderer.h>
51 #include <vtkSphereSource.h>
52 #include <vtkTransform.h>
53 #include <vtkTubeFilter.h>
54 #include <vtkImplicitBoolean.h>
55 #include <vtkImplicitFunctionCollection.h>
57 #include <vtkFollower.h>
58 #include <vtkObjectFactory.h>
59 #include <vtkDataSet.h>
60 #include <vtkRenderWindow.h>
64 IsValidPlane2Position(vtkPlane *pPx,
66 vtkFloatingPointType aTol=0.003);
69 GetBndPoints(vtkDataSet *pDataSet,
70 vtkFloatingPointType aPnts[24]);
73 DistanceToPlane(const vtkFloatingPointType x[3],
74 const vtkFloatingPointType n[3],
75 const vtkFloatingPointType p0[3]);
77 vtkCxxRevisionMacro(VISU_PlanesWidget, "$Revision$");
78 vtkStandardNewMacro(VISU_PlanesWidget);
80 //==================================================================
81 // function: VISU_PlanesWidget
83 //==================================================================
84 VISU_PlanesWidget::VISU_PlanesWidget()
86 VISU_ImplicitFunctionWidget()
88 State = VISU_PlanesWidget::Start;
89 EventCallbackCommand->SetCallback(VISU_PlanesWidget::ProcessEvents);
95 HandleMoveEvent = true;
96 HandleLeftButtonEvent = true;
97 HandleMiddleButtonEvent = false;
98 HandleRightButtonEvent = false;
100 // Build the representation of the widget
102 myPlane1 = vtkPlane::New();
103 myPlane1->SetNormal(0,0,1);
104 myPlane1->SetOrigin(0,0,0);
107 myPlane2 = vtkPlane::New();
108 myPlane2->SetNormal(0.,0.,-1.);
109 myPlane2->SetOrigin(0,0,myDistance);
111 myImplicitFunction = vtkImplicitBoolean::New();
112 myImplicitFunction->SetOperationType(VTK_UNION);
114 myBox = vtkImageData::New();
115 myBox->SetDimensions(2,2,2);
116 myOutline = vtkOutlineFilter::New();
117 myOutline->SetInput(myBox);
118 myOutlineMapper = vtkPolyDataMapper::New();
119 myOutlineMapper->SetInput(myOutline->GetOutput());
120 myOutlineActor = vtkActor::New();
121 this->myOutlineActor->SetMapper(this->myOutlineMapper);
122 this->myOutlineActor->PickableOff();
123 this->OutlineTranslation = 0;
125 this->myCutter1 = vtkCutter::New();
126 this->myCutter1->SetInput(myBox);
127 this->myCutter1->SetCutFunction(myPlane1);
128 this->myCutMapper1 = vtkPolyDataMapper::New();
129 this->myCutMapper1->SetInput(this->myCutter1->GetOutput());
130 this->myCutActor1 = vtkActor::New();
131 this->myCutActor1->SetMapper(this->myCutMapper1);
132 this->myDrawPlane = 1;
134 this->myEdges1 = vtkFeatureEdges::New();
135 myEdges1->SetColoring(0);
136 this->myEdges1->SetInput(this->myCutter1->GetOutput());
137 this->myEdgesMapper1 = vtkPolyDataMapper::New();
138 this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput());
139 this->myEdgesActor1 = vtkActor::New();
140 this->myEdgesActor1->SetMapper(this->myEdgesMapper1);
141 myEdgesActor1->GetProperty()->SetLineWidth(4.);
142 myEdgesActor1->GetProperty()->SetColor(0., .5, .7);
144 this->myCutter2 = vtkCutter::New();
145 this->myCutter2->SetInput(myBox);
146 this->myCutter2->SetCutFunction(this->myPlane2);
147 this->myCutMapper2 = vtkPolyDataMapper::New();
148 this->myCutMapper2->SetInput(this->myCutter2->GetOutput());
149 this->myCutActor2 = vtkActor::New();
150 this->myCutActor2->SetMapper(this->myCutMapper2);
152 myEdges2 = vtkFeatureEdges::New();
153 myEdges2->SetColoring(0);
154 myEdges2->SetInput(myCutter2->GetOutput());
155 myEdgesMapper2 = vtkPolyDataMapper::New();
156 myEdgesMapper2->SetInput(myEdges2->GetOutput());
157 myEdgesActor2 = vtkActor::New();
158 myEdgesActor2->SetMapper(myEdgesMapper2);
159 myEdgesActor2->GetProperty()->SetLineWidth(4.);
160 myEdgesActor2->GetProperty()->SetColor(.7, .0, .0);
162 // Create the + plane normal
163 this->LineSource = vtkLineSource::New();
164 this->LineSource->SetResolution(1);
165 this->LineMapper = vtkPolyDataMapper::New();
166 this->LineMapper->SetInput(this->LineSource->GetOutput());
167 this->LineActor = vtkActor::New();
168 this->LineActor->SetMapper(this->LineMapper);
170 this->ConeSource = vtkConeSource::New();
171 this->ConeSource->SetResolution(12);
172 this->ConeSource->SetAngle(20.);
173 this->ConeMapper = vtkPolyDataMapper::New();
174 this->ConeMapper->SetInput(this->ConeSource->GetOutput());
175 this->ConeActor = VISU_UnScaledActor::New();
176 this->ConeActor->SetMapper(this->ConeMapper);
177 ConeActor->SetSize(36);
178 ConeActor->SetCenter(ConeSource->GetCenter());
180 // Create the - plane normal
181 this->LineSource2 = vtkLineSource::New();
182 this->LineSource2->SetResolution(1);
183 this->LineMapper2 = vtkPolyDataMapper::New();
184 this->LineMapper2->SetInput(this->LineSource2->GetOutput());
185 this->LineActor2 = vtkActor::New();
186 this->LineActor2->SetMapper(this->LineMapper2);
188 this->ConeSource2 = vtkConeSource::New();
189 this->ConeSource2->SetResolution(12);
190 this->ConeSource2->SetAngle(20.);
191 this->ConeMapper2 = vtkPolyDataMapper::New();
192 this->ConeMapper2->SetInput(this->ConeSource2->GetOutput());
193 this->ConeActor2 = VISU_UnScaledActor::New();
194 this->ConeActor2->SetMapper(this->ConeMapper2);
195 ConeActor2->SetSize(36);
196 ConeActor2->SetCenter(ConeSource2->GetCenter());
198 // Create the origin handle
199 this->Sphere = vtkSphereSource::New();
200 this->Sphere->SetThetaResolution(16);
201 this->Sphere->SetPhiResolution(8);
202 this->SphereMapper = vtkPolyDataMapper::New();
203 this->SphereMapper->SetInput(this->Sphere->GetOutput());
204 this->SphereActor = VISU_UnScaledActor::New();
205 this->SphereActor->SetMapper(this->SphereMapper);
206 SphereActor->SetSize(36);
207 SphereActor->SetCenter(Sphere->GetCenter());
209 this->Transform = vtkTransform::New();
211 // Define the point coordinates
212 vtkFloatingPointType bounds[6];
220 // Initial creation of the widget, serves to initialize it
221 this->PlaceWidget(bounds);
223 //Manage the picking stuff
224 this->Picker = vtkCellPicker::New();
225 this->Picker->SetTolerance(0.005);
226 this->Picker->AddPickList(this->myCutActor1);
227 this->Picker->AddPickList(this->myCutActor2);
228 this->Picker->AddPickList(this->LineActor);
229 this->Picker->AddPickList(this->ConeActor);
230 this->Picker->AddPickList(this->LineActor2);
231 this->Picker->AddPickList(this->ConeActor2);
232 this->Picker->AddPickList(this->SphereActor);
233 this->Picker->AddPickList(this->myOutlineActor);
234 this->Picker->PickFromListOn();
236 // Set up the initial properties
237 this->CreateDefaultProperties();
240 //==================================================================
243 //==================================================================
244 VISU_PlanesWidget::~VISU_PlanesWidget()
248 this->myPlane2->Delete();
249 this->myImplicitFunction->Delete();
252 this->myOutline->Delete();
253 this->myOutlineMapper->Delete();
254 this->myOutlineActor->Delete();
256 this->myCutter1->Delete();
257 this->myCutMapper1->Delete();
258 this->myCutActor1->Delete();
260 this->myEdges1->Delete();
261 this->myEdgesMapper1->Delete();
262 this->myEdgesActor1->Delete();
265 myCutMapper2->Delete();
266 myCutActor2->Delete();
269 myEdgesMapper2->Delete();
270 myEdgesActor2->Delete();
272 this->LineSource->Delete();
273 this->LineMapper->Delete();
274 this->LineActor->Delete();
276 this->ConeSource->Delete();
277 this->ConeMapper->Delete();
278 this->ConeActor->Delete();
280 this->LineSource2->Delete();
281 this->LineMapper2->Delete();
282 this->LineActor2->Delete();
284 this->ConeSource2->Delete();
285 this->ConeMapper2->Delete();
286 this->ConeActor2->Delete();
288 this->Sphere->Delete();
289 this->SphereMapper->Delete();
290 this->SphereActor->Delete();
292 this->Transform->Delete();
294 this->Picker->Delete();
296 this->NormalProperty->Delete();
297 this->SelectedNormalProperty->Delete();
298 this->PlaneProperty->Delete();
299 this->SelectedPlaneProperty->Delete();
300 this->OutlineProperty->Delete();
301 this->SelectedOutlineProperty->Delete();
302 this->EdgesProperty->Delete();
304 //==================================================================
305 // function: ImplicitFunction
307 //==================================================================
308 vtkImplicitFunction* VISU_PlanesWidget::ImplicitFunction()
310 return this->myImplicitFunction;
312 //==================================================================
313 // function: SetDistance
315 //==================================================================
318 ::SetDistance(const vtkFloatingPointType theDistance)
320 if( theDistance <= 0.0 || theDistance == myDistance )
323 myDistance=theDistance;
325 vtkFloatingPointType *origin, *normal, oNew[3], aN2[3];
326 origin = myPlane1->GetOrigin();
327 normal = myPlane1->GetNormal();
328 vtkMath::Normalize(normal);
329 oNew[0] = origin[0] + myDistance*normal[0];
330 oNew[1] = origin[1] + myDistance*normal[1];
331 oNew[2] = origin[2] + myDistance*normal[2];
332 myPlane2->SetOrigin(oNew);
336 myPlane2->SetNormal(aN2);
338 //==================================================================
339 // function: Distance
341 //==================================================================
348 //==================================================================
349 // function: SetEnabled
351 //==================================================================
352 void VISU_PlanesWidget::SetEnabled(int enabling)
354 if ( ! this->Interactor ) {
355 vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget");
359 if ( enabling ) {//------------------------------------------------------------
360 vtkDebugMacro(<<"Enabling plane widget");
362 if ( this->Enabled ){ //already enabled, just return
366 if ( ! this->CurrentRenderer ){
367 this->CurrentRenderer = this->Interactor->FindPokedRenderer(
368 this->Interactor->GetLastEventPosition()[0],
369 this->Interactor->GetLastEventPosition()[1]);
370 if (this->CurrentRenderer == NULL) {
375 vtkCamera *pCamera=CurrentRenderer->GetActiveCamera();
376 pCamera->SetParallelProjection(1);
378 this->myImplicitFunction->AddFunction(myPlane1);
379 this->myImplicitFunction->AddFunction(this->myPlane2);
383 // listen for the following events
384 vtkRenderWindowInteractor *i = this->Interactor;
385 if( this->HandleMoveEvent ) {
386 i->AddObserver(vtkCommand::MouseMoveEvent,
387 this->EventCallbackCommand,
390 if( this->HandleLeftButtonEvent ) {
391 i->AddObserver(vtkCommand::LeftButtonPressEvent,
392 this->EventCallbackCommand,
394 i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
395 this->EventCallbackCommand,
398 if( this->HandleMiddleButtonEvent ) {
399 i->AddObserver(vtkCommand::MiddleButtonPressEvent,
400 this->EventCallbackCommand,
402 i->AddObserver(vtkCommand::MiddleButtonReleaseEvent,
403 this->EventCallbackCommand,
406 if( this->HandleRightButtonEvent ) {
407 i->AddObserver(vtkCommand::RightButtonPressEvent,
408 this->EventCallbackCommand,
410 i->AddObserver(vtkCommand::RightButtonReleaseEvent,
411 this->EventCallbackCommand,
415 this->CurrentRenderer->AddActor(this->myOutlineActor);
416 this->myOutlineActor->SetProperty(this->OutlineProperty);
419 this->CurrentRenderer->AddActor(this->myEdgesActor1);
420 this->CurrentRenderer->AddActor(myEdgesActor2);
422 this->myOutlineActor->SetProperty(this->EdgesProperty);
424 // add the normal vector
425 this->CurrentRenderer->AddActor(this->LineActor);
426 this->LineActor->SetProperty(this->NormalProperty);
427 this->CurrentRenderer->AddActor(this->ConeActor);
428 this->ConeActor->SetProperty(this->NormalProperty);
430 this->CurrentRenderer->AddActor(this->LineActor2);
431 this->LineActor2->SetProperty(this->NormalProperty);
432 this->CurrentRenderer->AddActor(this->ConeActor2);
433 this->ConeActor2->SetProperty(this->NormalProperty);
435 // add the origin handle
436 this->CurrentRenderer->AddActor(this->SphereActor);
437 this->SphereActor->SetProperty(this->NormalProperty);
439 // add the plane (if desired)
440 if ( this->myDrawPlane ) {
441 this->CurrentRenderer->AddActor(this->myCutActor1);
442 this->CurrentRenderer->AddActor(this->myCutActor2);
444 this->myCutActor1->SetProperty(this->PlaneProperty);
445 myCutActor2->SetProperty(this->PlaneProperty);
447 this->UpdateRepresentation();
448 //this->SizeHandles();
449 this->InvokeEvent(vtkCommand::EnableEvent,NULL);
452 else {//disabling----------------------------------------------------------
453 vtkDebugMacro(<<"Disabling plane widget");
455 if ( ! this->Enabled ) {//already disabled, just return
459 if(vtkImplicitFunctionCollection* aFunction = this->myImplicitFunction->GetFunction()){
460 aFunction->RemoveAllItems();
461 this->myImplicitFunction->Modified(); // VTK bug
466 // don't listen for events any more
467 this->Interactor->RemoveObserver(this->EventCallbackCommand);
469 // turn off the various actors
470 this->CurrentRenderer->RemoveActor(this->myOutlineActor);
471 this->CurrentRenderer->RemoveActor(this->myEdgesActor1);
472 this->CurrentRenderer->RemoveActor(myEdgesActor2);
473 this->CurrentRenderer->RemoveActor(this->LineActor);
474 this->CurrentRenderer->RemoveActor(this->ConeActor);
475 this->CurrentRenderer->RemoveActor(this->LineActor2);
476 this->CurrentRenderer->RemoveActor(this->ConeActor2);
477 this->CurrentRenderer->RemoveActor(this->SphereActor);
478 this->CurrentRenderer->RemoveActor(this->myCutActor1);
479 this->CurrentRenderer->RemoveActor(myCutActor2);
481 this->InvokeEvent(vtkCommand::DisableEvent,NULL);
482 this->CurrentRenderer = NULL;
485 this->Interactor->Render();
487 //==================================================================
488 // function: ProcessEvents
490 //==================================================================
491 void VISU_PlanesWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
494 void* vtkNotUsed(calldata))
496 VISU_PlanesWidget* self =
497 reinterpret_cast<VISU_PlanesWidget *>( clientdata );
499 //okay, let's do the right thing
502 case vtkCommand::LeftButtonPressEvent:
503 self->OnLeftButtonDown();
505 case vtkCommand::LeftButtonReleaseEvent:
506 self->OnLeftButtonUp();
508 case vtkCommand::MiddleButtonPressEvent:
509 self->OnMiddleButtonDown();
511 case vtkCommand::MiddleButtonReleaseEvent:
512 self->OnMiddleButtonUp();
514 case vtkCommand::RightButtonPressEvent:
515 self->OnRightButtonDown();
517 case vtkCommand::RightButtonReleaseEvent:
518 self->OnRightButtonUp();
520 case vtkCommand::MouseMoveEvent:
527 //==================================================================
528 // function: HighlightNormal
530 //==================================================================
531 void VISU_PlanesWidget::HighlightNormal(int highlight)
534 this->LineActor->SetProperty(this->SelectedNormalProperty);
535 this->ConeActor->SetProperty(this->SelectedNormalProperty);
536 this->LineActor2->SetProperty(this->SelectedNormalProperty);
537 this->ConeActor2->SetProperty(this->SelectedNormalProperty);
538 this->SphereActor->SetProperty(this->SelectedNormalProperty);
542 this->LineActor->SetProperty(this->NormalProperty);
543 this->ConeActor->SetProperty(this->NormalProperty);
544 this->LineActor2->SetProperty(this->NormalProperty);
545 this->ConeActor2->SetProperty(this->NormalProperty);
546 this->SphereActor->SetProperty(this->NormalProperty);
549 //==================================================================
550 // function: HighlightPlane
552 //==================================================================
553 void VISU_PlanesWidget::HighlightPlane(int highlight)
556 this->myCutActor1->SetProperty(this->SelectedPlaneProperty);
557 myCutActor2->SetProperty(this->SelectedPlaneProperty);
560 this->myCutActor1->SetProperty(this->PlaneProperty);
561 myCutActor2->SetProperty(this->PlaneProperty);
564 //==================================================================
565 // function: HighlightOutline
567 //==================================================================
568 void VISU_PlanesWidget::HighlightOutline(int highlight)
571 this->myOutlineActor->SetProperty(this->SelectedOutlineProperty);
574 this->myOutlineActor->SetProperty(this->OutlineProperty);
577 //==================================================================
578 // function: OnLeftButtonDown
580 //==================================================================
581 void VISU_PlanesWidget::OnLeftButtonDown()
583 // We're only here if we are enabled
584 int X = this->Interactor->GetEventPosition()[0];
585 int Y = this->Interactor->GetEventPosition()[1];
587 // Okay, we can process this. See if we've picked anything.
588 // Make sure it's in the activated renderer
589 vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y);
590 if ( ren != this->CurrentRenderer ) {
591 this->State = VISU_PlanesWidget::Outside;
595 vtkAssemblyPath *path;
596 this->Picker->Pick(X,Y,0.0,this->CurrentRenderer);
597 path = this->Picker->GetPath();
599 if ( path == NULL ) {//not picking this widget
600 this->HighlightPlane(0);
601 this->HighlightNormal(0);
602 this->HighlightOutline(0);
603 this->State = VISU_PlanesWidget::Outside;
607 vtkProp *prop = path->GetFirstNode()->GetProp();
609 this->Picker->GetPickPosition(this->LastPickPosition);
611 if ( prop == this->ConeActor || prop == this->LineActor ||
612 prop == this->ConeActor2 || prop == this->LineActor2 ) {
613 this->HighlightPlane(1);
614 this->HighlightNormal(1);
615 this->State = VISU_PlanesWidget::Rotating;
617 else if ( prop == this->myCutActor1) {
618 this->HighlightPlane(1);
619 this->State = VISU_PlanesWidget::Pushing;
621 else if ( prop == this->SphereActor ) {
622 this->HighlightNormal(1);
623 this->State = VISU_PlanesWidget::MovingOrigin;
625 else if (prop == myCutActor2) {
626 this->HighlightPlane(1);
627 this->State = VISU_PlanesWidget::ChangeDistance;
630 if ( this->OutlineTranslation ) {
631 this->HighlightOutline(1);
632 this->State = VISU_PlanesWidget::MovingOutline;
636 this->EventCallbackCommand->SetAbortFlag(1);
637 this->StartInteraction();
638 this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
639 this->Interactor->Render();
641 //==================================================================
642 // function: OnLeftButtonUp
644 //==================================================================
645 void VISU_PlanesWidget::OnLeftButtonUp()
647 if ( this->State == VISU_PlanesWidget::Outside ) {
651 this->State = VISU_PlanesWidget::Start;
652 this->HighlightPlane(0);
653 this->HighlightOutline(0);
654 this->HighlightNormal(0);
655 //this->SizeHandles();
657 this->EventCallbackCommand->SetAbortFlag(1);
658 this->EndInteraction();
659 this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
660 this->Interactor->Render();
662 //==================================================================
663 // function: OnMiddleButtonDown
665 //==================================================================
666 void VISU_PlanesWidget::OnMiddleButtonDown()
668 int X = this->Interactor->GetEventPosition()[0];
669 int Y = this->Interactor->GetEventPosition()[1];
671 // Okay, we can process this. See if we've picked anything.
672 // Make sure it's in the activated renderer
673 vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y);
674 if ( ren != this->CurrentRenderer ) {
675 this->State = VISU_PlanesWidget::Outside;
679 // Okay, we can process this.
680 vtkAssemblyPath *path;
681 this->Picker->Pick(X,Y,0.0,this->CurrentRenderer);
682 path = this->Picker->GetPath();
684 if ( path == NULL ) {//nothing picked
685 this->State = VISU_PlanesWidget::Outside;
690 this->Picker->GetPickPosition(this->LastPickPosition);
691 this->State = VISU_PlanesWidget::MovingPlane;
692 this->HighlightNormal(1);
693 this->HighlightPlane(1);
695 this->EventCallbackCommand->SetAbortFlag(1);
696 this->StartInteraction();
697 this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
698 this->Interactor->Render();
700 //==================================================================
701 // function: OnMiddleButtonUp
703 //==================================================================
704 void VISU_PlanesWidget::OnMiddleButtonUp()
706 if ( this->State == VISU_PlanesWidget::Outside ) {
710 this->State = VISU_PlanesWidget::Start;
711 this->HighlightPlane(0);
712 this->HighlightOutline(0);
713 this->HighlightNormal(0);
714 //this->SizeHandles();
716 this->EventCallbackCommand->SetAbortFlag(1);
717 this->EndInteraction();
718 this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
719 this->Interactor->Render();
721 //==================================================================
722 // function: OnRightButtonDown
724 //==================================================================
725 void VISU_PlanesWidget::OnRightButtonDown()
727 this->State = VISU_PlanesWidget::Scaling;
729 int X = this->Interactor->GetEventPosition()[0];
730 int Y = this->Interactor->GetEventPosition()[1];
732 // Okay, we can process this. See if we've picked anything.
733 // Make sure it's in the activated renderer
734 vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y);
735 if ( ren != this->CurrentRenderer ) {
736 this->State = VISU_PlanesWidget::Outside;
740 // Okay, we can process this. Try to pick handles first;
741 // if no handles picked, then pick the bounding box.
742 vtkAssemblyPath *path;
743 this->Picker->Pick(X,Y,0.0,this->CurrentRenderer);
744 path = this->Picker->GetPath();
745 if ( path == NULL ){ //nothing picked
746 this->State = VISU_PlanesWidget::Outside;
751 this->Picker->GetPickPosition(this->LastPickPosition);
752 this->HighlightPlane(1);
753 this->HighlightOutline(1);
754 this->HighlightNormal(1);
756 this->EventCallbackCommand->SetAbortFlag(1);
757 this->StartInteraction();
758 this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
759 this->Interactor->Render();
761 //==================================================================
762 // function: OnRightButtonUp
764 //==================================================================
765 void VISU_PlanesWidget::OnRightButtonUp()
767 if ( this->State == VISU_PlanesWidget::Outside ) {
771 this->State = VISU_PlanesWidget::Start;
772 this->HighlightPlane(0);
773 this->HighlightOutline(0);
774 this->HighlightNormal(0);
775 //this->SizeHandles();
777 this->EventCallbackCommand->SetAbortFlag(1);
778 this->EndInteraction();
779 this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
780 this->Interactor->Render();
782 //==================================================================
783 // function: OnMouseMove
785 //==================================================================
786 void VISU_PlanesWidget::OnMouseMove()
788 //this->SizeHandles();
790 // See whether we're active
791 if ( this->State == VISU_PlanesWidget::Outside ||
792 this->State == VISU_PlanesWidget::Start ) {
796 int X = this->Interactor->GetEventPosition()[0];
797 int Y = this->Interactor->GetEventPosition()[1];
799 // Do different things depending on state
800 // Calculations everybody does
801 double focalPoint[4], pickPoint[4], prevPickPoint[4];
804 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
809 // Compute the two points defining the motion vector
810 this->ComputeWorldToDisplay(this->LastPickPosition[0], this->LastPickPosition[1],
811 this->LastPickPosition[2], focalPoint);
813 this->ComputeDisplayToWorld(double(this->Interactor->GetLastEventPosition()[0]),
814 double(this->Interactor->GetLastEventPosition()[1]),
816 this->ComputeDisplayToWorld(double(X), double(Y), z, pickPoint);
818 // Process the motion
819 if ( this->State == VISU_PlanesWidget::MovingPlane ) {
820 //this->TranslatePlane(prevPickPoint, pickPoint);
821 //printf(" TranslatePlane\n");
823 else if ( this->State == VISU_PlanesWidget::MovingOutline ) {
824 //this->TranslateOutline(prevPickPoint, pickPoint);
825 //printf(" TranslateOutline\n");
827 else if ( this->State == VISU_PlanesWidget::MovingOrigin ) {
828 this->TranslateOrigin(prevPickPoint, pickPoint);
829 //printf(" TranslateOrigin\n");
831 else if ( this->State == VISU_PlanesWidget::Pushing ) {
832 this->Push(prevPickPoint, pickPoint);
833 // printf(" Push\n");
835 else if ( this->State == VISU_PlanesWidget::Scaling ) {
836 //this->Scale(prevPickPoint, pickPoint, X, Y);
837 //printf(" Scale\n");
839 else if ( this->State == VISU_PlanesWidget::Rotating ) {
840 camera->GetViewPlaneNormal(vpn);
841 this->Rotate(X, Y, prevPickPoint, pickPoint, vpn);
842 //printf(" Rotate\n");
844 else if ( this->State == VISU_PlanesWidget::ChangeDistance ) {
845 this->PushDistance(prevPickPoint, pickPoint);
846 //printf(" PushDistance\n");
848 // Interact, if desired
849 this->EventCallbackCommand->SetAbortFlag(1);
850 this->InvokeEvent(vtkCommand::InteractionEvent,NULL);
852 this->Interactor->Render();
854 //==================================================================
857 //==================================================================
858 void VISU_PlanesWidget::Push(double *p1, double *p2)
860 //Get the motion vector
862 vtkFloatingPointType v[3];
865 v[i] = p2[i] - p1[i];
868 vtkFloatingPointType aOr1[3], aNr1[3], aNr2[3], aD, z1;
870 myPlane1->GetOrigin(aOr1);
871 myPlane1->GetNormal(aNr1);
872 myPlane2->GetNormal(aNr2);
874 aD=vtkMath::Dot(v, aNr2);
875 z1 = aOr1[2]+aD*aNr2[2];
876 if( z1 <= myBox->GetOrigin()[2] ){
880 aD=vtkMath::Dot(v, aNr1);
881 for (i=0; i < 3; ++i) {
882 aOr1[i]=aOr1[i]+aD*aNr1[i];
884 SetOriginInternal(aOr1);
885 this->UpdateRepresentation();
887 //==================================================================
888 // function: TranslateOrigin
890 //==================================================================
891 void VISU_PlanesWidget::TranslateOrigin(double *p1, double *p2)
893 //Get the motion vector
898 v[i] = p2[i] - p1[i];
901 //Add to the current point, project back down onto plane
902 vtkFloatingPointType *o = myPlane1->GetOrigin();
903 vtkFloatingPointType *n = myPlane1->GetNormal();
904 vtkFloatingPointType newOrigin[3];
907 newOrigin[i]=o[i] + v[i];
909 vtkPlane::ProjectPoint(newOrigin, o, n, newOrigin);
910 SetOriginInternal(newOrigin);
911 this->UpdateRepresentation();
913 //==================================================================
914 // function: SetOriginInternal
915 // purpose : Set the origin of the plane.(for Internal calls)
916 //==================================================================
917 void VISU_PlanesWidget::SetOriginInternal(vtkFloatingPointType x[3])
919 vtkFloatingPointType *bounds = this->myOutline->GetOutput()->GetBounds();
921 for (i=0; i<3; ++i) {
923 if ( x[i] < bounds[j] ) {
926 else if ( x[i] > bounds[j+1] ) {
932 vtkFloatingPointType aOr2[3], aNr2[3], aNr1[3];
935 myPlane1->GetNormal(aNr1);
936 myPlane2->GetNormal(aNr2);
937 for (i=0; i<3; ++i) {
938 aOr2[i]=x[i]+myDistance*aNr1[i];
941 pPx->SetOrigin(aOr2);
942 pPx->SetNormal(aNr2);
943 bFlag=IsValidPlane2Position(pPx, myBox);
945 myPlane1->SetOrigin(x);
946 myPlane2->SetOrigin(aOr2);
950 //==================================================================
953 //==================================================================
954 void VISU_PlanesWidget::Rotate(int X, int Y,
955 double *p1, double *p2,
958 double v[3]; //vector of motion
959 double axis[3]; //axis of rotation
960 double theta; //rotation angle
963 // mouse motion vector in world space
965 v[i] = p2[i] - p1[i];
968 vtkFloatingPointType *origin = myPlane1->GetOrigin();
969 vtkFloatingPointType *normal = myPlane1->GetNormal();
971 // Create axis of rotation and angle of rotation
972 vtkMath::Cross(vpn,v,axis);
973 if ( vtkMath::Normalize(axis) == 0.0 ) {
977 int *size = this->CurrentRenderer->GetSize();
978 double l2 = (X-this->Interactor->GetLastEventPosition()[0])*
979 (X-this->Interactor->GetLastEventPosition()[0]) +
980 (Y-this->Interactor->GetLastEventPosition()[1])*
981 (Y-this->Interactor->GetLastEventPosition()[1]);
982 theta = 360.0 * sqrt(l2/((double)size[0]*size[0]+size[1]*size[1]));
984 //Manipulate the transform to reflect the rotation
985 this->Transform->Identity();
986 this->Transform->Translate(origin[0],origin[1],origin[2]);
987 this->Transform->RotateWXYZ(theta,axis);
988 this->Transform->Translate(-origin[0],-origin[1],-origin[2]);
991 vtkFloatingPointType nNew[3], aN2[3], oNew[3];
992 this->Transform->TransformNormal(normal,nNew);
997 vtkMath::Normalize(nNew);
999 oNew[i] = origin[i] + myDistance*nNew[i];
1002 vtkPlane *pPx=vtkPlane::New();
1003 pPx->SetNormal(aN2);
1004 pPx->SetOrigin(oNew);
1006 bool bFlag=IsValidPlane2Position(pPx, myBox);
1008 myPlane1->SetNormal(nNew);
1009 this->myPlane2->SetNormal(aN2);
1010 this->myPlane2->SetOrigin(oNew);
1013 this->UpdateRepresentation();
1015 //==================================================================
1016 // function: PushDistance
1018 //==================================================================
1019 void VISU_PlanesWidget::PushDistance(double *p1, double *p2)
1022 vtkFloatingPointType v[3], *anOrigin1, *aN1, *anOrigin2, *aN2, aD;
1023 //Get the motion vector
1024 for (i=0; i<3; ++i){
1025 v[i] = p2[i] - p1[i];
1028 anOrigin1 = myPlane1->GetOrigin();
1029 aN1 = myPlane1->GetNormal();
1030 anOrigin2 = myPlane2->GetOrigin();
1031 aN2 = myPlane2->GetNormal();
1033 vtkMath::Normalize(aN1);
1035 vtkFloatingPointType origin[3];
1036 double distance = vtkMath::Dot( v, aN2 );
1037 for(i=0; i<3; ++i) {
1038 origin[i] = anOrigin2[i] + distance * aN2[i];
1040 vtkFloatingPointType d = DistanceToPlane(origin, aN1, anOrigin1);
1045 vtkFloatingPointType aOr2[3], aNr2[3];
1048 myPlane2->GetOrigin(aOr2);
1049 myPlane2->GetNormal(aNr2);
1050 pPx=vtkPlane::New();
1051 pPx->SetNormal(aNr2);
1052 aD=vtkMath::Dot(v, aNr2);
1053 for (i=0; i < 3; ++i) {
1054 aOr2[i]=aOr2[i]+aD*aNr2[i];
1056 pPx->SetOrigin(aOr2);
1057 bFlag=IsValidPlane2Position(pPx, myBox);
1059 myPlane2->SetOrigin(aOr2);
1060 myPlane2->Modified();
1061 aD=DistanceToPlane(aOr2, aN1, anOrigin1);
1066 this->UpdateRepresentation();
1069 //==================================================================
1070 // function: TranslatePlane
1071 // purpose : Loop through all points and translate them
1072 //==================================================================
1073 void VISU_PlanesWidget::TranslatePlane(double *p1, double *p2)
1075 //Get the motion vector
1077 v[0] = p2[0] - p1[0];
1078 v[1] = p2[1] - p1[1];
1079 v[2] = p2[2] - p1[2];
1081 //Translate the plane
1082 vtkFloatingPointType oNew[3];
1083 vtkFloatingPointType *origin = myPlane1->GetOrigin();
1084 oNew[0] = origin[0] + v[0];
1085 oNew[1] = origin[1] + v[1];
1086 oNew[2] = origin[2] + v[2];
1087 myPlane1->SetOrigin(oNew);
1089 origin = this->myPlane2->GetOrigin();
1090 oNew[0] = origin[0] + v[0];
1091 oNew[1] = origin[1] + v[1];
1092 oNew[2] = origin[2] + v[2];
1093 this->myPlane2->SetOrigin(oNew);
1095 this->UpdateRepresentation();
1097 //==================================================================
1098 // function: TranslateOutline
1099 // purpose :Loop through all points and translate them
1100 //==================================================================
1101 void VISU_PlanesWidget::TranslateOutline(double *p1, double *p2)
1103 //Get the motion vector
1105 v[0] = p2[0] - p1[0];
1106 v[1] = p2[1] - p1[1];
1107 v[2] = p2[2] - p1[2];
1109 //Translate the bounding box
1110 vtkFloatingPointType *origin = myBox->GetOrigin();
1111 vtkFloatingPointType oNew[3];
1112 oNew[0] = origin[0] + v[0];
1113 oNew[1] = origin[1] + v[1];
1114 oNew[2] = origin[2] + v[2];
1115 myBox->SetOrigin(oNew);
1117 //Translate the plane
1118 origin = myPlane1->GetOrigin();
1119 oNew[0] = origin[0] + v[0];
1120 oNew[1] = origin[1] + v[1];
1121 oNew[2] = origin[2] + v[2];
1122 myPlane1->SetOrigin(oNew);
1124 origin = this->myPlane2->GetOrigin();
1125 oNew[0] = origin[0] + v[0];
1126 oNew[1] = origin[1] + v[1];
1127 oNew[2] = origin[2] + v[2];
1128 this->myPlane2->SetOrigin(oNew);
1130 this->UpdateRepresentation();
1133 //==================================================================
1136 //==================================================================
1137 void VISU_PlanesWidget::Scale(double *p1, double *p2,
1138 int vtkNotUsed(X), int Y)
1140 //Get the motion vector
1142 v[0] = p2[0] - p1[0];
1143 v[1] = p2[1] - p1[1];
1144 v[2] = p2[2] - p1[2];
1146 //int res = this->PlaneSource->GetXResolution();
1147 vtkFloatingPointType *o = myPlane1->GetOrigin();
1149 // Compute the scale factor
1150 vtkFloatingPointType sf = vtkMath::Norm(v) / this->myOutline->GetOutput()->GetLength();
1151 if ( Y > this->Interactor->GetLastEventPosition()[1] ) {
1158 this->Transform->Identity();
1159 this->Transform->Translate(o[0],o[1],o[2]);
1160 this->Transform->Scale(sf,sf,sf);
1161 this->Transform->Translate(-o[0],-o[1],-o[2]);
1163 vtkFloatingPointType *origin = myBox->GetOrigin();
1164 vtkFloatingPointType *spacing = myBox->GetSpacing();
1165 vtkFloatingPointType oNew[3], p[3], pNew[3];
1166 p[0] = origin[0] + spacing[0];
1167 p[1] = origin[1] + spacing[1];
1168 p[2] = origin[2] + spacing[2];
1170 this->Transform->TransformPoint(origin,oNew);
1171 this->Transform->TransformPoint(p,pNew);
1173 myBox->SetOrigin(oNew);
1174 myBox->SetSpacing( (pNew[0]-oNew[0]), (pNew[1]-oNew[1]), (pNew[2]-oNew[2]) );
1176 this->UpdateRepresentation();
1181 //==================================================================
1182 // function: CreateDefaultProperties
1184 //==================================================================
1185 void VISU_PlanesWidget::CreateDefaultProperties()
1187 // Normal properties
1188 this->NormalProperty = vtkProperty::New();
1189 this->NormalProperty->SetColor(1,1,1);
1190 this->NormalProperty->SetLineWidth(2);
1192 this->SelectedNormalProperty = vtkProperty::New();
1193 this->SelectedNormalProperty->SetColor(1,0,0);
1194 this->NormalProperty->SetLineWidth(2);
1197 this->PlaneProperty = vtkProperty::New();
1198 this->PlaneProperty->SetAmbient(1.0);
1199 this->PlaneProperty->SetAmbientColor(1.0,1.0,1.0);
1201 this->SelectedPlaneProperty = vtkProperty::New();
1202 this->SelectedPlaneProperty->SetAmbient(1.0);
1203 this->SelectedPlaneProperty->SetAmbientColor(0.0,1.0,0.0);
1204 this->SelectedPlaneProperty->SetOpacity(0.25);
1206 // Outline properties
1207 this->OutlineProperty = vtkProperty::New();
1208 this->OutlineProperty->SetAmbient(1.0);
1209 this->OutlineProperty->SetAmbientColor(1.0,1.0,1.0);
1211 this->SelectedOutlineProperty = vtkProperty::New();
1212 this->SelectedOutlineProperty->SetAmbient(1.0);
1213 this->SelectedOutlineProperty->SetAmbientColor(0.0,1.0,0.0);
1216 this->EdgesProperty = vtkProperty::New();
1217 this->EdgesProperty->SetAmbient(1.0);
1218 this->EdgesProperty->SetAmbientColor(1.0,1.0,1.0);
1220 //==================================================================
1221 // function: InitialPlaceWidget
1223 //==================================================================
1224 void VISU_PlanesWidget::InitialPlaceWidget(vtkFloatingPointType bds[6])
1226 vtkFloatingPointType bounds[6], origin[3];
1230 this->AdjustBounds(bds, bounds, origin);
1231 this->SetOrigin((bounds[1]+bounds[0])/2.0,
1232 (bounds[3]+bounds[2])/2.0,
1233 (bounds[5]+bounds[4])/2.0);
1235 static vtkFloatingPointType DIST_COEFF = 0.1;
1236 SetDistance(this->InitialLength*DIST_COEFF);
1238 this->UpdateRepresentation();
1240 //==================================================================
1241 // function: PlaceWidget
1243 //==================================================================
1244 void VISU_PlanesWidget::PlaceWidget(vtkFloatingPointType bds[6])
1247 vtkFloatingPointType bounds[6], origin[3];
1249 this->AdjustBounds(bds, bounds, origin);
1251 // Set up the bounding box
1252 myBox->SetOrigin(bounds[0],bounds[2],bounds[4]);
1253 myBox->SetSpacing((bounds[1]-bounds[0]),(bounds[3]-bounds[2]),
1254 (bounds[5]-bounds[4]));
1255 this->myOutline->Update();
1257 if (this->Input || this->Prop3D) {
1258 this->LineSource->SetPoint1(myPlane1->GetOrigin());
1259 if ( this->NormalToYAxis ) {
1260 myPlane1->SetNormal(0,1,0);
1261 myPlane2->SetNormal(0,-1,0);
1262 this->LineSource->SetPoint2(0,1,0);
1264 else if ( this->NormalToZAxis ) {
1265 myPlane1->SetNormal(0,0,1);
1266 myPlane2->SetNormal(0,0,-1);
1267 this->LineSource->SetPoint2(0,0,1);
1269 else{ //default or x-normal
1270 myPlane1->SetNormal(1,0,0);
1271 myPlane2->SetNormal(-1,0,0);
1272 this->LineSource->SetPoint2(1,0,0);
1276 for (i=0; i<6; i++) {
1277 this->InitialBounds[i] = bounds[i];
1280 this->InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
1281 (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
1282 (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
1284 this->UpdateRepresentation();
1286 //==================================================================
1287 // function: SetOrigin
1288 // purpose :Set the origin of the plane.(for external calls)
1289 //==================================================================
1290 void VISU_PlanesWidget::SetOrigin(vtkFloatingPointType x, vtkFloatingPointType y, vtkFloatingPointType z)
1292 vtkFloatingPointType origin[3];
1296 this->SetOrigin(origin);
1298 //==================================================================
1299 // function: SetOrigin
1300 // purpose : Set the origin of the plane.(for external calls)
1301 //==================================================================
1302 void VISU_PlanesWidget::SetOrigin(vtkFloatingPointType x[3])
1304 vtkFloatingPointType *bounds = this->myOutline->GetOutput()->GetBounds();
1305 for (int i=0; i<3; i++) {
1306 if ( x[i] < bounds[2*i] ) {
1309 else if ( x[i] > bounds[2*i+1] ) {
1310 x[i] = bounds[2*i+1];
1313 myPlane1->SetOrigin(x);
1314 vtkFloatingPointType *origin, *normal, oNew[3];
1315 origin = myPlane1->GetOrigin();
1316 normal = myPlane1->GetNormal();
1317 vtkMath::Normalize(normal);
1318 oNew[0] = origin[0] + myDistance*normal[0];
1319 oNew[1] = origin[1] + myDistance*normal[1];
1320 oNew[2] = origin[2] + myDistance*normal[2];
1321 this->myPlane2->SetOrigin(oNew);
1322 this->UpdateRepresentation();
1324 //==================================================================
1325 // function: GetOrigin
1326 // purpose :Get the origin of the plane.
1327 //==================================================================
1328 vtkFloatingPointType* VISU_PlanesWidget::GetOrigin()
1330 return myPlane1->GetOrigin();
1333 void VISU_PlanesWidget::GetOrigin(vtkFloatingPointType xyz[3])
1335 myPlane1->GetOrigin(xyz);
1337 //==================================================================
1338 // function: SetNormal
1339 // purpose :Set the normal to the plane.
1340 //==================================================================
1341 void VISU_PlanesWidget::SetNormal(vtkFloatingPointType x, vtkFloatingPointType y, vtkFloatingPointType z)
1343 vtkFloatingPointType n[3];
1347 vtkMath::Normalize(n);
1348 myPlane1->SetNormal(n);
1352 this->myPlane2->SetNormal(n);
1354 this->UpdateRepresentation();
1357 //==================================================================
1358 // function: SetNormal
1359 // purpose :Set the normal to the plane.
1360 //==================================================================
1361 void VISU_PlanesWidget::SetNormal(vtkFloatingPointType n[3])
1363 this->SetNormal(n[0], n[1], n[2]);
1365 //==================================================================
1366 // function: GetNormal
1367 // purpose :Get the normal to the plane.
1368 //==================================================================
1369 vtkFloatingPointType* VISU_PlanesWidget::GetNormal()
1371 return myPlane1->GetNormal();
1373 //==================================================================
1374 // function: GetNormal
1375 // purpose :Get the normal to the plane.
1376 //==================================================================
1377 void VISU_PlanesWidget::GetNormal(vtkFloatingPointType xyz[3])
1379 myPlane1->GetNormal(xyz);
1381 //==================================================================
1382 // function: SetDrawPlane
1384 //==================================================================
1385 void VISU_PlanesWidget::SetDrawPlane(int drawPlane)
1387 if ( drawPlane == this->myDrawPlane ) {
1392 this->myDrawPlane = drawPlane;
1393 if ( this->Enabled ) {
1395 this->CurrentRenderer->AddActor(this->myCutActor1);
1396 this->CurrentRenderer->AddActor(myCutActor2);
1399 this->CurrentRenderer->RemoveActor(this->myCutActor1);
1400 this->CurrentRenderer->RemoveActor(myCutActor2);
1402 this->Interactor->Render();
1405 //==================================================================
1406 // function: SetNormalToXAxis
1408 //==================================================================
1409 void VISU_PlanesWidget::SetNormalToXAxis (int var)
1411 if (this->NormalToXAxis != var) {
1412 this->NormalToXAxis = var;
1416 this->NormalToYAxisOff();
1417 this->NormalToZAxisOff();
1420 //==================================================================
1421 // function: SetNormalToYAxis
1423 //==================================================================
1424 void VISU_PlanesWidget::SetNormalToYAxis (int var)
1426 if (this->NormalToYAxis != var) {
1427 this->NormalToYAxis = var;
1431 this->NormalToXAxisOff();
1432 this->NormalToZAxisOff();
1435 //==================================================================
1436 // function: SetNormalToZAxis
1438 //==================================================================
1439 void VISU_PlanesWidget::SetNormalToZAxis (int var)
1441 if (this->NormalToZAxis != var) {
1442 this->NormalToZAxis = var;
1446 this->NormalToXAxisOff();
1447 this->NormalToYAxisOff();
1450 //==================================================================
1451 // function: GetPolyData
1453 //==================================================================
1454 void VISU_PlanesWidget::GetPolyData(vtkPolyData *pd)
1456 pd->ShallowCopy(this->myCutter1->GetOutput());
1458 //==================================================================
1459 // function: GetPolyDataSource
1461 //==================================================================
1463 vtkPolyDataSource *VISU_PlanesWidget::GetPolyDataSource()
1465 return this->myCutter1;
1468 //==================================================================
1469 // function:GetPlane
1471 //==================================================================
1472 void VISU_PlanesWidget::GetPlane(vtkPlane *plane)
1474 if ( plane == NULL ) {
1478 plane->SetNormal(myPlane1->GetNormal());
1479 plane->SetOrigin(myPlane1->GetOrigin());
1481 //==================================================================
1482 // function:UpdatePlacement
1484 //==================================================================
1485 void VISU_PlanesWidget::UpdatePlacement(void)
1487 this->myOutline->Update();
1488 this->myCutter1->Update();
1489 this->myEdges1->Update();
1491 //==================================================================
1492 // function:UpdateRepresentation
1494 //==================================================================
1495 void VISU_PlanesWidget::UpdateRepresentation()
1497 if ( ! this->CurrentRenderer ) {
1501 vtkFloatingPointType *origin = myPlane1->GetOrigin();
1502 vtkFloatingPointType *normal = myPlane1->GetNormal();
1503 vtkFloatingPointType p2[3];
1505 // Setup the plane normal
1506 vtkFloatingPointType d = this->myOutline->GetOutput()->GetLength();
1508 p2[0] = origin[0] + 0.30 * d * normal[0];
1509 p2[1] = origin[1] + 0.30 * d * normal[1];
1510 p2[2] = origin[2] + 0.30 * d * normal[2];
1512 this->LineSource->SetPoint1(origin);
1513 this->LineSource->SetPoint2(p2);
1514 this->ConeSource->SetCenter(p2);
1515 this->ConeSource->SetDirection(normal);
1516 ConeActor->SetCenter(p2);
1518 p2[0] = origin[0] - 0.30 * d * normal[0];
1519 p2[1] = origin[1] - 0.30 * d * normal[1];
1520 p2[2] = origin[2] - 0.30 * d * normal[2];
1522 this->LineSource2->SetPoint1(origin);
1523 this->LineSource2->SetPoint2(p2);
1524 this->ConeSource2->SetCenter(p2);
1525 this->ConeSource2->SetDirection(normal);
1526 ConeActor2->SetCenter(p2);
1528 // Set up the position handle
1529 this->Sphere->SetCenter(origin);
1530 SphereActor->SetCenter(origin);
1532 this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput());
1535 //==================================================================
1536 // function:PrintSelf
1538 //==================================================================
1539 void VISU_PlanesWidget::PrintSelf(ostream& os, vtkIndent indent)
1541 this->Superclass::PrintSelf(os,indent);
1543 //==================================================================
1544 // function: IsValidPlane2Position
1546 //==================================================================
1547 bool IsValidPlane2Position(vtkPlane *pPx,
1548 vtkDataSet *pDataSet,
1549 vtkFloatingPointType aTol)
1553 vtkFloatingPointType aD, aDmax, aPnts[24], aDiagonal;
1554 vtkFloatingPointType aTol1, aOr[3], aN[3];
1557 aDiagonal=pDataSet->GetLength();
1558 aTol1=aDiagonal*aTol;
1560 GetBndPoints(pDataSet, aPnts);
1562 pPx->GetOrigin(aOr);
1564 vtkMath::Normalize(aN);
1568 for (i=0; i<24; i+=3){
1569 aD=-DistanceToPlane(aPnts+i, aN, aOr);
1575 if (iFound && aDmax>aTol1) {
1580 //==================================================================
1581 // function: GetBndPoints
1583 //==================================================================
1585 GetBndPoints(vtkDataSet *pDataSet,
1586 vtkFloatingPointType aPnts[24])
1589 0,2,4,1,2,4,1,3,4,0,3,4,
1590 0,2,5,1,2,5,1,3,5,0,3,5
1593 vtkFloatingPointType *pBounds=pDataSet->GetBounds();
1595 for (i=0; i<24; ++i){
1596 aPnts[i]=pBounds[aIndx[i]];
1599 //==================================================================
1600 // function: DistanceToPlane
1602 //==================================================================
1603 vtkFloatingPointType
1604 DistanceToPlane(const vtkFloatingPointType x[3],
1605 const vtkFloatingPointType n[3],
1606 const vtkFloatingPointType p0[3])
1608 return ((n[0]*(x[0]-p0[0]) +
1610 n[2]*(x[2]-p0[2])));
1613 //==================================================================
1614 // function:SizeHandles
1616 //==================================================================
1617 void VISU_PlanesWidget::SizeHandles()
1619 // vtkFloatingPointType radius =
1620 this->vtk3DWidget::SizeHandles(1.35);