00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_UGRIDLABELS_H
00023 #define MECHSYS_UGRIDLABELS_H
00024
00025
00026 #include "vtkRenderer.h"
00027 #include "vtkUnstructuredGrid.h"
00028 #include "vtkIdFilter.h"
00029 #include "vtkCellCenters.h"
00030 #include "vtkSelectVisiblePoints.h"
00031 #include "vtkBorderRepresentation.h"
00032 #include "vtkBorderWidget.h"
00033 #include "vtkLabeledDataMapper.h"
00034 #include "vtkTextProperty.h"
00035 #include "vtkActor2D.h"
00036 #include "vtkProperty.h"
00037 #include "vtkProperty2D.h"
00038
00039
00040 #include "vtkwrap/selectcallback.h"
00041 #include "vtkwrap/colors.h"
00042 #include "vtkwrap/vtkwin.h"
00043
00044 class UGridLabels
00045 {
00046 public:
00047
00048 UGridLabels(VTKWin & Win, vtkUnstructuredGrid * Dataset);
00049 UGridLabels(VTKWin & Win, vtkAlgorithmOutput * OutputPort);
00050
00051
00052 ~UGridLabels();
00053
00054
00055 void AddActorsTo (VTKWin & Win);
00056 void DelActorsFrom (VTKWin & Win);
00057 void EnableWidget (int Enable=1) { _wid->SetEnabled(Enable); }
00058
00059 private:
00060
00061 vtkIdFilter * _ids;
00062 vtkCellCenters * _cen;
00063 vtkSelectVisiblePoints * _nodes_vis_pts;
00064 vtkSelectVisiblePoints * _cells_vis_pts;
00065 vtkBorderRepresentation * _rep;
00066 vtkBorderWidget * _wid;
00067 SelectCallBack * _sel_cback;
00068 vtkTextProperty * _tnodes;
00069 vtkTextProperty * _tcells;
00070 vtkLabeledDataMapper * _nodes_ldm;
00071 vtkLabeledDataMapper * _cells_ldm;
00072 vtkActor2D * _lnodes_actor;
00073 vtkActor2D * _lcells_actor;
00074
00075
00076 void _init_for_given_ids_and_cen(VTKWin & Win);
00077
00078 };
00079
00080 inline UGridLabels::UGridLabels(VTKWin & Win, vtkUnstructuredGrid * Dataset)
00081 {
00082
00083 _ids = vtkIdFilter ::New();
00084 _cen = vtkCellCenters ::New();
00085 _ids -> SetInput (Dataset);
00086 _ids -> PointIdsOn ();
00087 _ids -> CellIdsOn ();
00088 _ids -> FieldDataOn ();
00089 _cen -> SetInputConnection (_ids->GetOutputPort());
00090
00091
00092 _init_for_given_ids_and_cen(Win);
00093
00094 }
00095
00096 inline UGridLabels::UGridLabels(VTKWin & Win, vtkAlgorithmOutput * OutputPort)
00097 {
00098
00099 _ids = vtkIdFilter ::New();
00100 _cen = vtkCellCenters ::New();
00101 _ids -> SetInputConnection (OutputPort);
00102 _ids -> PointIdsOn ();
00103 _ids -> CellIdsOn ();
00104 _ids -> FieldDataOn ();
00105 _cen -> SetInputConnection (_ids->GetOutputPort());
00106
00107
00108 _init_for_given_ids_and_cen(Win);
00109
00110 }
00111
00112 inline void UGridLabels::_init_for_given_ids_and_cen(VTKWin & Win)
00113 {
00114
00115 _nodes_vis_pts = vtkSelectVisiblePoints::New();
00116 _nodes_vis_pts -> SetInputConnection (_ids->GetOutputPort());
00117 _nodes_vis_pts -> SetRenderer (Win.GetRen());
00118 _nodes_vis_pts -> SelectionWindowOn ();
00119
00120
00121 _cells_vis_pts = vtkSelectVisiblePoints::New();
00122 _cells_vis_pts -> SetInputConnection (_cen->GetOutputPort());
00123 _cells_vis_pts -> SetRenderer (Win.GetRen());
00124 _cells_vis_pts -> SelectionWindowOn ();
00125
00126
00127 _rep = vtkBorderRepresentation ::New();
00128 _wid = vtkBorderWidget ::New();
00129 _sel_cback = SelectCallBack ::New();
00130 _rep -> SetPosition (0.1,0.1);
00131 _rep -> SetPosition2 (0.8,0.8);
00132 _rep -> SetShowBorderToOn ();
00133 _rep -> GetBorderProperty ()->SetColor(CLR["blue"].C);
00134 _wid -> SetInteractor (Win.GetIRen());
00135 _wid -> SetRepresentation (_rep);
00136 _wid -> SelectableOn ();
00137 _wid -> AddObserver (vtkCommand::EnableEvent , _sel_cback);
00138 _wid -> AddObserver (vtkCommand::InteractionEvent, _sel_cback);
00139 _sel_cback -> Setup (Win.GetRen(), _rep, _nodes_vis_pts, _cells_vis_pts);
00140
00141
00142 _tnodes = vtkTextProperty::New();
00143 _tnodes -> SetFontSize (18);
00144 _tnodes -> SetFontFamilyToArial ();
00145 _tnodes -> SetJustificationToCentered ();
00146 _tnodes -> BoldOn ();
00147 _tnodes -> ItalicOn ();
00148 _tnodes -> ShadowOn ();
00149 _tnodes -> SetColor (CLR["blue"].C);
00150
00151
00152 _tcells = vtkTextProperty::New();
00153 _tcells -> SetFontSize (18);
00154 _tcells -> SetFontFamilyToArial ();
00155 _tcells -> SetJustificationToCentered ();
00156 _tcells -> BoldOn ();
00157 _tcells -> ItalicOn ();
00158 _tcells -> ShadowOn ();
00159 _tcells -> SetColor (CLR["red"].C);
00160
00161
00162 _nodes_ldm = vtkLabeledDataMapper ::New();
00163 _lnodes_actor = vtkActor2D ::New();
00164 _nodes_ldm -> SetInputConnection (_nodes_vis_pts->GetOutputPort());
00165 _nodes_ldm -> SetLabelFormat ("%g");
00166 _nodes_ldm -> SetLabelModeToLabelFieldData ();
00167 _nodes_ldm -> SetLabelTextProperty (_tnodes);
00168 _lnodes_actor -> SetMapper (_nodes_ldm);
00169
00170
00171 _cells_ldm = vtkLabeledDataMapper ::New();
00172 _lcells_actor = vtkActor2D ::New();
00173 _cells_ldm -> SetInputConnection (_cells_vis_pts->GetOutputPort());
00174 _cells_ldm -> SetLabelFormat ("%g");
00175 _cells_ldm -> SetLabelModeToLabelFieldData ();
00176 _cells_ldm -> SetLabelTextProperty (_tcells);
00177 _lcells_actor -> SetMapper (_cells_ldm);
00178 }
00179
00180 inline UGridLabels::~UGridLabels()
00181 {
00182 _ids -> Delete();
00183 _cen -> Delete();
00184 _nodes_vis_pts -> Delete();
00185 _cells_vis_pts -> Delete();
00186 _rep -> Delete();
00187 _wid -> Delete();
00188 _sel_cback -> Delete();
00189 _tnodes -> Delete();
00190 _tcells -> Delete();
00191 _nodes_ldm -> Delete();
00192 _cells_ldm -> Delete();
00193 _lnodes_actor -> Delete();
00194 _lcells_actor -> Delete();
00195 }
00196
00197 inline void UGridLabels::AddActorsTo(VTKWin & Win)
00198 {
00199 Win.AddActor2D(_lnodes_actor);
00200 Win.AddActor2D(_lcells_actor);
00201 }
00202
00203 inline void UGridLabels::DelActorsFrom(VTKWin & Win)
00204 {
00205 Win.DelActor2D(_lnodes_actor);
00206 Win.DelActor2D(_lcells_actor);
00207 }
00208
00209 #endif // MECHSYS_UGRIDLABELS_H
00210
00211