1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VVTK_ImplicitFunctionWidget.cxx
25 // Author : Peter KURNEV
29 #include "VISU_PlanesWidget.hxx"
30 #include "VISU_ImplicitFunctionWidget.hxx"
33 #include <vtkAssemblyNode.h>
34 #include <vtkAssemblyPath.h>
35 #include <vtkCallbackCommand.h>
36 #include <vtkCamera.h>
37 #include <vtkCellPicker.h>
38 #include <vtkConeSource.h>
39 #include <vtkCutter.h>
40 #include <vtkFeatureEdges.h>
41 #include <vtkImageData.h>
42 #include <vtkLineSource.h>
44 #include <vtkObjectFactory.h>
45 #include <vtkOutlineFilter.h>
47 #include <vtkPolyData.h>
48 #include <vtkPolyDataMapper.h>
49 #include <vtkProperty.h>
50 #include <vtkRenderWindowInteractor.h>
51 #include <vtkRenderer.h>
52 #include <vtkSphereSource.h>
53 #include <vtkTransform.h>
54 #include <vtkTubeFilter.h>
55 #include <vtkImplicitBoolean.h>
56 #include <vtkImplicitFunctionCollection.h>
58 #include <vtkFollower.h>
59 #include <vtkObjectFactory.h>
60 #include <vtkDataSet.h>
61 #include <vtkRenderWindow.h>
64 bool IsValidPlane2Position(vtkPlane *pPx,
68 void GetBndPoints(vtkDataSet *pDataSet,
71 float DistanceToPlane(const float x[3],
75 vtkCxxRevisionMacro(VISU_PlanesWidget, "$Revision$");
76 vtkStandardNewMacro(VISU_PlanesWidget);
78 //==================================================================
79 // function: VISU_PlanesWidget
81 //==================================================================
82 VISU_PlanesWidget::VISU_PlanesWidget()
84 VISU_ImplicitFunctionWidget()
86 State = VISU_PlanesWidget::Start;
87 EventCallbackCommand->SetCallback(VISU_PlanesWidget::ProcessEvents);
93 HandleMoveEvent = true;
94 HandleLeftButtonEvent = true;
95 HandleMiddleButtonEvent = false;
96 HandleRightButtonEvent = false;
98 // Build the representation of the widget
100 myPlane1 = vtkPlane::New();
101 myPlane1->SetNormal(0,0,1);
102 myPlane1->SetOrigin(0,0,0);
105 myPlane2 = vtkPlane::New();
106 myPlane2->SetNormal(0.,0.,-1.);
107 myPlane2->SetOrigin(0,0,myDistance);
109 myImplicitFunction = vtkImplicitBoolean::New();
110 myImplicitFunction->SetOperationType(VTK_UNION);
112 myBox = vtkImageData::New();
113 myBox->SetDimensions(2,2,2);
114 myOutline = vtkOutlineFilter::New();
115 myOutline->SetInput(myBox);
116 myOutlineMapper = vtkPolyDataMapper::New();
117 myOutlineMapper->SetInput(myOutline->GetOutput());
118 myOutlineActor = vtkActor::New();
119 this->myOutlineActor->SetMapper(this->myOutlineMapper);
120 this->myOutlineActor->PickableOff();
121 this->OutlineTranslation = 0;
123 this->myCutter1 = vtkCutter::New();
124 this->myCutter1->SetInput(myBox);
125 this->myCutter1->SetCutFunction(myPlane1);
126 this->myCutMapper1 = vtkPolyDataMapper::New();
127 this->myCutMapper1->SetInput(this->myCutter1->GetOutput());
128 this->myCutActor1 = vtkActor::New();
129 this->myCutActor1->SetMapper(this->myCutMapper1);
130 this->myDrawPlane = 1;
132 this->myEdges1 = vtkFeatureEdges::New();
133 myEdges1->SetColoring(0);
134 this->myEdges1->SetInput(this->myCutter1->GetOutput());
135 this->myEdgesMapper1 = vtkPolyDataMapper::New();
136 this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput());
137 this->myEdgesActor1 = vtkActor::New();
138 this->myEdgesActor1->SetMapper(this->myEdgesMapper1);
139 myEdgesActor1->GetProperty()->SetLineWidth(4.);
140 myEdgesActor1->GetProperty()->SetColor(0., .5, .7);
142 this->myCutter2 = vtkCutter::New();
143 this->myCutter2->SetInput(myBox);
144 this->myCutter2->SetCutFunction(this->myPlane2);
145 this->myCutMapper2 = vtkPolyDataMapper::New();
146 this->myCutMapper2->SetInput(this->myCutter2->GetOutput());
147 this->myCutActor2 = vtkActor::New();
148 this->myCutActor2->SetMapper(this->myCutMapper2);
150 myEdges2 = vtkFeatureEdges::New();
151 myEdges2->SetColoring(0);
152 myEdges2->SetInput(myCutter2->GetOutput());
153 myEdgesMapper2 = vtkPolyDataMapper::New();
154 myEdgesMapper2->SetInput(myEdges2->GetOutput());
155 myEdgesActor2 = vtkActor::New();
156 myEdgesActor2->SetMapper(myEdgesMapper2);
157 myEdgesActor2->GetProperty()->SetLineWidth(4.);
158 myEdgesActor2->GetProperty()->SetColor(.7, .0, .0);
160 // Create the + plane normal
161 this->LineSource = vtkLineSource::New();
162 this->LineSource->SetResolution(1);
163 this->LineMapper = vtkPolyDataMapper::New();
164 this->LineMapper->SetInput(this->LineSource->GetOutput());
165 this->LineActor = vtkActor::New();
166 this->LineActor->SetMapper(this->LineMapper);
168 this->ConeSource = vtkConeSource::New();
169 this->ConeSource->SetResolution(12);
170 this->ConeSource->SetAngle(20.);
171 this->ConeMapper = vtkPolyDataMapper::New();
172 this->ConeMapper->SetInput(this->ConeSource->GetOutput());
173 this->ConeActor = VISU_UnScaledActor::New();
174 this->ConeActor->SetMapper(this->ConeMapper);
175 ConeActor->SetSize(36);
176 ConeActor->SetCenter(ConeSource->GetCenter());
178 // Create the - plane normal
179 this->LineSource2 = vtkLineSource::New();
180 this->LineSource2->SetResolution(1);
181 this->LineMapper2 = vtkPolyDataMapper::New();
182 this->LineMapper2->SetInput(this->LineSource2->GetOutput());
183 this->LineActor2 = vtkActor::New();
184 this->LineActor2->SetMapper(this->LineMapper2);
186 this->ConeSource2 = vtkConeSource::New();
187 this->ConeSource2->SetResolution(12);
188 this->ConeSource2->SetAngle(20.);
189 this->ConeMapper2 = vtkPolyDataMapper::New();
190 this->ConeMapper2->SetInput(this->ConeSource2->GetOutput());
191 this->ConeActor2 = VISU_UnScaledActor::New();
192 this->ConeActor2->SetMapper(this->ConeMapper2);
193 ConeActor2->SetSize(36);
194 ConeActor2->SetCenter(ConeSource2->GetCenter());
196 // Create the origin handle
197 this->Sphere = vtkSphereSource::New();
198 this->Sphere->SetThetaResolution(16);
199 this->Sphere->SetPhiResolution(8);
200 this->SphereMapper = vtkPolyDataMapper::New();
201 this->SphereMapper->SetInput(this->Sphere->GetOutput());
202 this->SphereActor = VISU_UnScaledActor::New();
203 this->SphereActor->SetMapper(this->SphereMapper);
204 SphereActor->SetSize(36);
205 SphereActor->SetCenter(Sphere->GetCenter());
207 this->Transform = vtkTransform::New();
209 // Define the point coordinates
218 // Initial creation of the widget, serves to initialize it
219 this->PlaceWidget(bounds);
221 //Manage the picking stuff
222 this->Picker = vtkCellPicker::New();
223 this->Picker->SetTolerance(0.005);
224 this->Picker->AddPickList(this->myCutActor1);
225 this->Picker->AddPickList(this->myCutActor2);
226 this->Picker->AddPickList(this->LineActor);
227 this->Picker->AddPickList(this->ConeActor);
228 this->Picker->AddPickList(this->LineActor2);
229 this->Picker->AddPickList(this->ConeActor2);
230 this->Picker->AddPickList(this->SphereActor);
231 this->Picker->AddPickList(this->myOutlineActor);
232 this->Picker->PickFromListOn();
234 // Set up the initial properties
235 this->CreateDefaultProperties();
238 //==================================================================
241 //==================================================================
242 VISU_PlanesWidget::~VISU_PlanesWidget()
246 this->myPlane2->Delete();
247 this->myImplicitFunction->Delete();
250 this->myOutline->Delete();
251 this->myOutlineMapper->Delete();
252 this->myOutlineActor->Delete();
254 this->myCutter1->Delete();
255 this->myCutMapper1->Delete();
256 this->myCutActor1->Delete();
258 this->myEdges1->Delete();
259 this->myEdgesMapper1->Delete();
260 this->myEdgesActor1->Delete();
263 myCutMapper2->Delete();
264 myCutActor2->Delete();
267 myEdgesMapper2->Delete();
268 myEdgesActor2->Delete();
270 this->LineSource->Delete();
271 this->LineMapper->Delete();
272 this->LineActor->Delete();
274 this->ConeSource->Delete();
275 this->ConeMapper->Delete();
276 this->ConeActor->Delete();
278 this->LineSource2->Delete();
279 this->LineMapper2->Delete();
280 this->LineActor2->Delete();
282 this->ConeSource2->Delete();
283 this->ConeMapper2->Delete();
284 this->ConeActor2->Delete();
286 this->Sphere->Delete();
287 this->SphereMapper->Delete();
288 this->SphereActor->Delete();
290 this->Transform->Delete();
292 this->Picker->Delete();
294 this->NormalProperty->Delete();
295 this->SelectedNormalProperty->Delete();
296 this->PlaneProperty->Delete();
297 this->SelectedPlaneProperty->Delete();
298 this->OutlineProperty->Delete();
299 this->SelectedOutlineProperty->Delete();
300 this->EdgesProperty->Delete();
302 //==================================================================
303 // function: ImplicitFunction
305 //==================================================================
306 vtkImplicitFunction* VISU_PlanesWidget::ImplicitFunction()
308 return this->myImplicitFunction;
310 //==================================================================
311 // function: SetDistance
313 //==================================================================
314 void VISU_PlanesWidget::SetDistance(const float theDistance)
316 if( theDistance <= 0.0 || theDistance == myDistance )
319 myDistance=theDistance;
321 float *origin, *normal, oNew[3], aN2[3];
322 origin = myPlane1->GetOrigin();
323 normal = myPlane1->GetNormal();
324 vtkMath::Normalize(normal);
325 oNew[0] = origin[0] + myDistance*normal[0];
326 oNew[1] = origin[1] + myDistance*normal[1];
327 oNew[2] = origin[2] + myDistance*normal[2];
328 myPlane2->SetOrigin(oNew);
332 myPlane2->SetNormal(aN2);
334 //==================================================================
335 // function: Distance
337 //==================================================================
338 float VISU_PlanesWidget::Distance()const
342 //==================================================================
343 // function: SetEnabled
345 //==================================================================
346 void VISU_PlanesWidget::SetEnabled(int enabling)
348 if ( ! this->Interactor ) {
349 vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget");
353 if ( enabling ) {//------------------------------------------------------------
354 vtkDebugMacro(<<"Enabling plane widget");
356 if ( this->Enabled ){ //already enabled, just return
360 if ( ! this->CurrentRenderer ){
361 this->CurrentRenderer = this->Interactor->FindPokedRenderer(
362 this->Interactor->GetLastEventPosition()[0],
363 this->Interactor->GetLastEventPosition()[1]);
364 if (this->CurrentRenderer == NULL) {
369 vtkCamera *pCamera=CurrentRenderer->GetActiveCamera();
370 pCamera->SetParallelProjection(1);
372 this->myImplicitFunction->AddFunction(myPlane1);
373 this->myImplicitFunction->AddFunction(this->myPlane2);
377 // listen for the following events
378 vtkRenderWindowInteractor *i = this->Interactor;
379 if( this->HandleMoveEvent ) {
380 i->AddObserver(vtkCommand::MouseMoveEvent,
381 this->EventCallbackCommand,
384 if( this->HandleLeftButtonEvent ) {
385 i->AddObserver(vtkCommand::LeftButtonPressEvent,
386 this->EventCallbackCommand,
388 i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
389 this->EventCallbackCommand,
392 if( this->HandleMiddleButtonEvent ) {
393 i->AddObserver(vtkCommand::MiddleButtonPressEvent,
394 this->EventCallbackCommand,
396 i->AddObserver(vtkCommand::MiddleButtonReleaseEvent,
397 this->EventCallbackCommand,
400 if( this->HandleRightButtonEvent ) {
401 i->AddObserver(vtkCommand::RightButtonPressEvent,
402 this->EventCallbackCommand,
404 i->AddObserver(vtkCommand::RightButtonReleaseEvent,
405 this->EventCallbackCommand,
409 this->CurrentRenderer->AddActor(this->myOutlineActor);
410 this->myOutlineActor->SetProperty(this->OutlineProperty);
413 this->CurrentRenderer->AddActor(this->myEdgesActor1);
414 this->CurrentRenderer->AddActor(myEdgesActor2);
416 this->myOutlineActor->SetProperty(this->EdgesProperty);
418 // add the normal vector
419 this->CurrentRenderer->AddActor(this->LineActor);
420 this->LineActor->SetProperty(this->NormalProperty);
421 this->CurrentRenderer->AddActor(this->ConeActor);
422 this->ConeActor->SetProperty(this->NormalProperty);
424 this->CurrentRenderer->AddActor(this->LineActor2);
425 this->LineActor2->SetProperty(this->NormalProperty);
426 this->CurrentRenderer->AddActor(this->ConeActor2);
427 this->ConeActor2->SetProperty(this->NormalProperty);
429 // add the origin handle
430 this->CurrentRenderer->AddActor(this->SphereActor);
431 this->SphereActor->SetProperty(this->NormalProperty);
433 // add the plane (if desired)
434 if ( this->myDrawPlane ) {
435 this->CurrentRenderer->AddActor(this->myCutActor1);
436 this->CurrentRenderer->AddActor(this->myCutActor2);
438 this->myCutActor1->SetProperty(this->PlaneProperty);
439 myCutActor2->SetProperty(this->PlaneProperty);
441 this->UpdateRepresentation();
442 //this->SizeHandles();
443 this->InvokeEvent(vtkCommand::EnableEvent,NULL);
446 else {//disabling----------------------------------------------------------
447 vtkDebugMacro(<<"Disabling plane widget");
449 if ( ! this->Enabled ) {//already disabled, just return
453 if(vtkImplicitFunctionCollection* aFunction = this->myImplicitFunction->GetFunction()){
454 aFunction->RemoveAllItems();
455 this->myImplicitFunction->Modified(); // VTK bug
460 // don't listen for events any more
461 this->Interactor->RemoveObserver(this->EventCallbackCommand);
463 // turn off the various actors
464 this->CurrentRenderer->RemoveActor(this->myOutlineActor);
465 this->CurrentRenderer->RemoveActor(this->myEdgesActor1);
466 this->CurrentRenderer->RemoveActor(myEdgesActor2);
467 this->CurrentRenderer->RemoveActor(this->LineActor);
468 this->CurrentRenderer->RemoveActor(this->ConeActor);
469 this->CurrentRenderer->RemoveActor(this->LineActor2);
470 this->CurrentRenderer->RemoveActor(this->ConeActor2);
471 this->CurrentRenderer->RemoveActor(this->SphereActor);
472 this->CurrentRenderer->RemoveActor(this->myCutActor1);
473 this->CurrentRenderer->RemoveActor(myCutActor2);
475 this->InvokeEvent(vtkCommand::DisableEvent,NULL);
476 this->CurrentRenderer = NULL;
479 this->Interactor->Render();
481 //==================================================================
482 // function: ProcessEvents
484 //==================================================================
485 void VISU_PlanesWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
488 void* vtkNotUsed(calldata))
490 VISU_PlanesWidget* self =
491 reinterpret_cast<VISU_PlanesWidget *>( clientdata );
493 //okay, let's do the right thing
496 case vtkCommand::LeftButtonPressEvent:
497 self->OnLeftButtonDown();
499 case vtkCommand::LeftButtonReleaseEvent:
500 self->OnLeftButtonUp();
502 case vtkCommand::MiddleButtonPressEvent:
503 self->OnMiddleButtonDown();
505 case vtkCommand::MiddleButtonReleaseEvent:
506 self->OnMiddleButtonUp();
508 case vtkCommand::RightButtonPressEvent:
509 self->OnRightButtonDown();
511 case vtkCommand::RightButtonReleaseEvent:
512 self->OnRightButtonUp();
514 case vtkCommand::MouseMoveEvent:
521 //==================================================================
522 // function: HighlightNormal
524 //==================================================================
525 void VISU_PlanesWidget::HighlightNormal(int highlight)
528 this->LineActor->SetProperty(this->SelectedNormalProperty);
529 this->ConeActor->SetProperty(this->SelectedNormalProperty);
530 this->LineActor2->SetProperty(this->SelectedNormalProperty);
531 this->ConeActor2->SetProperty(this->SelectedNormalProperty);
532 this->SphereActor->SetProperty(this->SelectedNormalProperty);
536 this->LineActor->SetProperty(this->NormalProperty);
537 this->ConeActor->SetProperty(this->NormalProperty);
538 this->LineActor2->SetProperty(this->NormalProperty);
539 this->ConeActor2->SetProperty(this->NormalProperty);
540 this->SphereActor->SetProperty(this->NormalProperty);
543 //==================================================================
544 // function: HighlightPlane
546 //==================================================================
547 void VISU_PlanesWidget::HighlightPlane(int highlight)
550 this->myCutActor1->SetProperty(this->SelectedPlaneProperty);
551 myCutActor2->SetProperty(this->SelectedPlaneProperty);
554 this->myCutActor1->SetProperty(this->PlaneProperty);
555 myCutActor2->SetProperty(this->PlaneProperty);
558 //==================================================================
559 // function: HighlightOutline
561 //==================================================================
562 void VISU_PlanesWidget::HighlightOutline(int highlight)
565 this->myOutlineActor->SetProperty(this->SelectedOutlineProperty);
568 this->myOutlineActor->SetProperty(this->OutlineProperty);
571 //==================================================================
572 // function: OnLeftButtonDown
574 //==================================================================
575 void VISU_PlanesWidget::OnLeftButtonDown()
577 // We're only here if we are enabled
578 int X = this->Interactor->GetEventPosition()[0];
579 int Y = this->Interactor->GetEventPosition()[1];
581 // Okay, we can process this. See if we've picked anything.
582 // Make sure it's in the activated renderer
583 vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y);
584 if ( ren != this->CurrentRenderer ) {
585 this->State = VISU_PlanesWidget::Outside;
589 vtkAssemblyPath *path;
590 this->Picker->Pick(X,Y,0.0,this->CurrentRenderer);
591 path = this->Picker->GetPath();
593 if ( path == NULL ) {//not picking this widget
594 this->HighlightPlane(0);
595 this->HighlightNormal(0);
596 this->HighlightOutline(0);
597 this->State = VISU_PlanesWidget::Outside;
601 vtkProp *prop = path->GetFirstNode()->GetProp();
603 this->Picker->GetPickPosition(this->LastPickPosition);
605 if ( prop == this->ConeActor || prop == this->LineActor ||
606 prop == this->ConeActor2 || prop == this->LineActor2 ) {
607 this->HighlightPlane(1);
608 this->HighlightNormal(1);
609 this->State = VISU_PlanesWidget::Rotating;
611 else if ( prop == this->myCutActor1) {
612 this->HighlightPlane(1);
613 this->State = VISU_PlanesWidget::Pushing;
615 else if ( prop == this->SphereActor ) {
616 this->HighlightNormal(1);
617 this->State = VISU_PlanesWidget::MovingOrigin;
619 else if (prop == myCutActor2) {
620 this->HighlightPlane(1);
621 this->State = VISU_PlanesWidget::ChangeDistance;
624 if ( this->OutlineTranslation ) {
625 this->HighlightOutline(1);
626 this->State = VISU_PlanesWidget::MovingOutline;
630 this->EventCallbackCommand->SetAbortFlag(1);
631 this->StartInteraction();
632 this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
633 this->Interactor->Render();
635 //==================================================================
636 // function: OnLeftButtonUp
638 //==================================================================
639 void VISU_PlanesWidget::OnLeftButtonUp()
641 if ( this->State == VISU_PlanesWidget::Outside ) {
645 this->State = VISU_PlanesWidget::Start;
646 this->HighlightPlane(0);
647 this->HighlightOutline(0);
648 this->HighlightNormal(0);
649 //this->SizeHandles();
651 this->EventCallbackCommand->SetAbortFlag(1);
652 this->EndInteraction();
653 this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
654 this->Interactor->Render();
656 //==================================================================
657 // function: OnMiddleButtonDown
659 //==================================================================
660 void VISU_PlanesWidget::OnMiddleButtonDown()
662 int X = this->Interactor->GetEventPosition()[0];
663 int Y = this->Interactor->GetEventPosition()[1];
665 // Okay, we can process this. See if we've picked anything.
666 // Make sure it's in the activated renderer
667 vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y);
668 if ( ren != this->CurrentRenderer ) {
669 this->State = VISU_PlanesWidget::Outside;
673 // Okay, we can process this.
674 vtkAssemblyPath *path;
675 this->Picker->Pick(X,Y,0.0,this->CurrentRenderer);
676 path = this->Picker->GetPath();
678 if ( path == NULL ) {//nothing picked
679 this->State = VISU_PlanesWidget::Outside;
684 this->Picker->GetPickPosition(this->LastPickPosition);
685 this->State = VISU_PlanesWidget::MovingPlane;
686 this->HighlightNormal(1);
687 this->HighlightPlane(1);
689 this->EventCallbackCommand->SetAbortFlag(1);
690 this->StartInteraction();
691 this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
692 this->Interactor->Render();
694 //==================================================================
695 // function: OnMiddleButtonUp
697 //==================================================================
698 void VISU_PlanesWidget::OnMiddleButtonUp()
700 if ( this->State == VISU_PlanesWidget::Outside ) {
704 this->State = VISU_PlanesWidget::Start;
705 this->HighlightPlane(0);
706 this->HighlightOutline(0);
707 this->HighlightNormal(0);
708 //this->SizeHandles();
710 this->EventCallbackCommand->SetAbortFlag(1);
711 this->EndInteraction();
712 this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
713 this->Interactor->Render();
715 //==================================================================
716 // function: OnRightButtonDown
718 //==================================================================
719 void VISU_PlanesWidget::OnRightButtonDown()
721 this->State = VISU_PlanesWidget::Scaling;
723 int X = this->Interactor->GetEventPosition()[0];
724 int Y = this->Interactor->GetEventPosition()[1];
726 // Okay, we can process this. See if we've picked anything.
727 // Make sure it's in the activated renderer
728 vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y);
729 if ( ren != this->CurrentRenderer ) {
730 this->State = VISU_PlanesWidget::Outside;
734 // Okay, we can process this. Try to pick handles first;
735 // if no handles picked, then pick the bounding box.
736 vtkAssemblyPath *path;
737 this->Picker->Pick(X,Y,0.0,this->CurrentRenderer);
738 path = this->Picker->GetPath();
739 if ( path == NULL ){ //nothing picked
740 this->State = VISU_PlanesWidget::Outside;
745 this->Picker->GetPickPosition(this->LastPickPosition);
746 this->HighlightPlane(1);
747 this->HighlightOutline(1);
748 this->HighlightNormal(1);
750 this->EventCallbackCommand->SetAbortFlag(1);
751 this->StartInteraction();
752 this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
753 this->Interactor->Render();
755 //==================================================================
756 // function: OnRightButtonUp
758 //==================================================================
759 void VISU_PlanesWidget::OnRightButtonUp()
761 if ( this->State == VISU_PlanesWidget::Outside ) {
765 this->State = VISU_PlanesWidget::Start;
766 this->HighlightPlane(0);
767 this->HighlightOutline(0);
768 this->HighlightNormal(0);
769 //this->SizeHandles();
771 this->EventCallbackCommand->SetAbortFlag(1);
772 this->EndInteraction();
773 this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
774 this->Interactor->Render();
776 //==================================================================
777 // function: OnMouseMove
779 //==================================================================
780 void VISU_PlanesWidget::OnMouseMove()
782 //this->SizeHandles();
784 // See whether we're active
785 if ( this->State == VISU_PlanesWidget::Outside ||
786 this->State == VISU_PlanesWidget::Start ) {
790 int X = this->Interactor->GetEventPosition()[0];
791 int Y = this->Interactor->GetEventPosition()[1];
793 // Do different things depending on state
794 // Calculations everybody does
795 double focalPoint[4], pickPoint[4], prevPickPoint[4];
798 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
803 // Compute the two points defining the motion vector
804 this->ComputeWorldToDisplay(this->LastPickPosition[0], this->LastPickPosition[1],
805 this->LastPickPosition[2], focalPoint);
807 this->ComputeDisplayToWorld(double(this->Interactor->GetLastEventPosition()[0]),
808 double(this->Interactor->GetLastEventPosition()[1]),
810 this->ComputeDisplayToWorld(double(X), double(Y), z, pickPoint);
812 // Process the motion
813 if ( this->State == VISU_PlanesWidget::MovingPlane ) {
814 //this->TranslatePlane(prevPickPoint, pickPoint);
815 //printf(" TranslatePlane\n");
817 else if ( this->State == VISU_PlanesWidget::MovingOutline ) {
818 //this->TranslateOutline(prevPickPoint, pickPoint);
819 //printf(" TranslateOutline\n");
821 else if ( this->State == VISU_PlanesWidget::MovingOrigin ) {
822 this->TranslateOrigin(prevPickPoint, pickPoint);
823 //printf(" TranslateOrigin\n");
825 else if ( this->State == VISU_PlanesWidget::Pushing ) {
826 this->Push(prevPickPoint, pickPoint);
827 // printf(" Push\n");
829 else if ( this->State == VISU_PlanesWidget::Scaling ) {
830 //this->Scale(prevPickPoint, pickPoint, X, Y);
831 //printf(" Scale\n");
833 else if ( this->State == VISU_PlanesWidget::Rotating ) {
834 camera->GetViewPlaneNormal(vpn);
835 this->Rotate(X, Y, prevPickPoint, pickPoint, vpn);
836 //printf(" Rotate\n");
838 else if ( this->State == VISU_PlanesWidget::ChangeDistance ) {
839 this->PushDistance(prevPickPoint, pickPoint);
840 //printf(" PushDistance\n");
842 // Interact, if desired
843 this->EventCallbackCommand->SetAbortFlag(1);
844 this->InvokeEvent(vtkCommand::InteractionEvent,NULL);
846 this->Interactor->Render();
848 //==================================================================
851 //==================================================================
852 void VISU_PlanesWidget::Push(double *p1, double *p2)
854 //Get the motion vector
859 v[i] = p2[i] - p1[i];
862 float aOr1[3], aNr1[3], aNr2[3], aD, z1;
864 myPlane1->GetOrigin(aOr1);
865 myPlane1->GetNormal(aNr1);
866 myPlane2->GetNormal(aNr2);
868 aD=vtkMath::Dot(v, aNr2);
869 z1 = aOr1[2]+aD*aNr2[2];
870 if( z1 <= myBox->GetOrigin()[2] ){
874 aD=vtkMath::Dot(v, aNr1);
875 for (i=0; i < 3; ++i) {
876 aOr1[i]=aOr1[i]+aD*aNr1[i];
878 SetOriginInternal(aOr1);
879 this->UpdateRepresentation();
881 //==================================================================
882 // function: TranslateOrigin
884 //==================================================================
885 void VISU_PlanesWidget::TranslateOrigin(double *p1, double *p2)
887 //Get the motion vector
892 v[i] = p2[i] - p1[i];
895 //Add to the current point, project back down onto plane
896 float *o = myPlane1->GetOrigin();
897 float *n = myPlane1->GetNormal();
901 newOrigin[i]=o[i] + v[i];
903 vtkPlane::ProjectPoint(newOrigin, o, n, newOrigin);
904 SetOriginInternal(newOrigin);
905 this->UpdateRepresentation();
907 //==================================================================
908 // function: SetOriginInternal
909 // purpose : Set the origin of the plane.(for Internal calls)
910 //==================================================================
911 void VISU_PlanesWidget::SetOriginInternal(float x[3])
913 float *bounds = this->myOutline->GetOutput()->GetBounds();
915 for (i=0; i<3; ++i) {
917 if ( x[i] < bounds[j] ) {
920 else if ( x[i] > bounds[j+1] ) {
926 float aOr2[3], aNr2[3], aNr1[3];
929 myPlane1->GetNormal(aNr1);
930 myPlane2->GetNormal(aNr2);
931 for (i=0; i<3; ++i) {
932 aOr2[i]=x[i]+myDistance*aNr1[i];
935 pPx->SetOrigin(aOr2);
936 pPx->SetNormal(aNr2);
937 bFlag=IsValidPlane2Position(pPx, myBox);
939 myPlane1->SetOrigin(x);
940 myPlane2->SetOrigin(aOr2);
944 //==================================================================
947 //==================================================================
948 void VISU_PlanesWidget::Rotate(int X, int Y,
949 double *p1, double *p2,
952 double v[3]; //vector of motion
953 double axis[3]; //axis of rotation
954 double theta; //rotation angle
957 // mouse motion vector in world space
959 v[i] = p2[i] - p1[i];
962 float *origin = myPlane1->GetOrigin();
963 float *normal = myPlane1->GetNormal();
965 // Create axis of rotation and angle of rotation
966 vtkMath::Cross(vpn,v,axis);
967 if ( vtkMath::Normalize(axis) == 0.0 ) {
971 int *size = this->CurrentRenderer->GetSize();
972 double l2 = (X-this->Interactor->GetLastEventPosition()[0])*
973 (X-this->Interactor->GetLastEventPosition()[0]) +
974 (Y-this->Interactor->GetLastEventPosition()[1])*
975 (Y-this->Interactor->GetLastEventPosition()[1]);
976 theta = 360.0 * sqrt(l2/((double)size[0]*size[0]+size[1]*size[1]));
978 //Manipulate the transform to reflect the rotation
979 this->Transform->Identity();
980 this->Transform->Translate(origin[0],origin[1],origin[2]);
981 this->Transform->RotateWXYZ(theta,axis);
982 this->Transform->Translate(-origin[0],-origin[1],-origin[2]);
985 float nNew[3], aN2[3], oNew[3];
986 this->Transform->TransformNormal(normal,nNew);
991 vtkMath::Normalize(nNew);
993 oNew[i] = origin[i] + myDistance*nNew[i];
996 vtkPlane *pPx=vtkPlane::New();
998 pPx->SetOrigin(oNew);
1000 bool bFlag=IsValidPlane2Position(pPx, myBox);
1002 myPlane1->SetNormal(nNew);
1003 this->myPlane2->SetNormal(aN2);
1004 this->myPlane2->SetOrigin(oNew);
1007 this->UpdateRepresentation();
1009 //==================================================================
1010 // function: PushDistance
1012 //==================================================================
1013 void VISU_PlanesWidget::PushDistance(double *p1, double *p2)
1016 float v[3], *anOrigin1, *aN1, *anOrigin2, *aN2, aD;
1017 //Get the motion vector
1018 for (i=0; i<3; ++i){
1019 v[i] = p2[i] - p1[i];
1022 anOrigin1 = myPlane1->GetOrigin();
1023 aN1 = myPlane1->GetNormal();
1024 anOrigin2 = myPlane2->GetOrigin();
1025 aN2 = myPlane2->GetNormal();
1027 vtkMath::Normalize(aN1);
1030 double distance = vtkMath::Dot( v, aN2 );
1031 for(i=0; i<3; ++i) {
1032 origin[i] = anOrigin2[i] + distance * aN2[i];
1034 float d = DistanceToPlane(origin, aN1, anOrigin1);
1039 float aOr2[3], aNr2[3];
1042 myPlane2->GetOrigin(aOr2);
1043 myPlane2->GetNormal(aNr2);
1044 pPx=vtkPlane::New();
1045 pPx->SetNormal(aNr2);
1046 aD=vtkMath::Dot(v, aNr2);
1047 for (i=0; i < 3; ++i) {
1048 aOr2[i]=aOr2[i]+aD*aNr2[i];
1050 pPx->SetOrigin(aOr2);
1051 bFlag=IsValidPlane2Position(pPx, myBox);
1053 myPlane2->SetOrigin(aOr2);
1054 myPlane2->Modified();
1055 aD=DistanceToPlane(aOr2, aN1, anOrigin1);
1060 this->UpdateRepresentation();
1063 //==================================================================
1064 // function: TranslatePlane
1065 // purpose : Loop through all points and translate them
1066 //==================================================================
1067 void VISU_PlanesWidget::TranslatePlane(double *p1, double *p2)
1069 //Get the motion vector
1071 v[0] = p2[0] - p1[0];
1072 v[1] = p2[1] - p1[1];
1073 v[2] = p2[2] - p1[2];
1075 //Translate the plane
1077 float *origin = myPlane1->GetOrigin();
1078 oNew[0] = origin[0] + v[0];
1079 oNew[1] = origin[1] + v[1];
1080 oNew[2] = origin[2] + v[2];
1081 myPlane1->SetOrigin(oNew);
1083 origin = this->myPlane2->GetOrigin();
1084 oNew[0] = origin[0] + v[0];
1085 oNew[1] = origin[1] + v[1];
1086 oNew[2] = origin[2] + v[2];
1087 this->myPlane2->SetOrigin(oNew);
1089 this->UpdateRepresentation();
1091 //==================================================================
1092 // function: TranslateOutline
1093 // purpose :Loop through all points and translate them
1094 //==================================================================
1095 void VISU_PlanesWidget::TranslateOutline(double *p1, double *p2)
1097 //Get the motion vector
1099 v[0] = p2[0] - p1[0];
1100 v[1] = p2[1] - p1[1];
1101 v[2] = p2[2] - p1[2];
1103 //Translate the bounding box
1104 float *origin = myBox->GetOrigin();
1106 oNew[0] = origin[0] + v[0];
1107 oNew[1] = origin[1] + v[1];
1108 oNew[2] = origin[2] + v[2];
1109 myBox->SetOrigin(oNew);
1111 //Translate the plane
1112 origin = myPlane1->GetOrigin();
1113 oNew[0] = origin[0] + v[0];
1114 oNew[1] = origin[1] + v[1];
1115 oNew[2] = origin[2] + v[2];
1116 myPlane1->SetOrigin(oNew);
1118 origin = this->myPlane2->GetOrigin();
1119 oNew[0] = origin[0] + v[0];
1120 oNew[1] = origin[1] + v[1];
1121 oNew[2] = origin[2] + v[2];
1122 this->myPlane2->SetOrigin(oNew);
1124 this->UpdateRepresentation();
1127 //==================================================================
1130 //==================================================================
1131 void VISU_PlanesWidget::Scale(double *p1, double *p2,
1132 int vtkNotUsed(X), int Y)
1134 //Get the motion vector
1136 v[0] = p2[0] - p1[0];
1137 v[1] = p2[1] - p1[1];
1138 v[2] = p2[2] - p1[2];
1140 //int res = this->PlaneSource->GetXResolution();
1141 float *o = myPlane1->GetOrigin();
1143 // Compute the scale factor
1144 float sf = vtkMath::Norm(v) / this->myOutline->GetOutput()->GetLength();
1145 if ( Y > this->Interactor->GetLastEventPosition()[1] ) {
1152 this->Transform->Identity();
1153 this->Transform->Translate(o[0],o[1],o[2]);
1154 this->Transform->Scale(sf,sf,sf);
1155 this->Transform->Translate(-o[0],-o[1],-o[2]);
1157 float *origin = myBox->GetOrigin();
1158 float *spacing = myBox->GetSpacing();
1159 float oNew[3], p[3], pNew[3];
1160 p[0] = origin[0] + spacing[0];
1161 p[1] = origin[1] + spacing[1];
1162 p[2] = origin[2] + spacing[2];
1164 this->Transform->TransformPoint(origin,oNew);
1165 this->Transform->TransformPoint(p,pNew);
1167 myBox->SetOrigin(oNew);
1168 myBox->SetSpacing( (pNew[0]-oNew[0]), (pNew[1]-oNew[1]), (pNew[2]-oNew[2]) );
1170 this->UpdateRepresentation();
1175 //==================================================================
1176 // function: CreateDefaultProperties
1178 //==================================================================
1179 void VISU_PlanesWidget::CreateDefaultProperties()
1181 // Normal properties
1182 this->NormalProperty = vtkProperty::New();
1183 this->NormalProperty->SetColor(1,1,1);
1184 this->NormalProperty->SetLineWidth(2);
1186 this->SelectedNormalProperty = vtkProperty::New();
1187 this->SelectedNormalProperty->SetColor(1,0,0);
1188 this->NormalProperty->SetLineWidth(2);
1191 this->PlaneProperty = vtkProperty::New();
1192 this->PlaneProperty->SetAmbient(1.0);
1193 this->PlaneProperty->SetAmbientColor(1.0,1.0,1.0);
1195 this->SelectedPlaneProperty = vtkProperty::New();
1196 this->SelectedPlaneProperty->SetAmbient(1.0);
1197 this->SelectedPlaneProperty->SetAmbientColor(0.0,1.0,0.0);
1198 this->SelectedPlaneProperty->SetOpacity(0.25);
1200 // Outline properties
1201 this->OutlineProperty = vtkProperty::New();
1202 this->OutlineProperty->SetAmbient(1.0);
1203 this->OutlineProperty->SetAmbientColor(1.0,1.0,1.0);
1205 this->SelectedOutlineProperty = vtkProperty::New();
1206 this->SelectedOutlineProperty->SetAmbient(1.0);
1207 this->SelectedOutlineProperty->SetAmbientColor(0.0,1.0,0.0);
1210 this->EdgesProperty = vtkProperty::New();
1211 this->EdgesProperty->SetAmbient(1.0);
1212 this->EdgesProperty->SetAmbientColor(1.0,1.0,1.0);
1214 //==================================================================
1215 // function: InitialPlaceWidget
1217 //==================================================================
1218 void VISU_PlanesWidget::InitialPlaceWidget(float bds[6])
1220 float bounds[6], origin[3];
1224 this->AdjustBounds(bds, bounds, origin);
1225 this->SetOrigin((bounds[1]+bounds[0])/2.0,
1226 (bounds[3]+bounds[2])/2.0,
1227 (bounds[5]+bounds[4])/2.0);
1229 static float DIST_COEFF = 0.1;
1230 SetDistance(this->InitialLength*DIST_COEFF);
1232 this->UpdateRepresentation();
1234 //==================================================================
1235 // function: PlaceWidget
1237 //==================================================================
1238 void VISU_PlanesWidget::PlaceWidget(float bds[6])
1241 float bounds[6], origin[3];
1243 this->AdjustBounds(bds, bounds, origin);
1245 // Set up the bounding box
1246 myBox->SetOrigin(bounds[0],bounds[2],bounds[4]);
1247 myBox->SetSpacing((bounds[1]-bounds[0]),(bounds[3]-bounds[2]),
1248 (bounds[5]-bounds[4]));
1249 this->myOutline->Update();
1251 if (this->Input || this->Prop3D) {
1252 this->LineSource->SetPoint1(myPlane1->GetOrigin());
1253 if ( this->NormalToYAxis ) {
1254 myPlane1->SetNormal(0,1,0);
1255 myPlane2->SetNormal(0,-1,0);
1256 this->LineSource->SetPoint2(0,1,0);
1258 else if ( this->NormalToZAxis ) {
1259 myPlane1->SetNormal(0,0,1);
1260 myPlane2->SetNormal(0,0,-1);
1261 this->LineSource->SetPoint2(0,0,1);
1263 else{ //default or x-normal
1264 myPlane1->SetNormal(1,0,0);
1265 myPlane2->SetNormal(-1,0,0);
1266 this->LineSource->SetPoint2(1,0,0);
1270 for (i=0; i<6; i++) {
1271 this->InitialBounds[i] = bounds[i];
1274 this->InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
1275 (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
1276 (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
1278 this->UpdateRepresentation();
1280 //==================================================================
1281 // function: SetOrigin
1282 // purpose :Set the origin of the plane.(for external calls)
1283 //==================================================================
1284 void VISU_PlanesWidget::SetOrigin(float x, float y, float z)
1290 this->SetOrigin(origin);
1292 //==================================================================
1293 // function: SetOrigin
1294 // purpose : Set the origin of the plane.(for external calls)
1295 //==================================================================
1296 void VISU_PlanesWidget::SetOrigin(float x[3])
1298 float *bounds = this->myOutline->GetOutput()->GetBounds();
1299 for (int i=0; i<3; i++) {
1300 if ( x[i] < bounds[2*i] ) {
1303 else if ( x[i] > bounds[2*i+1] ) {
1304 x[i] = bounds[2*i+1];
1307 myPlane1->SetOrigin(x);
1308 float *origin, *normal, oNew[3];
1309 origin = myPlane1->GetOrigin();
1310 normal = myPlane1->GetNormal();
1311 vtkMath::Normalize(normal);
1312 oNew[0] = origin[0] + myDistance*normal[0];
1313 oNew[1] = origin[1] + myDistance*normal[1];
1314 oNew[2] = origin[2] + myDistance*normal[2];
1315 this->myPlane2->SetOrigin(oNew);
1316 this->UpdateRepresentation();
1318 //==================================================================
1319 // function: GetOrigin
1320 // purpose :Get the origin of the plane.
1321 //==================================================================
1322 float* VISU_PlanesWidget::GetOrigin()
1324 return myPlane1->GetOrigin();
1327 void VISU_PlanesWidget::GetOrigin(float xyz[3])
1329 myPlane1->GetOrigin(xyz);
1331 //==================================================================
1332 // function: SetNormal
1333 // purpose :Set the normal to the plane.
1334 //==================================================================
1335 void VISU_PlanesWidget::SetNormal(float x, float y, float z)
1341 vtkMath::Normalize(n);
1342 myPlane1->SetNormal(n);
1346 this->myPlane2->SetNormal(n);
1348 this->UpdateRepresentation();
1351 //==================================================================
1352 // function: SetNormal
1353 // purpose :Set the normal to the plane.
1354 //==================================================================
1355 void VISU_PlanesWidget::SetNormal(float n[3])
1357 this->SetNormal(n[0], n[1], n[2]);
1359 //==================================================================
1360 // function: GetNormal
1361 // purpose :Get the normal to the plane.
1362 //==================================================================
1363 float* VISU_PlanesWidget::GetNormal()
1365 return myPlane1->GetNormal();
1367 //==================================================================
1368 // function: GetNormal
1369 // purpose :Get the normal to the plane.
1370 //==================================================================
1371 void VISU_PlanesWidget::GetNormal(float xyz[3])
1373 myPlane1->GetNormal(xyz);
1375 //==================================================================
1376 // function: SetDrawPlane
1378 //==================================================================
1379 void VISU_PlanesWidget::SetDrawPlane(int drawPlane)
1381 if ( drawPlane == this->myDrawPlane ) {
1386 this->myDrawPlane = drawPlane;
1387 if ( this->Enabled ) {
1389 this->CurrentRenderer->AddActor(this->myCutActor1);
1390 this->CurrentRenderer->AddActor(myCutActor2);
1393 this->CurrentRenderer->RemoveActor(this->myCutActor1);
1394 this->CurrentRenderer->RemoveActor(myCutActor2);
1396 this->Interactor->Render();
1399 //==================================================================
1400 // function: SetNormalToXAxis
1402 //==================================================================
1403 void VISU_PlanesWidget::SetNormalToXAxis (int var)
1405 if (this->NormalToXAxis != var) {
1406 this->NormalToXAxis = var;
1410 this->NormalToYAxisOff();
1411 this->NormalToZAxisOff();
1414 //==================================================================
1415 // function: SetNormalToYAxis
1417 //==================================================================
1418 void VISU_PlanesWidget::SetNormalToYAxis (int var)
1420 if (this->NormalToYAxis != var) {
1421 this->NormalToYAxis = var;
1425 this->NormalToXAxisOff();
1426 this->NormalToZAxisOff();
1429 //==================================================================
1430 // function: SetNormalToZAxis
1432 //==================================================================
1433 void VISU_PlanesWidget::SetNormalToZAxis (int var)
1435 if (this->NormalToZAxis != var) {
1436 this->NormalToZAxis = var;
1440 this->NormalToXAxisOff();
1441 this->NormalToYAxisOff();
1444 //==================================================================
1445 // function: GetPolyData
1447 //==================================================================
1448 void VISU_PlanesWidget::GetPolyData(vtkPolyData *pd)
1450 pd->ShallowCopy(this->myCutter1->GetOutput());
1452 //==================================================================
1453 // function: GetPolyDataSource
1455 //==================================================================
1457 vtkPolyDataSource *VISU_PlanesWidget::GetPolyDataSource()
1459 return this->myCutter1;
1462 //==================================================================
1463 // function:GetPlane
1465 //==================================================================
1466 void VISU_PlanesWidget::GetPlane(vtkPlane *plane)
1468 if ( plane == NULL ) {
1472 plane->SetNormal(myPlane1->GetNormal());
1473 plane->SetOrigin(myPlane1->GetOrigin());
1475 //==================================================================
1476 // function:UpdatePlacement
1478 //==================================================================
1479 void VISU_PlanesWidget::UpdatePlacement(void)
1481 this->myOutline->Update();
1482 this->myCutter1->Update();
1483 this->myEdges1->Update();
1485 //==================================================================
1486 // function:UpdateRepresentation
1488 //==================================================================
1489 void VISU_PlanesWidget::UpdateRepresentation()
1491 if ( ! this->CurrentRenderer ) {
1495 float *origin = myPlane1->GetOrigin();
1496 float *normal = myPlane1->GetNormal();
1499 // Setup the plane normal
1500 float d = this->myOutline->GetOutput()->GetLength();
1502 p2[0] = origin[0] + 0.30 * d * normal[0];
1503 p2[1] = origin[1] + 0.30 * d * normal[1];
1504 p2[2] = origin[2] + 0.30 * d * normal[2];
1506 this->LineSource->SetPoint1(origin);
1507 this->LineSource->SetPoint2(p2);
1508 this->ConeSource->SetCenter(p2);
1509 this->ConeSource->SetDirection(normal);
1510 ConeActor->SetCenter(p2);
1512 p2[0] = origin[0] - 0.30 * d * normal[0];
1513 p2[1] = origin[1] - 0.30 * d * normal[1];
1514 p2[2] = origin[2] - 0.30 * d * normal[2];
1516 this->LineSource2->SetPoint1(origin);
1517 this->LineSource2->SetPoint2(p2);
1518 this->ConeSource2->SetCenter(p2);
1519 this->ConeSource2->SetDirection(normal);
1520 ConeActor2->SetCenter(p2);
1522 // Set up the position handle
1523 this->Sphere->SetCenter(origin);
1524 SphereActor->SetCenter(origin);
1526 this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput());
1529 //==================================================================
1530 // function:PrintSelf
1532 //==================================================================
1533 void VISU_PlanesWidget::PrintSelf(ostream& os, vtkIndent indent)
1535 this->Superclass::PrintSelf(os,indent);
1537 //==================================================================
1538 // function: IsValidPlane2Position
1540 //==================================================================
1541 bool IsValidPlane2Position(vtkPlane *pPx,
1542 vtkDataSet *pDataSet,
1547 float aD, aDmax, aPnts[24], aDiagonal;
1548 float aTol1, aOr[3], aN[3];
1551 aDiagonal=pDataSet->GetLength();
1552 aTol1=aDiagonal*aTol;
1554 GetBndPoints(pDataSet, aPnts);
1556 pPx->GetOrigin(aOr);
1558 vtkMath::Normalize(aN);
1562 for (i=0; i<24; i+=3){
1563 aD=-DistanceToPlane(aPnts+i, aN, aOr);
1569 if (iFound && aDmax>aTol1) {
1574 //==================================================================
1575 // function: GetBndPoints
1577 //==================================================================
1578 void GetBndPoints(vtkDataSet *pDataSet,
1582 0,2,4,1,2,4,1,3,4,0,3,4,
1583 0,2,5,1,2,5,1,3,5,0,3,5
1586 float *pBounds=pDataSet->GetBounds();
1588 for (i=0; i<24; ++i){
1589 aPnts[i]=pBounds[aIndx[i]];
1592 //==================================================================
1593 // function: DistanceToPlane
1595 //==================================================================
1596 float DistanceToPlane(const float x[3],
1600 return ((float) (n[0]*(x[0]-p0[0]) +
1602 n[2]*(x[2]-p0[2])));
1605 //==================================================================
1606 // function:SizeHandles
1608 //==================================================================
1609 void VISU_PlanesWidget::SizeHandles()
1612 this->vtk3DWidget::SizeHandles(1.35);