00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef VTKWRAP_CUTCLIP_H
00022 #define VTKWRAP_CUTCLIP_H
00023
00024 #include <vector>
00025
00026
00027 #include "vtkPlane.h"
00028 #include "vtkClipPolyData.h"
00029 #include "vtkPolyDataMapper.h"
00030 #include "vtkProperty.h"
00031 #include "vtkActor.h"
00032 #include "vtkCutter.h"
00033 #include "vtkStripper.h"
00034 #include "vtkPolyData.h"
00035 #include "vtkTriangleFilter.h"
00036
00037
00038 #include "util/string.h"
00039 #include "vtkwrap/colors.h"
00040 #include "vtkwrap/vtkwin.h"
00041
00042 class CutClip
00043 {
00044 friend std::ostream & operator<< (std::ostream & os, CutClip const & cc);
00045 public:
00046
00047 CutClip();
00048 ~CutClip();
00049
00050
00051 CutClip & SetClipColor (String const & Color ) { _clip_clr =Color ; return (*this); }
00052 CutClip & SetClipOpac (double Opacity) { _clip_opac =Opacity; return (*this); }
00053 CutClip & SetBackColor (String const & Color ) { _back_clr =Color ; return (*this); }
00054 CutClip & SetCutColor (String const & Color ) { _cut_clr =Color ; return (*this); }
00055 CutClip & SetCutOpac (double Opacity) { _cut_opac =Opacity; return (*this); }
00056 CutClip & SetCPartColor (String const & Color ) { _cpart_clr =Color ; return (*this); }
00057 CutClip & SetCPartOpac (double Opacity) { _cpart_opac=Opacity; return (*this); }
00058 CutClip & SetCPartWire (bool UseWire) { _cpart_wire=UseWire; return (*this); }
00059
00060
00061 void Generate (double x0, double y0, double z0, double nx, double ny, double nz, vtkAlgorithmOutput * OutPort);
00062
00063
00064 vtkActor * GetClipActor () { return _clip_actor; }
00065 vtkActor * GetCutActor () { return _cut_actor; }
00066 vtkActor * GetCPartActor() { return _cpart_actor; }
00067
00068
00069 void AddActorsTo (VTKWin & Win);
00070 void DelActorsFrom (VTKWin & Win);
00071
00072 private:
00073
00074 String _clip_clr;
00075 double _clip_opac;
00076 String _back_clr;
00077 String _cut_clr;
00078 double _cut_opac;
00079 String _cpart_clr;
00080 double _cpart_opac;
00081 bool _cpart_wire;
00082
00083 vtkPlane * _plane;
00084 vtkClipPolyData * _clipper;
00085 vtkPolyDataMapper * _clip_mapper;
00086 vtkProperty * _back_prop;
00087 vtkActor * _clip_actor;
00088
00089 vtkCutter * _cut_edges;
00090 vtkStripper * _cut_strips;
00091 vtkPolyData * _cut_poly;
00092 vtkTriangleFilter * _cut_triangles;
00093 vtkPolyDataMapper * _cut_mapper;
00094 vtkActor * _cut_actor;
00095
00096 vtkPolyDataMapper * _cpart_mapper;
00097 vtkActor * _cpart_actor;
00098
00099
00100 void _clean_up ();
00101 };
00102
00103 std::ostream & operator<< (std::ostream & os, CutClip const & cc)
00104 {
00105 cc._clipper->Print(os);
00106 return os;
00107 }
00108
00109
00111
00112
00113 inline CutClip::CutClip()
00114 : _clip_clr (String("peacock")),
00115 _clip_opac (1.0),
00116 _back_clr (String("green")),
00117 _cut_clr (String("red")),
00118 _cut_opac (1.0),
00119 _cpart_clr (String("yellow")),
00120 _cpart_opac (1.0),
00121 _cpart_wire (false),
00122 _plane (NULL),
00123 _clipper (NULL),
00124 _clip_mapper (NULL),
00125 _back_prop (NULL),
00126 _clip_actor (NULL),
00127 _cut_edges (NULL),
00128 _cut_strips (NULL),
00129 _cut_poly (NULL),
00130 _cut_triangles (NULL),
00131 _cut_mapper (NULL),
00132 _cut_actor (NULL),
00133 _cpart_mapper (NULL),
00134 _cpart_actor (NULL)
00135 {
00136 }
00137
00138 inline CutClip::~CutClip()
00139 {
00140 _clean_up();
00141 }
00142
00143 inline void CutClip::Generate (double x0, double y0, double z0, double nx, double ny, double nz, vtkAlgorithmOutput * OutPort)
00144 {
00145
00146 _clean_up();
00147
00148
00149 _plane = vtkPlane :: New();
00150 _clipper = vtkClipPolyData :: New();
00151 _clip_mapper = vtkPolyDataMapper :: New();
00152 _back_prop = vtkProperty :: New();
00153 _clip_actor = vtkActor :: New();
00154 _plane -> SetOrigin(x0, y0, z0);
00155 _plane -> SetNormal(nx, ny, nz);
00156 _clipper -> SetInputConnection (OutPort);
00157 _clipper -> SetClipFunction (_plane);
00158 _clipper -> GenerateClipScalarsOn ();
00159 _clipper -> GenerateClippedOutputOn ();
00160 _clipper -> SetValue (0);
00161 _clip_mapper -> SetInputConnection (_clipper->GetOutputPort());
00162 _clip_mapper -> ScalarVisibilityOff ();
00163 _back_prop -> SetDiffuseColor (CLR[_back_clr.GetSTL()].C);
00164 _clip_actor -> SetMapper (_clip_mapper);
00165 _clip_actor -> GetProperty ()->SetColor(CLR[_clip_clr.GetSTL()].C);
00166 _clip_actor -> GetProperty ()->SetOpacity(_clip_opac);
00167 _clip_actor -> SetBackfaceProperty (_back_prop);
00168
00169
00170 _cut_edges = vtkCutter :: New();
00171 _cut_strips = vtkStripper :: New();
00172 _cut_poly = vtkPolyData :: New();
00173 _cut_triangles = vtkTriangleFilter :: New();
00174 _cut_mapper = vtkPolyDataMapper :: New();
00175 _cut_actor = vtkActor :: New();
00176 _cut_edges -> SetInputConnection (OutPort);
00177 _cut_edges -> SetCutFunction (_plane);
00178 _cut_edges -> GenerateCutScalarsOn ();
00179 _cut_edges -> SetValue (0, 0);
00180 _cut_strips -> SetInputConnection (_cut_edges->GetOutputPort());
00181 _cut_strips -> Update ();
00182 _cut_poly -> SetPoints (_cut_strips->GetOutput()->GetPoints());
00183 _cut_poly -> SetPolys (_cut_strips->GetOutput()->GetLines ());
00184 _cut_triangles -> SetInput (_cut_poly);
00185 _cut_mapper -> SetInput (_cut_poly);
00186 _cut_mapper -> SetInputConnection (_cut_triangles->GetOutputPort());
00187 _cut_actor -> SetMapper (_cut_mapper);
00188 _cut_actor -> GetProperty ()->SetColor(CLR[_cut_clr.GetSTL()].C);
00189 _cut_actor -> GetProperty ()->SetOpacity(_cut_opac);
00190
00191
00192 _cpart_mapper = vtkPolyDataMapper ::New();
00193 _cpart_actor = vtkActor ::New();
00194 _cpart_mapper -> SetInput (_clipper->GetClippedOutput());
00195 _cpart_mapper -> ScalarVisibilityOff ();
00196 _cpart_actor -> SetMapper (_cpart_mapper);
00197 _cpart_actor -> GetProperty ()->SetColor(CLR[_cpart_clr.GetSTL()].C);
00198 _cpart_actor -> GetProperty ()->SetOpacity(_cpart_opac);
00199 if (_cpart_wire)
00200 {
00201 _cpart_actor->GetProperty()->SetRepresentationToWireframe();
00202 }
00203
00204 _clip_mapper ->SetResolveCoincidentTopologyPolygonOffsetParameters(0,1);
00205 _clip_mapper ->SetResolveCoincidentTopologyToPolygonOffset();
00206 _cut_mapper ->SetResolveCoincidentTopologyPolygonOffsetParameters(1,1);
00207 _cut_mapper ->SetResolveCoincidentTopologyToPolygonOffset();
00208 _cpart_mapper->SetResolveCoincidentTopologyPolygonOffsetParameters(1,1);
00209 _cpart_mapper->SetResolveCoincidentTopologyToPolygonOffset();
00210
00211 }
00212
00213 inline void CutClip::AddActorsTo(VTKWin & Win)
00214 {
00215 Win.AddActor(_clip_actor );
00216 Win.AddActor(_cut_actor );
00217 Win.AddActor(_cpart_actor);
00218 }
00219
00220 inline void CutClip::DelActorsFrom(VTKWin & Win)
00221 {
00222 Win.DelActor(_clip_actor );
00223 Win.DelActor(_cut_actor );
00224 Win.DelActor(_cpart_actor);
00225 }
00226
00227 inline void CutClip::_clean_up()
00228 {
00229
00230 if (_plane !=NULL) _plane -> Delete();
00231 if (_clipper !=NULL) _clipper -> Delete();
00232 if (_clip_mapper!=NULL) _clip_mapper -> Delete();
00233 if (_back_prop !=NULL) _back_prop -> Delete();
00234 if (_clip_actor !=NULL) _clip_actor -> Delete();
00235
00236 if (_cut_edges !=NULL) _cut_edges -> Delete();
00237 if (_cut_strips !=NULL) _cut_strips -> Delete();
00238 if (_cut_poly !=NULL) _cut_poly -> Delete();
00239 if (_cut_triangles!=NULL) _cut_triangles -> Delete();
00240 if (_cut_mapper !=NULL) _cut_mapper -> Delete();
00241 if (_cut_actor !=NULL) _cut_actor -> Delete();
00242
00243 if (_cpart_mapper!=NULL) _cpart_mapper -> Delete();
00244 if (_cpart_actor !=NULL) _cpart_actor -> Delete();
00245 }
00246
00247 #endif // VTKWRAP_CUTCLIP_H
00248
00249