1 #include "manualViewBaseContour.h"
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
8 manualViewBaseContour::manualViewBaseContour()
13 _wxvtkbaseview = NULL;
15 _posibleSelected = false;
16 _viewControlPoints = false;
19 _contourVtkActor = NULL;
22 _sizePointsContour = 100;
35 _coulorSelection_r = 0;
36 _coulorSelection_g = 1;
37 _coulorSelection_b = 0;
42 // ----------------------------------------------------------------------------
43 manualViewBaseContour::~manualViewBaseContour()
45 int i,size=_lstViewPoints.size();
46 for (i=0;i<size; i++){
47 delete _lstViewPoints[i];
49 _lstViewPoints.clear();
51 // ----------------------------------------------------------------------------
54 int manualViewBaseContour::GetType() // virtual
57 //int manualViewBaseContour::GetType() 0;
58 //int manualViewContour::GetType() 1;
59 //int manualViewRoi::GetType() 2;
60 //int manualViewCircle::GetType() 3;
61 //int manualViewStar::GetType() 4;
62 //int manualViewLine::GetType() 6;
63 //int manualViewPoints::GetType() 7;
68 // ----------------------------------------------------------------------------
70 void manualViewBaseContour::Save(FILE *pFile)
72 fprintf(pFile,"TypeView %d\n", GetType() );
75 // ----------------------------------------------------------------------------
76 void manualViewBaseContour::Open(FILE *pFile)
80 // ----------------------------------------------------------------------------
81 void manualViewBaseContour :: AddCompleteContourActor( bool ifControlPoints )
83 _viewControlPoints = ifControlPoints;
84 /*vtkRenderer * theRenderer = */ _wxvtkbaseview->GetRenderer(); // JPRx ??
89 //Adding each control point
95 // ---------------------------------------------------------------------------
97 void manualViewBaseContour :: RemoveCompleteContourActor()
99 /*vtkRenderer * theRenderer =*/ _wxvtkbaseview->GetRenderer(); // JPRx ??
100 //Removing the spline
104 //Removing each point
105 RemoveControlPoints();
109 // ---------------------------------------------------------------------------
110 manualViewBaseContour * manualViewBaseContour :: Clone( )//virtual
112 manualViewBaseContour * clone = new manualViewBaseContour();
113 CopyAttributesTo(clone);
118 // ---------------------------------------------------------------------------
120 void manualViewBaseContour::CopyAttributesTo( manualViewBaseContour * cloneObject)
123 //XXXX::CopyAttributesTo(cloneObject);
125 cloneObject-> SetWxVtkBaseView( this->_wxvtkbaseview );
126 cloneObject-> SetSelected( this->GetSelected() );
127 cloneObject-> SetPosibleSelected( this->GetPosibleSelected() );
128 cloneObject-> SetIfViewControlPoints( this->GetIfViewControlPoints() );
129 cloneObject-> SetRange( this->GetRange() );
130 cloneObject-> SetZ( this->GetZ() );
131 cloneObject-> SetSpacing( _spc );
132 cloneObject-> SetColorNormalContour( _coulorNormal_r, _coulorNormal_g, _coulorNormal_b );
133 cloneObject-> SetColorEditContour( _coulorEdit_r, _coulorEdit_g, _coulorEdit_b );
134 cloneObject-> SetColorSelectContour( _coulorSelection_r, _coulorSelection_g, _coulorSelection_b );
136 int i, size = _lstViewPoints.size();
137 for ( i=0; i<size; i++ )
139 cloneObject->AddPoint( );
143 // ----------------------------------------------------------------------------
144 void manualViewBaseContour :: AddSplineActor()
146 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
147 if (_contourVtkActor!=NULL)
148 theRenderer->AddActor( _contourVtkActor );
150 // ----------------------------------------------------------------------------
151 void manualViewBaseContour :: RemoveSplineActor() // virtual
153 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
154 if (_contourVtkActor!=NULL)
155 theRenderer->RemoveActor( _contourVtkActor );
157 // ----------------------------------------------------------------------------
158 void manualViewBaseContour :: RemoveControlPoints()
160 if (_wxvtkbaseview!=NULL){
161 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
162 int i,size=_lstViewPoints.size();
163 for (i=0;i<size; i++)
165 vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
166 theRenderer->RemoveActor( pointActor );
169 SetIfViewControlPoints( false );
171 // ----------------------------------------------------------------------------
172 void manualViewBaseContour::AddControlPoints()
174 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
175 SetIfViewControlPoints( true );
176 if( _viewControlPoints )
178 int i,size=_lstViewPoints.size();
179 for (i=0;i<size; i++)
181 vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
182 theRenderer->AddActor( pointActor );
186 // ----------------------------------------------------------------------------
187 void manualViewBaseContour::AddTextActor()
189 _wxvtkbaseview->GetRenderer()->AddActor2D( _textActor );
191 // ----------------------------------------------------------------------------
192 void manualViewBaseContour::RemoveTextActor()
194 _wxvtkbaseview->GetRenderer()->RemoveActor2D( _textActor );
196 // ----------------------------------------------------------------------------
197 void manualViewBaseContour::DeleteVtkObjects()
199 if ( _contourVtkActor != NULL ) { _contourVtkActor -> Delete(); }
200 if ( _bboxMapper != NULL ) { _bboxMapper -> Delete(); }
201 if ( _pts != NULL ) { _pts -> Delete(); }
202 if ( _pd != NULL ) { _pd -> Delete(); }
203 _contourVtkActor = NULL;
210 // ----------------------------------------------------------------------------
211 void manualViewBaseContour::SetWidthLine(double width)
214 this->UpdateColorActor();
216 // for the control points
217 int id, size = _lstViewPoints.size();
218 for( id=0; id<size; id++)
220 this->_lstViewPoints[id]->SetWidthLine(_widthline);
225 // ----------------------------------------------------------------------------
226 double manualViewBaseContour::GetWidthLine()
231 // ----------------------------------------------------------------------------
232 void manualViewBaseContour::ConstructVTKObjects()
236 //JSTG 29-02-08 -----------------------------------------------
237 //int i , nps = _sizePointsContour;
239 int nps = _manContModel->GetNumberOfPointsSpline();
240 //-------------------------------------------------------------
243 _pts = vtkPoints::New();
244 _pts->SetNumberOfPoints(nps);
245 for (i=0 ; i<nps ; i++){
246 _pts->SetPoint(i, 0 , 0 , 0 );
248 // This is for the boundaring inicialisation
251 //_pts->SetPoint(0, 0 , 0 , -1000 );
252 //_pts->SetPoint(1, 0 , 0 , 1000 );
253 _pts->SetPoint(0, -1000 , -1000 , -1000 );
254 _pts->SetPoint(1, 1000 , 1000 , 1000 );
256 vtkCellArray *lines = vtkCellArray::New();
257 lines->InsertNextCell( nps /* +1 */ );
258 for ( i=0 ; i<nps+1 ; i++ ){
259 lines->InsertCellPoint(i % nps );
261 _pd = vtkPolyData::New();
262 _pd->SetPoints( _pts );
263 _pd->SetLines( lines );
264 lines->Delete(); //do not delete lines ??
266 _contourVtkActor = vtkActor::New();
267 _bboxMapper = vtkPolyDataMapper::New();
268 _bboxMapper->ScalarVisibilityOff( );
271 _bboxMapper->SetInput(_pd);
272 _bboxMapper->ImmediateModeRenderingOn();
273 _contourVtkActor->SetMapper(_bboxMapper);
274 _contourVtkActor->GetProperty()->BackfaceCullingOff();
279 _pd->ComputeBounds();
286 void manualViewBaseContour::InitTextActor()
289 _textActor = vtkTextActor::New();
290 // _textActor->SetDisplayPosition(200, 200);
291 _textActor->SetInput("00");
292 // Set coordinates to match the old vtkScaledTextActor default value
293 // _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
294 // _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
295 _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
296 // _textActor->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
298 vtkTextProperty *tprop = _textActor->GetTextProperty();
299 tprop->SetFontSize(14);
300 tprop->SetFontFamilyToArial();
301 tprop->SetColor(0, 0, 1);
304 // ----------------------------------------------------------------------------
305 void manualViewBaseContour::CreateNewContour()
307 ConstructVTKObjects();
309 _wxvtkbaseview->GetRenderer()->AddActor( _contourVtkActor );
310 _wxvtkbaseview->GetRenderer()->AddActor2D(_textActor);*/
311 AddCompleteContourActor();
313 // ----------------------------------------------------------------------------
314 void manualViewBaseContour::UpdateViewPoint(int id) // virtual
316 manualPoint *mp = _manContModel->GetManualPoint(id);
319 double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
320 // wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
321 // wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
323 _lstViewPoints[id]->SetPositionXY( XX , YY ,_range, ZZ );
326 // ----------------------------------------------------------------------------
327 void manualViewBaseContour::UpdateViewPoints()
329 int id, size = _lstViewPoints.size();
330 for( id=0; id<size; id++)
332 UpdateViewPoint( id );
336 // ----------------------------------------------------------------------------
337 void manualViewBaseContour::AddPoint()
339 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
342 // ----------------------------------------------------------------------------
343 void manualViewBaseContour::AddPoint( manualViewPoint * manualViewPoint )
345 _lstViewPoints.push_back( manualViewPoint );
348 manualViewPoint->SetSpacing(_spc);
350 vtkActor *actor = manualViewPoint->CreateVtkPointActor();
351 _wxvtkbaseview->GetRenderer()->AddActor( actor );
354 // ----------------------------------------------------------------------------
355 void manualViewBaseContour::InsertPoint(int id)
357 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
360 mvp->SetSpacing(_spc);
362 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
363 _lstViewPoints.insert(itNum,mvp);
364 _wxvtkbaseview->GetRenderer()->AddActor( mvp->CreateVtkPointActor() );
366 // ----------------------------------------------------------------------------
367 void manualViewBaseContour::DeleteContour()
369 RemoveCompleteContourActor();
370 /*if (_contourVtkActor!=NULL){
371 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
374 int i,size=_lstViewPoints.size();
375 for (i=0;i<size;i++){
376 manualViewBaseContour::DeletePoint(0);
380 // ----------------------------------------------------------------------------
381 void manualViewBaseContour::DeletePoint(int id) // virtual
383 int size=_lstViewPoints.size();
384 if ( (id>=0) && (id<size) ){
385 manualViewPoint *mvp =_lstViewPoints[id];
387 // _handlePicker->DeletePickList(mvp->GetVtkActor());
388 _wxvtkbaseview->GetRenderer()->RemoveActor( mvp->GetVtkActor() );
389 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
390 _lstViewPoints.erase(itNum);
395 // ----------------------------------------------------------------------------
396 void manualViewBaseContour::DeletePoint(int x, int y, int z)
398 int id=GetIdPoint(x,y,z);
403 // ----------------------------------------------------------------------------
404 void manualViewBaseContour::SetSelected(bool selected)
408 // ----------------------------------------------------------------------------
409 void manualViewBaseContour::SetPosibleSelected(bool posibleSelected)
411 _posibleSelected=posibleSelected;
413 // ----------------------------------------------------------------------------
414 bool manualViewBaseContour::GetEditable()
418 // ----------------------------------------------------------------------------
419 void manualViewBaseContour::SetEditable( bool * condition )
421 _editable = condition;
423 // ----------------------------------------------------------------------------
424 bool manualViewBaseContour::GetSelected()
428 // ----------------------------------------------------------------------------
429 bool manualViewBaseContour::GetPosibleSelected()
431 return _posibleSelected;
433 // ----------------------------------------------------------------------------
434 void manualViewBaseContour::DeleteSelectedPoints()
436 int i,size=_lstViewPoints.size();
437 for (i=size-1;i>=0;i--){
438 if (_lstViewPoints[i]->GetSelected()==true){
444 // ----------------------------------------------------------------------------
445 void manualViewBaseContour::SelectPoint(int i, bool select)
447 _lstViewPoints[i]->SetSelected(select);
449 // ----------------------------------------------------------------------------
450 void manualViewBaseContour::SelectLstPoints()
454 // ----------------------------------------------------------------------------
455 void manualViewBaseContour::SelectAllPoints(bool select)
457 int i,size=_lstViewPoints.size();
458 for (i=0;i<size;i++){
459 SelectPoint(i,select);
462 //-----------------------------------------------------------------------------
463 void manualViewBaseContour:: SetIfViewControlPoints(bool ifShow)
465 _viewControlPoints = ifShow;
467 // ----------------------------------------------------------------------------
468 bool manualViewBaseContour:: GetIfViewControlPoints()
470 return _viewControlPoints;
473 // ----------------------------------------------------------------------------
474 void manualViewBaseContour::SetPointPosibleSelected(int id,bool select)
476 _lstViewPoints[id]->SetPosibleSelected(select);
478 // ----------------------------------------------------------------------------
479 void manualViewBaseContour::SetPointSelected(int id,bool select)
481 _lstViewPoints[id]->SetSelected(select);
483 // ----------------------------------------------------------------------------
484 void manualViewBaseContour::SelectAllPossibleSelected(bool select)
486 int i,size=_lstViewPoints.size();
487 for (i=0;i<size;i++){
488 SetPointPosibleSelected(i,select);
491 // ----------------------------------------------------------------------------
492 int manualViewBaseContour::SelectPosiblePoint(int x, int y, int z) // virtual
494 SelectAllPossibleSelected(false);
496 int id = GetIdPoint(x,y,z);
499 SetPointPosibleSelected(id,true);
503 // ----------------------------------------------------------------------------
504 bool manualViewBaseContour::SelectPosibleContour(int x, int y, int z)
507 SetPosibleSelected(result);
508 int id = GetIdPoint(x,y,z);
510 if( !GetEditable() && !_selected && id!= -1)
513 _posibleSelected=true;
517 if ( (GetEditable()==true) && (id==-1 ) && (this->_lstViewPoints.size()>=2) )
519 if (ifTouchContour(x,y,z)==true)
522 SetPosibleSelected(result);
526 if (GetEditable()==false)
528 if (ifTouchContour(x,y,z)==true)
531 SetPosibleSelected(result);
538 // ----------------------------------------------------------------------------
539 bool manualViewBaseContour::ifTouchContour(int x,int y, int z) // virtual
543 // ----------------------------------------------------------------------------
544 void manualViewBaseContour::UnSelectPoint(int i){
545 _lstViewPoints[i]->SetSelected(false);
548 // ----------------------------------------------------------------------------
549 void manualViewBaseContour::UnSelectLstPoints(){
552 // ----------------------------------------------------------------------------
553 void manualViewBaseContour::UnSelectAllPoints(){
554 int i,size=_lstViewPoints.size();
555 for (i=0;i<size;i++){
560 // ----------------------------------------------------------------------------
561 void manualViewBaseContour::SetModel(manualBaseModel *manContModel){
562 _manContModel=manContModel;
564 // ----------------------------------------------------------------------------
565 void manualViewBaseContour::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview){
566 _wxvtkbaseview = wxvtkbaseview;
568 // ----------------------------------------------------------------------------
569 void manualViewBaseContour::RefreshContour() // Virtual
572 // ----------------------------------------------------------------------------
573 double* manualViewBaseContour::GetVectorPointsXManualContour(){
575 int i,size = _sizePointsContour;
576 double *vx = (double*)malloc(sizeof(double)*size);
577 for (i=0;i<size;i++){
578 _pts->GetPoint(i,pp);
583 // ----------------------------------------------------------------------------
584 double* manualViewBaseContour::GetVectorPointsYManualContour()
587 int i,size = _sizePointsContour;
588 double *vy = (double*)malloc(sizeof(double)*size);
589 for (i=0;i<size;i++){
590 _pts->GetPoint(i,pp);
595 // ----------------------------------------------------------------------------
596 double* manualViewBaseContour::GetVectorPointsZManualContour()
599 int i,size = _sizePointsContour;
600 double *vz = (double*)malloc(sizeof(double)*size);
601 for (i=0;i<size;i++){
602 _pts->GetPoint(i,pp);
607 // ----------------------------------------------------------------------------
608 void manualViewBaseContour::Refresh() // virtual
610 if (_contourVtkActor!=NULL){
613 int i,size=_lstViewPoints.size();
614 for (i=0;i<size;i++){
616 _lstViewPoints[i]->UpdateColorActor();
620 if (_show_text==true)
625 vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
628 _wxvtkbaseview->GetRenWin()->Render();
629 printf("EED %p How to optimize manualViewBaseContour::Refresh() \n",this);
633 // ----------------------------------------------------------------------------
634 void manualViewBaseContour::RefreshText() // virtual
636 if( _textActor!=NULL)
637 _textActor -> SetInput("00");
639 // ----------------------------------------------------------------------------
640 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
646 // ----------------------------------------------------------------------------
647 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
653 // ----------------------------------------------------------------------------
654 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
660 // ----------------------------------------------------------------------------
661 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
667 // ----------------------------------------------------------------------------
668 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
670 _coulorSelection_r = r;
671 _coulorSelection_g = g;
672 _coulorSelection_b = b;
674 // ----------------------------------------------------------------------------
675 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
677 r = _coulorSelection_r;
678 g = _coulorSelection_g;
679 b = _coulorSelection_b;
681 // ----------------------------------------------------------------------------
682 void manualViewBaseContour::UpdateColorActor()
684 if (_contourVtkActor!=NULL)
686 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
687 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
688 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
690 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
694 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
698 // ----------------------------------------------------------------------------
699 int manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
702 if (_manContModel!=NULL){
706 TransfromCoordViewWorld(xx,yy,zz);
707 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
712 // ----------------------------------------------------------------------------
715 int manualViewBaseContour::GetNumberOfPoints()
717 return _lstViewPoints.size();
720 // ----------------------------------------------------------------------------
722 //JSTG 25-02-08 ---------------------------------------------------------------
723 /*int manualViewBaseContour::GetNumberOfPointsSpline()
725 return _sizePointsContour;
727 //----------------------------------------------------------------------------
729 //JSTG 25-02-08 ---------------------------------------------------------------
730 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
732 _sizePointsContour = size;
734 //----------------------------------------------------------------------------
736 void manualViewBaseContour::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // Virtual
738 _wxvtkbaseview->TransFromCoordScreenToWorld(X, Y, Z,false, type);
743 // wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
744 // wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z);
747 // ----------------------------------------------------------------------------
748 void manualViewBaseContour::SetRange(double range)
752 // ----------------------------------------------------------------------------
753 double manualViewBaseContour::GetRange()
757 // ----------------------------------------------------------------------------
758 void manualViewBaseContour::SetZ(int z)
762 // ----------------------------------------------------------------------------
763 int manualViewBaseContour::GetZ()
768 // ----------------------------------------------------------------------------
769 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
773 // ----------------------------------------------------------------------------
774 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
777 // ----------------------------------------------------------------------------
778 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
782 // ----------------------------------------------------------------------------
783 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
788 int size=_manContModel->GetSizeLstPoints();
793 bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
799 for( i = 0; i < size; i++ )
801 mp=_manContModel->GetManualPoint(i);
853 // ----------------------------------------------------------------------------
854 void manualViewBaseContour::ClearContour()
856 if (_contourVtkActor!=NULL){
857 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
860 int i,size=_lstViewPoints.size();
861 for (i=0;i<size;i++){
866 // ----------------------------------------------------------------------------
867 void manualViewBaseContour::ClearPoint(int id)
871 // ----------------------------------------------------------------------------
872 void manualViewBaseContour::SetVisible(bool ok)
882 int i,size=_lstViewPoints.size();
883 for (i=0;i<size;i++){
884 actor = _lstViewPoints[i]->GetVtkActor();
885 actor->GetProperty()->SetOpacity( opacity );
887 _contourVtkActor->GetProperty()->SetOpacity( opacity );
888 _textActor->GetProperty()->SetOpacity( opacity );
889 _textActor->SetInput("00");
892 // ----------------------------------------------------------------------------
893 void manualViewBaseContour::SetShowText(bool ok)
896 if (_show_text==false)
898 _textActor->SetInput("00");
901 // ----------------------------------------------------------------------------
902 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
904 return this->_wxvtkbaseview;
906 // ----------------------------------------------------------------------------
907 void manualViewBaseContour::GetSpacing(double spc[3])
913 // ----------------------------------------------------------------------------
914 void manualViewBaseContour::SetSpacing(double spc[3])