1 // Copyright (C) 2007-2012 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
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
24 // File : VISU_PlanesWidget.h
25 // Author : Peter KURNEV
29 #ifndef __VISU_PlanesWidget_h
30 #define __VISU_PlanesWidget_h
32 #include "VISUPipeline.hxx"
33 #include "VISU_ImplicitFunctionWidget.hxx"
35 class vtkPolyDataMapper;
39 class vtkSphereSource;
44 class vtkOutlineFilter;
45 class vtkFeatureEdges;
48 class vtkImplicitBoolean;
49 class vtkImplicitFunction;
50 class VISU_UnScaledActor;
53 class VISU_PIPELINE_EXPORT VISU_PlanesWidget : public VISU_ImplicitFunctionWidget
57 // Instantiate the object.
58 static VISU_PlanesWidget *New();
60 vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget);
61 void PrintSelf(ostream& os, vtkIndent indent);
64 SetDistance(const vtkFloatingPointType theDistance);
69 vtkGetMacro(InitialLength,vtkFloatingPointType);
76 // Methods that satisfy the superclass' API.
83 PlaceWidget(vtkFloatingPointType bounds[6]);
86 // Get the origin of the plane.
88 SetOrigin(vtkFloatingPointType x,
89 vtkFloatingPointType y,
90 vtkFloatingPointType z);
93 SetOrigin(vtkFloatingPointType x[3]);
99 GetOrigin(vtkFloatingPointType xyz[3]);
102 // Get the normal to the plane.
104 SetNormal(vtkFloatingPointType x,
105 vtkFloatingPointType y,
106 vtkFloatingPointType z);
109 SetNormal(vtkFloatingPointType x[3]);
111 vtkFloatingPointType*
115 GetNormal(vtkFloatingPointType xyz[3]);
118 // Force the plane widget to be aligned with one of the x-y-z axes.
119 // If one axis is set on, the other two will be set off.
120 // Remember that when the state changes, a ModifiedEvent is invoked.
121 // This can be used to snap the plane to the axes if it is orginally
124 SetNormalToXAxis(int);
126 vtkGetMacro(NormalToXAxis,int);
127 vtkBooleanMacro(NormalToXAxis,int);
130 SetNormalToYAxis(int);
132 vtkGetMacro(NormalToYAxis,int);
133 vtkBooleanMacro(NormalToYAxis,int);
136 SetNormalToZAxis(int);
137 vtkGetMacro(NormalToZAxis,int);
138 vtkBooleanMacro(NormalToZAxis,int);
141 // Turn on/off tubing of the wire outline of the plane. The tube thickens
142 // the line by wrapping with a vtkTubeFilter.
143 //vtkSetMacro(Tubing,int);
144 //vtkGetMacro(Tubing,int);
145 //vtkBooleanMacro(Tubing,int);
148 // Enable/disable the drawing of the plane. In some cases the plane
149 // interferes with the object that it is operating on (i.e., the
150 // plane interferes with the cut surface it produces producing
151 // z-buffer artifacts.)
153 SetDrawPlane(int plane);
162 // Turn on/off the ability to translate the bounding box by grabbing it
163 // with the left mouse button.
164 vtkSetMacro(OutlineTranslation,int);
165 vtkGetMacro(OutlineTranslation,int);
166 vtkBooleanMacro(OutlineTranslation,int);
169 // Grab the polydata that defines the plane. The polydata contains a single
170 // polygon that is clipped by the bounding box.
172 GetPolyData(vtkPolyData *pd);
175 // Satisfies superclass API. This returns a pointer to the underlying
176 // PolyData (which represents the plane).
177 //vtkPolyDataSource* GetPolyDataSource();
180 // Get the implicit function for the plane. The user must provide the
181 // instance of the class vtkPlane. Note that vtkPlane is a subclass of
182 // vtkImplicitFunction, meaning that it can be used by a variety of filters
183 // to perform clipping, cutting, and selection of data.
185 GetPlane(vtkPlane *plane);
188 // Satisfies the superclass API. This will change the state of the widget
189 // to match changes that have been made to the underlying PolyDataSource
191 UpdatePlacement(void);
194 // Get the properties on the normal (line and cone).
195 vtkGetObjectMacro(NormalProperty,vtkProperty);
196 vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
199 // Get the plane properties. The properties of the plane when selected
200 // and unselected can be manipulated.
201 vtkGetObjectMacro(PlaneProperty,vtkProperty);
202 vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
205 // Get the property of the outline.
206 vtkGetObjectMacro(OutlineProperty,vtkProperty);
207 vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
210 // Get the property of the intersection edges. (This property also
211 // applies to the edges when tubed.)
212 vtkGetObjectMacro(EdgesProperty,vtkProperty);
215 InitialPlaceWidget(vtkFloatingPointType bds[6]);
219 ~VISU_PlanesWidget();
221 //BTX - manage the state of the widget
240 ProcessEvents(vtkObject* object, unsigned long event,
241 void* clientdata, void* calldata);
243 // ProcessEvents() dispatches to these methods.
244 void OnLeftButtonDown();
245 void OnLeftButtonUp();
246 void OnMiddleButtonDown();
247 void OnMiddleButtonUp();
248 void OnRightButtonDown();
249 void OnRightButtonUp();
252 // Methods to manipulate the plane
253 void ConstrainOrigin(vtkFloatingPointType x[3]);
254 void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
255 void TranslatePlane(double *p1, double *p2);
256 void TranslateOutline(double *p1, double *p2);
257 void TranslateOrigin(double *p1, double *p2);
258 void Push(double *p1, double *p2);
259 void Scale(double *p1, double *p2, int X, int Y);
260 void PushDistance(double *p1, double *p2);
262 void CreateDefaultProperties();
264 void GeneratePlane();
265 //virtual void SizeHandles();
266 void HighlightPlane(int highlight);
267 void HighlightNormal(int highlight);
268 void HighlightOutline(int highlight);
269 void UpdateRepresentation();
270 void SetOriginInternal(vtkFloatingPointType x[3]);
278 // Flags to handle mouse events
279 bool HandleMoveEvent;
280 bool HandleLeftButtonEvent;
281 bool HandleMiddleButtonEvent;
282 bool HandleRightButtonEvent;
283 // The actual plane which is being manipulated
287 vtkFloatingPointType myDistance;
288 vtkImplicitBoolean *myImplicitFunction;
290 // The bounding box is represented by a single voxel image data
292 vtkOutlineFilter *myOutline;
293 vtkPolyDataMapper *myOutlineMapper;
294 vtkActor *myOutlineActor;
296 int OutlineTranslation; //whether the outline can be moved
298 // The cut plane is produced with a vtkEDFCutter
299 vtkEDFCutter *myCutter1;
300 vtkPolyDataMapper *myCutMapper1;
301 vtkActor *myCutActor1;
303 vtkEDFCutter *myCutter2;
304 vtkPolyDataMapper *myCutMapper2;
305 vtkActor *myCutActor2;
307 vtkFeatureEdges *myEdges2;
308 vtkPolyDataMapper *myEdgesMapper2;
309 vtkActor *myEdgesActor2;
313 vtkFeatureEdges *myEdges1;
314 vtkPolyDataMapper *myEdgesMapper1;
315 vtkActor *myEdgesActor1;
318 vtkConeSource *ConeSource;
319 vtkPolyDataMapper *ConeMapper;
320 VISU_UnScaledActor *ConeActor;
322 vtkLineSource *LineSource;
323 vtkPolyDataMapper *LineMapper;
326 vtkConeSource *ConeSource2;
327 vtkPolyDataMapper *ConeMapper2;
328 VISU_UnScaledActor *ConeActor2;
330 vtkLineSource *LineSource2;
331 vtkPolyDataMapper *LineMapper2;
332 vtkActor *LineActor2;
333 // The origin positioning handle
334 vtkSphereSource *Sphere;
335 vtkPolyDataMapper *SphereMapper;
336 VISU_UnScaledActor *SphereActor;
339 vtkCellPicker *Picker;
341 // Transform the normal (used for rotation)
342 vtkTransform *Transform;
343 // Properties used to control the appearance of selected objects and
344 // the manipulator in general.
345 vtkProperty *NormalProperty;
346 vtkProperty *SelectedNormalProperty;
347 vtkProperty *PlaneProperty;
348 vtkProperty *SelectedPlaneProperty;
349 vtkProperty *OutlineProperty;
350 vtkProperty *SelectedOutlineProperty;
351 vtkProperty *EdgesProperty;
354 VISU_PlanesWidget(const VISU_PlanesWidget&); //Not implemented
355 void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented