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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : VISU_PlanesWidget.h
25 // Author : Peter KURNEV
29 #ifndef __VISU_PlanesWidget_h
30 #define __VISU_PlanesWidget_h
32 #include "VISU_ImplicitFunctionWidget.hxx"
34 class vtkPolyDataMapper;
38 class vtkSphereSource;
43 class vtkOutlineFilter;
44 class vtkFeatureEdges;
47 class vtkImplicitBoolean;
48 class vtkImplicitFunction;
49 class VISU_UnScaledActor;
52 class VISU_PlanesWidget : public VISU_ImplicitFunctionWidget
56 // Instantiate the object.
57 static VISU_PlanesWidget *New();
59 vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget);
60 void PrintSelf(ostream& os, vtkIndent indent);
63 SetDistance(const vtkFloatingPointType theDistance);
68 vtkGetMacro(InitialLength,vtkFloatingPointType);
75 // Methods that satisfy the superclass' API.
82 PlaceWidget(vtkFloatingPointType bounds[6]);
85 // Get the origin of the plane.
87 SetOrigin(vtkFloatingPointType x,
88 vtkFloatingPointType y,
89 vtkFloatingPointType z);
92 SetOrigin(vtkFloatingPointType x[3]);
98 GetOrigin(vtkFloatingPointType xyz[3]);
101 // Get the normal to the plane.
103 SetNormal(vtkFloatingPointType x,
104 vtkFloatingPointType y,
105 vtkFloatingPointType z);
108 SetNormal(vtkFloatingPointType x[3]);
110 vtkFloatingPointType*
114 GetNormal(vtkFloatingPointType xyz[3]);
117 // Force the plane widget to be aligned with one of the x-y-z axes.
118 // If one axis is set on, the other two will be set off.
119 // Remember that when the state changes, a ModifiedEvent is invoked.
120 // This can be used to snap the plane to the axes if it is orginally
123 SetNormalToXAxis(int);
125 vtkGetMacro(NormalToXAxis,int);
126 vtkBooleanMacro(NormalToXAxis,int);
129 SetNormalToYAxis(int);
131 vtkGetMacro(NormalToYAxis,int);
132 vtkBooleanMacro(NormalToYAxis,int);
135 SetNormalToZAxis(int);
136 vtkGetMacro(NormalToZAxis,int);
137 vtkBooleanMacro(NormalToZAxis,int);
140 // Turn on/off tubing of the wire outline of the plane. The tube thickens
141 // the line by wrapping with a vtkTubeFilter.
142 //vtkSetMacro(Tubing,int);
143 //vtkGetMacro(Tubing,int);
144 //vtkBooleanMacro(Tubing,int);
147 // Enable/disable the drawing of the plane. In some cases the plane
148 // interferes with the object that it is operating on (i.e., the
149 // plane interferes with the cut surface it produces producing
150 // z-buffer artifacts.)
152 SetDrawPlane(int plane);
161 // Turn on/off the ability to translate the bounding box by grabbing it
162 // with the left mouse button.
163 vtkSetMacro(OutlineTranslation,int);
164 vtkGetMacro(OutlineTranslation,int);
165 vtkBooleanMacro(OutlineTranslation,int);
168 // Grab the polydata that defines the plane. The polydata contains a single
169 // polygon that is clipped by the bounding box.
171 GetPolyData(vtkPolyData *pd);
174 // Satisfies superclass API. This returns a pointer to the underlying
175 // PolyData (which represents the plane).
176 //vtkPolyDataSource* GetPolyDataSource();
179 // Get the implicit function for the plane. The user must provide the
180 // instance of the class vtkPlane. Note that vtkPlane is a subclass of
181 // vtkImplicitFunction, meaning that it can be used by a variety of filters
182 // to perform clipping, cutting, and selection of data.
184 GetPlane(vtkPlane *plane);
187 // Satisfies the superclass API. This will change the state of the widget
188 // to match changes that have been made to the underlying PolyDataSource
190 UpdatePlacement(void);
193 // Get the properties on the normal (line and cone).
194 vtkGetObjectMacro(NormalProperty,vtkProperty);
195 vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
198 // Get the plane properties. The properties of the plane when selected
199 // and unselected can be manipulated.
200 vtkGetObjectMacro(PlaneProperty,vtkProperty);
201 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
204 // Get the property of the outline.
205 vtkGetObjectMacro(OutlineProperty,vtkProperty);
206 vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
209 // Get the property of the intersection edges. (This property also
210 // applies to the edges when tubed.)
211 vtkGetObjectMacro(EdgesProperty,vtkProperty);
214 InitialPlaceWidget(vtkFloatingPointType bds[6]);
218 ~VISU_PlanesWidget();
220 //BTX - manage the state of the widget
239 ProcessEvents(vtkObject* object, unsigned long event,
240 void* clientdata, void* calldata);
242 // ProcessEvents() dispatches to these methods.
243 void OnLeftButtonDown();
244 void OnLeftButtonUp();
245 void OnMiddleButtonDown();
246 void OnMiddleButtonUp();
247 void OnRightButtonDown();
248 void OnRightButtonUp();
251 // Methods to manipulate the plane
252 void ConstrainOrigin(vtkFloatingPointType x[3]);
253 void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
254 void TranslatePlane(double *p1, double *p2);
255 void TranslateOutline(double *p1, double *p2);
256 void TranslateOrigin(double *p1, double *p2);
257 void Push(double *p1, double *p2);
258 void Scale(double *p1, double *p2, int X, int Y);
259 void PushDistance(double *p1, double *p2);
261 void CreateDefaultProperties();
263 void GeneratePlane();
264 //virtual void SizeHandles();
265 void HighlightPlane(int highlight);
266 void HighlightNormal(int highlight);
267 void HighlightOutline(int highlight);
268 void UpdateRepresentation();
269 void SetOriginInternal(vtkFloatingPointType x[3]);
277 // Flags to handle mouse events
278 bool HandleMoveEvent;
279 bool HandleLeftButtonEvent;
280 bool HandleMiddleButtonEvent;
281 bool HandleRightButtonEvent;
282 // The actual plane which is being manipulated
286 vtkFloatingPointType myDistance;
287 vtkImplicitBoolean *myImplicitFunction;
289 // The bounding box is represented by a single voxel image data
291 vtkOutlineFilter *myOutline;
292 vtkPolyDataMapper *myOutlineMapper;
293 vtkActor *myOutlineActor;
295 int OutlineTranslation; //whether the outline can be moved
297 // The cut plane is produced with a vtkCutter
298 vtkCutter *myCutter1;
299 vtkPolyDataMapper *myCutMapper1;
300 vtkActor *myCutActor1;
302 vtkCutter *myCutter2;
303 vtkPolyDataMapper *myCutMapper2;
304 vtkActor *myCutActor2;
306 vtkFeatureEdges *myEdges2;
307 vtkPolyDataMapper *myEdgesMapper2;
308 vtkActor *myEdgesActor2;
312 vtkFeatureEdges *myEdges1;
313 vtkPolyDataMapper *myEdgesMapper1;
314 vtkActor *myEdgesActor1;
317 vtkConeSource *ConeSource;
318 vtkPolyDataMapper *ConeMapper;
319 VISU_UnScaledActor *ConeActor;
321 vtkLineSource *LineSource;
322 vtkPolyDataMapper *LineMapper;
325 vtkConeSource *ConeSource2;
326 vtkPolyDataMapper *ConeMapper2;
327 VISU_UnScaledActor *ConeActor2;
329 vtkLineSource *LineSource2;
330 vtkPolyDataMapper *LineMapper2;
331 vtkActor *LineActor2;
332 // The origin positioning handle
333 vtkSphereSource *Sphere;
334 vtkPolyDataMapper *SphereMapper;
335 VISU_UnScaledActor *SphereActor;
338 vtkCellPicker *Picker;
340 // Transform the normal (used for rotation)
341 vtkTransform *Transform;
342 // Properties used to control the appearance of selected objects and
343 // the manipulator in general.
344 vtkProperty *NormalProperty;
345 vtkProperty *SelectedNormalProperty;
346 vtkProperty *PlaneProperty;
347 vtkProperty *SelectedPlaneProperty;
348 vtkProperty *OutlineProperty;
349 vtkProperty *SelectedOutlineProperty;
350 vtkProperty *EdgesProperty;
353 VISU_PlanesWidget(const VISU_PlanesWidget&); //Not implemented
354 void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented