vtkGBlackBoxView.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 Program:   bbtk
00003 Module:    $RCSfile: vtkGBlackBoxView.cxx,v $
00004 Language:  C++
00005 Date:      $Date: 2012/05/23 10:54:02 $
00006 Version:   $Revision: 1.24 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and
00015 *  abiding by the rules of distribution of free software. You can  use,
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability.
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */
00030 
00037 #include "vtkGBlackBoxView.h"
00038 
00039 namespace bbtk
00040 {
00041 
00042 
00043         //=========================================================================
00044         vtkGBlackBoxView::vtkGBlackBoxView()
00045         {
00046         }
00047 
00048         //=========================================================================
00049         vtkGBlackBoxView::~vtkGBlackBoxView()
00050         {
00051         }
00052 
00053         //=========================================================================
00054     void vtkGBlackBoxView::update_X_Fin()
00055     {
00056                 double xInic, yInic,zInic,xFin, yFin,zFin;
00057                 _model->getInicPoint(xInic,yInic,zInic);
00058         double *bounds = _boxTextActor->GetBounds();
00059                 _model->getFinalPoint(xFin, yFin,zFin);
00060 
00061                 double xFin1,xFin2,xFin3;
00062                 // position referens from box name
00063                 xFin1 = xInic+(bounds[1]-bounds[0])/2 + 20;
00064         xFin2=xFin1;
00065         xFin3=xFin1;
00066         // position referens from input ports
00067         GBoxModel* gbm=(GBoxModel*)_model;
00068                 if ( gbm->getNumInputPorts()>0 )
00069                 {
00070             GPortModel* gpm = gbm->getInputPort( gbm->getNumInputPorts()-1 );
00071             double xpFin, ypFin, zpFin;
00072             gpm->getFinalPoint(xpFin, ypFin, zpFin);
00073             xFin2 = xpFin+1;
00074         }
00075         // position referens from output ports
00076                 if ( gbm->getNumOutputPorts()>0 )
00077                 {
00078             GPortModel* gpm = gbm->getOutputPort( gbm->getNumOutputPorts()-1 );
00079             double xpFin, ypFin, zpFin;
00080             gpm->getFinalPoint(xpFin, ypFin, zpFin);
00081             xFin3 = xpFin+2;
00082         }
00083         xFin=xFin1;
00084         if (xFin2>xFin) xFin=xFin2;
00085         if (xFin3>xFin) xFin=xFin3;
00086                 _model->setFinalPoint( xFin , yFin , zFin  );
00087     }
00088 
00089         //=========================================================================
00090         void vtkGBlackBoxView::update(int idController,int command)
00091         {
00092                 updateColors();
00093 
00094                 double xInic, yInic,zInic,xFin, yFin,zFin;
00095                 _model->getInicPoint(xInic,yInic,zInic);
00096 
00097                 updatePositionTextActor(xInic, yInic,zInic);
00098         update_X_Fin();
00099                 _model->getFinalPoint(xFin, yFin,zFin);
00100 
00101                 // RaC In the actual version, zInic=zFin=900
00102 
00103                 _pts->SetPoint(0, xInic, yInic, zInic );
00104                 _pts->SetPoint(1, xInic, yFin, zInic );
00105                 _pts->SetPoint(2, xFin, yFin, zFin );
00106                 _pts->SetPoint(3, xFin, yInic, zFin );
00107 
00108                 updatePorts();
00109 
00110                 _borderPolyMapper->Modified();
00111                 _fillPolyMapper->Modified();
00112                 //-----------
00113 
00114                 //-----------
00115                 setRefreshWaiting();
00116         }
00117 
00118         //=========================================================================
00119 
00120         void vtkGBlackBoxView::createVtkObjects() //virtual
00121         {
00122 
00123                 //------------
00124                 _pts                            = vtkPoints::New();
00125                 vtkCellArray *lines = vtkCellArray::New();
00126                 vtkPolyData *_pd        = vtkPolyData::New();
00127                 _borderPolyMapper       = vtkPolyDataMapper::New();
00128                 _borderObjectActor      = vtkActor::New();
00129 
00130                 _pts->SetNumberOfPoints(4);
00131 
00132                 double xInic, yInic,zInic,xFin, yFin,zFin;
00133                 _model->getInicPoint(xInic,yInic,zInic);
00134                 _model->getFinalPoint(xFin, yFin,zFin);
00135 
00136                 // RaC In the actual version, zInic=zFin=900
00137 
00138 //EED           _pts->SetPoint(0, xInic, yInic, zInic );
00139 //EED           _pts->SetPoint(1, xInic, yFin, zInic );
00140 //EED           _pts->SetPoint(2, xFin, yFin, zFin );
00141 //EED           _pts->SetPoint(3, xFin, yInic, zFin );
00142 
00143                 _pts->SetPoint(0, -1000, -1000, -1000 );
00144                 _pts->SetPoint(1, xInic, yFin, zInic );
00145                 _pts->SetPoint(2, 1000, 1000, 1000 );
00146                 _pts->SetPoint(3, xFin, yInic, zFin );
00147 
00148 
00149 
00150                 lines->InsertNextCell(5);
00151                 lines->InsertCellPoint(0);
00152                 lines->InsertCellPoint(1);
00153                 lines->InsertCellPoint(2);
00154                 lines->InsertCellPoint(3);
00155                 lines->InsertCellPoint(0);
00156 
00157                 _pd->SetPoints( _pts );
00158                 _pd->SetLines( lines );
00159 
00160                 _borderPolyMapper->SetInput(_pd);
00161                 _borderObjectActor->SetMapper(_borderPolyMapper);
00162                 _borderPolyMapper->Modified();
00163 
00164 
00166 
00167                 vtkCellArray *strip = vtkCellArray::New();
00168                 vtkPolyData *pdFill = vtkPolyData::New();
00169                 _fillPolyMapper         = vtkPolyDataMapper::New();
00170                 _fillObjectActor        = vtkActor::New();
00171 
00172                 // RaC In the actual version, zInic=zFin=900
00173 
00174                 strip->InsertNextCell(5);
00175                 strip->InsertCellPoint(0);
00176                 strip->InsertCellPoint(1);
00177                 strip->InsertCellPoint(2);
00178                 strip->InsertCellPoint(0);
00179                 strip->InsertCellPoint(3);
00180 
00181                 pdFill->SetPoints( _pts );
00182                 pdFill->SetStrips( strip );
00183 
00184                 _fillPolyMapper->SetInput(pdFill);
00185                 _fillObjectActor->SetMapper(_fillPolyMapper);
00186                 _fillPolyMapper->Modified();
00187 
00189 
00190                 //------------
00191 
00192                 _boxTextActor           = vtkTextActor3D::New();
00193                 vtkTextProperty *prop =  vtkTextProperty::New();
00194                 prop->BoldOn();
00195                 prop->SetFontFamilyToArial();
00196                 _boxTextActor->GetTextProperty()->BoldOn();
00197                 prop->SetFontSize(80);
00198                 _boxTextActor->SetTextProperty(prop);
00199         
00200         //      _boxTextActor->GetTextProperty()->SetFontSize(80);
00201                 
00202 
00203                 //------------
00204 
00205                 updatePositionTextActor( xInic,  yInic,  zInic);
00206         }
00207 
00208         //=========================================================================
00209 
00210         void vtkGBlackBoxView::addVtkActors()//virtual
00211         {
00212                 
00213                 _baseView->GetRenderer()->AddActor(_borderObjectActor);
00214                 vtkGObjectView::addVtkActors();
00215                 _baseView->GetRenderer()->AddActor(_boxTextActor);
00216         }
00217 
00218         //=========================================================================
00219 
00220         void vtkGBlackBoxView::removeVtkActors()//virtual
00221         {
00222                 _baseView->GetRenderer()->RemoveActor(_borderObjectActor);
00223                 _baseView->GetRenderer()->RemoveActor(_boxTextActor);
00224                 vtkGObjectView::removeVtkActors();
00225         }
00226 
00227         //=========================================================================
00228 
00229         void vtkGBlackBoxView::updatePositionTextActor(double xInic, double yInic, double zInic)
00230         {
00231                 std::string temp        = _model->getBBTKType();
00232                 temp+=":";
00233                 temp+=_model->getBBTKName();
00234                 _boxTextActor->SetInput(temp.c_str());
00235                 _boxTextActor->SetPosition(xInic+4,yInic-7,zInic+1);
00236                 _boxTextActor->SetScale(0.05,0.05,1);
00237         }
00238 
00239         //=========================================================================
00240 
00241         void vtkGBlackBoxView::updateColors()
00242         {
00243                 _fillObjectActor->GetProperty()->SetAmbient(0.6);
00244 
00245                 if(_state==NOTHING_HAPPENS)
00246                 {
00247                         _borderObjectActor->GetProperty()->SetLineWidth(1);
00248                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,BOXBORDER_NH_G,BOXBORDER_NH_B);
00249                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,BOXFILL_NH_G,BOXFILL_NH_B);
00250                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_NH_R,BOXTEXT_NH_G,BOXTEXT_NH_B);
00251 
00252                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
00253                         if(bbmodel->isExecutable())
00254                         {
00255                                 _borderObjectActor->GetProperty()->SetColor(BOXBORDER_NH_R,0.9,BOXBORDER_HIGHLIGHTED_B);
00256                                 _fillObjectActor->GetProperty()->SetColor(BOXFILL_NH_R,0.9,BOXFILL_HIGHLIGHTED_B);
00257                         }
00258 
00259                 }
00260                 else if(_state==HIGHLIGHTED)
00261                 {
00262                         _borderObjectActor->GetProperty()->SetLineWidth(2);
00263 
00264                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_HIGHLIGHTED_R,BOXBORDER_HIGHLIGHTED_G,BOXBORDER_HIGHLIGHTED_B);
00265                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_HIGHLIGHTED_R,BOXFILL_HIGHLIGHTED_G,BOXFILL_HIGHLIGHTED_B);
00266                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_HIGHLIGHTED_R,BOXTEXT_HIGHLIGHTED_G,BOXTEXT_HIGHLIGHTED_B);
00267                 }
00268                 else if(_state==DRAG)
00269                 {
00270                         _borderObjectActor->GetProperty()->SetLineWidth(1.2);
00271                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_DRAG_R,BOXBORDER_DRAG_G,BOXBORDER_DRAG_B);
00272                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_DRAG_R,BOXFILL_DRAG_G,BOXFILL_DRAG_B);
00273                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_DRAG_R,BOXTEXT_DRAG_G,BOXTEXT_DRAG_B);
00274                 }
00275                 else if(_state==SELECTED)
00276                 {
00277                         _borderObjectActor->GetProperty()->SetLineWidth(2);
00278                         _borderObjectActor->GetProperty()->SetColor(BOXBORDER_SELECTED_R,BOXBORDER_SELECTED_G,BOXBORDER_SELECTED_B);
00279                         _fillObjectActor->GetProperty()->SetColor(BOXFILL_SELECTED_R,BOXFILL_SELECTED_G,BOXFILL_SELECTED_B);
00280                         _boxTextActor->GetTextProperty()->SetColor(BOXTEXT_SELECTED_R,BOXTEXT_SELECTED_G,BOXTEXT_SELECTED_B);
00281                 }
00282         }
00283 
00284         //=========================================================================
00285 
00286 
00287 }  // EO namespace bbtk
00288 
00289 // EOF
00290 

Generated on Thu May 31 15:12:19 2012 for bbtkGEditor by  doxygen 1.5.7.1