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( );
270 _bboxMapper->SetInput(_pd);
271 _bboxMapper->ImmediateModeRenderingOn();
272 _contourVtkActor->SetMapper(_bboxMapper);
273 _contourVtkActor->GetProperty()->BackfaceCullingOff();
277 _pd->ComputeBounds();
282 void manualViewBaseContour::InitTextActor()
285 _textActor = vtkTextActor::New();
286 // _textActor->SetDisplayPosition(200, 200);
287 _textActor->SetInput("00");
288 // Set coordinates to match the old vtkScaledTextActor default value
289 // _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
290 // _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
291 _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
292 // _textActor->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
294 vtkTextProperty *tprop = _textActor->GetTextProperty();
295 tprop->SetFontSize(14);
296 tprop->SetFontFamilyToArial();
297 tprop->SetColor(0, 0, 1);
300 // ----------------------------------------------------------------------------
301 void manualViewBaseContour::CreateNewContour()
303 ConstructVTKObjects();
305 _wxvtkbaseview->GetRenderer()->AddActor( _contourVtkActor );
306 _wxvtkbaseview->GetRenderer()->AddActor2D(_textActor);*/
307 AddCompleteContourActor();
309 // ----------------------------------------------------------------------------
310 void manualViewBaseContour::UpdateViewPoint(int id) // virtual
312 manualPoint *mp = _manContModel->GetManualPoint(id);
315 double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
316 // wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
317 // wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
319 _lstViewPoints[id]->SetPositionXY( XX , YY ,_range, ZZ );
322 // ----------------------------------------------------------------------------
323 void manualViewBaseContour::UpdateViewPoints()
325 int id, size = _lstViewPoints.size();
326 for( id=0; id<size; id++)
328 UpdateViewPoint( id );
332 // ----------------------------------------------------------------------------
333 void manualViewBaseContour::AddPoint()
335 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
338 // ----------------------------------------------------------------------------
339 void manualViewBaseContour::AddPoint( manualViewPoint * manualViewPoint )
341 _lstViewPoints.push_back( manualViewPoint );
344 manualViewPoint->SetSpacing(_spc);
346 vtkActor *actor = manualViewPoint->CreateVtkPointActor();
347 _wxvtkbaseview->GetRenderer()->AddActor( actor );
350 // ----------------------------------------------------------------------------
351 void manualViewBaseContour::InsertPoint(int id)
353 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
356 mvp->SetSpacing(_spc);
358 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
359 _lstViewPoints.insert(itNum,mvp);
360 _wxvtkbaseview->GetRenderer()->AddActor( mvp->CreateVtkPointActor() );
362 // ----------------------------------------------------------------------------
363 void manualViewBaseContour::DeleteContour()
365 RemoveCompleteContourActor();
366 /*if (_contourVtkActor!=NULL){
367 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
370 int i,size=_lstViewPoints.size();
371 for (i=0;i<size;i++){
372 manualViewBaseContour::DeletePoint(0);
376 // ----------------------------------------------------------------------------
377 void manualViewBaseContour::DeletePoint(int id) // virtual
379 int size=_lstViewPoints.size();
380 if ( (id>=0) && (id<size) ){
381 manualViewPoint *mvp =_lstViewPoints[id];
383 // _handlePicker->DeletePickList(mvp->GetVtkActor());
384 _wxvtkbaseview->GetRenderer()->RemoveActor( mvp->GetVtkActor() );
385 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
386 _lstViewPoints.erase(itNum);
391 // ----------------------------------------------------------------------------
392 void manualViewBaseContour::DeletePoint(int x, int y, int z)
394 int id=GetIdPoint(x,y,z);
399 // ----------------------------------------------------------------------------
400 void manualViewBaseContour::SetSelected(bool selected)
404 // ----------------------------------------------------------------------------
405 void manualViewBaseContour::SetPosibleSelected(bool posibleSelected)
407 _posibleSelected=posibleSelected;
409 // ----------------------------------------------------------------------------
410 bool manualViewBaseContour::GetEditable()
414 // ----------------------------------------------------------------------------
415 void manualViewBaseContour::SetEditable( bool * condition )
417 _editable = condition;
419 // ----------------------------------------------------------------------------
420 bool manualViewBaseContour::GetSelected()
424 // ----------------------------------------------------------------------------
425 bool manualViewBaseContour::GetPosibleSelected()
427 return _posibleSelected;
429 // ----------------------------------------------------------------------------
430 void manualViewBaseContour::DeleteSelectedPoints()
432 int i,size=_lstViewPoints.size();
433 for (i=size-1;i>=0;i--){
434 if (_lstViewPoints[i]->GetSelected()==true){
440 // ----------------------------------------------------------------------------
441 void manualViewBaseContour::SelectPoint(int i, bool select)
443 _lstViewPoints[i]->SetSelected(select);
445 // ----------------------------------------------------------------------------
446 void manualViewBaseContour::SelectLstPoints()
450 // ----------------------------------------------------------------------------
451 void manualViewBaseContour::SelectAllPoints(bool select)
453 int i,size=_lstViewPoints.size();
454 for (i=0;i<size;i++){
455 SelectPoint(i,select);
458 //-----------------------------------------------------------------------------
459 void manualViewBaseContour:: SetIfViewControlPoints(bool ifShow)
461 _viewControlPoints = ifShow;
463 // ----------------------------------------------------------------------------
464 bool manualViewBaseContour:: GetIfViewControlPoints()
466 return _viewControlPoints;
469 // ----------------------------------------------------------------------------
470 void manualViewBaseContour::SetPointPosibleSelected(int id,bool select)
472 _lstViewPoints[id]->SetPosibleSelected(select);
474 // ----------------------------------------------------------------------------
475 void manualViewBaseContour::SetPointSelected(int id,bool select)
477 _lstViewPoints[id]->SetSelected(select);
479 // ----------------------------------------------------------------------------
480 void manualViewBaseContour::SelectAllPossibleSelected(bool select)
482 int i,size=_lstViewPoints.size();
483 for (i=0;i<size;i++){
484 SetPointPosibleSelected(i,select);
487 // ----------------------------------------------------------------------------
488 int manualViewBaseContour::SelectPosiblePoint(int x, int y, int z) // virtual
490 SelectAllPossibleSelected(false);
492 int id = GetIdPoint(x,y,z);
495 SetPointPosibleSelected(id,true);
499 // ----------------------------------------------------------------------------
500 bool manualViewBaseContour::SelectPosibleContour(int x, int y, int z)
503 SetPosibleSelected(result);
504 int id = GetIdPoint(x,y,z);
506 if( !GetEditable() && !_selected && id!= -1)
509 _posibleSelected=true;
513 if ( (GetEditable()==true) && (id==-1 ) && (this->_lstViewPoints.size()>=2) )
515 if (ifTouchContour(x,y,z)==true)
518 SetPosibleSelected(result);
522 if (GetEditable()==false)
524 if (ifTouchContour(x,y,z)==true)
527 SetPosibleSelected(result);
533 // ----------------------------------------------------------------------------
534 bool manualViewBaseContour::ifTouchContour(int x,int y, int z) // virtual
538 // ----------------------------------------------------------------------------
539 void manualViewBaseContour::UnSelectPoint(int i){
540 _lstViewPoints[i]->SetSelected(false);
543 // ----------------------------------------------------------------------------
544 void manualViewBaseContour::UnSelectLstPoints(){
547 // ----------------------------------------------------------------------------
548 void manualViewBaseContour::UnSelectAllPoints(){
549 int i,size=_lstViewPoints.size();
550 for (i=0;i<size;i++){
555 // ----------------------------------------------------------------------------
556 void manualViewBaseContour::SetModel(manualBaseModel *manContModel){
557 _manContModel=manContModel;
559 // ----------------------------------------------------------------------------
560 void manualViewBaseContour::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview){
561 _wxvtkbaseview = wxvtkbaseview;
563 // ----------------------------------------------------------------------------
564 void manualViewBaseContour::RefreshContour() // Virtual
567 // ----------------------------------------------------------------------------
568 double* manualViewBaseContour::GetVectorPointsXManualContour(){
570 int i,size = _sizePointsContour;
571 double *vx = (double*)malloc(sizeof(double)*size);
572 for (i=0;i<size;i++){
573 _pts->GetPoint(i,pp);
578 // ----------------------------------------------------------------------------
579 double* manualViewBaseContour::GetVectorPointsYManualContour()
582 int i,size = _sizePointsContour;
583 double *vy = (double*)malloc(sizeof(double)*size);
584 for (i=0;i<size;i++){
585 _pts->GetPoint(i,pp);
590 // ----------------------------------------------------------------------------
591 double* manualViewBaseContour::GetVectorPointsZManualContour()
594 int i,size = _sizePointsContour;
595 double *vz = (double*)malloc(sizeof(double)*size);
596 for (i=0;i<size;i++){
597 _pts->GetPoint(i,pp);
602 // ----------------------------------------------------------------------------
603 void manualViewBaseContour::Refresh() // virtual
605 if (_contourVtkActor!=NULL){
608 int i,size=_lstViewPoints.size();
609 for (i=0;i<size;i++){
611 _lstViewPoints[i]->UpdateColorActor();
615 if (_show_text==true)
620 vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
623 _wxvtkbaseview->GetRenWin()->Render();
624 printf("EED %p How to optimize manualViewBaseContour::Refresh() \n",this);
628 // ----------------------------------------------------------------------------
629 void manualViewBaseContour::RefreshText() // virtual
631 if( _textActor!=NULL)
632 _textActor -> SetInput("00");
634 // ----------------------------------------------------------------------------
635 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
641 // ----------------------------------------------------------------------------
642 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
648 // ----------------------------------------------------------------------------
649 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
655 // ----------------------------------------------------------------------------
656 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
662 // ----------------------------------------------------------------------------
663 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
665 _coulorSelection_r = r;
666 _coulorSelection_g = g;
667 _coulorSelection_b = b;
669 // ----------------------------------------------------------------------------
670 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
672 r = _coulorSelection_r;
673 g = _coulorSelection_g;
674 b = _coulorSelection_b;
676 // ----------------------------------------------------------------------------
677 void manualViewBaseContour::UpdateColorActor()
679 if (_contourVtkActor!=NULL)
681 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
682 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
683 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
685 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
689 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
693 // ----------------------------------------------------------------------------
694 int manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
697 if (_manContModel!=NULL){
701 TransfromCoordViewWorld(xx,yy,zz);
702 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
707 // ----------------------------------------------------------------------------
710 int manualViewBaseContour::GetNumberOfPoints()
712 return _lstViewPoints.size();
715 // ----------------------------------------------------------------------------
717 //JSTG 25-02-08 ---------------------------------------------------------------
718 /*int manualViewBaseContour::GetNumberOfPointsSpline()
720 return _sizePointsContour;
722 //----------------------------------------------------------------------------
724 //JSTG 25-02-08 ---------------------------------------------------------------
725 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
727 _sizePointsContour = size;
729 //----------------------------------------------------------------------------
731 void manualViewBaseContour::TransfromCoordViewWorld(double &X, double &Y, double &Z, int type) // Virtual
733 _wxvtkbaseview->TransFromCoordScreenToWorld(X, Y, Z,false, type);
738 // wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
739 // wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z);
742 // ----------------------------------------------------------------------------
743 void manualViewBaseContour::SetRange(double range)
747 // ----------------------------------------------------------------------------
748 double manualViewBaseContour::GetRange()
752 // ----------------------------------------------------------------------------
753 void manualViewBaseContour::SetZ(int z)
757 // ----------------------------------------------------------------------------
758 int manualViewBaseContour::GetZ()
763 // ----------------------------------------------------------------------------
764 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
768 // ----------------------------------------------------------------------------
769 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
772 // ----------------------------------------------------------------------------
773 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
777 // ----------------------------------------------------------------------------
778 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
783 int size=_manContModel->GetSizeLstPoints();
788 bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
794 for( i = 0; i < size; i++ )
796 mp=_manContModel->GetManualPoint(i);
848 // ----------------------------------------------------------------------------
849 void manualViewBaseContour::ClearContour()
851 if (_contourVtkActor!=NULL){
852 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
855 int i,size=_lstViewPoints.size();
856 for (i=0;i<size;i++){
861 // ----------------------------------------------------------------------------
862 void manualViewBaseContour::ClearPoint(int id)
866 // ----------------------------------------------------------------------------
867 void manualViewBaseContour::SetVisible(bool ok)
877 int i,size=_lstViewPoints.size();
878 for (i=0;i<size;i++){
879 actor = _lstViewPoints[i]->GetVtkActor();
880 actor->GetProperty()->SetOpacity( opacity );
882 _contourVtkActor->GetProperty()->SetOpacity( opacity );
883 _textActor->GetProperty()->SetOpacity( opacity );
884 _textActor->SetInput("00");
887 // ----------------------------------------------------------------------------
888 void manualViewBaseContour::SetShowText(bool ok)
891 if (_show_text==false)
893 _textActor->SetInput("00");
896 // ----------------------------------------------------------------------------
897 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
899 return this->_wxvtkbaseview;
901 // ----------------------------------------------------------------------------
902 void manualViewBaseContour::GetSpacing(double spc[3])
908 // ----------------------------------------------------------------------------
909 void manualViewBaseContour::SetSpacing(double spc[3])