00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_UGRIDCLIPPER_H
00023 #define MECHSYS_UGRIDCLIPPER_H
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include "config.h"
00027 #else
00028 #ifndef REAL
00029 #define REAL double
00030 #endif
00031 #endif
00032
00033
00034 #include "vtkRenderer.h"
00035 #include "vtkUnstructuredGrid.h"
00036 #include "vtkPlane.h"
00037 #include "vtkClipDataSet.h"
00038 #include "vtkDataSetMapper.h"
00039 #include "vtkActor.h"
00040 #include "vtkImplicitPlaneWidget2.h"
00041 #include "vtkImplicitPlaneRepresentation.h"
00042 #include "vtkProperty.h"
00043 #include "vtkAlgorithmOutput.h"
00044
00045
00046 #include "vtkwrap/vtkwin.h"
00047 #include "vtkwrap/colors.h"
00048 #include "vtkwrap/updateplanecallback.h"
00049
00050 class UGridClipper
00051 {
00052 public:
00053
00054 UGridClipper(VTKWin & Win, vtkUnstructuredGrid * Dataset, vtkAlgorithmOutput * OutputPort=NULL,
00055 REAL x0=0, REAL y0=0, REAL z0=0,
00056 REAL nx=1, REAL ny=1, REAL nz=1);
00057
00058
00059 ~UGridClipper();
00060
00061
00062 void AddActorsTo (VTKWin & Win);
00063 void DelActorsFrom (VTKWin & Win);
00064 void EnableWidget (int Enable=1) { _widget->SetEnabled(Enable); }
00065 vtkAlgorithmOutput * GetOutputPort() { if (_clipper!=NULL) return _clipper->GetOutputPort(); else return NULL; }
00066
00067 private:
00068
00069 vtkPlane * _plane;
00070 vtkClipDataSet * _clipper;
00071 vtkDataSetMapper * _mapper;
00072 vtkActor * _actor;
00073 UpdatePlaneCallBack * _update_cback;
00074 vtkImplicitPlaneWidget2 * _widget;
00075 vtkImplicitPlaneRepresentation * _rep;
00076
00077 };
00078
00079
00081
00082
00083 inline UGridClipper::UGridClipper(VTKWin & Win, vtkUnstructuredGrid * Dataset, vtkAlgorithmOutput * AlgoOut,
00084 REAL x0, REAL y0, REAL z0,
00085 REAL nx, REAL ny, REAL nz)
00086 {
00087
00088 _plane = vtkPlane ::New();
00089 _clipper = vtkClipDataSet ::New();
00090 _mapper = vtkDataSetMapper ::New();
00091 _actor = vtkActor ::New();
00092 _plane -> SetOrigin (x0,y0,z0);
00093 _plane -> SetNormal (nx,ny,nz); if (AlgoOut==NULL) {
00094 _clipper -> SetInput (Dataset); } else {
00095 _clipper -> SetInputConnection (AlgoOut); }
00096 _clipper -> SetClipFunction (_plane);
00097 _clipper -> InsideOutOn ();
00098 _mapper -> SetInputConnection (_clipper->GetOutputPort());
00099 _actor -> SetMapper (_mapper);
00100
00101
00102 _update_cback = UpdatePlaneCallBack ::New();
00103 _rep = vtkImplicitPlaneRepresentation ::New();
00104 _widget = vtkImplicitPlaneWidget2 ::New();
00105 _rep -> SetPlaceFactor (1.25);
00106 _rep -> PlaceWidget (Dataset->GetBounds());
00107 _rep -> DrawPlaneOff ();
00108 _rep -> GetNormalProperty ()->SetColor(CLR["peacock"].C);
00109 _rep -> GetOutlineProperty ()->SetColor(CLR["black"].C);
00110 _rep -> GetEdgesProperty ()->SetColor(CLR["salmon"].C);
00111 _rep -> SetOrigin (x0,y0,z0);
00112 _rep -> SetNormal (nx,ny,nz);
00113 _update_cback -> SetPlane (_plane);
00114 _widget -> SetInteractor (Win.GetIRen());
00115 _widget -> SetRepresentation (_rep);;
00116 _widget -> AddObserver (vtkCommand::InteractionEvent, _update_cback);
00117
00118
00119 }
00120
00121 inline UGridClipper::~UGridClipper()
00122 {
00123 _plane -> Delete();
00124 _clipper -> Delete();
00125 _mapper -> Delete();
00126 _actor -> Delete();
00127 _update_cback -> Delete();
00128 _widget -> Delete();
00129 }
00130
00131 inline void UGridClipper::AddActorsTo(VTKWin & Win)
00132 {
00133 Win.AddActor(_actor);
00134 }
00135
00136 inline void UGridClipper::DelActorsFrom(VTKWin & Win)
00137 {
00138 Win.DelActor(_actor);
00139 }
00140
00141 #endif // MECHSYS_UGRIDCLIPPER_H
00142
00143