ugridclipper.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
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 // VTK
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 // MechSys
00046 #include "vtkwrap/vtkwin.h"
00047 #include "vtkwrap/colors.h"
00048 #include "vtkwrap/updateplanecallback.h"
00049 
00050 class UGridClipper
00051 {
00052 public:
00053     // Constructor
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     // Destructor
00059     ~UGridClipper();
00060     
00061     // Methods
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     // Data
00069     vtkPlane                       * _plane;
00070     vtkClipDataSet                 * _clipper;
00071     vtkDataSetMapper               * _mapper;
00072     vtkActor                       * _actor;
00073     UpdatePlaneCallBack            * _update_cback;
00074     vtkImplicitPlaneWidget2        * _widget;
00075     vtkImplicitPlaneRepresentation * _rep;
00076     
00077 }; // class UGridClipper
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     // Clipper
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     // Widget
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     //_widget       -> AddObserver    (vtkCommand::EnableEvent     , _update_cback);
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 // vim:fdm=marker

Generated on Wed Jan 24 15:56:28 2007 for MechSys by  doxygen 1.4.7