From 0794f161828e0602d361e1c0760b745d688496b9 Mon Sep 17 00:00:00 2001 From: Ricardo Corredor Date: Tue, 13 Oct 2009 02:36:32 +0000 Subject: [PATCH] Changes with manualBaseModel. It improves the functionality with the new points contour and some saving and loading aspects of the contours RaC --- .../widgets/manualContour/manualBaseModel.cpp | 369 ++++++++++++++++++ .../widgets/manualContour/manualBaseModel.h | 139 +++++++ .../manualContour/manualViewPoints.cpp | 158 ++++++++ .../widgets/manualContour/manualViewPoints.h | 105 +++++ 4 files changed, 771 insertions(+) create mode 100644 lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.cpp create mode 100644 lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.h create mode 100644 lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.cpp create mode 100644 lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.h diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.cpp new file mode 100644 index 0000000..5819d6c --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.cpp @@ -0,0 +1,369 @@ +#include "manualBaseModel.h" + +// ---------------------------------------------------------------------------- +manualBaseModel::manualBaseModel() +{ + + _sizePointsContour = 100; //JSTG 25-02-08 The change in the inisialization of these variable is critical. + +} + +// ---------------------------------------------------------------------------- +manualBaseModel::~manualBaseModel() +{ + int i,size=_lstPoints.size(); + for (i=0;iSetPoint(x,y,z); + AddManualPoint(mp); + + return _lstPoints.size()-1; +} +// ---------------------------------------------------------------------------- +int manualBaseModel::InsertPoint(double x,double y,double z) +{ + double dd,ddmin=9999999; + int ibak=0; + double xx,x1,x2; + double yy,y1,y2; + double zz,z1,z2; + int i,ii,iii,size=_lstPoints.size(); + double j,MaxDivisions=20,porcentage; + int sizeB=size; + + double jbak; + + for ( i=0 ; iGetX(); + y1=_lstPoints[ii]->GetY(); + z1=_lstPoints[ii]->GetZ(); + x2=_lstPoints[iii]->GetX(); + y2=_lstPoints[iii]->GetY(); + z2=_lstPoints[iii]->GetZ(); + for (j=0; j<=MaxDivisions; j++) + { + porcentage=(j/MaxDivisions); + xx=(x2-x1)*porcentage+x1; + yy=(y2-y1)*porcentage+y1; + zz=(z2-z1)*porcentage+z1; + dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) ); + if ( ddSetPoint(x,y,z); + std::vector::iterator itNum = _lstPoints.begin() + id; + _lstPoints.insert(itNum,mp); +} +// ---------------------------------------------------------------------------- + +void manualBaseModel::DeletePoint(int i) +{ + std::vector::iterator itNum = _lstPoints.begin() + i; + _lstPoints.erase(itNum); +} +// ---------------------------------------------------------------------------- +void manualBaseModel::DeleteAllPoints() +{ + int i,size=_lstPoints.size(); + for (i=0;iGetX()+dx; + double y=mp->GetY()+dy; + double z=mp->GetZ()+dz; + mp->SetPoint(x,y,z); +} +// ---------------------------------------------------------------------------- +void manualBaseModel::MoveLstPoints(double dx,double dy,double dz) +{ + // ToDo +} +// ---------------------------------------------------------------------------- +void manualBaseModel::MoveAllPoints(double dx,double dy,double dz) +{ + int i,size=_lstPoints.size(); + for (i=0;iGetX(); + yy=mp->GetY(); + zz=mp->GetZ(); + + if (type==-1) + { + if ((fabs(xx-x)GetX(); + yy=mp->GetY(); + + //RaC Be Careful!! Cast to have a point like the one in the params 27-09-09 + if(x==(int)xx && y==(int)yy ) + { + exists=true; + } + } + return exists; + +} +// ---------------------------------------------------------------------------- +manualPoint* manualBaseModel::GetManualPoint(int id) +{ + return _lstPoints[id]; +} +// ---------------------------------------------------------------------------- +int manualBaseModel::GetSizeLstPoints() +{ + return _lstPoints.size(); +} + +// ---------------------------------------------------------------------------- +manualBaseModel * manualBaseModel :: Clone() // virtual +{ + manualBaseModel * clone = new manualBaseModel(); + CopyAttributesTo(clone); + return clone; +} + +// ---------------------------------------------------------------------------- +int manualBaseModel::GetTypeModel() //virtual +{ + // 0 spline + // 1 spline + // 2 rectangle + // 3 circle + // 4 BullEye + // 5 BullEyeSector + // 6 Line + // 7 Points + return 7; +} + +// --------------------------------------------------------------------------- + +void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject) +{ + int i, size = GetSizeLstPoints(); + for( i=0; iAddManualPoint( GetManualPoint( i )->Clone() ); + } +} + + +// --------------------------------------------------------------------------- +void manualBaseModel::AddManualPoint( manualPoint* theManualPoint ) +{ + _lstPoints.push_back( theManualPoint ); +} + +void manualBaseModel::Open(FILE *ff) // virtual +{ +} +void manualBaseModel::Save(FILE *ff) // virtual +{ +} + +void manualBaseModel::SaveData(FILE *ff)// virtual +{ +} + + +// --------------------------------------------------------------------------- +void manualBaseModel::SetNumberOfPointsSpline(int size) +{ + _sizePointsContour = size; +} + +double manualBaseModel::GetPathSize() +{ + return 0.0; +} + +void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By) +{ +} + +void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z) +{ + //RaC 20-09-09 IF it's a points contour + if(GetTypeModel()==7){ + if (_lstPoints.size()==0) + { + *x = 0; + *y = 0; + *z = 0; + } + else + { + manualPoint *mp; + mp = _lstPoints[i]; + *x = mp->GetX(); + *y = mp->GetY(); + *z = mp->GetZ(); + } + + } + +} + +void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z) +{ +} + +// --------------------------------------------------------------------------- +int manualBaseModel::GetNumberOfPointsSpline() +{ + + //RaC 20-09-09 IF it's a points contour + if(GetTypeModel()==7){ + return _lstPoints.size(); + } + return _sizePointsContour; +} + +// --------------------------------------------------------------------------- +void manualBaseModel::UpdateSpline() +{ +} + +// --------------------------------------------------------------------------- +std::vector manualBaseModel::ExploseModel( ) +{ + std::vector lstTmp; + lstTmp.push_back(this); + return lstTmp; +} + +// --------------------------------------------------------------------------- +double manualBaseModel::GetPathArea() +{ + return 0.0; +} +void manualBaseModel::GetNearestPointAndNormal(double *p, double *rp, double *rn) +{ +} +void manualBaseModel::SetCloseContour(bool closeContour) +{ +} +bool manualBaseModel::IfCloseContour() +{ + return false; +} +//CMRU 17-08-09---------------------------------------------------------------------------- +void manualBaseModel::SetLabel(std::string newLabel) +{ +} + +void manualBaseModel::SetRealSize(double newRealSize) +{ +} + +double manualBaseModel::GetRealSize() +{ + return -1; +} + +std::string manualBaseModel::GetLabel() +{ + return ""; +} +void manualBaseModel::OpenData(FILE *ff) +{ +} +//---------------------------------------------------------------------------- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.h new file mode 100644 index 0000000..fe772f7 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.h @@ -0,0 +1,139 @@ +#ifndef manualBaseModel_h +#define manualBaseModel_h + +#include "vtkRenderWindow.h" + +#include "vtkRenderer.h" +#include "vtkRenderWindowInteractor.h" //extremely important with VC++ don't remove ! +#include "vtkCommand.h" +#include "vtkPolyData.h" +#include "vtkCellArray.h" +#include "vtkPolyDataMapper.h" +#include "vtkInteractorObserver.h" +#include "vtkInteractorStyleImage.h" +#include +#include +#include +#include +#include + +#include "wxVTKRenderWindowInteractor.h" + +#include +#include "wxVtkBaseView.h" +#include "marTypes.h" +#include "manualPoint.h" + +// -------------------------------------------------------------------------------------------- +// Includes the functionality to manage a contour without the spline line usage +// @author RaC 09-09 +class creaMaracasVisu_EXPORT manualBaseModel +{ +public: + manualBaseModel(); + virtual ~manualBaseModel(); + + virtual manualBaseModel * Clone(); + void CopyAttributesTo( manualBaseModel *cloneObject ); + virtual void Open(FILE *ff); // virtual + virtual void Save(FILE *ff); // virtual + virtual int GetTypeModel(); // virtual + + virtual void SetNumberOfPointsSpline(int size); + + virtual int AddPoint(double x,double y,double z); + virtual int InsertPoint(double x,double y,double z); + virtual void InsertPoint_id(int id, double x,double y,double z); + virtual void AddManualPoint( manualPoint* theManualPoint ); + virtual void DeletePoint(int i); + virtual void DeleteAllPoints(); + + virtual void MovePoint(int i,double dx,double dy,double dz); + virtual void MoveLstPoints(double dx,double dy,double dz); + virtual void MoveAllPoints(double dx,double dy,double dz); + + // Returns the id of the point in the coordinates and the i_range given, according to the type + // which corresponds to the plane where it's necessary to find the point. + // @param type=-1 x,y,z - type=0 y,z - type=1 x,z - type=2 x,y + // @return int - Returns the id of the point in the coordinates given. Returns -1 otherwise. + virtual int GetIdPoint(double x, double y, double z, int i_range,int type); + virtual manualPoint* GetManualPoint(int id); + virtual int GetSizeLstPoints(); + virtual double GetPathSize(); + virtual void Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By); + virtual void GetSpline_i_Point(int i, double *x, double *y, double *z); + virtual void GetSpline_t_Point(double t, double *x, double *y, double *z); + + // + // Returns the number of points of the spline line, but not the contour control points + // @return int - spline points size + // + virtual int GetNumberOfPointsSpline(); + virtual void UpdateSpline(); + + // + // Returns a list with the actual model + // @return std::vector + // + virtual std::vector ExploseModel( ); + virtual double GetPathArea(); + virtual void GetNearestPointAndNormal(double *p, double *rp, double *rn); + + virtual void SetCloseContour(bool closeContour); + virtual bool IfCloseContour(); + + // RaC 27-09-09 ---- + + // + // Returns true if the point with the coordinates in parameters is one of the points in + // the list of points of the model, + // @param x double + // @param y double + // @return true if the point with the coordinates in parameters is one of the points, false otherwise + // + int IsPoint(double x, double y); + + // CMRU 17-08-09 ----------------------------------------------------------------- + + /* + * Assigns the parameter value to the label + * @param newLabel New label of the contour + */ + virtual void SetLabel(std::string newLabel); + + /* + * Assigns the parameter value to the real size + * @param newRealSize New real size in milimeters of the contour + */ + virtual void SetRealSize(double newRealSize); + + /** + * Returns the label of the contour + */ + virtual std::string GetLabel(); + + /** + * Returns the real size in milimeters of the contour + */ + virtual double GetRealSize(); + + /* + * Saves the label and the real size of the contour + * @param ff File where the information is stored + */ + virtual void SaveData(FILE *ff); + + /* + * Reads and interprets the information of the label and the real size + * @param ff File where the information is readed + */ + virtual void OpenData(FILE *ff); + +protected: + int _sizePointsContour; + std::vector _lstPoints; + +}; + + +#endif // manualBaseModel_h diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.cpp new file mode 100644 index 0000000..192da18 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.cpp @@ -0,0 +1,158 @@ +#include "manualViewPoints.h" + +// ---------------------------------------------------------------------------- +manualViewPoints::manualViewPoints() +{ +} + +// ---------------------------------------------------------------------------- +manualViewPoints::~manualViewPoints() +{ + int i,size=_copyViewPoints.size(); + for (i=0;iGetIdPoint(xx,yy,zz,_range,2); + + if(id!=-1){ + result = true; + } + + + return result; +} + +// ---------------------------------------------------------------------------- +void manualViewPoints::Refresh() // VIRTUAL +{ + RefreshContour(); + manualViewBaseContour::Refresh(); +} + +// ---------------------------------------------------------------------------- +void manualViewPoints::RefreshContour() // VIRTUAL +{ + int np = GetNumberOfPoints(); + int copynp= _copyViewPoints.size(); + + while(copynp!=np){ + + if(copynpCreateVtkPointActor(); + _wxvtkbaseview->GetRenderer()->AddActor( actor ); + + _copyViewPoints.push_back(mvp); + }//if + else if(copynp>np) + { + manualViewPoint *t = _copyViewPoints[0]; + _wxvtkbaseview->GetRenderer()->RemoveActor( t->GetVtkActor() ); + std::vector::iterator itNum = _copyViewPoints.begin(); + _copyViewPoints.erase(itNum); + delete t; + }// else if + copynp= _copyViewPoints.size(); + + }// while + + int i; + for(i=0;iGetManualPoint(i)->GetX(); + double yy = _manContModel->GetManualPoint(i)->GetY(); + double zz = 900; // RaC REVISAR !! + + manualViewPoint *mv = _copyViewPoints[i]; + + //Paints new Rectangular points bigger than the actual control points + mv->SetPositionXY(xx, yy, _range*2, zz); + + vtkActor *_pointVtkActor = mv->GetVtkActor(); + + _pointVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b ); + if (_posibleSelected || (_posibleSelected && GetEditable() ) ) + { + _pointVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b ); + } + if( _selected ) + { + _pointVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b ); + } + + //IF you want to customize the points which are going to be painted + //mv->UpdateColorActor(_colorViewPoints_r,_colorViewPoints_g,_colorViewPoints_b); + //mv->SetWidthLine(1.3); + } +} + +// ---------------------------------------------------------------------------- +void manualViewPoints::ConstructVTKObjects() // VIRTUAL +{ + InitTextActor(); +} + +// ---------------------------------------------------------------------------- +void manualViewPoints::AddSplineActor() // VIRTUAL +{ + int i,size=_copyViewPoints.size(); + for (i=0;iGetRenderer()->AddActor( _copyViewPoints[i]->GetVtkActor() ); + } +} + +// ---------------------------------------------------------------------------- +void manualViewPoints::RemoveSplineActor() // VIRTUAL +{ + int i,size=_copyViewPoints.size(); + for (i=0;iGetRenderer()->RemoveActor(_copyViewPoints[i]->GetVtkActor()); + + } +} + + + diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.h new file mode 100644 index 0000000..1b95a44 --- /dev/null +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoints.h @@ -0,0 +1,105 @@ +#ifndef manualViewPoints_h +#define manualViewPoints_h + +#include "manualViewBaseContour.h" +#include "manualViewPoint.h" +#include + + +// -------------------------------------------------------------------------------------------- +// Class that includes the functionality to manage some selected points like a new contour +// @author RaC 09-09 +class creaMaracasVisu_EXPORT manualViewPoints: public manualViewBaseContour +{ + +//--------------------------------------------------- +// PUBLIC METHODS & ATTS +//--------------------------------------------------- +public: + // + // Class Constructor + // + manualViewPoints(); + + // + // Method to copy all attributes to the clone object references by parameter + // @param *cloneObject - manualViewPoints Clone object + /// + void CopyAttributesTo( manualViewPoints *cloneObject ); + + //--------------------------------------------------- + // PUBLIC & VIRTUAL METHODS & ATTS + //--------------------------------------------------- + + /// + // Class Destructor. Delete all elements in points copy list + /// + virtual ~manualViewPoints(); + + // + // Method to clone a manualViewPoints object + // + virtual manualViewPoints * Clone(); + + // + // Returns the contour type + // Points Contour type := 7 + // @return type - int + // + virtual int GetType(); + + // + // Returns true if the point with the (x,y,z) window coordinates touch the contour + // @param x - int + // @param y - int + // @param z - int + // @return true if touch contour, false otherwise + // + virtual bool ifTouchContour(int x,int y, int z); + + // + // Refresh control points with the specified color, calls the RefreshContour method + // and render the contour + // + virtual void Refresh(); + + // + // Refresh contour. In this case, it synchronizes the copy list with the control points list in order + // to paint the point actors in the position assigned in the model points list + // + virtual void RefreshContour(); + + // + // Removes actor of the contour points, but no the control points. + // + virtual void RemoveSplineActor(); + + // + // Adds actor of the contour points, but no the control points. + // + virtual void AddSplineActor(); + + // + // Constructs VTKObjects. Only initializes text actor + // + virtual void ConstructVTKObjects(); + + // + // To move all the contour + // + //virtual void MoveContour(int x, int y, int z); + +//--------------------------------------------------- +// PRIVATE METHODS & ATTS +//--------------------------------------------------- +private: + + // + // Copy of the control points list. These are the points which are painted when the + // contour is not selected + // + std::vector _copyViewPoints; + +}; + +#endif // manualViewPoints_h -- 2.46.0